From 5888bd8c576e50fcd2bc9c91a15aba0801195f8d Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Sat, 3 Oct 2026 22:40:35 +0200 Subject: [PATCH] kernel: map the toolchain directory out of the debug information The compressed LoongArch kernel (vmlinuz.efi) differs between builds in different directories. The code and data of vmlinux are identical, but its GNU build ID is not: the debug information of vmlinux holds a single absolute path, the include directory of the compiler, e.g. /builder/shared-workdir/build/staging_dir/toolchain-loongarch64_generic_gcc-14.4.0_musl/lib/gcc/loongarch64-openwrt-linux-musl/14.4.0/include asm/loongarch.h includes the compiler's larchintrin.h, so core files like arch/loongarch/kernel/cpu-probe.c refer to it. The prefix maps of the kernel cover the build and the staging directory, but not the toolchain directory. The build ID hashes all of vmlinux, so it depends on the build directory, and with it the compressed kernel. Map the toolchain directory as well, like the staging directory. On loongarch64/generic, vmlinux built without the map holds this one absolute path, like the published one; built with it, no absolute path is left, while .text, .rodata and .data stay byte-identical. Link: https://github.com/openwrt/openwrt/pull/25648 Signed-off-by: Paul Spooren --- include/kernel.mk | 4 ++-- rules.mk | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/kernel.mk b/include/kernel.mk index 44be1e6c7c6..30557b56400 100644 --- a/include/kernel.mk +++ b/include/kernel.mk @@ -101,8 +101,8 @@ endif KERNEL_MAKE = $(MAKE) $(KERNEL_MAKEOPTS) KERNEL_MAKE_FLAGS = \ - KCFLAGS="$(call iremap,$(BUILD_DIR),$(notdir $(BUILD_DIR))) $(IREMAP_STAGING_DIR) $(filter-out -fno-plt,$(call qstrip,$(CONFIG_EXTRA_OPTIMIZATION))) $(call qstrip,$(CONFIG_KERNEL_CFLAGS))" \ - KAFLAGS="$(call iremap,$(BUILD_DIR),$(notdir $(BUILD_DIR))) $(IREMAP_STAGING_DIR)" \ + KCFLAGS="$(call iremap,$(BUILD_DIR),$(notdir $(BUILD_DIR))) $(IREMAP_STAGING_DIR) $(IREMAP_TOOLCHAIN_DIR) $(filter-out -fno-plt,$(call qstrip,$(CONFIG_EXTRA_OPTIMIZATION))) $(call qstrip,$(CONFIG_KERNEL_CFLAGS))" \ + KAFLAGS="$(call iremap,$(BUILD_DIR),$(notdir $(BUILD_DIR))) $(IREMAP_STAGING_DIR) $(IREMAP_TOOLCHAIN_DIR)" \ HOSTCFLAGS="$(HOST_CFLAGS) -Wall -Wmissing-prototypes -Wstrict-prototypes" \ CROSS_COMPILE="$(KERNEL_CROSS)" \ ARCH="$(LINUX_KARCH)" \ diff --git a/rules.mk b/rules.mk index 82b83dcc559..18f2ca289fe 100644 --- a/rules.mk +++ b/rules.mk @@ -194,6 +194,10 @@ fremap = -ffile-prefix-map=$(1)=$(2) remap_staging_dir = $(call $(1),$(STAGING_DIR),staging_dir/$(notdir $(STAGING_DIR))) IREMAP_STAGING_DIR = $(call remap_staging_dir,iremap) +# The compiler's own headers, e.g. larchintrin.h which the LoongArch kernel +# includes, come with the absolute path of the toolchain directory. +IREMAP_TOOLCHAIN_DIR = $(call iremap,$(TOOLCHAIN_DIR),staging_dir/$(notdir $(TOOLCHAIN_DIR))) + PACKAGE_DIR?=$(BIN_DIR)/packages PACKAGE_DIR_ALL?=$(TOPDIR)/staging_dir/packages/$(BOARD) BUILD_DIR:=$(BUILD_DIR_BASE)/$(TARGET_DIR_NAME)