linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Fix cross compilation with CLANG_CROSS_FLAGS
@ 2023-02-17 15:18 Florent Revest
  2023-02-17 15:27 ` Florent Revest
  2023-02-22 21:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Florent Revest @ 2023-02-17 15:18 UTC (permalink / raw)
  To: bpf, linux-kselftest, linux-kernel, llvm, linux-kbuild
  Cc: andrii, mykolal, ast, daniel, kpsingh, masahiroy, nathan,
	ndesaulniers, Florent Revest

I cross-compile my BPF selftests with the following command:

CLANG_CROSS_FLAGS="--target=aarch64-linux-gnu --sysroot=/sysroot/" \
  make LLVM=1 CC=clang CROSS_COMPILE=aarch64-linux-gnu- SRCARCH=arm64

(Note the use of CLANG_CROSS_FLAGS to specify a custom sysroot instead
of letting clang use gcc's default sysroot)

However, CLANG_CROSS_FLAGS gets propagated to host tools builds (libbpf
and bpftool) and because they reference it directly in their Makefiles,
they end up cross-compiling host objects which results in linking
errors.

This patch ensures that CLANG_CROSS_FLAGS is reset if CROSS_COMPILE
isn't set (for example when reaching a BPF host tool build).

Signed-off-by: Florent Revest <revest@chromium.org>
---
 tools/scripts/Makefile.include | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
index 0efb8f2b33ce..ff527ac065cf 100644
--- a/tools/scripts/Makefile.include
+++ b/tools/scripts/Makefile.include
@@ -108,6 +108,8 @@ endif # GCC_TOOLCHAIN_DIR
 endif # CLANG_CROSS_FLAGS
 CFLAGS += $(CLANG_CROSS_FLAGS)
 AFLAGS += $(CLANG_CROSS_FLAGS)
+else
+CLANG_CROSS_FLAGS :=
 endif # CROSS_COMPILE
 
 # Hack to avoid type-punned warnings on old systems such as RHEL5:
-- 
2.39.2.637.g21b0678d19-goog


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

* Re: [PATCH bpf-next] selftests/bpf: Fix cross compilation with CLANG_CROSS_FLAGS
  2023-02-17 15:18 [PATCH bpf-next] selftests/bpf: Fix cross compilation with CLANG_CROSS_FLAGS Florent Revest
@ 2023-02-17 15:27 ` Florent Revest
  2023-02-22 21:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Florent Revest @ 2023-02-17 15:27 UTC (permalink / raw)
  To: bpf, linux-kselftest, linux-kernel, llvm, linux-kbuild
  Cc: andrii, mykolal, ast, daniel, kpsingh, masahiroy, nathan, ndesaulniers

On Fri, Feb 17, 2023 at 4:18 PM Florent Revest <revest@chromium.org> wrote:
>
> I cross-compile my BPF selftests with the following command:
>
> CLANG_CROSS_FLAGS="--target=aarch64-linux-gnu --sysroot=/sysroot/" \
>   make LLVM=1 CC=clang CROSS_COMPILE=aarch64-linux-gnu- SRCARCH=arm64
>
> (Note the use of CLANG_CROSS_FLAGS to specify a custom sysroot instead
> of letting clang use gcc's default sysroot)
>
> However, CLANG_CROSS_FLAGS gets propagated to host tools builds (libbpf
> and bpftool) and because they reference it directly in their Makefiles,
> they end up cross-compiling host objects which results in linking
> errors.
>
> This patch ensures that CLANG_CROSS_FLAGS is reset if CROSS_COMPILE
> isn't set (for example when reaching a BPF host tool build).

Note: I'm not entirely sure which tree should take that patch. I
tagged this patch as "bpf-next" because 1- that's the tree I know best
2- as far as I can tell, only BPF tools Makefiles reference
CLANG_CROSS_FLAGS directly and are currently broken in this way 3- I
figured this would be a simple enough patch that it's not too hard for
another tree to take it.

Anyway, I tried to CC other relevant folks, I figured there could be
different opinions on how this should get solved, for example the bpf
Makefiles using CLANG_CROSS_FLAGS could check whether CROSS_COMPILE is
set first. I'd be happy to adapt a v2 to any suggestion.

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

* Re: [PATCH bpf-next] selftests/bpf: Fix cross compilation with CLANG_CROSS_FLAGS
  2023-02-17 15:18 [PATCH bpf-next] selftests/bpf: Fix cross compilation with CLANG_CROSS_FLAGS Florent Revest
  2023-02-17 15:27 ` Florent Revest
@ 2023-02-22 21:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-02-22 21:10 UTC (permalink / raw)
  To: Florent Revest
  Cc: bpf, linux-kselftest, linux-kernel, llvm, linux-kbuild, andrii,
	mykolal, ast, daniel, kpsingh, masahiroy, nathan, ndesaulniers

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Fri, 17 Feb 2023 16:18:32 +0100 you wrote:
> I cross-compile my BPF selftests with the following command:
> 
> CLANG_CROSS_FLAGS="--target=aarch64-linux-gnu --sysroot=/sysroot/" \
>   make LLVM=1 CC=clang CROSS_COMPILE=aarch64-linux-gnu- SRCARCH=arm64
> 
> (Note the use of CLANG_CROSS_FLAGS to specify a custom sysroot instead
> of letting clang use gcc's default sysroot)
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: Fix cross compilation with CLANG_CROSS_FLAGS
    https://git.kernel.org/bpf/bpf-next/c/b539a287baaa

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-02-22 21:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-17 15:18 [PATCH bpf-next] selftests/bpf: Fix cross compilation with CLANG_CROSS_FLAGS Florent Revest
2023-02-17 15:27 ` Florent Revest
2023-02-22 21:10 ` patchwork-bot+netdevbpf

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