Skip to contentSkip to conversation

x86: quote section names when defining them in linker script

PATCH In review Roger Pau Monne 2 participants 2 messages Sep 15, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: quote section names when defining them in linker script

LLVM ld seems to require section names to be quoted at both definition and when referencing them for a match to happen, or else we get the following errors:

ld: error: xen.lds:45: undefined section ".text"
ld: error: xen.lds:69: undefined section ".rodata"
ld: error: xen.lds:104: undefined section ".note.gnu.build-id" [...]

The original fix for GNU ld 2.37 only quoted the section name when referencing it in the ADDR function. Fix by also quoting the section names when declaring them.

Fixes 58ad654ebce7 ("x86: work around build issue with GNU ld 2.37")

---
This seems to make all versions that we test in gitlab happy:
https://gitlab.com/xen-project/people/royger/xen/-/pipelines/370610794
Plus the FreeBSD Cirrus-CI:
https://cirrus-ci.com/build/6690836768358400

I'm slightly worried that LLVM ld requires quotes to be present always in order to match, but I can confirm such quotes are not present in the sections names in the output binary.

---
 xen/arch/x86/xen.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/xen.lds.S +1 -1
index 955d5cf4a0..11b1da2154 100644
@@ -18,7 +18,7 @@ ENTRY(efi_start)
 #else /* !EFI */
 
 #define FORMAT "elf64-x86-64"
-#define DECL_SECTION(x) x : AT(ADDR(#x) - __XEN_VIRT_START)
+#define DECL_SECTION(x) #x : AT(ADDR(#x) - __XEN_VIRT_START)
 
 ENTRY(start_pa)
 
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Roger Pau Monne

LLVM ld seems to require section names to be quoted at both definition and when referencing them for a match to happen, or else we get the following errors:

ld: error: xen.lds:45: undefined section ".text"
ld: error: xen.lds:69: undefined section ".rodata"
ld: error: xen.lds:104: undefined section ".note.gnu.build-id" [...]

Quoted 7 lines

The original fix for GNU ld 2.37 only quoted the section name when referencing it in the ADDR function. Fix by also quoting the section names when declaring them.

Fixes 58ad654ebce7 ("x86: work around build issue with GNU ld 2.37")
Quoted 3 lines

I'm slightly worried that LLVM ld requires quotes to be present always in order to match, but I can confirm such quotes are not present in the sections names in the output binary.

They're "drop in replacement" statement clearly is too ambitious.

xen/arch/x86/xen.lds.S ENTRY(efi_start) · line 21

Quoted 8 lines
xen/arch/x86/xen.lds.S +1 -1
@@ -18,7 +18,7 @@ ENTRY(efi_start)
 #else /* !EFI */
 
 #define FORMAT "elf64-x86-64"
-#define DECL_SECTION(x) x : AT(ADDR(#x) - __XEN_VIRT_START)
+#define DECL_SECTION(x) #x : AT(ADDR(#x) - __XEN_VIRT_START)

Indeed much neater an adjustment. Thanks!

Jan