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

[binutils-gdb/binutils-2_28-branch] PR ld/21334: Always call `_bfd_elf_link_renumber_dynsyms' if required


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

commit 1be438fd16d8a42e2a09d7b932da27c0e36094b6
Author: Maciej W. Rozycki <macro@imgtec.com>
Date:   Wed Apr 26 22:23:44 2017 +0100

    PR ld/21334: Always call `_bfd_elf_link_renumber_dynsyms' if required
    
    Complement commit e17b0c351f0b ("MIPS/BFD: Respect the ELF gABI dynamic
    symbol table sort requirement") and correct an inconsistency in dynamic
    symbol accounting data causing an assertion failure in the MIPS backend:
    
    ld: BFD (GNU Binutils) 2.28.51.20170330 assertion fail
    ../../binutils-gdb/bfd/elfxx-mips.c:3860
    
    in the course of making a GOT entry in a static binary to satisfy a GOT
    relocation present in input, due to the local dynamic symbol count not
    having been established.
    
    To do so let backends request `_bfd_elf_link_renumber_dynsyms' to be
    always called, rather than where a dynamic binary is linked only, and
    then make this request in the MIPS backend.
    
    	bfd/
    	PR ld/21334
    	* elf-bfd.h (elf_backend_data): Add `always_renumber_dynsyms'
    	member.
    	* elfxx-target.h [!elf_backend_always_renumber_dynsyms]
    	(elf_backend_always_renumber_dynsyms): Define.
    	(elfNN_bed): Initialize `always_renumber_dynsyms' member.
    	* elfxx-mips.h (elf_backend_always_renumber_dynsyms): Define.
    	* elflink.c (bfd_elf_size_dynsym_hash_dynstr): Also call
    	`_bfd_elf_link_renumber_dynsyms' if the backend has requested
    	it.
    	(elf_gc_sweep): Likewise.
    
    (backported from commit 23ec1e32b1ab714649a7c25e49b5d721fe3bd3db)

Diff:
---
 bfd/ChangeLog      | 14 ++++++++++++++
 bfd/elf-bfd.h      |  4 ++++
 bfd/elflink.c      | 34 +++++++++++++++++++++++-----------
 bfd/elfxx-mips.h   |  1 +
 bfd/elfxx-target.h |  6 +++++-
 5 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 5bcd30b..76f7b82 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,19 @@
 2017-04-26  Maciej W. Rozycki  <macro@imgtec.com>
 
+	PR ld/21334
+	* elf-bfd.h (elf_backend_data): Add `always_renumber_dynsyms'
+	member.
+	* elfxx-target.h [!elf_backend_always_renumber_dynsyms]
+	(elf_backend_always_renumber_dynsyms): Define.
+	(elfNN_bed): Initialize `always_renumber_dynsyms' member.
+	* elfxx-mips.h (elf_backend_always_renumber_dynsyms): Define.
+	* elflink.c (bfd_elf_size_dynsym_hash_dynstr): Also call
+	`_bfd_elf_link_renumber_dynsyms' if the backend has requested
+	it.
+	(elf_gc_sweep): Likewise.
+
+2017-04-26  Maciej W. Rozycki  <macro@imgtec.com>
+
 	* elflink.c (elf_gc_sweep): Only call
 	`_bfd_elf_link_renumber_dynsyms' if dynamic sections have been
 	created.
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 5de9ab6..dc4bd87 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1478,6 +1478,10 @@ struct elf_backend_data
   /* Address of protected data defined in the shared library may be
      external, i.e., due to copy relocation.   */
   unsigned extern_protected_data : 1;
+
+  /* True if `_bfd_elf_link_renumber_dynsyms' must be called even for
+     static binaries.  */
+  unsigned always_renumber_dynsyms : 1;
 };
 
 /* Information about reloc sections associated with a bfd_elf_section_data
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 1c3e1b0..cd03a13 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -6707,6 +6707,8 @@ bfd_boolean
 bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info)
 {
   const struct elf_backend_data *bed;
+  unsigned long section_sym_count;
+  bfd_size_type dynsymcount;
 
   if (!is_elf_hash_table (info->hash))
     return TRUE;
@@ -6714,24 +6716,30 @@ bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info)
   bed = get_elf_backend_data (output_bfd);
   (*bed->elf_backend_init_index_section) (output_bfd, info);
 
+  /* Assign dynsym indices.  In a shared library we generate a section
+     symbol for each output section, which come first.  Next come all
+     of the back-end allocated local dynamic syms, followed by the rest
+     of the global symbols.
+
+     This is usually not needed for static binaries, however backends
+     can request to always do it, e.g. the MIPS backend uses dynamic
+     symbol counts to lay out GOT, which will be produced in the
+     presence of GOT relocations even in static binaries (holding fixed
+     data in that case, to satisfy those relocations).  */
+
+  if (elf_hash_table (info)->dynamic_sections_created
+      || bed->always_renumber_dynsyms)
+    dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info,
+						  &section_sym_count);
+
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       bfd *dynobj;
       asection *s;
