efi/libstub/x86: work around LLVM ELF quirk build regression
Ard Biesheuvel
maintainerPATCH 1/1 efi/libstub/x86: work around LLVM ELF quirk build regression
When building the x86 EFI stub with Clang, the libstub Makefile rules that manipulate the ELF object files may throw an error like:
STUBCPY drivers/firmware/efi/libstub/efi-stub-helper.stub.o
strip: drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10
objcopy: drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10
This is the result of a LLVM 'feature' [0] where symbol references are stored in a LLVM specific .llvm_addrsig section in a non-transparent way, causing generic ELF tools such as strip or objcopy to choke on them.
So drop the .llvm_addrsig section explicitly as well, to work around this behavior.
[0] https://sourceware.org/bugzilla/show_bug.cgi?id=23817
--- drivers/firmware/efi/libstub/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/firmware/efi/libstub/Makefile +3 -2
@@ -66,7 +66,8 @@ CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) # .data section of the compressed kernel to ensure initialization. Rename the # .bss section here so it's easy to pick out in the linker script. # -STUBCOPY_FLAGS-$(CONFIG_X86) += --rename-section .bss=.bss.efistub,load,alloc +STUBCOPY_FLAGS-$(CONFIG_X86) += -R .llvm_addrsig \ + --rename-section .bss=.bss.efistub,load,alloc STUBCOPY_RELOC-$(CONFIG_X86_32) := R_386_32 STUBCOPY_RELOC-$(CONFIG_X86_64) := R_X86_64_64
@@ -111,7 +112,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE # quiet_cmd_stubcopy = STUBCPY $@ cmd_stubcopy = \ - $(STRIP) --strip-debug -o $@ $<; \ + $(STRIP) --strip-debug -R .llvm_addrsig -o $@ $<; \ if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then \ echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \ /bin/false; \
Signature · 1 line
2.17.1
Quoted 8 lines · Ard Biesheuvel
When building the x86 EFI stub with Clang, the libstub
Makefilerules that manipulate the ELF object files may throw an error like:STUBCPY
drivers/firmware/efi/libstub/efi-stub-helper.stub.o
strip:drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10
objcopy:drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10
Quoted 8 lines
This is the result of a LLVM 'feature' [0] where symbol references are stored in a LLVM specific .llvm_addrsig section in a non-transparent way, causing generic ELF tools such as strip or objcopy to choke on them.
So drop the .llvm_addrsig section explicitly as well, to work around this behavior.
This page also has info about the extension:
https://llvm.org/docs/Extensions.html#sht-llvm-addrsig-section-address-significance-table
Peter, do you know if it's possible to prevent the emission of this section from clang? Scanning through the sources, it looks like it's set unconditionally during LTO, but I couldn't find where else? Is this section required for more than LTO?
We need a generic way to disable LLVM extensions when we're not using the LLVM binutils. We have a couple cases where -no-integrated-as will prevent AsmStreamer from not using assembler extensions, but in this case it's the linker+objcopy+strip that don't work with the extensions.
Quoted 3 lines
Cc Nick Desaulniers <[email protected]>Reported-by Arnd Bergmann <[email protected]>
Do you have a link to the configs or report so we can repro?
Also, scripts/get_maintainer.pl should recommend our list for patches mentioning clang or llvm, which is a wider audience that can help test and review. I've been out sick much of the past week, so I appreciate the shared help with code review. Of course if your intention was to be more discreet, I'm sorry I may have just messed that up.
Quoted 10 lines
Signed-off-by Ard Biesheuvel <[email protected]>--- drivers/firmware/efi/libstub/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/firmware/efi/libstub/Makefile +0
-0
drivers/firmware/efi/libstub/Makefile CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) · line 70
Quoted 6 lines
drivers/firmware/efi/libstub/Makefile +2
-1@@ -66,7 +66,8 @@ CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) # .data section of the compressed kernel to ensure initialization. Rename the # .bss section here so it's easy to pick out in the linker script. # -STUBCOPY_FLAGS-$(CONFIG_X86) += --rename-section .bss=.bss.efistub,load,alloc +STUBCOPY_FLAGS-$(CONFIG_X86) += -R .llvm_addrsig \ + --rename-section .bss=.bss.efistub,load,alloc
Do we only observe this for x86, not ARM?
Quoted 13 lines
drivers/firmware/efi/libstub/Makefile +1
-2STUBCOPY_RELOC-$(CONFIG_X86_32) := R_386_32 STUBCOPY_RELOC-$(CONFIG_X86_64) := R_X86_64_64@@ -111,7 +112,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE # quiet_cmd_stubcopy = STUBCPY $@ cmd_stubcopy = \ - $(STRIP) --strip-debug -o $@ $<; \ + $(STRIP) --strip-debug -R .llvm_addrsig -o $@ $<; \ if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then \ echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \ /bin/false; \ --
Quoted 2 lines
2.17.1
In the absence of a linker script where we can use DISCARD rules, this looks like the best approach, though I'm still curious about ARM.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 7 lines · Nick Desaulniers' via Clang Built Linux
Quoted 3 lines · Ard Biesheuvel
Cc Nick Desaulniers <[email protected]>Reported-by Arnd Bergmann <[email protected]>Do you have a link to the configs or report so we can repro?
I ran into this four times over a day, here are two such configs:
https://pastebin.com/raw/cjNdRfF4
https://pastebin.com/raw/pYKUrW56
Arnd
Quoted 16 lines · Nick Desaulniers
Quoted 15 lines · Ard Biesheuvel
When building the x86 EFI stub with Clang, the libstub
Makefilerules that manipulate the ELF object files may throw an error like:STUBCPY
drivers/firmware/efi/libstub/efi-stub-helper.stub.o
strip:drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10
objcopy:drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10This is the result of a LLVM 'feature' [0] where symbol references are stored in a LLVM specific .llvm_addrsig section in a non-transparent way, causing generic ELF tools such as strip or objcopy to choke on them.
So drop the .llvm_addrsig section explicitly as well, to work around this behavior.
Quoted 8 lines
Quoted 1 line
This page also has info about the extension:
https://llvm.org/docs/Extensions.html#sht-llvm-addrsig-section-address-significance-table
Peter, do you know if it's possible to prevent the emission of this section from clang? Scanning through the sources, it looks like it's set unconditionally during LTO, but I couldn't find where else? Is this section required for more than LTO?
-faddrsig has been the default for many platforms since clang 7. You can find the current default state on various platforms here:
https://github.com/llvm/llvm-project/blob/master/clang/lib/Driver/ToolChains/Clang.cpp#L6157
The table may have other benefits but currently the only use case is lld --icf=safe , which is safer and better than gold's --icf=safe (which relies on (hacky) relocation scanning).
The current way things work:
(1) clang always emits .llvm_addrsig
(2) if the linker is lld and --icf=safe is specified, .llvm_addrsig is read to perform safe ICF
makes it easy for people to try --icf=safe, otherwise people will need to change CFLAGS as well to try the linker size optimization.
This section has nothing to do with LTO.
I am a bit surprised that certain strip can error "Failed to find link section for section 10" They were expected to set sh_link to 0.
Quoted 5 lines
We need a generic way to disable LLVM extensions when we're not using the LLVM binutils. We have a couple cases where
-no-integrated-aswill prevent AsmStreamer from not using assembler extensions, but in this case it's the linker+objcopy+strip that don't work with the extensions.
objcopy -R .llvm_addrsig can be used when it is difficult to pass -fno-addrsig
If possible, use -fno-addrsig instead.
Quoted 53 lines
Quoted 3 lines
Cc Nick Desaulniers <[email protected]>Reported-by Arnd Bergmann <[email protected]>Do you have a link to the configs or report so we can repro?
Also,
scripts/get_maintainer.plshould recommend our list for patches mentioning clang or llvm, which is a wider audience that can help test and review. I've been out sick much of the past week, so I appreciate the shared help with code review. Of course if your intention was to be more discreet, I'm sorry I may have just messed that up.Quoted 10 lines
Signed-off-by Ard Biesheuvel <[email protected]>--- drivers/firmware/efi/libstub/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/firmware/efi/libstub/Makefile +0
-0drivers/firmware/efi/libstub/Makefile CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) · line 70
Quoted 6 lines
drivers/firmware/efi/libstub/Makefile +2
-1@@ -66,7 +66,8 @@ CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) # .data section of the compressed kernel to ensure initialization. Rename the # .bss section here so it's easy to pick out in the linker script. # -STUBCOPY_FLAGS-$(CONFIG_X86) += --rename-section .bss=.bss.efistub,load,alloc +STUBCOPY_FLAGS-$(CONFIG_X86) += -R .llvm_addrsig \ + --rename-section .bss=.bss.efistub,load,allocDo we only observe this for x86, not ARM?
Quoted 13 lines
drivers/firmware/efi/libstub/Makefile +1
-2STUBCOPY_RELOC-$(CONFIG_X86_32) := R_386_32 STUBCOPY_RELOC-$(CONFIG_X86_64) := R_X86_64_64@@ -111,7 +112,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE # quiet_cmd_stubcopy = STUBCPY $@ cmd_stubcopy = \ - $(STRIP) --strip-debug -o $@ $<; \ + $(STRIP) --strip-debug -R .llvm_addrsig -o $@ $<; \ if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then \ echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \ /bin/false; \ --Quoted 2 lines
2.17.1
In the absence of a linker script where we can use
DISCARDrules, this looks like the best approach, though I'm still curious about ARM.Reviewed-by Nick Desaulniers <[email protected]>Signature · 2 lines
Thanks, ~Nick Desaulniers