BPF List
 help / color / mirror / Atom feed
From: Quentin Monnet <qmo@kernel.org>
To: Viktor Malik <vmalik@redhat.com>, bpf@vger.kernel.org
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Mykola Lysenko <mykolal@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>
Subject: Re: [PATCH bpf-next 2/3] bpftool: Prevent setting duplicate _GNU_SOURCE in Makefile
Date: Tue, 15 Oct 2024 11:03:53 +0100	[thread overview]
Message-ID: <13c4f2dd-e315-4d0e-9481-b385946c33dc@kernel.org> (raw)
In-Reply-To: <507d699068777b78a5720e617c99fb19a9bb8a89.1728975031.git.vmalik@redhat.com>

2024-10-15 08:54 UTC+0200 ~ Viktor Malik <vmalik@redhat.com>
> When building selftests with CFLAGS set via env variable, the value of
> CFLAGS is propagated into bpftool Makefile (called from selftests
> Makefile). This makes the compilation fail as _GNU_SOURCE is defined two
> times - once from selftests Makefile (by including lib.mk) and once from
> bpftool Makefile (by calling `llvm-config --cflags`):
> 
>      $ CFLAGS="" make -C tools/testing/selftests/bpf
>      [...]
>      CC      /bpf-next/tools/testing/selftests/bpf/tools/build/bpftool/btf.o
>      <command-line>: error: "_GNU_SOURCE" redefined [-Werror]
>      <command-line>: note: this is the location of the previous definition
>      cc1: all warnings being treated as errors
>      [...]
> 
> Let bpftool Makefile check if _GNU_SOURCE is already defined and if so,
> do not let llvm-config add it again.
> 
> Signed-off-by: Viktor Malik <vmalik@redhat.com>
> ---
>   tools/bpf/bpftool/Makefile | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index ba927379eb20..2b5a713d71d8 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -147,7 +147,13 @@ ifeq ($(feature-llvm),1)
>     # If LLVM is available, use it for JIT disassembly
>     CFLAGS  += -DHAVE_LLVM_SUPPORT
>     LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets
> -  CFLAGS  += $(shell $(LLVM_CONFIG) --cflags)
> +  # When bpftool build is called from another Makefile which already sets
> +  # -D_GNU_SOURCE, do not let llvm-config add it again as it will cause conflict.


Thanks! Can you please make your comment more explicit and mention the 
file tools/testing/selftests/lib.mk and/or the use case addressed 
(building bpftool from selftests), given that you match on the exact 
string "-D_GNU_SOURCE="? Your check won't skip adding the duplicate 
definition if someone passes "-D_GNU_SOURCE", without the "=", by 
calling the Makefile from another path; that's fine, but I don't want 
users to read the Makefile and expect it to remove the second definition 
in such a case.


> +  ifneq ($(filter -D_GNU_SOURCE=,$(CFLAGS)),)
> +    CFLAGS += $(filter-out -D_GNU_SOURCE,$(shell $(LLVM_CONFIG) --cflags))
> +  else
> +    CFLAGS += $(shell $(LLVM_CONFIG) --cflags)
> +  endif

Looks good otherwise:

Reviewed-by: Quentin Monnet <qmo@kernel.org>

  reply	other threads:[~2024-10-15 10:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15  6:54 [PATCH bpf-next 0/3] selftests/bpf: Improve building with extra Viktor Malik
2024-10-15  6:54 ` [PATCH bpf-next 1/3] selftests/bpf: Allow building with extra flags Viktor Malik
2024-10-16 23:17   ` Eduard Zingerman
2024-10-17  7:29     ` Viktor Malik
2024-10-15  6:54 ` [PATCH bpf-next 2/3] bpftool: Prevent setting duplicate _GNU_SOURCE in Makefile Viktor Malik
2024-10-15 10:03   ` Quentin Monnet [this message]
2024-10-15 10:17     ` Viktor Malik
2024-10-16 20:34   ` Andrii Nakryiko
2024-10-17  6:08     ` Viktor Malik
2024-10-15  6:54 ` [PATCH bpf-next 3/3] selftests/bpf: Allow ignoring some flags for Clang builds Viktor Malik
2024-10-16 20:37   ` Andrii Nakryiko
2024-10-16 22:18     ` Eduard Zingerman
2024-10-17  8:34       ` Viktor Malik

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=13c4f2dd-e315-4d0e-9481-b385946c33dc@kernel.org \
    --to=qmo@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=morbo@google.com \
    --cc=mykolal@fb.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=vmalik@redhat.com \
    --cc=yonghong.song@linux.dev \
    /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