-      bfd_size_type dynsymcount;
-      unsigned long section_sym_count;
       unsigned int dtagcount;
 
       dynobj = elf_hash_table (info)->dynobj;
 
-      /* Assign dynsym indicies.  In a shared library we generate a
-	 section symbol for each output section, which come first.
-	 Next come all of the back-end allocated local dynamic syms,
-	 followed by the rest of the global symbols.  */
-
-      dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info,
-						    &section_sym_count);
-
       /* Work out the size of the symbol version section.  */
       s = bfd_get_linker_section (dynobj, ".gnu.version");
       BFD_ASSERT (s != NULL);
@@ -12983,7 +12991,11 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
   elf_link_hash_traverse (elf_hash_table (info), elf_gc_sweep_symbol,
 			  &sweep_info);
 
-  if (elf_hash_table (info)->dynamic_sections_created)
+  /* We need to reassign dynsym indices now that symbols may have
+     been removed.  See the call in `bfd_elf_size_dynsym_hash_dynstr'
+     for the details of the conditions used here.  */
+  if (elf_hash_table (info)->dynamic_sections_created
+      || bed->always_renumber_dynsyms)
     _bfd_elf_link_renumber_dynsyms (abfd, info, &section_sym_count);
   return TRUE;
 }
diff --git a/bfd/elfxx-mips.h b/bfd/elfxx-mips.h
index fa5b5d2..274129b 100644
--- a/bfd/elfxx-mips.h
+++ b/bfd/elfxx-mips.h
@@ -196,3 +196,4 @@ literal_reloc_p (int r_type)
 #define elf_backend_post_process_headers _bfd_mips_post_process_headers
 #define elf_backend_compact_eh_encoding _bfd_mips_elf_compact_eh_encoding
 #define elf_backend_cant_unwind_opcode _bfd_mips_elf_cant_unwind_opcode
+#define elf_backend_always_renumber_dynsyms TRUE
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index d063fb7..d07600c 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -126,6 +126,9 @@
 #ifndef elf_backend_extern_protected_data
 #define elf_backend_extern_protected_data 0
 #endif
+#ifndef elf_backend_always_renumber_dynsyms
+#define elf_backend_always_renumber_dynsyms FALSE
+#endif
 #ifndef elf_backend_stack_align
 #define elf_backend_stack_align 16
 #endif
@@ -866,7 +869,8 @@ static struct elf_backend_data elfNN_bed =
   elf_backend_no_page_alias,
   elf_backend_default_execstack,
   elf_backend_caches_rawsize,
-  elf_backend_extern_protected_data
+  elf_backend_extern_protected_data,
+  elf_backend_always_renumber_dynsyms
 };
 
 /* Forward declaration for use when initialising alternative_target field.  */


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