summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-01-27 10:27:42 +1030
committerAlan Modra <amodra@gmail.com>2020-01-29 11:14:12 +1030
commit7b647b69680015f240b20e6f38d824d71d4bd30d (patch)
tree11ab35ce8e43d18a46ab912761dcfc0caee1df0e
parent9d4684ce5baf54f6f9cf73f96de836e255eeb7ba (diff)
downloadbinutils-gdb-7b647b69680015f240b20e6f38d824d71d4bd30d.tar.gz
Mark all weak aliases for copy relocations
bfd/ PR ld/25458 * elflink.c (_bfd_elf_gc_mark_rsec): Mark all weak aliases. ld/ PR ld/25458 * testsuite/ld-elf/pr25458.map: New file. * testsuite/ld-elf/pr25458.rd: Likewise. * testsuite/ld-elf/pr25458a.s: Likewise. * testsuite/ld-elf/pr25458b.s: Likewise. * testsuite/ld-elf/shared.exp: Run PR ld/25458 test. (cherry picked from commit 3024a17ae029ec7f55b498e99ddd6238e22fe565)
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/elflink.c18
-rw-r--r--ld/ChangeLog12
-rw-r--r--ld/testsuite/ld-elf/pr25458.map4
-rw-r--r--ld/testsuite/ld-elf/pr25458.rd10
-rw-r--r--ld/testsuite/ld-elf/pr25458a.s6
-rw-r--r--ld/testsuite/ld-elf/pr25458b.s11
-rw-r--r--ld/testsuite/ld-elf/shared.exp32
8 files changed, 91 insertions, 7 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 41a60ffb397..8970c8fd8cf 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,6 +1,11 @@
2020-01-29 Alan Modra <amodra@gmail.com>
Apply from master
+ 2020-01-27 H.J. Lu <hongjiu.lu@intel.com>
+ Alan Modra <amodra@gmail.com>
+ PR ld/25458
+ * elflink.c (_bfd_elf_gc_mark_rsec): Mark all weak aliases.
+
2020-01-23 Alan Modra <amodra@gmail.com>
PR 25444
* elf.c (assign_file_positions_for_load_sections): Avoid divide
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 300be3f7437..5217528a79b 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -13123,7 +13123,7 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_info *info, asection *sec,
bfd_boolean *start_stop)
{
unsigned long r_symndx;
- struct elf_link_hash_entry *h;
+ struct elf_link_hash_entry *h, *hw;
r_symndx = cookie->rel->r_info >> cookie->r_sym_shift;
if (r_symndx == STN_UNDEF)
@@ -13143,12 +13143,16 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_info *info, asection *sec,
|| h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
h->mark = 1;
- /* If this symbol is weak and there is a non-weak definition, we
- keep the non-weak definition because many backends put
- dynamic reloc info on the non-weak definition for code
- handling copy relocs. */
- if (h->is_weakalias)
- weakdef (h)->mark = 1;
+ /* Keep all aliases of the symbol too. If an object symbol
+ needs to be copied into .dynbss then all of its aliases
+ should be present as dynamic symbols, not just the one used
+ on the copy relocation. */
+ hw = h;
+ while (hw->is_weakalias)
+ {
+ hw = hw->u.alias;
+ hw->mark = 1;
+ }
if (start_stop != NULL)
{
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 3163f6b3fc2..25878f9234a 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,15 @@
+2020-01-29 Alan Modra <amodra@gmail.com>
+
+ Apply from master
+ 2020-01-27 H.J. Lu <hongjiu.lu@intel.com>
+ Alan Modra <amodra@gmail.com>
+ PR ld/25458
+ * testsuite/ld-elf/pr25458.map: New file.
+ * testsuite/ld-elf/pr25458.rd: Likewise.
+ * testsuite/ld-elf/pr25458a.s: Likewise.
+ * testsuite/ld-elf/pr25458b.s: Likewise.
+ * testsuite/ld-elf/shared.exp: Run PR ld/25458 test.
+
2020-01-20 Nick Clifton <nickc@redhat.com>
* po/pt_BR.po: Updated Brazilian Portuguese translation.
diff --git a/ld/testsuite/ld-elf/pr25458.map b/ld/testsuite/ld-elf/pr25458.map
new file mode 100644
index 00000000000..5578d1fae72
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr25458.map
@@ -0,0 +1,4 @@
+FOO {
+global:
+ __environ; _environ; environ;
+};
diff --git a/ld/testsuite/ld-elf/pr25458.rd b/ld/testsuite/ld-elf/pr25458.rd
new file mode 100644
index 00000000000..d0fc6b9bed7
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr25458.rd
@@ -0,0 +1,10 @@
+#...
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: [0-9a-f]+ +(4|8)+ OBJECT +(WEAK|GLOBAL) +DEFAULT +[0-9]+ _*environ@FOO \(2\)
+#...
+ +[0-9]+: [0-9a-f]+ +(4|8)+ OBJECT +(WEAK|GLOBAL) +DEFAULT +[0-9]+ _*environ@FOO \(2\)
+#...
+ +[0-9]+: [0-9a-f]+ +(4|8)+ OBJECT +(WEAK|GLOBAL) +DEFAULT +[0-9]+ _*environ@FOO \(2\)
+#pass
diff --git a/ld/testsuite/ld-elf/pr25458a.s b/ld/testsuite/ld-elf/pr25458a.s
new file mode 100644
index 00000000000..59e6af2c192
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr25458a.s
@@ -0,0 +1,6 @@
+ .text
+ .globl _start
+ .type _start, %function
+_start:
+ .dc.a environ
+ .size _start, .-_start
diff --git a/ld/testsuite/ld-elf/pr25458b.s b/ld/testsuite/ld-elf/pr25458b.s
new file mode 100644
index 00000000000..ff64cc7584b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr25458b.s
@@ -0,0 +1,11 @@
+ .data
+ .globl __environ
+ .type __environ,%object
+__environ:
+ .dc.a 0
+ .size __environ, .-__environ
+ .weak _environ
+ .globl _environ
+ .set _environ, __environ
+ .weak environ
+ .set environ, __environ
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index e03906a142d..b1762aff9be 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -337,6 +337,38 @@ if { [check_gc_sections_available] } {
"pr22150" \
] \
]
+
+ switch -glob $target_triplet {
+ # exclude targets that don't support copy relocs
+ bfin-*-* { }
+ frv-*-* { }
+ lm32-*-* { }
+ mips*-*-* { }
+ tic6x-*-* { }
+ xtensa-*-* { }
+ default {
+ run_ld_link_tests [list \
+ [list \
+ "Build pr25458.so" \
+ "$LFLAGS -shared --version-script=pr25458.map" \
+ "" \
+ "$AFLAGS_PIC" \
+ {pr25458b.s} \
+ {} \
+ "pr25458.so" \
+ ] \
+ [list \
+ "Build pr25458" \
+ "$LFLAGS -e _start --gc-sections" \
+ "tmpdir/pr25458.so" \
+ "$AFLAGS_PIC" \
+ {pr25458a.s} \
+ {{readelf {--dyn-sym --wide} pr25458.rd}} \
+ "pr25458" \
+ ] \
+ ]
+ }
+ }
}
set ASFLAGS $old_ASFLAGS