public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
To: krebbel@linux.ibm.com, binutils@sourceware.org
Cc: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Subject: [PATCH] IBM zSystems: Fix offset relative to static TLS
Date: Tue, 10 Jan 2023 14:35:35 +0100	[thread overview]
Message-ID: <20230110133534.5295-1-stefansf@linux.ibm.com> (raw)

For local exec TLS relocations of the form foo@NTPOFF+x the addend was
ignored.

Build and tested on s390x.  Ok for mainline and branches 2.{39,40}?

bfd/ChangeLog:

	* elf32-s390.c (elf_s390_relocate_section): Honor addend for
	R_390_TLS_LE32.
	* elf64-s390.c (elf_s390_relocate_section): Honor addend for
	R_390_TLS_LE64.

ld/ChangeLog:

	* testsuite/ld-s390/reloctlsle-1.d: New test.
	* testsuite/ld-s390/reloctlsle-1.s: New test.
---
 bfd/elf32-s390.c                    |  4 ++--
 bfd/elf64-s390.c                    |  4 ++--
 ld/testsuite/ld-s390/reloctlsle-1.d |  6 ++++++
 ld/testsuite/ld-s390/reloctlsle-1.s | 14 ++++++++++++++
 4 files changed, 24 insertions(+), 4 deletions(-)
 create mode 100644 ld/testsuite/ld-s390/reloctlsle-1.d
 create mode 100644 ld/testsuite/ld-s390/reloctlsle-1.s

diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index 061307d6c3b..9496b1472d6 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -2706,7 +2706,7 @@ elf_s390_relocate_section (bfd *output_bfd,
 	      /* This relocation gets optimized away by the local exec
 		 access optimization.  */
 	      BFD_ASSERT (! unresolved_reloc);
-	      bfd_put_32 (output_bfd, -tpoff (info, relocation),
+	      bfd_put_32 (output_bfd, -tpoff (info, relocation) + rel->r_addend,
 			  contents + rel->r_offset);
 	      continue;
 	    }
@@ -2901,7 +2901,7 @@ elf_s390_relocate_section (bfd *output_bfd,
 	  else
 	    {
 	      BFD_ASSERT (! unresolved_reloc);
-	      bfd_put_32 (output_bfd, -tpoff (info, relocation),
+	      bfd_put_32 (output_bfd, -tpoff (info, relocation) + rel->r_addend,
 			  contents + rel->r_offset);
 	    }
 	  continue;
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index 5279660f8f5..bcf59032c41 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -2714,7 +2714,7 @@ elf_s390_relocate_section (bfd *output_bfd,
 	      /* This relocation gets optimized away by the local exec
 		 access optimization.  */
 	      BFD_ASSERT (! unresolved_reloc);
-	      bfd_put_64 (output_bfd, -tpoff (info, relocation),
+	      bfd_put_64 (output_bfd, -tpoff (info, relocation) + rel->r_addend,
 			  contents + rel->r_offset);
 	      continue;
 	    }
@@ -2907,7 +2907,7 @@ elf_s390_relocate_section (bfd *output_bfd,
 	  else
 	    {
 	      BFD_ASSERT (! unresolved_reloc);
-	      bfd_put_64 (output_bfd, -tpoff (info, relocation),
+	      bfd_put_64 (output_bfd, -tpoff (info, relocation) + rel->r_addend,
 			  contents + rel->r_offset);
 	    }
 	  continue;
diff --git a/ld/testsuite/ld-s390/reloctlsle-1.d b/ld/testsuite/ld-s390/reloctlsle-1.d
new file mode 100644
index 00000000000..a24c3d60c25
--- /dev/null
+++ b/ld/testsuite/ld-s390/reloctlsle-1.d
@@ -0,0 +1,6 @@
+#as: -m64 -mzarch -march=z900
+#ld: -m elf64_s390 -static
+#readelf: -x .data
+
+Hex dump of section '.data':
+  0x[0-9a-f]+ ffffffff fffffff0 ffffffff fffffff8 ................
diff --git a/ld/testsuite/ld-s390/reloctlsle-1.s b/ld/testsuite/ld-s390/reloctlsle-1.s
new file mode 100644
index 00000000000..c8f351dd6e6
--- /dev/null
+++ b/ld/testsuite/ld-s390/reloctlsle-1.s
@@ -0,0 +1,14 @@
+	.text
+	.globl	_start
+_start:
+	larl	%r0,bar
+
+	.section .tbss,"awT",@nobits
+	.align	8
+foo:	.zero	8
+	.zero	8
+
+	.data
+	.align	8
+	.quad	foo@NTPOFF
+bar:	.quad	foo@NTPOFF+8
-- 
2.38.1


             reply	other threads:[~2023-01-10 13:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10 13:35 Stefan Schulze Frielinghaus [this message]
2023-01-10 13:40 ` Andreas Krebbel

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=20230110133534.5295-1-stefansf@linux.ibm.com \
    --to=stefansf@linux.ibm.com \
    --cc=binutils@sourceware.org \
    --cc=krebbel@linux.ibm.com \
    /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 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 read-only IMAP folder(s) and NNTP newsgroup(s).