diff mbox series

[01/13] selftests: filter kselftest headers from command in lib.mk

Message ID 20201008122633.687877-2-tommi.t.rantala@nokia.com
State Accepted
Headers show
Series selftests fixes | expand

Commit Message

Tommi Rantala Oct. 8, 2020, 12:26 p.m. UTC
Commit 1056d3d2c97e ("selftests: enforce local header dependency in
lib.mk") added header dependency to the rule, but as the rule uses $^,
the headers are added to the compiler command line.

This can cause unexpected precompiled header files being generated when
compilation fails:

  $ echo { >> openat2_test.c

  $ make
  gcc -Wall -O2 -g -fsanitize=address -fsanitize=undefined  openat2_test.c
    tools/testing/selftests/kselftest_harness.h tools/testing/selftests/kselftest.h helpers.c
    -o tools/testing/selftests/openat2/openat2_test
  openat2_test.c:313:1: error: expected identifier or ‘(’ before ‘{’ token
    313 | {
        | ^
  make: *** [../lib.mk:140: tools/testing/selftests/openat2/openat2_test] Error 1

  $ file openat2_test*
  openat2_test:   GCC precompiled header (version 014) for C
  openat2_test.c: C source, ASCII text

Fix it by filtering out the headers, so that we'll only pass the actual
*.c files in the compiler command line.

Fixes: 1056d3d2c97e ("selftests: enforce local header dependency in lib.mk")
Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
---
 tools/testing/selftests/lib.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kees Cook Oct. 8, 2020, 8:05 p.m. UTC | #1
On Thu, Oct 08, 2020 at 03:26:21PM +0300, Tommi Rantala wrote:
> Commit 1056d3d2c97e ("selftests: enforce local header dependency in
> lib.mk") added header dependency to the rule, but as the rule uses $^,
> the headers are added to the compiler command line.
> 
> This can cause unexpected precompiled header files being generated when
> compilation fails:
> 
>   $ echo { >> openat2_test.c
> 
>   $ make
>   gcc -Wall -O2 -g -fsanitize=address -fsanitize=undefined  openat2_test.c
>     tools/testing/selftests/kselftest_harness.h tools/testing/selftests/kselftest.h helpers.c
>     -o tools/testing/selftests/openat2/openat2_test
>   openat2_test.c:313:1: error: expected identifier or ‘(’ before ‘{’ token
>     313 | {
>         | ^
>   make: *** [../lib.mk:140: tools/testing/selftests/openat2/openat2_test] Error 1
> 
>   $ file openat2_test*
>   openat2_test:   GCC precompiled header (version 014) for C
>   openat2_test.c: C source, ASCII text
> 
> Fix it by filtering out the headers, so that we'll only pass the actual
> *.c files in the compiler command line.
> 
> Fixes: 1056d3d2c97e ("selftests: enforce local header dependency in lib.mk")
> Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>

Ah yes, thanks!

Acked-by: Kees Cook <keescook@chromium.org>
Christian Brauner Oct. 9, 2020, 12:06 p.m. UTC | #2
On Thu, Oct 08, 2020 at 03:26:21PM +0300, Tommi Rantala wrote:
> Commit 1056d3d2c97e ("selftests: enforce local header dependency in
> lib.mk") added header dependency to the rule, but as the rule uses $^,
> the headers are added to the compiler command line.
> 
> This can cause unexpected precompiled header files being generated when
> compilation fails:
> 
>   $ echo { >> openat2_test.c
> 
>   $ make
>   gcc -Wall -O2 -g -fsanitize=address -fsanitize=undefined  openat2_test.c
>     tools/testing/selftests/kselftest_harness.h tools/testing/selftests/kselftest.h helpers.c
>     -o tools/testing/selftests/openat2/openat2_test
>   openat2_test.c:313:1: error: expected identifier or ‘(’ before ‘{’ token
>     313 | {
>         | ^
>   make: *** [../lib.mk:140: tools/testing/selftests/openat2/openat2_test] Error 1
> 
>   $ file openat2_test*
>   openat2_test:   GCC precompiled header (version 014) for C
>   openat2_test.c: C source, ASCII text
> 
> Fix it by filtering out the headers, so that we'll only pass the actual
> *.c files in the compiler command line.
> 
> Fixes: 1056d3d2c97e ("selftests: enforce local header dependency in lib.mk")
> Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
> ---

Thanks!
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 7a17ea815736..66f3317dc365 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -137,7 +137,7 @@  endif
 ifeq ($(OVERRIDE_TARGETS),)
 LOCAL_HDRS := $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
 $(OUTPUT)/%:%.c $(LOCAL_HDRS)
-	$(LINK.c) $^ $(LDLIBS) -o $@
+	$(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@
 
 $(OUTPUT)/%.o:%.S
 	$(COMPILE.S) $^ -o $@