Skip to contentSkip to conversation

hvmloader: fix build with LLVM Linker

PATCH Superseded Roger Pau Monne 2 participants 4 messages Aug 24, 2018 – Sep 3, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hvmloader: fix build with LLVM Linker

The hvmloader binary generated when using LLVM LD doesn't work properly and seems to get stuck while trying to generate and load the ACPI tables. This is caused by the layout of the binary when linked with LLVM LD.

LLVM LD has a different default linker script that GNU LD, and the resulting hvmloader binary is slightly different:

LLVM LD:
Program Headers:

  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x000ff034 0x000ff034 0x00060 0x00060 R   0x4
  LOAD           0x000000 0x000ff000 0x000ff000 0x38000 0x38000 RWE 0x1000
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0

GNU LD:
Program Headers:

  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000080 0x00100000 0x00100000 0x36308 0x3fd74 RWE 0x10
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4

Note that in the LLVM LD case (as with GNU LD) the .text section does indeed have the address set to 0x100000 as requested on the command line:

[ 1] .text PROGBITS 00100000 001000 00dd10 00 AX 0 0 16

There's however the PHDR which is not present when using GNU LD.

Fix this by using a very simple linker script that generates the same binary regardless of whether LLVM or GNU LD is used. By using a linker script the usage of -Ttext can also be avoided by placing the desired .text load address directly in the linker script.

---
Jan Beulich <[email protected]>
Andrew Cooper <[email protected]>
Wei Liu <[email protected]>
Ian Jackson <[email protected]>

---
 tools/firmware/hvmloader/Makefile      |  7 ++-----
 tools/firmware/hvmloader/hvmloader.lds | 13 +++++++++++++
 2 files changed, 15 insertions(+), 5 deletions(-)
 create mode 100644 tools/firmware/hvmloader/hvmloader.lds
tools/firmware/hvmloader/Makefile +2 -5
index 496ac72b77..e980ce7c5f 100644
@@ -20,9 +20,6 @@
 XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/firmware/Rules.mk
 
-
-LOADADDR = 0x100000
-
 # SMBIOS spec requires format mm/dd/yyyy
 SMBIOS_REL_DATE ?= $(shell date +%m/%d/%Y)
 
@@ -82,8 +79,8 @@ vpath build.c $(ACPI_PATH)
 vpath static_tables.c $(ACPI_PATH)
 OBJS += $(ACPI_OBJS)
 
-hvmloader: $(OBJS)
-	$(LD) $(LDFLAGS_DIRECT) -N -Ttext $(LOADADDR) -o $@ $^
+hvmloader: $(OBJS) hvmloader.lds
+	$(LD) $(LDFLAGS_DIRECT) -N -T hvmloader.lds -o $@ $(OBJS)
 
 roms.inc: $(ROMS)
 	echo "/* Autogenerated file. DO NOT EDIT */" > [email protected]
tools/firmware/hvmloader/hvmloader.lds new file +13 -0
new file mode 100644
index 0000000000..15d8f38fff
@@ -0,0 +1,13 @@
+SECTIONS
+{
+  . = 0x100000;
+  /*
+   * NB: there's no need to use the AT keyword in order to set the LMA, by
+   * default the linker will use VMA = LMA unless specified otherwise.
+   */
+  .text : { *(.text) }
+  .rodata : { *(.rodata) }
+  .data : { *(.data) }
+  .bss : { *(.bss) }
+  _end = .;
+}
Signature · 7 lines
2.18.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.08.18 at 11:58, <[email protected]> wrote:
tools/firmware/hvmloader/hvmloader.lds new file +3 -0
@@ -0,0 +1,13 @@
+SECTIONS
+{
+  . = 0x100000;

tools/firmware/hvmloader/hvmloader.lds line 13

Quoted 10 lines
tools/firmware/hvmloader/hvmloader.lds new file +10 -0
+  /*
+   * NB: there's no need to use the AT keyword in order to set the LMA, by
+   * default the linker will use VMA = LMA unless specified otherwise.
+   */
+  .text : { *(.text) }
+  .rodata : { *(.rodata) }
+  .data : { *(.data) }
+  .bss : { *(.bss) }
+  _end = .;
+}

Is this really sufficient? Iirc the compiler could create quite a few more variants of the sections named above, like .rodata.str* or .text.cold. Hence at the very least I'd expect .<section> on the right sides above to be accompanied by .<section>.* .

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 24.08.18 at 11:58, <[email protected]> wrote:
tools/firmware/hvmloader/hvmloader.lds new file +10 -0
@@ -0,0 +1,13 @@
+SECTIONS
+{
+  . = 0x100000;
+  /*
+   * NB: there's no need to use the AT keyword in order to set the LMA, by
+   * default the linker will use VMA = LMA unless specified otherwise.
+   */
+  .text : { *(.text) }
+  .rodata : { *(.rodata) }
+  .data : { *(.data) }
Quoted 8 lines

tools/firmware/hvmloader/hvmloader.lds line 13

Quoted 3 lines
tools/firmware/hvmloader/hvmloader.lds new file +3 -0
+  .bss : { *(.bss) }
+  _end = .;
+}

Is this really sufficient? Iirc the compiler could create quite a few more variants of the sections named above, like .rodata.str* or .text.cold. Hence at the very least I'd expect .<section> on the right sides above to be accompanied by .<section>.* .

Right, ATM the compiler I'm using doesn't generate any of those, but you are correct that this could be the case.

Do you have a preference for adding .<section>.* instead of just using a single .<section>*?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 03.09.18 at 16:19, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 24.08.18 at 11:58, <[email protected]> wrote:
tools/firmware/hvmloader/hvmloader.lds new file +10 -0
@@ -0,0 +1,13 @@
+SECTIONS
+{
+  . = 0x100000;
+  /*
+   * NB: there's no need to use the AT keyword in order to set the LMA, by
+   * default the linker will use VMA = LMA unless specified otherwise.
+   */
+  .text : { *(.text) }
+  .rodata : { *(.rodata) }
+  .data : { *(.data) }
Quoted 8 lines

tools/firmware/hvmloader/hvmloader.lds line 13

Quoted 3 lines
tools/firmware/hvmloader/hvmloader.lds new file +3 -0
+  .bss : { *(.bss) }
+  _end = .;
+}

Is this really sufficient? Iirc the compiler could create quite a few more variants of the sections named above, like .rodata.str* or .text.cold. Hence at the very least I'd expect .<section> on the right sides above to be accompanied by .<section>.* .

Quoted 5 lines

Right, ATM the compiler I'm using doesn't generate any of those, but you are correct that this could be the case.

Do you have a preference for adding .<section>.* instead of just using a single .<section>*?

Yes, I think we shouldn't match more aggressively than we have to. .text.* etc are well known forms, and while .text1 etc may also be, I wouldn't want to match more exotic ones like .textual.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel