This is the mail archive of the binutils@sourceware.org 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]

[PATCH] VAX/BFD: Correct GOT/PLT refcounts for static links


Hi,

 In preparation for the next change I am about to propose here is a fix 
for GOT/PLT refcounts in static links.

 Obviously in a static link no GOT or PLT is created.  Our code still 
behaves though as if they were to be and collects refcounts as usually.  
Contrary to the comments around elf_vax_instantiate_got_entries (both at 
its calling place and at its definintion itself) the function is not 
called for static links.  The call to elf_vax_size_dynamic_sections (via 
bed->elf_backend_size_dynamic_sections) in bfd_elf_size_dynamic_sections 
is only made if dynobj is non-NULL, which is never the case for static 
links, and elf_vax_instantiate_got_entries is only called from 
elf_vax_size_dynamic_sections.

 In order to simplify the handling of the GOT and PLT relocs I have made 
the change below that resets all the GOT/PLT refcounts in static links so 
that the case of a static link does not have to be treated specially in 
reloc handling code.  This change adds an always_size_sections handler 
that's always called from bfd_elf_size_dynamic_sections, even for static 
links.  Static-link code from elf_vax_size_dynamic_sections is then moved 
to this new handler and a new function, elf_vax_discard_got_entries, is 
called as the counterpart to elf_vax_instantiate_got_entries for static 
links.  I have adjusted comments accordingly.

 No regressions in vax-linux or vax-netbsdelf testing.  OK to apply?

2013-05-20  Maciej W. Rozycki  <macro@linux-mips.org>

	* elf32-vax.c (elf_vax_discard_got_entries): New function.
	(elf_vax_always_size_sections): Likewise.
	(elf_vax_size_dynamic_sections): Remove code moved to 
	elf_vax_always_size_sections.  Make comment on
	elf_vax_instantiate_got_entries match reality.
	(elf_vax_instantiate_got_entries): Assert that rather than check
	if dynobj is null.  Don't check for dynamic_sections_created.
	Make function description match reality.
	(elf_backend_always_size_sections): New macro.

  Maciej

binutils-2.23.1-vax-size-sections.patch
Index: binutils-2.23.1/bfd/elf32-vax.c
===================================================================
--- binutils-2.23.1.orig/bfd/elf32-vax.c
+++ binutils-2.23.1/bfd/elf32-vax.c
@@ -1046,6 +1046,59 @@ elf_vax_adjust_dynamic_symbol (struct bf
   return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
+/* This function is called via elf_link_hash_traverse.  It resets GOT
+   and PLT (.GOT) reference counts back to -1 so normal PC32 relocation
+   will be done.  */
+
+static bfd_boolean
+elf_vax_discard_got_entries (struct elf_link_hash_entry *h,
+			     void *infoptr ATTRIBUTE_UNUSED)
+{
+  h->got.refcount = -1;
+  h->plt.refcount = -1;
+
+  return TRUE;
+}
+
+/* Discard unused dynamic data if this is a static link.  */
+
+static bfd_boolean
+elf_vax_always_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
+			      struct bfd_link_info *info)
+{
+  bfd *dynobj;
+  asection *s;
+
+  dynobj = elf_hash_table (info)->dynobj;
+
+  if (dynobj && !elf_hash_table (info)->dynamic_sections_created)
+    {
+      /* We may have created entries in the .rela.got and .got sections.
+	 However, if we are not creating the dynamic sections, we will
+	 not actually use these entries.  Reset the size of .rela.got
+	 and .got, which will cause it to get stripped from the output
+	 file below.  */
+      s = bfd_get_linker_section (dynobj, ".rela.got");
+      if (s != NULL)
+	s->size = 0;
+      s = bfd_get_linker_section (dynobj, ".got.plt");
+      if (s != NULL)
+	s->size = 0;
+      s = bfd_get_linker_section (dynobj, ".got");
+      if (s != NULL)
+	s->size = 0;
+    }
+
+  /* If this is a static link, we need to discard all the got entries we've
+     recorded.  */
+  if (!dynobj || !elf_hash_table (info)->dynamic_sections_created)
+    elf_link_hash_traverse (elf_hash_table (info),
+			    elf_vax_discard_got_entries,
+			    info);
+
+  return TRUE;
+}
+
 /* Set the sizes of the dynamic sections.  */
 
 static bfd_boolean
