hvmloader: fix build with LLVM Linker
PATCH v2 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.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Ian Jackson <[email protected]>
---
Changes since v1:
- Also add .<section>.*.
--- 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
@@ -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
@@ -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) *(.text.*) } + .rodata : { *(.rodata) *(.rodata.*) } + .data : { *(.data) *(.data.*) } + .bss : { *(.bss) *(.bss.*) } + _end = .; +}
Signature · 7 lines
2.18.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 27 lines · Roger Pau Monne
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 0GNU 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 0x4Note that in the LLVM LD case (as with GNU LD) the .text section does indeed have the address set to
0x100000as requested on the command line:[ 1] .text PROGBITS 00100000 001000 00dd10 00 AX 0 0 16
Quoted 8 lines
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.
Signed-off-by Roger Pau Monné <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel