[Concept,06/12] x86: Build 16-bit startup objects as 32-bit for x86_64
Commit Message
From: Simon Glass <simon.glass@canonical.com>
The 64-bit PIE linker cannot handle 16-bit relocations, so
start16.o and resetvec.o cannot be linked into the 64-bit
u-boot binary.
Override the assembler flags to build these objects as 32-bit
(elf_i386) when targeting x86_64, and exclude them from head-y
since they are handled separately by binman.
Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
arch/x86/Makefile | 2 ++
arch/x86/cpu/Makefile | 11 +++++++++++
2 files changed, 13 insertions(+)
@@ -20,8 +20,10 @@ endif
endif
endif # EFI
+ifndef CONFIG_$(PHASE_)X86_64
head-$(CONFIG_$(PHASE_)X86_16BIT_INIT) += arch/x86/cpu/start16.o
head-$(CONFIG_$(PHASE_)X86_16BIT_INIT) += arch/x86/cpu/resetvec.o
+endif
libs-y += arch/x86/cpu/
libs-y += arch/x86/lib/
@@ -26,6 +26,17 @@ endif
extra-$(CONFIG_$(PHASE_)X86_16BIT_INIT) += resetvec.o start16.o
+ifdef CONFIG_$(PHASE_)X86_64
+# The 16-bit startup code must be assembled as 32-bit since the 64-bit
+# linker cannot handle 16-bit relocations in a PIE binary. These
+# objects are not linked into the 64-bit u-boot; instead their sections
+# are extracted to binary files for binman to place.
+AFLAGS_REMOVE_start16.o := -march=core2 -m64
+AFLAGS_start16.o := -march=i386 -m32
+AFLAGS_REMOVE_resetvec.o := -march=core2 -m64
+AFLAGS_resetvec.o := -march=i386 -m32
+endif
+
obj-y += cpu.o
ifndef CONFIG_TPL_BUILD
obj-y += cpu_x86.o