@@ -1071,23 +1124,6 @@ elf_vax_size_dynamic_sections (bfd *outp
 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
 	}
     }
-  else
-    {
-      /* We may have created entries in the .rela.got and .got sections.
-	 However, if we are not creating the dynamic sections, we will
-	 not actually use these entries.  Reset the size of .rela.got
-	 and .got, which will cause it to get stripped from the output
-	 file below.  */
-      s = bfd_get_linker_section (dynobj, ".rela.got");
-      if (s != NULL)
-	s->size = 0;
-      s = bfd_get_linker_section (dynobj, ".got.plt");
-      if (s != NULL)
-	s->size = 0;
-      s = bfd_get_linker_section (dynobj, ".got");
-      if (s != NULL)
-	s->size = 0;
-    }
 
   /* If this is a -Bsymbolic shared link, then we need to discard all PC
      relative relocs against symbols defined in a regular object.  We
@@ -1098,9 +1134,9 @@ elf_vax_size_dynamic_sections (bfd *outp
 				elf_vax_discard_copies,
 				NULL);
 
-  /* If this is a -Bsymbolic shared link or a static link, we need to
-     discard all the got entries we've recorded.  Otherwise, we need to
-     instantiate (allocate space for them).  */
+  /* If this is a -Bsymbolic shared link, we need to discard all the got
+     entries we've recorded.  Otherwise, we need to instantiate (allocate
+     space for them).  */
   elf_link_hash_traverse (elf_hash_table (info),
 			  elf_vax_instantiate_got_entries,
 			  info);
@@ -1256,12 +1292,12 @@ elf_vax_discard_copies (struct elf_vax_l
   return TRUE;
 }
 
-/* This function is called via elf_link_hash_traverse.  It looks for entries
-   that have GOT or PLT (.GOT) references.  If creating a static object or a
-   shared object with -Bsymbolic, or the symbol has been forced local, then
-   it resets the reference count back to -1 so normal PC32 relocation will
-   be done.  Otherwise space in the .got and .rela.got will be reserved for
-   the symbol.  */
+/* This function is called via elf_link_hash_traverse.  It looks for
+   entries that have GOT or PLT (.GOT) references.  If creating a shared
+   object with -Bsymbolic, or the symbol has been forced local, then it
+   resets the reference count back to -1 so normal PC32 relocation will
+   be done.  Otherwise space in the .got and .rela.got will be reserved
+   for the symbol.  */
 
 static bfd_boolean
 elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, void * infoptr)
@@ -1276,14 +1312,12 @@ elf_vax_instantiate_got_entries (struct 
     return TRUE;
 
   dynobj = elf_hash_table (info)->dynobj;
-  if (dynobj == NULL)
-    return TRUE;
+  BFD_ASSERT (dynobj != NULL);
 
   sgot = bfd_get_linker_section (dynobj, ".got");
   srelgot = bfd_get_linker_section (dynobj, ".rela.got");
 
-  if (!elf_hash_table (info)->dynamic_sections_created
-      || (info->shared && info->symbolic)
+  if ((info->shared && info->symbolic)
       || h->forced_local)
     {
       h->got.refcount = -1;
@@ -2059,6 +2093,8 @@ elf_vax_plt_sym_val (bfd_vma i, const as
 #define elf_backend_check_relocs	elf_vax_check_relocs
 #define elf_backend_adjust_dynamic_symbol \
 					elf_vax_adjust_dynamic_symbol
+#define elf_backend_always_size_sections \
+					elf_vax_always_size_sections
 #define elf_backend_size_dynamic_sections \
 					elf_vax_size_dynamic_sections
 #define elf_backend_init_index_section	_bfd_elf_init_1_index_section


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