samples: bpf: fix build issues with Clang/LLVM
Subsystems (4)
cover samples: bpf: fix build issues with Clang/LLVM
Samples, at least XDP ones, can be built only with the compiler used to build the kernel itself.
However, XDP sample infra introduced in Aug'21 was probably tested with GCC/Binutils only as it's not really compilable for now with Clang/LLVM.
These two are trivial fixes addressing this.
Alexander Lobakin (2):
samples: bpf: fix xdp_sample_user.o linking with Clang
samples: bpf: fix 'unknown warning group' build warning on Clang
samples/bpf/Makefile | 5 +++++ samples/bpf/Makefile.target | 2 +- samples/bpf/xdp_sample_user.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
2.33.1
PATCH 1/2 samples: bpf: fix xdp_sample_user.o linking with Clang
Clang (13) doesn't get the jokes about specifying libraries to link in cclags of individual .o objects:
clang-13: warning: -lm: 'linker' input unused [-Wunused-command-line-argument] [ ... ]
LD samples/bpf/xdp_redirect_cpu LD samples/bpf/xdp_redirect_map_multi LD samples/bpf/xdp_redirect_map LD samples/bpf/xdp_redirect LD samples/bpf/xdp_monitor
/usr/bin/ld: samples/bpf/xdp_sample_user.o: in function `sample_summary_print':
xdp_sample_user.c:(.text+0x84c): undefined reference to floor' /usr/bin/ld: xdp_sample_user.c:(.text+0x870): undefined reference to ceil' /usr/bin/ld: xdp_sample_user.c:(.text+0x8cf): undefined reference to floor' /usr/bin/ld: xdp_sample_user.c:(.text+0x8f3): undefined reference to ceil' [ more ]
Specify '-lm' as ldflags for all xdp_sample_user.o users in the main Makefile and remove it from ccflags of ^ in Makefile.target -- just like it's done for all other samples. This works with all compilers.
--- samples/bpf/Makefile | 5 +++++ samples/bpf/Makefile.target | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
samples/bpf/Makefile +5 -0
@@ -215,6 +215,11 @@ TPROGS_LDFLAGS := -L$(SYSROOT)/usr/lib endif TPROGS_LDLIBS += $(LIBBPF) -lelf -lz +TPROGLDLIBS_xdp_monitor += -lm +TPROGLDLIBS_xdp_redirect += -lm +TPROGLDLIBS_xdp_redirect_cpu += -lm +TPROGLDLIBS_xdp_redirect_map += -lm +TPROGLDLIBS_xdp_redirect_map_multi += -lm TPROGLDLIBS_tracex4 += -lrt TPROGLDLIBS_trace_output += -lrt TPROGLDLIBS_map_perf_test += -lrt
samples/bpf/Makefile.target +1 -1
@@ -76,7 +76,7 @@ $(tprog-cobjs): $(obj)/%.o: $(src)/%.c FORCE # Override includes for xdp_sample_user.o because $(srctree)/usr/include in # TPROGS_CFLAGS causes conflicts -XDP_SAMPLE_CFLAGS += -Wall -O2 -lm \ +XDP_SAMPLE_CFLAGS += -Wall -O2 \ -I./tools/include \ -I./tools/include/uapi \ -I./tools/lib \
Signature · 1 line
2.33.1
Re: [PATCH bpf 1/2] samples: bpf: fix xdp_sample_user.o linking with Clang
Quoted 21 lines · Alexander Lobakin
Clang (13) doesn't get the jokes about specifying libraries to link in cclags of individual .o objects:
clang-13: warning: -lm: 'linker' input unused [-Wunused-command-line-argument] [ ... ]
LD samples/bpf/xdp_redirect_cpu LD samples/bpf/xdp_redirect_map_multi LD samples/bpf/xdp_redirect_map LD samples/bpf/xdp_redirect LD samples/bpf/xdp_monitor
/usr/bin/ld:samples/bpf/xdp_sample_user.o: in function `sample_summary_print':
xdp_sample_user.c:(.text+0x84c): undefined reference tofloor' /usr/bin/ld: xdp_sample_user.c:(.text+0x870): undefined reference toceil'/usr/bin/ld: xdp_sample_user.c:(.text+0x8cf): undefined reference tofloor' /usr/bin/ld: xdp_sample_user.c:(.text+0x8f3): undefined reference toceil' [ more ]Specify '-lm' as ldflags for all xdp_sample_user.o users in the main
Makefileand remove it from ccflags of ^ in Makefile.target -- just like it's done for all other samples. This works with all compilers.
Quoted 7 lines
Fixes 6e1051a54e31 ("samples: bpf: Convert xdp_monitor to XDP samples helper")Fixes b926c55d856c ("samples: bpf: Convert xdp_redirect to XDP samples helper")Fixes e531a220cc59 ("samples: bpf: Convert xdp_redirect_cpu to XDP samples helper")Fixes bbe65865aa05 ("samples: bpf: Convert xdp_redirect_map to XDP samples helper")Fixes 594a116b2aa1 ("samples: bpf: Convert xdp_redirect_map_multi to XDP samples helper")Signed-off-by Alexander Lobakin <[email protected]>---
Thanks, something to remember to test for next time.
--
Kartikeya
PATCH 2/2 samples: bpf: fix 'unknown warning group' build warning on Clang
In reply to Alexander LobakinClang doesn't have 'stringop-truncation' group like GCC does, and complains about it when building samples which use xdp_sample_user infra:
samples/bpf/xdp_sample_user.h:48:32: warning: unknown warning group '-Wstringop-truncation', ignored [-Wunknown-warning-option] #pragma GCC diagnostic ignored "-Wstringop-truncation"
^
[ repeat ]
Those are harmless, but avoidable when guarding it with ifdef. I could guard push/pop as well, but this would require one more ifdef cruft around a single line which I don't think is reasonable.
--- samples/bpf/xdp_sample_user.h | 2 ++ 1 file changed, 2 insertions(+)
samples/bpf/xdp_sample_user.h +2 -0
@@ -45,7 +45,9 @@ const char *get_driver_name(int ifindex);int get_mac_addr (int ifindex,void *mac_addr);#pragma GCC diagnostic push +#ifndef __clang__#pragma GCC diagnostic ignored "-Wstringop-truncation" +#endif __attribute__((unused))static inline char *safe_strncpy (char *dst,const char *src,size_t size) {
Signature · 1 line
2.33.1
Re: [PATCH bpf 2/2] samples: bpf: fix 'unknown warning group' build warning on Clang
Quoted 9 lines · Alexander Lobakin
Clang doesn't have 'stringop-truncation' group like GCC does, and complains about it when building samples which use
xdp_sample_userinfra:
samples/bpf/xdp_sample_user.h:48:32: warning: unknown warning group '-Wstringop-truncation', ignored [-Wunknown-warning-option] #pragma GCC diagnostic ignored "-Wstringop-truncation"^[ repeat ]
Quoted 7 lines
Those are harmless, but avoidable when guarding it with ifdef. I could guard push/pop as well, but this would require one more ifdef cruft around a single line which I don't think is reasonable.
Fixes 156f886cf697 ("samples: bpf: Add basic infrastructure for XDP samples")Signed-off-by Alexander Lobakin <[email protected]>---
Quoted 1 line
[...]
--
Kartikeya
Quoted 8 lines · Alexander Lobakin
Samples, at least XDP ones, can be built only with the compiler used to build the kernel itself.
However, XDP sample infra introduced in Aug'21 was probably tested with GCC/Binutils only as it's not really compilable for now with Clang/LLVM.
These two are trivial fixes addressing this.
Quoted 4 lines
Alexander Lobakin (2):
samples: bpf: fix xdp_sample_user.o linking with Clang
samples: bpf: fix 'unknown warning group' build warning on Clang
There were conflicts when applying, but luckily I was the one who caused this conflict in XDP_SAMPLE_CFLAGS, so I just fixed it up locally and pushed to bpf-next. Thanks.
Quoted 8 lines
samples/bpf/Makefile | 5 +++++ samples/bpf/Makefile.target | 2 +- samples/bpf/xdp_sample_user.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-)--
2.33.1