linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/boot: move the .got section to after the .dynamic section
@ 2020-10-17  0:01 Bill Wendling
  2020-10-19 23:56 ` Fāng-ruì Sòng
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bill Wendling @ 2020-10-17  0:01 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Fangrui Song, Alan Modra, Paul Mackerras, Bill Wendling

Both .dynamic and .got are RELRO sections and should be placed together,
and LLD emits an error:

  ld.lld: error: section: .got is not contiguous with other relro sections

Place them together to avoid this.

Cc: Fangrui Song <maskray@google.com>
Cc: Alan Modra <amodra@gmail.com>
Signed-off-by: Bill Wendling <morbo@google.com>
---
 arch/powerpc/boot/zImage.lds.S | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/boot/zImage.lds.S b/arch/powerpc/boot/zImage.lds.S
index a21f3a76e06f..d6f072865627 100644
--- a/arch/powerpc/boot/zImage.lds.S
+++ b/arch/powerpc/boot/zImage.lds.S
@@ -34,6 +34,17 @@ SECTIONS
     __dynamic_start = .;
     *(.dynamic)
   }
+
+#ifdef CONFIG_PPC64_BOOT_WRAPPER
+  . = ALIGN(256);
+  .got :
+  {
+    __toc_start = .;
+    *(.got)
+    *(.toc)
+  }
+#endif
+
   .hash : { *(.hash) }
   .interp : { *(.interp) }
   .rela.dyn :
@@ -76,16 +87,6 @@ SECTIONS
     _esm_blob_end =  .;
   }
 
-#ifdef CONFIG_PPC64_BOOT_WRAPPER
-  . = ALIGN(256);
-  .got :
-  {
-    __toc_start = .;
-    *(.got)
-    *(.toc)
-  }
-#endif
-
   . = ALIGN(4096);
   .bss       :
   {
-- 
2.29.0.rc1.297.gfa9743e501-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/boot: move the .got section to after the .dynamic section
  2020-10-17  0:01 [PATCH] powerpc/boot: move the .got section to after the .dynamic section Bill Wendling
@ 2020-10-19 23:56 ` Fāng-ruì Sòng
  2020-11-18 22:39 ` [PATCH] powerpc/wrapper: add "-z rodynamic" when using LLD Bill Wendling
  2020-12-10 11:30 ` [PATCH] powerpc/boot: move the .got section to after the .dynamic section Michael Ellerman
  2 siblings, 0 replies; 6+ messages in thread
From: Fāng-ruì Sòng @ 2020-10-19 23:56 UTC (permalink / raw)
  To: Bill Wendling; +Cc: Alan Modra, linuxppc-dev, Paul Mackerras

On Fri, Oct 16, 2020 at 5:01 PM Bill Wendling <morbo@google.com> wrote:
>
> Both .dynamic and .got are RELRO sections and should be placed together,
> and LLD emits an error:
>
>   ld.lld: error: section: .got is not contiguous with other relro sections
>
> Place them together to avoid this.
>
> Cc: Fangrui Song <maskray@google.com>
> Cc: Alan Modra <amodra@gmail.com>
> Signed-off-by: Bill Wendling <morbo@google.com>
> ---
>  arch/powerpc/boot/zImage.lds.S | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/arch/powerpc/boot/zImage.lds.S b/arch/powerpc/boot/zImage.lds.S
> index a21f3a76e06f..d6f072865627 100644
> --- a/arch/powerpc/boot/zImage.lds.S
> +++ b/arch/powerpc/boot/zImage.lds.S
> @@ -34,6 +34,17 @@ SECTIONS
>      __dynamic_start = .;
>      *(.dynamic)
>    }
> +
> +#ifdef CONFIG_PPC64_BOOT_WRAPPER
> +  . = ALIGN(256);
> +  .got :
> +  {
> +    __toc_start = .;
> +    *(.got)
> +    *(.toc)
> +  }
> +#endif
> +
>    .hash : { *(.hash) }
>    .interp : { *(.interp) }
>    .rela.dyn :
> @@ -76,16 +87,6 @@ SECTIONS
>      _esm_blob_end =  .;
>    }
>
> -#ifdef CONFIG_PPC64_BOOT_WRAPPER
> -  . = ALIGN(256);
> -  .got :
> -  {
> -    __toc_start = .;
> -    *(.got)
> -    *(.toc)
> -  }
> -#endif

