public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Harmstone <mark@harmstone.com>
To: binutils@sourceware.org, amodra@gmail.com
Cc: Mark Harmstone <mark@harmstone.com>
Subject: [PATCH] ld: Fix ADDR32/64 incorrect outputs in pe-aarch64
Date: Wed, 18 Jan 2023 05:11:36 +0000	[thread overview]
Message-ID: <20230118051136.10243-1-mark@harmstone.com> (raw)

This changes coff_pe_aarch64_relocate_section to also perform
IMAGE_REL_ARM64_ADDR32 and IMAGE_REL_ARM64_ADDR64 relocations, which
fixes the test failures shown by 52936661.

---
 bfd/coff-aarch64.c | 45 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/bfd/coff-aarch64.c b/bfd/coff-aarch64.c
index 7f6511c82cb..a0cc4f01ae6 100644
--- a/bfd/coff-aarch64.c
+++ b/bfd/coff-aarch64.c
@@ -526,10 +526,7 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
       asection *sec = NULL;
       uint64_t dest_vma;
 
-      /* skip trivial relocations */
-      if (rel->r_type == IMAGE_REL_ARM64_ADDR32
-	  || rel->r_type == IMAGE_REL_ARM64_ADDR64
-	  || rel->r_type == IMAGE_REL_ARM64_ABSOLUTE)
+      if (rel->r_type == IMAGE_REL_ARM64_ABSOLUTE)
 	continue;
 
       symndx = rel->r_symndx;
@@ -564,6 +561,46 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd,
 
       switch (rel->r_type)
 	{
+	case IMAGE_REL_ARM64_ADDR32:
+	  {
+	    uint64_t val;
+	    int32_t addend;
+
+	    addend = bfd_getl32 (contents + rel->r_vaddr);
+
+	    dest_vma += addend;
+
+	    val = dest_vma;
+
+	    if (val > 0xffffffff)
+	      (*info->callbacks->reloc_overflow)
+		(info, h ? &h->root : NULL, syms[symndx]._n._n_name,
+		"IMAGE_REL_ARM64_ADDR32", addend, input_bfd,
+		input_section, rel->r_vaddr - input_section->vma);
+
+	    bfd_putl32 (val, contents + rel->r_vaddr);
+	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+
+	    break;
+	  }
+
+	case IMAGE_REL_ARM64_ADDR64:
+	  {
+	    uint64_t val;
+	    int64_t addend;
+
+	    addend = bfd_getl64 (contents + rel->r_vaddr);
+
+	    dest_vma += addend;
+
+	    val = dest_vma;
+
+	    bfd_putl64 (val, contents + rel->r_vaddr);
+	    rel->r_type = IMAGE_REL_ARM64_ABSOLUTE;
+
+	    break;
+	  }
+
 	case IMAGE_REL_ARM64_ADDR32NB:
 	  {
 	    uint64_t val;
-- 
2.38.2


             reply	other threads:[~2023-01-18  5:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-18  5:11 Mark Harmstone [this message]
2023-01-24 13:43 ` Nick Clifton
2023-01-25  0:12   ` Mark Harmstone
2023-01-25  2:29     ` Alan Modra

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=20230118051136.10243-1-mark@harmstone.com \
    --to=mark@harmstone.com \
    --cc=amodra@gmail.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).