diff mbox series

[2/4] selftests: Fix seccomp to support relocatable build (O=objdir)

Message ID 11967e5f164f0cd717921bd382ff9c13ef740146.1583358715.git.skhan@linuxfoundation.org
State Not Applicable
Delegated to: David Miller
Headers show
Series Kselftest integration into Kernel CI - Part 1 | expand

Commit Message

Shuah Khan March 4, 2020, 10:13 p.m. UTC
Fix seccomp relocatable builds. This is a simple fix to use the
right lib.mk variable TEST_GEN_PROGS for objects to leverage
lib.mk common framework for relocatable builds.

Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
 tools/testing/selftests/seccomp/Makefile | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

Comments

Kees Cook March 4, 2020, 10:42 p.m. UTC | #1
On Wed, Mar 04, 2020 at 03:13:33PM -0700, Shuah Khan wrote:
> Fix seccomp relocatable builds. This is a simple fix to use the
> right lib.mk variable TEST_GEN_PROGS for objects to leverage
> lib.mk common framework for relocatable builds.
> 
> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
> ---
>  tools/testing/selftests/seccomp/Makefile | 16 +++-------------
>  1 file changed, 3 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
> index 1760b3e39730..a8a9717fc1be 100644
> --- a/tools/testing/selftests/seccomp/Makefile
> +++ b/tools/testing/selftests/seccomp/Makefile
> @@ -1,17 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0
> -all:
> -
> -include ../lib.mk
> -
> -.PHONY: all clean
> -
> -BINARIES := seccomp_bpf seccomp_benchmark
>  CFLAGS += -Wl,-no-as-needed -Wall
> +LDFLAGS += -lpthread
>  
> -seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h

How is the ../kselftest_harness.h dependency detected in the resulting
build rules?

Otherwise, looks good.

-Kees

