return 0;
}
+/* Mark symbol, NAME, as locally defined by linker if it is referenced
+ and not defined in a relocatable object file. */
+
+static void
+elf_x86_linker_defined (struct bfd_link_info *info, const char *name)
+{
+ struct elf_link_hash_entry *h;
+
+ h = elf_link_hash_lookup (elf_hash_table (info), name,
+ FALSE, FALSE, FALSE);
+ if (h == NULL)
+ return;
+
+ while (h->root.type == bfd_link_hash_indirect)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ if (h->root.type == bfd_link_hash_new
+ || h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak
+ || h->root.type == bfd_link_hash_common
+ || (!h->def_regular && h->def_dynamic))
+ {
+ elf_x86_hash_entry (h)->local_ref = 2;
+ elf_x86_hash_entry (h)->linker_def = 1;
+ }
+}
+
bfd_boolean
_bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
{
/* "__ehdr_start" will be defined by linker as a hidden symbol
later if it is referenced and not defined. */
- h = elf_link_hash_lookup (elf_hash_table (info),
- "__ehdr_start",
- FALSE, FALSE, FALSE);
- if (h != NULL
- && (h->root.type == bfd_link_hash_new
- || h->root.type == bfd_link_hash_undefined
- || h->root.type == bfd_link_hash_undefweak
- || h->root.type == bfd_link_hash_common))
+ elf_x86_linker_defined (info, "__ehdr_start");
+
+ if (bfd_link_executable (info))
{
- elf_x86_hash_entry (h)->local_ref = 2;
- elf_x86_hash_entry (h)->linker_def = 1;
+ /* References to __bss_start, _end and _edata should be
+ locally resolved within executables. */
+ elf_x86_linker_defined (info, "__bss_start");
+ elf_x86_linker_defined (info, "_end");
+ elf_x86_linker_defined (info, "_edata");
}
}
}
+2018-05-14 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/23162
+ * testsuite/ld-elf/pr23162.map: New file.
+ * testsuite/ld-elf/pr23162.rd: Likewise.
+ * testsuite/ld-elf/pr23162a.c: Likewise.
+ * testsuite/ld-elf/pr23162b.c: Likewise.
+ * testsuite/ld-elf/shared.exp: Run PR ld/23162 tests.
+
2018-05-12 Alan Modra <amodra@gmail.com>
PR 20659
--- /dev/null
+There are no relocations in this file\.
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +[0-9]+ +_edata
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +[0-9]+ +_end
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +[0-9]+ +__bss_start
+#...
mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"
+
+if { ([istarget "i?86-*-*"]
+ || [istarget "x86_64-*-*"]) } {
+ run_ld_link_tests [list \
+ [list \
+ "Build libpr23162a.so" \
+ "-shared" \
+ "" \
+ "$AFLAGS_PIC" \
+ { pr23162a.c } \
+ "" \
+ "libpr23162a.so" \
+ "-fPIC -O2" \
+ ] \
+ [list \
+ "Build pr23162a" \
+ "-pie --no-as-needed tmpdir/libpr23162a.so" \
+ "" \
+ "-mrelax-relocations=yes" \
+ { pr23162b.c } \
+ {{readelf {--dyn-syms -rW} pr23162.rd}} \
+ "pr23162a" \
+ "-fPIC -O0" \
+ ] \
+ [list \
+ "Build libpr23162b.so" \
+ "-shared --version-script=pr23162.map" \
+ "" \
+ "$AFLAGS_PIC" \
+ { pr23162a.c } \
+ "" \
+ "libpr23162b.so" \
+ "-fPIC -O2" \
+ ] \
+ [list \
+ "Build pr23162b" \
+ "-pie --no-as-needed tmpdir/libpr23162b.so" \
+ "" \
+ "-mrelax-relocations=yes" \
+ { pr23162b.c } \
+ {{readelf {--dyn-syms -rW} pr23162.rd}} \
+ "pr23162b" \
+ "-fPIC -O0" \
+ ] \
+ ]
+}