[v2,15/17] x86/sev: Use PIC codegen for early SEV startup code
Commit Message
From: Ard Biesheuvel <ardb@kernel.org>
Use PIC codegen for the compilation units containing code that may be
called very early during the boot, at which point the CPU still runs
from the 1:1 mapping of memory. This is necessary to prevent the
compiler from emitting absolute symbol references to addresses that are
not mapped yet.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/kernel/Makefile | 1 +
arch/x86/kernel/vmlinux.lds.S | 1 +
arch/x86/lib/Makefile | 2 +-
arch/x86/mm/Makefile | 3 ++-
4 files changed, 5 insertions(+), 2 deletions(-)
@@ -24,6 +24,7 @@ endif
# head64.c contains C code that may execute from a different virtual address
# than it was linked at, so we always build it using PIE codegen
CFLAGS_head64.o += $(PIE_CFLAGS)
+CFLAGS_sev.o += $(PIE_CFLAGS)
KASAN_SANITIZE_head$(BITS).o := n
KASAN_SANITIZE_dumpstack.o := n
@@ -182,6 +182,7 @@ SECTIONS
DATA_DATA
CONSTRUCTORS
+ *(.data.rel .data.rel.*)
/* rarely changed data like cpu maps */
READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
@@ -24,7 +24,7 @@ ifdef CONFIG_FUNCTION_TRACER
CFLAGS_REMOVE_cmdline.o = -pg
endif
-CFLAGS_cmdline.o := -fno-stack-protector -fno-jump-tables
+CFLAGS_cmdline.o := $(PIE_CFLAGS)
endif
inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awk
@@ -31,7 +31,8 @@ obj-y += pat/
# Make sure __phys_addr has no stackprotector
CFLAGS_physaddr.o := -fno-stack-protector
-CFLAGS_mem_encrypt_identity.o := -fno-stack-protector
+CFLAGS_mem_encrypt_identity.o := $(PIE_CFLAGS)
+CFLAGS_pti.o := $(PIE_CFLAGS)
CFLAGS_fault.o := -I $(srctree)/$(src)/../include/asm/trace