The kernel does not require this but normally all read-only sections
precede SHF_WRITE sections.
.dynamic and .got have the SHF_WRITE flag and should be placed here.

Ideally, the order is: R RX RW(RELRO) RW(non-RELRO)  (LLD order)

For comparison:
GNU ld -z separate-code order: R RX R RW(RELRO) RW(non-RELRO) (GNU
ld>=2.31 enables -z separate-code by default for Linux x86)
GNU ld -z noseparate-code order: RX RW(RELRO) RW(non-RELRO)

(AFAIK The only reason .dynamic is writable is due to DT_DEBUG (whose
purpose is questionable nowadays). mips .dynamic is read-only. LLD has
an option -z rodynamic to make .dynamic readonly)

>    . = ALIGN(4096);
>    .bss       :
>    {
> --
> 2.29.0.rc1.297.gfa9743e501-goog
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] powerpc/wrapper: add "-z rodynamic" when using LLD
  2020-10-17  0:01 [PATCH] powerpc/boot: move the .got section to after the .dynamic section Bill Wendling
  2020-10-19 23:56 ` Fāng-ruì Sòng
@ 2020-11-18 22:39 ` Bill Wendling
  2020-11-18 22:55   ` Fangrui Song
  2020-12-10 11:30   ` Michael Ellerman
  2020-12-10 11:30 ` [PATCH] powerpc/boot: move the .got section to after the .dynamic section Michael Ellerman
  2 siblings, 2 replies; 6+ messages in thread
From: Bill Wendling @ 2020-11-18 22:39 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev
  Cc: Nick Desaulniers, Bill Wendling, Fangrui Song, Alan Modra

Normally all read-only sections precede SHF_WRITE sections. .dynamic and
.got have the SHF_WRITE flag; .dynamic probably because of DT_DEBUG. LLD
emits an error when this happens, so use "-z rodynamic" to mark .dynamic
as read-only.

Cc: Fangrui Song <maskray@google.com>
Cc: Alan Modra <amodra@gmail.com>
Signed-off-by: Bill Wendling <morbo@google.com>
---
 arch/powerpc/boot/wrapper | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
index cd58a62e810d..e1194955adbb 100755
--- a/arch/powerpc/boot/wrapper
+++ b/arch/powerpc/boot/wrapper
@@ -46,6 +46,7 @@ compression=.gz
 uboot_comp=gzip
 pie=
 format=
+rodynamic=
 
 # cross-compilation prefix
 CROSS=
@@ -353,6 +354,7 @@ epapr)
     platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o"
     link_address='0x20000000'
     pie=-pie
+    rodynamic=$(if ${CROSS}ld -V 2>&1 | grep -q LLD ; then echo "-z rodynamic"; fi)
     ;;
 mvme5100)
     platformo="$object/fixed-head.o $object/mvme5100.o"
@@ -493,7 +495,7 @@ if [ "$platform" != "miboot" ]; then
         text_start="-Ttext $link_address"
     fi
 #link everything
-    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl -o "$ofile" $map \
+    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl $rodynamic -o "$ofile" $map \
 	$platformo $tmp $object/wrapper.a
     rm $tmp
 fi
-- 
2.29.2.454.gaff20da3a2-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/wrapper: add "-z rodynamic" when using LLD
  2020-11-18 22:39 ` [PATCH] powerpc/wrapper: add "-z rodynamic" when using LLD Bill Wendling
@ 2020-11-18 22:55   ` Fangrui Song
  2020-12-10 11:30   ` Michael Ellerman
  1 sibling, 0 replies; 6+ messages in thread
From: Fangrui Song @ 2020-11-18 22:55 UTC (permalink / raw)
  To: Bill Wendling; +Cc: Alan Modra, Nick Desaulniers, linuxppc-dev

We could wait for https://lkml.org/lkml/2020/11/13/19
"[PATCH] kbuild: Always link with '-z norelro'"

Then we would not need -z rodynamic to work around a -z relro issue.

(The issue is that some sections don't strictly follow the normal
R/RX/RW(RELRO)/RW(non-RELRO) section flag partition. As a linker person
I would suggest that we don't create multiple clusters with the same
section flags (e.g. RW in two separate places), but this is my very
minor complaint.)

