This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA:] elflink.c: Hide _GLOBAL_OFFSET_TABLE_


> I prefer this one.  Mostly because it restores old behaviour with
> respect to got relocs.  Also, at some stage I might change selected
> backends over to use just one section symbol (or the zero sym) for
> dynamic relocs.  If you're using a local G_O_T sym, I'll probably
> assume the sparc backend wants it that way for some arcane reason..

Fine with me, installed.

May I install the cleanup part of the discarded patch though?  The rationale 
for the SPARC 64-bit changes is to make the 64-bit code more similar to the 
32-bit code.


2005-01-09  Eric Botcazou  <ebotcazou@libertysurf.fr>

	* elf32-sparc.c (elf32_sparc_link_hash_table_create): Use bfd_zmalloc
	to zero the structure.
	(create_got_section): Use BFD_ASSERT instead of abort.
	* elf64-sparc.c (struct sparc64_elf_link_hash_table): New 'sgot' and
	'srelgot' fields.
	(create_got_section): New function.
	(sparc64_elf_create_dynamic_sections): Likewise.
	(sparc64_elf_check_relocs): Invoke create_got_section instead of
	_bfd_elf_create_got_section.  Use the sgot and srelgot shortcuts.
	(sparc64_elf_size_dynamic_sections): Use the srelgot shortcut.
	(sparc64_elf_relocate_section): Use the sgot and srelgot shortcuts.
	(sparc64_elf_finish_dynamic_symbol): Likewise.
	(sparc64_elf_finish_dynamic_sections): Use the sgot shortcut.
	(elf_backend_create_dynamic_sections): Define to
	sparc64_elf_create_dynamic_sections.


-- 
Eric Botcazou
Index: elf32-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sparc.c,v
retrieving revision 1.77
diff -u -p -r1.77 elf32-sparc.c
--- elf32-sparc.c	9 Jan 2005 09:26:55 -0000	1.77
+++ elf32-sparc.c	9 Jan 2005 09:42:06 -0000
@@ -695,7 +695,7 @@ elf32_sparc_link_hash_table_create (abfd
   struct elf32_sparc_link_hash_table *ret;
   bfd_size_type amt = sizeof (struct elf32_sparc_link_hash_table);
 
-  ret = (struct elf32_sparc_link_hash_table *) bfd_malloc (amt);
+  ret = (struct elf32_sparc_link_hash_table *) bfd_zmalloc (amt);
   if (ret == NULL)
     return NULL;
 
@@ -705,15 +705,6 @@ elf32_sparc_link_hash_table_create (abfd
       return NULL;
     }
 
-  ret->sgot = NULL;
-  ret->srelgot = NULL;
-  ret->splt = NULL;
-  ret->srelplt = NULL;
-  ret->sdynbss = NULL;
-  ret->srelbss = NULL;
-  ret->tls_ldm_got.refcount = 0;
-  ret->sym_sec.abfd = NULL;
-
   return &ret->elf.root;
 }
 
@@ -732,15 +723,16 @@ create_got_section (dynobj, info)
 
   htab = elf32_sparc_hash_table (info);
   htab->sgot = bfd_get_section_by_name (dynobj, ".got");
-  if (!htab->sgot)
-    abort ();
+  BFD_ASSERT (htab->sgot != NULL);
 
   htab->srelgot = bfd_make_section (dynobj, ".rela.got");
   if (htab->srelgot == NULL
-      || ! bfd_set_section_flags (dynobj, htab->srelgot,
-				  (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
-				   | SEC_IN_MEMORY | SEC_LINKER_CREATED
-				   | SEC_READONLY))
+      || ! bfd_set_section_flags (dynobj, htab->srelgot, SEC_ALLOC
+							 | SEC_LOAD
+							 | SEC_HAS_CONTENTS
+							 | SEC_IN_MEMORY
+							 | SEC_LINKER_CREATED
+							 | SEC_READONLY)
       || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
     return FALSE;
   return TRUE;
Index: elf64-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-sparc.c,v
retrieving revision 1.99
diff -u -p -r1.99 elf64-sparc.c
--- elf64-sparc.c	9 Jan 2005 09:26:55 -0000	1.99
+++ elf64-sparc.c	9 Jan 2005 09:42:07 -0000
@@ -36,6 +36,10 @@
 
 static struct bfd_link_hash_table * sparc64_elf_bfd_link_hash_table_create
   PARAMS ((bfd *));
+static bfd_boolean create_got_section
+  PARAMS ((bfd *, struct bfd_link_info *));
+static bfd_boolean sparc64_elf_create_dynamic_sections
+  PARAMS ((bfd *, struct bfd_link_info *));
 static bfd_reloc_status_type init_insn_reloc
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *,
 	   bfd *, bfd_vma *, bfd_vma *));
@@ -738,6 +742,10 @@ struct sparc64_elf_link_hash_table
 {
   struct elf_link_hash_table root;
 
+  /* Short-cuts to get to dynamic linker sections.  */
+  asection *sgot;
+  asection *srelgot;
+
   struct sparc64_elf_app_reg app_regs [4];
 };
 
@@ -768,6 +776,57 @@ sparc64_elf_bfd_link_hash_table_create (
 
   return &ret->root.root;
 }
