[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2] 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.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Cc: Jan Beulich <jbeulich@xxxxxxxx>
Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Cc: Wei Liu <wei.liu2@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
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

diff --git a/tools/firmware/hvmloader/Makefile 
b/tools/firmware/hvmloader/Makefile
index 496ac72b77..e980ce7c5f 100644
--- a/tools/firmware/hvmloader/Makefile
+++ b/tools/firmware/hvmloader/Makefile
@@ -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 */" > $@.new
diff --git a/tools/firmware/hvmloader/hvmloader.lds 
b/tools/firmware/hvmloader/hvmloader.lds
new file mode 100644
index 0000000000..4471d7af27
--- /dev/null
+++ b/tools/firmware/hvmloader/hvmloader.lds
@@ -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 = .;
+}
-- 
2.18.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.