This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Don't PROVIDE over top of common symbols
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Tue, 23 Dec 2014 23:17:29 +1030
- Subject: Don't PROVIDE over top of common symbols
- Authentication-results: sourceware.org; auth=none
This:
int end[100000];
int main(void) { end[99999] = 0; return 0; }
should not segfault.
The testcase added here fails on alpha, cr16, crx and dlx. The alpha
failue is fixed by a later patch. The other three fail due to not
defining _end. cr16 and crx also fail due to
config.sort_common = TRUE;
in after_parse which I think is sufficiently bad to not xfail the new
test for those targets. (sort_common is an enum, not a boolean.)
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 --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/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
--
Alan Modra
Australia Development Lab, IBM