public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: Szabolcs Nagy <nsz@sourceware.org>
To: binutils-cvs@sourceware.org
Subject: [binutils-gdb] aarch64: Add DT_RELR support for ILP32 ABI
Date: Tue, 25 Jun 2024 10:09:18 +0000 (GMT)	[thread overview]
Message-ID: <20240625100918.8D0CA386D615@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c9cf7bdfe53a5c8446f8dc6e6f1bafa4c3636f59

commit c9cf7bdfe53a5c8446f8dc6e6f1bafa4c3636f59
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Jun 12 15:17:09 2024 +0100

    aarch64: Add DT_RELR support for ILP32 ABI
    
    Extend the 64bit DT_RELR support to work on 32bit ELF too. For this
    only a few changes were needed in the sizing and creation of the
    relr relocations.

Diff:
---
 bfd/elfnn-aarch64.c             | 37 +++++++++++++++++++++----------------
 ld/emulparams/aarch64elf32.sh   |  2 ++
 ld/emulparams/aarch64linux32.sh |  2 ++
 3 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 2221de0a480..000564672df 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -9451,6 +9451,11 @@ sort_relr (struct bfd_link_info *info,
   return true;
 }
 
+/* Size of a relr entry and a relocated location.  */
+#define RELR_SZ (ARCH_SIZE / 8)
+/* Number of consecutive locations a relr bitmap entry references.  */
+#define RELR_N (ARCH_SIZE - 1)
+
 /* Size .relr.dyn whenever the layout changes, the number of packed
    relocs are unchanged but the packed representation can.  */
 
@@ -9473,19 +9478,19 @@ elfNN_aarch64_size_relative_relocs (struct bfd_link_info *info,
     {
       bfd_vma base = addr[i];
       i++;
-      srelrdyn->size += 8;
-      base += 8;
+      srelrdyn->size += RELR_SZ;
+      base += RELR_SZ;
       for (;;)
 	{
 	  bfd_size_type start_i = i;
 	  while (i < htab->relr_count
-		 && addr[i] - base < 63 * 8
-		 && (addr[i] - base) % 8 == 0)
+		 && addr[i] - base < RELR_N * RELR_SZ
+		 && (addr[i] - base) % RELR_SZ == 0)
 	    i++;
 	  if (i == start_i)
 	    break;
-	  srelrdyn->size += 8;
-	  base += 63 * 8;
+	  srelrdyn->size += RELR_SZ;
+	  base += RELR_N * RELR_SZ;
 	}
     }
   if (srelrdyn->size != oldsize)
@@ -9522,25 +9527,25 @@ elfNN_aarch64_finish_relative_relocs (struct bfd_link_info *info)
     {
       bfd_vma base = addr[i];
       i++;
-      bfd_put_64 (dynobj, base, loc);
-      loc += 8;
-      base += 8;
+      bfd_put_NN (dynobj, base, loc);
+      loc += RELR_SZ;
+      base += RELR_SZ;
       for (;;)
 	{
 	  bfd_vma bits = 0;
 	  while (i < htab->relr_count)
 	    {
 	      bfd_vma delta = addr[i] - base;
-	      if (delta >= 63 * 8 || delta % 8 != 0)
+	      if (delta >= RELR_N * RELR_SZ || delta % RELR_SZ != 0)
 		break;
-	      bits |= (bfd_vma) 1 << (delta / 8);
+	      bits |= (bfd_vma) 1 << (delta / RELR_SZ);
 	      i++;
 	    }
 	  if (bits == 0)
 	    break;
-	  bfd_put_64 (dynobj, (bits << 1) | 1, loc);
-	  loc += 8;
-	  base += 63 * 8;
+	  bfd_put_NN (dynobj, (bits << 1) | 1, loc);
+	  loc += RELR_SZ;
+	  base += RELR_N * RELR_SZ;
 	}
     }
   free (addr);
@@ -9548,8 +9553,8 @@ elfNN_aarch64_finish_relative_relocs (struct bfd_link_info *info)
   /* Pad any excess with 1's, a do-nothing encoding.  */
   while (loc < srelrdyn->contents + srelrdyn->size)
     {
-      bfd_put_64 (dynobj, 1, loc);
-      loc += 8;
+      bfd_put_NN (dynobj, 1, loc);
+      loc += RELR_SZ;
     }
   return true;
 }
diff --git a/ld/emulparams/aarch64elf32.sh b/ld/emulparams/aarch64elf32.sh
index 5a08d9e29f1..45bf31a179a 100644
--- a/ld/emulparams/aarch64elf32.sh
+++ b/ld/emulparams/aarch64elf32.sh
@@ -1,3 +1,5 @@
+source_sh ${srcdir}/emulparams/dt-relr.sh
+
 ARCH="aarch64:ilp32"
 MACHINE=
 NOP=0x1f2003d5
diff --git a/ld/emulparams/aarch64linux32.sh b/ld/emulparams/aarch64linux32.sh
index 3e75d1492e6..3292c7ca32a 100644
--- a/ld/emulparams/aarch64linux32.sh
+++ b/ld/emulparams/aarch64linux32.sh
@@ -1,3 +1,5 @@
+source_sh ${srcdir}/emulparams/dt-relr.sh
+
 ARCH="aarch64:ilp32"
 MACHINE=
 NOP=0x1f2003d5

                 reply	other threads:[~2024-06-25 10:09 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=20240625100918.8D0CA386D615@sourceware.org \
    --to=nsz@sourceware.org \
    --cc=binutils-cvs@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).