public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] x86: Add elf_x86_allocate_local_got_info
@ 2022-01-05 21:23 H.J. Lu
  0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2022-01-05 21:23 UTC (permalink / raw)
  To: binutils

Add elf_x86_allocate_local_got_info to allocate x86 GOT info for local
symbols.

	* elf32-i386.c (elf_i386_check_relocs): Call
	elf_x86_allocate_local_got_info.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elfxx-x86.h (elf_x86_allocate_local_got_info): New.
---
 bfd/elf32-i386.c   | 21 ++++-----------------
 bfd/elf64-x86-64.c | 21 ++++-----------------
 bfd/elfxx-x86.h    | 22 ++++++++++++++++++++++
 3 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index aa7d0283135..97962072ff0 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1668,25 +1668,12 @@ elf_i386_check_relocs (bfd *abfd,
 	      {
 		bfd_signed_vma *local_got_refcounts;
 
+		if (!elf_x86_allocate_local_got_info (abfd,
+						      symtab_hdr->sh_info))
+		      goto error_return;
+
 		/* This is a global offset table entry for a local symbol.  */
 		local_got_refcounts = elf_local_got_refcounts (abfd);
-		if (local_got_refcounts == NULL)
-		  {
-		    bfd_size_type size;
-
-		    size = symtab_hdr->sh_info;
-		    size *= (sizeof (bfd_signed_vma)
-			     + sizeof (bfd_vma) + sizeof(char));
-		    local_got_refcounts = (bfd_signed_vma *)
-			bfd_zalloc (abfd, size);
-		    if (local_got_refcounts == NULL)
-		      goto error_return;
-		    elf_local_got_refcounts (abfd) = local_got_refcounts;
-		    elf_x86_local_tlsdesc_gotent (abfd)
-		      = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
-		    elf_x86_local_got_tls_type (abfd)
-		      = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
-		  }
 		local_got_refcounts[r_symndx] = 1;
 		old_tls_type = elf_x86_local_got_tls_type (abfd) [r_symndx];
 	      }
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 00e47bee1c6..22aa3ee3b68 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2066,25 +2066,12 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	      {
 		bfd_signed_vma *local_got_refcounts;
 
+		if (!elf_x86_allocate_local_got_info (abfd,
+						      symtab_hdr->sh_info))
+		      goto error_return;
+
 		/* This is a global offset table entry for a local symbol.  */
 		local_got_refcounts = elf_local_got_refcounts (abfd);
-		if (local_got_refcounts == NULL)
-		  {
-		    bfd_size_type size;
-
-		    size = symtab_hdr->sh_info;
-		    size *= sizeof (bfd_signed_vma)
-		      + sizeof (bfd_vma) + sizeof (char);
-		    local_got_refcounts = ((bfd_signed_vma *)
-					   bfd_zalloc (abfd, size));
-		    if (local_got_refcounts == NULL)
-		      goto error_return;
-		    elf_local_got_refcounts (abfd) = local_got_refcounts;
-		    elf_x86_local_tlsdesc_gotent (abfd)
-		      = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
-		    elf_x86_local_got_tls_type (abfd)
-		      = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
-		  }
 		local_got_refcounts[r_symndx] = 1;
 		old_tls_type
 		  = elf_x86_local_got_tls_type (abfd) [r_symndx];
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index 25791af27d7..16565a5638b 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -789,3 +789,25 @@ elf_x86_start_stop_gc_p (struct bfd_link_info *link_info,
      --gc-sections or -z start-stop-gc isn't used.  */
   return false;
 }
+
+/* Allocate x86 GOT info for local symbols.  */
+
+static inline bool
+elf_x86_allocate_local_got_info (bfd *abfd, bfd_size_type count)
+{
+  bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
+  if (local_got_refcounts == NULL)
+    {
+      bfd_size_type size = count * (sizeof (bfd_signed_vma)
+				    + sizeof (bfd_vma) + sizeof(char));
+      local_got_refcounts = (bfd_signed_vma *) bfd_zalloc (abfd, size);
+      if (local_got_refcounts == NULL)
+	return false;
+      elf_local_got_refcounts (abfd) = local_got_refcounts;
+      elf_x86_local_tlsdesc_gotent (abfd) =
+	(bfd_vma *) (local_got_refcounts + count);
+      elf_x86_local_got_tls_type (abfd) =
+	(char *) (local_got_refcounts + 2 * count);
+    }
+  return true;
+}
-- 
2.33.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-05 21:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 21:23 [PATCH] x86: Add elf_x86_allocate_local_got_info H.J. Lu

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