]> git.dujemihanovic.xyz Git - linux.git/commitdiff
efi/libstub: zboot.lds: Discard .discard sections
authorNathan Chancellor <nathan@kernel.org>
Wed, 22 May 2024 17:32:43 +0000 (10:32 -0700)
committerArd Biesheuvel <ardb@kernel.org>
Thu, 23 May 2024 07:02:39 +0000 (09:02 +0200)
When building ARCH=loongarch defconfig + CONFIG_UNWINDER_ORC=y using
LLVM, there is a warning from ld.lld when linking the EFI zboot image
due to the use of unreachable() in number() in vsprintf.c:

  ld.lld: warning: drivers/firmware/efi/libstub/lib.a(vsprintf.stub.o):(.discard.unreachable+0x0): has non-ABS relocation R_LARCH_32_PCREL against symbol ''

If the compiler cannot eliminate the default case for any reason, the
.discard.unreachable section will remain in the final binary but the
entire point of any section prefixed with .discard is that it is only
used at compile time, so it can be discarded via /DISCARD/ in a linker
script. The asm-generic vmlinux.lds.h includes .discard and .discard.*
in the COMMON_DISCARDS macro but that is not used for zboot.lds, as it
is not a kernel image linker script.

Add .discard and .discard.* to /DISCARD/ in zboot.lds, so that any
sections meant to be discarded at link time are not included in the
final zboot image. This issue is not specific to LoongArch, it is just
the first architecture to select CONFIG_OBJTOOL, which defines
annotate_unreachable() as an asm statement to add the
.discard.unreachable section, and use the EFI stub.

Closes: https://github.com/ClangBuiltLinux/linux/issues/2023
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/zboot.lds

index ac8c0ef851581f5d3eb51260ac1d2a6b92955bb6..af2c82f7bd9024094470a443d46dfc3381862ec8 100644 (file)
@@ -41,6 +41,7 @@ SECTIONS
        }
 
        /DISCARD/ : {
+               *(.discard .discard.*)
                *(.modinfo .init.modinfo)
        }
 }