/* ELF linking support for BFD.
- Copyright (C) 1995-2016 Free Software Foundation, Inc.
+ Copyright (C) 1995-2017 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
#include "libiberty.h"
#include "objalloc.h"
#if BFD_SUPPORTS_PLUGINS
+#include "plugin-api.h"
#include "plugin.h"
#endif
struct elf_link_hash_table *htab = elf_hash_table (info);
/* This function may be called more than once. */
- s = bfd_get_linker_section (abfd, ".got");
- if (s != NULL)
+ if (htab->sgot != NULL)
return TRUE;
flags = bed->dynamic_sec_flags;
(SEC_ALLOC | SEC_LINKER_CREATED));
if (s == NULL)
return FALSE;
+ htab->sdynbss = s;
+
+ if (bed->want_dynrelro)
+ {
+ /* Similarly, but for symbols that were originally in read-only
+ sections. */
+ s = bfd_make_section_anyway_with_flags (abfd, ".data.rel.ro",
+ (SEC_ALLOC | SEC_READONLY
+ | SEC_HAS_CONTENTS
+ | SEC_LINKER_CREATED));
+ if (s == NULL)
+ return FALSE;
+ htab->sdynrelro = s;
+ }
/* The .rel[a].bss section holds copy relocs. This section is not
normally needed. We need to create it here, though, so that the
be needed, we can discard it later. We will never need this
section when generating a shared object, since they do not use
copy relocs. */
- if (! bfd_link_pic (info))
+ if (bfd_link_executable (info))
{
s = bfd_make_section_anyway_with_flags (abfd,
(bed->rela_plts_and_copies_p
if (s == NULL
|| ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
return FALSE;
+ htab->srelbss = s;
+
+ if (bed->want_dynrelro)
+ {
+ s = (bfd_make_section_anyway_with_flags
+ (abfd, (bed->rela_plts_and_copies_p
+ ? ".rela.data.rel.ro" : ".rel.data.rel.ro"),
+ flags | SEC_READONLY));
+ if (s == NULL
+ || ! bfd_set_section_alignment (abfd, s,
+ bed->s->log_file_align))
+ return FALSE;
+ htab->sreldynrelro = s;
+ }
}
}
if (h == NULL)
return provide;
+ if (h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
if (h->versioned == unknown)
{
/* Set versioned if symbol version is unknown. */
hv->root.u.i.link = (struct bfd_link_hash_entry *) h;
(*bed->elf_backend_copy_indirect_symbol) (info, h, hv);
break;
- case bfd_link_hash_warning:
- abort ();
- break;
+ default:
+ BFD_FAIL ();
+ return FALSE;
}
/* If this symbol is being provided by the linker script, and it is
for (p = elf_hash_table (info)->dynlocal; p ; p = p->next)
p->dynindx = ++dynsymcount;
}
+ elf_hash_table (info)->local_dynsymcount = dynsymcount;
elf_link_hash_traverse (elf_hash_table (info),
elf_link_renumber_hash_table_dynsyms,
}
if (tdef && ntdef)
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%s: TLS definition in %B section %A "
"mismatches non-TLS definition in %B section %A"),
tbfd, tsec, ntbfd, ntsec, h->root.root.string);
else if (!tdef && !ntdef)
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%s: TLS reference in %B "
"mismatches non-TLS reference in %B"),
tbfd, ntbfd, h->root.root.string);
else if (tdef)
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%s: TLS definition in %B section %A "
"mismatches non-TLS reference in %B"),
tbfd, tsec, ntbfd, h->root.root.string);
else
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%s: TLS reference in %B "
"mismatches non-TLS definition in %B section %A"),
tbfd, ntbfd, ntsec, h->root.root.string);
overridden by a versioned definition. */
if (hi->root.type != bfd_link_hash_defined
&& hi->root.type != bfd_link_hash_defweak)
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: unexpected redefinition of indirect versioned symbol `%s'"),
abfd, shortname);
}
{
/* We could not find the version for a symbol when
generating a shared archive. Return an error. */
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: version node not found for symbol %s"),
info->output_bfd, h->root.root.string);
bfd_set_error (bfd_error_bad_value);
{
if ((size_t) r_symndx >= nsyms)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: bad reloc symbol index (0x%lx >= 0x%lx)"
" for offset 0x%lx in section `%A'"),
abfd, sec,
}
else if (r_symndx != STN_UNDEF)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: non-zero symbol index (0x%lx) for offset 0x%lx in section `%A'"
" when the object file has no symbol table"),
abfd, sec,
}
else
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: relocation size mismatch in %B section %A"),
output_bfd, input_section->owner, input_section);
bfd_set_error (bfd_error_wrong_format);
&& (h->root.u.def.section->owner->flags & (DYNAMIC | BFD_PLUGIN)) == 0)
h->def_regular = 1;
+ /* If a weak undefined symbol has non-default visibility, we also
+ hide it from the dynamic linker. */
+ if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+ && h->root.type == bfd_link_hash_undefweak)
+ (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE);
+
+ /* A hidden versioned symbol in executable should be forced local if
+ it is is locally defined, not referenced by shared library and not
+ exported. */
+ else if (bfd_link_executable (eif->info)
+ && h->versioned == versioned_hidden
+ && !eif->info->export_dynamic
+ && !h->dynamic
+ && !h->ref_dynamic
+ && h->def_regular)
+ (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE);
+
/* If -Bsymbolic was used (which means to bind references to global
symbols to the definition within the shared object), and this
symbol was defined in a regular object, then it actually doesn't
need a PLT entry. Likewise, if the symbol has non-default
visibility. If the symbol has hidden or internal visibility, we
will force it local. */
- if (h->needs_plt
- && bfd_link_pic (eif->info)
- && is_elf_hash_table (eif->info->hash)
- && (SYMBOLIC_BIND (eif->info, h)
- || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
- && h->def_regular)
+ else if (h->needs_plt
+ && bfd_link_pic (eif->info)
+ && is_elf_hash_table (eif->info->hash)
+ && (SYMBOLIC_BIND (eif->info, h)
+ || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+ && h->def_regular)
{
bfd_boolean force_local;
(*bed->elf_backend_hide_symbol) (eif->info, h, force_local);
}
- /* If a weak undefined symbol has non-default visibility, we also
- hide it from the dynamic linker. */
- if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
- && h->root.type == bfd_link_hash_undefweak)
- (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE);
-
/* If this is a weak defined symbol in a dynamic object, and we know
the real definition in the dynamic object, copy interesting flags
over to the real definition. */
if (h->size == 0
&& h->type == STT_NOTYPE
&& !h->needs_plt)
- (*_bfd_error_handler)
+ _bfd_error_handler
(_("warning: type and size of dynamic symbol `%s' are not defined"),
h->root.root.string);
|| (bed->elf_machine_alt2 != 0
&& ehdr->e_machine == bed->elf_machine_alt2)))
info->callbacks->einfo
+ /* xgettext:c-format */
(_("%P: alternate ELF machine code found (%d) in %B, expecting %d\n"),
ehdr->e_machine, abfd, bed->elf_machine_code);
const char *soname = NULL;
char *audit = NULL;
struct bfd_link_needed_list *rpath = NULL, *runpath = NULL;
+ const Elf_Internal_Phdr *phdr;
int ret;
/* ld --just-symbols and dynamic objects don't mix very well.
*pn = rpath;
}
+ /* If we have a PT_GNU_RELRO program header, mark as read-only
+ all sections contained fully therein. This makes relro
+ shared library sections appear as they will at run-time. */
+ phdr = elf_tdata (abfd)->phdr + elf_elfheader (abfd)->e_phnum;
+ while (--phdr >= elf_tdata (abfd)->phdr)
+ if (phdr->p_type == PT_GNU_RELRO)
+ {
+ for (s = abfd->sections; s != NULL; s = s->next)
+ if ((s->flags & SEC_ALLOC) != 0
+ && s->vma >= phdr->p_vaddr
+ && s->vma + s->size <= phdr->p_vaddr + phdr->p_memsz)
+ s->flags |= SEC_READONLY;
+ break;
+ }
+
/* We do not want to include any of the sections in a dynamic
object in the output file. We hack by simply clobbering the
list of sections in the BFD. This could be handled more
if (verstr == NULL)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: %s: invalid version %u (max %d)"),
abfd, name, vernum,
elf_tdata (abfd)->cverdefs);
}
if (verstr == NULL)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: %s: invalid needed version %d"),
abfd, name, vernum);
bfd_set_error (bfd_error_bad_value);
{
/* PR binutils/2735 */
if (normal_bfd == NULL)
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("Warning: alignment %u of common symbol `%s' in %B is"
" greater than the alignment (%u) of its section %A"),
common_bfd, h->root.u.def.section,
1 << common_align, name, 1 << normal_align);
else
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("Warning: alignment %u of symbol `%s' in %B"
" is smaller than %u in %B"),
normal_bfd, common_bfd,
if (h->size != 0
&& h->size != isym->st_size
&& ! size_change_ok)
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("Warning: size of symbol `%s' changed"
" from %lu in %B to %lu in %B"),
old_bfd, abfd,
if (h->type != type)
{
if (h->type != STT_NOTYPE && ! type_change_ok)
- (*_bfd_error_handler)
+ /* xgettext:c-format */
+ _bfd_error_handler
(_("Warning: type of symbol `%s' changed"
" from %d to %d in %B"),
abfd, name, h->type, type);
if (old_bfd != NULL
&& (elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: undefined reference to symbol '%s'"),
old_bfd, name);
bfd_set_error (bfd_error_missing_dso);
/* The symbol has no type if specified on the command line. */
h->type = STT_OBJECT;
if (info->stacksize)
- (*_bfd_error_handler) (_("%B: stack size specified and %s set"),
- output_bfd, legacy_symbol);
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%B: stack size specified and %s set"),
+ output_bfd, legacy_symbol);
else if (h->root.u.def.section != bfd_abs_section_ptr)
- (*_bfd_error_handler) (_("%B: %s not absolute"),
- output_bfd, legacy_symbol);
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%B: %s not absolute"),
+ output_bfd, legacy_symbol);
else
info->stacksize = h->root.u.def.value;
}
for (d = t->globals.list; d != NULL; d = d->next)
if (d->literal && !d->symver && !d->script)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
(_("%s: undefined version: %s"),
d->pattern, t->name);
all_defined = FALSE;
if (elf_section_data (o)->this_hdr.sh_type
== SHT_PREINIT_ARRAY)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
(_("%B: .preinit_array section is not allowed in DSO"),
sub);
break;
struct elf_link_hash_table *htab;
/* Copy down any references that we may have already seen to the
- symbol which just became indirect if DIR isn't a hidden versioned
- symbol. */
+ symbol which just became indirect. */
if (dir->versioned != versioned_hidden)
- {
- dir->ref_dynamic |= ind->ref_dynamic;
- dir->ref_regular |= ind->ref_regular;
- dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
- dir->non_got_ref |= ind->non_got_ref;
- dir->needs_plt |= ind->needs_plt;
- dir->pointer_equality_needed |= ind->pointer_equality_needed;
- }
+ dir->ref_dynamic |= ind->ref_dynamic;
+ dir->ref_regular |= ind->ref_regular;
+ dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
+ dir->non_got_ref |= ind->non_got_ref;
+ dir->needs_plt |= ind->needs_plt;
+ dir->pointer_equality_needed |= ind->pointer_equality_needed;
if (ind->root.type != bfd_link_hash_indirect)
return;
static void
undefined_reference (const char *reftype, const char *name)
{
+ /* xgettext:c-format */
_bfd_error_handler (_("undefined %s reference in complex symbol: %s"),
reftype, name);
}
case 'S':
symbol_is_section = TRUE;
+ /* Fall through. */
case 's':
++sym;
symlen = strtol (sym, (char **) symp, 10);
static bfd_boolean
elf_link_adjust_relocs (bfd *abfd,
+ asection *sec,
struct bfd_elf_section_reloc_data *reldata,
bfd_boolean sort)
{
(*swap_out) (abfd, irela, erela);
}
+ if (bed->elf_backend_update_relocs)
+ (*bed->elf_backend_update_relocs) (sec, reldata);
+
if (sort && count != 0)
{
bfd_vma (*ext_r_off) (const void *);
{
/* The gABI doesn't support dynamic symbols in output sections
beyond 64k. */
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: Too many sections: %d (>= %d)"),
abfd, bfd_count_sections (abfd), SHN_LORESERVE & 0xffff);
bfd_set_error (bfd_error_nonrepresentable_section);
case bfd_link_hash_undefined:
case bfd_link_hash_undefweak:
abfd = h->root.u.undef.abfd;
- if ((abfd->flags & DYNAMIC) == 0
+ if (abfd == NULL
+ || (abfd->flags & DYNAMIC) == 0
|| (elf_dyn_lib_class (abfd) & DYN_DT_NEEDED) == 0)
return FALSE;
break;
long indx;
int ret;
unsigned int type;
- /* A symbol is bound locally if it is forced local or it is locally
- defined, hidden versioned, not referenced by shared library and
- not exported when linking executable. */
- bfd_boolean local_bind = (h->forced_local
- || (bfd_link_executable (flinfo->info)
- && !flinfo->info->export_dynamic
- && !h->dynamic
- && !h->ref_dynamic
- && h->def_regular
- && h->versioned == versioned_hidden));
if (h->root.type == bfd_link_hash_warning)
{
/* Decide whether to output this symbol in this pass. */
if (eoinfo->localsyms)
{
- if (!local_bind)
+ if (!h->forced_local)
return TRUE;
}
else
{
- if (local_bind)
+ if (h->forced_local)
return TRUE;
}
hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL)
+ /* xgettext:c-format */
msg = _("%B: internal symbol `%s' in %B is referenced by DSO");
else if (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
+ /* xgettext:c-format */
msg = _("%B: hidden symbol `%s' in %B is referenced by DSO");
else
+ /* xgettext:c-format */
msg = _("%B: local symbol `%s' in %B is referenced by DSO");
def_bfd = flinfo->output_bfd;
if (hi->root.u.def.section != bfd_abs_section_ptr)
def_bfd = hi->root.u.def.section->owner;
- (*_bfd_error_handler) (msg, flinfo->output_bfd, def_bfd,
- h->root.root.string);
+ _bfd_error_handler (msg, flinfo->output_bfd, def_bfd,
+ h->root.root.string);
bfd_set_error (bfd_error_bad_value);
eoinfo->failed = TRUE;
return FALSE;
input_sec->output_section);
if (sym.st_shndx == SHN_BAD)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: could not find output section %A for input section %A"),
flinfo->output_bfd, input_sec->output_section, input_sec);
bfd_set_error (bfd_error_nonrepresentable_section);
abort ();
}
- if (local_bind)
+ if (h->forced_local)
{
sym.st_info = ELF_ST_INFO (STB_LOCAL, type);
/* Turn off visibility on local symbol. */
const char *msg;
if (ELF_ST_VISIBILITY (sym.st_other) == STV_PROTECTED)
+ /* xgettext:c-format */
msg = _("%B: protected symbol `%s' isn't defined");
else if (ELF_ST_VISIBILITY (sym.st_other) == STV_INTERNAL)
+ /* xgettext:c-format */
msg = _("%B: internal symbol `%s' isn't defined");
else
+ /* xgettext:c-format */
msg = _("%B: hidden symbol `%s' isn't defined");
- (*_bfd_error_handler) (msg, flinfo->output_bfd, h->root.root.string);
+ _bfd_error_handler (msg, flinfo->output_bfd, h->root.root.string);
bfd_set_error (bfd_error_bad_value);
eoinfo->failed = TRUE;
return FALSE;
/* Since there is no version information in the dynamic string,
if there is no version info in symbol version section, we will
have a run-time problem if not linking executable, referenced
- by shared library, not locally defined, or not bound locally.
- */
+ by shared library, or not bound locally. */
if (h->verinfo.verdef == NULL
- && !local_bind
&& (!bfd_link_executable (flinfo->info)
|| h->ref_dynamic
|| !h->def_regular))
if (p && p [1] != '\0')
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: No symbol version section for versioned symbol `%s'"),
flinfo->output_bfd, h->root.root.string);
eoinfo->failed = TRUE;
{
if (o->size != o->reloc_count * address_size)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("error: %B: size of section %A is not "
"multiple of address size"),
input_bfd, o);
char buffer [32];
sprintf_vma (buffer, rel->r_info);
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("error: %B contains a reloc (0x%s) for section %A "
"that references a non-existent global symbol"),
input_bfd, o, buffer);
BFD_ASSERT (r_symndx != STN_UNDEF);
if (action_discarded & COMPLAIN)
(*flinfo->info->callbacks->einfo)
+ /* xgettext:c-format */
(_("%X`%s' referenced in section `%A' of %B: "
"defined in discarded section `%A' of %B\n"),
sym_name, o, input_bfd, sec, sec->owner);
= get_elf_backend_data (s->owner);
if (bed->link_order_error_handler)
bed->link_order_error_handler
+ /* xgettext:c-format */
(_("%B: warning: sh_link not set for section `%A'"), s->owner, s);
return 0;
}
if (seen_other && seen_linkorder)
{
if (other_sec && linkorder_sec)
- (*_bfd_error_handler) (_("%A has both ordered [`%A' in %B] and unordered [`%A' in %B] sections"),
- o, linkorder_sec,
- linkorder_sec->owner, other_sec,
- other_sec->owner);
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("%A has both ordered [`%A' in %B] "
+ "and unordered [`%A' in %B] sections"),
+ o, linkorder_sec,
+ linkorder_sec->owner, other_sec,
+ other_sec->owner);
else
- (*_bfd_error_handler) (_("%A has both ordered and unordered sections"),
- o);
+ _bfd_error_handler
+ (_("%A has both ordered and unordered sections"), o);
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
return TRUE;
}
+/* Generate an import library in INFO->implib_bfd from symbols in ABFD.
+ Returns TRUE upon success, FALSE otherwise. */
+
+static bfd_boolean
+elf_output_implib (bfd *abfd, struct bfd_link_info *info)
+{
+ bfd_boolean ret = FALSE;
+ bfd *implib_bfd;
+ const struct elf_backend_data *bed;
+ flagword flags;
+ enum bfd_architecture arch;
+ unsigned int mach;
+ asymbol **sympp = NULL;
+ long symsize;
+ long symcount;
+ long src_count;
+ elf_symbol_type *osymbuf;
+
+ implib_bfd = info->out_implib_bfd;
+ bed = get_elf_backend_data (abfd);
+
+ if (!bfd_set_format (implib_bfd, bfd_object))
+ return FALSE;
+
+ flags = bfd_get_file_flags (abfd);
+ flags &= ~HAS_RELOC;
+ if (!bfd_set_start_address (implib_bfd, 0)
+ || !bfd_set_file_flags (implib_bfd, flags))
+ return FALSE;
+
+ /* Copy architecture of output file to import library file. */
+ arch = bfd_get_arch (abfd);
+ mach = bfd_get_mach (abfd);
+ if (!bfd_set_arch_mach (implib_bfd, arch, mach)
+ && (abfd->target_defaulted
+ || bfd_get_arch (abfd) != bfd_get_arch (implib_bfd)))
+ return FALSE;
+
+ /* Get symbol table size. */
+ symsize = bfd_get_symtab_upper_bound (abfd);
+ if (symsize < 0)
+ return FALSE;
+
+ /* Read in the symbol table. */
+ sympp = (asymbol **) xmalloc (symsize);
+ symcount = bfd_canonicalize_symtab (abfd, sympp);
+ if (symcount < 0)
+ goto free_sym_buf;
+
+ /* Allow the BFD backend to copy any private header data it
+ understands from the output BFD to the import library BFD. */
+ if (! bfd_copy_private_header_data (abfd, implib_bfd))
+ goto free_sym_buf;
+
+ /* Filter symbols to appear in the import library. */
+ if (bed->elf_backend_filter_implib_symbols)
+ symcount = bed->elf_backend_filter_implib_symbols (abfd, info, sympp,
+ symcount);
+ else
+ symcount = _bfd_elf_filter_global_symbols (abfd, info, sympp, symcount);
+ if (symcount == 0)
+ {
+ bfd_set_error (bfd_error_no_symbols);
+ _bfd_error_handler (_("%B: no symbol found for import library"),
+ implib_bfd);
+ goto free_sym_buf;
+ }
+
+
+ /* Make symbols absolute. */
+ osymbuf = (elf_symbol_type *) bfd_alloc2 (implib_bfd, symcount,
+ sizeof (*osymbuf));
+ for (src_count = 0; src_count < symcount; src_count++)
+ {
+ memcpy (&osymbuf[src_count], (elf_symbol_type *) sympp[src_count],
+ sizeof (*osymbuf));
+ osymbuf[src_count].symbol.section = bfd_abs_section_ptr;
+ osymbuf[src_count].internal_elf_sym.st_shndx = SHN_ABS;
+ osymbuf[src_count].symbol.value += sympp[src_count]->section->vma;
+ osymbuf[src_count].internal_elf_sym.st_value =
+ osymbuf[src_count].symbol.value;
+ sympp[src_count] = &osymbuf[src_count].symbol;
+ }
+
+ bfd_set_symtab (implib_bfd, sympp, symcount);
+
+ /* Allow the BFD backend to copy any private data it understands
+ from the output BFD to the import library BFD. This is done last
+ to permit the routine to look at the filtered symbol table. */
+ if (! bfd_copy_private_bfd_data (abfd, implib_bfd))
+ goto free_sym_buf;
+
+ if (!bfd_close (implib_bfd))
+ goto free_sym_buf;
+
+ ret = TRUE;
+
+free_sym_buf:
+ free (sympp);
+ return ret;
+}
+
static void
elf_final_link_free (bfd *obfd, struct elf_final_link_info *flinfo)
{
asection *attr_section = NULL;
bfd_vma attr_size = 0;
const char *std_attrs_section;
+ struct elf_link_hash_table *htab = elf_hash_table (info);
- if (! is_elf_hash_table (info->hash))
+ if (!is_elf_hash_table (htab))
return FALSE;
if (bfd_link_pic (info))
abfd->flags |= DYNAMIC;
- dynamic = elf_hash_table (info)->dynamic_sections_created;
- dynobj = elf_hash_table (info)->dynobj;
+ dynamic = htab->dynamic_sections_created;
+ dynobj = htab->dynobj;
emit_relocs = (bfd_link_relocatable (info)
|| info->emitrelocations);
asection *sec;
sec = p->u.indirect.section;
- esdi = elf_section_data (sec);
/* Mark all sections which are to be included in the
link. This will normally be every section. We need
if (sec->flags & SEC_MERGE)
merged = TRUE;
- if (esdo->this_hdr.sh_type == SHT_REL
- || esdo->this_hdr.sh_type == SHT_RELA)
- /* Some backends use reloc_count in relocation sections
- to count particular types of relocs. Of course,
- reloc sections themselves can't have relocations. */
- reloc_count = 0;
- else if (emit_relocs)
- {
- reloc_count = sec->reloc_count;
- if (bed->elf_backend_count_additional_relocs)
- {
- int c;
- c = (*bed->elf_backend_count_additional_relocs) (sec);
- additional_reloc_count += c;
- }
- }
- else if (bed->elf_backend_count_relocs)
- reloc_count = (*bed->elf_backend_count_relocs) (info, sec);
-
if (sec->rawsize > max_contents_size)
max_contents_size = sec->rawsize;
if (sec->size > max_contents_size)
max_contents_size = sec->size;
- /* We are interested in just local symbols, not all
- symbols. */
if (bfd_get_flavour (sec->owner) == bfd_target_elf_flavour
&& (sec->owner->flags & DYNAMIC) == 0)
{
size_t sym_count;
+ /* We are interested in just local symbols, not all
+ symbols. */
if (elf_bad_symtab (sec->owner))
sym_count = (elf_tdata (sec->owner)->symtab_hdr.sh_size
/ bed->s->sizeof_sym);
&& elf_symtab_shndx_list (sec->owner) != NULL)
max_sym_shndx_count = sym_count;
+ if (esdo->this_hdr.sh_type == SHT_REL
+ || esdo->this_hdr.sh_type == SHT_RELA)
+ /* Some backends use reloc_count in relocation sections
+ to count particular types of relocs. Of course,
+ reloc sections themselves can't have relocations. */
+ ;
+ else if (emit_relocs)
+ {
+ reloc_count = sec->reloc_count;
+ if (bed->elf_backend_count_additional_relocs)
+ {
+ int c;
+ c = (*bed->elf_backend_count_additional_relocs) (sec);
+ additional_reloc_count += c;
+ }
+ }
+ else if (bed->elf_backend_count_relocs)
+ reloc_count = (*bed->elf_backend_count_relocs) (info, sec);
+
+ esdi = elf_section_data (sec);
+
if ((sec->flags & SEC_RELOC) != 0)
{
size_t ext_size = 0;
}
if (! bfd_link_relocatable (info) && merged)
- elf_link_hash_traverse (elf_hash_table (info),
- _bfd_elf_link_sec_merge_syms, abfd);
+ elf_link_hash_traverse (htab, _bfd_elf_link_sec_merge_syms, abfd);
/* Figure out the file positions for everything but the symbol table
and the relocs. We set symcount to force assign_section_numbers
if (max_sym_count < 20)
max_sym_count = 20;
- elf_hash_table (info)->strtabsize = max_sym_count;
+ htab->strtabsize = max_sym_count;
amt = max_sym_count * sizeof (struct elf_sym_strtab);
- elf_hash_table (info)->strtab
- = (struct elf_sym_strtab *) bfd_malloc (amt);
- if (elf_hash_table (info)->strtab == NULL)
+ htab->strtab = (struct elf_sym_strtab *) bfd_malloc (amt);
+ if (htab->strtab == NULL)
goto error_return;
/* The real buffer will be allocated in elf_link_swap_symbols_out. */
flinfo.symshndxbuf
goto error_return;
}
- if (elf_hash_table (info)->tls_sec)
+ if (htab->tls_sec)
{
bfd_vma base, end = 0;
asection *sec;
- for (sec = elf_hash_table (info)->tls_sec;
+ for (sec = htab->tls_sec;
sec && (sec->flags & SEC_THREAD_LOCAL);
sec = sec->next)
{
}
end = sec->vma + size;
}
- base = elf_hash_table (info)->tls_sec->vma;
+ base = htab->tls_sec->vma;
/* Only align end of TLS section if static TLS doesn't have special
alignment requirements. */
if (bed->static_tls_alignment == 1)
- end = align_power (end,
- elf_hash_table (info)->tls_sec->alignment_power);
- elf_hash_table (info)->tls_size = end - base;
+ end = align_power (end, htab->tls_sec->alignment_power);
+ htab->tls_size = end - base;
}
/* Reorder SHF_LINK_ORDER sections. */
}
bfd_set_error (bfd_error_wrong_format);
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B: file class %s incompatible with %s"),
sub, iclass, oclass);
}
symtab_hdr->sh_info = bfd_get_symcount (abfd);
if (dynamic
- && elf_hash_table (info)->dynsym != NULL
- && (elf_hash_table (info)->dynsym->output_section
- != bfd_abs_section_ptr))
+ && htab->dynsym != NULL
+ && htab->dynsym->output_section != bfd_abs_section_ptr)
{
Elf_Internal_Sym sym;
- bfd_byte *dynsym = elf_hash_table (info)->dynsym->contents;
- long last_local = 0;
+ bfd_byte *dynsym = htab->dynsym->contents;
+
+ o = htab->dynsym->output_section;
+ elf_section_data (o)->this_hdr.sh_info = htab->local_dynsymcount + 1;
/* Write out the section symbols for the output sections. */
if (bfd_link_pic (info)
- || elf_hash_table (info)->is_relocatable_executable)
+ || htab->is_relocatable_executable)
{
asection *s;
return FALSE;
sym.st_value = s->vma;
dest = dynsym + dynindx * bed->s->sizeof_sym;
- if (last_local < dynindx)
- last_local = dynindx;
bed->s->swap_symbol_out (abfd, &sym, dest, 0);
}
}
/* Write out the local dynsyms. */
- if (elf_hash_table (info)->dynlocal)
+ if (htab->dynlocal)
{
struct elf_link_local_dynamic_entry *e;
- for (e = elf_hash_table (info)->dynlocal; e ; e = e->next)
+ for (e = htab->dynlocal; e ; e = e->next)
{
asection *s;
bfd_byte *dest;
+ e->isym.st_value);
}
- if (last_local < e->dynindx)
- last_local = e->dynindx;
-
dest = dynsym + e->dynindx * bed->s->sizeof_sym;
bed->s->swap_symbol_out (abfd, &sym, dest, 0);
}
}
-
- elf_section_data (elf_hash_table (info)->dynsym->output_section)->this_hdr.sh_info =
- last_local + 1;
}
/* We get the global symbols from the hash table. */
return FALSE;
}
+ if (info->out_implib_bfd && !elf_output_implib (abfd, info))
+ {
+ _bfd_error_handler (_("%B: failed to generate import library"),
+ info->out_implib_bfd);
+ return FALSE;
+ }
+
/* Adjust the relocs to have the correct symbol indices. */
for (o = abfd->sections; o != NULL; o = o->next)
{
sort = bed->sort_relocs_p == NULL || (*bed->sort_relocs_p) (o);
if (esdo->rel.hdr != NULL
- && !elf_link_adjust_relocs (abfd, &esdo->rel, sort))
+ && !elf_link_adjust_relocs (abfd, o, &esdo->rel, sort))
return FALSE;
if (esdo->rela.hdr != NULL
- && !elf_link_adjust_relocs (abfd, &esdo->rela, sort))
+ && !elf_link_adjust_relocs (abfd, o, &esdo->rela, sort))
return FALSE;
/* Set the reloc_count field to 0 to prevent write_relocs from
{
struct elf_link_hash_entry *h;
- h = elf_link_hash_lookup (elf_hash_table (info), name,
- FALSE, FALSE, TRUE);
+ h = elf_link_hash_lookup (htab, name, FALSE, FALSE, TRUE);
if (h != NULL
&& (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak))
o = bfd_get_section_by_name (abfd, name);
if (o == NULL)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
(_("could not find section %s"), name);
goto error_return;
}
if (o->size == 0)
- (*_bfd_error_handler)
+ _bfd_error_handler
(_("warning: %s section has zero size"), name);
dyn.d_un.d_val = o->size;
break;
do_vma:
if (o == NULL)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
(_("could not find section %s"), name);
goto error_return;
}
if (elf_section_data (o->output_section)->this_hdr.sh_type == SHT_NOTE)
{
- (*_bfd_error_handler)
+ _bfd_error_handler
(_("warning: section '%s' is being made into a note"), name);
bfd_set_error (bfd_error_nonrepresentable_section);
goto error_return;
}
}
}
+ if (bed->dtrel_excludes_plt && htab->srelplt != NULL)
+ {
+ /* Don't count procedure linkage table relocs in the
+ overall reloc count. */
+ if (dyn.d_tag == DT_RELSZ || dyn.d_tag == DT_RELASZ)
+ dyn.d_un.d_val -= htab->srelplt->size;
+ /* If .rela.plt is the first .rela section, exclude
+ it from DT_RELA. */
+ else if (dyn.d_un.d_ptr == (htab->srelplt->output_section->vma
+ + htab->srelplt->output_offset))
+ dyn.d_un.d_ptr += htab->srelplt->size;
+ }
break;
}
bed->s->swap_dyn_out (dynobj, &dyn, dyncon);
created by _bfd_elf_link_create_dynamic_sections. */
continue;
}
- if (elf_hash_table (info)->stab_info.stabstr == o)
+ if (htab->stab_info.stabstr == o)
continue;
- if (elf_hash_table (info)->eh_info.hdr_sec == o)
+ if (htab->eh_info.hdr_sec == o)
continue;
if (strcmp (o->name, ".dynstr") != 0)
{
off = elf_section_data (o->output_section)->this_hdr.sh_offset;
if (bfd_seek (abfd, off, SEEK_SET) != 0
- || ! _bfd_elf_strtab_emit (abfd,
- elf_hash_table (info)->dynstr))
+ || !_bfd_elf_strtab_emit (abfd, htab->dynstr))
goto error_return;
}
}
}
/* If we have optimized stabs strings, output them. */
- if (elf_hash_table (info)->stab_info.stabstr != NULL)
+ if (htab->stab_info.stabstr != NULL)
{
- if (! _bfd_write_stab_strings (abfd, &elf_hash_table (info)->stab_info))
+ if (!_bfd_write_stab_strings (abfd, &htab->stab_info))
goto error_return;
}
o->flags |= SEC_EXCLUDE;
if (info->print_gc_sections && o->size != 0)
+ /* xgettext:c-format */
_bfd_error_handler (_("Removing unused section '%s' in file '%B'"), sub, o->name);
/* But we also have to update some of the relocation
&& ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
&& ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
&& (!bfd_link_executable (info)
+ || info->gc_keep_exported
|| info->export_dynamic
|| (h->dynamic
&& d != NULL
if (h != NULL
&& (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
- && !bfd_is_abs_section (h->root.u.def.section))
+ && !bfd_is_abs_section (h->root.u.def.section)
+ && !bfd_is_und_section (h->root.u.def.section))
h->root.u.def.section->flags |= SEC_KEEP;
}
}
if (!bed->can_gc_sections
|| !is_elf_hash_table (info->hash))
{
- (*_bfd_error_handler)(_("Warning: gc-sections option ignored"));
+ _bfd_error_handler(_("Warning: gc-sections option ignored"));
return TRUE;
}
return FALSE;
/* Mark dynamically referenced symbols. */
- if (htab->dynamic_sections_created)
+ if (htab->dynamic_sections_created || info->gc_keep_exported)
elf_link_hash_traverse (htab, bed->gc_mark_dynamic_ref, info);
/* Grovel through relocs to find out who stays ... */
goto win;
}
- (*_bfd_error_handler) ("%B: %A+%lu: No symbol found for INHERIT",
- abfd, sec, (unsigned long) offset);
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%B: %A+%lu: No symbol found for INHERIT"),
+ abfd, sec, (unsigned long) offset);
bfd_set_error (bfd_error_invalid_operation);
return FALSE;