* [PATCH v3] kbuild: Strip runtime const RELA sections correctly
@ 2025-01-13 15:53 Ard Biesheuvel
2025-01-16 22:02 ` Charlie Jenkins
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2025-01-13 15:53 UTC (permalink / raw)
To: linux-kbuild
Cc: linux-kernel, Ard Biesheuvel, Linus Torvalds, Masahiro Yamada,
linux-riscv, linux-s390, Ron Economos
From: Ard Biesheuvel <ardb@kernel.org>
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.
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: linux-riscv@lists.infradead.org
Cc: linux-s390@vger.kernel.org
Cc: Ron Economos <re@w6rz.net>
Link: https://lore.kernel.org/all/CAHk-=wjk3ynjomNvFN8jf9A1k=qSc=JFF591W00uXj-qqNUxPQ@mail.gmail.com/
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
v3: put back missing 'endif' to fix the RISC-V build
v2: add missing include of scripts/Makefile.lib
arch/riscv/Makefile.postlink | 8 ++------
arch/s390/Makefile.postlink | 6 +-----
arch/x86/Makefile.postlink | 6 +-----
scripts/Makefile.lib | 3 +++
4 files changed, 7 insertions(+), 18 deletions(-)
diff --git a/arch/riscv/Makefile.postlink b/arch/riscv/Makefile.postlink
index 829b9abc91f6..750d2784f69e 100644
--- a/arch/riscv/Makefile.postlink
+++ b/arch/riscv/Makefile.postlink
@@ -10,6 +10,7 @@ __archpost:
-include include/config/auto.conf
include $(srctree)/scripts/Kbuild.include
+include $(srctree)/scripts/Makefile.lib
quiet_cmd_relocs_check = CHKREL $@
cmd_relocs_check = \
@@ -19,11 +20,6 @@ ifdef CONFIG_RELOCATABLE
quiet_cmd_cp_vmlinux_relocs = CPREL vmlinux.relocs
cmd_cp_vmlinux_relocs = cp vmlinux vmlinux.relocs
-quiet_cmd_relocs_strip = STRIPREL $@
-cmd_relocs_strip = $(OBJCOPY) --remove-section='.rel.*' \
- --remove-section='.rel__*' \
- --remove-section='.rela.*' \
- --remove-section='.rela__*' $@
endif
# `@true` prevents complaint when there is nothing to be done
@@ -33,7 +27,7 @@ vmlinux: FORCE
ifdef CONFIG_RELOCATABLE
$(call if_changed,relocs_check)
$(call if_changed,cp_vmlinux_relocs)
- $(call if_changed,relocs_strip)
+ $(call if_changed,strip_relocs)
endif
clean:
diff --git a/arch/s390/Makefile.postlink b/arch/s390/Makefile.postlink
index df82f5410769..1ae5478cd6ac 100644
--- a/arch/s390/Makefile.postlink
+++ b/arch/s390/Makefile.postlink
@@ -11,6 +11,7 @@ __archpost:
-include include/config/auto.conf
include $(srctree)/scripts/Kbuild.include
+include $(srctree)/scripts/Makefile.lib
CMD_RELOCS=arch/s390/tools/relocs
OUT_RELOCS = arch/s390/boot
@@ -19,11 +20,6 @@ quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/relocs.S
mkdir -p $(OUT_RELOCS); \
$(CMD_RELOCS) $@ > $(OUT_RELOCS)/relocs.S
-quiet_cmd_strip_relocs = RSTRIP $@
- cmd_strip_relocs = \
- $(OBJCOPY) --remove-section='.rel.*' --remove-section='.rel__*' \
- --remove-section='.rela.*' --remove-section='.rela__*' $@
-
vmlinux: FORCE
$(call cmd,relocs)
$(call cmd,strip_relocs)
diff --git a/arch/x86/Makefile.postlink b/arch/x86/Makefile.postlink
index fef2e977cc7d..8b8a68162c94 100644
--- a/arch/x86/Makefile.postlink
+++ b/arch/x86/Makefile.postlink
@@ -11,6 +11,7 @@ __archpost:
-include include/config/auto.conf
include $(srctree)/scripts/Kbuild.include
+include $(srctree)/scripts/Makefile.lib
CMD_RELOCS = arch/x86/tools/relocs
OUT_RELOCS = arch/x86/boot/compressed
@@ -20,11 +21,6 @@ quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/$@.relocs
$(CMD_RELOCS) $@ > $(OUT_RELOCS)/$@.relocs; \
$(CMD_RELOCS) --abs-relocs $@
-quiet_cmd_strip_relocs = RSTRIP $@
- cmd_strip_relocs = \
- $(OBJCOPY) --remove-section='.rel.*' --remove-section='.rel__*' \
- --remove-section='.rela.*' --remove-section='.rela__*' $@
-
# `@true` prevents complaint when there is nothing to be done
vmlinux: FORCE
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 7395200538da..f604f51d23ca 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -374,6 +374,9 @@ quiet_cmd_ar = AR $@
quiet_cmd_objcopy = OBJCOPY $@
cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
+quiet_cmd_strip_relocs = RSTRIP $@
+cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $@
+
# Gzip
# ---------------------------------------------------------------------------
--
2.47.1.688.g23fc6f90ad-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-13 15:53 [PATCH v3] kbuild: Strip runtime const RELA sections correctly Ard Biesheuvel
@ 2025-01-16 22:02 ` Charlie Jenkins
2025-01-19 17:15 ` Ard Biesheuvel
2025-01-22 16:49 ` Alexander Gordeev
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Charlie Jenkins @ 2025-01-16 22:02 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: linux-kbuild, linux-kernel, Ard Biesheuvel, Linus Torvalds,
Masahiro Yamada, Alexandre Ghiti, linux-riscv, linux-s390,
Ron Economos
On Mon, Jan 13, 2025 at 04:53:07PM +0100, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
>
> 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.
>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: linux-riscv@lists.infradead.org
> Cc: linux-s390@vger.kernel.org
> Cc: Ron Economos <re@w6rz.net>
> Link: https://lore.kernel.org/all/CAHk-=wjk3ynjomNvFN8jf9A1k=qSc=JFF591W00uXj-qqNUxPQ@mail.gmail.com/
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> v3: put back missing 'endif' to fix the RISC-V build
> v2: add missing include of scripts/Makefile.lib
>
> arch/riscv/Makefile.postlink | 8 ++------
> arch/s390/Makefile.postlink | 6 +-----
> arch/x86/Makefile.postlink | 6 +-----
> scripts/Makefile.lib | 3 +++
> 4 files changed, 7 insertions(+), 18 deletions(-)
>
> diff --git a/arch/riscv/Makefile.postlink b/arch/riscv/Makefile.postlink
> index 829b9abc91f6..750d2784f69e 100644
> --- a/arch/riscv/Makefile.postlink
> +++ b/arch/riscv/Makefile.postlink
When I compile x86 as relocatable I see the problem that you are fixing
here, but I don't see it on riscv. It's probably better to keep around
this code for riscv, but I don't think it even needs this stripping? I
am adding Alex since he added this for riscv.
Anyways this works as expected:
Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
Tested-by: Charlie Jenkins <charlie@rivosinc.com>
> @@ -10,6 +10,7 @@ __archpost:
>
> -include include/config/auto.conf
> include $(srctree)/scripts/Kbuild.include
> +include $(srctree)/scripts/Makefile.lib
>
> quiet_cmd_relocs_check = CHKREL $@
> cmd_relocs_check = \
> @@ -19,11 +20,6 @@ ifdef CONFIG_RELOCATABLE
> quiet_cmd_cp_vmlinux_relocs = CPREL vmlinux.relocs
> cmd_cp_vmlinux_relocs = cp vmlinux vmlinux.relocs
>
> -quiet_cmd_relocs_strip = STRIPREL $@
> -cmd_relocs_strip = $(OBJCOPY) --remove-section='.rel.*' \
> - --remove-section='.rel__*' \
> - --remove-section='.rela.*' \
> - --remove-section='.rela__*' $@
> endif
>
> # `@true` prevents complaint when there is nothing to be done
> @@ -33,7 +27,7 @@ vmlinux: FORCE
> ifdef CONFIG_RELOCATABLE
> $(call if_changed,relocs_check)
> $(call if_changed,cp_vmlinux_relocs)
> - $(call if_changed,relocs_strip)
> + $(call if_changed,strip_relocs)
> endif
>
> clean:
> diff --git a/arch/s390/Makefile.postlink b/arch/s390/Makefile.postlink
> index df82f5410769..1ae5478cd6ac 100644
> --- a/arch/s390/Makefile.postlink
> +++ b/arch/s390/Makefile.postlink
> @@ -11,6 +11,7 @@ __archpost:
>
> -include include/config/auto.conf
> include $(srctree)/scripts/Kbuild.include
> +include $(srctree)/scripts/Makefile.lib
>
> CMD_RELOCS=arch/s390/tools/relocs
> OUT_RELOCS = arch/s390/boot
> @@ -19,11 +20,6 @@ quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/relocs.S
> mkdir -p $(OUT_RELOCS); \
> $(CMD_RELOCS) $@ > $(OUT_RELOCS)/relocs.S
>
> -quiet_cmd_strip_relocs = RSTRIP $@
> - cmd_strip_relocs = \
> - $(OBJCOPY) --remove-section='.rel.*' --remove-section='.rel__*' \
> - --remove-section='.rela.*' --remove-section='.rela__*' $@
> -
> vmlinux: FORCE
> $(call cmd,relocs)
> $(call cmd,strip_relocs)
> diff --git a/arch/x86/Makefile.postlink b/arch/x86/Makefile.postlink
> index fef2e977cc7d..8b8a68162c94 100644
> --- a/arch/x86/Makefile.postlink
> +++ b/arch/x86/Makefile.postlink
> @@ -11,6 +11,7 @@ __archpost:
>
> -include include/config/auto.conf
> include $(srctree)/scripts/Kbuild.include
> +include $(srctree)/scripts/Makefile.lib
>
> CMD_RELOCS = arch/x86/tools/relocs
> OUT_RELOCS = arch/x86/boot/compressed
> @@ -20,11 +21,6 @@ quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/$@.relocs
> $(CMD_RELOCS) $@ > $(OUT_RELOCS)/$@.relocs; \
> $(CMD_RELOCS) --abs-relocs $@
>
> -quiet_cmd_strip_relocs = RSTRIP $@
> - cmd_strip_relocs = \
> - $(OBJCOPY) --remove-section='.rel.*' --remove-section='.rel__*' \
> - --remove-section='.rela.*' --remove-section='.rela__*' $@
> -
> # `@true` prevents complaint when there is nothing to be done
>
> vmlinux: FORCE
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 7395200538da..f604f51d23ca 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -374,6 +374,9 @@ quiet_cmd_ar = AR $@
> quiet_cmd_objcopy = OBJCOPY $@
> cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
>
> +quiet_cmd_strip_relocs = RSTRIP $@
> +cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $@
> +
> # Gzip
> # ---------------------------------------------------------------------------
>
> --
> 2.47.1.688.g23fc6f90ad-goog
>
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-16 22:02 ` Charlie Jenkins
@ 2025-01-19 17:15 ` Ard Biesheuvel
0 siblings, 0 replies; 11+ messages in thread
From: Ard Biesheuvel @ 2025-01-19 17:15 UTC (permalink / raw)
To: Charlie Jenkins
Cc: Ard Biesheuvel, linux-kbuild, linux-kernel, Linus Torvalds,
Masahiro Yamada, Alexandre Ghiti, linux-riscv, linux-s390,
Ron Economos
On Thu, 16 Jan 2025 at 23:02, Charlie Jenkins <charlie@rivosinc.com> wrote:
>
> On Mon, Jan 13, 2025 at 04:53:07PM +0100, Ard Biesheuvel wrote:
> > From: Ard Biesheuvel <ardb@kernel.org>
> >
> > 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.
> >
> > Cc: Linus Torvalds <torvalds@linux-foundation.org>
> > Cc: Masahiro Yamada <masahiroy@kernel.org>
> > Cc: linux-riscv@lists.infradead.org
> > Cc: linux-s390@vger.kernel.org
> > Cc: Ron Economos <re@w6rz.net>
> > Link: https://lore.kernel.org/all/CAHk-=wjk3ynjomNvFN8jf9A1k=qSc=JFF591W00uXj-qqNUxPQ@mail.gmail.com/
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> > ---
> > v3: put back missing 'endif' to fix the RISC-V build
> > v2: add missing include of scripts/Makefile.lib
> >
> > arch/riscv/Makefile.postlink | 8 ++------
> > arch/s390/Makefile.postlink | 6 +-----
> > arch/x86/Makefile.postlink | 6 +-----
> > scripts/Makefile.lib | 3 +++
> > 4 files changed, 7 insertions(+), 18 deletions(-)
> >
> > diff --git a/arch/riscv/Makefile.postlink b/arch/riscv/Makefile.postlink
> > index 829b9abc91f6..750d2784f69e 100644
> > --- a/arch/riscv/Makefile.postlink
> > +++ b/arch/riscv/Makefile.postlink
>
> When I compile x86 as relocatable I see the problem that you are fixing
> here, but I don't see it on riscv.
That is because riscv does not yet support optimized runtime
constants. Only arm64, s390 and x86 implement this today but I'd
expect other architectures to follow suit.
> It's probably better to keep around
> this code for riscv, but I don't think it even needs this stripping? I
> am adding Alex since he added this for riscv.
>
If vmlinux is linked with --emit-relocs, the stripping is probably
necessary, or you get a lot of metadata in vmlinux that is not needed
for debugging.
> Anyways this works as expected:
>
> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
> Tested-by: Charlie Jenkins <charlie@rivosinc.com>
>
Thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-13 15:53 [PATCH v3] kbuild: Strip runtime const RELA sections correctly Ard Biesheuvel
2025-01-16 22:02 ` Charlie Jenkins
@ 2025-01-22 16:49 ` Alexander Gordeev
2025-01-22 17:22 ` Alexander Gordeev
2025-01-31 18:35 ` Masahiro Yamada
2025-02-03 19:16 ` patchwork-bot+linux-riscv
3 siblings, 1 reply; 11+ messages in thread
From: Alexander Gordeev @ 2025-01-22 16:49 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: linux-kbuild, linux-kernel, Ard Biesheuvel, Linus Torvalds,
Masahiro Yamada, linux-riscv, linux-s390, Ron Economos
On Mon, Jan 13, 2025 at 04:53:07PM +0100, Ard Biesheuvel wrote:
Hi Ard,
> 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.
On s390 this is before:
[32] .relaruntime[...] RELA 0000000000000000 13b3fe20
[34] .relaruntime[...] RELA 0000000000000000 13b3fe98
This is after:
[ 2] .rela.text RELA 0000000000000000 13b3fe20
[ 4] .rela.rodata RELA 0000000000000000 142cf588
[ 6] .rela__ksymtab RELA 0000000000000000 142ece08
[ 8] .rela__ksymt[...] RELA 0000000000000000 1433f200
[13] .rela__param RELA 0000000000000000 14432d40
[15] .rela__modver RELA 0000000000000000 14436358
[17] .rela__ex_table RELA 0000000000000000 14436538
[20] .rela.data..[...] RELA 0000000000000000 14446228
[22] .rela.data.rel.ro RELA 0000000000000000 144d9240
[25] .rela.data RELA 0000000000000000 14559148
[27] .rela__bug_table RELA 0000000000000000 145b4ae0
[29] .rela.data.rel RELA 0000000000000000 1461aab0
[32] .rela.amode3[...] RELA 0000000000000000 146eb280
[34] .rela.init.text RELA 0000000000000000 146eb430
[36] .rela.exit.text RELA 0000000000000000 14750c20
[38] .rela.altins[...] RELA 0000000000000000 14753d28
[41] .rela.nospec[...] RELA 0000000000000000 1484ca58
[43] .rela.nospec[...] RELA 0000000000000000 1487ef90
[46] .rela.amode3[...] RELA 0000000000000000 14a0d168
[48] .rela.amode3[...] RELA 0000000000000000 14a0d270
[51] .rela.init.data RELA 0000000000000000 14a0d330
[53] .relaruntime[...] RELA 0000000000000000 14b5d6f0
[55] .relaruntime[...] RELA 0000000000000000 14b5d768
[57] .rela.data..[...] RELA 0000000000000000 14b5d7e0
[61] .rela.debug_[...] RELA 0000000000000000 14b5d918
[63] .rela.debug_info RELA 0000000000000000 14b80478
[66] .rela.debug_line RELA 0000000000000000 250ef010
[68] .rela.debug_frame RELA 0000000000000000 25123060
[71] .rela.debug_loc RELA 0000000000000000 253bb1a0
[73] .rela.debug_[...] RELA 0000000000000000 298eb5a8
Thanks!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-22 16:49 ` Alexander Gordeev
@ 2025-01-22 17:22 ` Alexander Gordeev
0 siblings, 0 replies; 11+ messages in thread
From: Alexander Gordeev @ 2025-01-22 17:22 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: linux-kbuild, linux-kernel, Ard Biesheuvel, Linus Torvalds,
Masahiro Yamada, linux-riscv, linux-s390, Ron Economos
On Wed, Jan 22, 2025 at 05:49:53PM +0100, Alexander Gordeev wrote:
> On Mon, Jan 13, 2025 at 04:53:07PM +0100, Ard Biesheuvel wrote:
>
> Hi Ard,
>
> > 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.
>
> On s390 this is before:
>
> [32] .relaruntime[...] RELA 0000000000000000 13b3fe20
> [34] .relaruntime[...] RELA 0000000000000000 13b3fe98
>
> This is after:
>
> [ 2] .rela.text RELA 0000000000000000 13b3fe20
...
> [73] .rela.debug_[...] RELA 0000000000000000 298eb5a8
Sorry, I checked the wrong version. It works as expected.
Tested-by: Alexander Gordeev <agordeev@linux.ibm.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-13 15:53 [PATCH v3] kbuild: Strip runtime const RELA sections correctly Ard Biesheuvel
2025-01-16 22:02 ` Charlie Jenkins
2025-01-22 16:49 ` Alexander Gordeev
@ 2025-01-31 18:35 ` Masahiro Yamada
2025-01-31 18:40 ` Ard Biesheuvel
2025-02-03 19:16 ` patchwork-bot+linux-riscv
3 siblings, 1 reply; 11+ messages in thread
From: Masahiro Yamada @ 2025-01-31 18:35 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: linux-kbuild, linux-kernel, Ard Biesheuvel, Linus Torvalds,
linux-riscv, linux-s390, Ron Economos
On Tue, Jan 14, 2025 at 12:53 AM Ard Biesheuvel <ardb+git@google.com> wrote:
>
> From: Ard Biesheuvel <ardb@kernel.org>
>
> 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.
Dumb question - why can't you rename the section 'runtime*' to '.runtime*' ?
.rel* matches to sections that just happen to start with '.rel',
which may not be REL or RELA.
> 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.
>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: linux-riscv@lists.infradead.org
> Cc: linux-s390@vger.kernel.org
> Cc: Ron Economos <re@w6rz.net>
> Link: https://lore.kernel.org/all/CAHk-=wjk3ynjomNvFN8jf9A1k=qSc=JFF591W00uXj-qqNUxPQ@mail.gmail.com/
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> v3: put back missing 'endif' to fix the RISC-V build
> v2: add missing include of scripts/Makefile.lib
>
> arch/riscv/Makefile.postlink | 8 ++------
> arch/s390/Makefile.postlink | 6 +-----
> arch/x86/Makefile.postlink | 6 +-----
> scripts/Makefile.lib | 3 +++
> 4 files changed, 7 insertions(+), 18 deletions(-)
>
> diff --git a/arch/riscv/Makefile.postlink b/arch/riscv/Makefile.postlink
> index 829b9abc91f6..750d2784f69e 100644
> --- a/arch/riscv/Makefile.postlink
> +++ b/arch/riscv/Makefile.postlink
> @@ -10,6 +10,7 @@ __archpost:
>
> -include include/config/auto.conf
> include $(srctree)/scripts/Kbuild.include
> +include $(srctree)/scripts/Makefile.lib
>
> quiet_cmd_relocs_check = CHKREL $@
> cmd_relocs_check = \
> @@ -19,11 +20,6 @@ ifdef CONFIG_RELOCATABLE
> quiet_cmd_cp_vmlinux_relocs = CPREL vmlinux.relocs
> cmd_cp_vmlinux_relocs = cp vmlinux vmlinux.relocs
>
> -quiet_cmd_relocs_strip = STRIPREL $@
> -cmd_relocs_strip = $(OBJCOPY) --remove-section='.rel.*' \
> - --remove-section='.rel__*' \
> - --remove-section='.rela.*' \
> - --remove-section='.rela__*' $@
> endif
>
> # `@true` prevents complaint when there is nothing to be done
> @@ -33,7 +27,7 @@ vmlinux: FORCE
> ifdef CONFIG_RELOCATABLE
> $(call if_changed,relocs_check)
> $(call if_changed,cp_vmlinux_relocs)
> - $(call if_changed,relocs_strip)
> + $(call if_changed,strip_relocs)
> endif
>
> clean:
> diff --git a/arch/s390/Makefile.postlink b/arch/s390/Makefile.postlink
> index df82f5410769..1ae5478cd6ac 100644
> --- a/arch/s390/Makefile.postlink
> +++ b/arch/s390/Makefile.postlink
> @@ -11,6 +11,7 @@ __archpost:
>
> -include include/config/auto.conf
> include $(srctree)/scripts/Kbuild.include
> +include $(srctree)/scripts/Makefile.lib
>
> CMD_RELOCS=arch/s390/tools/relocs
> OUT_RELOCS = arch/s390/boot
> @@ -19,11 +20,6 @@ quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/relocs.S
> mkdir -p $(OUT_RELOCS); \
> $(CMD_RELOCS) $@ > $(OUT_RELOCS)/relocs.S
>
> -quiet_cmd_strip_relocs = RSTRIP $@
> - cmd_strip_relocs = \
> - $(OBJCOPY) --remove-section='.rel.*' --remove-section='.rel__*' \
> - --remove-section='.rela.*' --remove-section='.rela__*' $@
> -
> vmlinux: FORCE
> $(call cmd,relocs)
> $(call cmd,strip_relocs)
> diff --git a/arch/x86/Makefile.postlink b/arch/x86/Makefile.postlink
> index fef2e977cc7d..8b8a68162c94 100644
> --- a/arch/x86/Makefile.postlink
> +++ b/arch/x86/Makefile.postlink
> @@ -11,6 +11,7 @@ __archpost:
>
> -include include/config/auto.conf
> include $(srctree)/scripts/Kbuild.include
> +include $(srctree)/scripts/Makefile.lib
>
> CMD_RELOCS = arch/x86/tools/relocs
> OUT_RELOCS = arch/x86/boot/compressed
> @@ -20,11 +21,6 @@ quiet_cmd_relocs = RELOCS $(OUT_RELOCS)/$@.relocs
> $(CMD_RELOCS) $@ > $(OUT_RELOCS)/$@.relocs; \
> $(CMD_RELOCS) --abs-relocs $@
>
> -quiet_cmd_strip_relocs = RSTRIP $@
> - cmd_strip_relocs = \
> - $(OBJCOPY) --remove-section='.rel.*' --remove-section='.rel__*' \
> - --remove-section='.rela.*' --remove-section='.rela__*' $@
> -
> # `@true` prevents complaint when there is nothing to be done
>
> vmlinux: FORCE
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 7395200538da..f604f51d23ca 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -374,6 +374,9 @@ quiet_cmd_ar = AR $@
> quiet_cmd_objcopy = OBJCOPY $@
> cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
>
> +quiet_cmd_strip_relocs = RSTRIP $@
> +cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $@
> +
> # Gzip
> # ---------------------------------------------------------------------------
>
> --
> 2.47.1.688.g23fc6f90ad-goog
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-31 18:35 ` Masahiro Yamada
@ 2025-01-31 18:40 ` Ard Biesheuvel
2025-01-31 18:57 ` Masahiro Yamada
0 siblings, 1 reply; 11+ messages in thread
From: Ard Biesheuvel @ 2025-01-31 18:40 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Ard Biesheuvel, linux-kbuild, linux-kernel, Linus Torvalds,
linux-riscv, linux-s390, Ron Economos
On Fri, 31 Jan 2025 at 19:35, Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Tue, Jan 14, 2025 at 12:53 AM Ard Biesheuvel <ardb+git@google.com> wrote:
> >
> > From: Ard Biesheuvel <ardb@kernel.org>
> >
> > 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.
>
>
> Dumb question - why can't you rename the section 'runtime*' to '.runtime*' ?
>
> .rel* matches to sections that just happen to start with '.rel',
> which may not be REL or RELA.
>
That is what I proposed originally [0] but it was shot down by Linus.
[0] https://lore.kernel.org/all/20241014125703.2287936-4-ardb+git@google.com/T/#u
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-31 18:40 ` Ard Biesheuvel
@ 2025-01-31 18:57 ` Masahiro Yamada
2025-01-31 19:02 ` Ard Biesheuvel
0 siblings, 1 reply; 11+ messages in thread
From: Masahiro Yamada @ 2025-01-31 18:57 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: Ard Biesheuvel, linux-kbuild, linux-kernel, Linus Torvalds,
linux-riscv, linux-s390, Ron Economos
On Sat, Feb 1, 2025 at 3:40 AM Ard Biesheuvel <ardb@kernel.org> wrote:
>
> On Fri, 31 Jan 2025 at 19:35, Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > On Tue, Jan 14, 2025 at 12:53 AM Ard Biesheuvel <ardb+git@google.com> wrote:
> > >
> > > From: Ard Biesheuvel <ardb@kernel.org>
> > >
> > > 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.
> >
> >
> > Dumb question - why can't you rename the section 'runtime*' to '.runtime*' ?
> >
> > .rel* matches to sections that just happen to start with '.rel',
> > which may not be REL or RELA.
> >
>
> That is what I proposed originally [0] but it was shot down by Linus.
>
> [0] https://lore.kernel.org/all/20241014125703.2287936-4-ardb+git@google.com/T/#u
Does this work ?
$(OBJCOPY) --remove-relocations='*' $@
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-31 18:57 ` Masahiro Yamada
@ 2025-01-31 19:02 ` Ard Biesheuvel
2025-01-31 19:27 ` Masahiro Yamada
0 siblings, 1 reply; 11+ messages in thread
From: Ard Biesheuvel @ 2025-01-31 19:02 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Ard Biesheuvel, linux-kbuild, linux-kernel, Linus Torvalds,
linux-riscv, linux-s390, Ron Economos
On Fri, 31 Jan 2025 at 19:58, Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Sat, Feb 1, 2025 at 3:40 AM Ard Biesheuvel <ardb@kernel.org> wrote:
> >
> > On Fri, 31 Jan 2025 at 19:35, Masahiro Yamada <masahiroy@kernel.org> wrote:
> > >
> > > On Tue, Jan 14, 2025 at 12:53 AM Ard Biesheuvel <ardb+git@google.com> wrote:
> > > >
> > > > From: Ard Biesheuvel <ardb@kernel.org>
> > > >
> > > > 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.
> > >
> > >
> > > Dumb question - why can't you rename the section 'runtime*' to '.runtime*' ?
> > >
> > > .rel* matches to sections that just happen to start with '.rel',
> > > which may not be REL or RELA.
> > >
> >
> > That is what I proposed originally [0] but it was shot down by Linus.
> >
> > [0] https://lore.kernel.org/all/20241014125703.2287936-4-ardb+git@google.com/T/#u
>
>
> Does this work ?
>
> $(OBJCOPY) --remove-relocations='*' $@
>
Only with binutils, not with llvm-objcopy
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-31 19:02 ` Ard Biesheuvel
@ 2025-01-31 19:27 ` Masahiro Yamada
0 siblings, 0 replies; 11+ messages in thread
From: Masahiro Yamada @ 2025-01-31 19:27 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: Ard Biesheuvel, linux-kbuild, linux-kernel, Linus Torvalds,
linux-riscv, linux-s390, Ron Economos
On Sat, Feb 1, 2025 at 4:02 AM Ard Biesheuvel <ardb@kernel.org> wrote:
>
> On Fri, 31 Jan 2025 at 19:58, Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > On Sat, Feb 1, 2025 at 3:40 AM Ard Biesheuvel <ardb@kernel.org> wrote:
> > >
> > > On Fri, 31 Jan 2025 at 19:35, Masahiro Yamada <masahiroy@kernel.org> wrote:
> > > >
> > > > On Tue, Jan 14, 2025 at 12:53 AM Ard Biesheuvel <ardb+git@google.com> wrote:
> > > > >
> > > > > From: Ard Biesheuvel <ardb@kernel.org>
> > > > >
> > > > > 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.
> > > >
> > > >
> > > > Dumb question - why can't you rename the section 'runtime*' to '.runtime*' ?
> > > >
> > > > .rel* matches to sections that just happen to start with '.rel',
> > > > which may not be REL or RELA.
> > > >
> > >
> > > That is what I proposed originally [0] but it was shot down by Linus.
> > >
> > > [0] https://lore.kernel.org/all/20241014125703.2287936-4-ardb+git@google.com/T/#u
> >
> >
> > Does this work ?
> >
> > $(OBJCOPY) --remove-relocations='*' $@
> >
>
> Only with binutils, not with llvm-objcopy
Applied to linux-kbuild.
Thanks.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
2025-01-13 15:53 [PATCH v3] kbuild: Strip runtime const RELA sections correctly Ard Biesheuvel
` (2 preceding siblings ...)
2025-01-31 18:35 ` Masahiro Yamada
@ 2025-02-03 19:16 ` patchwork-bot+linux-riscv
3 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-02-03 19:16 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: linux-riscv, linux-kbuild, linux-kernel, ardb, torvalds,
masahiroy, linux-s390, re
Hello:
This patch was applied to riscv/linux.git (fixes)
by Masahiro Yamada <masahiroy@kernel.org>:
On Mon, 13 Jan 2025 16:53:07 +0100 you wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
>
> 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.
>
> [...]
Here is the summary with links:
- [v3] kbuild: Strip runtime const RELA sections correctly
https://git.kernel.org/riscv/c/71d815bf5dfd
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-02-03 19:15 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-13 15:53 [PATCH v3] kbuild: Strip runtime const RELA sections correctly Ard Biesheuvel
2025-01-16 22:02 ` Charlie Jenkins
2025-01-19 17:15 ` Ard Biesheuvel
2025-01-22 16:49 ` Alexander Gordeev
2025-01-22 17:22 ` Alexander Gordeev
2025-01-31 18:35 ` Masahiro Yamada
2025-01-31 18:40 ` Ard Biesheuvel
2025-01-31 18:57 ` Masahiro Yamada
2025-01-31 19:02 ` Ard Biesheuvel
2025-01-31 19:27 ` Masahiro Yamada
2025-02-03 19:16 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).