public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Krebbel <krebbel@linux.ibm.com>
To: binutils@sourceware.org
Subject: [PATCH 1/1] IBM zSystems: Issue error for *DBL relocs on misaligned symbols
Date: Tue, 18 Oct 2022 10:12:05 +0200	[thread overview]
Message-ID: <20221018081205.17880-1-krebbel@linux.ibm.com> (raw)

Relocs like PC32DBL require a right shift of the symbol value.  There
is no situation where dropping symbol value bits with the right shift
is a good thing.  Hence we now issue an error to detect such problems.
---
 bfd/elf64-s390.c                    | 18 ++++++++++++++++++
 ld/testsuite/ld-s390/reloccheck-1.d |  5 +++++
 ld/testsuite/ld-s390/reloccheck-1.s | 14 ++++++++++++++
 3 files changed, 37 insertions(+)
 create mode 100644 ld/testsuite/ld-s390/reloccheck-1.d
 create mode 100644 ld/testsuite/ld-s390/reloccheck-1.s

diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index c1ed3d619d6..fa4497181fe 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -3056,6 +3056,24 @@ elf_s390_relocate_section (bfd *output_bfd,
 	  || r_type == R_390_PLT24DBL)
 	rel->r_offset--;
 
+      /* Issue an error if the right shift implied by the relocation
+	 would drop bits from the symbol value.  */
+      if (howto->rightshift
+	  && (relocation & (((bfd_vma)1 << howto->rightshift) - 1)))
+	{
+	  _bfd_error_handler
+	    /* xgettext:c-format */
+	    (_("%pB(%pA+%#" PRIx64 "): "
+	       "misaligned symbol `%s' (%#" PRIx64 ") for relocation %s"),
+	     input_bfd,
+	     input_section,
+	     (uint64_t) rel->r_offset,
+	     h->root.root.string,
+	     (uint64_t)relocation,
+	     howto->name);
+	  return false;
+	}
+
       if (r_type == R_390_20
 	  || r_type == R_390_GOT20
 	  || r_type == R_390_GOTPLT20
diff --git a/ld/testsuite/ld-s390/reloccheck-1.d b/ld/testsuite/ld-s390/reloccheck-1.d
new file mode 100644
index 00000000000..00c568cffa1
--- /dev/null
+++ b/ld/testsuite/ld-s390/reloccheck-1.d
@@ -0,0 +1,5 @@
+#as: -m64 -mzarch -march=z900
+#ld: -m elf64_s390 -e start -static
+#error: .*misaligned symbol.*
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-s390/reloccheck-1.s b/ld/testsuite/ld-s390/reloccheck-1.s
new file mode 100644
index 00000000000..6c932bdfb0c
--- /dev/null
+++ b/ld/testsuite/ld-s390/reloccheck-1.s
@@ -0,0 +1,14 @@
+        .machinemode zarch
+        .machine "z900"
+.text
+        .align  8
+.globl start
+        .type   start, @function
+start:
+	larl	%r1, test
+.globl	test
+.data
+	.align	4
+	.byte	23
+test:
+	.zero	4
-- 
2.37.3


                 reply	other threads:[~2022-10-18  8:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221018081205.17880-1-krebbel@linux.ibm.com \
    --to=krebbel@linux.ibm.com \
    --cc=binutils@sourceware.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 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).