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_25-branch] Don't PROVIDE over top of common symbols


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

commit 05377b8eb892e2a8a6eebaa15839fda1169be049
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Dec 22 10:49:23 2014 +1030

    Don't PROVIDE over top of common symbols
    
    This:
      int end[100000];
      int main(void) { end[99999] = 0; return 0; }
    should not segfault.
    
    ld/
    	* ldexp.c (exp_fold_tree_1 <etree_provide>): Leave bfd_link_hash_common
    	symbols alone.
    ld/testsuite/
    	* ld-elf/endsym.s, *ld-elf/endsym.d: New test.

Diff:
---
 ld/ChangeLog                 |  4 ++++
 ld/ldexp.c                   | 12 ++++++------
 ld/testsuite/ChangeLog       |  3 +++
 ld/testsuite/ld-elf/endsym.d | 13 +++++++++++++
 ld/testsuite/ld-elf/endsym.s |  2 ++
 5 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 2896965..566cd70 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -2,6 +2,10 @@
 
 	Apply from master.
 	2014-12-23  Alan Modra  <amodra@gmail.com>
+	* ldexp.c (exp_fold_tree_1 <etree_provide>): Leave bfd_link_hash_common
+	symbols alone.
+
+	2014-12-23  Alan Modra  <amodra@gmail.com>
 	* ldexp.c (update_definedness): Correct logic setting by_object.
 
 	2014-12-23  Alan Modra  <amodra@gmail.com>
diff --git a/ld/ldexp.c b/ld/ldexp.c
index e9e95f9..8615869 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -1070,15 +1070,15 @@ exp_fold_tree_1 (etree_type *tree)
 	      h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst,
 					FALSE, FALSE, TRUE);
 	      if (h == NULL
-		  || (h->type != bfd_link_hash_new
-		      && h->type != bfd_link_hash_undefined
-		      && h->type != bfd_link_hash_common
-		      && !(h->type == bfd_link_hash_defined
+		  || !(h->type == bfd_link_hash_new
+		       || h->type == bfd_link_hash_undefined
+		       || (h->type == bfd_link_hash_defined
 			   && (h->u.def.section->flags
 			       & SEC_LINKER_CREATED) != 0)))
 		{
-		  /* Do nothing.  The symbol was never referenced, or was
-		     defined by some object.  */
+		  /* Do nothing.  The symbol was never referenced, or
+		     was defined in some object file.  Undefined weak
+		     symbols stay undefined.  */
 		  break;
 		}
 	    }
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 9429574..6cadc68 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,6 +1,9 @@
 2015-02-11  Alan Modra  <amodra@gmail.com>
 
 	Apply from master.
+	2014-12-23  Alan Modra  <amodra@gmail.com>
+	* ld-elf/endsym.s, *ld-elf/endsym.d: New test.
+
 	2014-12-04  Alan Modra  <amodra@gmail.com>
 	* ld-powerpc/vxworks-relax.rd: Update for reloc sorting.
 	* ld-powerpc/vxworks-relax-2.rd: Likewise.
diff --git a/ld/testsuite/ld-elf/endsym.d b/ld/testsuite/ld-elf/endsym.d
new file mode 100644
index 0000000..912d3de
--- /dev/null
+++ b/ld/testsuite/ld-elf/endsym.d
@@ -0,0 +1,13 @@
+#source: start.s
+#source: endsym.s
+#ld: --sort-common
+#nm: -n
+#notarget: hppa*-*-hpux*
+
+#...
+.* end
+#...
+.* end2
+#...
+.* _?_end
+#pass
diff --git a/ld/testsuite/ld-elf/endsym.s b/ld/testsuite/ld-elf/endsym.s
new file mode 100644
index 0000000..5255c04
--- /dev/null
+++ b/ld/testsuite/ld-elf/endsym.s
@@ -0,0 +1,2 @@
+ .comm end,4,4
+ .comm end2,2,2


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