summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Spooren2026-09-23 08:46:11 +0000
committerPaul Spooren2026-09-25 07:13:47 +0000
commit6c03a267b09b2d8bd7ddd4f6e7e702efe71202f1 (patch)
treec15b971716a2db585361efe78b24a7b1e14fa3c7
parentad1b1f2d36aacf13e3f983a1bdf4d699ef929ae3 (diff)
build: bpf: remap build paths in BTF line info
CompileBPF calls clang with -g but without any prefix map. Stripping debug info keeps .BTF and .BTF.ext, since libbpf needs them, and their line info carries the absolute path of each source file. This makes BPF objects like qosify-bpf.o depend on the build directory and breaks reproducibility: -/builder/shared-workdir/build/build_dir/.../qosify-bpf.c +/tmp/rebuilderd-openwrt.juCsuQ/src/build_dir/.../qosify-bpf.c IREMAP_CFLAGS is not enough here: without CONFIG_REPRODUCIBLE_DEBUG_INFO it only sets -fmacro-prefix-map, which leaves the line info alone, and it is empty for external toolchains, which have no say over the host clang. Unlike regular debug info, BTF ships with the package, so always pass -ffile-prefix-map for the build and staging directories. Add an fremap helper next to iremap for that, and let IREMAP_STAGING_DIR and CompileBPF share the map of the staging directory, so they cannot drift apart. Link: https://github.com/openwrt/openwrt/pull/25359 Signed-off-by: Paul Spooren <mail@aparcar.org>
-rw-r--r--include/bpf.mk6
-rw-r--r--rules.mk9
2 files changed, 13 insertions, 2 deletions
diff --git a/include/bpf.mk b/include/bpf.mk
index b9c8034c68..82025eb9a9 100644
--- a/include/bpf.mk
+++ b/include/bpf.mk
@@ -74,6 +74,10 @@ BPF_CFLAGS := \
-Wno-unused-label \
-O2 -emit-llvm -Xclang -disable-llvm-passes
+BPF_IREMAP_CFLAGS := \
+ $(call fremap,$(PKG_BUILD_DIR),$(notdir $(PKG_BUILD_DIR))) \
+ $(call remap_staging_dir,fremap)
+
ifneq ($(CONFIG_HAS_BPF_TOOLCHAIN),)
ifeq ($(DUMP)$(filter download refresh,$(MAKECMDGOALS)),)
CLANG_VER:=$(shell $(CLANG) --target=$(BPF_TARGET) -dM -E - < /dev/null | grep __clang_major__ | cut -d' ' -f3)
@@ -85,7 +89,7 @@ endif
endif
define CompileBPF
- $(CLANG) -g -target $(BPF_ARCH)-linux-gnu $(BPF_CFLAGS) $(2) \
+ $(CLANG) -g -target $(BPF_ARCH)-linux-gnu $(BPF_CFLAGS) $(BPF_IREMAP_CFLAGS) $(2) \
-c $(1) -o $(patsubst %.c,%.bc,$(1))
$(LLVM_OPT) -O2 -mtriple=$(BPF_TARGET) < $(patsubst %.c,%.bc,$(1)) > $(patsubst %.c,%.opt,$(1))
$(LLVM_DIS) < $(patsubst %.c,%.opt,$(1)) > $(patsubst %.c,%.S,$(1))
diff --git a/rules.mk b/rules.mk
index 3adf4ec2fc..82b83dcc55 100644
--- a/rules.mk
+++ b/rules.mk
@@ -181,11 +181,18 @@ ifeq ($(or $(CONFIG_EXTERNAL_TOOLCHAIN),$(CONFIG_TARGET_uml)),)
iremap = -f$(if $(CONFIG_REPRODUCIBLE_DEBUG_INFO),file,macro)-prefix-map=$(1)=$(2)
endif
+# Unlike iremap, always rewrite the paths in the debug information, for output
+# that ships with it, such as the BTF of BPF objects.
+fremap = -ffile-prefix-map=$(1)=$(2)
+
# A header taken from the staging directory reaches __FILE__ and the debug
# information with its absolute path, which no other map covers. Keep the
# staging_dir element, so that the result stays apart from the map of
# BUILD_DIR, whose last element carries the same name.
-IREMAP_STAGING_DIR = $(call iremap,$(STAGING_DIR),staging_dir/$(notdir $(STAGING_DIR)))
+#
+# @param 1: Name of the map helper, iremap or fremap.
+remap_staging_dir = $(call $(1),$(STAGING_DIR),staging_dir/$(notdir $(STAGING_DIR)))
+IREMAP_STAGING_DIR = $(call remap_staging_dir,iremap)
PACKAGE_DIR?=$(BIN_DIR)/packages
PACKAGE_DIR_ALL?=$(TOPDIR)/staging_dir/packages/$(BOARD)