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] ELF: Check ELF_COMMON_DEF_P for common symbols


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

commit 5a0ac7ba3c5277b3ab04f55de23bccb7614a9e59
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Apr 7 07:40:14 2017 -0700

    ELF: Check ELF_COMMON_DEF_P for common symbols
    
    Since common symbols that are turned into definitions don't have the
    DEF_REGULAR flag set, we need to check ELF_COMMON_DEF_P for common
    symbols.
    
    bfd/
    
    	PR ld/19579
    	PR ld/21306
    	* elf32-s390.c (elf_s390_finish_dynamic_symbol): Check
    	ELF_COMMON_DEF_P for common symbols.
    	* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
    	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
    	* elflink.c (_bfd_elf_merge_symbol): Revert commits
    	202ac193bbbecc96a4978d1ac3d17148253f9b01 and
    	07492f668d2173da7a2bda3707ff0985e0f460b6.
    
    ld/
    
    	PR ld/19579
    	PR ld/21306
    	* testsuite/ld-elf/pr19579a.c (main): Updated.
    
    (cherry picked from commit 8170f7693bc0a9442c0aa280197925db92d48ca6)

Diff:
---
 bfd/ChangeLog                  | 12 ++++++++++++
 bfd/elf32-s390.c               |  2 +-
 bfd/elf64-s390.c               |  2 +-
 bfd/elf64-x86-64.c             |  3 ++-
 bfd/elflink.c                  |  7 ++-----
 ld/ChangeLog                   |  6 ++++++
 ld/testsuite/ld-elf/pr19579a.c |  2 +-
 7 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 17e7e3b..03cc6f9 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,15 @@
+2017-04-10  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/19579
+	PR ld/21306
+	* elf32-s390.c (elf_s390_finish_dynamic_symbol): Check
+	ELF_COMMON_DEF_P for common symbols.
+	* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
+	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
+	* elflink.c (_bfd_elf_merge_symbol): Revert commits
+	202ac193bbbecc96a4978d1ac3d17148253f9b01 and
+	07492f668d2173da7a2bda3707ff0985e0f460b6.
+
 2017-03-07  Alan Modra  <amodra@gmail.com>
 
 	PR 21224
diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index fd1bc13..ddb6f5b 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -3785,7 +3785,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
 	     RELATIVE reloc.  The entry in the global offset table
 	     will already have been initialized in the
 	     relocate_section function.  */
-	  if (!h->def_regular)
+	  if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
 	    return FALSE;
 	  BFD_ASSERT((h->got.offset & 1) != 0);
 	  rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index b5fd05f..fbbf8d6 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -3582,7 +3582,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
 	     RELATIVE reloc.  The entry in the global offset table
 	     will already have been initialized in the
 	     relocate_section function.  */
-	  if (!h->def_regular)
+	  if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
 	    return FALSE;
 	  BFD_ASSERT((h->got.offset & 1) != 0);
 	  rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index e0e6c16..e363eaf 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4926,7 +4926,8 @@ do_ifunc_pointer:
 		{
 		  /* Symbol is referenced locally.  Make sure it is
 		     defined locally or for a branch.  */
-		  fail = !h->def_regular && !branch;
+		  fail = (!(h->def_regular || ELF_COMMON_DEF_P (h))
+			  && !branch);
 		}
 	      else if (!(bfd_link_pie (info)
 			 && (h->needs_copy || eh->needs_copy)))
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 69b66f2..46d57e5 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1543,16 +1543,13 @@ _bfd_elf_merge_symbol (bfd *abfd,
      represent variables; this can cause confusion in principle, but
      any such confusion would seem to indicate an erroneous program or
      shared library.  We also permit a common symbol in a regular
-     object to override a weak symbol in a shared object.  A common
-     symbol in executable also overrides a symbol in a shared object.  */
+     object to override a weak symbol in a shared object.  */
 
   if (newdyn
       && newdef
       && (olddef
 	  || (h->root.type == bfd_link_hash_common
-	      && (newweak
-		  || newfunc
-		  || (!olddyn && bfd_link_executable (info))))))
+	      && (newweak || newfunc))))
     {
       *override = TRUE;
       newdef = FALSE;
diff --git a/ld/ChangeLog b/ld/ChangeLog
index a3a8903..5b93acf 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,9 @@
+2017-04-10  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/19579
+	PR ld/21306
+	* testsuite/ld-elf/pr19579a.c (main): Updated.
+
 2017-04-05  Maciej W. Rozycki  <macro@imgtec.com>
 
 	PR ld/21233
diff --git a/ld/testsuite/ld-elf/pr19579a.c b/ld/testsuite/ld-elf/pr19579a.c
index e4a6eb1..69d0f35 100644
--- a/ld/testsuite/ld-elf/pr19579a.c
+++ b/ld/testsuite/ld-elf/pr19579a.c
@@ -9,7 +9,7 @@ extern int *bar_p (void);
 int
 main ()
 {
-  if (foo[0] == 0 && foo == foo_p () && bar[0] == 0 && bar == bar_p ())
+  if (foo[0] == 0 && foo == foo_p () && bar[0] == -1 && bar == bar_p ())
     printf ("PASS\n");
   return 0;
 }


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