From c6e8a9a802bcd3a96ef14b6ea1b6cd60d5d8d065 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 30 Jul 2015 03:27:44 -0700 Subject: [PATCH] Don't change the default symbol for relocatable link We should change the default symbol for the versioned symbol only when not performing a relocatable link. bfd/ PR ld/18735 * elflink.c (_bfd_elf_add_default_symbol): Add the default symbol if not performing a relocatable link. (elf_link_add_object_symbols): Adjust the default symbol if not performing a relocatable link. ld/testsuite/ PR ld/18735 * ld-elf/pr18735.d: New file. * ld-elf/pr18735.s: Likewise. --- bfd/ChangeLog | 8 ++++++++ bfd/elflink.c | 24 +++++++++++++++--------- ld/testsuite/ChangeLog | 6 ++++++ ld/testsuite/ld-elf/pr18735.d | 10 ++++++++++ ld/testsuite/ld-elf/pr18735.s | 13 +++++++++++++ 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 ld/testsuite/ld-elf/pr18735.d create mode 100644 ld/testsuite/ld-elf/pr18735.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e3339d0ba41..e9776bf4814 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2015-07-30 H.J. Lu + + PR ld/18735 + * elflink.c (_bfd_elf_add_default_symbol): Add the default + symbol if not performing a relocatable link. + (elf_link_add_object_symbols): Adjust the default symbol if + not performing a relocatable link. + 2015-07-29 H.J. Lu * elflink.c (elf_link_add_object_symbols): Remove diff --git a/bfd/elflink.c b/bfd/elflink.c index fc1fd087bb7..846f35e8879 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -1655,12 +1655,17 @@ _bfd_elf_add_default_symbol (bfd *abfd, if (! override) { - bh = &hi->root; - if (! (_bfd_generic_link_add_one_symbol - (info, abfd, shortname, BSF_INDIRECT, bfd_ind_section_ptr, - 0, name, FALSE, collect, &bh))) - return FALSE; - hi = (struct elf_link_hash_entry *) bh; + /* Add the default symbol if not performing a relocatable link. */ + if (! info->relocatable) + { + bh = &hi->root; + if (! (_bfd_generic_link_add_one_symbol + (info, abfd, shortname, BSF_INDIRECT, + bfd_ind_section_ptr, + 0, name, FALSE, collect, &bh))) + return FALSE; + hi = (struct elf_link_hash_entry *) bh; + } } else { @@ -4609,9 +4614,10 @@ error_free_dyn: old_tab = NULL; } - /* Now that all the symbols from this input file are created, handle - .symver foo, foo@BAR such that any relocs against foo become foo@BAR. */ - if (nondeflt_vers != NULL) + /* Now that all the symbols from this input file are created, if + not performing a relocatable link, handle .symver foo, foo@BAR + such that any relocs against foo become foo@BAR. */ + if (!info->relocatable && nondeflt_vers != NULL) { bfd_size_type cnt, symidx; diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 267361f6bb7..c35d4a79bb7 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-07-30 H.J. Lu + + PR ld/18735 + * ld-elf/pr18735.d: New file. + * ld-elf/pr18735.s: Likewise. + 2015-07-29 H.J. Lu * ld-elf/pr18718.c (bar): Use noclone attribute only for GCC diff --git a/ld/testsuite/ld-elf/pr18735.d b/ld/testsuite/ld-elf/pr18735.d new file mode 100644 index 00000000000..8ec0938d1f1 --- /dev/null +++ b/ld/testsuite/ld-elf/pr18735.d @@ -0,0 +1,10 @@ +#ld: -r +#readelf: -s + +Symbol table '.symtab' contains .* entries: +#... +[ ]*[0-9]+: [0-9a-fA-F]* +1 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +foo@FOO +[ ]*[0-9]+: [0-9a-fA-F]* +1 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +bar@@FOO +[ ]*[0-9]+: [0-9a-fA-F]* +1 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +foo +[ ]*[0-9]+: [0-9a-fA-F]* +1 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +bar +#pass diff --git a/ld/testsuite/ld-elf/pr18735.s b/ld/testsuite/ld-elf/pr18735.s new file mode 100644 index 00000000000..aae609daec1 --- /dev/null +++ b/ld/testsuite/ld-elf/pr18735.s @@ -0,0 +1,13 @@ + .data + .symver foo, foo@FOO + .symver bar, bar@@FOO + .globl foo + .type foo, %object +foo: + .byte 0 + .size foo, .-foo + .globl bar + .type bar, %object +bar: + .byte 0 + .size bar, .-bar -- 2.30.2