All of lore.kernel.org
 help / color / mirror / Atom feed
From: Charlie Jenkins <charlie@rivosinc.com>
To: Ard Biesheuvel <ardb+git@google.com>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ard Biesheuvel <ardb@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Alexandre Ghiti <alexghiti@rivosinc.com>,
	linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org,
	Ron Economos <re@w6rz.net>
Subject: Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
Date: Thu, 16 Jan 2025 14:02:32 -0800	[thread overview]
Message-ID: <Z4mB-I5jeGithAQX@ghost> (raw)
In-Reply-To: <20250113155306.1922992-2-ardb+git@google.com>

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

WARNING: multiple messages have this Message-ID (diff)
From: Charlie Jenkins <charlie@rivosinc.com>
To: Ard Biesheuvel <ardb+git@google.com>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ard Biesheuvel <ardb@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Alexandre Ghiti <alexghiti@rivosinc.com>,
	linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org,
	Ron Economos <re@w6rz.net>
Subject: Re: [PATCH v3] kbuild: Strip runtime const RELA sections correctly
Date: Thu, 16 Jan 2025 14:02:32 -0800	[thread overview]
Message-ID: <Z4mB-I5jeGithAQX@ghost> (raw)
In-Reply-To: <20250113155306.1922992-2-ardb+git@google.com>

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

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2025-01-16 22:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13 15:53 [PATCH v3] kbuild: Strip runtime const RELA sections correctly Ard Biesheuvel
2025-01-13 15:53 ` Ard Biesheuvel
2025-01-16 22:02 ` Charlie Jenkins [this message]
2025-01-16 22:02   ` Charlie Jenkins
2025-01-19 17:15   ` Ard Biesheuvel
2025-01-19 17:15     ` Ard Biesheuvel
2025-01-22 16:49 ` Alexander Gordeev
2025-01-22 16:49   ` Alexander Gordeev
2025-01-22 17:22   ` Alexander Gordeev
2025-01-22 17:22     ` Alexander Gordeev
2025-01-31 18:35 ` Masahiro Yamada
2025-01-31 18:35   ` Masahiro Yamada
2025-01-31 18:40   ` Ard Biesheuvel
2025-01-31 18:40     ` Ard Biesheuvel
2025-01-31 18:57     ` Masahiro Yamada
2025-01-31 18:57       ` Masahiro Yamada
2025-01-31 19:02       ` Ard Biesheuvel
2025-01-31 19:02         ` Ard Biesheuvel
2025-01-31 19:27         ` Masahiro Yamada
2025-01-31 19:27           ` Masahiro Yamada
2025-02-03 19:16 ` patchwork-bot+linux-riscv
2025-02-03 19:16   ` patchwork-bot+linux-riscv

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z4mB-I5jeGithAQX@ghost \
    --to=charlie@rivosinc.com \
    --cc=alexghiti@rivosinc.com \
    --cc=ardb+git@google.com \
    --cc=ardb@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=re@w6rz.net \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.