[PATCH v3 08/28] efi/libstub: Drop .discard.addressable from the stub objects

From: Josh Poimboeuf

Date: Mon Sep 21 2026 - 18:36:06 EST


On arm64, riscv and loongarch, the EFI stub objects are objcopy'd with
--prefix-alloc-sections=.init, which renames every allocatable section.

The .discard.addressable section is allocatable, so if
STACK_FRAME_NON_STANDARD() and __ADDRESSABLE() are used, the section
gets renamed and never discarded:

ld: warning: orphan section `.init.discard.addressable' from `vmlinux.o' being placed in section `.init.discard.addressable'

The section is also a problem for the stub's absolute relocation check
on some arches.

In preparation for using STACK_FRAME_NON_STANDARD() in libstub code,
remove the section for both cases.

Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
---
drivers/firmware/efi/libstub/Makefile | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index 77a2b2d74f3f6..0d5d99c3cacdd 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -155,6 +155,11 @@ STUBCOPY_FLAGS-$(CONFIG_LOONGARCH) += --prefix-alloc-sections=.init \
--prefix-symbols=__efistub_
STUBCOPY_RELOC-$(CONFIG_LOONGARCH) := R_LARCH_MARK_LA

+# Drop the section created by __ADDRESSABLE() from the absolute symbol check
+# and the objcopy, otherwise it gets prefixed and doesn't get discared.
+STUBCOPY_RM_SECTIONS := --remove-section=.discard.addressable
+STUBCOPY_FLAGS-y += $(STUBCOPY_RM_SECTIONS)
+
$(obj)/%.stub.o: $(obj)/%.o FORCE
$(call if_changed,stubcopy)

@@ -166,7 +171,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
#
quiet_cmd_stubcopy = STUBCPY $@
cmd_stubcopy = \
- $(STRIP) --strip-debug -o $@ $<; \
+ $(STRIP) --strip-debug $(STUBCOPY_RM_SECTIONS) -o $@ $<; \
if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then \
echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \
/bin/false; \
--
2.55.0