On 2020-11-18, Bill Wendling wrote:
>Normally all read-only sections precede SHF_WRITE sections. .dynamic and
>.got have the SHF_WRITE flag; .dynamic probably because of DT_DEBUG. LLD
>emits an error when this happens, so use "-z rodynamic" to mark .dynamic
>as read-only.
>
>Cc: Fangrui Song <maskray@google.com>
>Cc: Alan Modra <amodra@gmail.com>
>Signed-off-by: Bill Wendling <morbo@google.com>
>---
> arch/powerpc/boot/wrapper | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
>diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
>index cd58a62e810d..e1194955adbb 100755
>--- a/arch/powerpc/boot/wrapper
>+++ b/arch/powerpc/boot/wrapper
>@@ -46,6 +46,7 @@ compression=.gz
> uboot_comp=gzip
> pie=
> format=
>+rodynamic=
>
> # cross-compilation prefix
> CROSS=
>@@ -353,6 +354,7 @@ epapr)
>     platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o"
>     link_address='0x20000000'
>     pie=-pie
>+    rodynamic=$(if ${CROSS}ld -V 2>&1 | grep -q LLD ; then echo "-z rodynamic"; fi)
>     ;;
> mvme5100)
>     platformo="$object/fixed-head.o $object/mvme5100.o"
>@@ -493,7 +495,7 @@ if [ "$platform" != "miboot" ]; then
>         text_start="-Ttext $link_address"
>     fi
> #link everything
>-    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl -o "$ofile" $map \
>+    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl $rodynamic -o "$ofile" $map \
> 	$platformo $tmp $object/wrapper.a
>     rm $tmp
> fi
>-- 
>2.29.2.454.gaff20da3a2-goog
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/boot: move the .got section to after the .dynamic section
  2020-10-17  0:01 [PATCH] powerpc/boot: move the .got section to after the .dynamic section Bill Wendling
  2020-10-19 23:56 ` Fāng-ruì Sòng
  2020-11-18 22:39 ` [PATCH] powerpc/wrapper: add "-z rodynamic" when using LLD Bill Wendling
@ 2020-12-10 11:30 ` Michael Ellerman
  2 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2020-12-10 11:30 UTC (permalink / raw)
  To: Bill Wendling, linuxppc-dev; +Cc: Paul Mackerras, Fangrui Song, Alan Modra

On Fri, 16 Oct 2020 17:01:51 -0700, Bill Wendling wrote:
> Both .dynamic and .got are RELRO sections and should be placed together,
> and LLD emits an error:
> 
>   ld.lld: error: section: .got is not contiguous with other relro sections
> 
> Place them together to avoid this.

Applied to powerpc/next.

[1/1] powerpc/boot: Move the .got section to after the .dynamic section
      https://git.kernel.org/powerpc/c/a538d184e3f0e3b5f800c5ab148e83bb5cdd0133

cheers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] powerpc/wrapper: add "-z rodynamic" when using LLD
  2020-11-18 22:39 ` [PATCH] powerpc/wrapper: add "-z rodynamic" when using LLD Bill Wendling
  2020-11-18 22:55   ` Fangrui Song
@ 2020-12-10 11:30   ` Michael Ellerman
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2020-12-10 11:30 UTC (permalink / raw)
  To: Bill Wendling, linuxppc-dev, Michael Ellerman
  Cc: Nick Desaulniers, Fangrui Song, Alan Modra

On Wed, 18 Nov 2020 14:39:10 -0800, Bill Wendling wrote:
> Normally all read-only sections precede SHF_WRITE sections. .dynamic and
> .got have the SHF_WRITE flag; .dynamic probably because of DT_DEBUG. LLD
> emits an error when this happens, so use "-z rodynamic" to mark .dynamic
> as read-only.

Applied to powerpc/next.

[1/1] powerpc/boot/wrapper: Add "-z rodynamic" when using LLD
      https://git.kernel.org/powerpc/c/26ba9f9651d802ba38583138f43fea5dc7eb0fd6

cheers

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-12-10 14:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-17  0:01 [PATCH] powerpc/boot: move the .got section to after the .dynamic section Bill Wendling
2020-10-19 23:56 ` Fāng-ruì Sòng
2020-11-18 22:39 ` [PATCH] powerpc/wrapper: add "-z rodynamic" when using LLD Bill Wendling
2020-11-18 22:55   ` Fangrui Song
2020-12-10 11:30   ` Michael Ellerman
2020-12-10 11:30 ` [PATCH] powerpc/boot: move the .got section to after the .dynamic section Michael Ellerman

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).