All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: "Daniel Díaz" <daniel.diaz@linaro.org>, "Shuah Khan" <shuah@kernel.org>
Cc: Fathi Boudra <fathi.boudra@linaro.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/4] selftests: seccomp: use LDLIBS instead of LDFLAGS
Date: Wed, 16 Jan 2019 10:13:59 -0800	[thread overview]
Message-ID: <CAGXu5j+1tOvB0jHk=kCxfhTg-PEPjCHp2TQb++wZsGxJCcQxng@mail.gmail.com> (raw)
In-Reply-To: <20190116174320.14938-3-daniel.diaz@linaro.org>

On Wed, Jan 16, 2019 at 9:44 AM Daniel Díaz <daniel.diaz@linaro.org> wrote:
>
> From: Fathi Boudra <fathi.boudra@linaro.org>
>
> seccomp_bpf fails to build due to undefined reference errors:
>
>  aarch64-linaro-linux-gcc --sysroot=/build/tmp-rpb-glibc/sysroots/hikey
>  -O2 -pipe -g -feliminate-unused-debug-types -Wl,-no-as-needed -Wall
>  -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -lpthread seccomp_bpf.c -o
>  /build/tmp-rpb-glibc/work/hikey-linaro-linux/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf
>  /tmp/ccrlR3MW.o: In function `tsync_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1920: undefined reference to `sem_post'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1920: undefined reference to `sem_post'
>  /tmp/ccrlR3MW.o: In function `TSYNC_setup':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1863: undefined reference to `sem_init'
>  /tmp/ccrlR3MW.o: In function `TSYNC_teardown':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1904: undefined reference to `sem_destroy'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1897: undefined reference to `pthread_kill'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1898: undefined reference to `pthread_cancel'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1899: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_siblings_fail_prctl':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1978: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1990: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1992: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_ancestor':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2016: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2032: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2034: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_sibling_want_nnp':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2046: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2058: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2060: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_no_filter':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2073: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2098: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2100: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_one_divergence':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2125: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2143: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2145: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_not_under_filter':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2169: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2202: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2227: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>
> It's GNU Make and linker specific.
>
> The default Makefile rule looks like:
>
> $(CC) $(CFLAGS) $(LDFLAGS) $@ $^ $(LDLIBS)
>
> When linking is done by gcc itself, no issue, but when it needs to be passed
> to proper ld, only LDLIBS follows and then ld cannot know what libs to link
> with.
>
> More detail:
> https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
>
> LDFLAGS
> Extra flags to give to compilers when they are supposed to invoke the linker,
> ‘ld’, such as -L. Libraries (-lfoo) should be added to the LDLIBS variable
> instead.
>
> LDLIBS
> Library flags or names given to compilers when they are supposed to invoke the
> linker, ‘ld’. LOADLIBES is a deprecated (but still supported) alternative to
> LDLIBS. Non-library linker flags, such as -L, should go in the LDFLAGS
> variable.
>
> https://lkml.org/lkml/2010/2/10/362
>
> tools/perf: libraries must come after objects
>
> Link order matters, use LDLIBS instead of LDFLAGS to properly link against
> libpthread.
>
> Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>

Acked-by: Kees Cook <keescook@chromium.org>

Shuah, can you take this?

-Kees

> ---
>  tools/testing/selftests/seccomp/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
> index fce7f4ce0692..1760b3e39730 100644
> --- a/tools/testing/selftests/seccomp/Makefile
> +++ b/tools/testing/selftests/seccomp/Makefile
> @@ -9,7 +9,7 @@ BINARIES := seccomp_bpf seccomp_benchmark
>  CFLAGS += -Wl,-no-as-needed -Wall
>
>  seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
> -       $(CC) $(CFLAGS) $(LDFLAGS) -lpthread $< -o $@
> +       $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@
>
>  TEST_PROGS += $(BINARIES)
>  EXTRA_CLEAN := $(BINARIES)
> --
> 2.17.1
>


-- 
Kees Cook

WARNING: multiple messages have this Message-ID (diff)
From: keescook at chromium.org (Kees Cook)
Subject: [PATCH 3/4] selftests: seccomp: use LDLIBS instead of LDFLAGS
Date: Wed, 16 Jan 2019 10:13:59 -0800	[thread overview]
Message-ID: <CAGXu5j+1tOvB0jHk=kCxfhTg-PEPjCHp2TQb++wZsGxJCcQxng@mail.gmail.com> (raw)
In-Reply-To: <20190116174320.14938-3-daniel.diaz@linaro.org>

On Wed, Jan 16, 2019 at 9:44 AM Daniel Díaz <daniel.diaz at linaro.org> wrote:
>
> From: Fathi Boudra <fathi.boudra at linaro.org>
>
> seccomp_bpf fails to build due to undefined reference errors:
>
>  aarch64-linaro-linux-gcc --sysroot=/build/tmp-rpb-glibc/sysroots/hikey
>  -O2 -pipe -g -feliminate-unused-debug-types -Wl,-no-as-needed -Wall
>  -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -lpthread seccomp_bpf.c -o
>  /build/tmp-rpb-glibc/work/hikey-linaro-linux/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf
>  /tmp/ccrlR3MW.o: In function `tsync_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1920: undefined reference to `sem_post'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1920: undefined reference to `sem_post'
>  /tmp/ccrlR3MW.o: In function `TSYNC_setup':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1863: undefined reference to `sem_init'
>  /tmp/ccrlR3MW.o: In function `TSYNC_teardown':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1904: undefined reference to `sem_destroy'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1897: undefined reference to `pthread_kill'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1898: undefined reference to `pthread_cancel'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1899: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_siblings_fail_prctl':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1978: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1990: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1992: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_ancestor':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2016: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2032: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2034: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_sibling_want_nnp':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2046: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2058: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2060: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_no_filter':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2073: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2098: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2100: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_one_divergence':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2125: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2143: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2145: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_not_under_filter':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2169: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2202: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2227: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>
> It's GNU Make and linker specific.
>
> The default Makefile rule looks like:
>
> $(CC) $(CFLAGS) $(LDFLAGS) $@ $^ $(LDLIBS)
>
> When linking is done by gcc itself, no issue, but when it needs to be passed
> to proper ld, only LDLIBS follows and then ld cannot know what libs to link
> with.
>
> More detail:
> https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
>
> LDFLAGS
> Extra flags to give to compilers when they are supposed to invoke the linker,
> ‘ld’, such as -L. Libraries (-lfoo) should be added to the LDLIBS variable
> instead.
>
> LDLIBS
> Library flags or names given to compilers when they are supposed to invoke the
> linker, ‘ld’. LOADLIBES is a deprecated (but still supported) alternative to
> LDLIBS. Non-library linker flags, such as -L, should go in the LDFLAGS
> variable.
>
> https://lkml.org/lkml/2010/2/10/362
>
> tools/perf: libraries must come after objects
>
> Link order matters, use LDLIBS instead of LDFLAGS to properly link against
> libpthread.
>
> Signed-off-by: Fathi Boudra <fathi.boudra at linaro.org>

Acked-by: Kees Cook <keescook at chromium.org>

Shuah, can you take this?

-Kees

> ---
>  tools/testing/selftests/seccomp/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
> index fce7f4ce0692..1760b3e39730 100644
> --- a/tools/testing/selftests/seccomp/Makefile
> +++ b/tools/testing/selftests/seccomp/Makefile
> @@ -9,7 +9,7 @@ BINARIES := seccomp_bpf seccomp_benchmark
>  CFLAGS += -Wl,-no-as-needed -Wall
>
>  seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
> -       $(CC) $(CFLAGS) $(LDFLAGS) -lpthread $< -o $@
> +       $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@
>
>  TEST_PROGS += $(BINARIES)
>  EXTRA_CLEAN := $(BINARIES)
> --
> 2.17.1
>


-- 
Kees Cook

WARNING: multiple messages have this Message-ID (diff)
From: keescook@chromium.org (Kees Cook)
Subject: [PATCH 3/4] selftests: seccomp: use LDLIBS instead of LDFLAGS
Date: Wed, 16 Jan 2019 10:13:59 -0800	[thread overview]
Message-ID: <CAGXu5j+1tOvB0jHk=kCxfhTg-PEPjCHp2TQb++wZsGxJCcQxng@mail.gmail.com> (raw)
Message-ID: <20190116181359.c9JmmU74k1Vt1z8U-P2BtS7GzW6y22eshEBuAdp7JuY@z> (raw)
In-Reply-To: <20190116174320.14938-3-daniel.diaz@linaro.org>

On Wed, Jan 16, 2019@9:44 AM Daniel Díaz <daniel.diaz@linaro.org> wrote:
>
> From: Fathi Boudra <fathi.boudra at linaro.org>
>
> seccomp_bpf fails to build due to undefined reference errors:
>
>  aarch64-linaro-linux-gcc --sysroot=/build/tmp-rpb-glibc/sysroots/hikey
>  -O2 -pipe -g -feliminate-unused-debug-types -Wl,-no-as-needed -Wall
>  -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -lpthread seccomp_bpf.c -o
>  /build/tmp-rpb-glibc/work/hikey-linaro-linux/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf
>  /tmp/ccrlR3MW.o: In function `tsync_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1920: undefined reference to `sem_post'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1920: undefined reference to `sem_post'
>  /tmp/ccrlR3MW.o: In function `TSYNC_setup':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1863: undefined reference to `sem_init'
>  /tmp/ccrlR3MW.o: In function `TSYNC_teardown':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1904: undefined reference to `sem_destroy'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1897: undefined reference to `pthread_kill'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1898: undefined reference to `pthread_cancel'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1899: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_siblings_fail_prctl':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1978: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1990: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1992: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_ancestor':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2016: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2032: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2034: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_sibling_want_nnp':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2046: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2058: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2060: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_no_filter':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2073: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2098: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2100: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_with_one_divergence':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2125: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2143: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2145: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>  /tmp/ccrlR3MW.o: In function `TSYNC_two_siblings_not_under_filter':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2169: undefined reference to `sem_wait'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2202: undefined reference to `pthread_join'
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:2227: undefined reference to `pthread_join'
>  /tmp/ccrlR3MW.o: In function `tsync_start_sibling':
>  /usr/src/debug/kselftests/4.12-r0/linux-4.12-rc7/tools/testing/selftests/seccomp/seccomp_bpf.c:1941: undefined reference to `pthread_create'
>
> It's GNU Make and linker specific.
>
> The default Makefile rule looks like:
>
> $(CC) $(CFLAGS) $(LDFLAGS) $@ $^ $(LDLIBS)
>
> When linking is done by gcc itself, no issue, but when it needs to be passed
> to proper ld, only LDLIBS follows and then ld cannot know what libs to link
> with.
>
> More detail:
> https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
>
> LDFLAGS
> Extra flags to give to compilers when they are supposed to invoke the linker,
> ‘ld’, such as -L. Libraries (-lfoo) should be added to the LDLIBS variable
> instead.
>
> LDLIBS
> Library flags or names given to compilers when they are supposed to invoke the
> linker, ‘ld’. LOADLIBES is a deprecated (but still supported) alternative to
> LDLIBS. Non-library linker flags, such as -L, should go in the LDFLAGS
> variable.
>
> https://lkml.org/lkml/2010/2/10/362
>
> tools/perf: libraries must come after objects
>
> Link order matters, use LDLIBS instead of LDFLAGS to properly link against
> libpthread.
>
> Signed-off-by: Fathi Boudra <fathi.boudra at linaro.org>

