Skip to content

Commit 559d1e4

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Use --emit-relocs in order to move .rela.dyn in init
To circumvent an issue where placing the relocations inside the init sections produces empty relocations, use --emit-relocs. But to avoid carrying those relocations in vmlinux, use an intermediate vmlinux.relocs file which is a copy of vmlinux *before* stripping its relocations. Suggested-by: Björn Töpel <bjorn@kernel.org> Suggested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/20230329045329.64565-7-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent c2dea0b commit 559d1e4

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

arch/riscv/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
OBJCOPYFLAGS := -O binary
1010
ifeq ($(CONFIG_RELOCATABLE),y)
11-
LDFLAGS_vmlinux += -shared -Bsymbolic -z notext -z norelro
11+
LDFLAGS_vmlinux += -shared -Bsymbolic -z notext -z norelro --emit-relocs
1212
KBUILD_CFLAGS += -fPIE
1313
endif
1414
ifeq ($(CONFIG_DYNAMIC_FTRACE),y)

arch/riscv/Makefile.postlink

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@ quiet_cmd_relocs_check = CHKREL $@
1515
cmd_relocs_check = \
1616
$(CONFIG_SHELL) $(srctree)/arch/riscv/tools/relocs_check.sh "$(OBJDUMP)" "$(NM)" "$@"
1717

18+
ifdef CONFIG_RELOCATABLE
19+
quiet_cmd_cp_vmlinux_relocs = CPREL vmlinux.relocs
20+
cmd_cp_vmlinux_relocs = cp vmlinux vmlinux.relocs
21+
22+
quiet_cmd_relocs_strip = STRIPREL $@
23+
cmd_relocs_strip = $(OBJCOPY) --remove-section='.rel.*' \
24+
--remove-section='.rel__*' \
25+
--remove-section='.rela.*' \
26+
--remove-section='.rela__*' $@
27+
endif
28+
1829
# `@true` prevents complaint when there is nothing to be done
1930

2031
vmlinux: FORCE
2132
@true
2233
ifdef CONFIG_RELOCATABLE
2334
$(call if_changed,relocs_check)
35+
$(call if_changed,cp_vmlinux_relocs)
36+
$(call if_changed,relocs_strip)
2437
endif
2538

2639
%.ko: FORCE

arch/riscv/boot/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ $(obj)/xipImage: vmlinux FORCE
3333

3434
endif
3535

36+
ifdef CONFIG_RELOCATABLE
37+
vmlinux.relocs: vmlinux
38+
@ (! [ -f vmlinux.relocs ] && echo "vmlinux.relocs can't be found, please remove vmlinux and try again") || true
39+
40+
$(obj)/Image: vmlinux.relocs FORCE
41+
else
3642
$(obj)/Image: vmlinux FORCE
43+
endif
3744
$(call if_changed,objcopy)
3845

3946
$(obj)/Image.gz: $(obj)/Image FORCE

0 commit comments

Comments
 (0)