[1/2] s390: Do not replace brcth referencing undefined weak symbol

Message ID 20240626152033.2567309-2-jremus@linux.ibm.com
State New
Headers
Series s390: Avoid relocation overflows on undefined weak symbols |

Checks

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

Commit Message

Jens Remus June 26, 2024, 3:20 p.m. UTC
  Branch Relative on Count High (brcth) is a conditional branch relative
instruction. It is not guaranteed that it only appears within loops
that sooner or later will take the branch. It may very well be used to
check a condition that will prevent the branch from ever being taken.

bfd/
	* elf64-s390.c (elf_s390_relocate_section): Do not replace brcth
	referencing undefined weak symbol with a trap.

ld/
	* testsuite/ld-s390/weakundef-1.s: Update test case accordingly.
	* testsuite/ld-s390/weakundef-1.dd: Likewise.

Fixes: 896a639babe2 ("s390: Avoid reloc overflows on undefined weak symbols")
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
 bfd/elf64-s390.c                    | 5 ++---
 ld/testsuite/ld-s390/weakundef-1.dd | 6 +++---
 ld/testsuite/ld-s390/weakundef-1.s  | 1 -
 3 files changed, 5 insertions(+), 7 deletions(-)
  

Comments

Andreas Krebbel July 12, 2024, 12:27 p.m. UTC | #1
On 6/26/24 17:20, Jens Remus wrote:
> Branch Relative on Count High (brcth) is a conditional branch relative
> instruction. It is not guaranteed that it only appears within loops
> that sooner or later will take the branch. It may very well be used to
> check a condition that will prevent the branch from ever being taken.
>
> bfd/
> 	* elf64-s390.c (elf_s390_relocate_section): Do not replace brcth
> 	referencing undefined weak symbol with a trap.
>
> ld/
> 	* testsuite/ld-s390/weakundef-1.s: Update test case accordingly.
> 	* testsuite/ld-s390/weakundef-1.dd: Likewise.
>
> Fixes: 896a639babe2 ("s390: Avoid reloc overflows on undefined weak symbols")
> Signed-off-by: Jens Remus <jremus@linux.ibm.com>

Ok. Thanks!


Andreas
  

Patch

diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index 05dd4e80c6b3..2f35da4a6275 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -2517,10 +2517,9 @@  elf_s390_relocate_section (bfd *output_bfd,
 		 - store halfword relative long (sthrl)
 		 - execute relative long (exrl)
 		 - compare (logical) relative long (crl, clrl, cgrl, clgrl, cgfrl, clgfrl)
-		 - compare (logical) halfword relative long (chrl, cghrl, clhrl, clghrl)
-		 - branch relative on count high (brcth)  */
+		 - compare (logical) halfword relative long (chrl, cghrl, clhrl, clghrl)  */
 	      else if (op == 0xc005 || (op & 0xff00) == 0xc400
-		       || (op & 0xff00) == 0xc600 || op == 0xcc06)
+		       || (op & 0xff00) == 0xc600)
 		{
 		  /* Emit a 6-byte trap: jg .+2  */
 		  bfd_put_16 (output_bfd, 0xc0f4, insn_start);
diff --git a/ld/testsuite/ld-s390/weakundef-1.dd b/ld/testsuite/ld-s390/weakundef-1.dd
index e5145245602e..04d53c91d58e 100644
--- a/ld/testsuite/ld-s390/weakundef-1.dd
+++ b/ld/testsuite/ld-s390/weakundef-1.dd
@@ -3,13 +3,13 @@  tmpdir/weakundef-1:     file format elf64-s390
 Disassembly of section .text:
 
 .* <foo>:
-.*:	c0 10 00 00 00 1e [	 ]*larl	%r1,20000003c <d>
-.*:	c0 10 00 00 00 1f [	 ]*larl	%r1,200000044 <wd>
+.*:	c0 10 00 00 00 1c [	 ]*larl	%r1,200000038 <d>
+.*:	c0 10 00 00 00 1d [	 ]*larl	%r1,200000040 <wd>
 .*:	e3 10 00 00 00 71 [	 ]*lay	%r1,0
 .*:	c0 f4 00 00 00 01 [	 ]*jg	.*
 .*:	c0 f4 00 00 00 01 [	 ]*jg	.*
 .*:	c0 f4 00 00 00 01 [	 ]*jg	.*
 .*:	c0 f4 00 00 00 01 [	 ]*jg	.*
 .*:	c0 f4 00 00 00 01 [	 ]*jg	.*
-.*:	c0 f4 00 00 00 01 [	 ]*jg	.*
 .*:	c0 04 00 00 00 00 [	 ]*jgnop	.*
+.*:	07 07 [	 ]*nopr	%r7
diff --git a/ld/testsuite/ld-s390/weakundef-1.s b/ld/testsuite/ld-s390/weakundef-1.s
index aeaef8d2456f..db909329cda6 100644
--- a/ld/testsuite/ld-s390/weakundef-1.s
+++ b/ld/testsuite/ld-s390/weakundef-1.s
@@ -9,7 +9,6 @@  foo:
 	lrl	%r1,wu
 	strl	%r1,wu
 	exrl	%r1,wu
-	brcth	%r1,wu
 	pfdrl	%r1,wu
 	.weak	wd
 	.weak	wu