> -	$(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@
> -
> -TEST_PROGS += $(BINARIES)
> -EXTRA_CLEAN := $(BINARIES)
> +TEST_GEN_PROGS := seccomp_bpf seccomp_benchmark
>  
> -all: $(BINARIES)
> +include ../lib.mk
> -- 
> 2.20.1
>
Shuah Khan March 4, 2020, 11:15 p.m. UTC | #2
On 3/4/20 3:42 PM, Kees Cook wrote:
> On Wed, Mar 04, 2020 at 03:13:33PM -0700, Shuah Khan wrote:
>> Fix seccomp relocatable builds. This is a simple fix to use the
>> right lib.mk variable TEST_GEN_PROGS for objects to leverage
>> lib.mk common framework for relocatable builds.
>>
>> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
>> ---
>>   tools/testing/selftests/seccomp/Makefile | 16 +++-------------
>>   1 file changed, 3 insertions(+), 13 deletions(-)
>>
>> diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
>> index 1760b3e39730..a8a9717fc1be 100644
>> --- a/tools/testing/selftests/seccomp/Makefile
>> +++ b/tools/testing/selftests/seccomp/Makefile
>> @@ -1,17 +1,7 @@
>>   # SPDX-License-Identifier: GPL-2.0
>> -all:
>> -
>> -include ../lib.mk
>> -
>> -.PHONY: all clean
>> -
>> -BINARIES := seccomp_bpf seccomp_benchmark
>>   CFLAGS += -Wl,-no-as-needed -Wall
>> +LDFLAGS += -lpthread
>>   
>> -seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
> 
> How is the ../kselftest_harness.h dependency detected in the resulting
> build rules?
> 
> Otherwise, looks good.

Didn't see any problems. I will look into adding the dependency.

thanks,
-- Shuah
Michael Ellerman March 5, 2020, 12:22 a.m. UTC | #3
Shuah Khan <skhan@linuxfoundation.org> writes:
> On 3/4/20 3:42 PM, Kees Cook wrote:
>> On Wed, Mar 04, 2020 at 03:13:33PM -0700, Shuah Khan wrote:
>>> Fix seccomp relocatable builds. This is a simple fix to use the
>>> right lib.mk variable TEST_GEN_PROGS for objects to leverage
>>> lib.mk common framework for relocatable builds.
>>>
>>> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
>>> ---
>>>   tools/testing/selftests/seccomp/Makefile | 16 +++-------------
>>>   1 file changed, 3 insertions(+), 13 deletions(-)
>>>
>>> diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
>>> index 1760b3e39730..a8a9717fc1be 100644
>>> --- a/tools/testing/selftests/seccomp/Makefile
>>> +++ b/tools/testing/selftests/seccomp/Makefile
>>> @@ -1,17 +1,7 @@
>>>   # SPDX-License-Identifier: GPL-2.0
>>> -all:
>>> -
>>> -include ../lib.mk
>>> -
>>> -.PHONY: all clean
>>> -
>>> -BINARIES := seccomp_bpf seccomp_benchmark
>>>   CFLAGS += -Wl,-no-as-needed -Wall
>>> +LDFLAGS += -lpthread
>>>   
>>> -seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
>> 
>> How is the ../kselftest_harness.h dependency detected in the resulting
>> build rules?
>> 
>> Otherwise, looks good.
>
> Didn't see any problems. I will look into adding the dependency.

Before:

  $ make --no-print-directory -C tools/testing/selftests/ TARGETS=seccomp
  make --no-builtin-rules INSTALL_HDR_PATH=$BUILD/usr \
          ARCH=powerpc -C ../../.. headers_install
    INSTALL /home/michael/build/adhoc/kselftest/usr/include
  gcc -Wl,-no-as-needed -Wall  seccomp_bpf.c -lpthread -o seccomp_bpf
  gcc -Wl,-no-as-needed -Wall    seccomp_benchmark.c   -o seccomp_benchmark
  
  $ touch tools/testing/selftests/kselftest_harness.h
  
  $ make --no-print-directory -C tools/testing/selftests/ TARGETS=seccomp
  make --no-builtin-rules INSTALL_HDR_PATH=$BUILD/usr \
          ARCH=powerpc -C ../../.. headers_install
    INSTALL /home/michael/build/adhoc/kselftest/usr/include
  gcc -Wl,-no-as-needed -Wall  seccomp_bpf.c -lpthread -o seccomp_bpf
  $

Note that touching the header causes it to rebuild seccomp_bpf.

With this patch applied:

  $ make --no-print-directory -C tools/testing/selftests/ TARGETS=seccomp
  make -s --no-builtin-rules INSTALL_HDR_PATH=$BUILD/usr \
          ARCH=powerpc -C ../../.. headers_install
  gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_bpf.c  -o /home/michael/build/adhoc/kselftest/seccomp/seccomp_bpf
  gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_benchmark.c  -o /home/michael/build/adhoc/kselftest/seccomp/seccomp_benchmark
  
  $ touch tools/testing/selftests/kselftest_harness.h
  
  $ make --no-print-directory -C tools/testing/selftests/ TARGETS=seccomp
  make -s --no-builtin-rules INSTALL_HDR_PATH=$BUILD/usr \
          ARCH=powerpc -C ../../.. headers_install
  make[1]: Nothing to be done for 'all'.
  $


So yeah it still needs:

seccomp_bpf: ../kselftest_harness.h


cheers
Shuah Khan March 5, 2020, 12:29 a.m. UTC | #4
On 3/4/20 5:22 PM, Michael Ellerman wrote:
> Shuah Khan <skhan@linuxfoundation.org> writes:
>> On 3/4/20 3:42 PM, Kees Cook wrote:
>>> On Wed, Mar 04, 2020 at 03:13:33PM -0700, Shuah Khan wrote:
>>>> Fix seccomp relocatable builds. This is a simple fix to use the
>>>> right lib.mk variable TEST_GEN_PROGS for objects to leverage
>>>> lib.mk common framework for relocatable builds.
>>>>
>>>> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
>>>> ---
>>>>    tools/testing/selftests/seccomp/Makefile | 16 +++-------------
>>>>    1 file changed, 3 insertions(+), 13 deletions(-)
>>>>
>>>> diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
>>>> index 1760b3e39730..a8a9717fc1be 100644
>>>> --- a/tools/testing/selftests/seccomp/Makefile
>>>> +++ b/tools/testing/selftests/seccomp/Makefile
>>>> @@ -1,17 +1,7 @@
>>>>    # SPDX-License-Identifier: GPL-2.0
>>>> -all:
>>>> -
>>>> -include ../lib.mk
>>>> -
>>>> -.PHONY: all clean
>>>> -
>>>> -BINARIES := seccomp_bpf seccomp_benchmark
>>>>    CFLAGS += -Wl,-no-as-needed -Wall
>>>> +LDFLAGS += -lpthread
>>>>    
>>>> -seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
>>>
>>> How is the ../kselftest_harness.h dependency detected in the resulting
>>> build rules?
>>>
>>> Otherwise, looks good.
>>
>> Didn't see any problems. I will look into adding the dependency.
> 
> Before:
> 
>    $ make --no-print-directory -C tools/testing/selftests/ TARGETS=seccomp
>    make --no-builtin-rules INSTALL_HDR_PATH=$BUILD/usr \
>            ARCH=powerpc -C ../../.. headers_install
>      INSTALL /home/michael/build/adhoc/kselftest/usr/include
>    gcc -Wl,-no-as-needed -Wall  seccomp_bpf.c -lpthread -o seccomp_bpf
>    gcc -Wl,-no-as-needed -Wall    seccomp_benchmark.c   -o seccomp_benchmark
>    
>    $ touch tools/testing/selftests/kselftest_harness.h
>    
>    $ make --no-print-directory -C tools/testing/selftests/ TARGETS=seccomp
>    make --no-builtin-rules INSTALL_HDR_PATH=$BUILD/usr \
>            ARCH=powerpc -C ../../.. headers_install
>      INSTALL /home/michael/build/adhoc/kselftest/usr/include
>    gcc -Wl,-no-as-needed -Wall  seccomp_bpf.c -lpthread -o seccomp_bpf
>    $
> 
> Note that touching the header causes it to rebuild seccomp_bpf.
> 
> With this patch applied:
> 
>    $ make --no-print-directory -C tools/testing/selftests/ TARGETS=seccomp
>    make -s --no-builtin-rules INSTALL_HDR_PATH=$BUILD/usr \
>            ARCH=powerpc -C ../../.. headers_install
>    gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_bpf.c  -o /home/michael/build/adhoc/kselftest/seccomp/seccomp_bpf
>    gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_benchmark.c  -o /home/michael/build/adhoc/kselftest/seccomp/seccomp_benchmark
>    
>    $ touch tools/testing/selftests/kselftest_harness.h
>    
>    $ make --no-print-directory -C tools/testing/selftests/ TARGETS=seccomp
>    make -s --no-builtin-rules INSTALL_HDR_PATH=$BUILD/usr \
>            ARCH=powerpc -C ../../.. headers_install
>    make[1]: Nothing to be done for 'all'.
>    $
> 
> 

Thanks. I realized I overlooked header dependency case.

> So yeah it still needs:
> 
> seccomp_bpf: ../kselftest_harness.h
> 
> 
Yes v2 coming up. It also has to handle OUTPUT relocation.

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
index 1760b3e39730..a8a9717fc1be 100644
--- a/tools/testing/selftests/seccomp/Makefile
+++ b/tools/testing/selftests/seccomp/Makefile
@@ -1,17 +1,7 @@ 
 # SPDX-License-Identifier: GPL-2.0
-all:
-
-include ../lib.mk
-
-.PHONY: all clean
-
-BINARIES := seccomp_bpf seccomp_benchmark
 CFLAGS += -Wl,-no-as-needed -Wall
+LDFLAGS += -lpthread
 
-seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
-	$(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@
-
-TEST_PROGS += $(BINARIES)
-EXTRA_CLEAN := $(BINARIES)
+TEST_GEN_PROGS := seccomp_bpf seccomp_benchmark
 
-all: $(BINARIES)
+include ../lib.mk