bpf: tools: support build selftests/bpf with clang
Subsystems (4)
v2 cover 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
But 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:
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/lib.mk | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/5 selftests: set CC to clang in lib.mk if LLVM is set
selftests/bpf/Makefile includes lib.mk. With the following command
make -j60 LLVM=1 LLVM_IAS=1 <=== compile kernel
make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1 V=1
some files are still compiled with gcc. This patch fixed lib.mk issue which sets CC to gcc in all cases.
--- tools/testing/selftests/lib.mk | 4 ++++ 1 file changed, 4 insertions(+)
tools/testing/selftests/lib.mk +4 -0
@@ -1,6 +1,10 @@ # This mimics the top-level Makefile. We do it explicitly here so that this # Makefile can operate with or without the kbuild infrastructure. +ifneq ($(LLVM),) +CC := clang +else CC := $(CROSS_COMPILE)gcc +endif ifeq (0,$(MAKELEVEL)) ifeq ($(OUTPUT),)
Signature · 1 line
2.30.2
PATCH v2 2/5 tools: allow proper CC/CXX/... override with LLVM=1 in Makefile.include
In reply to Yonghong Songselftests/bpf/Makefile includes tools/scripts/Makefile.include. With the following command
make -j60 LLVM=1 LLVM_IAS=1 <=== compile kernel make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1 V=1
some files are still compiled with gcc. This patch fixed the case if CC/AR/LD/CXX/STRIP is allowed to be overridden, it will be written to clang/llvm-ar/..., instead of gcc binaries. The definition of CC_NO_CLANG is also relocated to the place after the above CC is defined.
--- tools/scripts/Makefile.include | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
tools/scripts/Makefile.include +10 -2
@@ -39,8 +39,6 @@ EXTRA_WARNINGS += -Wundef EXTRA_WARNINGS += -Wwrite-strings EXTRA_WARNINGS += -Wformat -CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) - # Makefiles suck: This macro sets a default value of $(2) for the # variable named by $(1), unless the variable has been set by # environment or command line. This is necessary for CC and AR
@@ -52,12 +50,22 @@ define allow-override $(eval $(1) = $(2))) endef +ifneq ($(LLVM),) +$(call allow-override,CC,clang) +$(call allow-override,AR,llvm-ar) +$(call allow-override,LD,ld.lld) +$(call allow-override,CXX,clang++) +$(call allow-override,STRIP,llvm-strip) +else # Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix. $(call allow-override,CC,$(CROSS_COMPILE)gcc) $(call allow-override,AR,$(CROSS_COMPILE)ar) $(call allow-override,LD,$(CROSS_COMPILE)ld) $(call allow-override,CXX,$(CROSS_COMPILE)g++) $(call allow-override,STRIP,$(CROSS_COMPILE)strip) +endif + +CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) ifneq ($(LLVM),) HOSTAR ?= llvm-ar
Signature · 1 line
2.30.2
PATCH v2 3/5 selftests/bpf: fix test_cpp compilation failure with clang
In reply to Yonghong SongWith clang compiler:
make -j60 LLVM=1 LLVM_IAS=1 <=== compile kernel
make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1
the test_cpp build failed due to the failure:
warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang-13: error: cannot specify -o when generating multiple output files
test_cpp compilation flag looks like:
clang++ -g -Og -rdynamic -Wall -I<...> ... \
-Dbpf_prog_load=bpf_prog_test_load -Dbpf_load_program=bpf_test_load_program \
test_cpp.cpp <...>/test_core_extern.skel.h <...>/libbpf.a <...>/test_stub.o \
-lcap -lelf -lz -lrt -lpthread -o <...>/test_cpp
The clang++ compiler complains the header file in the command line and also failed the compilation due to this.
Let us remove the header file from the command line which is not intended any way, and this fixed the compilation problem.
--- tools/testing/selftests/bpf/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +1 -1
@@ -481,7 +481,7 @@ $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT) # Make sure we are able to include and link libbpf against c++. $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ) $(call msg,CXX,,$@) - $(Q)$(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@ + $(Q)$(CXX) $(CFLAGS) test_cpp.cpp $(BPFOBJ) $(LDLIBS) -o $@ # Benchmark runner $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
Signature · 1 line
2.30.2
PATCH v2 4/5 selftests/bpf: silence clang compilation warnings
In reply to Yonghong SongWith clang compiler:
make -j60 LLVM=1 LLVM_IAS=1 <=== compile kernel
make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1
Some linker flags are not used/effective for some binaries and we have warnings like:
warning: -lelf: 'linker' input unused [-Wunused-command-line-argument]
We also have warnings like:
.../selftests/bpf/prog_tests/ns_current_pid_tgid.c:74:57: note: treat the string as an argument to avoid this
if (CHECK(waitpid(cpid, &wstatus, 0) == -1, "waitpid", strerror(errno)))
^
"%s",
.../selftests/bpf/test_progs.h:129:35: note: expanded from macro 'CHECK'
_CHECK(condition, tag, duration, format)
^
.../selftests/bpf/test_progs.h:108:21: note: expanded from macro '_CHECK'
fprintf(stdout, ##format); \
^The first warning can be silenced with clang option -Wno-unused-command-line-argument, and the second with -Wno-format-security. Further, gcc does not support the option -Wno-unused-command-line-argument. Since the warning only happens with clang compiler, these two options are enabled only when clang compiler is used and this fixed the above warnings.
--- tools/testing/selftests/bpf/Makefile | 5 +++++ 1 file changed, 5 insertions(+)
tools/testing/selftests/bpf/Makefile +5 -0
@@ -28,6 +28,11 @@ CFLAGS += -g -Og -rdynamic -Wall $(GENFLAGS) $(SAN_CFLAGS) \ -Dbpf_load_program=bpf_test_load_program LDLIBS += -lcap -lelf -lz -lrt -lpthread +# Silence some warnings when compiled with clang +ifneq ($(LLVM),) +CFLAGS += -Wno-unused-command-line-argument -Wno-format-security +endif + # Order correspond to 'make run_tests' order TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ test_verifier_log test_dev_cgroup \
Signature · 1 line
2.30.2
Re: [PATCH bpf-next v2 4/5] selftests/bpf: silence clang compilation warnings
Quoted 8 lines · Yonghong Song
With clang compiler:
make -j60 LLVM=1 LLVM_IAS=1 <=== compile kernel
make -j60 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1
Some linker flags are not used/effective for some binaries and we have warnings like:
warning: -lelf: 'linker' input unused [-Wunused-command-line-argument]
Quoted 5 lines
We also have warnings like:
.../selftests/bpf/prog_tests/ns_current_pid_tgid.c:74:57: note: treat the string as an argument to avoid thisif (CHECK(waitpid(cpid, &wstatus, 0) == -1, "waitpid", strerror(errno))) ^ "%s",
So why not do what the compiler suggests and use "err %s", strerror(errno) instead of silencing useful warning globally?
Quoted 7 lines
.../selftests/bpf/test_progs.h:129:35: note: expanded from macro 'CHECK'
_CHECK(condition, tag, duration, format)
^
.../selftests/bpf/test_progs.h:108:21: note: expanded from macro '_CHECK'fprintf(stdout, ##format); \ ^The first warning can be silenced with clang option -Wno-unused-command-line-argument,
this one does seem necessary, otherwise we'll have to adjust per each .c file the list of libraries needed
Quoted 29 lines
and the second with -Wno-format-security. Further, gcc does not support the option -Wno-unused-command-line-argument. Since the warning only happens with clang compiler, these two options are enabled only when clang compiler is used and this fixed the above warnings.
Signed-off-by Yonghong Song <[email protected]>--- tools/testing/selftests/bpf/Makefile | 5 +++++ 1 file changed, 5 insertions(+)tools/testing/selftests/bpf/Makefile +5
-1@@ -28,6 +28,11 @@ CFLAGS += -g -Og -rdynamic -Wall $(GENFLAGS) $(SAN_CFLAGS) \ -Dbpf_load_program=bpf_test_load_program LDLIBS += -lcap -lelf -lz -lrt -lpthread +# Silence some warnings when compiled with clang +ifneq ($(LLVM),) +CFLAGS += -Wno-unused-command-line-argument -Wno-format-security +endif + # Order correspond to 'make run_tests' order TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ test_verifier_log test_dev_cgroup \ --2.30.2
PATCH v2 5/5 bpftool: fix a clang compilation warning
In reply to Yonghong SongWith clang compiler:
make -j60 LLVM=1 LLVM_IAS=1 <=== compile kernel
# build selftests/bpf or bpftool
make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1
make -j60 -C tools/bpf/bpftool LLVM=1 LLVM_IAS=1
the following compilation warning showed up,
net.c:160:37: warning: comparison of integers of different signs: '__u32' (aka 'unsigned int') and 'int' [-Wsign-compare]
for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len);
^~~~~~~~~~~~~~~~~
.../tools/include/uapi/linux/netlink.h:99:24: note: expanded from macro 'NLMSG_OK'
(nlh)->nlmsg_len <= (len))
~~~~~~~~~~~~~~~~ ^ ~~~In this particular case, "len" is defined as "int" and (nlh)->nlmsg_len is "unsigned int". The macro NLMSG_OK is defined as below in uapi/linux/netlink.h.
#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
(nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
(nlh)->nlmsg_len <= (len))The clang compiler complains the comparision "(nlh)->nlmsg_len <= (len))", but in bpftool/net.c, it is already ensured that "len > 0" must be true. So theoretically the compiler could deduce that comparison of "(nlh)->nlmsg_len" and "len" is okay, but this really depends on compiler internals. Let us add an explicit type conversion (from "int" to "unsigned int") for "len" in NLMSG_OK to silence this warning right now.
--- tools/bpf/bpftool/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/net.c +1 -1
@@ -157,7 +157,7 @@ static int netlink_recv(int sock, __u32 nl_pid, __u32 seq,if (len ==0 )break ; -for (nh = (struct nlmsghdr *)buf;NLMSG_OK (nh, len); +for (nh = (struct nlmsghdr *)buf;NLMSG_OK (nh, (unsigned int )len); nh =NLMSG_NEXT (nh, len)) {if (nh->nlmsg_pid != nl_pid) { ret = -LIBBPF_ERRNO__WRNGPID ;
Signature · 1 line
2.30.2
Re: [PATCH bpf-next v2 5/5] bpftool: fix a clang compilation warning
Quoted 27 lines · Yonghong Song
With clang compiler:
make -j60 LLVM=1 LLVM_IAS=1 <=== compile kernel# build selftests/bpf or bpftool make -j60 -C tools/testing/selftests/bpf LLVM=1 LLVM_IAS=1 make -j60 -C tools/bpf/bpftool LLVM=1 LLVM_IAS=1 the following compilation warning showed up, net.c:160:37: warning: comparison of integers of different signs: '__u32' (aka 'unsigned int') and 'int' [-Wsign-compare] for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); ^~~~~~~~~~~~~~~~~ .../tools/include/uapi/linux/netlink.h:99:24: note: expanded from macro 'NLMSG_OK' (nlh)->nlmsg_len <= (len)) ~~~~~~~~~~~~~~~~ ^ ~~~In this particular case, "len" is defined as "int" and (nlh)->nlmsg_len is "unsigned int". The macro
NLMSG_OKis defined as below inuapi/linux/netlink.h.#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \ (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \ (nlh)->nlmsg_len <= (len))The clang compiler complains the comparision "(nlh)->nlmsg_len <= (len))", but in
bpftool/net.c, it is already ensured that "len > 0" must be true. So theoretically the compiler could deduce that comparison of "(nlh)->nlmsg_len" and "len" is okay, but this really depends on compiler internals. Let us add an explicit type conversion (from "int" to "unsigned int") for "len" inNLMSG_OKto silence this warning right now.
Quoted 4 lines
Signed-off-by Yonghong Song <[email protected]>--- tools/bpf/bpftool/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines
tools/bpf/bpftool/net.c +1
-2@@ -157,7 +157,7 @@ static int netlink_recv(int sock, __u32 nl_pid, __u32 seq,if (len ==0 )break ; -for (nh = (struct nlmsghdr *)buf;NLMSG_OK (nh, len); +for (nh = (struct nlmsghdr *)buf;NLMSG_OK (nh, (unsigned int )len); nh =NLMSG_NEXT (nh, len)) {if (nh->nlmsg_pid != nl_pid) { ret = -LIBBPF_ERRNO__WRNGPID ; --2.30.2
Quoted 11 lines · Yonghong Song
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1
Thank you for the series Yonghong. When I test the above command with your series applied, I observe:/usr/bin/ld: cannot find -lcap
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
I need to install libcap-dev, but this also seems to imply that BFD is being used as the linker, not LLD. Perhaps if the compiler is being used as the "driver" to also link executables, -fuse-ld=lld is needed for the compiler flags.
Then there's:tools/include/tools/libc_compat.h:11:21: error: static declaration of 'reallocarray' follows non-static declaration
static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
^
/usr/include/stdlib.h:559:14: note: previous declaration is here
extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
^so perhaps the detection of COMPAT_NEED_REALLOCARRAY/feature-reallocarray is incorrect?
Quoted 23 lines
But 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:
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: fixtest_cppcompilation failure with clang selftests/bpf: silence clang compilation warnings
bpftool: fix a clang compilation warning
Quoted 9 lines
tools/bpf/bpftool/net.c | 2 +- tools/scripts/Makefile.include | 12 ++++++++++-- tools/testing/selftests/bpf/Makefile | 7 ++++++- tools/testing/selftests/lib.mk | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-)--
2.30.2
--
Thanks,
~Nick Desaulniers
Quoted 19 lines · Nick Desaulniers
Quoted 11 lines · Yonghong Song
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1Thank you for the series Yonghong. When I test the above command with your series applied, I observe:
tools/include/tools/libc_compat.h:11:21: error: static declaration of 'reallocarray' follows non-static declaration
static inline void *reallocarray(void *ptr,size_tnmemb,size_tsize)
Quoted 6 lines
^ /usr/include/stdlib.h:559:14: note: previous declaration is here extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) ^so perhaps the detection of COMPAT_NEED_REALLOCARRAY/feature-reallocarray is incorrect?
Is this related to _DEFAULT_SOURCE vs _GNU_SOURCE. via man 3 reallocarray:
reallocarray():
Since glibc 2.29:
_DEFAULT_SOURCE
Glibc 2.28 and earlier:
_GNU_SOURCE
$ cd tools/testing/selftests/bpf $ grep -rn _DEFAULT_SOURCE | wc -l 0 $ grep -rn _GNU_SOURCE | wc -l 37 $ ldd --version | head -n1 ldd (Debian GLIBC 2.31-9+build1) 2.31
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 28 lines · Nick Desaulniers
Quoted 19 lines · Nick Desaulniers
Quoted 11 lines · Yonghong Song
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1Thank you for the series Yonghong. When I test the above command with your series applied, I observe:
tools/include/tools/libc_compat.h:11:21: error: static declaration of 'reallocarray' follows non-static declaration
static inline void *reallocarray(void *ptr,size_tnmemb,size_tsize)Quoted 6 lines
^ /usr/include/stdlib.h:559:14: note: previous declaration is here extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) ^so perhaps the detection of COMPAT_NEED_REALLOCARRAY/feature-reallocarray is incorrect?
Quoted 7 lines
Is this related to
_DEFAULT_SOURCEvs_GNU_SOURCE. via man 3 reallocarray:
reallocarray():
Since glibc 2.29:
_DEFAULT_SOURCE
Glibc 2.28 and earlier:
_GNU_SOURCE
You can try the following patch to see whether it works or not.
tools/build/feature/test-reallocarray.c +2 -2
@@ -1,5 +1,5 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE +#define _DEFAULT_SOURCE#include <stdlib.h> int main (void )
@@ -7,4 +7,4 @@ int main(void)return !!reallocarray (NULL ,1 ,1 ); } -#undef _GNU_SOURCE +#undef _DEFAULT_SOURCE
[[email protected] ~/work/bpf-next/tools/build]$
Quoted 8 lines
$ cd tools/testing/selftests/bpf $ grep -rn _DEFAULT_SOURCE | wc -l 0 $ grep -rn _GNU_SOURCE | wc -l 37 $ ldd --version | head -n1 ldd (Debian GLIBC 2.31-9+build1) 2.31
Quoted 55 lines · Yonghong Song
Quoted 28 lines · Nick Desaulniers
Quoted 19 lines · Nick Desaulniers
Quoted 11 lines · Yonghong Song
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1Thank you for the series Yonghong. When I test the above command with your series applied, I observe:
tools/include/tools/libc_compat.h:11:21: error: static declaration of 'reallocarray' follows non-static declaration
static inline void *reallocarray(void *ptr,size_tnmemb,size_tsize)Quoted 6 lines
^ /usr/include/stdlib.h:559:14: note: previous declaration is here extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) ^so perhaps the detection of COMPAT_NEED_REALLOCARRAY/feature-reallocarray is incorrect?
Quoted 7 lines
Is this related to
_DEFAULT_SOURCEvs_GNU_SOURCE. via man 3 reallocarray:
reallocarray():
Since glibc 2.29:
_DEFAULT_SOURCE
Glibc 2.28 and earlier:
_GNU_SOURCEYou can try the following patch to see whether it works or not.
tools/build/feature/test-reallocarray.c +1
-1@@ -1,5 +1,5 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE +#define _DEFAULT_SOURCE#include <stdlib.h> int main (void )
tools/build/feature/test-reallocarray.c int main(void) · line 10
Quoted 5 lines
tools/build/feature/test-reallocarray.c +1
-1@@ -7,4 +7,4 @@ int main(void)return !!reallocarray (NULL ,1 ,1 ); } -#undef _GNU_SOURCE +#undef _DEFAULT_SOURCE
Yeah, I had tried that. No luck though; same error message. Even:
$ cat foo.c
#define _DEFAULT_SOURCE
#include <stdlib.h>
void *reallocarray(void *ptr, size_t nmemb, size_t size) { return (void*)0; };
$ clang -c foo.c
$ echo $?
0So I'm not sure precisely what's going on here. I probably have to go digging around to understand tools/build/feature/ anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861
Quoted 10 lines
[[email protected] ~/work/bpf-next/tools/build]$
Quoted 8 lines
$ cd tools/testing/selftests/bpf $ grep -rn _DEFAULT_SOURCE | wc -l 0 $ grep -rn _GNU_SOURCE | wc -l 37 $ ldd --version | head -n1 ldd (Debian GLIBC 2.31-9+build1) 2.31
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 73 lines · Nick Desaulniers
Quoted 55 lines · Yonghong Song
Quoted 28 lines · Nick Desaulniers
Quoted 19 lines · Nick Desaulniers
Quoted 11 lines · Yonghong Song
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1Thank you for the series Yonghong. When I test the above command with your series applied, I observe:
tools/include/tools/libc_compat.h:11:21: error: static declaration of 'reallocarray' follows non-static declaration
static inline void *reallocarray(void *ptr,size_tnmemb,size_tsize)Quoted 6 lines
^ /usr/include/stdlib.h:559:14: note: previous declaration is here extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) ^so perhaps the detection of COMPAT_NEED_REALLOCARRAY/feature-reallocarray is incorrect?
Quoted 7 lines
Is this related to
_DEFAULT_SOURCEvs_GNU_SOURCE. via man 3 reallocarray:
reallocarray():
Since glibc 2.29:
_DEFAULT_SOURCE
Glibc 2.28 and earlier:
_GNU_SOURCEYou can try the following patch to see whether it works or not.
tools/build/feature/test-reallocarray.c +1
-1@@ -1,5 +1,5 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE +#define _DEFAULT_SOURCE#include <stdlib.h> int main (void )tools/build/feature/test-reallocarray.c int main(void) · line 10
Quoted 5 lines
tools/build/feature/test-reallocarray.c +1
-1@@ -7,4 +7,4 @@ int main(void)return !!reallocarray (NULL ,1 ,1 ); } -#undef _GNU_SOURCE +#undef _DEFAULT_SOURCEYeah, I had tried that. No luck though; same error message. Even:
$ cat foo.c #define _DEFAULT_SOURCE #include <stdlib.h> void *reallocarray(void *ptr, size_t nmemb, size_t size) { return (void*)0; }; $ clang -c foo.c $ echo $? 0
Quoted 6 lines
So I'm not sure precisely what's going on here. I probably have to go digging around to understand
tools/build/feature/anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861
Jiri, any tips on how to debug feature detection in tools/build/feature/Makefile?
Quoted 17 lines
Quoted 11 lines
[[email protected] ~/work/bpf-next/tools/build]$
Quoted 8 lines
$ cd tools/testing/selftests/bpf $ grep -rn _DEFAULT_SOURCE | wc -l 0 $ grep -rn _GNU_SOURCE | wc -l 37 $ ldd --version | head -n1 ldd (Debian GLIBC 2.31-9+build1) 2.31--
Thanks,
~Nick Desaulniers
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 82 lines · Nick Desaulniers
Quoted 73 lines · Nick Desaulniers
Quoted 55 lines · Yonghong Song
Quoted 28 lines · Nick Desaulniers
Quoted 19 lines · Nick Desaulniers
Quoted 11 lines · Yonghong Song
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1Thank you for the series Yonghong. When I test the above command with your series applied, I observe:
tools/include/tools/libc_compat.h:11:21: error: static declaration of 'reallocarray' follows non-static declaration
static inline void *reallocarray(void *ptr,size_tnmemb,size_tsize)Quoted 6 lines
^ /usr/include/stdlib.h:559:14: note: previous declaration is here extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) ^so perhaps the detection of COMPAT_NEED_REALLOCARRAY/feature-reallocarray is incorrect?
Quoted 7 lines
Is this related to
_DEFAULT_SOURCEvs_GNU_SOURCE. via man 3 reallocarray:
reallocarray():
Since glibc 2.29:
_DEFAULT_SOURCE
Glibc 2.28 and earlier:
_GNU_SOURCEYou can try the following patch to see whether it works or not.
tools/build/feature/test-reallocarray.c +1
-1@@ -1,5 +1,5 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE +#define _DEFAULT_SOURCE#include <stdlib.h> int main (void )tools/build/feature/test-reallocarray.c int main(void) · line 10
Quoted 5 lines
tools/build/feature/test-reallocarray.c +1
-1@@ -7,4 +7,4 @@ int main(void)return !!reallocarray (NULL ,1 ,1 ); } -#undef _GNU_SOURCE +#undef _DEFAULT_SOURCEYeah, I had tried that. No luck though; same error message. Even:
$ cat foo.c #define _DEFAULT_SOURCE #include <stdlib.h> void *reallocarray(void *ptr, size_t nmemb, size_t size) { return (void*)0; }; $ clang -c foo.c $ echo $? 0Quoted 6 lines
So I'm not sure precisely what's going on here. I probably have to go digging around to understand
tools/build/feature/anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861
Quoted 2 lines
Jiri, any tips on how to debug feature detection in
tools/build/feature/Makefile?
for quick check, there's output file for each test, like:
[jolsa@krava feature]$ ls -l *.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-all.make.output -rw-rw-r--. 1 jolsa jolsa 182 Apr 9 15:52 test-bionic.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-cplus-demangle.make.output -rw-rw-r--. 1 jolsa jolsa 145 Apr 9 15:52 test-jvmti.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbabeltrace.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbpf.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libdebuginfod.make.output -rw-rw-r--. 1 jolsa jolsa 193 Apr 9 15:52 test-libunwind-aarch64.make.output -rw-rw-r--. 1 jolsa jolsa 177 Apr 9 15:52 test-libunwind-x86.make.output [jolsa@krava feature]$ cat test-libunwind-aarch64.make.output test-libunwind-aarch64.c:2:10: fatal error: libunwind-aarch64.h: No such file or directory 2 | #include <libunwind-aarch64.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. [jolsa@krava feature]$ cat test-libunwind-x86.make.output test-libunwind-x86.c:2:10: fatal error: libunwind-x86.h: No such file or directory 2 | #include <libunwind-x86.h> | ^~~~~~~~~~~~~~~~~
zlib should be done by:
[jolsa@krava feature]$ make test-zlib.bin
gcc -MD -Wall -Werror -o test-zlib.bin test-zlib.c > test-zlib.make.output 2>&1 -lz
I can try to recreate, how do you build?
jirka
Quoted 22 lines · Jiri Olsa
Quoted 20 lines · Nick Desaulniers
Quoted 18 lines · Nick Desaulniers
Quoted 16 lines · Yonghong Song
Quoted 12 lines · Nick Desaulniers
Quoted 10 lines · Nick Desaulniers
Quoted 8 lines · Yonghong Song
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.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
After kernel is build with clang, the following command can be used to build selftests with clang:
make -j60 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1
^ note below
Quoted 84 lines
Quoted 59 lines
Quoted 52 lines
Quoted 36 lines
Quoted 13 lines
Quoted 6 lines
Thank you for the series Yonghong. When I test the above command with your series applied, I observe:
tools/include/tools/libc_compat.h:11:21: error: static declaration of 'reallocarray' follows non-static declaration
static inline void *reallocarray(void *ptr,size_tnmemb,size_tsize)Quoted 6 lines
^ /usr/include/stdlib.h:559:14: note: previous declaration is here extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) ^so perhaps the detection of COMPAT_NEED_REALLOCARRAY/feature-reallocarray is incorrect?
Quoted 7 lines
Is this related to
_DEFAULT_SOURCEvs_GNU_SOURCE. via man 3 reallocarray:
reallocarray():
Since glibc 2.29:
_DEFAULT_SOURCE
Glibc 2.28 and earlier:
_GNU_SOURCEYou can try the following patch to see whether it works or not.
tools/build/feature/test-reallocarray.c +1
-1@@ -1,5 +1,5 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE +#define _DEFAULT_SOURCE#include <stdlib.h> int main (void )tools/build/feature/test-reallocarray.c int main(void) · line 10
Quoted 5 lines
tools/build/feature/test-reallocarray.c +1
-1@@ -7,4 +7,4 @@ int main(void)return !!reallocarray (NULL ,1 ,1 ); } -#undef _GNU_SOURCE +#undef _DEFAULT_SOURCEYeah, I had tried that. No luck though; same error message. Even:
$ cat foo.c #define _DEFAULT_SOURCE #include <stdlib.h> void *reallocarray(void *ptr, size_t nmemb, size_t size) { return (void*)0; }; $ clang -c foo.c $ echo $? 0Quoted 6 lines
So I'm not sure precisely what's going on here. I probably have to go digging around to understand
tools/build/feature/anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861Quoted 2 lines
Jiri, any tips on how to debug feature detection in
tools/build/feature/Makefile?for quick check, there's output file for each test, like:
[jolsa@krava feature]$ ls -l *.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-all.make.output -rw-rw-r--. 1 jolsa jolsa 182 Apr 9 15:52 test-bionic.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-cplus-demangle.make.output -rw-rw-r--. 1 jolsa jolsa 145 Apr 9 15:52 test-jvmti.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbabeltrace.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbpf.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libdebuginfod.make.output -rw-rw-r--. 1 jolsa jolsa 193 Apr 9 15:52 test-libunwind-aarch64.make.output -rw-rw-r--. 1 jolsa jolsa 177 Apr 9 15:52 test-libunwind-x86.make.output [jolsa@krava feature]$ cat test-libunwind-aarch64.make.output test-libunwind-aarch64.c:2:10: fatal error: libunwind-aarch64.h: No such file or directory 2 | #include <libunwind-aarch64.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. [jolsa@krava feature]$ cat test-libunwind-x86.make.output test-libunwind-x86.c:2:10: fatal error: libunwind-x86.h: No such file or directory 2 | #include <libunwind-x86.h> | ^~~~~~~~~~~~~~~~~
Quoted 6 lines
zlib should be done by:
[jolsa@krava feature]$ make test-zlib.bin
gcc -MD -Wall -Werror -o test-zlib.bintest-zlib.c> test-zlib.make.output 2>&1 -lzI can try to recreate, how do you build?
See note above, I'm similarly running precisely:
$ make LLVM=1 LLVM_IAS=1 -j72 defconfig $ make LLVM=1 LLVM_IAS=1 -j72 clean $ make LLVM=1 LLVM_IAS=1 -j72 -C tools/testing/selftests/bpf
Signature · 2 lines
Thanks, ~Nick Desaulniers
On Tue, Apr 13, 2021 at 01:45:39PM -0700, Nick Desaulniers wrote:
SNIP
Quoted 38 lines
Quoted 38 lines
Quoted 10 lines
Quoted 7 lines
So I'm not sure precisely what's going on here. I probably have to go digging around to understand
tools/build/feature/anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861Jiri, any tips on how to debug feature detection in
tools/build/feature/Makefile?for quick check, there's output file for each test, like:
[jolsa@krava feature]$ ls -l *.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-all.make.output -rw-rw-r--. 1 jolsa jolsa 182 Apr 9 15:52 test-bionic.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-cplus-demangle.make.output -rw-rw-r--. 1 jolsa jolsa 145 Apr 9 15:52 test-jvmti.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbabeltrace.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbpf.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libdebuginfod.make.output -rw-rw-r--. 1 jolsa jolsa 193 Apr 9 15:52 test-libunwind-aarch64.make.output -rw-rw-r--. 1 jolsa jolsa 177 Apr 9 15:52 test-libunwind-x86.make.output [jolsa@krava feature]$ cat test-libunwind-aarch64.make.output test-libunwind-aarch64.c:2:10: fatal error: libunwind-aarch64.h: No such file or directory 2 | #include <libunwind-aarch64.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. [jolsa@krava feature]$ cat test-libunwind-x86.make.output test-libunwind-x86.c:2:10: fatal error: libunwind-x86.h: No such file or directory 2 | #include <libunwind-x86.h> | ^~~~~~~~~~~~~~~~~zlib should be done by:
[jolsa@krava feature]$ make test-zlib.bin
gcc -MD -Wall -Werror -o test-zlib.bintest-zlib.c> test-zlib.make.output 2>&1 -lz
Quoted 6 lines
Quoted 1 line
I can try to recreate, how do you build?
See note above, I'm similarly running precisely:
$ make LLVM=1 LLVM_IAS=1 -j72 defconfig $ make LLVM=1 LLVM_IAS=1 -j72 clean $ make LLVM=1 LLVM_IAS=1 -j72 -C tools/testing/selftests/bpf
for some reason I'm stuck with this error on latest bpf-next/master
$ make LLVM=1 LLVM_IAS=1 -C tools/testing/selftests/bpf
make[1]: Nothing to be done for 'docs'.
CLNG-BPF [test_maps] test_lwt_ip_encap.o
CLNG-BPF [test_maps] test_tc_edt.o
CLNG-BPF [test_maps] local_storage.oprogs/local_storage.c:41:15: error: use of undeclared identifier 'BPF_MAP_TYPE_TASK_STORAGE'; did you mean 'BPF_MAP_TYPE_SK_STORAGE'?
__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
^~~~~~~~~~~~~~~~~~~~~~~~~
BPF_MAP_TYPE_SK_STORAGE
/home/jolsa/linux/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:13:39: note: expanded from macro '__uint'
#define __uint(name, val) int (*name)[val]
^
/home/jolsa/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h:10317:2: note: 'BPF_MAP_TYPE_SK_STORAGE' declared here
BPF_MAP_TYPE_SK_STORAGE = 24,
^1 error generated.
make: *** [Makefile:448: /home/jolsa/linux/tools/testing/selftests/bpf/local_storage.o] Error 1
make: Leaving directory '/home/jolsa/linux/tools/testing/selftests/bpf'
jirka
Quoted 43 lines · Jiri Olsa
On Tue, Apr 13, 2021 at 01:45:39PM -0700, Nick Desaulniers wrote:
SNIP
Quoted 38 lines
Quoted 38 lines
Quoted 10 lines
Quoted 7 lines
So I'm not sure precisely what's going on here. I probably have to go digging around to understand
tools/build/feature/anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861Jiri, any tips on how to debug feature detection in
tools/build/feature/Makefile?for quick check, there's output file for each test, like:
[jolsa@krava feature]$ ls -l *.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-all.make.output -rw-rw-r--. 1 jolsa jolsa 182 Apr 9 15:52 test-bionic.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-cplus-demangle.make.output -rw-rw-r--. 1 jolsa jolsa 145 Apr 9 15:52 test-jvmti.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbabeltrace.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbpf.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libdebuginfod.make.output -rw-rw-r--. 1 jolsa jolsa 193 Apr 9 15:52 test-libunwind-aarch64.make.output -rw-rw-r--. 1 jolsa jolsa 177 Apr 9 15:52 test-libunwind-x86.make.output [jolsa@krava feature]$ cat test-libunwind-aarch64.make.output test-libunwind-aarch64.c:2:10: fatal error: libunwind-aarch64.h: No such file or directory 2 | #include <libunwind-aarch64.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. [jolsa@krava feature]$ cat test-libunwind-x86.make.output test-libunwind-x86.c:2:10: fatal error: libunwind-x86.h: No such file or directory 2 | #include <libunwind-x86.h> | ^~~~~~~~~~~~~~~~~zlib should be done by:
[jolsa@krava feature]$ make test-zlib.bin
gcc -MD -Wall -Werror -o test-zlib.bintest-zlib.c> test-zlib.make.output 2>&1 -lz
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
I can try to recreate, how do you build?
See note above, I'm similarly running precisely:
$ make LLVM=1 LLVM_IAS=1 -j72 defconfig $ make LLVM=1 LLVM_IAS=1 -j72 clean $ make LLVM=1 LLVM_IAS=1 -j72 -C tools/testing/selftests/bpffor some reason I'm stuck with this error on latest bpf-next/master
did you build vmlinux image before building selftests? those enums should come through vmlinux.h from up-to-date vmlinux
Quoted 24 lines
$ make LLVM=1 LLVM_IAS=1 -C tools/testing/selftests/bpfmake[1]: Nothing to be done for 'docs'.
CLNG-BPF [test_maps] test_lwt_ip_encap.o
CLNG-BPF [test_maps] test_tc_edt.o
CLNG-BPF [test_maps] local_storage.oprogs/local_storage.c:41:15: error: use of undeclared identifier 'BPF_MAP_TYPE_TASK_STORAGE'; did you mean 'BPF_MAP_TYPE_SK_STORAGE'?__uint(type, BPF_MAP_TYPE_TASK_STORAGE); ^~~~~~~~~~~~~~~~~~~~~~~~~ BPF_MAP_TYPE_SK_STORAGE /home/jolsa/linux/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:13:39: note: expanded from macro '__uint' #define __uint(name, val) int (*name)[val] ^ /home/jolsa/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h:10317:2: note: 'BPF_MAP_TYPE_SK_STORAGE' declared here BPF_MAP_TYPE_SK_STORAGE = 24, ^1 error generated.
make: *** [Makefile:448:/home/jolsa/linux/tools/testing/selftests/bpf/local_storage.o] Error 1
make: Leaving directory '/home/jolsa/linux/tools/testing/selftests/bpf'jirka
Quoted 51 lines · Andrii Nakryiko
Quoted 50 lines · Jiri Olsa
On Tue, Apr 13, 2021 at 01:45:39PM -0700, Nick Desaulniers wrote:
SNIP
Quoted 44 lines
Quoted 33 lines
Quoted 10 lines
Quoted 7 lines
So I'm not sure precisely what's going on here. I probably have to go digging around to understand
tools/build/feature/anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861Jiri, any tips on how to debug feature detection in
tools/build/feature/Makefile?for quick check, there's output file for each test, like:
[jolsa@krava feature]$ ls -l *.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-all.make.output -rw-rw-r--. 1 jolsa jolsa 182 Apr 9 15:52 test-bionic.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-cplus-demangle.make.output -rw-rw-r--. 1 jolsa jolsa 145 Apr 9 15:52 test-jvmti.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbabeltrace.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbpf.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libdebuginfod.make.output -rw-rw-r--. 1 jolsa jolsa 193 Apr 9 15:52 test-libunwind-aarch64.make.output -rw-rw-r--. 1 jolsa jolsa 177 Apr 9 15:52 test-libunwind-x86.make.output [jolsa@krava feature]$ cat test-libunwind-aarch64.make.output test-libunwind-aarch64.c:2:10: fatal error: libunwind-aarch64.h: No such file or directory 2 | #include <libunwind-aarch64.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. [jolsa@krava feature]$ cat test-libunwind-x86.make.output test-libunwind-x86.c:2:10: fatal error: libunwind-x86.h: No such file or directory 2 | #include <libunwind-x86.h> | ^~~~~~~~~~~~~~~~~Quoted 6 lines
zlib should be done by:
[jolsa@krava feature]$ make test-zlib.bin
gcc -MD -Wall -Werror -o test-zlib.bintest-zlib.c> test-zlib.make.output 2>&1 -lzI can try to recreate, how do you build?
See note above, I'm similarly running precisely:
$ make LLVM=1 LLVM_IAS=1 -j72 defconfig $ make LLVM=1 LLVM_IAS=1 -j72 clean $ make LLVM=1 LLVM_IAS=1 -j72 -C tools/testing/selftests/bpf
Quoted 4 lines
Quoted 1 line
for some reason I'm stuck with this error on latest bpf-next/master
did you build vmlinux image before building selftests? those enums should come through
vmlinux.hfrom up-to-date vmlinux
it was there.. but I found the clang/lld I compiled can't link properly, which is probably unrelated to the error below, but I need to solve it first ;-)
jirka
Quoted 26 lines
Quoted 25 lines
$ make LLVM=1 LLVM_IAS=1 -C tools/testing/selftests/bpfmake[1]: Nothing to be done for 'docs'.
CLNG-BPF [test_maps] test_lwt_ip_encap.o
CLNG-BPF [test_maps] test_tc_edt.o
CLNG-BPF [test_maps] local_storage.oprogs/local_storage.c:41:15: error: use of undeclared identifier 'BPF_MAP_TYPE_TASK_STORAGE'; did you mean 'BPF_MAP_TYPE_SK_STORAGE'?__uint(type, BPF_MAP_TYPE_TASK_STORAGE); ^~~~~~~~~~~~~~~~~~~~~~~~~ BPF_MAP_TYPE_SK_STORAGE /home/jolsa/linux/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:13:39: note: expanded from macro '__uint' #define __uint(name, val) int (*name)[val] ^ /home/jolsa/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h:10317:2: note: 'BPF_MAP_TYPE_SK_STORAGE' declared here BPF_MAP_TYPE_SK_STORAGE = 24, ^1 error generated.
make: *** [Makefile:448:/home/jolsa/linux/tools/testing/selftests/bpf/local_storage.o] Error 1
make: Leaving directory '/home/jolsa/linux/tools/testing/selftests/bpf'jirka
Quoted 53 lines · Jiri Olsa
Quoted 51 lines · Andrii Nakryiko
Quoted 50 lines · Jiri Olsa
On Tue, Apr 13, 2021 at 01:45:39PM -0700, Nick Desaulniers wrote:
SNIP
Quoted 44 lines
Quoted 33 lines
Quoted 10 lines
Quoted 7 lines
So I'm not sure precisely what's going on here. I probably have to go digging around to understand
tools/build/feature/anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861Jiri, any tips on how to debug feature detection in
tools/build/feature/Makefile?for quick check, there's output file for each test, like:
[jolsa@krava feature]$ ls -l *.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-all.make.output -rw-rw-r--. 1 jolsa jolsa 182 Apr 9 15:52 test-bionic.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-cplus-demangle.make.output -rw-rw-r--. 1 jolsa jolsa 145 Apr 9 15:52 test-jvmti.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbabeltrace.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbpf.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libdebuginfod.make.output -rw-rw-r--. 1 jolsa jolsa 193 Apr 9 15:52 test-libunwind-aarch64.make.output -rw-rw-r--. 1 jolsa jolsa 177 Apr 9 15:52 test-libunwind-x86.make.output [jolsa@krava feature]$ cat test-libunwind-aarch64.make.output test-libunwind-aarch64.c:2:10: fatal error: libunwind-aarch64.h: No such file or directory 2 | #include <libunwind-aarch64.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. [jolsa@krava feature]$ cat test-libunwind-x86.make.output test-libunwind-x86.c:2:10: fatal error: libunwind-x86.h: No such file or directory 2 | #include <libunwind-x86.h> | ^~~~~~~~~~~~~~~~~Quoted 6 lines
zlib should be done by:
[jolsa@krava feature]$ make test-zlib.bin
gcc -MD -Wall -Werror -o test-zlib.bintest-zlib.c> test-zlib.make.output 2>&1 -lzI can try to recreate, how do you build?
See note above, I'm similarly running precisely:
$ make LLVM=1 LLVM_IAS=1 -j72 defconfig $ make LLVM=1 LLVM_IAS=1 -j72 clean $ make LLVM=1 LLVM_IAS=1 -j72 -C tools/testing/selftests/bpf
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
for some reason I'm stuck with this error on latest bpf-next/master
did you build vmlinux image before building selftests? those enums should come through
vmlinux.hfrom up-to-date vmlinuxit was there.. but I found the clang/lld I compiled can't link properly, which is probably unrelated to the error below, but I need to solve it first ;-)
Do you have more info about what command you're running, or what error you're observing? The kernel itself is not linking for you?
Quoted 30 lines
jirka
Quoted 26 lines
Quoted 25 lines
$ make LLVM=1 LLVM_IAS=1 -C tools/testing/selftests/bpfmake[1]: Nothing to be done for 'docs'.
CLNG-BPF [test_maps] test_lwt_ip_encap.o
CLNG-BPF [test_maps] test_tc_edt.o
CLNG-BPF [test_maps] local_storage.oprogs/local_storage.c:41:15: error: use of undeclared identifier 'BPF_MAP_TYPE_TASK_STORAGE'; did you mean 'BPF_MAP_TYPE_SK_STORAGE'?__uint(type, BPF_MAP_TYPE_TASK_STORAGE); ^~~~~~~~~~~~~~~~~~~~~~~~~ BPF_MAP_TYPE_SK_STORAGE /home/jolsa/linux/tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:13:39: note: expanded from macro '__uint' #define __uint(name, val) int (*name)[val] ^ /home/jolsa/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h:10317:2: note: 'BPF_MAP_TYPE_SK_STORAGE' declared here BPF_MAP_TYPE_SK_STORAGE = 24, ^1 error generated.
make: *** [Makefile:448:/home/jolsa/linux/tools/testing/selftests/bpf/local_storage.o] Error 1
make: Leaving directory '/home/jolsa/linux/tools/testing/selftests/bpf'jirka
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 59 lines · Nick Desaulniers
Quoted 58 lines · Jiri Olsa
Quoted 55 lines · Andrii Nakryiko
Quoted 43 lines · Jiri Olsa
On Tue, Apr 13, 2021 at 01:45:39PM -0700, Nick Desaulniers wrote:
SNIP
Quoted 38 lines
Quoted 38 lines
Quoted 10 lines
Quoted 7 lines
So I'm not sure precisely what's going on here. I probably have to go digging around to understand
tools/build/feature/anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861Jiri, any tips on how to debug feature detection in
tools/build/feature/Makefile?for quick check, there's output file for each test, like:
[jolsa@krava feature]$ ls -l *.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-all.make.output -rw-rw-r--. 1 jolsa jolsa 182 Apr 9 15:52 test-bionic.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-cplus-demangle.make.output -rw-rw-r--. 1 jolsa jolsa 145 Apr 9 15:52 test-jvmti.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbabeltrace.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbpf.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libdebuginfod.make.output -rw-rw-r--. 1 jolsa jolsa 193 Apr 9 15:52 test-libunwind-aarch64.make.output -rw-rw-r--. 1 jolsa jolsa 177 Apr 9 15:52 test-libunwind-x86.make.output [jolsa@krava feature]$ cat test-libunwind-aarch64.make.output test-libunwind-aarch64.c:2:10: fatal error: libunwind-aarch64.h: No such file or directory 2 | #include <libunwind-aarch64.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. [jolsa@krava feature]$ cat test-libunwind-x86.make.output test-libunwind-x86.c:2:10: fatal error: libunwind-x86.h: No such file or directory 2 | #include <libunwind-x86.h> | ^~~~~~~~~~~~~~~~~zlib should be done by:
[jolsa@krava feature]$ make test-zlib.bin
gcc -MD -Wall -Werror -o test-zlib.bintest-zlib.c> test-zlib.make.output 2>&1 -lzQuoted 8 lines
Quoted 6 lines
Quoted 1 line
I can try to recreate, how do you build?
See note above, I'm similarly running precisely:
$ make LLVM=1 LLVM_IAS=1 -j72 defconfig $ make LLVM=1 LLVM_IAS=1 -j72 clean $ make LLVM=1 LLVM_IAS=1 -j72 -C tools/testing/selftests/bpffor some reason I'm stuck with this error on latest bpf-next/master
did you build vmlinux image before building selftests? those enums should come through
vmlinux.hfrom up-to-date vmlinux
Quoted 6 lines
Quoted 3 lines
it was there.. but I found the clang/lld I compiled can't link properly, which is probably unrelated to the error below, but I need to solve it first ;-)
Do you have more info about what command you're running, or what error you're observing? The kernel itself is not linking for you?
I did the commands you sent, but I might have but llvm/clang build, I'm rebuilding now, it takes forever..
jirka
Quoted 64 lines · Jiri Olsa
Quoted 63 lines · Nick Desaulniers
Quoted 61 lines · Jiri Olsa
Quoted 51 lines · Andrii Nakryiko
Quoted 50 lines · Jiri Olsa
On Tue, Apr 13, 2021 at 01:45:39PM -0700, Nick Desaulniers wrote:
SNIP
Quoted 44 lines
Quoted 33 lines
Quoted 10 lines
Quoted 7 lines
So I'm not sure precisely what's going on here. I probably have to go digging around to understand
tools/build/feature/anyways. With your v3 applied, I consistently see:
No zlib found
and yet, I certainly do have zlib on my host.
https://stackoverflow.com/a/54558861Jiri, any tips on how to debug feature detection in
tools/build/feature/Makefile?for quick check, there's output file for each test, like:
[jolsa@krava feature]$ ls -l *.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-all.make.output -rw-rw-r--. 1 jolsa jolsa 182 Apr 9 15:52 test-bionic.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-cplus-demangle.make.output -rw-rw-r--. 1 jolsa jolsa 145 Apr 9 15:52 test-jvmti.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbabeltrace.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libbpf.make.output -rw-rw-r--. 1 jolsa jolsa 0 Apr 8 20:25 test-libdebuginfod.make.output -rw-rw-r--. 1 jolsa jolsa 193 Apr 9 15:52 test-libunwind-aarch64.make.output -rw-rw-r--. 1 jolsa jolsa 177 Apr 9 15:52 test-libunwind-x86.make.output [jolsa@krava feature]$ cat test-libunwind-aarch64.make.output test-libunwind-aarch64.c:2:10: fatal error: libunwind-aarch64.h: No such file or directory 2 | #include <libunwind-aarch64.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. [jolsa@krava feature]$ cat test-libunwind-x86.make.output test-libunwind-x86.c:2:10: fatal error: libunwind-x86.h: No such file or directory 2 | #include <libunwind-x86.h> | ^~~~~~~~~~~~~~~~~Quoted 6 lines
zlib should be done by:
[jolsa@krava feature]$ make test-zlib.bin
gcc -MD -Wall -Werror -o test-zlib.bintest-zlib.c> test-zlib.make.output 2>&1 -lzI can try to recreate, how do you build?
See note above, I'm similarly running precisely:
$ make LLVM=1 LLVM_IAS=1 -j72 defconfig $ make LLVM=1 LLVM_IAS=1 -j72 clean $ make LLVM=1 LLVM_IAS=1 -j72 -C tools/testing/selftests/bpfQuoted 4 lines
Quoted 1 line
for some reason I'm stuck with this error on latest bpf-next/master
did you build vmlinux image before building selftests? those enums should come through
vmlinux.hfrom up-to-date vmlinuxit was there.. but I found the clang/lld I compiled can't link properly, which is probably unrelated to the error below, but I need to solve it first ;-)
Quoted 5 lines
Quoted 2 lines
Do you have more info about what command you're running, or what error you're observing? The kernel itself is not linking for you?
I did the commands you sent, but I might have but llvm/clang build, I'm rebuilding now, it takes forever..
ok, finished all commands finaly.. did not reproduce the issue :-\
any luck with those build make.output files for zlib?
jirka
Quoted 19 lines · Nick Desaulniers
Quoted 11 lines · Yonghong Song
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1Thank you for the series Yonghong. When I test the above command with your series applied, I observe:
/usr/bin/ld: cannot find -lcap
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
Quoted 4 lines
I need to install libcap-dev, but this also seems to imply that BFD is being used as the linker, not LLD. Perhaps if the compiler is being used as the "driver" to also link executables,
-fuse-ld=lldis needed for the compiler flags.
Yes, bfd is needed to build selftests/bpf. This is due to a dependency on bpftool which needs uses libbfd to disassemble the jited code.
Quoted 11 lines
Then there's:
tools/include/tools/libc_compat.h:11:21: error: static declaration of 'reallocarray' follows non-static declaration
static inline void *reallocarray(void *ptr,size_tnmemb,size_tsize)^ /usr/include/stdlib.h:559:14: note: previous declaration is here extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) ^so perhaps the detection of COMPAT_NEED_REALLOCARRAY/feature-reallocarray is incorrect?
libbpf already stopped to use system reallocarray(), but bpftool still uses it.
In bpftool makefile, we have
ifeq ($(feature-reallocarray), 0)
CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
endif
I guess probably detection of feature-reallocarray is not correct? Could you take a look at your system? My system supports reallocarray, so the above -DCOMPAT_NEED_REALLOCARRAY is not added to compilation flags.
Quoted 40 lines
Quoted 25 lines
But 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:
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: fixtest_cppcompilation failure with clang selftests/bpf: silence clang compilation warnings
bpftool: fix a clang compilation warningQuoted 9 lines
tools/bpf/bpftool/net.c | 2 +- tools/scripts/Makefile.include | 12 ++++++++++-- tools/testing/selftests/bpf/Makefile | 7 ++++++- tools/testing/selftests/lib.mk | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-)--
2.30.2--
Thanks,
~Nick Desaulniers
Quoted 12 lines · Yonghong Song
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1
Quoted 7 lines
But 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.
Might be good to add some hints like when the build stops or errors:
Like in my case when I had no CONFIG_DEBUG_INFO_BTF set.
Of course in combination with Clang-LTO a pointer "you need pahole version 1.21." and CONFIG_DEBUG_INFO_BTF=y.
Finally, a hint for missing xxx-dev(el) packages (see Nick's report).
The tools directory has its own build rules thus I cannot say how to check for specific Kconfigs.
I have not looked.
NOTE: I have not checked without setting CONFIG_DEBUG_INFO.
- Sedat -
Quoted 24 lines
Changelog:
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: fixtest_cppcompilation failure with clang selftests/bpf: silence clang compilation warnings
bpftool: fix a clang compilation warningtools/bpf/bpftool/net.c | 2 +- tools/scripts/Makefile.include | 12 ++++++++++-- tools/testing/selftests/bpf/Makefile | 7 ++++++- tools/testing/selftests/lib.mk | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-)--
2.30.2
Quoted 25 lines · Sedat Dilek
Quoted 12 lines · Yonghong Song
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1Quoted 7 lines
But 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.Might be good to add some hints like when the build stops or errors:
Like in my case when I had no
CONFIG_DEBUG_INFO_BTFset.
Quoted 8 lines
Of course in combination with Clang-LTO a pointer "you need pahole version 1.21." and
CONFIG_DEBUG_INFO_BTF=y.Finally, a hint for missing xxx-dev(el) packages (see Nick's report).
The tools directory has its own build rules thus I cannot say how to check for specific Kconfigs.
I have not looked.
I will add some more information about how I have tested in the cover letter.
Quoted 29 lines
NOTE: I have not checked without setting
CONFIG_DEBUG_INFO.- Sedat -
Quoted 24 lines
Changelog:
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: fixtest_cppcompilation failure with clang selftests/bpf: silence clang compilation warnings
bpftool: fix a clang compilation warningtools/bpf/bpftool/net.c | 2 +- tools/scripts/Makefile.include | 12 ++++++++++-- tools/testing/selftests/bpf/Makefile | 7 ++++++- tools/testing/selftests/lib.mk | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-)--
2.30.2
Quoted 3 lines · Yonghong Song
To build kernel with clang, people typically use
make -j60 LLVM=1 LLVM_IAS=1
Just as a side note:
When building with a high parallel-make-job like above "-j60" I saw that "test_core_extern.skel.h" was not generated which is a pre-req header file for building stuff like test_cpp.cpp.
I have in my build-script:
MAXCPUS="$(($(getconf _NPROCESSORS_ONLN)))"
MAKE_JOBS="${MAXCPUS}"
Thanks.
- Sedat -
Quoted 40 lines
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 -Ctools/testing/selftests/bpfLLVM=1 LLVM_IAS=1But 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:
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: fixtest_cppcompilation failure with clang selftests/bpf: silence clang compilation warnings
bpftool: fix a clang compilation warningtools/bpf/bpftool/net.c | 2 +- tools/scripts/Makefile.include | 12 ++++++++++-- tools/testing/selftests/bpf/Makefile | 7 ++++++- tools/testing/selftests/lib.mk | 4 ++++ 4 files changed, 21 insertions(+), 4 deletions(-)--
2.30.2