aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ld/ChangeLog12
-rw-r--r--ld/ldlang.c2
-rw-r--r--ld/testsuite/ld-elf/pr21233-e.ld2
-rw-r--r--ld/testsuite/ld-elf/pr21233-l.s6
-rw-r--r--ld/testsuite/ld-elf/pr21233-l.sd6
-rw-r--r--ld/testsuite/ld-elf/pr21233.ld17
-rw-r--r--ld/testsuite/ld-elf/pr21233.s8
-rw-r--r--ld/testsuite/ld-elf/pr21233.sd9
-rw-r--r--ld/testsuite/ld-elf/shared.exp39
9 files changed, 101 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index c9298e9..d8b9a22 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,15 @@
+2017-04-04 Maciej W. Rozycki <macro@imgtec.com>
+
+ PR ld/21233
+ * ldlang.c (insert_undefined): Set `mark' for ELF symbols.
+ * testsuite/ld-elf/pr21233.sd: New test.
+ * testsuite/ld-elf/pr21233-l.sd: New test.
+ * testsuite/ld-elf/pr21233.ld: New test linker script.
+ * testsuite/ld-elf/pr21233-e.ld: New test linker script.
+ * testsuite/ld-elf/pr21233.s: New test source.
+ * testsuite/ld-elf/pr21233-l.s: New test source.
+ * testsuite/ld-elf/shared.exp: Run the new tests.
+
2017-04-04 H.J. Lu <hongjiu.lu@intel.com>
* NEWS: Mention support for ELF SHF_GNU_MBIND and
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 5a42659..266c099 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -3429,6 +3429,8 @@ insert_undefined (const char *name)
{
h->type = bfd_link_hash_undefined;
h->u.undef.abfd = NULL;
+ if (is_elf_hash_table (link_info.hash))
+ ((struct elf_link_hash_entry *) h)->mark = 1;
bfd_link_add_undef (link_info.hash, h);
}
}
diff --git a/ld/testsuite/ld-elf/pr21233-e.ld b/ld/testsuite/ld-elf/pr21233-e.ld
new file mode 100644
index 0000000..f0bc281
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21233-e.ld
@@ -0,0 +1,2 @@
+EXTERN (bar)
+INCLUDE pr21233.ld
diff --git a/ld/testsuite/ld-elf/pr21233-l.s b/ld/testsuite/ld-elf/pr21233-l.s
new file mode 100644
index 0000000..1d02f9a
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21233-l.s
@@ -0,0 +1,6 @@
+ .data
+ .globl bar
+ .type bar, %object
+bar:
+ .byte 1
+ .size bar, . - bar
diff --git a/ld/testsuite/ld-elf/pr21233-l.sd b/ld/testsuite/ld-elf/pr21233-l.sd
new file mode 100644
index 0000000..724fdd4
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21233-l.sd
@@ -0,0 +1,6 @@
+# Make sure global `bar' is present in the dynamic symbol table, e.g.:
+# Num: Value Size Type Bind Vis Ndx Name
+# 1: 00000000 1 OBJECT GLOBAL DEFAULT 5 bar
+#...
+ *[0-9]+: +[0-9a-f]+ +1 +OBJECT +GLOBAL +DEFAULT +[0-9]+ +bar
+#pass
diff --git a/ld/testsuite/ld-elf/pr21233.ld b/ld/testsuite/ld-elf/pr21233.ld
new file mode 100644
index 0000000..a3b547b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21233.ld
@@ -0,0 +1,17 @@
+SECTIONS
+{
+ .hash : { *(.hash) }
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .rel.dyn : { *(.rel.dyn) }
+ .text : { *(.text) }
+ .dynamic : { *(.dynamic) }
+ .data : { *(.data) }
+ .symtab : { *(.symtab) }
+ .strtab : { *(.strtab) }
+ .shstrtab : { *(.shstrtab) }
+ .plt : { *(.plt) }
+ .got.plt : { *(.got.plt) }
+ .got : { *(.got) }
+ /DISCARD/ : { *(*) }
+}
diff --git a/ld/testsuite/ld-elf/pr21233.s b/ld/testsuite/ld-elf/pr21233.s
new file mode 100644
index 0000000..0c405c6
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21233.s
@@ -0,0 +1,8 @@
+ .text
+ .globl foo
+ .type foo, %function
+foo:
+ .size foo, . - foo
+
+ .data
+ .dc.a bar
diff --git a/ld/testsuite/ld-elf/pr21233.sd b/ld/testsuite/ld-elf/pr21233.sd
new file mode 100644
index 0000000..74d446d
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr21233.sd
@@ -0,0 +1,9 @@
+# Make sure the `bar' reference is global rather than local
+# in the dynamic symbol table, e.g.:
+# Num: Value Size Type Bind Vis Ndx Name
+# 1: 00000000 0 OBJECT GLOBAL DEFAULT UND bar
+# vs:
+# 1: 00000000 0 OBJECT LOCAL DEFAULT UND bar
+#...
+ *[0-9]+: +[0-9a-f]+ +0 +OBJECT +GLOBAL +DEFAULT +UND +bar
+#pass
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 300100a..be30ec0 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -115,6 +115,45 @@ if { [check_gc_sections_available] } {
{{objdump -p pr20828-v.od}} \
"pr20828-v-2"]]
}
+# PR ld/21233 check for correct dynamic symbol table entries where:
+# - a symbol has been defined in a shared library used in the link,
+# - the symbol has been referenced from a section swept in garbage collection,
+# - the symbol has also been forced to be entered in the output file as an
+# undefined symbol, either with a command-line option or a linker script
+# command.
+# Verify that the undefined symbol is global rather than local.
+if { [check_gc_sections_available] } {
+ run_ld_link_tests [list \
+ [list \
+ "PR ld/21233 dynamic symbols with section GC\
+ (auxiliary shared library)" \
+ "$LFLAGS -shared -T pr21233.ld" "" "$AFLAGS_PIC" \
+ {pr21233-l.s} \
+ {{readelf --dyn-syms pr21233-l.sd}} \
+ "libpr21233.so"] \
+ [list \
+ "PR ld/21233 dynamic symbols with section GC (--undefined)" \
+ "$LFLAGS --gc-sections -e foo --undefined=bar -T pr21233.ld" \
+ "tmpdir/libpr21233.so" "" \
+ {pr21233.s} \
+ {{readelf --dyn-syms pr21233.sd}} \
+ "pr21233-1"] \
+ [list \
+ "PR ld/21233 dynamic symbols with section GC (--require-defined)" \
+ "$LFLAGS --gc-sections -e foo --require-defined=bar\
+ -T pr21233.ld" \
+ "tmpdir/libpr21233.so" "" \
+ {pr21233.s} \
+ {{readelf --dyn-syms pr21233.sd}} \
+ "pr21233-2"] \
+ [list \
+ "PR ld/21233 dynamic symbols with section GC (EXTERN)" \
+ "$LFLAGS --gc-sections -e foo -T pr21233-e.ld" \
+ "tmpdir/libpr21233.so" "" \
+ {pr21233.s} \
+ {{readelf --dyn-syms pr21233.sd}} \
+ "pr21233-3"]]
+}
# Check to see if the C compiler works
if { [which $CC] == 0 } {