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] mips: Check UNDEFWEAK_NO_DYNAMIC_RELOC


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

commit ad9512030937e79e28d08108fde7adf18635c58b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat Oct 14 10:52:12 2017 -0700

    mips: Check UNDEFWEAK_NO_DYNAMIC_RELOC
    
    Don't generate dynamic relocation against weak undefined symbol if it
    is resolved to zero.  FIXME: UNDEFWEAK_NO_DYNAMIC_RELOC may need to be
    checked in more places.
    
    	PR ld/22269
    	* elfxx-mips.c (mips_elf_calculate_relocation): Don't generate
    	dynamic relocation if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
    	(allocate_dynrelocs): Don't allocate dynamic relocations if
    	UNDEFWEAK_NO_DYNAMIC_RELOC is true.

Diff:
---
 bfd/ChangeLog    |  8 ++++++++
 bfd/elfxx-mips.c | 11 +++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 849ce20..900c411 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,6 +1,14 @@
 2017-10-14  H.J. Lu  <hongjiu.lu@intel.com>
 
 	PR ld/22269
+	* elfxx-mips.c (mips_elf_calculate_relocation): Don't generate
+	dynamic relocation if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
+	(allocate_dynrelocs): Don't allocate dynamic relocations if
+	UNDEFWEAK_NO_DYNAMIC_RELOC is true.
+
+2017-10-14  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/22269
 	* elf32-arm.c (elf32_arm_final_link_relocate): Don't generate
 	dynamic relocation if UNDEFWEAK_NO_DYNAMIC_RELOC is true.
 	(allocate_dynrelocs_for_symbol): Discard dynamic relocations
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 6a4d3e1..23fba1b 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -5310,6 +5310,7 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
   bfd_boolean target_is_micromips_code_p = FALSE;
   struct mips_elf_link_hash_table *htab;
   bfd *dynobj;
+  bfd_boolean resolved_to_zero;
 
   dynobj = elf_hash_table (info)->dynobj;
   htab = mips_elf_hash_table (info);
@@ -5665,6 +5666,10 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
       addend = 0;
     }
 
+  resolved_to_zero = (h != NULL
+		      && UNDEFWEAK_NO_DYNAMIC_RELOC (info,
+							  &h->root));
+
   /* If we haven't already determined the GOT offset, and we're going
      to need it, get it now.  */
   switch (r_type)
@@ -5796,7 +5801,8 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd,
 	  && r_symndx != STN_UNDEF
 	  && (h == NULL
 	      || h->root.root.type != bfd_link_hash_undefweak
-	      || ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
+	      || (ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT
+		  && !resolved_to_zero))
 	  && (input_section->flags & SEC_ALLOC) != 0)
 	{
 	  /* If we're creating a shared library, then we can't know
@@ -8940,7 +8946,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 	{
 	  /* Do not copy relocations for undefined weak symbols with
 	     non-default visibility.  */
-	  if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+	  if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+	      || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
 	    do_copy = FALSE;
 
 	  /* Make sure undefined weak symbols are output as a dynamic


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