IBM zSystems: Rewrite l(g)rl @GOTENT to larl for --no-pie

Message ID 20240610133530.650063-1-iii@linux.ibm.com
State New
Headers
Series IBM zSystems: Rewrite l(g)rl @GOTENT to larl for --no-pie |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed

Commit Message

Ilya Leoshkevich June 10, 2024, 1:33 p.m. UTC
  Regtested on s390x-redhat-linux.


Rewriting l(g)rl @GOTENT to larl is unnecessarily guarded by
bfd_link_pic().  There were no use cases for this in the past, but
since recently the Linux Kernel on s390x is compiled with -fPIE
and linked with --no-pie.  Remove the unnecessary bfd_link_pic()
check.

bfd/ChangeLog:

        * elf32-s390.c (elf_s390_relocate_section): Don't check for
	bfd_link_pic() when rewriting lrl@GOTENT to larl.
	(elf_s390_finish_dynamic_symbol): Emit a relative reloc for
	the above case.
        * elf64-s390.c (elf_s390_relocate_section): Don't check for
	bfd_link_pic() when rewriting lgrl@GOTENT to larl.
	(elf_s390_finish_dynamic_symbol): Emit a relative reloc for
	the above case.

ld/ChangeLog:

        * testsuite/ld-s390/s390.exp: Hook up the new tests.
        * testsuite/ld-s390/gotreloc_31-no-pie-1.dd: New test.
        * testsuite/ld-s390/gotreloc_64-no-pie-1.dd: New test.
---
 bfd/elf32-s390.c                             |  7 ++-----
 bfd/elf64-s390.c                             | 11 ++++-------
 ld/testsuite/ld-s390/gotreloc_31-no-pie-1.dd | 13 +++++++++++++
 ld/testsuite/ld-s390/gotreloc_64-no-pie-1.dd | 12 ++++++++++++
 ld/testsuite/ld-s390/s390.exp                | 10 ++++++++++
 5 files changed, 41 insertions(+), 12 deletions(-)
 create mode 100644 ld/testsuite/ld-s390/gotreloc_31-no-pie-1.dd
 create mode 100644 ld/testsuite/ld-s390/gotreloc_64-no-pie-1.dd
  

Comments

Andreas Krebbel June 10, 2024, 1:57 p.m. UTC | #1
On 6/10/24 15:33, Ilya Leoshkevich wrote:
> Regtested on s390x-redhat-linux.
>
>
> Rewriting l(g)rl @GOTENT to larl is unnecessarily guarded by
> bfd_link_pic().  There were no use cases for this in the past, but
> since recently the Linux Kernel on s390x is compiled with -fPIE
> and linked with --no-pie.  Remove the unnecessary bfd_link_pic()
> check.
>
> bfd/ChangeLog:
>
>          * elf32-s390.c (elf_s390_relocate_section): Don't check for
> 	bfd_link_pic() when rewriting lrl@GOTENT to larl.
> 	(elf_s390_finish_dynamic_symbol): Emit a relative reloc for
> 	the above case.
>          * elf64-s390.c (elf_s390_relocate_section): Don't check for
> 	bfd_link_pic() when rewriting lgrl@GOTENT to larl.
> 	(elf_s390_finish_dynamic_symbol): Emit a relative reloc for
> 	the above case.
>
> ld/ChangeLog:
>
>          * testsuite/ld-s390/s390.exp: Hook up the new tests.
>          * testsuite/ld-s390/gotreloc_31-no-pie-1.dd: New test.
>          * testsuite/ld-s390/gotreloc_64-no-pie-1.dd: New test.

Ok. Thanks!


Andreas
  

Patch

diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index 2b97b7d2aec..702b0239dd5 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -2236,8 +2236,7 @@  elf_s390_relocate_section (bfd *output_bfd,
 	      else if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
 							  bfd_link_pic (info),
 							  h)
