linker: fix build with LLVM LD
cover linker: fix build with LLVM LD
Hello,
LLVM LD doesn't remove quotes from sections names, and thus the resulting binary cannot be parsed by some tools due to the quoted sections names.
First patch has already been posted independently and got not enough Acks/RB, second patch depends on the first one and is the actual fix for the issue.
Thanks, Roger.
Roger Pau Monne (2):
kconfig: detect LD implementation linker/lld: do not generate quoted section names
xen/Kconfig | 6 ++++++ xen/arch/x86/xen.lds.S | 6 +++++- xen/include/xen/xen.lds.h | 8 ++++---- 3 files changed, 15 insertions(+), 5 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/2 kconfig: detect LD implementation
Detect GNU and LLVM ld implementations. This is required for further patches that will introduce diverging behaviour depending on the linker implementation in use.
Note that LLVM ld returns "compatible with GNU linkers" as part of the version string, so be on the safe side and use '^' to only match at the start of the line in case LLVM ever decides to change the text to use "compatible with GNU ld" instead.
---
This was discussed with Jan in:
https://lore.kernel.org/xen-devel/[email protected]/
While he would be fine to use the option if it was present, he isn't convinced tools capabilities should be recorded in Kconfig, and hence doesn't want to introduce the option himself (I hope I got this worded right).
--- xen/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+)
xen/Kconfig +6 -0
@@ -23,6 +23,12 @@ config CLANG_VERSION int default $(shell,$(srctree)/scripts/clang-version.sh $(CC)) +config LD_IS_GNU + def_bool $(success,$(LD) --version | head -n 1 | grep -q "^GNU ld") + +config LD_IS_LLVM + def_bool $(success,$(LD) --version | head -n 1 | grep -q "^LLD") + # -fvisibility=hidden reduces -fpic cost, if it's available config CC_HAS_VISIBILITY_ATTRIBUTE def_bool $(cc-option,-fvisibility=hidden)
Signature · 1 line
2.35.1
Re: [PATCH 1/2] kconfig: detect LD implementation
Hi Roger,
Quoted 11 lines · Roger Pau Monne
Detect GNU and LLVM ld implementations. This is required for further patches that will introduce diverging behaviour depending on the linker implementation in use.
Note that LLVM ld returns "compatible with GNU linkers" as part of the version string, so be on the safe side and use '^' to only match at the start of the line in case LLVM ever decides to change the text to use "compatible with GNU ld" instead.
Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Michal Orzel <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH 2/2 linker/lld: do not generate quoted section names
In reply to Roger Pau MonneLLVM LD doesn't strip the quotes from the section names, and so the resulting binary ends up with section names like:
[ 1] ".text" PROGBITS ffff82d040200000 00008000
000000000018cbc1 0000000000000000 AX 0 0 4096
This confuses some tools (like gdb) and prevents proper parsing of the binary.
The issue has already been reported and is being fixed in LLD. In order to workaround this issue and keep the GNU ld support define different DECL_SECTION macros depending on the used ld implementation.
Drop the quotes from the definitions of the debug sections in DECL_DEBUG{2}, as those quotes are not required for GNU ld either.
---
Reference to the patch for LLD:
https://reviews.llvm.org/D124266
--- xen/arch/x86/xen.lds.S | 6 +++++- xen/include/xen/xen.lds.h | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
xen/arch/x86/xen.lds.S +5 -1
@@ -20,7 +20,11 @@ ENTRY(efi_start) #else /* !EFI */ #define FORMAT "elf64-x86-64" -#define DECL_SECTION(x) #x : AT(ADDR(#x) - __XEN_VIRT_START) +#ifdef CONFIG_LD_IS_GNU +# define DECL_SECTION(x) x : AT(ADDR(#x) - __XEN_VIRT_START) +#else +# define DECL_SECTION(x) x : AT(ADDR(x) - __XEN_VIRT_START) +#endif ENTRY(start_pa)
xen/include/xen/xen.lds.h +4 -4
@@ -18,11 +18,11 @@* for PE output, in order to record that we'd prefer these sections to not * be loaded into memory. */ -#define DECL_DEBUG (x, a) #x ALIGN(a) (NOLOAD) : { *(x) } -#define DECL_DEBUG2 (x, y, a) #x ALIGN(a) (NOLOAD) : { *(x) *(y) } +#define DECL_DEBUG (x, a) x ALIGN(a) (NOLOAD) : { *(x) } +#define DECL_DEBUG2 (x, y, a) x ALIGN(a) (NOLOAD) : { *(x) *(y) }#else -#define DECL_DEBUG (x, a) #x 0 : { *(x) } -#define DECL_DEBUG2 (x, y, a) #x 0 : { *(x) *(y) } +#define DECL_DEBUG (x, a) x 0 : { *(x) } +#define DECL_DEBUG2 (x, y, a) x 0 : { *(x) *(y) }#endif /*
Signature · 1 line
2.35.1
Re: [PATCH 2/2] linker/lld: do not generate quoted section names
Quoted 14 lines · Roger Pau Monne
LLVM LD doesn't strip the quotes from the section names, and so the resulting binary ends up with section names like:
[ 1] ".text" PROGBITS
ffff82d04020000000008000000000000018cbc1 0000000000000000 AX 0 0 4096This confuses some tools (like gdb) and prevents proper parsing of the binary.
The issue has already been reported and is being fixed in LLD. In order to workaround this issue and keep the GNU ld support define different
DECL_SECTIONmacros depending on the used ld implementation.
Quoted 5 lines
Drop the quotes from the definitions of the debug sections in DECL_DEBUG{2}, as those quotes are not required for GNU ld either.
Fixes 6254920587c3 ('x86: quote section names when defining them in linker script')Signed-off-by Roger Pau Monné <[email protected]>