H.J. Lu
2018-12-07 14:23:03 UTC
Mark the previous definition from IR object as undefined so that the
generic linker will override it.
bfd/
PR ld/23958
* elflink.c (_bfd_elf_add_default_symbol): Override the previous
definition from IR object.
ld/
PR ld/23958
* testsuite/ld-plugin/lto.exp: Run PR ld/23958 test.
* testsuite/ld-plugin/pr23958.c: New file.
* testsuite/ld-plugin/pr23958.t: Likewise.
---
bfd/elflink.c | 9 +++++++++
ld/testsuite/ld-plugin/lto.exp | 6 ++++++
ld/testsuite/ld-plugin/pr23958.c | 6 ++++++
ld/testsuite/ld-plugin/pr23958.t | 4 ++++
4 files changed, 25 insertions(+)
create mode 100644 ld/testsuite/ld-plugin/pr23958.c
create mode 100644 ld/testsuite/ld-plugin/pr23958.t
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 4eca389bd1..8992a5016f 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1941,6 +1941,15 @@ _bfd_elf_add_default_symbol (bfd *abfd,
if (! bfd_link_relocatable (info))
{
bh = &hi->root;
+ if (bh->type == bfd_link_hash_defined
+ && (bh->u.def.section->owner->flags & BFD_PLUGIN) != 0)
+ {
+ /* Mark the previous definition from IR object as
+ undefined so that the generic linker will override
+ it. */
+ bh->type = bfd_link_hash_undefined;
+ bh->u.undef.abfd = bh->u.def.section->owner;
+ }
if (! (_bfd_generic_link_add_one_symbol
(info, abfd, shortname, BSF_INDIRECT,
bfd_ind_section_ptr,
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 008bde79de..b56bd63ef4 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -225,6 +225,12 @@ set lto_link_tests [list \
{pr23818a.c pr23818b.c} \
{{"readelf" {-s --wide} "pr23818.d"}} \
"libpr23818.so"] \
+ [list "Build libpr23958.so" \
+ "-shared -flto -Wl,-version-script,pr23958.t" \
+ "-g -flto $lto_fat" \
+ {pr23958.c} \
+ "" \
+ "libpr23958.so"] \
]
if { [at_least_gcc_version 4 7] } {
diff --git a/ld/testsuite/ld-plugin/pr23958.c b/ld/testsuite/ld-plugin/pr23958.c
new file mode 100644
index 0000000000..656dc31706
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr23958.c
@@ -0,0 +1,6 @@
+void
+dwarf_bytesize (void)
+{
+}
+
+asm (".symver dwarf_bytesize,dwarf_bytesize@@@ELFUTILS_0.143");
diff --git a/ld/testsuite/ld-plugin/pr23958.t b/ld/testsuite/ld-plugin/pr23958.t
new file mode 100644
index 0000000000..d3af1ae0cd
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr23958.t
@@ -0,0 +1,4 @@
+ELFUTILS_0.143 {
+global:
+ dwarf_bytesize;
+};
generic linker will override it.
bfd/
PR ld/23958
* elflink.c (_bfd_elf_add_default_symbol): Override the previous
definition from IR object.
ld/
PR ld/23958
* testsuite/ld-plugin/lto.exp: Run PR ld/23958 test.
* testsuite/ld-plugin/pr23958.c: New file.
* testsuite/ld-plugin/pr23958.t: Likewise.
---
bfd/elflink.c | 9 +++++++++
ld/testsuite/ld-plugin/lto.exp | 6 ++++++
ld/testsuite/ld-plugin/pr23958.c | 6 ++++++
ld/testsuite/ld-plugin/pr23958.t | 4 ++++
4 files changed, 25 insertions(+)
create mode 100644 ld/testsuite/ld-plugin/pr23958.c
create mode 100644 ld/testsuite/ld-plugin/pr23958.t
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 4eca389bd1..8992a5016f 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1941,6 +1941,15 @@ _bfd_elf_add_default_symbol (bfd *abfd,
if (! bfd_link_relocatable (info))
{
bh = &hi->root;
+ if (bh->type == bfd_link_hash_defined
+ && (bh->u.def.section->owner->flags & BFD_PLUGIN) != 0)
+ {
+ /* Mark the previous definition from IR object as
+ undefined so that the generic linker will override
+ it. */
+ bh->type = bfd_link_hash_undefined;
+ bh->u.undef.abfd = bh->u.def.section->owner;
+ }
if (! (_bfd_generic_link_add_one_symbol
(info, abfd, shortname, BSF_INDIRECT,
bfd_ind_section_ptr,
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 008bde79de..b56bd63ef4 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -225,6 +225,12 @@ set lto_link_tests [list \
{pr23818a.c pr23818b.c} \
{{"readelf" {-s --wide} "pr23818.d"}} \
"libpr23818.so"] \
+ [list "Build libpr23958.so" \
+ "-shared -flto -Wl,-version-script,pr23958.t" \
+ "-g -flto $lto_fat" \
+ {pr23958.c} \
+ "" \
+ "libpr23958.so"] \
]
if { [at_least_gcc_version 4 7] } {
diff --git a/ld/testsuite/ld-plugin/pr23958.c b/ld/testsuite/ld-plugin/pr23958.c
new file mode 100644
index 0000000000..656dc31706
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr23958.c
@@ -0,0 +1,6 @@
+void
+dwarf_bytesize (void)
+{
+}
+
+asm (".symver dwarf_bytesize,dwarf_bytesize@@@ELFUTILS_0.143");
diff --git a/ld/testsuite/ld-plugin/pr23958.t b/ld/testsuite/ld-plugin/pr23958.t
new file mode 100644
index 0000000000..d3af1ae0cd
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr23958.t
@@ -0,0 +1,4 @@
+ELFUTILS_0.143 {
+global:
+ dwarf_bytesize;
+};
--
2.19.2
2.19.2