Skip to content

bpf: tools: support build selftests/bpf with clang

Yonghong Song bpf 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest5 patches 12 repliesIn review
  2. v25 patches 19 repliesSuperseded
  3. v15 patches 24 repliesSuperseded

Changes in v3 from the cover letter

. more test environment description in cover letter. (Sedat) . use a different fix, but similar to other use in selftests/bpf
Makefile, to exclude header files from CXX compilation command line. (Andrii)
. fix codes instead of adding -Wno-format-security. (Andrii)

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5selftests: set CC to clang in lib.mk if LLVM is settools/testing/selftests/lib.mk+4 -05 replies
2/5tools: allow proper CC/CXX/... override with LLVM=1 in Makefile.includetools/scripts/Makefile.include+10 -20 replies
3/5selftests/bpf: fix test_cpp compilation failure with clangtools/testing/selftests/bpf/Makefile+1 -11 reply
4/5selftests/bpf: silence clang compilation warningstools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/prog_tests/fexit_sleep.c tools/testing/selftests/bpf/prog_tests/ns_current_pid_tgid.c+9 -43 replies
5/5bpftool: fix a clang compilation warningtools/bpf/bpftool/net.c+1 -10 replies

Reviews trailers per patch

4 of 5 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchAndrii NakryikoMartin KaFai Lau
SeriesA-b
1/5A-b
2/5
3/5A-b
4/5A-b
5/5A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH bpf-next v3 0/5] bpf: tools: support build selftests/bpf with clang

To build kernel with clang, people typically use
make -j60 LLVM=1 LLVM_IAS=1
LLVM_IAS=1 is not required for non-LTO build but
is required for LTO build. In my environment,
I am always having LLVM_IAS=1 regardless of
whether LTO is enabled or not.

After kernel is build with clang, the following command can be used to build selftests with clang:
make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1

I am using latest bpf-next kernel code base and
latest clang built from source from
https://github.com/llvm/llvm-project.git
Using earlier version of llvm may have compilation errors, see
tools/testing/selftests/bpf
due to continuous development in llvm bpf features and selftests to use these features.

To run bpf selftest properly, you need have certain necessary kernel configs like at:
bpf-next:tools/testing/selftests/bpf/config
(not that this is not a complete .config file and some other configs
might still be needed.)

Currently, using the above command, some compilations still use gcc and there are also compilation errors and warnings. This patch set intends to fix these issues.
Patch #1 and #2 fixed the issue so clang/clang++ is used instead of gcc/g++. Patch #3 fixed a compilation failure. Patch #4 and #5 fixed various compiler warnings.

Changelog:
v2 -> v3:
. more test environment description in cover letter. (Sedat) . use a different fix, but similar to other use in selftests/bpf
Makefile, to exclude header files from CXX compilation command line. (Andrii)
. fix codes instead of adding -Wno-format-security. (Andrii)
v1 -> v2:
. add -Wno-unused-command-line-argument and -Wno-format-security
for clang only as (1). gcc does not exhibit those warnings, and (2). -Wno-unused-command-line-argument is only supported by clang. (Sedat)

Yonghong Song (5):
selftests: set CC to clang in lib.mk if LLVM is set
tools: allow proper CC/CXX/... override with LLVM=1 in
Makefile.include
selftests/bpf: fix test_cpp compilation failure with clang selftests/bpf: silence clang compilation warnings
bpftool: fix a clang compilation warning

 tools/bpf/bpftool/net.c                              |  2 +-
 tools/scripts/Makefile.include                       | 12 ++++++++++--
 tools/testing/selftests/bpf/Makefile                 |  7 ++++++-
 tools/testing/selftests/bpf/prog_tests/fexit_sleep.c |  4 ++--
 .../selftests/bpf/prog_tests/ns_current_pid_tgid.c   |  4 ++--
 tools/testing/selftests/lib.mk                       |  4 ++++
 6 files changed, 25 insertions(+), 8 deletions(-)
Signature · 1 line
2.30.2