[committed] Small cleanup in elf32-hppa.c

John David Anglin dave@hiauly1.hia.nrc.ca
Sun Mar 1 18:18:00 GMT 2009


This patch introduces a new function to eliminate a bit of duplicated
code.

Tested on hppa-unknown-linux-gnu with no regressions.  Committed to
trunk.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)

2009-03-01  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

	* elf32-hppa.c (hppa32_elf_local_refcounts): New function.
	(elf32_hppa_check_relocs): Use it.

Index: elf32-hppa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-hppa.c,v
retrieving revision 1.164
diff -u -3 -p -r1.164 elf32-hppa.c
--- elf32-hppa.c	25 Nov 2008 13:03:55 -0000	1.164
+++ elf32-hppa.c	1 Mar 2009 17:58:44 -0000
@@ -1113,6 +1113,38 @@ elf32_hppa_optimized_tls_reloc (struct b
   return r_type;
 }
 
+/* Return a pointer to the local GOT, PLT and TLS reference counts
+   for ABFD.  Returns NULL if the storage allocation fails.  */
+
+static bfd_signed_vma *
+hppa32_elf_local_refcounts (bfd *abfd)
+{
+  Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  bfd_signed_vma *local_refcounts;
+                  
+  local_refcounts = elf_local_got_refcounts (abfd);
+  if (local_refcounts == NULL)
+    {
+      bfd_size_type size;
+
+      /* Allocate space for local GOT and PLT reference
+	 counts.  Done this way to save polluting elf_obj_tdata
+	 with another target specific pointer.  */
+      size = symtab_hdr->sh_info;
+      size *= 2 * sizeof (bfd_signed_vma);
+      /* Add in space to store the local GOT TLS types.  */
+      size += symtab_hdr->sh_info;
+      local_refcounts = bfd_zalloc (abfd, size);
+      if (local_refcounts == NULL)
+	return NULL;
+      elf_local_got_refcounts (abfd) = local_refcounts;
+      memset (hppa_elf_local_got_tls_type (abfd), GOT_UNKNOWN,
+	      symtab_hdr->sh_info);
+    }
+  return local_refcounts;
+}
+
+
 /* Look through the relocs for a section during the first phase, and
    calculate needed space in the global offset table, procedure linkage
    table, and dynamic reloc sections.  At this point we haven't
@@ -1359,26 +1391,9 @@ elf32_hppa_check_relocs (bfd *abfd,
 	          bfd_signed_vma *local_got_refcounts;
 		  
 	          /* This is a global offset table entry for a local symbol.  */
-	          local_got_refcounts = elf_local_got_refcounts (abfd);
+	          local_got_refcounts = hppa32_elf_local_refcounts (abfd);
 	          if (local_got_refcounts == NULL)
-		    {
-		      bfd_size_type size;
-
-		      /* Allocate space for local got offsets and local
-		         plt offsets.  Done this way to save polluting
-		         elf_obj_tdata with another target specific
-		         pointer.  */
-		      size = symtab_hdr->sh_info;
-		      size *= 2 * sizeof (bfd_signed_vma);
-		      /* Add in space to store the local GOT TLS types.  */
-		      size += symtab_hdr->sh_info;
-		      local_got_refcounts = bfd_zalloc (abfd, size);
-		      if (local_got_refcounts == NULL)
-		        return FALSE;
-		      elf_local_got_refcounts (abfd) = local_got_refcounts;
-		      memset (hppa_elf_local_got_tls_type (abfd),
-		    	  GOT_UNKNOWN, symtab_hdr->sh_info);
-		    }
+		    return FALSE;
 	          local_got_refcounts[r_symndx] += 1;
 
 	          old_tls_type = hppa_elf_local_got_tls_type (abfd) [r_symndx];
@@ -1425,22 +1440,9 @@ elf32_hppa_check_relocs (bfd *abfd,
 		  bfd_signed_vma *local_got_refcounts;
 		  bfd_signed_vma *local_plt_refcounts;
 
-		  local_got_refcounts = elf_local_got_refcounts (abfd);
+		  local_got_refcounts = hppa32_elf_local_refcounts (abfd);
 		  if (local_got_refcounts == NULL)
-		    {
-		      bfd_size_type size;
-
-		      /* Allocate space for local got offsets and local
-			 plt offsets.  */
-		      size = symtab_hdr->sh_info;
-		      size *= 2 * sizeof (bfd_signed_vma);
-		      /* Add in space to store the local GOT TLS types.  */
-		      size += symtab_hdr->sh_info;
-		      local_got_refcounts = bfd_zalloc (abfd, size);
-		      if (local_got_refcounts == NULL)
-			return FALSE;
-		      elf_local_got_refcounts (abfd) = local_got_refcounts;
-		    }
+		    return FALSE;
 		  local_plt_refcounts = (local_got_refcounts
 					 + symtab_hdr->sh_info);
 		  local_plt_refcounts[r_symndx] += 1;



More information about the Binutils mailing list