netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: Shuah Khan <skhan@linuxfoundation.org>,
	shuah@kernel.org, keescook@chromium.org, luto@amacapital.net,
	wad@chromium.org, daniel@iogearbox.net, kafai@fb.com, yhs@fb.com,
	andriin@fb.com, gregkh@linuxfoundation.org, tglx@linutronix.de
Cc: Shuah Khan <skhan@linuxfoundation.org>,
	khilman@baylibre.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH v3] selftests: Fix seccomp to support relocatable build (O=objdir)
Date: Mon, 16 Mar 2020 23:12:57 +1100	[thread overview]
Message-ID: <8736a8qz06.fsf@mpe.ellerman.id.au> (raw)
In-Reply-To: <20200313212404.24552-1-skhan@linuxfoundation.org>

Shuah Khan <skhan@linuxfoundation.org> writes:
> Fix seccomp relocatable builds. This is a simple fix to use the right
> lib.mk variable TEST_GEN_PROGS with dependency on kselftest_harness.h
> header, and defining LDFLAGS for pthread lib.
>
> Removes custom clean rule which is no longer necessary with the use of
> TEST_GEN_PROGS. 
>
> Uses $(OUTPUT) defined in lib.mk to handle build relocation.
>
> The following use-cases work with this change:
>
> In seccomp directory:
> make all and make clean
>
> From top level from main Makefile:
> make kselftest-install O=objdir ARCH=arm64 HOSTCC=gcc \
>  CROSS_COMPILE=aarch64-linux-gnu- TARGETS=seccomp
>
> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
> ---
>
> Changes since v2:
> -- Using TEST_GEN_PROGS is sufficient to generate objects.
>    Addresses review comments from Kees Cook.
>
>  tools/testing/selftests/seccomp/Makefile | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/tools/testing/selftests/seccomp/Makefile b/tools/testing/selftests/seccomp/Makefile
> index 1760b3e39730..a0388fd2c3f2 100644
> --- a/tools/testing/selftests/seccomp/Makefile
> +++ b/tools/testing/selftests/seccomp/Makefile
> @@ -1,17 +1,15 @@
>  # SPDX-License-Identifier: GPL-2.0
> -all:
> -
> -include ../lib.mk
> +CFLAGS += -Wl,-no-as-needed -Wall
> +LDFLAGS += -lpthread
>  
>  .PHONY: all clean
>  
> -BINARIES := seccomp_bpf seccomp_benchmark
> -CFLAGS += -Wl,-no-as-needed -Wall
> +include ../lib.mk
> +
> +# OUTPUT set by lib.mk
> +TEST_GEN_PROGS := $(OUTPUT)/seccomp_bpf $(OUTPUT)/seccomp_benchmark
>  
> -seccomp_bpf: seccomp_bpf.c ../kselftest_harness.h
> -	$(CC) $(CFLAGS) $(LDFLAGS) $< -lpthread -o $@
> +$(TEST_GEN_PROGS): ../kselftest_harness.h
>  
> -TEST_PROGS += $(BINARIES)
> -EXTRA_CLEAN := $(BINARIES)
> +all: $(TEST_GEN_PROGS)
>  
> -all: $(BINARIES)


It shouldn't be that complicated. We just need to define TEST_GEN_PROGS
before including lib.mk, and then add the dependency on the harness
after we include lib.mk (so that TEST_GEN_PROGS has been updated to
prefix $(OUTPUT)).

eg:

  # SPDX-License-Identifier: GPL-2.0
  CFLAGS += -Wl,-no-as-needed -Wall
  LDFLAGS += -lpthread
  
  TEST_GEN_PROGS := seccomp_bpf seccomp_benchmark
  
  include ../lib.mk
  
  $(TEST_GEN_PROGS): ../kselftest_harness.h


Normal in-tree build:

  selftests$ make TARGETS=seccomp
  make[1]: Entering directory '/home/michael/linux/tools/testing/selftests/seccomp'
  gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_bpf.c ../kselftest_harness.h  -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_bpf
  gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_benchmark.c ../kselftest_harness.h  -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_benchmark
  make[1]: Leaving directory '/home/michael/linux/tools/testing/selftests/seccomp'
  
  selftests$ ls -l seccomp/
  total 388
  -rw-rw-r-- 1 michael michael     41 Jan  9 12:00 config
  -rw-rw-r-- 1 michael michael    201 Mar 16 23:04 Makefile
  -rwxrwxr-x 1 michael michael  70824 Mar 16 23:07 seccomp_benchmark*
  -rw-rw-r-- 1 michael michael   2289 Feb 17 21:39 seccomp_benchmark.c
  -rwxrwxr-x 1 michael michael 290520 Mar 16 23:07 seccomp_bpf*
  -rw-rw-r-- 1 michael michael  94778 Mar  5 23:33 seccomp_bpf.c


O= build:

  selftests$ make TARGETS=seccomp O=$PWD/build
  make[1]: Entering directory '/home/michael/linux/tools/testing/selftests/seccomp'
  gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_bpf.c ../kselftest_harness.h  -o /home/michael/linux/tools/testing/selftests/build/seccomp/seccomp_bpf
  gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_benchmark.c ../kselftest_harness.h  -o /home/michael/linux/tools/testing/selftests/build/seccomp/seccomp_benchmark
  make[1]: Leaving directory '/home/michael/linux/tools/testing/selftests/seccomp'
  
  selftests$ ls -l build/seccomp/
  total 280
  -rwxrwxr-x 1 michael michael  70824 Mar 16 23:05 seccomp_benchmark*
  -rwxrwxr-x 1 michael michael 290520 Mar 16 23:05 seccomp_bpf*


Build in the directory itself:
  selftests$ cd seccomp
  seccomp$ make
  gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_bpf.c ../kselftest_harness.h  -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_bpf
  gcc -Wl,-no-as-needed -Wall  -lpthread  seccomp_benchmark.c ../kselftest_harness.h  -o /home/michael/linux/tools/testing/selftests/seccomp/seccomp_benchmark
  
  seccomp$ ls -l
  total 388
  -rw-rw-r-- 1 michael michael     41 Jan  9 12:00 config
  -rw-rw-r-- 1 michael michael    201 Mar 16 23:04 Makefile
  -rwxrwxr-x 1 michael michael  70824 Mar 16 23:06 seccomp_benchmark*
  -rw-rw-r-- 1 michael michael   2289 Feb 17 21:39 seccomp_benchmark.c
  -rwxrwxr-x 1 michael michael 290520 Mar 16 23:06 seccomp_bpf*
  -rw-rw-r-- 1 michael michael  94778 Mar  5 23:33 seccomp_bpf.c


cheers

  parent reply	other threads:[~2020-03-16 12:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-13 21:24 [PATCH v3] selftests: Fix seccomp to support relocatable build (O=objdir) Shuah Khan
2020-03-13 23:18 ` Kees Cook
2020-03-13 23:38   ` Shuah Khan
2020-03-16 12:12 ` Michael Ellerman [this message]
2020-03-16 21:05   ` Kees Cook
2020-03-19  3:15     ` Michael Ellerman
2020-03-23 20:18       ` Shuah Khan
2020-03-23 20:50         ` Kees Cook

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=8736a8qz06.fsf@mpe.ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=andriin@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=kafai@fb.com \
    --cc=keescook@chromium.org \
    --cc=khilman@baylibre.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=netdev@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tglx@linutronix.de \
    --cc=wad@chromium.org \
    --cc=yhs@fb.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).