From 07492f668d2173da7a2bda3707ff0985e0f460b6 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 4 Mar 2016 06:37:34 -0800 Subject: Treat common symbol in executable as definition Common symbol in executable is a definition, which overrides definition from shared objects. When linker sees a new definition from a shared object, the new dynamic definition should be overridden by the previous common symbol in executable. bfd/ PR ld/19579 * elflink.c (_bfd_elf_merge_symbol): Treat common symbol in executable as definition if the new definition comes from a shared library. ld/ PR ld/19579 * testsuite/ld-elf/pr19579a.c: New file. * testsuite/ld-elf/pr19579b.c: Likewise. * testsuite/ld-elf/shared.exp: Run PR ld/19579 test. --- bfd/ChangeLog | 7 +++++++ bfd/elflink.c | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index b2cc5b8..5f9f99d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2016-03-04 H.J. Lu + + PR ld/19579 + * elflink.c (_bfd_elf_merge_symbol): Treat common symbol in + executable as definition if the new definition comes from a + shared library. + 2016-03-02 Alan Modra * Makefile.in: Regenerate. diff --git a/bfd/elflink.c b/bfd/elflink.c index 0e3abff..39157bf 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -1172,9 +1172,12 @@ _bfd_elf_merge_symbol (bfd *abfd, newdef = !bfd_is_und_section (sec) && !bfd_is_com_section (sec); + /* The old common symbol in executable is a definition if the new + definition comes from a shared library. */ olddef = (h->root.type != bfd_link_hash_undefined && h->root.type != bfd_link_hash_undefweak - && h->root.type != bfd_link_hash_common); + && (h->root.type != bfd_link_hash_common + || (!olddyn && newdyn && bfd_link_executable (info)))); /* NEWFUNC and OLDFUNC indicate whether the new or old symbol, respectively, appear to be a function. */ -- cgit v1.1