aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2022-10-15 08:29:29 -0700
committerAndrew G. Morgan <morgan@kernel.org>2022-10-15 08:29:42 -0700
commitf30f85c637d7d38f87f1a93ef05b64ee45d6a825 (patch)
tree062e77150fd2ecfc9cf647761c1eacae8958ad4b
parent911da84bf4e1613567d4ef57e70c85326161ccad (diff)
downloadlibcap-f30f85c637d7d38f87f1a93ef05b64ee45d6a825.tar.gz
Modify DYNAMIC=no linking to only refer to libcap.a
There is a longstanding WONT_FIX bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12491 that has been causing capsh, when linked fully statically, to segfault. So, for non-dynamic linking of capsh etc utilities only link statically to libcap. This way, in tree builds can be guaranteed to get to execute with in tree API changes. For normal installations, DYNAMIC=yes works as before. Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--progs/Makefile12
1 files changed, 7 insertions, 5 deletions
diff --git a/progs/Makefile b/progs/Makefile
index 2cb7520..826834c 100644
--- a/progs/Makefile
+++ b/progs/Makefile
@@ -15,9 +15,11 @@ LDPATH = LD_LIBRARY_PATH=../libcap
DEPS = ../libcap/libcap.so
else
# For this build variant override the LDFLAGS to link statically from
-# libraries within the build tree. If you never want this, use
-# make DYNAMIC=yes ...
-LDFLAGS = --static
+# libraries within the build tree. If you never want this, use make
+# DYNAMIC=yes . Note, we can't reliably link statically against glibc
+# becasuse of https://sourceware.org/bugzilla/show_bug.cgi?id=12491 .
+LDFLAGS = -Wl,-Bstatic
+LDFLAGS_SUFFIX = -Wl,-Bdynamic
DEPS = ../libcap/libcap.a
endif
@@ -28,7 +30,7 @@ endif
$(MAKE) -C ../libcap libcap.so
$(BUILD): %: %.o $(DEPS)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBCAPLIB)
+ $(CC) $(CFLAGS) $(LDFLAGS) $< $(LIBCAPLIB) $(LDFLAGS_SUFFIX) -o $@
%.o: %.c $(INCS)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
@@ -50,7 +52,7 @@ capshdoc.c.cf: capshdoc.c ./mkcapshdoc.sh
diff -u capshdoc.c $@ || (rm $@ ; exit 1)
capsh: capsh.c capshdoc.c.cf capshdoc.h $(DEPS)
- $(CC) $(CFLAGS) $(CPPFLAGS) $(CAPSH_SHELL) $(LDFLAGS) -o $@ $< capshdoc.c $(LIBCAPLIB)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(CAPSH_SHELL) $(LDFLAGS) $< capshdoc.c $(LIBCAPLIB) $(LDFLAGS_SUFFIX) -o $@
# Statically linked with minimal linkage flags to enable running in a
# chroot and in other in-tree testing contexts.