Skip to contentSkip to conversation

EFI build with -ffunction-sections fails.

PATCH In review Konrad Rzeszutek Wilk 2 participants 2 messages Jul 13, 2016 – Jul 14, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EFI build with -ffunction-sections fails.

When we build Xen with the Rules.mk modified we end up:

ld -mi386pep --subsystem=10 --image-base=0xffff82d080000000 --stack=0,0 --heap=0,0 --strip-debug --section-alignment=0x200000 --file-alignment=0x20 --major-image-version=4 --minor-image-version=8 --major-os-version=2 --minor-os-version=0 --major-subsystem-version=2 --minor-subsystem-version=0 -T efi.lds -N prelink-efi.o efi/relocs-dummy.o /home/konrad/xen/xen/common/symbols-dummy.o -o /home/konrad/xen/xen/.xen.efi.0xffff82d080000000.0 && ld -mi386pep --subsystem=10 --image-base=0xffff82d0c0000000 --stack=0,0 --heap=0,0 --strip-debug --section-alignment=0x200000 --file-alignment=0x20 --major-image-version=4 --minor-image-version=8 --major-os-version=2 --minor-os-version=0 --major-subsystem-version=2 --minor-subsystem-version=0 -T efi.lds -N prelink-efi.o efi/relocs-dummy.o /home/konrad/xen/xen/common/symbols-dummy.o -o /home/konrad/xen/xen/.xen.efi.0xffff82d0c0000000.0 && :
ld: Xen image overlaps stubs area
prelink-efi.o: In function `__high_start':
/home/konrad/xen/xen/arch/x86/boot/x86_64.S:6:(.text+0x23): relocation truncated to fit: R_X86_64_PC32 against gdt_descr' /home/konrad/xen/xen/arch/x86/boot/x86_64.S:18:(.text+0x43): relocation truncated to fit: R_X86_64_PC32 against stack_start' /home/konrad/xen/xen/arch/x86/boot/x86_64.S:35:(.text+0x6a): relocation truncated to fit: R_X86_64_PC32 against .data' /home/konrad/xen/xen/arch/x86/boot/x86_64.S:36:(.text+0x6f): relocation truncated to fit: R_X86_64_PC32 against __start_xen' .. and more.

Re-running it with -M on a build (the giant ld -mi386pep..) with the -ffunction-sections and without it makes it obvious what the problem is:

With: -ffunction-sections -fdata-sections:

.data 0xffff82d291e18000 0xf8 prelink-efi.o

                0xffff82d291e18006                gdt_descr

*(.text)
.text 0xffff82d0c0100000 0x27e4 prelink-efi.o

                0xffff82d0c0100000                start
                0xffff82d0c0100020                __high_start

distance is 0x1D1D18000

Normal build:

.data 0xffff82d0c0818000 0x12e8 prelink-efi.o

                0xffff82d0c0818006                gdt_descr

.text 0xffff82d0c0100000 0x14b000

                0xffff82d0c0100000                _stext = .
 *(.text)
 .text          0xffff82d0c0100000   0x149243 prelink-efi.o
                0xffff82d0c0100000                start
                0xffff82d0c0100020                __high_start

where the distance is 0x718000

The 0x1D1D18000 is most certainly over the 32-bit limit and leads to the truncation.

Now if we look more closely at the map we can see that each .text section is:

.text.domain_kill

                0xffff82d0cd200000      0x140
 .text.domain_kill
                0xffff82d0cd200000      0x139 prelink-efi.o
                0xffff82d0cd200000                domain_kill

.text.domain_create

                0xffff82d0cd400000      0x520
 .text.domain_create
                0xffff82d0cd400000      0x502 prelink-efi.o
                0xffff82d0cd400000                domain_create

.. seperated by 2MB!

A bit of grepping showed that the issue is with:

--section-alignment=0x200000

which is used on the linker command line and this fix replaces the --section-alignment to be 4KB which allows the build to complete.

---
 livepatch-build | 2 ++
 1 file changed, 2 insertions(+)
livepatch-build +2 -0
index 8dc8889..6ccadd6 100755
@@ -86,8 +86,10 @@ function build_special()
     # Build with special GCC flags
     cd "${SRCDIR}/xen" || die
     sed -i 's/CFLAGS += -nostdinc/CFLAGS += -nostdinc -ffunction-sections -fdata-sections/' Rules.mk
+    sed -i 's/--section-alignment=0x200000/--section-alignment=0x1000/' arch/x86/Makefile
     make "-j$CPUS" debug="$XEN_DEBUG" &> "${OUTPUT}/build_${name}_compile.log" || die
     sed -i 's/CFLAGS += -nostdinc -ffunction-sections -fdata-sections/CFLAGS += -nostdinc/' Rules.mk
+    sed -i 's/--section-alignment=0x1000/--section-alignment=0x200000/' arch/x86/Makefile
 
     unset LIVEPATCH_BUILD_DIR
     unset LIVEPATCH_CAPTURE_DIR
Signature · 7 lines
2.5.5


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Konrad Rzeszutek Wilk

When we build Xen with the Rules.mk modified we end up:

... snip

Quoted 5 lines

A bit of grepping showed that the issue is with:

--section-alignment=0x200000

Quoted 9 lines

which is used on the linker command line and this fix replaces the --section-alignment to be 4KB which allows the build to complete.

---
 livepatch-build | 2 ++
 1 file changed, 2 insertions(+)
Signature · 6 lines
Ross Lagerwall

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