+
+/* Create .got and .rela.got sections in DYNOBJ and set up
+   shortcuts to them in our hash table.  */
+
+static bfd_boolean
+create_got_section (dynobj, info)
+     bfd *dynobj;
+     struct bfd_link_info *info;
+{
+  struct sparc64_elf_link_hash_table *htab;
+
+  if (! _bfd_elf_create_got_section (dynobj, info))
+    return FALSE;
+
+  htab = sparc64_elf_hash_table (info);
+  htab->sgot = bfd_get_section_by_name (dynobj, ".got");
+  BFD_ASSERT (htab->sgot != NULL);
+
+  htab->srelgot = bfd_make_section (dynobj, ".rela.got");
+  if (htab->srelgot == NULL
+      || ! bfd_set_section_flags (dynobj, htab->srelgot, SEC_ALLOC
+							 | SEC_LOAD
+							 | SEC_HAS_CONTENTS
+							 | SEC_IN_MEMORY
+							 | SEC_LINKER_CREATED
+							 | SEC_READONLY)
+      || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
+    return FALSE;
+  return TRUE;
+}
+
+/* Create .plt, .rela.plt, .got, .rela.got, .dynbss, and
+   .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
+   hash table.  */
+
+static bfd_boolean
+sparc64_elf_create_dynamic_sections (dynobj, info)
+     bfd *dynobj;
+     struct bfd_link_info *info;
+{
+  struct sparc64_elf_link_hash_table *htab;
+
+  htab = sparc64_elf_hash_table (info);
+  if (!htab->sgot && !create_got_section (dynobj, info))
+    return FALSE;
+
+  if (!_bfd_elf_create_dynamic_sections (dynobj, info))
+    return FALSE;
+
+  return TRUE;
+}
 
 /* Utility for performing the standard initial work of an instruction
    relocation.
@@ -1137,35 +1196,22 @@ sparc64_elf_check_relocs (abfd, info, se
 
 	  if (dynobj == NULL)
 	    {
-	      /* Create the .got section.  */
+	      /* Create the .got and .rela.got sections.  */
 	      elf_hash_table (info)->dynobj = dynobj = abfd;
-	      if (! _bfd_elf_create_got_section (dynobj, info))
+	      if (! create_got_section (dynobj, info))
 		return FALSE;
 	    }
 
 	  if (sgot == NULL)
 	    {
-	      sgot = bfd_get_section_by_name (dynobj, ".got");
+	      sgot = sparc64_elf_hash_table (info)->sgot;
 	      BFD_ASSERT (sgot != NULL);
 	    }
 
 	  if (srelgot == NULL && (h != NULL || info->shared))
 	    {
-	      srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
-	      if (srelgot == NULL)
-		{
-		  srelgot = bfd_make_section (dynobj, ".rela.got");
-		  if (srelgot == NULL
-		      || ! bfd_set_section_flags (dynobj, srelgot,
-						  (SEC_ALLOC
-						   | SEC_LOAD
-						   | SEC_HAS_CONTENTS
-						   | SEC_IN_MEMORY
-						   | SEC_LINKER_CREATED
-						   | SEC_READONLY))
-		      || ! bfd_set_section_alignment (dynobj, srelgot, 3))
-		    return FALSE;
-		}
+	      srelgot = sparc64_elf_hash_table (info)->srelgot;
+	      BFD_ASSERT (srelgot != NULL);
 	    }
 
 	  if (h != NULL)
@@ -1811,7 +1857,7 @@ sparc64_elf_size_dynamic_sections (outpu
          not actually use these entries.  Reset the size of .rela.got,
          which will cause it to get stripped from the output file
          below.  */
-      s = bfd_get_section_by_name (dynobj, ".rela.got");
+      s = sparc64_elf_hash_table (info)->srelgot;
       if (s != NULL)
 	s->size = 0;
     }
@@ -2324,7 +2370,7 @@ sparc64_elf_relocate_section (output_bfd
 	     offset table.  */
 	  if (sgot == NULL)
 	    {
-	      sgot = bfd_get_section_by_name (dynobj, ".got");
+	      sgot = sparc64_elf_hash_table (info)->sgot;
 	      BFD_ASSERT (sgot != NULL);
 	    }
 
@@ -2398,7 +2444,7 @@ sparc64_elf_relocate_section (output_bfd
 
 		      /* We need to generate a R_SPARC_RELATIVE reloc
 			 for the dynamic linker.  */
-		      s = bfd_get_section_by_name(dynobj, ".rela.got");
+		      s = sparc64_elf_hash_table (info)->srelgot;
 		      BFD_ASSERT (s != NULL);
 
 		      outrel.r_offset = (sgot->output_section->vma
@@ -2779,8 +2825,8 @@ sparc64_elf_finish_dynamic_symbol (outpu
 
       /* This symbol has an entry in the GOT.  Set it up.  */
 
-      sgot = bfd_get_section_by_name (dynobj, ".got");
-      srela = bfd_get_section_by_name (dynobj, ".rela.got");
+      sgot = sparc64_elf_hash_table (info)->sgot;
+      srela = sparc64_elf_hash_table (info)->srelgot;
       BFD_ASSERT (sgot != NULL && srela != NULL);
 
       rela.r_offset = (sgot->output_section->vma
@@ -2928,7 +2974,7 @@ sparc64_elf_finish_dynamic_sections (out
 
   /* Set the first entry in the global offset table to the address of
      the dynamic section.  */
-  sgot = bfd_get_section_by_name (dynobj, ".got");
+  sgot = sparc64_elf_hash_table (info)->sgot;
   BFD_ASSERT (sgot != NULL);
   if (sgot->size > 0)
     {
@@ -3206,7 +3252,7 @@ const struct elf_size_info sparc64_elf_s
   sparc64_elf_new_section_hook
 
 #define elf_backend_create_dynamic_sections \
-  _bfd_elf_create_dynamic_sections
+  sparc64_elf_create_dynamic_sections
 #define elf_backend_add_symbol_hook \
   sparc64_elf_add_symbol_hook
 #define elf_backend_get_symbol_type \

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]