summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-03-03 21:49:15 +0000
committermidipix <writeonce@midipix.org>2024-03-04 03:28:57 +0000
commit93e38b3566a587e0aec3c46de85abf28f82614ac (patch)
tree3a77ce8c94a2f6fffc1606def23b88a859e42c9b
parenta3e2d3ae686409f59f7470ae1898f96e1c9df453 (diff)
downloadslibtool-93e38b3566a587e0aec3c46de85abf28f82614ac.tar.bz2
slibtool-93e38b3566a587e0aec3c46de85abf28f82614ac.tar.xz
link mode: unless created for the current .la, mark the .a or .so as disabled.
-rw-r--r--src/internal/slibtool_symlink_impl.c10
-rw-r--r--src/logic/linkcmd/slbt_linkcmd_archive.c19
-rw-r--r--src/logic/linkcmd/slbt_linkcmd_dsolib.c32
-rw-r--r--src/logic/slbt_exec_link.c77
4 files changed, 109 insertions, 29 deletions
diff --git a/src/internal/slibtool_symlink_impl.c b/src/internal/slibtool_symlink_impl.c
index a788800..34661f0 100644
--- a/src/internal/slibtool_symlink_impl.c
+++ b/src/internal/slibtool_symlink_impl.c
@@ -47,18 +47,14 @@ slbt_hidden int slbt_create_symlink(
fdevnull = (options & SLBT_SYMLINK_DEVNULL);
/* symlink is a placeholder? */
- if (fliteral && fdevnull) {
+ if (fliteral) {
slash = target;
- } else if ((dctx->cctx->drvflags & SLBT_DEV_NULL_FLAGS)
- && !strcmp(target,"/dev/null")) {
+ /* .disabled .so or .a file */
+ } else if (fdevnull) {
slash = target;
suffix = ".disabled";
- /* target is an absolute path? */
- } else if (fliteral) {
- slash = target;
-
/* symlink target contains a dirname? */
} else if ((slash = strrchr(target,'/'))) {
slash++;
diff --git a/src/logic/linkcmd/slbt_linkcmd_archive.c b/src/logic/linkcmd/slbt_linkcmd_archive.c
index a8002fb..9b002f6 100644
--- a/src/logic/linkcmd/slbt_linkcmd_archive.c
+++ b/src/logic/linkcmd/slbt_linkcmd_archive.c
@@ -57,17 +57,26 @@ static int slbt_exec_link_remove_file(
const char * target)
{
int fdcwd;
-
- (void)ectx;
+ char * mark;
+ char * sbuf;
/* fdcwd */
fdcwd = slbt_driver_fdcwd(dctx);
/* remove target (if any) */
- if (!unlinkat(fdcwd,target,0) || (errno == ENOENT))
- return 0;
+ if (unlinkat(fdcwd,target,0) && (errno != ENOENT))
+ return SLBT_SYSTEM_ERROR(dctx,0);
+
+ /* remove a previous .disabled placeholder */
+ sbuf = (slbt_get_exec_ictx(ectx))->sbuf;
+ mark = sbuf;
+ mark += sprintf(mark,"%s",target);
+ strcpy(mark,".disabled");
- return SLBT_SYSTEM_ERROR(dctx,0);
+ if (unlinkat(fdcwd,sbuf,0) && (errno != ENOENT))
+ return SLBT_SYSTEM_ERROR(dctx,0);
+
+ return 0;
}
slbt_hidden int slbt_exec_link_create_archive(
diff --git a/src/logic/linkcmd/slbt_linkcmd_dsolib.c b/src/logic/linkcmd/slbt_linkcmd_dsolib.c
index dd5bf64..b740a00 100644
--- a/src/logic/linkcmd/slbt_linkcmd_dsolib.c
+++ b/src/logic/linkcmd/slbt_linkcmd_dsolib.c
@@ -55,6 +55,34 @@ static int slbt_exec_link_remove_file(
return SLBT_SYSTEM_ERROR(dctx,0);
}
+static int slbt_exec_link_remove_dso_files(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ const char * target)
+{
+ int fdcwd;
+ char * mark;
+ char * sbuf;
+
+ /* fdcwd */
+ fdcwd = slbt_driver_fdcwd(dctx);
+
+ /* remove target (if any) */
+ if (unlinkat(fdcwd,target,0) && (errno != ENOENT))
+ return SLBT_SYSTEM_ERROR(dctx,0);
+
+ /* remove a previous .disabled placeholder */
+ sbuf = (slbt_get_exec_ictx(ectx))->sbuf;
+ mark = sbuf;
+ mark += sprintf(mark,"%s",target);
+ strcpy(mark,".disabled");
+
+ if (unlinkat(fdcwd,sbuf,0) && (errno != ENOENT))
+ return SLBT_SYSTEM_ERROR(dctx,0);
+
+ return 0;
+}
+
slbt_hidden int slbt_exec_link_create_library(
const struct slbt_driver_ctx * dctx,
struct slbt_exec_ctx * ectx,
@@ -85,6 +113,10 @@ slbt_hidden int slbt_exec_link_create_library(
/* fdcwd */
fdcwd = slbt_driver_fdcwd(dctx);
+ /* remove previous libfoo.so, libfoo.so.disabled */
+ if (slbt_exec_link_remove_dso_files(dctx,ectx,ectx->dsofilename) < 0)
+ return SLBT_NESTED_ERROR(dctx);
+
/* input argument adjustment */
for (parg=ectx->cargv; *parg; parg++)
slbt_adjust_object_argument(*parg,true,false,fdcwd);
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index 423a20e..1e1e5b2 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -136,7 +136,9 @@ int slbt_exec_link(const struct slbt_driver_ctx * dctx)
char * dot;
struct slbt_exec_ctx * ectx;
bool fpic;
- bool fstaticonly;
+ bool fnodsolib;
+ bool fnoarchive;
+ bool fstaticobjs;
char soname[PATH_MAX];
char soxyz [PATH_MAX];
char solnk [PATH_MAX];
@@ -208,21 +210,37 @@ int slbt_exec_link(const struct slbt_driver_ctx * dctx)
return SLBT_NESTED_ERROR(dctx);
}
- /* fpic, fstaticonly */
+ /* fpic, fstaticobjs, fnodsolib, fnoarchive */
if (dctx->cctx->drvflags & SLBT_DRIVER_ALL_STATIC) {
- fstaticonly = true;
+ fstaticobjs = true;
+ fnodsolib = true;
+ fnoarchive = false;
fpic = false;
} else if (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_SHARED) {
- fstaticonly = true;
+ fstaticobjs = true;
+ fnodsolib = true;
+ fnoarchive = false;
fpic = false;
- } else if (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_STATIC) {
- fstaticonly = false;
- fpic = true;
} else if (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) {
- fstaticonly = false;
+ fstaticobjs = false;
fpic = true;
+
+ if (dctx->cctx->libname && dctx->cctx->rpath) {
+ fnodsolib = false;
+ fnoarchive = (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_STATIC);
+
+ } else if (dctx->cctx->libname) {
+ fnodsolib = true;
+ fnoarchive = false;
+
+ } else {
+ fnodsolib = true;
+ fnoarchive = true;
+ }
} else {
- fstaticonly = false;
+ fstaticobjs = false;
+ fnodsolib = true;
+ fnoarchive = false;
fpic = false;
}
@@ -235,7 +253,7 @@ int slbt_exec_link(const struct slbt_driver_ctx * dctx)
}
/* pic libfoo.a */
- if (dot && !strcmp(dot,".la"))
+ if (dot && !strcmp(dot,".la") && !fnoarchive)
if (slbt_exec_link_create_archive(
dctx,ectx,
ectx->arfilename,
@@ -245,7 +263,7 @@ int slbt_exec_link(const struct slbt_driver_ctx * dctx)
}
/* static-only libfoo.la */
- if (fstaticonly && dot && !strcmp(dot,".la")) {
+ if (fstaticobjs && dot && !strcmp(dot,".la")) {
const struct slbt_flavor_settings * dflavor;
if (slbt_host_flavor_settings("default",&dflavor) < 0)
@@ -277,21 +295,46 @@ int slbt_exec_link(const struct slbt_driver_ctx * dctx)
dctx,ectx,
"/dev/null",
ectx->deffilename,
- SLBT_SYMLINK_LITERAL|SLBT_SYMLINK_DEVNULL))
+ SLBT_SYMLINK_LITERAL))
return SLBT_NESTED_ERROR(dctx);
}
- /* -all-static library */
- if (fstaticonly && dctx->cctx->libname)
+ /* static archive or convenience library only? */
+ if (fnodsolib && ectx->dsofilename) {
+ if (slbt_create_symlink(
+ dctx,ectx,
+ "/dev/null",
+ ectx->dsofilename,
+ SLBT_SYMLINK_LITERAL))
+ return SLBT_NESTED_ERROR(dctx);
+
if (slbt_create_symlink(
dctx,ectx,
"/dev/null",
ectx->dsofilename,
+ SLBT_SYMLINK_DEVNULL))
+ return SLBT_NESTED_ERROR(dctx);
+ }
+
+ /* disable static? */
+ if (fnoarchive && ectx->arfilename) {
+ if (slbt_create_symlink(
+ dctx,ectx,
+ "/dev/null",
+ ectx->arfilename,
SLBT_SYMLINK_LITERAL))
return SLBT_NESTED_ERROR(dctx);
+ if (slbt_create_symlink(
+ dctx,ectx,
+ "/dev/null",
+ ectx->arfilename,
+ SLBT_SYMLINK_DEVNULL))
+ return SLBT_NESTED_ERROR(dctx);
+ }
+
/* dynamic library via -module */
- if (dctx->cctx->rpath && !fstaticonly) {
+ if (dctx->cctx->rpath && !fstaticobjs) {
if (dctx->cctx->drvflags & SLBT_DRIVER_MODULE) {
if (!dot || strcmp(dot,".la")) {
if (slbt_exec_link_create_library(
@@ -311,7 +354,7 @@ int slbt_exec_link(const struct slbt_driver_ctx * dctx)
}
/* dynamic library */
- if (dot && !strcmp(dot,".la") && dctx->cctx->rpath && !fstaticonly) {
+ if (dot && !strcmp(dot,".la") && dctx->cctx->rpath && !fstaticobjs) {
const struct slbt_flavor_settings * dflavor;
if (slbt_host_flavor_settings("default",&dflavor) < 0)
@@ -427,7 +470,7 @@ int slbt_exec_link(const struct slbt_driver_ctx * dctx)
dctx,ectx,
"/dev/null",
ectx->deffilename,
- SLBT_SYMLINK_LITERAL|SLBT_SYMLINK_DEVNULL))
+ SLBT_SYMLINK_LITERAL))
return SLBT_NESTED_ERROR(dctx);
}
}