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 <[email protected]> Tested-by: Conor Dooley <[email protected]> # booted on nezha & unmatched Fixes: 39b3307 ("riscv: Introduce CONFIG_RELOCATABLE") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent ed309ce commit 8dc2a7e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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)