arm64/efi: Mark __efistub_stext_offset as an absolute symbol explicitly
PATCH 1/1 arm64/efi: Mark __efistub_stext_offset as an absolute symbol explicitly
After r363059 and r363928 in LLVM, a build using ld.lld as the linker with CONFIG_RANDOMIZE_BASE enabled fails like so:
ld.lld: error: relocation R_AARCH64_ABS32 cannot be used against symbol __efistub_stext_offset; recompile with -fPIC
Fangrui and Peter figured out that ld.lld is incorrectly considering __efistub_stext_offset as a relative symbol because of the order in which symbols are evaluated. _text is treated as an absolute symbol and stext is a relative symbol, making __efistub_stext_offset a relative symbol.
Adding ABSOLUTE will force ld.lld to evalute this expression in the right context and does not change ld.bfd's behavior. ld.lld will need to be fixed but the developers do not see a quick or simple fix without some research (see the linked issue for further explanation). Add this simple workaround so that ld.lld can continue to link kernels.
--- arch/arm64/kernel/image.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/image.h +1 -1
@@ -67,7 +67,7 @@#ifdef CONFIG_EFI -__efistub_stext_offset = stext - _text; +__efistub_stext_offset =ABSOLUTE (stext - _text);/* * The EFI stub has its own symbol namespace prefixed by __efistub_, to
Signature · 1 line
2.22.0
Quoted 46 lines · Nathan Chancellor
After r363059 and r363928 in LLVM, a build using ld.lld as the linker with
CONFIG_RANDOMIZE_BASEenabled fails like so:ld.lld: error: relocation
R_AARCH64_ABS32cannot be used against symbol__efistub_stext_offset; recompile with -fPICFangrui and Peter figured out that ld.lld is incorrectly considering
__efistub_stext_offsetas a relative symbol because of the order in which symbols are evaluated._textis treated as an absolute symbol and stext is a relative symbol, making__efistub_stext_offseta relative symbol.Adding ABSOLUTE will force ld.lld to evalute this expression in the right context and does not change ld.bfd's behavior. ld.lld will need to be fixed but the developers do not see a quick or simple fix without some research (see the linked issue for further explanation). Add this simple workaround so that ld.lld can continue to link kernels.
Debugged-by Fangrui Song <[email protected]>Debugged-by Peter Smith <[email protected]>Suggested-by Fangrui Song <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- arch/arm64/kernel/image.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kernel/image.h +1
-2@@ -67,7 +67,7 @@#ifdef CONFIG_EFI -__efistub_stext_offset = stext - _text; +__efistub_stext_offset =ABSOLUTE (stext - _text);/* * The EFI stub has its own symbol namespace prefixed by __efistub_, to -- 2.22.0
Quoted 19 lines · Nathan Chancellor
After r363059 and r363928 in LLVM, a build using ld.lld as the linker with
CONFIG_RANDOMIZE_BASEenabled fails like so:ld.lld: error: relocation
R_AARCH64_ABS32cannot be used against symbol__efistub_stext_offset; recompile with -fPICFangrui and Peter figured out that ld.lld is incorrectly considering
__efistub_stext_offsetas a relative symbol because of the order in which symbols are evaluated._textis treated as an absolute symbol and stext is a relative symbol, making__efistub_stext_offseta relative symbol.Adding ABSOLUTE will force ld.lld to evalute this expression in the right context and does not change ld.bfd's behavior. ld.lld will need to be fixed but the developers do not see a quick or simple fix without some research (see the linked issue for further explanation). Add this simple workaround so that ld.lld can continue to link kernels.
Quoted 7 lines
Debugged-by Fangrui Song <[email protected]>Debugged-by Peter Smith <[email protected]>Suggested-by Fangrui Song <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>
Quoted 20 lines
--- arch/arm64/kernel/image.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kernel/image.h +1
-2@@ -67,7 +67,7 @@#ifdef CONFIG_EFI -__efistub_stext_offset = stext - _text; +__efistub_stext_offset =ABSOLUTE (stext - _text);/* * The EFI stub has its own symbol namespace prefixed by __efistub_, to -- 2.22.0
Will Deacon
maintainerQuoted 29 lines · Ard Biesheuvel
Quoted 19 lines · Nathan Chancellor
After r363059 and r363928 in LLVM, a build using ld.lld as the linker with
CONFIG_RANDOMIZE_BASEenabled fails like so:ld.lld: error: relocation
R_AARCH64_ABS32cannot be used against symbol__efistub_stext_offset; recompile with -fPICFangrui and Peter figured out that ld.lld is incorrectly considering
__efistub_stext_offsetas a relative symbol because of the order in which symbols are evaluated._textis treated as an absolute symbol and stext is a relative symbol, making__efistub_stext_offseta relative symbol.Adding ABSOLUTE will force ld.lld to evalute this expression in the right context and does not change ld.bfd's behavior. ld.lld will need to be fixed but the developers do not see a quick or simple fix without some research (see the linked issue for further explanation). Add this simple workaround so that ld.lld can continue to link kernels.
Quoted 7 lines
Debugged-by Fangrui Song <[email protected]>Debugged-by Peter Smith <[email protected]>Suggested-by Fangrui Song <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>
Quoted 1 line
Acked-by Ard Biesheuvel <[email protected]>
Thanks. I'll pick this up and add the link to the Clang issue as a comment in the header.
Will