From 4cc2bf08a4e18aa2009e9d4f1694a800eacbee17 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 22 Dec 2014 10:49:23 +1030 Subject: [PATCH] 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 ): Leave bfd_link_hash_common symbols alone. ld/testsuite/ * ld-elf/endsym.s, *ld-elf/endsym.d: New test. --- ld/ChangeLog | 5 +++++ ld/ldexp.c | 12 ++++++------ ld/testsuite/ChangeLog | 4 ++++ ld/testsuite/ld-elf/endsym.d | 13 +++++++++++++ ld/testsuite/ld-elf/endsym.s | 2 ++ 5 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 ld/testsuite/ld-elf/endsym.d create mode 100644 ld/testsuite/ld-elf/endsym.s diff --git a/ld/ChangeLog b/ld/ChangeLog index 43ce92432ea..f16d1d53076 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2014-12-23 Alan Modra + + * ldexp.c (exp_fold_tree_1 ): Leave bfd_link_hash_common + symbols alone. + 2014-12-23 Alan Modra * ldexp.c (update_definedness): Correct logic setting by_object. diff --git a/ld/ldexp.c b/ld/ldexp.c index e9e95f9ddeb..8615869b729 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 9607a1548ea..c901bb722bd 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-12-23 Alan Modra + + * ld-elf/endsym.s, *ld-elf/endsym.d: New test. + 2014-12-19 Matthew Fortune * ld-mips-elf/attr-gnu-4-00.d: Relax check for ISA extension. diff --git a/ld/testsuite/ld-elf/endsym.d b/ld/testsuite/ld-elf/endsym.d new file mode 100644 index 00000000000..912d3dee9d9 --- /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 00000000000..5255c049c86 --- /dev/null +++ b/ld/testsuite/ld-elf/endsym.s @@ -0,0 +1,2 @@ + .comm end,4,4 + .comm end2,2,2 -- 2.30.2