static boolean elf_link_add_archive_symbols
PARAMS ((bfd *, struct bfd_link_info *));
static boolean elf_merge_symbol
- PARAMS ((bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,
- asection **, bfd_vma *, struct elf_link_hash_entry **,
- boolean *, boolean *, boolean *, boolean));
+ PARAMS ((bfd *, struct bfd_link_info *, const char *,
+ Elf_Internal_Sym *, asection **, bfd_vma *,
+ struct elf_link_hash_entry **, boolean *, boolean *,
+ boolean *, boolean));
+static boolean elf_add_default_symbol
+ PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
+ const char *, Elf_Internal_Sym *, asection **, bfd_vma *,
+ boolean *, boolean, boolean));
static boolean elf_export_symbol
PARAMS ((struct elf_link_hash_entry *, PTR));
static boolean elf_finalize_dynstr
PARAMS ((const void *, const void *));
static size_t elf_link_sort_relocs
PARAMS ((bfd *, struct bfd_link_info *, asection **));
+static boolean elf_section_ignore_discarded_relocs
+ PARAMS ((asection *));
/* Given an ELF BFD, add symbols to the global hash table as
appropriate. */
return true;
}
+/* This function is called to create an indirect symbol from the
+ default for the symbol with the default version if needed. The
+ symbol is described by H, NAME, SYM, SEC, VALUE, and OVERRIDE. We
+ set DYNSYM if the new indirect symbol is dynamic. DT_NEEDED
+ indicates if it comes from a DT_NEEDED entry of a shared object. */
+
+static boolean
+elf_add_default_symbol (abfd, info, h, name, sym, sec, value,
+ dynsym, override, dt_needed)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ struct elf_link_hash_entry *h;
+ const char *name;
+ Elf_Internal_Sym *sym;
+ asection **sec;
+ bfd_vma *value;
+ boolean *dynsym;
+ boolean override;
+ boolean dt_needed;
+{
+ boolean type_change_ok;
+ boolean size_change_ok;
+ char *shortname;
+ struct elf_link_hash_entry *hi;
+ struct elf_backend_data *bed;
+ boolean collect;
+ boolean dynamic;
+ char *p;
+
+ /* 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 (override)
+ {
+ /* We are overridden by an old defition. We need to check if we
+ need to crreate the indirect symbol from the default name. */
+ hi = elf_link_hash_lookup (elf_hash_table (info), name, true,
+ false, false);
+ BFD_ASSERT (hi != NULL);
+ if (hi == h)
+ return true;
+ while (hi->root.type == bfd_link_hash_indirect
+ || hi->root.type == bfd_link_hash_warning)
+ {
+ hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
+ if (hi == h)
+ return true;
+ }
+ }
+
+ bed = get_elf_backend_data (abfd);
+ collect = bed->collect;
+ dynamic = (abfd->flags & DYNAMIC) != 0;
+
+ shortname = bfd_hash_allocate (&info->hash->table,
+ (size_t) (p - name + 1));
+ if (shortname == NULL)
+ return false;
+ strncpy (shortname, name, (size_t) (p - name));
+ shortname [p - name] = '\0';
+
+ /* We are going to create a new symbol. Merge it with any existing
+ symbol with this name. For the purposes of the merge, act as
+ though we were defining the symbol we just defined, although we
+ actually going to define an indirect symbol. */
+ type_change_ok = false;
+ size_change_ok = false;
+ if (! elf_merge_symbol (abfd, info, shortname, sym, sec, value,
+ &hi, &override, &type_change_ok,
+ &size_change_ok, dt_needed))
+ return false;
+
+ if (! override)
+ {
+ if (! (_bfd_generic_link_add_one_symbol
+ (info, abfd, shortname, BSF_INDIRECT, bfd_ind_section_ptr,
+ (bfd_vma) 0, name, false, collect,
+ (struct bfd_link_hash_entry **) &hi)))
+ return false;
+ }
+ else
+ {
+ /* In this case the symbol named SHORTNAME is overriding the
+ indirect symbol we want to add. We were planning on making
+ SHORTNAME an indirect symbol referring to NAME. SHORTNAME
+ is the name without a version. NAME is the fully versioned
+ name, and it is the default version.
+
+ Overriding means that we already saw a definition for the
+ symbol SHORTNAME in a regular object, and it is overriding
+ the symbol defined in the dynamic object.
+
+ When this happens, we actually want to change NAME, the
+ symbol we just added, to refer to SHORTNAME. This will cause
+ references to NAME in the shared object to become references
+ to SHORTNAME in the regular object. This is what we expect
+ when we override a function in a shared object: that the
+ references in the shared object will be mapped to the
+ definition in the regular object. */
+
+ while (hi->root.type == bfd_link_hash_indirect
+ || hi->root.type == bfd_link_hash_warning)
+ hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
+
+ h->root.type = bfd_link_hash_indirect;
+ h->root.u.i.link = (struct bfd_link_hash_entry *) hi;
+ if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
+ {
+ h->elf_link_hash_flags &=~ ELF_LINK_HASH_DEF_DYNAMIC;
+ hi->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
+ if (hi->elf_link_hash_flags
+ & (ELF_LINK_HASH_REF_REGULAR
+ | ELF_LINK_HASH_DEF_REGULAR))
+ {
+ if (! _bfd_elf_link_record_dynamic_symbol (info, hi))
+ return false;
+ }
+ }
+
+ /* Now set HI to H, so that the following code will set the
+ other fields correctly. */
+ hi = h;
+ }
+
+ /* 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)
+ {
+ struct elf_link_hash_entry *ht;
+
+ /* If the symbol became indirect, then we assume that we have
+ not seen a definition before. */
+ BFD_ASSERT ((hi->elf_link_hash_flags
+ & (ELF_LINK_HASH_DEF_DYNAMIC
+ | ELF_LINK_HASH_DEF_REGULAR)) == 0);
+
+ ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
+ (*bed->elf_backend_copy_indirect_symbol) (ht, hi);
+
+ /* See if the new flags lead us to realize that the symbol must
+ be dynamic. */
+ if (! *dynsym)
+ {
+ if (! dynamic)
+ {
+ if (info->shared
+ || ((hi->elf_link_hash_flags
+ & ELF_LINK_HASH_REF_DYNAMIC) != 0))
+ *dynsym = true;
+ }
+ else
+ {
+ if ((hi->elf_link_hash_flags
+ & ELF_LINK_HASH_REF_REGULAR) != 0)
+ *dynsym = true;
+ }
+ }
+ }
+
+ /* We also need to define an indirection from the nondefault version
+ of the symbol. */
+
+ shortname = bfd_hash_allocate (&info->hash->table, strlen (name));
+ if (shortname == NULL)
+ return false;
+ strncpy (shortname, name, (size_t) (p - name));
+ strcpy (shortname + (p - name), p + 1);
+
+ /* Once again, merge with any existing symbol. */
+ type_change_ok = false;
+ size_change_ok = false;
+ if (! elf_merge_symbol (abfd, info, shortname, sym, sec, value,
+ &hi, &override, &type_change_ok,
+ &size_change_ok, dt_needed))
+ return false;
+
+ 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. */
+ (*_bfd_error_handler)
+ (_("%s: warning: unexpected redefinition of `%s'"),
+ bfd_archive_filename (abfd), shortname);
+ }
+ else
+ {
+ if (! (_bfd_generic_link_add_one_symbol
+ (info, abfd, shortname, BSF_INDIRECT,
+ bfd_ind_section_ptr, (bfd_vma) 0, name, false,
+ collect, (struct bfd_link_hash_entry **) &hi)))
+ return false;
+
+ /* 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)
+ {
+ /* If the symbol became indirect, then we assume that we have
+ not seen a definition before. */
+ BFD_ASSERT ((hi->elf_link_hash_flags
+ & (ELF_LINK_HASH_DEF_DYNAMIC
+ | ELF_LINK_HASH_DEF_REGULAR)) == 0);
+
+ (*bed->elf_backend_copy_indirect_symbol) (h, hi);
+
+ /* See if the new flags lead us to realize that the symbol
+ must be dynamic. */
+ if (! *dynsym)
+ {
+ if (! dynamic)
+ {
+ if (info->shared
+ || ((hi->elf_link_hash_flags
+ & ELF_LINK_HASH_REF_DYNAMIC) != 0))
+ *dynsym = true;
+ }
+ else
+ {
+ if ((hi->elf_link_hash_flags
+ & ELF_LINK_HASH_REF_REGULAR) != 0)
+ *dynsym = true;
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
/* Add symbols from an ELF object file to the linker hash table. */
static boolean
boolean size_change_ok, type_change_ok;
boolean new_weakdef;
unsigned int old_alignment;
+ boolean override;
+
+ override = false;
elf_swap_symbol_in (abfd, esym, &sym);
{
Elf_Internal_Versym iver;
unsigned int vernum = 0;
- boolean override;
if (ever != NULL)
{
h->elf_link_hash_flags |= new_flag;
- /* 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. */
+ /* Check to see if we need to add an indirect symbol for
+ the default name. */
if (definition || h->root.type == bfd_link_hash_common)
- {
- char *p;
-
- p = strchr (name, ELF_VER_CHR);
- if (p != NULL && p[1] == ELF_VER_CHR)
- {
- char *shortname;
- struct elf_link_hash_entry *hi;
- boolean override;
-
- shortname = bfd_hash_allocate (&info->hash->table,
- (size_t) (p - name + 1));
- if (shortname == NULL)
- goto error_return;
- strncpy (shortname, name, (size_t) (p - name));
- shortname[p - name] = '\0';
-
- /* We are going to create a new symbol. Merge it
- with any existing symbol with this name. For the
- purposes of the merge, act as though we were
- defining the symbol we just defined, although we
- actually going to define an indirect symbol. */
- type_change_ok = false;
- size_change_ok = false;
- if (! elf_merge_symbol (abfd, info, shortname, &sym, &sec,
- &value, &hi, &override,
- &type_change_ok,
- &size_change_ok, dt_needed))
- goto error_return;
-
- if (! override)
- {
- if (! (_bfd_generic_link_add_one_symbol
- (info, abfd, shortname, BSF_INDIRECT,
- bfd_ind_section_ptr, (bfd_vma) 0, name, false,
- collect, (struct bfd_link_hash_entry **) &hi)))
- goto error_return;
- }
- else
- {
- /* In this case the symbol named SHORTNAME is
- overriding the indirect symbol we want to
- add. We were planning on making SHORTNAME an
- indirect symbol referring to NAME. SHORTNAME
- is the name without a version. NAME is the
- fully versioned name, and it is the default
- version.
-
- Overriding means that we already saw a
- definition for the symbol SHORTNAME in a
- regular object, and it is overriding the
- symbol defined in the dynamic object.
-
- When this happens, we actually want to change
- NAME, the symbol we just added, to refer to
- SHORTNAME. This will cause references to
- NAME in the shared object to become
- references to SHORTNAME in the regular
- object. This is what we expect when we
- override a function in a shared object: that
- the references in the shared object will be
- mapped to the definition in the regular
- object. */
-
- while (hi->root.type == bfd_link_hash_indirect
- || hi->root.type == bfd_link_hash_warning)
- hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
-
- h->root.type = bfd_link_hash_indirect;
- h->root.u.i.link = (struct bfd_link_hash_entry *) hi;
- if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
- {
- h->elf_link_hash_flags &=~ ELF_LINK_HASH_DEF_DYNAMIC;
- hi->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
- if (hi->elf_link_hash_flags
- & (ELF_LINK_HASH_REF_REGULAR
- | ELF_LINK_HASH_DEF_REGULAR))
- {
- if (! _bfd_elf_link_record_dynamic_symbol (info,
- hi))
- goto error_return;
- }
- }
-
- /* Now set HI to H, so that the following code
- will set the other fields correctly. */
- hi = h;
- }
-
- /* 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)
- {
- struct elf_link_hash_entry *ht;
-
- /* If the symbol became indirect, then we assume
- that we have not seen a definition before. */
- BFD_ASSERT ((hi->elf_link_hash_flags
- & (ELF_LINK_HASH_DEF_DYNAMIC
- | ELF_LINK_HASH_DEF_REGULAR))
- == 0);
-
- ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
- (*bed->elf_backend_copy_indirect_symbol) (ht, hi);
-
- /* See if the new flags lead us to realize that
- the symbol must be dynamic. */
- if (! dynsym)
- {
- if (! dynamic)
- {
- if (info->shared
- || ((hi->elf_link_hash_flags
- & ELF_LINK_HASH_REF_DYNAMIC)
- != 0))
- dynsym = true;
- }
- else
- {
- if ((hi->elf_link_hash_flags
- & ELF_LINK_HASH_REF_REGULAR) != 0)
- dynsym = true;
- }
- }
- }
-
- /* We also need to define an indirection from the
- nondefault version of the symbol. */
-
- shortname = bfd_hash_allocate (&info->hash->table,
- strlen (name));
- if (shortname == NULL)
- goto error_return;
- strncpy (shortname, name, (size_t) (p - name));
- strcpy (shortname + (p - name), p + 1);
-
- /* Once again, merge with any existing symbol. */
- type_change_ok = false;
- size_change_ok = false;
- if (! elf_merge_symbol (abfd, info, shortname, &sym, &sec,
- &value, &hi, &override,
- &type_change_ok,
- &size_change_ok, dt_needed))
- goto error_return;
-
- 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. */
- (*_bfd_error_handler)
- (_("%s: warning: unexpected redefinition of `%s'"),
- bfd_archive_filename (abfd), shortname);
- }
- else
- {
- if (! (_bfd_generic_link_add_one_symbol
- (info, abfd, shortname, BSF_INDIRECT,
- bfd_ind_section_ptr, (bfd_vma) 0, name, false,
- collect, (struct bfd_link_hash_entry **) &hi)))
- goto error_return;
-
- /* 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)
- {
- /* If the symbol became indirect, then we
- assume that we have not seen a definition
- before. */
- BFD_ASSERT ((hi->elf_link_hash_flags
- & (ELF_LINK_HASH_DEF_DYNAMIC
- | ELF_LINK_HASH_DEF_REGULAR))
- == 0);
-
- (*bed->elf_backend_copy_indirect_symbol) (h, hi);
-
- /* See if the new flags lead us to realize
- that the symbol must be dynamic. */
- if (! dynsym)
- {
- if (! dynamic)
- {
- if (info->shared
- || ((hi->elf_link_hash_flags
- & ELF_LINK_HASH_REF_DYNAMIC)
- != 0))
- dynsym = true;
- }
- else
- {
- if ((hi->elf_link_hash_flags
- & ELF_LINK_HASH_REF_REGULAR) != 0)
- dynsym = true;
- }
- }
- }
- }
- }
- }
+ if (! elf_add_default_symbol (abfd, info, h, name, &sym,
+ &sec, &value, &dynsym,
+ override, dt_needed))
+ goto error_return;
if (dynsym && h->dynindx == -1)
{
.eh_frame to describe a routine in the linkonce section,
and it turns out to be hard to remove the .eh_frame
entry too. FIXME. */
- if (!finfo->info->relocateable)
+ if (!finfo->info->relocateable
+ && !elf_section_ignore_discarded_relocs (o))
{
Elf_Internal_Rela *rel, *relend;
|| 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
- ->output_section))
+ ->output_section)
+ && elf_section_data (h->root.u.def.section)->merge_info
+ == NULL)
{
#if BFD_VERSION_DATE < 20031005
if ((o->flags & SEC_DEBUGGING) != 0)
_("warning: relocation against removed section; zeroing"),
NULL, input_bfd, o, rel->r_offset);
#endif
+ BFD_ASSERT (r_symndx != 0);
memset (rel, 0, sizeof (*rel));
}
else
}
else
{
- isym = finfo->internal_syms + r_symndx;
- if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
- {
- asection *sec = finfo->sections[r_symndx];
+ asection *sec = finfo->sections[r_symndx];
- if (sec != NULL
- && ! bfd_is_abs_section (sec)
- && bfd_is_abs_section (sec->output_section))
- {
+ if (sec != NULL
+ && ! bfd_is_abs_section (sec)
+ && bfd_is_abs_section (sec->output_section)
+ && elf_section_data (sec)->merge_info == NULL)
+ {
#if BFD_VERSION_DATE < 20031005
- if ((o->flags & SEC_DEBUGGING) != 0
- || (sec->flags & SEC_LINK_ONCE) != 0)
- {
+ if ((o->flags & SEC_DEBUGGING) != 0
+ || (sec->flags & SEC_LINK_ONCE) != 0)
+ {
#if BFD_VERSION_DATE > 20021005
- (*finfo->info->callbacks->warning)
- (finfo->info,
- _("warning: relocation against removed section"),
- NULL, input_bfd, o, rel->r_offset);
+ (*finfo->info->callbacks->warning)
+ (finfo->info,
+ _("warning: relocation against removed section"),
+ NULL, input_bfd, o, rel->r_offset);
#endif
- rel->r_info
- = ELF_R_INFO (0, ELF_R_TYPE (rel->r_info));
- rel->r_addend = 0;
- }
- else
+ BFD_ASSERT (r_symndx != 0);
+ rel->r_info
+ = ELF_R_INFO (0, ELF_R_TYPE (rel->r_info));
+ rel->r_addend = 0;
+ }
+ else
#endif
- {
- boolean ok;
- const char *msg
- = _("local symbols in discarded section %s");
- bfd_size_type amt
- = strlen (sec->name) + strlen (msg) - 1;
- char *buf = (char *) bfd_malloc (amt);
-
- if (buf != NULL)
- sprintf (buf, msg, sec->name);
- else
- buf = (char *) sec->name;
- ok = (*finfo->info->callbacks
- ->undefined_symbol) (finfo->info, buf,
- input_bfd, o,
- rel->r_offset,
- true);
- if (buf != sec->name)
- free (buf);
- if (!ok)
- return false;
- }
+ {
+ boolean ok;
+ const char *msg
+ = _("local symbols in discarded section %s");
+ bfd_size_type amt
+ = strlen (sec->name) + strlen (msg) - 1;
+ char *buf = (char *) bfd_malloc (amt);
+
+ if (buf != NULL)
+ sprintf (buf, msg, sec->name);
+ else
+ buf = (char *) sec->name;
+ ok = (*finfo->info->callbacks
+ ->undefined_symbol) (finfo->info, buf,
+ input_bfd, o,
+ rel->r_offset,
+ true);
+ if (buf != sec->name)
+ free (buf);
+ if (!ok)
+ return false;
}
}
}
}
/* Write out the modified section contents. */
- if (elf_section_data (o)->stab_info)
+ if (bed->elf_backend_write_section
+ && (*bed->elf_backend_write_section) (output_bfd, o, contents))
+ {
+ /* Section written out. */
+ }
+ else if (elf_section_data (o)->stab_info)
{
if (! (_bfd_write_section_stabs
(output_bfd, &elf_hash_table (finfo->info)->stab_info,
return true;
}
+
+boolean
+elf_reloc_symbol_deleted_p (offset, cookie)
+ bfd_vma offset;
+ PTR cookie;
+{
+ struct elf_reloc_cookie *rcookie = (struct elf_reloc_cookie *)cookie;
+
+ if (rcookie->bad_symtab)
+ rcookie->rel = rcookie->rels;
+
+ for (; rcookie->rel < rcookie->relend; rcookie->rel++)
+ {
+ unsigned long r_symndx = ELF_R_SYM (rcookie->rel->r_info);
+ Elf_Internal_Sym isym;
+
+ if (! rcookie->bad_symtab)
+ if (rcookie->rel->r_offset > offset)
+ return false;
+ if (rcookie->rel->r_offset != offset)
+ continue;
+
+ if (rcookie->locsyms && r_symndx < rcookie->locsymcount)
+ elf_swap_symbol_in (rcookie->abfd,
+ (Elf_External_Sym *) rcookie->locsyms + r_symndx,
+ &isym);
+
+ if (r_symndx >= rcookie->locsymcount
+ || (rcookie->locsyms
+ && ELF_ST_BIND (isym.st_info) != STB_LOCAL))
+ {
+ struct elf_link_hash_entry *h;
+
+ h = rcookie->sym_hashes[r_symndx - rcookie->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)
+ && ! bfd_is_abs_section (h->root.u.def.section)
+ && bfd_is_abs_section (h->root.u.def.section
+ ->output_section))
+ return true;
+ else
+ return false;
+ }
+ else if (rcookie->locsyms)
+ {
+ /* 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;
+
+ /* Need to: get the symbol; get the section. */
+ if (isym.st_shndx > 0 && isym.st_shndx < SHN_LORESERVE)
+ {
+ isec = section_from_elf_index (rcookie->abfd, isym.st_shndx);
+ if (isec != NULL
+ && ! bfd_is_abs_section (isec)
+ && bfd_is_abs_section (isec->output_section))
+ return true;
+ }
+ }
+ return false;
+ }
+ return false;
+}
+
+/* Discard unneeded references to discarded sections.
+ Returns true if any section's size was changed. */
+/* This function assumes that the relocations are in sorted order,
+ which is true for all known assemblers. */
+
+boolean
+elf_bfd_discard_info (info)
+ struct bfd_link_info *info;
+{
+ struct elf_reloc_cookie cookie;
+ asection *o;
+ Elf_Internal_Shdr *symtab_hdr;
+ Elf_External_Sym *freesyms;
+ struct elf_backend_data *bed;
+ bfd *abfd;
+ boolean ret = false;
+
+ if (info->relocateable
+ || info->traditional_format
+ || info->hash->creator->flavour != bfd_target_elf_flavour
+ || ! is_elf_hash_table (info)
+ || info->strip == strip_all
+ || info->strip == strip_debugger)
+ return false;
+ for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link_next)
+ {
+ if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+ continue;
+
+ bed = get_elf_backend_data (abfd);
+
+ if ((abfd->flags & DYNAMIC) != 0)
+ continue;
+
+ o = bfd_get_section_by_name (abfd, ".stab");
+ if (! o && ! bed->elf_backend_discard_info)
+ continue;
+
+ symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+
+ cookie.abfd = abfd;
+ cookie.sym_hashes = elf_sym_hashes (abfd);
+ cookie.bad_symtab = elf_bad_symtab (abfd);
+ if (cookie.bad_symtab)
+ {
+ cookie.locsymcount =
+ symtab_hdr->sh_size / sizeof (Elf_External_Sym);
+ cookie.extsymoff = 0;
+ }
+ else
+ {
+ cookie.locsymcount = symtab_hdr->sh_info;
+ cookie.extsymoff = symtab_hdr->sh_info;
+ }
+
+ freesyms = NULL;
+ if (symtab_hdr->contents)
+ cookie.locsyms = (void *) symtab_hdr->contents;
+ else if (cookie.locsymcount == 0)
+ cookie.locsyms = NULL;
+ else
+ {
+ bfd_size_type amt = cookie.locsymcount * sizeof (Elf_External_Sym);
+ cookie.locsyms = bfd_malloc (amt);
+ if (cookie.locsyms == NULL
+ || bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
+ || bfd_bread (cookie.locsyms, amt, abfd) != amt)
+ {
+ /* Something is very wrong - but we can still do our job for
+ global symbols, so don't give up. */
+ if (cookie.locsyms)
+ free (cookie.locsyms);
+ cookie.locsyms = NULL;
+ }
+ else
+ {
+ freesyms = cookie.locsyms;
+ }
+ }
+
+ if (o)
+ {
+ cookie.rels = (NAME(_bfd_elf,link_read_relocs)
+ (abfd, o, (PTR) NULL,
+ (Elf_Internal_Rela *) NULL,
+ info->keep_memory));
+ if (cookie.rels)
+ {
+ cookie.rel = cookie.rels;
+ cookie.relend =
+ cookie.rels + o->reloc_count * bed->s->int_rels_per_ext_rel;
+ if (_bfd_discard_section_stabs (abfd, o,
+ elf_section_data (o)->stab_info,
+ elf_reloc_symbol_deleted_p,
+ &cookie))
+ ret = true;
+ if (! info->keep_memory)
+ free (cookie.rels);
+ }
+ }
+
+ if (bed->elf_backend_discard_info)
+ {
+ if (bed->elf_backend_discard_info (abfd, &cookie, info))
+ ret = true;
+ }
+
+ if (freesyms)
+ free (freesyms);
+ }
+ return ret;
+}
+
+static boolean
+elf_section_ignore_discarded_relocs (sec)
+ asection *sec;
+{
+ if (strcmp (sec->name, ".stab") == 0)
+ return true;
+ else if ((get_elf_backend_data (sec->owner)
+ ->elf_backend_ignore_discarded_relocs != NULL)
+ && (*get_elf_backend_data (sec->owner)
+ ->elf_backend_ignore_discarded_relocs) (sec))
+ return true;
+ else
+ return false;
+}