From 9f068737d52a12f8cc15f16425158caf38e226ec Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Fri, 3 May 2019 12:33:33 -0700 Subject: [PATCH] arch/x86_64: Suppress spurious linker-generated code in the 32 bit stub Within the past few days, an update to the Ubuntu 18.04 toolchain has begun emitting code sections during link that are messing with our stub generation. They are appearing in the 32 bit stub link despite not being defined in the single object file, and (worse) being included in the output segment (i.e. at the start of the bootloader entry point!) despite not being specifically included by the linker script. I don't understand this behavior at all, and it appears to be directly contrary to the way the linker is documented. Marc Herbert discovered this was down to gcc being called with --enable-default-pie, so -no-pie works to suppress this behavior and restore the default. And it's correct: we aren't actually generating a position independent executable, even if we don't understand why the linker script is being disregarded (to include sections we don't include). See discussion in the linked github issue. Fixes #15877 Signed-off-by: Andy Ross --- arch/x86_64/core/CMakeLists.txt | 2 +- arch/x86_64/core/Makefile.xuk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86_64/core/CMakeLists.txt b/arch/x86_64/core/CMakeLists.txt index c9200c61cd7..c7bf2f136ee 100644 --- a/arch/x86_64/core/CMakeLists.txt +++ b/arch/x86_64/core/CMakeLists.txt @@ -44,7 +44,7 @@ add_custom_command( -c ${CMAKE_CURRENT_SOURCE_DIR}/xuk-stub32.c -o ${CMAKE_CURRENT_BINARY_DIR}/xuk-stub32.o COMMAND ${CMAKE_C_COMPILER} -m32 ${X86_64_BASE_CFLAGS} - -Wl,--build-id=none -nostdlib -nodefaultlibs -nostartfiles + -Wl,--build-id=none -nostdlib -nodefaultlibs -nostartfiles -no-pie -T ${CMAKE_CURRENT_SOURCE_DIR}/xuk-stub32.ld ${CMAKE_CURRENT_BINARY_DIR}/xuk-stub32.o -o ${CMAKE_CURRENT_BINARY_DIR}/xuk-stub32.elf diff --git a/arch/x86_64/core/Makefile.xuk b/arch/x86_64/core/Makefile.xuk index 7500666364a..b4630caceb9 100644 --- a/arch/x86_64/core/Makefile.xuk +++ b/arch/x86_64/core/Makefile.xuk @@ -28,7 +28,7 @@ stubs: xuk-stub32.bin xuk-stub16.bin # image. xuk-stub32.bin: xuk-stub32.c *.h xuk-stub32.ld $(CC) -Wall -m32 $(CFLAGS) -c xuk-stub32.c - $(CC) -m32 -T xuk-stub32.ld $(LDFLAGS) -o stub32.elf $(CFLAGS) xuk-stub32.o + $(CC) -m32 -T xuk-stub32.ld $(LDFLAGS) -no-pie -o stub32.elf $(CFLAGS) xuk-stub32.o $(OBJCOPY) -O binary stub32.elf $@ # This is the main OS image, starting with the 32 bit stub and