linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf 0/2] samples: bpf: fix build issues with Clang/LLVM
@ 2021-12-03 19:50 Alexander Lobakin
  2021-12-03 19:50 ` [PATCH bpf 1/2] samples: bpf: fix xdp_sample_user.o linking with Clang Alexander Lobakin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-12-03 19:50 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Alexander Lobakin, Toke Høiland-Jørgensen,
	Kumar Kartikeya Dwivedi, John Fastabend, Jesper Dangaard Brouer,
	Nathan Chancellor, Nick Desaulniers, netdev, bpf, linux-kernel,
	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(-)

-- 
2.33.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH bpf 1/2] samples: bpf: fix xdp_sample_user.o linking with Clang
  2021-12-03 19:50 [PATCH bpf 0/2] samples: bpf: fix build issues with Clang/LLVM Alexander Lobakin
@ 2021-12-03 19:50 ` Alexander Lobakin
  2021-12-04  0:47   ` Kumar Kartikeya Dwivedi
  2021-12-03 19:50 ` [PATCH bpf 2/2] samples: bpf: fix 'unknown warning group' build warning on Clang Alexander Lobakin
  2021-12-07  3:35 ` [PATCH bpf 0/2] samples: bpf: fix build issues with Clang/LLVM Andrii Nakryiko
  2 siblings, 1 reply; 6+ messages in thread
From: Alexander Lobakin @ 2021-12-03 19:50 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Alexander Lobakin, Toke Høiland-Jørgensen,
	Kumar Kartikeya Dwivedi, John Fastabend, Jesper Dangaard Brouer,
	Nathan Chancellor, Nick Desaulniers, netdev, bpf, linux-kernel,
	llvm

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(-)

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 \
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf 2/2] samples: bpf: fix 'unknown warning group' build warning on Clang
  2021-12-03 19:50 [PATCH bpf 0/2] samples: bpf: fix build issues with Clang/LLVM Alexander Lobakin
  2021-12-03 19:50 ` [PATCH bpf 1/2] samples: bpf: fix xdp_sample_user.o linking with Clang Alexander Lobakin
@ 2021-12-03 19:50 ` Alexander Lobakin
  2021-12-04  0:47   ` Kumar Kartikeya Dwivedi
  2021-12-07  3:35 ` [PATCH bpf 0/2] samples: bpf: fix build issues with Clang/LLVM Andrii Nakryiko
  2 siblings, 1 reply; 6+ messages in thread
From: Alexander Lobakin @ 2021-12-03 19:50 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Alexander Lobakin, Toke Høiland-Jørgensen,
	Kumar Kartikeya Dwivedi, John Fastabend, Jesper Dangaard Brouer,
	Nathan Chancellor, Nick Desaulniers, netdev, bpf, linux-kernel,
	llvm

Clang 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.

Fixes: 156f886cf697 ("samples: bpf: Add basic infrastructure for XDP samples")
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
 samples/bpf/xdp_sample_user.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/samples/bpf/xdp_sample_user.h b/samples/bpf/xdp_sample_user.h
index d97465ff8c62..5f44b877ecf5 100644
--- a/samples/bpf/xdp_sample_user.h
+++ b/samples/bpf/xdp_sample_user.h
@@ -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)
 {
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf 1/2] samples: bpf: fix xdp_sample_user.o linking with Clang
  2021-12-03 19:50 ` [PATCH bpf 1/2] samples: bpf: fix xdp_sample_user.o linking with Clang Alexander Lobakin
@ 2021-12-04  0:47   ` Kumar Kartikeya Dwivedi
  0 siblings, 0 replies; 6+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2021-12-04  0:47 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Toke Høiland-Jørgensen, John Fastabend,
	Jesper Dangaard Brouer, Nathan Chancellor, Nick Desaulniers,
	netdev, bpf, linux-kernel, llvm

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf 2/2] samples: bpf: fix 'unknown warning group' build warning on Clang
  2021-12-03 19:50 ` [PATCH bpf 2/2] samples: bpf: fix 'unknown warning group' build warning on Clang Alexander Lobakin
@ 2021-12-04  0:47   ` Kumar Kartikeya Dwivedi
  0 siblings, 0 replies; 6+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2021-12-04  0:47 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Toke Høiland-Jørgensen, John Fastabend,
	Jesper Dangaard Brouer, Nathan Chancellor, Nick Desaulniers,
	netdev, bpf, linux-kernel, llvm

On Sat, Dec 04, 2021 at 01:20:04AM IST, Alexander Lobakin wrote:
> Clang 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.
>
> Fixes: 156f886cf697 ("samples: bpf: Add basic infrastructure for XDP samples")
> Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
> ---

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

> [...]

--
Kartikeya

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf 0/2] samples: bpf: fix build issues with Clang/LLVM
  2021-12-03 19:50 [PATCH bpf 0/2] samples: bpf: fix build issues with Clang/LLVM Alexander Lobakin
  2021-12-03 19:50 ` [PATCH bpf 1/2] samples: bpf: fix xdp_sample_user.o linking with Clang Alexander Lobakin
  2021-12-03 19:50 ` [PATCH bpf 2/2] samples: bpf: fix 'unknown warning group' build warning on Clang Alexander Lobakin
@ 2021-12-07  3:35 ` Andrii Nakryiko
  2 siblings, 0 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2021-12-07  3:35 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Toke Høiland-Jørgensen, Kumar Kartikeya Dwivedi,
	John Fastabend, Jesper Dangaard Brouer, Nathan Chancellor,
	Nick Desaulniers, Networking, bpf, open list, llvm

On Fri, Dec 3, 2021 at 11:55 AM Alexander Lobakin
<alexandr.lobakin@intel.com> wrote:
>
> 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
>

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.

>  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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-07  3:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 19:50 [PATCH bpf 0/2] samples: bpf: fix build issues with Clang/LLVM Alexander Lobakin
2021-12-03 19:50 ` [PATCH bpf 1/2] samples: bpf: fix xdp_sample_user.o linking with Clang Alexander Lobakin
2021-12-04  0:47   ` Kumar Kartikeya Dwivedi
2021-12-03 19:50 ` [PATCH bpf 2/2] samples: bpf: fix 'unknown warning group' build warning on Clang Alexander Lobakin
2021-12-04  0:47   ` Kumar Kartikeya Dwivedi
2021-12-07  3:35 ` [PATCH bpf 0/2] samples: bpf: fix build issues with Clang/LLVM Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).