aboutsummaryrefslogtreecommitdiff
path: root/bfd/elflink.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-11-28 03:48:25 -0800
committerH.J. Lu <hjl.tools@gmail.com>2017-11-28 03:48:44 -0800
commita83ef4d139c377e0e87d105977d85c6ef9fbb162 (patch)
tree5c962499a8395d45d1d270f31a94f381ea0a7b6c /bfd/elflink.c
parentf0531ed6a429b0e6e6509e6852ccd3586f3fa1bd (diff)
downloadgdb-a83ef4d139c377e0e87d105977d85c6ef9fbb162.zip
gdb-a83ef4d139c377e0e87d105977d85c6ef9fbb162.tar.gz
gdb-a83ef4d139c377e0e87d105977d85c6ef9fbb162.tar.bz2
ld: Set non_ir_ref_regular on symbols referenced in regular objects
If linker plugin is enabled, set non_ir_ref_regular on symbols referenced in regular objects so that linker plugin will get the correct symbol resolution. bfd/ PR ld/22502 * elflink.c (_bfd_elf_merge_symbol): Also skip definition from an IR object. (elf_link_add_object_symbols): If linker plugin is enabled, set non_ir_ref_regular on symbols referenced in regular objects so that linker plugin will get the correct symbol resolution. ld/ PR ld/22502 * testsuite/ld-plugin/lto.exp: Run PR ld/22502 test. * testsuite/ld-plugin/pr22502a.c: New file. * testsuite/ld-plugin/pr22502b.c: Likewise.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r--bfd/elflink.c68
1 files changed, 65 insertions, 3 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 99f867d..ddd088c 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1555,10 +1555,13 @@ _bfd_elf_merge_symbol (bfd *abfd,
sec = *psec;
}
- /* There are multiple definitions of a normal symbol.
- Skip the default symbol as well. */
+ /* There are multiple definitions of a normal symbol. Skip the
+ default symbol as well as definition from an IR object. */
if (olddef && !olddyn && !oldweak && newdef && !newdyn && !newweak
- && !default_sym && h->def_regular)
+ && !default_sym && h->def_regular
+ && !(oldbfd != NULL
+ && (oldbfd->flags & BFD_PLUGIN) != 0
+ && (abfd->flags & BFD_PLUGIN) == 0))
{
/* Handle a multiple definition. */
(*info->callbacks->multiple_definition) (info, &h->root,
@@ -4931,6 +4934,65 @@ error_free_dyn:
}
}
+ if (info->lto_plugin_active
+ && !bfd_link_relocatable (info)
+ && (abfd->flags & BFD_PLUGIN) == 0
+ && !just_syms
+ && extsymcount)
+ {
+ int r_sym_shift;
+
+ if (bed->s->arch_size == 32)
+ r_sym_shift = 8;
+ else
+ r_sym_shift = 32;
+
+ /* If linker plugin is enabled, set non_ir_ref_regular on symbols
+ referenced in regular objects so that linker plugin will get
+ the correct symbol resolution. */
+
+ sym_hash = elf_sym_hashes (abfd);
+ for (s = abfd->sections; s != NULL; s = s->next)
+ {
+ Elf_Internal_Rela *internal_relocs;
+ Elf_Internal_Rela *rel, *relend;
+
+ /* Don't check relocations in excluded sections. */
+ if ((s->flags & SEC_RELOC) == 0
+ || s->reloc_count == 0
+ || (s->flags & SEC_EXCLUDE) != 0
+ || ((info->strip == strip_all
+ || info->strip == strip_debugger)
+ && (s->flags & SEC_DEBUGGING) != 0))
+ continue;
+
+ internal_relocs = _bfd_elf_link_read_relocs (abfd, s, NULL,
+ NULL,
+ info->keep_memory);
+ if (internal_relocs == NULL)
+ goto error_free_vers;
+
+ rel = internal_relocs;
+ relend = rel + s->reloc_count;
+ for ( ; rel < relend; rel++)
+ {
+ unsigned long r_symndx = rel->r_info >> r_sym_shift;
+ struct elf_link_hash_entry *h;
+
+ /* Skip local symbols. */
+ if (r_symndx < extsymoff)
+ continue;
+
+ h = sym_hash[r_symndx - extsymoff];
+ if (h != NULL)
+ h->root.non_ir_ref_regular = 1;
+ }
+
+ if (elf_section_data (s)->relocs != internal_relocs)
+ free (internal_relocs);
+ }
+ }
+
if (extversym != NULL)
{
free (extversym);