Skip to content

Commit 71d815b

Browse files
ardbiesheuvelmasahir0y
authored andcommitted
kbuild: Strip runtime const RELA sections correctly
Due to the fact that runtime const ELF sections are named without a leading period or double underscore, the RSTRIP logic that removes the static RELA sections from vmlinux fails to identify them. This results in a situation like below, where some sections that were supposed to get removed are left behind. [Nr] Name Type Address Off Size ES Flg Lk Inf Al [58] runtime_shift_d_hash_shift PROGBITS ffffffff83500f50 2900f50 000014 00 A 0 0 1 [59] .relaruntime_shift_d_hash_shift RELA 0000000000000000 55b6f00 000078 18 I 70 58 8 [60] runtime_ptr_dentry_hashtable PROGBITS ffffffff83500f68 2900f68 000014 00 A 0 0 1 [61] .relaruntime_ptr_dentry_hashtable RELA 0000000000000000 55b6f78 000078 18 I 70 60 8 [62] runtime_ptr_USER_PTR_MAX PROGBITS ffffffff83500f80 2900f80 000238 00 A 0 0 1 [63] .relaruntime_ptr_USER_PTR_MAX RELA 0000000000000000 55b6ff0 000d50 18 I 70 62 8 So tweak the match expression to strip all sections starting with .rel. While at it, consolidate the logic used by RISC-V, s390 and x86 into a single shared Makefile library command. Link: https://lore.kernel.org/all/CAHk-=wjk3ynjomNvFN8jf9A1k=qSc=JFF591W00uXj-qqNUxPQ@mail.gmail.com/ Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com> Tested-by: Charlie Jenkins <charlie@rivosinc.com> Tested-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent a409fc1 commit 71d815b

File tree

4 files changed

+7
-16
lines changed

4 files changed

+7
-16
lines changed

arch/riscv/Makefile.postlink

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ __archpost:
1010

1111
-include include/config/auto.conf
1212
include $(srctree)/scripts/Kbuild.include
13+
include $(srctree)/scripts/Makefile.lib
1314

1415
quiet_cmd_relocs_check = CHKREL $@
1516
cmd_relocs_check = \
@@ -19,11 +20,6 @@ ifdef CONFIG_RELOCATABLE
1920
quiet_cmd_cp_vmlinux_relocs = CPREL vmlinux.relocs
2021
cmd_cp_vmlinux_relocs = cp vmlinux vmlinux.relocs
2122

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__*' $@
2723
endif
2824

2925
# `@true` prevents complaint when there is nothing to be done
@@ -33,7 +29,7 @@ vmlinux: FORCE
3329
ifdef CONFIG_RELOCATABLE
3430
$(call if_changed,relocs_check)
3531
$(call if_changed,cp_vmlinux_relocs)
36-
$(call if_changed,relocs_strip)
32+
$(call if_changed,strip_relocs)
3733
endif
3834

3935
clean:

arch/s390/Makefile.postlink

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ __archpost:
1111

1212
-include include/config/auto.conf
1313
include $(srctree)/scripts/Kbuild.include
14+
include $(srctree)/scripts/Makefile.lib
1415

1516
CMD_RELOCS=arch/s390/tools/relocs
1617
OUT_RELOCS = arch/s390/boot
@@ -19,11 +20,6 @@ quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/relocs.S
1920
mkdir -p $(OUT_RELOCS); \
2021
$(CMD_RELOCS) $@ > $(OUT_RELOCS)/relocs.S
2122

22-
quiet_cmd_strip_relocs = RSTRIP $@
23-
cmd_strip_relocs = \
24-
$(OBJCOPY) --remove-section='.rel.*' --remove-section='.rel__*' \
25-
--remove-section='.rela.*' --remove-section='.rela__*' $@
26-
2723
vmlinux: FORCE
2824
$(call cmd,relocs)
2925
$(call cmd,strip_relocs)

arch/x86/Makefile.postlink

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ __archpost:
1111

1212
-include include/config/auto.conf
1313
include $(srctree)/scripts/Kbuild.include
14+
include $(srctree)/scripts/Makefile.lib
1415

1516
CMD_RELOCS = arch/x86/tools/relocs
1617
OUT_RELOCS = arch/x86/boot/compressed
@@ -20,11 +21,6 @@ quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/$@.relocs
2021
$(CMD_RELOCS) $@ > $(OUT_RELOCS)/$@.relocs; \
2122
$(CMD_RELOCS) --abs-relocs $@
2223

23-
quiet_cmd_strip_relocs = RSTRIP $@
24-
cmd_strip_relocs = \
25-
$(OBJCOPY) --remove-section='.rel.*' --remove-section='.rel__*' \
26-
--remove-section='.rela.*' --remove-section='.rela__*' $@
27-
2824
# `@true` prevents complaint when there is nothing to be done
2925

3026
vmlinux: FORCE

scripts/Makefile.lib

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ quiet_cmd_ar = AR $@
374374
quiet_cmd_objcopy = OBJCOPY $@
375375
cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
376376

377+
quiet_cmd_strip_relocs = RSTRIP $@
378+
cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $@
379+
377380
# Gzip
378381
# ---------------------------------------------------------------------------
379382

0 commit comments

Comments
 (0)