ld: Fix ADDR32/64 incorrect outputs in pe-aarch64

Message ID 20230118051136.10243-1-mark@harmstone.com
State Accepted
Headers
Series ld: Fix ADDR32/64 incorrect outputs in pe-aarch64 |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Mark Harmstone Jan. 18, 2023, 5:11 a.m. UTC
  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(-)
  

Comments

Nick Clifton Jan. 24, 2023, 1:43 p.m. UTC | #1
Hi Mark,

> 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.

Approved - please apply.

Cheers
   Nick
  
Mark Harmstone Jan. 25, 2023, 12:12 a.m. UTC | #2
Thanks Nick, but I think the changes that Alan made have superseded this - I no longer get the test failures. Alan, please correct me if I'm wrong.

Mark

On 24/1/23 13:43, Nick Clifton wrote:
> Hi Mark,
>
>> 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.
>
> Approved - please apply.
>
> Cheers
>   Nick
>
  
Alan Modra Jan. 25, 2023, 2:29 a.m. UTC | #3
On Wed, Jan 25, 2023 at 12:12:07AM +0000, Mark Harmstone wrote:
> Thanks Nick, but I think the changes that Alan made have superseded this

That's right.  It would be a backward step to install this patch.
  

Patch

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;