aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2021-08-23 19:47:38 -0700
committerAndrew G. Morgan <morgan@kernel.org>2021-08-23 19:47:38 -0700
commit5647374b3319796957edfb25400bf4164efca6c2 (patch)
tree90ffab67550a1ea028038ed562452093aafdc454
parent2e28d3f3e8a1eab3cae561465a4e8076b984be2f (diff)
downloadlibcap-5647374b3319796957edfb25400bf4164efca6c2.tar.gz
Revert most of the LDFLAGS -> LDSTATIC change.
The intention was to force --static linking in only one corner case, so be more explicit about that one, and revert the build behavior in the others. Reason for doing this was feedback from Arnout Vandecappelle in: https://bugzilla.kernel.org/show_bug.cgi?id=214023#c16 Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--progs/Makefile9
-rw-r--r--tests/Makefile19
2 files changed, 17 insertions, 11 deletions
diff --git a/progs/Makefile b/progs/Makefile
index 172ad37..c36ba9c 100644
--- a/progs/Makefile
+++ b/progs/Makefile
@@ -14,7 +14,10 @@ ifeq ($(DYNAMIC),yes)
LDPATH = LD_LIBRARY_PATH=../libcap
DEPS = ../libcap/libcap.so
else
-LDSTATIC = --static
+# 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
DEPS = ../libcap/libcap.a
endif
@@ -25,7 +28,7 @@ endif
make -C ../libcap libcap.so
$(BUILD): %: %.o $(DEPS)
- $(CC) $(CFLAGS) -o $@ $< $(LIBCAPLIB) $(LDSTATIC)
+ $(CC) $(CFLAGS) -o $@ $< $(LIBCAPLIB) $(LDFLAGS)
%.o: %.c $(INCS)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
@@ -46,7 +49,7 @@ capshdoc.h.cf: capshdoc.h ./mkcapshdoc.sh
diff -u capshdoc.h $@ || (rm $@ ; exit 1)
capsh: capsh.c capshdoc.h.cf $(DEPS)
- $(CC) $(CFLAGS) $(CPPFLAGS) $(CAPSH_SHELL) -o $@ $< $(LIBCAPLIB) $(LDSTATIC)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(CAPSH_SHELL) -o $@ $< $(LIBCAPLIB) $(LDFLAGS)
tcapsh-static: capsh.c capshdoc.h.cf $(DEPS)
$(CC) $(CFLAGS) $(CPPFLAGS) $(CAPSH_SHELL) -o $@ $< $(LIBCAPLIB) --static
diff --git a/tests/Makefile b/tests/Makefile
index 4e1a14d..de890d0 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -22,7 +22,10 @@ ifeq ($(PTHREADS),yes)
DEPS += ../libcap/libpsx.so
endif
else
-LDSTATIC = --static
+# 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
DEPS=../libcap/libcap.a
ifeq ($(PTHREADS),yes)
DEPS += ../libcap/libpsx.a
@@ -63,17 +66,17 @@ run_psx_test: psx_test
./psx_test
psx_test: psx_test.c $(DEPS)
- $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBPSXLIB) $(LDSTATIC)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBPSXLIB) $(LDFLAGS)
run_libcap_psx_test: libcap_psx_test
./libcap_psx_test
libcap_psx_test: libcap_psx_test.c $(DEPS)
- $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LIBPSXLIB) $(LDSTATIC)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LIBPSXLIB) $(LDFLAGS)
# privileged
uns_test: uns_test.c $(DEPS)
- $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LDSTATIC)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LDFLAGS)
run_uns_test: uns_test
echo exit | sudo ./uns_test
@@ -85,13 +88,13 @@ run_libcap_psx_launch_test: libcap_psx_launch_test ../progs/tcapsh-static
sudo ./libcap_psx_launch_test
libcap_launch_test: libcap_launch_test.c $(DEPS)
- $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LDSTATIC)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LDFLAGS)
# This varies only slightly from the above insofar as it currently
# only links in the pthreads fork support. TODO() we need to change
# the source to do something interesting with pthreads.
libcap_psx_launch_test: libcap_launch_test.c $(DEPS)
- $(CC) $(CFLAGS) $(CPPFLAGS) -DWITH_PTHREADS $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LIBPSXLIB) $(LDSTATIC)
+ $(CC) $(CFLAGS) $(CPPFLAGS) -DWITH_PTHREADS $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LIBPSXLIB) $(LDFLAGS)
# This test demonstrates that libpsx is needed to secure multithreaded
@@ -106,12 +109,12 @@ exploit.o: exploit.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
exploit: exploit.o $(DEPS)
- $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) -lpthread $(LDSTATIC)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) -lpthread $(LDFLAGS)
# Note, for some reason, the order of libraries is important to avoid
# the exploit working for dynamic linking.
noexploit: exploit.o $(DEPS)
- $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBPSXLIB) $(LIBCAPLIB) $(LDSTATIC)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(LINKEXTRA) $(LIBPSXLIB) $(LIBCAPLIB) $(LDFLAGS)
# This one runs in a chroot with no shared library files.
noop: noop.c