static bfd_boolean _bfd_elf_fix_symbol_flags
(struct elf_link_hash_entry *, struct elf_info_failed *);
+asection *
+_bfd_elf_section_for_symbol (struct elf_reloc_cookie *cookie,
+ unsigned long r_symndx,
+ bfd_boolean discard)
+{
+ if (r_symndx >= cookie->locsymcount
+ || ELF_ST_BIND (cookie->locsyms[r_symndx].st_info) != STB_LOCAL)
+ {
+ struct elf_link_hash_entry *h;
+
+ h = cookie->sym_hashes[r_symndx - cookie->extsymoff];
+
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ if ((h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ && discarded_section (h->root.u.def.section))
+ return h->root.u.def.section;
+ else
+ return NULL;
+ }
+ else
+ {
+ /* It's not a relocation against a global symbol,
+ but it could be a relocation against a local
+ symbol for a discarded section. */
+ asection *isec;
+ Elf_Internal_Sym *isym;
+
+ /* Need to: get the symbol; get the section. */
+ isym = &cookie->locsyms[r_symndx];
+ isec = bfd_section_from_elf_index (cookie->abfd, isym->st_shndx);
+ if (isec != NULL
+ && discard ? discarded_section (isec) : 1)
+ return isec;
+ }
+ return NULL;
+}
+
/* Define a symbol in a dynamic linkage section. */
struct elf_link_hash_entry *
static void
elf_merge_st_other (bfd *abfd, struct elf_link_hash_entry *h,
- const Elf_Internal_Sym *isym,
+ const Elf_Internal_Sym *isym, asection *sec,
bfd_boolean definition, bfd_boolean dynamic)
{
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
if (symvis - 1 < hvis - 1)
h->other = symvis | (h->other & ~ELF_ST_VISIBILITY (-1));
}
- else if (definition && ELF_ST_VISIBILITY (isym->st_other) != STV_DEFAULT)
+ else if (definition
+ && ELF_ST_VISIBILITY (isym->st_other) != STV_DEFAULT
+ && (sec->flags & SEC_READONLY) == 0)
h->protected_def = 1;
}
bfd_boolean *skip,
bfd_boolean *override,
bfd_boolean *type_change_ok,
- bfd_boolean *size_change_ok)
+ bfd_boolean *size_change_ok,
+ bfd_boolean *matched)
{
asection *sec, *oldsec;
struct elf_link_hash_entry *h;
bfd_boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon;
bfd_boolean newweak, oldweak, newfunc, oldfunc;
const struct elf_backend_data *bed;
+ char *new_version;
*skip = FALSE;
*override = FALSE;
bed = get_elf_backend_data (abfd);
+ /* NEW_VERSION is the symbol version of the new symbol. */
+ if (h->versioned != unversioned)
+ {
+ /* Symbol version is unknown or versioned. */
+ new_version = strrchr (name, ELF_VER_CHR);
+ if (new_version)
+ {
+ if (h->versioned == unknown)
+ {
+ if (new_version > name && new_version[-1] != ELF_VER_CHR)
+ h->versioned = versioned_hidden;
+ else
+ h->versioned = versioned;
+ }
+ new_version += 1;
+ if (new_version[0] == '\0')
+ new_version = NULL;
+ }
+ else
+ h->versioned = unversioned;
+ }
+ else
+ new_version = NULL;
+
/* For merging, we only care about real symbols. But we need to make
sure that indirect symbol dynamic flags are updated. */
hi = h;
|| h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ if (!*matched)
+ {
+ if (hi == h || h->root.type == bfd_link_hash_new)
+ *matched = TRUE;
+ else
+ {
+ /* OLD_HIDDEN is true if the existing symbol is only visibile
+ to the symbol with the same symbol version. NEW_HIDDEN is
+ true if the new symbol is only visibile to the symbol with
+ the same symbol version. */
+ bfd_boolean old_hidden = h->versioned == versioned_hidden;
+ bfd_boolean new_hidden = hi->versioned == versioned_hidden;
+ if (!old_hidden && !new_hidden)
+ /* The new symbol matches the existing symbol if both
+ aren't hidden. */
+ *matched = TRUE;
+ else
+ {
+ /* OLD_VERSION is the symbol version of the existing
+ symbol. */
+ char *old_version;
+
+ if (h->versioned >= versioned)
+ old_version = strrchr (h->root.root.string,
+ ELF_VER_CHR) + 1;
+ else
+ old_version = NULL;
+
+ /* The new symbol matches the existing symbol if they
+ have the same symbol version. */
+ *matched = (old_version == new_version
+ || (old_version != NULL
+ && new_version != NULL
+ && strcmp (old_version, new_version) == 0));
+ }
+ }
+ }
+
/* OLDBFD and OLDSEC are a BFD and an ASECTION associated with the
existing symbol. */
}
else
{
- h->dynamic_def = 1;
+ /* Update the existing symbol only if they match. */
+ if (*matched)
+ h->dynamic_def = 1;
hi->dynamic_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, newdef, newdyn);
+ elf_merge_st_other (abfd, h, sym, sec, newdef, newdyn);
if (h->dynindx != -1)
switch (ELF_ST_VISIBILITY (h->other))
{
char *p;
size_t len, shortlen;
asection *tmp_sec;
+ bfd_boolean matched;
+
+ if (h->versioned == unversioned || h->versioned == versioned_hidden)
+ return TRUE;
/* If this symbol has a version, and it is the default version, we
create an indirect symbol from the default name to the fully
decorated name. This will cause external references which do not
specify a version to be bound to this version of the symbol. */
p = strchr (name, ELF_VER_CHR);
- if (p == NULL || p[1] != ELF_VER_CHR)
- return TRUE;
+ if (h->versioned == unknown)
+ {
+ if (p == NULL)
+ {
+ h->versioned = unversioned;
+ return TRUE;
+ }
+ else
+ {
+ if (p[1] != ELF_VER_CHR)
+ {
+ h->versioned = versioned_hidden;
+ return TRUE;
+ }
+ else
+ h->versioned = versioned;
+ }
+ }
bed = get_elf_backend_data (abfd);
collect = bed->collect;
actually going to define an indirect symbol. */
type_change_ok = FALSE;
size_change_ok = FALSE;
+ matched = TRUE;
tmp_sec = sec;
if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &tmp_sec, &value,
&hi, poldbfd, NULL, NULL, &skip, &override,
- &type_change_ok, &size_change_ok))
+ &type_change_ok, &size_change_ok, &matched))
return FALSE;
if (skip)
if (! override)
{
- bh = &hi->root;
- if (! (_bfd_generic_link_add_one_symbol
- (info, abfd, shortname, BSF_INDIRECT, bfd_ind_section_ptr,
- 0, name, FALSE, collect, &bh)))
- return FALSE;
- hi = (struct elf_link_hash_entry *) bh;
+ /* Add the default symbol if not performing a relocatable link. */
+ if (! info->relocatable)
+ {
+ bh = &hi->root;
+ if (! (_bfd_generic_link_add_one_symbol
+ (info, abfd, shortname, BSF_INDIRECT,
+ bfd_ind_section_ptr,
+ 0, name, FALSE, collect, &bh)))
+ return FALSE;
+ hi = (struct elf_link_hash_entry *) bh;
+ }
}
else
{
tmp_sec = sec;
if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &tmp_sec, &value,
&hi, poldbfd, NULL, NULL, &skip, &override,
- &type_change_ok, &size_change_ok))
+ &type_change_ok, &size_change_ok, &matched))
return FALSE;
if (skip)
if (p != NULL && h->verinfo.vertree == NULL)
{
struct bfd_elf_version_tree *t;
- bfd_boolean hidden;
- hidden = TRUE;
-
- /* There are two consecutive ELF_VER_CHR characters if this is
- not a hidden symbol. */
++p;
if (*p == ELF_VER_CHR)
- {
- hidden = FALSE;
- ++p;
- }
+ ++p;
/* If there is no version string, we can just return out. */
if (*p == '\0')
- {
- if (hidden)
- h->hidden = 1;
- return TRUE;
- }
+ return TRUE;
/* Look for the version. If we find it, it is no longer weak. */
for (t = sinfo->info->version_info; t != NULL; t = t->next)
sinfo->failed = TRUE;
return FALSE;
}
-
- if (hidden)
- h->hidden = 1;
}
/* If we don't have a version for this symbol, see if we can find
/* No error if extern_protected_data is true. */
if (h->protected_def
- && !get_elf_backend_data (dynbss->owner)->extern_protected_data)
- {
- info->callbacks->einfo
- (_("%P: copy reloc against protected `%T' is invalid\n"),
- h->root.root.string);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
- }
+ && (!info->extern_protected_data
+ || (info->extern_protected_data < 0
+ && !get_elf_backend_data (dynbss->owner)->extern_protected_data)))
+ info->callbacks->einfo
+ (_("%P: copy reloc against protected `%T' is dangerous\n"),
+ h->root.root.string);
return TRUE;
}
/* If extern_protected_data is false, STV_PROTECTED non-function
symbols are local. */
- if (!bed->extern_protected_data && !bed->is_function_type (h->type))
+ if ((!info->extern_protected_data
+ || (info->extern_protected_data < 0
+ && !bed->extern_protected_data))
+ && !bed->is_function_type (h->type))
return TRUE;
/* Function pointer equality tests may require that STV_PROTECTED
if (abfd == NULL)
return FALSE;
+ /* Return FALSE if the object has been claimed by plugin. */
+ if (abfd->plugin_format == bfd_plugin_yes)
+ return FALSE;
+
if (! bfd_check_format (abfd, bfd_object))
return FALSE;
/* Make a special call to the linker "notice" function to tell it that
we are about to handle an as-needed lib, or have finished
- processing the lib. */
+ processing the lib. */
bfd_boolean
_bfd_elf_notice_as_needed (bfd *ibfd,
FALSE, bed->collect, NULL)))
goto error_return;
- if (!info->relocatable && info->executable)
+ if (info->executable)
{
/* Clobber the section size so that the warning does
not get copied into the output file. */
bfd_boolean common;
unsigned int old_alignment;
bfd *old_bfd;
+ bfd_boolean matched;
override = FALSE;
size_change_ok = FALSE;
type_change_ok = bed->type_change_ok;
old_weak = FALSE;
+ matched = FALSE;
old_alignment = 0;
old_bfd = NULL;
new_sec = sec;
if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec, &value,
sym_hash, &old_bfd, &old_weak,
&old_alignment, &skip, &override,
- &type_change_ok, &size_change_ok))
+ &type_change_ok, &size_change_ok,
+ &matched))
goto error_free_vers;
if (skip)
continue;
- if (override)
+ /* Override a definition only if the new symbol matches the
+ existing one. */
+ if (override && matched)
definition = FALSE;
h = *sym_hash;
/* If the indirect symbol has been forced local, don't
make the real symbol dynamic. */
if ((h == hi || !hi->forced_local)
- && (! info->executable
+ && ((! info->executable && ! info->relocatable)
|| h->def_dynamic
|| h->ref_dynamic))
dynsym = TRUE;
}
/* Merge st_other field. */
- elf_merge_st_other (abfd, h, isym, definition, dynamic);
+ elf_merge_st_other (abfd, h, isym, sec, definition, dynamic);
/* We don't want to make debug symbol dynamic. */
if (definition && (sec->flags & SEC_DEBUGGING) && !info->relocatable)
old_tab = NULL;
}
- /* Now that all the symbols from this input file are created, handle
- .symver foo, foo@BAR such that any relocs against foo become foo@BAR. */
- if (nondeflt_vers != NULL)
+ /* Now that all the symbols from this input file are created, if
+ not performing a relocatable link, handle .symver foo, foo@BAR
+ such that any relocs against foo become foo@BAR. */
+ if (!info->relocatable && nondeflt_vers != NULL)
{
bfd_size_type cnt, symidx;
{
struct hash_codes_info *inf = (struct hash_codes_info *) data;
const char *name;
- char *p;
unsigned long ha;
char *alc = NULL;
return TRUE;
name = h->root.root.string;
- p = strchr (name, ELF_VER_CHR);
- if (p != NULL)
+ if (h->versioned >= versioned)
{
- alc = (char *) bfd_malloc (p - name + 1);
- if (alc == NULL)
+ char *p = strchr (name, ELF_VER_CHR);
+ if (p != NULL)
{
- inf->error = TRUE;
- return FALSE;
+ alc = (char *) bfd_malloc (p - name + 1);
+ if (alc == NULL)
+ {
+ inf->error = TRUE;
+ return FALSE;
+ }
+ memcpy (alc, name, p - name);
+ alc[p - name] = '\0';
+ name = alc;
}
- memcpy (alc, name, p - name);
- alc[p - name] = '\0';
- name = alc;
}
/* Compute the hash value. */
{
struct collect_gnu_hash_codes *s = (struct collect_gnu_hash_codes *) data;
const char *name;
- char *p;
unsigned long ha;
char *alc = NULL;
return TRUE;
name = h->root.root.string;
- p = strchr (name, ELF_VER_CHR);
- if (p != NULL)
+ if (h->versioned >= versioned)
{
- alc = (char *) bfd_malloc (p - name + 1);
- if (alc == NULL)
+ char *p = strchr (name, ELF_VER_CHR);
+ if (p != NULL)
{
- s->error = TRUE;
- return FALSE;
+ alc = (char *) bfd_malloc (p - name + 1);
+ if (alc == NULL)
+ {
+ s->error = TRUE;
+ return FALSE;
+ }
+ memcpy (alc, name, p - name);
+ alc[p - name] = '\0';
+ name = alc;
}
- memcpy (alc, name, p - name);
- alc[p - name] = '\0';
- name = alc;
}
/* Compute the hash value. */
}
}
+ if (! _bfd_elf_maybe_strip_eh_frame_hdr (info))
+ return FALSE;
+
/* The backend must work out the sizes of all the other dynamic
sections. */
if (dynobj != NULL
&& ! (*bed->elf_backend_size_dynamic_sections) (output_bfd, info))
return FALSE;
- if (! _bfd_elf_maybe_strip_eh_frame_hdr (info))
- return FALSE;
-
if (dynobj != NULL && elf_hash_table (info)->dynamic_sections_created)
{
unsigned long section_sym_count;
struct elf_link_hash_table *htab;
/* Copy down any references that we may have already seen to the
- symbol which just became indirect. */
+ symbol which just became indirect if DIR isn't a hidden versioned
+ symbol. */
- 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 (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;
+ }
if (ind->root.type != bfd_link_hash_indirect)
return;
/* Output BFD. */
bfd *output_bfd;
/* Symbol string table. */
- struct bfd_strtab_hash *symstrtab;
+ struct elf_strtab_hash *symstrtab;
/* .dynsym section. */
asection *dynsym_sec;
/* .hash section. */
/* Array large enough to hold a section pointer for each local
symbol of any input BFD. */
asection **sections;
- /* Buffer to hold swapped out symbols. */
- bfd_byte *symbuf;
- /* And one for symbol section indices. */
+ /* Buffer for SHT_SYMTAB_SHNDX section. */
Elf_External_Sym_Shndx *symshndxbuf;
- /* Number of swapped out symbols in buffer. */
- size_t symbuf_count;
- /* Number of symbols which fit in symbuf. */
- size_t symbuf_size;
- /* And same for symshndxbuf. */
- size_t shndxbuf_size;
/* Number of STT_FILE syms seen. */
size_t filesym_count;
};
return ret;
}
-/* Flush the output symbols to the file. */
-
-static bfd_boolean
-elf_link_flush_output_syms (struct elf_final_link_info *flinfo,
- const struct elf_backend_data *bed)
-{
- if (flinfo->symbuf_count > 0)
- {
- Elf_Internal_Shdr *hdr;
- file_ptr pos;
- bfd_size_type amt;
-
- hdr = &elf_tdata (flinfo->output_bfd)->symtab_hdr;
- pos = hdr->sh_offset + hdr->sh_size;
- amt = flinfo->symbuf_count * bed->s->sizeof_sym;
- if (bfd_seek (flinfo->output_bfd, pos, SEEK_SET) != 0
- || bfd_bwrite (flinfo->symbuf, amt, flinfo->output_bfd) != amt)
- return FALSE;
-
- hdr->sh_size += amt;
- flinfo->symbuf_count = 0;
- }
-
- return TRUE;
-}
-
-/* Add a symbol to the output symbol table. */
+/* Add a symbol to the output symbol string table. */
static int
-elf_link_output_sym (struct elf_final_link_info *flinfo,
- const char *name,
- Elf_Internal_Sym *elfsym,
- asection *input_sec,
- struct elf_link_hash_entry *h)
-{
- bfd_byte *dest;
- Elf_External_Sym_Shndx *destshndx;
+elf_link_output_symstrtab (struct elf_final_link_info *flinfo,
+ const char *name,
+ Elf_Internal_Sym *elfsym,
+ asection *input_sec,
+ struct elf_link_hash_entry *h)
+{
int (*output_symbol_hook)
(struct bfd_link_info *, const char *, Elf_Internal_Sym *, asection *,
struct elf_link_hash_entry *);
+ struct elf_link_hash_table *hash_table;
const struct elf_backend_data *bed;
+ bfd_size_type strtabsize;
BFD_ASSERT (elf_onesymtab (flinfo->output_bfd));
return ret;
}
- if (name == NULL || *name == '\0')
- elfsym->st_name = 0;
- else if (input_sec->flags & SEC_EXCLUDE)
- elfsym->st_name = 0;
+ if (name == NULL
+ || *name == '\0'
+ || (input_sec->flags & SEC_EXCLUDE))
+ elfsym->st_name = (unsigned long) -1;
else
{
- elfsym->st_name = (unsigned long) _bfd_stringtab_add (flinfo->symstrtab,
- name, TRUE, FALSE);
+ /* Call _bfd_elf_strtab_offset after _bfd_elf_strtab_finalize
+ to get the final offset for st_name. */
+ elfsym->st_name
+ = (unsigned long) _bfd_elf_strtab_add (flinfo->symstrtab,
+ name, FALSE);
if (elfsym->st_name == (unsigned long) -1)
return 0;
}
- if (flinfo->symbuf_count >= flinfo->symbuf_size)
+ hash_table = elf_hash_table (flinfo->info);
+ strtabsize = hash_table->strtabsize;
+ if (strtabsize <= hash_table->strtabcount)
{
- if (! elf_link_flush_output_syms (flinfo, bed))
+ strtabsize += strtabsize;
+ hash_table->strtabsize = strtabsize;
+ strtabsize *= sizeof (*hash_table->strtab);
+ hash_table->strtab
+ = (struct elf_sym_strtab *) bfd_realloc (hash_table->strtab,
+ strtabsize);
+ if (hash_table->strtab == NULL)
return 0;
}
+ hash_table->strtab[hash_table->strtabcount].sym = *elfsym;
+ hash_table->strtab[hash_table->strtabcount].dest_index
+ = hash_table->strtabcount;
+ hash_table->strtab[hash_table->strtabcount].destshndx_index
+ = flinfo->symshndxbuf ? bfd_get_symcount (flinfo->output_bfd) : 0;
- dest = flinfo->symbuf + flinfo->symbuf_count * bed->s->sizeof_sym;
- destshndx = flinfo->symshndxbuf;
- if (destshndx != NULL)
+ bfd_get_symcount (flinfo->output_bfd) += 1;
+ hash_table->strtabcount += 1;
+
+ return 1;
+}
+
+/* Swap symbols out to the symbol table and flush the output symbols to
+ the file. */
+
+static bfd_boolean
+elf_link_swap_symbols_out (struct elf_final_link_info *flinfo)
+{
+ struct elf_link_hash_table *hash_table = elf_hash_table (flinfo->info);
+ bfd_size_type amt, i;
+ const struct elf_backend_data *bed;
+ bfd_byte *symbuf;
+ Elf_Internal_Shdr *hdr;
+ file_ptr pos;
+ bfd_boolean ret;
+
+ if (!hash_table->strtabcount)
+ return TRUE;
+
+ BFD_ASSERT (elf_onesymtab (flinfo->output_bfd));
+
+ bed = get_elf_backend_data (flinfo->output_bfd);
+
+ amt = bed->s->sizeof_sym * hash_table->strtabcount;
+ symbuf = (bfd_byte *) bfd_malloc (amt);
+ if (symbuf == NULL)
+ return FALSE;
+
+ if (flinfo->symshndxbuf)
{
- if (bfd_get_symcount (flinfo->output_bfd) >= flinfo->shndxbuf_size)
+ amt = (sizeof (Elf_External_Sym_Shndx)
+ * (bfd_get_symcount (flinfo->output_bfd)));
+ flinfo->symshndxbuf = (Elf_External_Sym_Shndx *) bfd_zmalloc (amt);
+ if (flinfo->symshndxbuf == NULL)
{
- bfd_size_type amt;
-
- amt = flinfo->shndxbuf_size * sizeof (Elf_External_Sym_Shndx);
- destshndx = (Elf_External_Sym_Shndx *) bfd_realloc (destshndx,
- amt * 2);
- if (destshndx == NULL)
- return 0;
- flinfo->symshndxbuf = destshndx;
- memset ((char *) destshndx + amt, 0, amt);
- flinfo->shndxbuf_size *= 2;
+ free (symbuf);
+ return FALSE;
}
- destshndx += bfd_get_symcount (flinfo->output_bfd);
}
- bed->s->swap_symbol_out (flinfo->output_bfd, elfsym, dest, destshndx);
- flinfo->symbuf_count += 1;
- bfd_get_symcount (flinfo->output_bfd) += 1;
+ for (i = 0; i < hash_table->strtabcount; i++)
+ {
+ struct elf_sym_strtab *elfsym = &hash_table->strtab[i];
+ if (elfsym->sym.st_name == (unsigned long) -1)
+ elfsym->sym.st_name = 0;
+ else
+ elfsym->sym.st_name
+ = (unsigned long) _bfd_elf_strtab_offset (flinfo->symstrtab,
+ elfsym->sym.st_name);
+ bed->s->swap_symbol_out (flinfo->output_bfd, &elfsym->sym,
+ ((bfd_byte *) symbuf
+ + (elfsym->dest_index
+ * bed->s->sizeof_sym)),
+ (flinfo->symshndxbuf
+ + elfsym->destshndx_index));
+ }
+
+ hdr = &elf_tdata (flinfo->output_bfd)->symtab_hdr;
+ pos = hdr->sh_offset + hdr->sh_size;
+ amt = hash_table->strtabcount * bed->s->sizeof_sym;
+ if (bfd_seek (flinfo->output_bfd, pos, SEEK_SET) == 0
+ && bfd_bwrite (symbuf, amt, flinfo->output_bfd) == amt)
+ {
+ hdr->sh_size += amt;
+ ret = TRUE;
+ }
+ else
+ ret = FALSE;
- return 1;
+ free (symbuf);
+
+ free (hash_table->strtab);
+ hash_table->strtab = NULL;
+
+ return ret;
}
/* Return TRUE if the dynamic symbol SYM in ABFD is supported. */
const struct elf_backend_data *bed;
long indx;
int ret;
+ /* 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
+ || (flinfo->info->executable
+ && !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 (!h->forced_local)
+ if (!local_bind)
return TRUE;
}
else
{
- if (h->forced_local)
+ if (local_bind)
return TRUE;
}
/* We should also warn if a forced local symbol is referenced from
shared libraries. */
- if (!flinfo->info->relocatable
- && flinfo->info->executable
+ if (flinfo->info->executable
&& h->forced_local
&& h->ref_dynamic
&& h->def_regular
sym.st_value = 0;
sym.st_size = h->size;
sym.st_other = h->other;
- if (h->forced_local)
+ if (local_bind)
{
sym.st_info = ELF_ST_INFO (STB_LOCAL, h->type);
/* Turn off visibility on local symbol. */
/* 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 (h->verinfo.verdef == NULL)
+ have a run-time problem if not linking executable, referenced
+ by shared library, not locally defined, or not bound locally.
+ */
+ if (h->verinfo.verdef == NULL
+ && !local_bind
+ && (!flinfo->info->executable
+ || h->ref_dynamic
+ || !h->def_regular))
{
char *p = strrchr (h->root.root.string, ELF_VER_CHR);
iversym.vs_vers++;
}
- if (h->hidden)
+ /* Turn on VERSYM_HIDDEN only if the hidden versioned symbol is
+ defined locally. */
+ if (h->versioned == versioned_hidden && h->def_regular)
iversym.vs_vers |= VERSYM_HIDDEN;
eversym = (Elf_External_Versym *) flinfo->symver_sec->contents;
memset (&fsym, 0, sizeof (fsym));
fsym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
fsym.st_shndx = SHN_ABS;
- if (!elf_link_output_sym (eoinfo->flinfo, NULL, &fsym,
- bfd_und_section_ptr, NULL))
+ if (!elf_link_output_symstrtab (eoinfo->flinfo, NULL, &fsym,
+ bfd_und_section_ptr, NULL))
return FALSE;
eoinfo->file_sym_done = TRUE;
}
indx = bfd_get_symcount (flinfo->output_bfd);
- ret = elf_link_output_sym (flinfo, h->root.root.string, &sym, input_sec, h);
+ ret = elf_link_output_symstrtab (flinfo, h->root.root.string, &sym,
+ input_sec, h);
if (ret == 0)
{
eoinfo->failed = TRUE;
{
case SEC_INFO_TYPE_STABS:
case SEC_INFO_TYPE_EH_FRAME:
+ case SEC_INFO_TYPE_EH_FRAME_ENTRY:
return TRUE;
default:
break;
memset (&osym, 0, sizeof (osym));
osym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
osym.st_shndx = SHN_ABS;
- if (!elf_link_output_sym (flinfo,
- (input_bfd->lto_output ? NULL
- : input_bfd->filename),
- &osym, bfd_abs_section_ptr, NULL))
+ if (!elf_link_output_symstrtab (flinfo,
+ (input_bfd->lto_output ? NULL
+ : input_bfd->filename),
+ &osym, bfd_abs_section_ptr,
+ NULL))
return FALSE;
}
}
indx = bfd_get_symcount (output_bfd);
- ret = elf_link_output_sym (flinfo, name, &osym, isec, NULL);
+ ret = elf_link_output_symstrtab (flinfo, name, &osym, isec, NULL);
if (ret == 0)
return FALSE;
else if (ret == 1)
sym.st_value += o->output_offset;
indx = bfd_get_symcount (output_bfd);
- ret = elf_link_output_sym (flinfo, name, &sym, o, NULL);
+ ret = elf_link_output_symstrtab (flinfo, name, &sym, o,
+ NULL);
if (ret == 0)
return FALSE;
else if (ret == 1)
}
indx = bfd_get_symcount (output_bfd);
- ret = elf_link_output_sym (flinfo, name, &sym, sec,
- NULL);
+ ret = elf_link_output_symstrtab (flinfo, name,
+ &sym, sec,
+ NULL);
if (ret == 0)
return FALSE;
else if (ret == 1)
return FALSE;
}
break;
+ case SEC_INFO_TYPE_EH_FRAME_ENTRY:
+ {
+ if (! _bfd_elf_write_section_eh_frame_entry (output_bfd,
+ flinfo->info,
+ o, contents))
+ return FALSE;
+ }
+ break;
default:
{
/* FIXME: octets_per_byte. */
asection *o;
if (flinfo->symstrtab != NULL)
- _bfd_stringtab_free (flinfo->symstrtab);
+ _bfd_elf_strtab_free (flinfo->symstrtab);
if (flinfo->contents != NULL)
free (flinfo->contents);
if (flinfo->external_relocs != NULL)
free (flinfo->indices);
if (flinfo->sections != NULL)
free (flinfo->sections);
- if (flinfo->symbuf != NULL)
- free (flinfo->symbuf);
if (flinfo->symshndxbuf != NULL)
free (flinfo->symshndxbuf);
for (o = obfd->sections; o != NULL; o = o->next)
flinfo.info = info;
flinfo.output_bfd = abfd;
- flinfo.symstrtab = _bfd_elf_stringtab_init ();
+ flinfo.symstrtab = _bfd_elf_strtab_init ();
if (flinfo.symstrtab == NULL)
return FALSE;
flinfo.internal_syms = NULL;
flinfo.indices = NULL;
flinfo.sections = NULL;
- flinfo.symbuf = NULL;
flinfo.symshndxbuf = NULL;
- flinfo.symbuf_count = 0;
- flinfo.shndxbuf_size = 0;
flinfo.filesym_count = 0;
/* The object attributes have been merged. Remove the input
to count upwards while actually outputting the relocations. */
esdo->rel.count = 0;
esdo->rela.count = 0;
+
+ if (esdo->this_hdr.sh_offset == (file_ptr) -1)
+ {
+ /* Cache the section contents so that they can be compressed
+ later. Use bfd_malloc since it will be freed by
+ bfd_compress_section_contents. */
+ unsigned char *contents = esdo->this_hdr.contents;
+ if ((o->flags & SEC_ELF_COMPRESS) == 0 || contents != NULL)
+ abort ();
+ contents
+ = (unsigned char *) bfd_malloc (esdo->this_hdr.sh_size);
+ if (contents == NULL)
+ goto error_return;
+ esdo->this_hdr.contents = contents;
+ }
}
/* We have now assigned file positions for all the sections except
/* sh_offset is set just below. */
symtab_hdr->sh_addralign = (bfd_vma) 1 << bed->s->log_file_align;
- /* Allocate a buffer to hold swapped out symbols. This is to avoid
- continuously seeking to the right position in the file. */
- if (! info->keep_memory || max_sym_count < 20)
- flinfo.symbuf_size = 20;
- else
- flinfo.symbuf_size = max_sym_count;
- amt = flinfo.symbuf_size;
- amt *= bed->s->sizeof_sym;
- flinfo.symbuf = (bfd_byte *) bfd_malloc (amt);
- if (flinfo.symbuf == NULL)
+ if (max_sym_count < 20)
+ max_sym_count = 20;
+ elf_hash_table (info)->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)
goto error_return;
- if (elf_numsections (abfd) > (SHN_LORESERVE & 0xFFFF))
- {
- /* Wild guess at number of output symbols. realloc'd as needed. */
- amt = 2 * max_sym_count + elf_numsections (abfd) + 1000;
- flinfo.shndxbuf_size = amt;
- amt *= sizeof (Elf_External_Sym_Shndx);
- flinfo.symshndxbuf = (Elf_External_Sym_Shndx *) bfd_zmalloc (amt);
- if (flinfo.symshndxbuf == NULL)
- goto error_return;
- }
+ /* The real buffer will be allocated in elf_link_swap_symbols_out. */
+ flinfo.symshndxbuf
+ = (elf_numsections (abfd) > (SHN_LORESERVE & 0xFFFF)
+ ? (Elf_External_Sym_Shndx *) -1 : NULL);
if (info->strip != strip_all || emit_relocs)
{
elfsym.st_other = 0;
elfsym.st_shndx = SHN_UNDEF;
elfsym.st_target_internal = 0;
- if (elf_link_output_sym (&flinfo, NULL, &elfsym, bfd_und_section_ptr,
- NULL) != 1)
+ if (elf_link_output_symstrtab (&flinfo, NULL, &elfsym,
+ bfd_und_section_ptr, NULL) != 1)
goto error_return;
/* Output a symbol for each section. We output these even if we are
elfsym.st_shndx = i;
if (!info->relocatable)
elfsym.st_value = o->vma;
- if (elf_link_output_sym (&flinfo, NULL, &elfsym, o, NULL) != 1)
+ if (elf_link_output_symstrtab (&flinfo, NULL, &elfsym, o,
+ NULL) != 1)
goto error_return;
}
}
return FALSE;
}
+ if (!_bfd_elf_fixup_eh_frame_hdr (info))
+ return FALSE;
+
/* Since ELF permits relocations to be against local symbols, we
must have the local symbols available when we do the relocations.
Since we would rather only read the local symbols once, and we
struct elf_link_hash_entry *);
if (! ((*bed->elf_backend_output_arch_local_syms)
- (abfd, info, &flinfo, (out_sym_func) elf_link_output_sym)))
+ (abfd, info, &flinfo,
+ (out_sym_func) elf_link_output_symstrtab)))
return FALSE;
}
struct elf_link_hash_entry *);
if (! ((*bed->elf_backend_output_arch_syms)
- (abfd, info, &flinfo, (out_sym_func) elf_link_output_sym)))
+ (abfd, info, &flinfo,
+ (out_sym_func) elf_link_output_symstrtab)))
return FALSE;
}
- /* Flush all symbols to the file. */
- if (! elf_link_flush_output_syms (&flinfo, bed))
+ /* Finalize the .strtab section. */
+ _bfd_elf_strtab_finalize (flinfo.symstrtab);
+
+ /* Swap out the .strtab section. */
+ if (!elf_link_swap_symbols_out (&flinfo))
return FALSE;
/* Now we know the size of the symtab section. */
symstrtab_hdr->sh_type = SHT_STRTAB;
symstrtab_hdr->sh_flags = 0;
symstrtab_hdr->sh_addr = 0;
- symstrtab_hdr->sh_size = _bfd_stringtab_size (flinfo.symstrtab);
+ symstrtab_hdr->sh_size = _bfd_elf_strtab_size (flinfo.symstrtab);
symstrtab_hdr->sh_entsize = 0;
symstrtab_hdr->sh_link = 0;
symstrtab_hdr->sh_info = 0;
elf_next_file_pos (abfd) = off;
if (bfd_seek (abfd, symstrtab_hdr->sh_offset, SEEK_SET) != 0
- || ! _bfd_stringtab_emit (abfd, flinfo.symstrtab))
+ || ! _bfd_elf_strtab_emit (abfd, flinfo.symstrtab))
return FALSE;
}
}
}
+ eh_frame = elf_section_eh_frame_entry (sec);
+ if (ret && eh_frame && !eh_frame->gc_mark)
+ if (!_bfd_elf_gc_mark (info, eh_frame, gc_mark_hook))
+ ret = FALSE;
+
return ret;
}
|| (h->dynamic
&& d != NULL
&& (*d->match) (&d->head, NULL, h->root.root.string)))
- && (strchr (h->root.root.string, ELF_VER_CHR) != NULL
+ && (h->versioned >= versioned
|| !bfd_hide_sym_by_version (info->version_info,
h->root.root.string)))))
h->root.u.def.section->flags |= SEC_KEEP;
}
}
+bfd_boolean
+bfd_elf_parse_eh_frame_entries (bfd *abfd ATTRIBUTE_UNUSED,
+ struct bfd_link_info *info)
+{
+ bfd *ibfd = info->input_bfds;
+
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
+ {
+ asection *sec;
+ struct elf_reloc_cookie cookie;
+
+ if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
+ continue;
+
+ if (!init_reloc_cookie (&cookie, info, ibfd))
+ return FALSE;
+
+ for (sec = ibfd->sections; sec; sec = sec->next)
+ {
+ if (CONST_STRNEQ (bfd_section_name (ibfd, sec), ".eh_frame_entry")
+ && init_reloc_cookie_rels (&cookie, info, ibfd, sec))
+ {
+ _bfd_elf_parse_eh_frame_entry (info, sec, &cookie);
+ fini_reloc_cookie_rels (&cookie, sec);
+ }
+ }
+ }
+ return TRUE;
+}
+
/* Do mark and sweep of unused sections. */
bfd_boolean
/* Try to parse each bfd's .eh_frame section. Point elf_eh_frame_section
at the .eh_frame section if we can mark the FDEs individually. */
- for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
+ for (sub = info->input_bfds;
+ info->eh_frame_hdr_type != COMPACT_EH_HDR && sub != NULL;
+ sub = sub->link.next)
{
asection *sec;
struct elf_reloc_cookie cookie;
}
}
- o = bfd_get_section_by_name (output_bfd, ".eh_frame");
+ o = NULL;
+ if (info->eh_frame_hdr_type != COMPACT_EH_HDR)
+ o = bfd_get_section_by_name (output_bfd, ".eh_frame");
if (o != NULL)
{
asection *i;
}
}
- if (info->eh_frame_hdr
+ if (info->eh_frame_hdr_type == COMPACT_EH_HDR)
+ _bfd_elf_end_eh_frame_parsing (info);
+
+ if (info->eh_frame_hdr_type
&& !info->relocatable
&& _bfd_elf_discard_section_eh_frame_hdr (output_bfd, info))
changed = 1;
ehdest->target_internal = ehsrc->target_internal;
isym.st_other = ehsrc->other;
- elf_merge_st_other (abfd, ehdest, &isym, TRUE, FALSE);
+ elf_merge_st_other (abfd, ehdest, &isym, NULL, TRUE, FALSE);
}
/* Append a RELA relocation REL to section S in BFD. */