[Buildroot] [git commit branch/2022.05.x] package/bpftool: add a patch to fix cross compilation

Peter Korsgaard peter at korsgaard.com
Mon Jul 11 16:51:13 UTC 2022


commit: https://git.buildroot.net/buildroot/commit/?id=8ebacc810e95963c406674cfbaa4cf79e5bb80c9
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/2022.05.x

If on the host machine the "co-re" is supported, bpftool will
build a bootstrap version of itself as well. In that case, the
cross compilation can fail. This commit adds a patch to remedy
that. The fix that you see here is already upsteamed [1].

[1]
https://lore.kernel.org/bpf/165477661272.11342.13015777410417612477.git-patchwork-notify@kernel.org/T/#t

Signed-off-by: Shahab Vahedi <shahab at synopsys.com>
[Arnout: use upstream metadata for the patch]
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout at mind.be>
(cherry picked from commit ef65d04ccdb1fffd0151fa7b2979e000e586145d)
Signed-off-by: Peter Korsgaard <peter at korsgaard.com>
---
 ...-bootstrapping-during-a-cross-compilation.patch | 96 ++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/package/bpftool/0001-bpftool-Fix-bootstrapping-during-a-cross-compilation.patch b/package/bpftool/0001-bpftool-Fix-bootstrapping-during-a-cross-compilation.patch
new file mode 100644
index 0000000000..fc192681e3
--- /dev/null
+++ b/package/bpftool/0001-bpftool-Fix-bootstrapping-during-a-cross-compilation.patch
@@ -0,0 +1,96 @@
+From 189f777ea4829bede0bf92f572c22fe1f2c37522 Mon Sep 17 00:00:00 2001
+From: Shahab Vahedi <Shahab.Vahedi at synopsys.com>
+Date: Wed, 8 Jun 2022 14:29:28 +0000
+Subject: [PATCH] bpftool: Fix bootstrapping during a cross compilation
+
+This change adjusts the Makefile to use "HOSTAR" as the archive tool
+to keep the sanity of the build process for the bootstrap part in
+check. For the rationale, please continue reading.
+
+When cross compiling bpftool with buildroot, it leads to an invocation
+like:
+
+$ AR="/path/to/buildroot/host/bin/arc-linux-gcc-ar" \
+  CC="/path/to/buildroot/host/bin/arc-linux-gcc"    \
+  ...
+  make
+
+Which in return fails while building the bootstrap section:
+
+----------------------------------8<----------------------------------
+
+  make: Entering directory '/src/bpftool-v6.7.0/src'
+  ...                        libbfd: [ on  ]
+  ...        disassembler-four-args: [ on  ]
+  ...                          zlib: [ on  ]
+  ...                        libcap: [ OFF ]
+  ...               clang-bpf-co-re: [ on  ] <-- triggers bootstrap
+
+  .
+  .
+  .
+
+    LINK     /src/bpftool-v6.7.0/src/bootstrap/bpftool
+  /usr/bin/ld: /src/bpftool-v6.7.0/src/bootstrap/libbpf/libbpf.a:
+               error adding symbols: archive has no index; run ranlib
+               to add one
+  collect2: error: ld returned 1 exit status
+  make: *** [Makefile:211: /src/bpftool-v6.7.0/src/bootstrap/bpftool]
+            Error 1
+  make: *** Waiting for unfinished jobs....
+    AR       /src/bpftool-v6.7.0/src/libbpf/libbpf.a
+    make[1]: Leaving directory '/src/bpftool-v6.7.0/libbpf/src'
+    make: Leaving directory '/src/bpftool-v6.7.0/src'
+
+---------------------------------->8----------------------------------
+
+This occurs because setting "AR" confuses the build process for the
+bootstrap section and it calls "arc-linux-gcc-ar" to create and index
+"libbpf.a" instead of the host "ar".
+
+Signed-off-by: Shahab Vahedi <shahab at synopsys.com>
+Signed-off-by: Daniel Borkmann <daniel at iogearbox.net>
+Reviewed-by: Quentin Monnet <quentin at isovalent.com>
+Cc: Jean-Philippe Brucker <jean-philippe at linaro.org>
+Link: https://lore.kernel.org/bpf/8d297f0c-cfd0-ef6f-3970-6dddb3d9a87a@synopsys.com
+Upstream: https://github.com/libbpf/bpftool/commit/189f777ea4829bede0bf92f572c22fe1f2c37522
+
+This is an adapted version, else it won't be possible to cross compile
+bpftool if "clang-bpf-co-re" feature is enabled.
+---
+ src/Makefile | 2 +-
+ src/Makefile.include       | 2 ++
+ 2 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/src/Makefile b/src/Makefile
+index b657502..b8b0808 100644
+--- a/src/Makefile
++++ b/src/Makefile
+@@ -51,7 +51,7 @@ $(LIBBPF_INTERNAL_HDRS): $(LIBBPF_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_HDRS_
+ $(LIBBPF_BOOTSTRAP): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_BOOTSTRAP_OUTPUT)
+ 	$(Q)$(MAKE) -C $(BPF_DIR) OBJDIR=$(patsubst %/,%,$(LIBBPF_BOOTSTRAP_OUTPUT)) \
+ 		PREFIX=$(LIBBPF_BOOTSTRAP_DESTDIR:/=) \
+-		ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) $@ install_headers
++		ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) AR=$(HOSTAR) $@ install_headers
+ 
+ $(LIBBPF_BOOTSTRAP_INTERNAL_HDRS): $(LIBBPF_BOOTSTRAP_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_BOOTSTRAP_HDRS_DIR)
+ 	$(call QUIET_INSTALL, $@)
+--- a/src/Makefile.include
++++ b/src/Makefile.include
+@@ -12,11 +12,13 @@
+ ifneq ($(LLVM),)
+   $(if $(findstring default,$(origin CC)),$(eval CC := clang$(LLVM_VERSION)))
+   $(if $(findstring default,$(origin LD)),$(eval LD := ld.lld$(LLVM_VERSION)))
++  HOSTAR ?= llvm-ar
+   HOSTCC ?= clang
+   HOSTLD ?= ld.lld
+ else
+   $(if $(findstring default,$(origin CC)),$(eval CC = $(CROSS_COMPILE)$(CC)))
+   $(if $(findstring default,$(origin LD)),$(eval LD = $(CROSS_COMPILE)$(LD)))
++  HOSTAR ?= ar
+   HOSTCC ?= gcc
+   HOSTLD ?= ld
+ endif
+--
+2.35.3
+



More information about the buildroot mailing list