Acked-by: Kees Cook <keescook at chromium.org>

Shuah, can you take this?

-Kees

> ---
>  tools/testing/selftests/seccomp/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
> index fce7f4ce0692..1760b3e39730 100644
> --- a/tools/testing/selftests/seccomp/Makefile
> +++ b/tools/testing/selftests/seccomp/Makefile
> @@ -9,7 +9,7 @@ BINARIES := seccomp_bpf seccomp_benchmark
>  CFLAGS += -Wl,-no-as-needed -Wall
>
>  seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
> -       $(CC) $(CFLAGS) $(LDFLAGS) -lpthread $< -o $@
> +       $(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@
>
>  TEST_PROGS += $(BINARIES)
>  EXTRA_CLEAN := $(BINARIES)
> --
> 2.17.1
>


-- 
Kees Cook

  reply	other threads:[~2019-01-16 18:14 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 17:43 [PATCH 1/4] selftests: lib: allow to override CC in the top-level Makefile Daniel Díaz
2019-01-16 17:43 ` Daniel Díaz
2019-01-16 17:43 ` 
2019-01-16 17:43 ` [PATCH 2/4] selftests: net: use LDLIBS instead of LDFLAGS Daniel Díaz
2019-01-16 17:43   ` Daniel Díaz
2019-01-16 17:43   ` 
2019-01-16 17:43 ` [PATCH 3/4] selftests: seccomp: " Daniel Díaz
2019-01-16 17:43   ` Daniel Díaz
2019-01-16 17:43   ` 
2019-01-16 18:13   ` Kees Cook [this message]
2019-01-16 18:13     ` Kees Cook
2019-01-16 18:13     ` keescook
2019-01-16 18:26     ` shuah
2019-01-16 18:26       ` shuah
2019-01-16 18:26       ` shuah
2019-01-16 17:43 ` [PATCH 4/4] selftests: timers: " Daniel Díaz
2019-01-16 17:43   ` Daniel Díaz
2019-01-16 17:43   ` 
2019-01-16 21:56 ` [PATCH 1/4] selftests: lib: allow to override CC in the top-level Makefile shuah
2019-01-16 21:56   ` shuah
2019-01-16 21:56   ` shuah
2019-01-18 17:54   ` Daniel Díaz
2019-01-18 17:54     ` Daniel Díaz
2019-01-18 17:54     ` 
2019-01-28 15:01     ` shuah
2019-01-28 15:01       ` shuah
2019-01-28 15:01       ` shuah
2019-01-28 15:42       ` Denys Dmytriyenko
2019-01-28 15:42         ` Denys Dmytriyenko
2019-01-28 15:42         ` denys
2019-01-28 16:28         ` shuah
2019-01-28 16:28           ` shuah
2019-01-28 16:28           ` shuah
2019-01-28 17:01           ` Daniel Díaz
2019-01-28 17:01             ` Daniel Díaz
2019-01-28 17:01             ` 

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGXu5j+1tOvB0jHk=kCxfhTg-PEPjCHp2TQb++wZsGxJCcQxng@mail.gmail.com' \
    --to=keescook@chromium.org \
    --cc=daniel.diaz@linaro.org \
    --cc=fathi.boudra@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=shuah@kernel.org \
    --cc=wad@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.