binutils/SOURCES/binutils-mark-all-weak-aliases.patch

124 lines
4.1 KiB
Diff
Raw Normal View History

2021-10-06 15:46:27 +00:00
--- binutils.orig/bfd/elflink.c 2021-03-19 13:03:56.464793790 +0000
+++ binutils-2.30/bfd/elflink.c 2021-03-19 13:05:17.475264954 +0000
@@ -12825,7 +12825,7 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_i
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)
@@ -12845,12 +12845,16 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_i
|| 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)
{
Only in binutils-2.30/ld/testsuite/ld-elf: pr25458.map
Only in binutils-2.30/ld/testsuite/ld-elf: pr25458.rd
Only in binutils-2.30/ld/testsuite/ld-elf: pr25458a.s
Only in binutils-2.30/ld/testsuite/ld-elf: pr25458b.s
diff -rup binutils.orig/ld/testsuite/ld-elf/shared.exp binutils-2.30/ld/testsuite/ld-elf/shared.exp
--- binutils.orig/ld/testsuite/ld-elf/shared.exp 2021-03-19 13:03:56.141795899 +0000
+++ binutils-2.30/ld/testsuite/ld-elf/shared.exp 2021-03-19 13:08:57.839826387 +0000
@@ -296,6 +296,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
--- /dev/null 2021-03-19 08:56:47.991465597 +0000
+++ binutils-2.30/ld/testsuite/ld-elf/pr25458.map 2021-03-19 13:06:34.859759781 +0000
@@ -0,0 +1,4 @@
+FOO {
+global:
+ __environ; _environ; environ;
+};
--- /dev/null 2021-03-19 08:56:47.991465597 +0000
+++ binutils-2.30/ld/testsuite/ld-elf/pr25458.rd 2021-03-19 13:06:34.860759774 +0000
@@ -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
--- /dev/null 2021-03-19 08:56:47.991465597 +0000
+++ binutils-2.30/ld/testsuite/ld-elf/pr25458a.s 2021-03-19 13:06:34.860759774 +0000
@@ -0,0 +1,6 @@
+ .text
+ .globl _start
+ .type _start, %function
+_start:
+ .dc.a environ
+ .size _start, .-_start
--- /dev/null 2021-03-19 08:56:47.991465597 +0000
+++ binutils-2.30/ld/testsuite/ld-elf/pr25458b.s 2021-03-19 13:06:34.860759774 +0000
@@ -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