Skip to content

Commit 8dc2a7e

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Fix relocatable kernels with early alternatives using -fno-pie
Early alternatives are called with the mmu disabled, and then should not access any global symbols through the GOT since it requires relocations, relocations that we do before but *virtually*. So only use medany code model for this early code. Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Tested-by: Conor Dooley <conor.dooley@microchip.com> # booted on nezha & unmatched Fixes: 39b3307 ("riscv: Introduce CONFIG_RELOCATABLE") Link: https://lore.kernel.org/r/20230526154630.289374-1-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent ed309ce commit 8dc2a7e

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

arch/riscv/errata/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
ifdef CONFIG_RELOCATABLE
2+
KBUILD_CFLAGS += -fno-pie
3+
endif
4+
15
obj-$(CONFIG_ERRATA_SIFIVE) += sifive/
26
obj-$(CONFIG_ERRATA_THEAD) += thead/

arch/riscv/kernel/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ ifdef CONFIG_FTRACE
2323
CFLAGS_REMOVE_alternative.o = $(CC_FLAGS_FTRACE)
2424
CFLAGS_REMOVE_cpufeature.o = $(CC_FLAGS_FTRACE)
2525
endif
26+
ifdef CONFIG_RELOCATABLE
27+
CFLAGS_alternative.o += -fno-pie
28+
CFLAGS_cpufeature.o += -fno-pie
29+
endif
2630
ifdef CONFIG_KASAN
2731
KASAN_SANITIZE_alternative.o := n
2832
KASAN_SANITIZE_cpufeature.o := n

0 commit comments

Comments
 (0)