diff mbox series

[bpf,1/2] samples: bpf: fix xdp_sample_user.o linking with Clang

Message ID 20211203195004.5803-2-alexandr.lobakin@intel.com (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series samples: bpf: fix build issues with Clang/LLVM | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 6 maintainers not CCed: kafai@fb.com songliubraving@fb.com kuba@kernel.org davem@davemloft.net kpsingh@kernel.org yhs@fb.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf fail VM_Test
bpf/vmtest-bpf-PR fail PR summary

Commit Message

Alexander Lobakin Dec. 3, 2021, 7:50 p.m. UTC
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.

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 <alexandr.lobakin@intel.com>
---
 samples/bpf/Makefile        | 5 +++++
 samples/bpf/Makefile.target | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Kumar Kartikeya Dwivedi Dec. 4, 2021, 12:47 a.m. UTC | #1
On Sat, Dec 04, 2021 at 01:20:03AM IST, Alexander Lobakin wrote:
> 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.
>
> 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 <alexandr.lobakin@intel.com>
> ---

Thanks, something to remember to test for next time.

Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

--
Kartikeya
diff mbox series

Patch

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index a886dff1ba89..e5b049ad5447 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -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
diff --git a/samples/bpf/Makefile.target b/samples/bpf/Makefile.target
index 5a368affa038..379560f11db4 100644
--- a/samples/bpf/Makefile.target
+++ b/samples/bpf/Makefile.target
@@ -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 \