-		       || (bfd_link_pic (info)
-			   && SYMBOL_REFERENCES_LOCAL (info, h))
+		       || SYMBOL_REFERENCES_LOCAL (info, h)
 		       || resolved_to_zero)
 		{
 		  /* This is actually a static link, or it is a
@@ -2262,7 +2261,6 @@  elf_s390_relocate_section (bfd *output_bfd,
 		    }
 
 		  if ((h->def_regular
-		       && bfd_link_pic (info)
 		       && SYMBOL_REFERENCES_LOCAL (info, h))
 		      /* lrl rx,sym@GOTENT -> larl rx, sym */
 		      && ((r_type == R_390_GOTENT
@@ -3492,8 +3490,7 @@  elf_s390_finish_dynamic_symbol (bfd *output_bfd,
 	      return true;
 	    }
 	}
-      else if (bfd_link_pic (info)
-	       && SYMBOL_REFERENCES_LOCAL (info, h))
+      else if (SYMBOL_REFERENCES_LOCAL (info, h))
 	{
 	  if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
 	    return true;
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index d3b6e17ed64..05dd4e80c6b 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -2222,8 +2222,7 @@  elf_s390_relocate_section (bfd *output_bfd,
 	      else if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
 							  bfd_link_pic (info),
 							  h)
-		       || (bfd_link_pic (info)
-			   && SYMBOL_REFERENCES_LOCAL (info, h))
+		       || SYMBOL_REFERENCES_LOCAL (info, h)
 		       || resolved_to_zero)
 		{
 		  Elf_Internal_Sym *isym;
@@ -2254,9 +2253,8 @@  elf_s390_relocate_section (bfd *output_bfd,
 		     reference using larl we have to make sure that
 		     the symbol is 1. properly aligned and 2. it is no
 		     ABS symbol or will become one.  */
-		  if ((h->def_regular
-		       && bfd_link_pic (info)
-		       && SYMBOL_REFERENCES_LOCAL (info, h))
+		  if (h->def_regular
+		      && SYMBOL_REFERENCES_LOCAL (info, h)
 		      /* lgrl rx,sym@GOTENT -> larl rx, sym */
 		      && ((r_type == R_390_GOTENT
 			   && (bfd_get_16 (input_bfd,
@@ -3414,8 +3412,7 @@  elf_s390_finish_dynamic_symbol (bfd *output_bfd,
 	      return true;
 	    }
 	}
-      else if (bfd_link_pic (info)
-	       && SYMBOL_REFERENCES_LOCAL (info, h))
+      else if (SYMBOL_REFERENCES_LOCAL (info, h))
 	{
 	  if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
 	    return true;
diff --git a/ld/testsuite/ld-s390/gotreloc_31-no-pie-1.dd b/ld/testsuite/ld-s390/gotreloc_31-no-pie-1.dd
new file mode 100644
index 00000000000..2e0d2cda87b
--- /dev/null
+++ b/ld/testsuite/ld-s390/gotreloc_31-no-pie-1.dd
@@ -0,0 +1,13 @@ 
+
+tmpdir/gotreloc_31-1:     file format elf32-s390
+
+Disassembly of section .text:
+
+.* <foo>:
+.*:	c4 18 00 00 08 1e [	 ]*lgrl	%r1,4010b0 <_GLOBAL_OFFSET_TABLE_\+0x14>
+.*:	e3 10 c0 14 00 04 [	 ]*lg	%r1,20\(%r12\)
+.*:	c0 10 00 00 08 1a [	 ]*larl	%r1,4010b4 <bar>
+.*:	58 10 c0 14 [	 ]*l	%r1,20\(%r12\)
+.*:	c0 10 00 00 08 15 [	 ]*larl	%r1,4010b4 <bar>
+.*:	c4 18 00 00 08 0e [	 ]*lgrl	%r1,4010ac <_GLOBAL_OFFSET_TABLE_\+0x10>
+.*:	c4 18 00 00 08 09 [	 ]*lgrl	%r1,4010a8 <_GLOBAL_OFFSET_TABLE_\+0xc>
diff --git a/ld/testsuite/ld-s390/gotreloc_64-no-pie-1.dd b/ld/testsuite/ld-s390/gotreloc_64-no-pie-1.dd
new file mode 100644
index 00000000000..751b7a8de6d
--- /dev/null
+++ b/ld/testsuite/ld-s390/gotreloc_64-no-pie-1.dd
@@ -0,0 +1,12 @@ 
+tmpdir/gotreloc_64-1:     file format elf64-s390
+
+Disassembly of section .text:
+
+.* <foo>:
+.*:	c0 10 00 00 08 2c [	 ]*larl	%r1,1001108 <bar>
+.*:	c0 10 00 00 08 29 [	 ]*larl	%r1,1001108 <bar>
+.*:	c4 1d 00 00 08 22 [	 ]*lrl	%r1,1001100 <_GLOBAL_OFFSET_TABLE_\+0x28>
+.*:	58 10 c0 28 [	 ]*l	%r1,40\(%r12\)
+.*:	e3 10 c0 28 00 58 [	 ]*ly	%r1,40\(%r12\)
+.*:	c4 18 00 00 08 16 [	 ]*lgrl	%r1,10010f8 <_GLOBAL_OFFSET_TABLE_\+0x20>
+.*:	c4 18 00 00 08 0f [	 ]*lgrl	%r1,10010f0 <_GLOBAL_OFFSET_TABLE_\+0x18>
diff --git a/ld/testsuite/ld-s390/s390.exp b/ld/testsuite/ld-s390/s390.exp
index 6b97b6c07d9..eb9ea35400b 100644
--- a/ld/testsuite/ld-s390/s390.exp
+++ b/ld/testsuite/ld-s390/s390.exp
@@ -54,6 +54,11 @@  set s390tests {
      "-m31" {gotreloc-1.s}
      {{objdump -dzrj.text gotreloc_31-1.dd}}
      "gotreloc_31-1"}
+    {"GOT: no-pie symbol address load from got to larl"
+     "-shared -melf_s390 --no-pie --hash-style=sysv --version-script=gotreloc-1.ver" ""
+     "-m31" {gotreloc-1.s}
+     {{objdump -dzrj.text gotreloc_31-no-pie-1.dd}}
+     "gotreloc_31-1"}
 }
 
 set s390xtests {
@@ -80,6 +85,11 @@  set s390xtests {
      "-m64" {gotreloc-1.s}
      {{objdump -dzrj.text gotreloc_64-relro-1.dd}}
      "gotreloc_64-1"}
+    {"GOT: no-pie symbol address load from got to larl"
+     "-shared -melf64_s390 --no-pie --hash-style=sysv --version-script=gotreloc-1.ver" ""
+     "-m64" {gotreloc-1.s}
+     {{objdump -dzrj.text gotreloc_64-no-pie-1.dd}}
+     "gotreloc_64-1"}
     {"PLT: offset test"
      "-shared -m elf64_s390 -dT pltoffset-1.ld --no-error-rwx-segments" ""
      "-m64" {pltoffset-1.s}