Skip to content
Browse files

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 <>
  • Loading branch information...
andyross authored and nashif committed May 3, 2019
1 parent be3d423 commit 9f068737d52a12f8cc15f16425158caf38e226ec
Showing with 2 additions and 2 deletions.
  1. +1 −1 arch/x86_64/core/CMakeLists.txt
  2. +1 −1 arch/x86_64/core/Makefile.xuk
@@ -44,7 +44,7 @@ add_custom_command(
-c ${CMAKE_CURRENT_SOURCE_DIR}/xuk-stub32.c
-o ${CMAKE_CURRENT_BINARY_DIR}/xuk-stub32.o
-Wl,--build-id=none -nostdlib -nodefaultlibs -nostartfiles
-Wl,--build-id=none -nostdlib -nodefaultlibs -nostartfiles -no-pie
-T ${CMAKE_CURRENT_SOURCE_DIR}/xuk-stub32.ld
-o ${CMAKE_CURRENT_BINARY_DIR}/xuk-stub32.elf
@@ -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

0 comments on commit 9f06873

Please sign in to comment.
You can’t perform that action at this time.