1 From 169977f82b210d3dbb2d24bc9718db5726a8087f Mon Sep 17 00:00:00 2001
2 From: Fathi Boudra <fathi.boudra@linaro.org>
3 Date: Wed, 16 Jan 2019 11:43:19 -0600
4 Subject: selftests: seccomp: use LDLIBS instead of LDFLAGS
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 [ Upstream commit 5bbc73a841d7f0bbe025a342146dde462a796a5a ]
11 seccomp_bpf fails to build due to undefined reference errors:
13 aarch64-linaro-linux-gcc --sysroot=/build/tmp-rpb-glibc/sysroots/hikey
14 -O2 -pipe -g -feliminate-unused-debug-types -Wl,-no-as-needed -Wall
15 -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -lpthread seccomp_bpf.c -o
16 /build/tmp-rpb-glibc/work/hikey-linaro-linux/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf
17 /tmp/ccrlR3MW.o: In function `tsync_sibling':
18 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1920: undefined reference to `sem_post'
19 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1920: undefined reference to `sem_post'
20 /tmp/ccrlR3MW.o: In function `TSYNC_setup':
21 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1863: undefined reference to `sem_init'
22 /tmp/ccrlR3MW.o: In function `TSYNC_teardown':
23 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1904: undefined reference to `sem_destroy'
24 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1897: undefined reference to `pthread_kill'
25 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1898: undefined reference to `pthread_cancel'
26 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1899: undefined reference to `pthread_join'
27 /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
28 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
29 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
30 /tmp/ccrlR3MW.o: In function `TSYNC_siblings_fail_prctl':
31 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1978: undefined reference to `sem_wait'
32 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1990: undefined reference to `pthread_join'
33 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1992: undefined reference to `pthread_join'
34 /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
35 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
36 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
37 /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_ancestor':
38 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2016: undefined reference to `sem_wait'
39 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2032: undefined reference to `pthread_join'
40 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2034: undefined reference to `pthread_join'
41 /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
42 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
43 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
44 /tmp/ccrlR3MW.o: In function `TSYNC_two_sibling_want_nnp':
45 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2046: undefined reference to `sem_wait'
46 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2058: undefined reference to `pthread_join'
47 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2060: undefined reference to `pthread_join'
48 /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
49 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
50 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
51 /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_no_filter':
52 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2073: undefined reference to `sem_wait'
53 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2098: undefined reference to `pthread_join'
54 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2100: undefined reference to `pthread_join'
55 /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
56 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
57 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
58 /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_one_divergence':
59 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2125: undefined reference to `sem_wait'
60 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2143: undefined reference to `pthread_join'
61 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2145: undefined reference to `pthread_join'
62 /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
63 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
64 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
65 /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_not_under_filter':
66 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2169: undefined reference to `sem_wait'
67 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2202: undefined reference to `pthread_join'
68 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2227: undefined reference to `pthread_join'
69 /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
70 /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
72 It's GNU Make and linker specific.
74 The default Makefile rule looks like:
76 $(CC) $(CFLAGS) $(LDFLAGS) $@ $^ $(LDLIBS)
78 When linking is done by gcc itself, no issue, but when it needs to be passed
79 to proper ld, only LDLIBS follows and then ld cannot know what libs to link
83 https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
86 Extra flags to give to compilers when they are supposed to invoke the linker,
87 ‘ld’, such as -L. Libraries (-lfoo) should be added to the LDLIBS variable
91 Library flags or names given to compilers when they are supposed to invoke the
92 linker, ‘ld’. LOADLIBES is a deprecated (but still supported) alternative to
93 LDLIBS. Non-library linker flags, such as -L, should go in the LDFLAGS
96 https://lkml.org/lkml/2010/2/10/362
98 tools/perf: libraries must come after objects
100 Link order matters, use LDLIBS instead of LDFLAGS to properly link against
103 Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>
104 Acked-by: Kees Cook <keescook@chromium.org>
105 Signed-off-by: Shuah Khan <shuah@kernel.org>
106 Signed-off-by: Sasha Levin <sashal@kernel.org>
108 tools/testing/selftests/seccomp/Makefile | 2 +-
109 1 file changed, 1 insertion(+), 1 deletion(-)
111 diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
112 index fce7f4ce06925..1760b3e397306 100644
113 --- a/tools/testing/selftests/seccomp/Makefile
114 +++ b/tools/testing/selftests/seccomp/Makefile
115 @@ -9,7 +9,7 @@ BINARIES := seccomp_bpf seccomp_benchmark
116 CFLAGS += -Wl,-no-as-needed -Wall
118 seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
119 - $(CC) $(CFLAGS) $(LDFLAGS) -lpthread $< -o $@
120 + $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@
122 TEST_PROGS += $(BINARIES)
123 EXTRA_CLEAN := $(BINARIES)