/* ELF linking support for BFD.
- Copyright (C) 1995-2020 Free Software Foundation, Inc.
+ Copyright (C) 1995-2021 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
static void
elf_merge_st_other (bfd *abfd, struct elf_link_hash_entry *h,
- const Elf_Internal_Sym *isym, asection *sec,
+ unsigned int st_other, asection *sec,
bfd_boolean definition, bfd_boolean dynamic)
{
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
/* If st_other has a processor-specific meaning, specific
code might be needed here. */
if (bed->elf_backend_merge_symbol_attribute)
- (*bed->elf_backend_merge_symbol_attribute) (h, isym, definition,
+ (*bed->elf_backend_merge_symbol_attribute) (h, st_other, definition,
dynamic);
if (!dynamic)
{
- unsigned symvis = ELF_ST_VISIBILITY (isym->st_other);
+ unsigned symvis = ELF_ST_VISIBILITY (st_other);
unsigned hvis = ELF_ST_VISIBILITY (h->other);
/* Keep the most constraining visibility. Leave the remainder
h->other = symvis | (h->other & ~ELF_ST_VISIBILITY (-1));
}
else if (definition
- && ELF_ST_VISIBILITY (isym->st_other) != STV_DEFAULT
+ && ELF_ST_VISIBILITY (st_other) != STV_DEFAULT
&& (sec->flags & SEC_READONLY) == 0)
h->protected_def = 1;
}
/* Merge st_other. If the symbol already has a dynamic index,
but visibility says it should not be visible, turn it into a
local symbol. */
- elf_merge_st_other (abfd, h, sym, sec, newdef, newdyn);
+ elf_merge_st_other (abfd, h, sym->st_other, sec, newdef, newdyn);
if (h->dynindx != -1)
switch (ELF_ST_VISIBILITY (h->other))
{
ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
(*bed->elf_backend_copy_indirect_symbol) (info, ht, hi);
+ /* If we first saw a reference to SHORTNAME with non-default
+ visibility, merge that visibility to the @@VER symbol. */
+ elf_merge_st_other (abfd, ht, hi->other, sec, TRUE, dynamic);
+
/* A reference to the SHORTNAME symbol from a dynamic library
will be satisfied by the versioned symbol at runtime. In
effect, we have a reference to the versioned symbol. */
return FALSE;
if (skip)
- return TRUE;
-
- if (override)
+ {
+ if (!dynamic
+ && h->root.type == bfd_link_hash_defweak
+ && hi->root.type == bfd_link_hash_defined)
+ {
+ /* We are handling a weak sym@@ver and attempting to define
+ a weak sym@ver, but _bfd_elf_merge_symbol said to skip the
+ new weak sym@ver because there is already a strong sym@ver.
+ However, sym@ver and sym@@ver are really the same symbol.
+ The existing strong sym@ver ought to override sym@@ver. */
+ h->root.type = bfd_link_hash_defined;
+ h->root.u.def.section = hi->root.u.def.section;
+ h->root.u.def.value = hi->root.u.def.value;
+ hi->root.type = bfd_link_hash_indirect;
+ hi->root.u.i.link = &h->root;
+ }
+ else
+ return TRUE;
+ }
+ else if (override)
{
/* Here SHORTNAME is a versioned name, so we don't expect to see
the type of override we do in the case above unless it is
/* xgettext:c-format */
(_("%pB: unexpected redefinition of indirect versioned symbol `%s'"),
abfd, shortname);
+ return TRUE;
}
else
{
bfd_ind_section_ptr, 0, name, FALSE, collect, &bh)))
return FALSE;
hi = (struct elf_link_hash_entry *) bh;
+ }
+
+ /* If there is a duplicate definition somewhere, then HI may not
+ point to an indirect symbol. We will have reported an error
+ to the user in that case. */
+ if (hi->root.type == bfd_link_hash_indirect)
+ {
+ (*bed->elf_backend_copy_indirect_symbol) (info, h, hi);
+ h->ref_dynamic_nonweak |= hi->ref_dynamic_nonweak;
+ hi->dynamic_def |= h->dynamic_def;
- /* If there is a duplicate definition somewhere, then HI may not
- point to an indirect symbol. We will have reported an error
- to the user in that case. */
+ /* If we first saw a reference to @VER symbol with
+ non-default visibility, merge that visibility to the
+ @@VER symbol. */
+ elf_merge_st_other (abfd, h, hi->other, sec, TRUE, dynamic);
- if (hi->root.type == bfd_link_hash_indirect)
+ /* See if the new flags lead us to realize that the symbol
+ must be dynamic. */
+ if (! *dynsym)
{
- (*bed->elf_backend_copy_indirect_symbol) (info, h, hi);
- h->ref_dynamic_nonweak |= hi->ref_dynamic_nonweak;
- hi->dynamic_def |= h->dynamic_def;
-
- /* See if the new flags lead us to realize that the symbol
- must be dynamic. */
- if (! *dynsym)
+ if (! dynamic)
{
- if (! dynamic)
- {
- if (! bfd_link_executable (info)
- || hi->ref_dynamic)
- *dynsym = TRUE;
- }
- else
- {
- if (hi->ref_regular)
- *dynsym = TRUE;
- }
+ if (! bfd_link_executable (info)
+ || hi->ref_dynamic)
+ *dynsym = TRUE;
+ }
+ else
+ {
+ if (hi->ref_regular)
+ *dynsym = TRUE;
}
}
}
_bfd_elf_strtab_finalize (dynstr);
size = _bfd_elf_strtab_size (dynstr);
+ /* Allow the linker to examine the dynsymtab now it's fully populated. */
+
+ if (info->callbacks->examine_strtab)
+ info->callbacks->examine_strtab (dynstr);
+
bed = get_elf_backend_data (dynobj);
sdyn = bfd_get_linker_section (dynobj, ".dynamic");
BFD_ASSERT (sdyn != NULL);
object and a shared object. */
bfd_boolean dynsym = FALSE;
- if (! dynamic)
+ /* Plugin symbols aren't normal. Don't set def/ref flags. */
+ if ((abfd->flags & BFD_PLUGIN) != 0)
+ ;
+ else if (!dynamic)
{
if (! definition)
{
h->ref_dynamic = 1;
}
}
-
- /* If the indirect symbol has been forced local, don't
- make the real symbol dynamic. */
- if ((h == hi || !hi->forced_local)
- && (bfd_link_dll (info)
- || h->def_dynamic
- || h->ref_dynamic))
- dynsym = TRUE;
}
else
{
h->def_dynamic = 1;
hi->def_dynamic = 1;
}
+ }
- /* If the indirect symbol has been forced local, don't
- make the real symbol dynamic. */
- if ((h == hi || !hi->forced_local)
- && (h->def_regular
- || h->ref_regular
- || (h->is_weakalias
- && weakdef (h)->dynindx != -1)))
+ /* If an indirect symbol has been forced local, don't
+ make the real symbol dynamic. */
+ if (h != hi && hi->forced_local)
+ ;
+ else if (!dynamic)
+ {
+ if (bfd_link_dll (info)
+ || h->def_dynamic
+ || h->ref_dynamic)
+ dynsym = TRUE;
+ }
+ else
+ {
+ if (h->def_regular
+ || h->ref_regular
+ || (h->is_weakalias
+ && weakdef (h)->dynindx != -1))
dynsym = TRUE;
}
/* Check to see if we need to add an indirect symbol for
the default name. */
- if (definition
- || (!override && h->root.type == bfd_link_hash_common))
+ if ((definition
+ || (!override && h->root.type == bfd_link_hash_common))
+ && !(hi != h
+ && hi->versioned == versioned_hidden))
if (!_bfd_elf_add_default_symbol (abfd, info, h, name, isym,
sec, value, &old_bfd, &dynsym))
goto error_free_vers;
}
/* Merge st_other field. */
- elf_merge_st_other (abfd, h, isym, sec, definition, dynamic);
+ elf_merge_st_other (abfd, h, isym->st_other, sec,
+ definition, dynamic);
/* We don't want to make debug symbol dynamic. */
if (definition
&& !bfd_link_relocatable (info))
dynsym = FALSE;
+ /* Nor should we make plugin symbols dynamic. */
+ if ((abfd->flags & BFD_PLUGIN) != 0)
+ dynsym = FALSE;
+
if (definition)
{
h->target_internal = isym->st_target_internal;
}
}
- if (dynsym && (abfd->flags & BFD_PLUGIN) == 0 && h->dynindx == -1)
+ if (dynsym && h->dynindx == -1)
{
if (! bfd_elf_link_record_dynamic_symbol (info, h))
goto error_free_vers;
&& definition
&& ((dynsym
&& h->ref_regular_nonweak)
+ || (old_bfd != NULL
+ && (old_bfd->flags & BFD_PLUGIN) != 0
+ && bind != STB_WEAK)
|| (h->ref_dynamic_nonweak
&& (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
&& !on_needed_list (elf_dt_name (abfd),
|| !_bfd_elf_add_dynamic_entry (info, DT_SYMTAB, 0)
|| !_bfd_elf_add_dynamic_entry (info, DT_STRSZ, strsize)
|| !_bfd_elf_add_dynamic_entry (info, DT_SYMENT,
- bed->s->sizeof_sym))
+ bed->s->sizeof_sym)
+ || (info->gnu_flags_1
+ && !_bfd_elf_add_dynamic_entry (info, DT_GNU_FLAGS_1,
+ info->gnu_flags_1)))
return FALSE;
}
}
}
}
+ /* Now swap out the symbols. */
for (i = 0; i < hash_table->strtabcount; i++)
{
struct elf_sym_strtab *elfsym = &hash_table->strtab[i];
elfsym->sym.st_name
= (unsigned long) _bfd_elf_strtab_offset (flinfo->symstrtab,
elfsym->sym.st_name);
+
+ /* Inform the linker of the addition of this symbol. */
+
+ if (flinfo->info->callbacks->ctf_new_symbol)
+ flinfo->info->callbacks->ctf_new_symbol (elfsym->dest_index,
+ &elfsym->sym);
+
bed->s->swap_symbol_out (flinfo->output_bfd, &elfsym->sym,
((bfd_byte *) symbuf
+ (elfsym->dest_index
+ elfsym->destshndx_index));
}
- /* Allow the linker to examine the strtab and symtab now they are
- populated. */
-
- if (flinfo->info->callbacks->examine_strtab)
- flinfo->info->callbacks->examine_strtab (hash_table->strtab,
- hash_table->strtabcount,
- flinfo->symstrtab);
-
hdr = &elf_tdata (flinfo->output_bfd)->symtab_hdr;
pos = hdr->sh_offset + hdr->sh_size;
amt = hash_table->strtabcount * bed->s->sizeof_sym;
eoinfo->failed = TRUE;
return FALSE;
}
+
+ /* Inform the linker of the addition of this symbol. */
+
+ if (flinfo->info->callbacks->ctf_new_dynsym)
+ flinfo->info->callbacks->ctf_new_dynsym (h->dynindx, &sym);
+
bed->s->swap_symbol_out (flinfo->output_bfd, &sym, esym, 0);
if (flinfo->hash_sec != NULL)
{
if ((kept->flags & SEC_GROUP) != 0)
kept = match_group_member (sec, kept, info);
- if (kept != NULL
- && ((sec->rawsize != 0 ? sec->rawsize : sec->size)
- != (kept->rawsize != 0 ? kept->rawsize : kept->size)))
- kept = NULL;
+ if (kept != NULL)
+ {
+ if ((sec->rawsize != 0 ? sec->rawsize : sec->size)
+ != (kept->rawsize != 0 ? kept->rawsize : kept->size))
+ kept = NULL;
+ else
+ {
+ /* Get the real kept section. */
+ asection *next;
+ for (next = kept->kept_section;
+ next != NULL;
+ next = next->kept_section)
+ kept = next;
+ }
+ }
sec->kept_section = kept;
}
return kept;
extsymoff = symtab_hdr->sh_info;
}
+ /* Enable GNU OSABI features in the output BFD that are used in the input
+ BFD. */
+ if (bed->elf_osabi == ELFOSABI_NONE
+ || bed->elf_osabi == ELFOSABI_GNU
+ || bed->elf_osabi == ELFOSABI_FREEBSD)
+ elf_tdata (output_bfd)->has_gnu_osabi
+ |= (elf_tdata (input_bfd)->has_gnu_osabi
+ & (bfd_link_relocatable (flinfo->info)
+ ? -1 : ~elf_gnu_osabi_retain));
+
/* Read the local symbols. */
isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
if (isymbuf == NULL && locsymcount != 0)
}
sym.st_value = s->vma;
dest = dynsym + dynindx * bed->s->sizeof_sym;
+
+ /* Inform the linker of the addition of this symbol. */
+
+ if (info->callbacks->ctf_new_dynsym)
+ info->callbacks->ctf_new_dynsym (dynindx, &sym);
+
bed->s->swap_symbol_out (abfd, &sym, dest, 0);
}
}
+ e->isym.st_value);
}
+ /* Inform the linker of the addition of this symbol. */
+
+ if (info->callbacks->ctf_new_dynsym)
+ info->callbacks->ctf_new_dynsym (e->dynindx, &sym);
+
dest = dynsym + e->dynindx * bed->s->sizeof_sym;
bed->s->swap_symbol_out (abfd, &sym, dest, 0);
}
== SHT_FINI_ARRAY)))
|| (elf_section_data (o)->this_hdr.sh_type == SHT_NOTE
&& elf_next_in_group (o) == NULL
- && elf_linked_to_section (o) == NULL)))
+ && elf_linked_to_section (o) == NULL)
+ || ((elf_tdata (sub)->has_gnu_osabi & elf_gnu_osabi_retain)
+ && (elf_section_flags (o) & SHF_GNU_RETAIN))))
{
if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
return FALSE;
flagword flag_value;
} elf_flags_to_name_table;
-static elf_flags_to_name_table elf_flags_to_names [] =
+static const elf_flags_to_name_table elf_flags_to_names [] =
{
{ "SHF_WRITE", SHF_WRITE },
{ "SHF_ALLOC", SHF_ALLOC },
ehdest->target_internal = ehsrc->target_internal;
isym.st_other = ehsrc->other;
- elf_merge_st_other (abfd, ehdest, &isym, NULL, TRUE, FALSE);
+ elf_merge_st_other (abfd, ehdest, isym.st_other, NULL, TRUE, FALSE);
}
/* Append a RELA relocation REL to section S in BFD. */