Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Typedefs | Functions | Variables
elflink.c File Reference
#include "bfd.h"
#include "sysdep.h"
#include "bfdlink.h"
#include "libbfd.h"
#include "elf-bfd.h"
#include "safe-ctype.h"
#include "libiberty.h"
#include "objalloc.h"

Go to the source code of this file.

Classes

struct  collect_gnu_hash_codes
struct  elf_outext_info
struct  elf_gc_sweep_symbol_info
struct  alloc_got_off_arg

Defines

#define ARCH_SIZE   0
#define UNARY_OP(op)
#define BINARY_OP(op)
#define TEXT_PREFIX   ".text."
#define TEXT_PREFIX2   ".gnu.linkonce.t."
#define GCC_EXCEPT_TABLE_PREFIX   ".gcc_except_table."

Typedefs

typedef bfd_boolean(* gc_sweep_hook_fn )(bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *)

Functions

struct elf_link_hash_entry_bfd_elf_define_linkage_sym (bfd *abfd, struct bfd_link_info *info, asection *sec, const char *name)
bfd_boolean _bfd_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
static bfd_boolean _bfd_elf_link_create_dynstrtab (bfd *abfd, struct bfd_link_info *info)
bfd_boolean _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
bfd_boolean _bfd_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
bfd_boolean bfd_elf_link_record_dynamic_symbol (struct bfd_link_info *info, struct elf_link_hash_entry *h)
void bfd_elf_link_mark_dynamic_symbol (struct bfd_link_info *info, struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)
bfd_boolean bfd_elf_record_link_assignment (bfd *output_bfd, struct bfd_link_info *info, const char *name, bfd_boolean provide, bfd_boolean hidden)
int bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info, bfd *input_bfd, long input_indx)
long _bfd_elf_link_lookup_local_dynindx (struct bfd_link_info *info, bfd *input_bfd, long input_indx)
static bfd_boolean elf_link_renumber_hash_table_dynsyms (struct elf_link_hash_entry *h, void *data)
static bfd_boolean elf_link_renumber_local_hash_table_dynsyms (struct elf_link_hash_entry *h, void *data)
bfd_boolean _bfd_elf_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED, struct bfd_link_info *info, asection *p)
static unsigned long _bfd_elf_link_renumber_dynsyms (bfd *output_bfd, struct bfd_link_info *info, unsigned long *section_sym_count)
bfd_boolean _bfd_elf_merge_symbol (bfd *abfd, struct bfd_link_info *info, const char *name, Elf_Internal_Sym *sym, asection **psec, bfd_vma *pvalue, unsigned int *pold_alignment, struct elf_link_hash_entry **sym_hash, bfd_boolean *skip, bfd_boolean *override, bfd_boolean *type_change_ok, bfd_boolean *size_change_ok)
bfd_boolean _bfd_elf_add_default_symbol (bfd *abfd, struct bfd_link_info *info, struct elf_link_hash_entry *h, const char *name, Elf_Internal_Sym *sym, asection **psec, bfd_vma *value, bfd_boolean *dynsym, bfd_boolean override)
bfd_boolean _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
bfd_boolean _bfd_elf_link_find_version_dependencies (struct elf_link_hash_entry *h, void *data)
bfd_boolean _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry *h, void *data)
static bfd_boolean elf_link_read_relocs_from_section (bfd *abfd, asection *sec, Elf_Internal_Shdr *shdr, void *external_relocs, Elf_Internal_Rela *internal_relocs)
Elf_Internal_Rela_bfd_elf_link_read_relocs (bfd *abfd, asection *o, void *external_relocs, Elf_Internal_Rela *internal_relocs, bfd_boolean keep_memory)
bfd_boolean _bfd_elf_link_size_reloc_section (bfd *abfd, Elf_Internal_Shdr *rel_hdr, asection *o)
bfd_boolean _bfd_elf_link_output_relocs (bfd *output_bfd, asection *input_section, Elf_Internal_Shdr *input_rel_hdr, Elf_Internal_Rela *internal_relocs, struct elf_link_hash_entry **rel_hash ATTRIBUTE_UNUSED)
bfd_boolean _bfd_elf_link_hash_fixup_symbol (struct bfd_link_info *info, struct elf_link_hash_entry *h)
bfd_boolean _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry *h, struct elf_info_failed *eif)
bfd_boolean _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry *h, void *data)
bfd_boolean _bfd_elf_link_sec_merge_syms (struct elf_link_hash_entry *h, void *data)
bfd_boolean _bfd_elf_dynamic_symbol_p (struct elf_link_hash_entry *h, struct bfd_link_info *info, bfd_boolean ignore_protected)
bfd_boolean _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry *h, struct bfd_link_info *info, bfd_boolean local_protected)
struct bfd_section_bfd_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
static bfd_boolean is_global_data_symbol_definition (bfd *abfd ATTRIBUTE_UNUSED, Elf_Internal_Sym *sym)
static bfd_boolean elf_link_is_defined_archive_symbol (bfd *abfd, carsym *symdef)
bfd_boolean _bfd_elf_add_dynamic_entry (struct bfd_link_info *info, bfd_vma tag, bfd_vma val)
static int elf_add_dt_needed_tag (bfd *abfd, struct bfd_link_info *info, const char *soname, bfd_boolean do_it)
static int elf_sort_symbol (const void *arg1, const void *arg2)
static bfd_boolean elf_adjust_dynstr_offsets (struct elf_link_hash_entry *h, void *data)
static bfd_boolean elf_finalize_dynstr (bfd *output_bfd, struct bfd_link_info *info)
static bfd_boolean elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
struct elf_link_hash_entry_bfd_elf_archive_symbol_lookup (bfd *abfd, struct bfd_link_info *info, const char *name)
static bfd_boolean elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
bfd_boolean bfd_elf_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
static bfd_boolean elf_collect_hash_codes (struct elf_link_hash_entry *h, void *data)
static bfd_boolean elf_collect_gnu_hash_codes (struct elf_link_hash_entry *h, void *data)
static bfd_boolean elf_renumber_gnu_hash_syms (struct elf_link_hash_entry *h, void *data)
bfd_boolean _bfd_elf_hash_symbol (struct elf_link_hash_entry *h)
static size_t compute_bucket_count (struct bfd_link_info *info, unsigned long int *hashcodes, unsigned long int nsyms, int gnu_hash)
bfd_boolean bfd_elf_size_dynamic_sections (bfd *output_bfd, const char *soname, const char *rpath, const char *filter_shlib, const char *const *auxiliary_filters, struct bfd_link_info *info, asection **sinterpptr, struct bfd_elf_version_tree *verdefs)
void _bfd_elf_init_1_index_section (bfd *output_bfd, struct bfd_link_info *info)
void _bfd_elf_init_2_index_sections (bfd *output_bfd, struct bfd_link_info *info)
bfd_boolean bfd_elf_size_dynsym_hash_dynstr (bfd *output_bfd, struct bfd_link_info *info)
static void set_symbol_value (bfd *bfd_with_globals, struct elf_final_link_info *finfo, int symidx, bfd_vma val)
static bfd_boolean resolve_symbol (const char *name, bfd *input_bfd, struct elf_final_link_info *finfo, bfd_vma *result, size_t locsymcount)
static bfd_boolean resolve_section (const char *name, asection *sections, bfd_vma *result)
static void undefined_reference (const char *reftype, const char *name)
static bfd_boolean eval_symbol (bfd_vma *result, char *sym, char **advanced, bfd *input_bfd, struct elf_final_link_info *finfo, bfd_vma addr, bfd_vma section_offset, size_t locsymcount, int signed_p)
static bfd_boolean evaluate_complex_relocation_symbols (bfd *input_bfd, struct elf_final_link_info *finfo, size_t locsymcount)
static void put_value (bfd_vma size, unsigned long chunksz, bfd *input_bfd, bfd_vma x, bfd_byte *location)
static bfd_vma get_value (bfd_vma size, unsigned long chunksz, bfd *input_bfd, bfd_byte *location)
static void decode_complex_addend (unsigned long *start, unsigned long *oplen, unsigned long *len, unsigned long *wordsz, unsigned long *chunksz, unsigned long *lsb0_p, unsigned long *signed_p, unsigned long *trunc_p, unsigned long encoded)
void bfd_elf_perform_complex_relocation (bfd *output_bfd ATTRIBUTE_UNUSED, struct bfd_link_info *info, bfd *input_bfd, asection *input_section, bfd_byte *contents, Elf_Internal_Rela *rel, Elf_Internal_Sym *local_syms, asection **local_sections)
static void elf_link_adjust_relocs (bfd *abfd, Elf_Internal_Shdr *rel_hdr, unsigned int count, struct elf_link_hash_entry **rel_hash)
static int elf_link_sort_cmp1 (const void *A, const void *B)
static int elf_link_sort_cmp2 (const void *A, const void *B)
static size_t elf_link_sort_relocs (bfd *abfd, struct bfd_link_info *info, asection **psec)
static bfd_boolean elf_link_flush_output_syms (struct elf_final_link_info *finfo, const struct elf_backend_data *bed)
static bfd_boolean elf_link_output_sym (struct elf_final_link_info *finfo, const char *name, Elf_Internal_Sym *elfsym, asection *input_sec, struct elf_link_hash_entry *h)
static bfd_boolean check_dynsym (bfd *abfd, Elf_Internal_Sym *sym)
static bfd_boolean elf_link_check_versioned_symbol (struct bfd_link_info *info, const struct elf_backend_data *bed, struct elf_link_hash_entry *h)
static bfd_boolean elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
static bfd_boolean elf_section_ignore_discarded_relocs (asection *sec)
unsigned int _bfd_elf_default_action_discarded (asection *sec)
static asectionmatch_group_member (asection *sec, asection *group, struct bfd_link_info *info)
asection_bfd_elf_check_kept_section (asection *sec, struct bfd_link_info *info)
static bfd_boolean elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd)
static bfd_boolean elf_reloc_link_order (bfd *output_bfd, struct bfd_link_info *info, asection *output_section, struct bfd_link_order *link_order)
static bfd_vma elf_get_linked_section_vma (struct bfd_link_order *p)
static int compare_link_order (const void *a, const void *b)
static bfd_boolean elf_fixup_link_order (bfd *abfd, asection *o)
bfd_boolean bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
asection_bfd_elf_gc_mark_hook (asection *sec, struct bfd_link_info *info ATTRIBUTE_UNUSED, Elf_Internal_Rela *rel ATTRIBUTE_UNUSED, struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)
bfd_boolean _bfd_elf_gc_mark (struct bfd_link_info *info, asection *sec, elf_gc_mark_hook_fn gc_mark_hook)
static bfd_boolean elf_gc_sweep_symbol (struct elf_link_hash_entry *h, void *data)
static bfd_boolean elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
static bfd_boolean elf_gc_propagate_vtable_entries_used (struct elf_link_hash_entry *h, void *okp)
static bfd_boolean elf_gc_smash_unused_vtentry_relocs (struct elf_link_hash_entry *h, void *okp)
bfd_boolean bfd_elf_gc_mark_dynamic_ref_symbol (struct elf_link_hash_entry *h, void *inf)
bfd_boolean bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
bfd_boolean bfd_elf_gc_record_vtinherit (bfd *abfd, asection *sec, struct elf_link_hash_entry *h, bfd_vma offset)
bfd_boolean bfd_elf_gc_record_vtentry (bfd *abfd ATTRIBUTE_UNUSED, asection *sec ATTRIBUTE_UNUSED, struct elf_link_hash_entry *h, bfd_vma addend)
static bfd_boolean elf_gc_allocate_got_offsets (struct elf_link_hash_entry *h, void *arg)
bfd_boolean bfd_elf_gc_common_finalize_got_offsets (bfd *abfd, struct bfd_link_info *info)
bfd_boolean bfd_elf_gc_common_final_link (bfd *abfd, struct bfd_link_info *info)
bfd_boolean bfd_elf_reloc_symbol_deleted_p (bfd_vma offset, void *cookie)
bfd_boolean bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
void _bfd_elf_section_already_linked (bfd *abfd, struct bfd_section *sec, struct bfd_link_info *info)
bfd_boolean _bfd_elf_common_definition (Elf_Internal_Sym *sym)
unsigned int _bfd_elf_common_section_index (asection *sec ATTRIBUTE_UNUSED)
asection_bfd_elf_common_section (asection *sec ATTRIBUTE_UNUSED)

Variables

static const size_t elf_buckets []

Class Documentation

struct collect_gnu_hash_codes

Definition at line 4939 of file elflink.c.

Collaboration diagram for collect_gnu_hash_codes:
Class Members
struct elf_backend_data * bed
bfd_vma * bitmask
unsigned long int bucketcount
bfd_byte * contents
unsigned long int * counts
unsigned long int * hashcodes
unsigned long int * hashval
unsigned long int * indx
long int local_indx
unsigned long int mask
unsigned long int maskbits
long int min_dynindx
unsigned long int nsyms
bfd * output_bfd
long int shift1
long int shift2
unsigned long int symindx
struct elf_final_link_info

Definition at line 6300 of file elflink.c.

Collaboration diagram for elf_final_link_info:
Class Members
bfd_byte * contents
asection * dynsym_sec
void * external_relocs
bfd_byte * external_syms
asection * hash_sec
long * indices
struct bfd_link_info * info
Elf_Internal_Rela * internal_relocs
Elf_Internal_Sym * internal_syms
Elf_External_Sym_Shndx * locsym_shndx
bfd * output_bfd
asection ** sections
size_t shndxbuf_size
bfd_byte * symbuf
size_t symbuf_count
size_t symbuf_size
Elf_External_Sym_Shndx * symshndxbuf
struct bfd_strtab_hash * symstrtab
asection * symver_sec
struct elf_outext_info

Definition at line 6348 of file elflink.c.

Collaboration diagram for elf_outext_info:
Class Members
bfd_boolean failed
struct elf_final_link_info * finfo
bfd_boolean localsyms
struct elf_link_sort_rela

Definition at line 7133 of file elflink.c.

Class Members
union elf_link_sort_rela u
struct alloc_got_off_arg

Definition at line 10741 of file elflink.c.

Class Members
unsigned int got_elt_size
bfd_vma gotoff
union elf_link_sort_rela.u

Definition at line 7135 of file elflink.c.

Class Members
bfd_vma offset
bfd_vma sym_mask

Define Documentation

#define ARCH_SIZE   0

Definition at line 25 of file elflink.c.

#define BINARY_OP (   op)
Value:
if (strncmp (sym, #op, strlen (#op)) == 0)                     \
    {                                                   \
      sym += strlen (#op);                              \
      if (* sym == ':')                                        \
        ++ sym;                                                \
      if (eval_symbol (& a, sym, & sym, input_bfd, finfo, addr, \
                       section_offset, locsymcount, signed_p)   \
                                                     != TRUE)  \
        return FALSE;                                          \
      ++ sym;                                           \
      if (eval_symbol (& b, sym, & sym, input_bfd, finfo, addr, \
                       section_offset, locsymcount, signed_p)   \
                                                     != TRUE)  \
        return FALSE;                                          \
      if (signed_p)                                             \
        * result = ((signed) a) op ((signed) b);         \
      else                                                      \
        * result = a op b;                                      \
      * advanced = sym;                                        \
      return TRUE;                                      \
    }
#define GCC_EXCEPT_TABLE_PREFIX   ".gcc_except_table."
#define TEXT_PREFIX   ".text."
#define TEXT_PREFIX2   ".gnu.linkonce.t."
#define UNARY_OP (   op)
Value:
if (strncmp (sym, #op, strlen (#op)) == 0)                     \
    {                                                   \
      sym += strlen (#op);                              \
      if (* sym == ':')                                        \
        ++ sym;                                                \
      if (eval_symbol (& a, sym, & sym, input_bfd, finfo, addr, \
                       section_offset, locsymcount, signed_p)   \
                                                    != TRUE)   \
        return FALSE;                                          \
      if (signed_p)                                             \
        * result = op ((signed)a);                             \
      else                                                      \
        * result = op a;                                        \
      * advanced = sym;                                 \
      return TRUE;                                      \
    }

Typedef Documentation

Definition at line 10269 of file elflink.c.


Function Documentation

bfd_boolean _bfd_elf_add_default_symbol ( bfd abfd,
struct bfd_link_info info,
struct elf_link_hash_entry h,
const char *  name,
Elf_Internal_Sym *  sym,
asection **  psec,
bfd_vma value,
bfd_boolean dynsym,
bfd_boolean  override 
)

Definition at line 1432 of file elflink.c.

{
  bfd_boolean type_change_ok;
  bfd_boolean size_change_ok;
  bfd_boolean skip;
  char *shortname;
  struct elf_link_hash_entry *hi;
  struct bfd_link_hash_entry *bh;
  const struct elf_backend_data *bed;
  bfd_boolean collect;
  bfd_boolean dynamic;
  char *p;
  size_t len, shortlen;
  asection *sec;

  /* 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 definition. We need to check if we
        need to create 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;

  shortlen = p - name;
  shortname = bfd_hash_allocate (&info->hash->table, shortlen + 1);
  if (shortname == NULL)
    return FALSE;
  memcpy (shortname, name, shortlen);
  shortname[shortlen] = '\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;
  sec = *psec;
  if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
                           NULL, &hi, &skip, &override,
                           &type_change_ok, &size_change_ok))
    return FALSE;

  if (skip)
    goto nondefault;

  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;
    }
  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->def_dynamic)
       {
         h->def_dynamic = 0;
         hi->ref_dynamic = 1;
         if (hi->ref_regular
             || hi->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;
    }

  /* Check if HI is a warning symbol.  */
  if (hi->root.type == bfd_link_hash_warning)
    hi = (struct elf_link_hash_entry *) hi->root.u.i.link;

  /* 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;

      ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
      (*bed->elf_backend_copy_indirect_symbol) (info, 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->ref_dynamic)
              *dynsym = TRUE;
           }
         else
           {
             if (hi->ref_regular)
              *dynsym = TRUE;
           }
       }
    }

  /* We also need to define an indirection from the nondefault version
     of the symbol.  */

nondefault:
  len = strlen (name);
  shortname = bfd_hash_allocate (&info->hash->table, len);
  if (shortname == NULL)
    return FALSE;
  memcpy (shortname, name, shortlen);
  memcpy (shortname + shortlen, p + 1, len - shortlen);

  /* Once again, merge with any existing symbol.  */
  type_change_ok = FALSE;
  size_change_ok = FALSE;
  sec = *psec;
  if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
                           NULL, &hi, &skip, &override,
                           &type_change_ok, &size_change_ok))
    return FALSE;

  if (skip)
    return TRUE;

  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
        overridden by a versioned definition.  */
      if (hi->root.type != bfd_link_hash_defined
         && hi->root.type != bfd_link_hash_defweak)
       (*_bfd_error_handler)
         (_("%B: unexpected redefinition of indirect versioned symbol `%s'"),
          abfd, shortname);
    }
  else
    {
      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;

      /* 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);

         /* See if the new flags lead us to realize that the symbol
            must be dynamic.  */
         if (! *dynsym)
           {
             if (! dynamic)
              {
                if (info->shared
                    || hi->ref_dynamic)
                  *dynsym = TRUE;
              }
             else
              {
                if (hi->ref_regular)
                  *dynsym = TRUE;
              }
           }
       }
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2898 of file elflink.c.

{
  struct elf_link_hash_table *hash_table;
  const struct elf_backend_data *bed;
  asection *s;
  bfd_size_type newsize;
  bfd_byte *newcontents;
  Elf_Internal_Dyn dyn;

  hash_table = elf_hash_table (info);
  if (! is_elf_hash_table (hash_table))
    return FALSE;

  bed = get_elf_backend_data (hash_table->dynobj);
  s = bfd_get_section_by_name (hash_table->dynobj, ".dynamic");
  BFD_ASSERT (s != NULL);

  newsize = s->size + bed->s->sizeof_dyn;
  newcontents = bfd_realloc (s->contents, newsize);
  if (newcontents == NULL)
    return FALSE;

  dyn.d_tag = tag;
  dyn.d_un.d_val = val;
  bed->s->swap_dyn_out (hash_table->dynobj, &dyn, newcontents + s->size);

  s->size = newsize;
  s->contents = newcontents;

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2486 of file elflink.c.

{
  struct elf_info_failed *eif = data;
  bfd *dynobj;
  const struct elf_backend_data *bed;

  if (! is_elf_hash_table (eif->info->hash))
    return FALSE;

  if (h->root.type == bfd_link_hash_warning)
    {
      h->got = elf_hash_table (eif->info)->init_got_offset;
      h->plt = elf_hash_table (eif->info)->init_plt_offset;

      /* When warning symbols are created, they **replace** the "real"
        entry in the hash table, thus we never get to see the real
        symbol in a hash traversal.  So look at it now.  */
      h = (struct elf_link_hash_entry *) h->root.u.i.link;
    }

  /* Ignore indirect symbols.  These are added by the versioning code.  */
  if (h->root.type == bfd_link_hash_indirect)
    return TRUE;

  /* Fix the symbol flags.  */
  if (! _bfd_elf_fix_symbol_flags (h, eif))
    return FALSE;

  /* If this symbol does not require a PLT entry, and it is not
     defined by a dynamic object, or is not referenced by a regular
     object, ignore it.  We do have to handle a weak defined symbol,
     even if no regular object refers to it, if we decided to add it
     to the dynamic symbol table.  FIXME: Do we normally need to worry
     about symbols which are defined by one dynamic object and
     referenced by another one?  */
  if (!h->needs_plt
      && (h->def_regular
         || !h->def_dynamic
         || (!h->ref_regular
             && (h->u.weakdef == NULL || h->u.weakdef->dynindx == -1))))
    {
      h->plt = elf_hash_table (eif->info)->init_plt_offset;
      return TRUE;
    }

  /* If we've already adjusted this symbol, don't do it again.  This
     can happen via a recursive call.  */
  if (h->dynamic_adjusted)
    return TRUE;

  /* Don't look at this symbol again.  Note that we must set this
     after checking the above conditions, because we may look at a
     symbol once, decide not to do anything, and then get called
     recursively later after REF_REGULAR is set below.  */
  h->dynamic_adjusted = 1;

  /* If this is a weak definition, and we know a real definition, and
     the real symbol is not itself defined by a regular object file,
     then get a good value for the real definition.  We handle the
     real symbol first, for the convenience of the backend routine.

     Note that there is a confusing case here.  If the real definition
     is defined by a regular object file, we don't get the real symbol
     from the dynamic object, but we do get the weak symbol.  If the
     processor backend uses a COPY reloc, then if some routine in the
     dynamic object changes the real symbol, we will not see that
     change in the corresponding weak symbol.  This is the way other
     ELF linkers work as well, and seems to be a result of the shared
     library model.

     I will clarify this issue.  Most SVR4 shared libraries define the
     variable _timezone and define timezone as a weak synonym.  The
     tzset call changes _timezone.  If you write
       extern int timezone;
       int _timezone = 5;
       int main () { tzset (); printf ("%d %d\n", timezone, _timezone); }
     you might expect that, since timezone is a synonym for _timezone,
     the same number will print both times.  However, if the processor
     backend uses a COPY reloc, then actually timezone will be copied
     into your process image, and, since you define _timezone
     yourself, _timezone will not.  Thus timezone and _timezone will
     wind up at different memory locations.  The tzset call will set
     _timezone, leaving timezone unchanged.  */

  if (h->u.weakdef != NULL)
    {
      /* If we get to this point, we know there is an implicit
        reference by a regular object file via the weak symbol H.
        FIXME: Is this really true?  What if the traversal finds
        H->U.WEAKDEF before it finds H?  */
      h->u.weakdef->ref_regular = 1;

      if (! _bfd_elf_adjust_dynamic_symbol (h->u.weakdef, eif))
       return FALSE;
    }

  /* If a symbol has no type and no size and does not require a PLT
     entry, then we are probably about to do the wrong thing here: we
     are probably going to create a COPY reloc for an empty object.
     This case can arise when a shared object is built with assembly
     code, and the assembly code fails to set the symbol type.  */
  if (h->size == 0
      && h->type == STT_NOTYPE
      && !h->needs_plt)
    (*_bfd_error_handler)
      (_("warning: type and size of dynamic symbol `%s' are not defined"),
       h->root.root.string);

  dynobj = elf_hash_table (eif->info)->dynobj;
  bed = get_elf_backend_data (dynobj);
  if (! (*bed->elf_backend_adjust_dynamic_symbol) (eif->info, h))
    {
      eif->failed = TRUE;
      return FALSE;
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct elf_link_hash_entry* _bfd_elf_archive_symbol_lookup ( bfd abfd,
struct bfd_link_info info,
const char *  name 
) [read]

Definition at line 4641 of file elflink.c.

{
  struct elf_link_hash_entry *h;
  char *p, *copy;
  size_t len, first;

  h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE);
  if (h != NULL)
    return h;

  /* If this is a default version (the name contains @@), look up the
     symbol again with only one `@' as well as without the version.
     The effect is that references to the symbol with and without the
     version will be matched by the default symbol in the archive.  */

  p = strchr (name, ELF_VER_CHR);
  if (p == NULL || p[1] != ELF_VER_CHR)
    return h;

  /* First check with only one `@'.  */
  len = strlen (name);
  copy = bfd_alloc (abfd, len);
  if (copy == NULL)
    return (struct elf_link_hash_entry *) 0 - 1;

  first = p - name + 1;
  memcpy (copy, name, first);
  memcpy (copy + first, name + first + 1, len - first);

  h = elf_link_hash_lookup (elf_hash_table (info), copy, FALSE, FALSE, FALSE);
  if (h == NULL)
    {
      /* We also need to check references to the symbol without the
        version.  */
      copy[first - 1] = '\0';
      h = elf_link_hash_lookup (elf_hash_table (info), copy,
                            FALSE, FALSE, FALSE);
    }

  bfd_release (abfd, copy);
  return h;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 8015 of file elflink.c.

{
  asection *kept;

  kept = sec->kept_section;
  if (kept != NULL)
    {
      if ((kept->flags & SEC_GROUP) != 0)
       kept = match_group_member (sec, kept, info);
      if (kept != NULL && sec->size != kept->size)
       kept = NULL;
      sec->kept_section = kept;
    }
  return kept;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bfd_boolean _bfd_elf_common_definition ( Elf_Internal_Sym *  sym)

Definition at line 11240 of file elflink.c.

{
  return sym->st_shndx == SHN_COMMON;
}
asection* _bfd_elf_common_section ( asection *sec  ATTRIBUTE_UNUSED)

Definition at line 11252 of file elflink.c.

{
  return bfd_com_section_ptr;
}
unsigned int _bfd_elf_common_section_index ( asection *sec  ATTRIBUTE_UNUSED)

Definition at line 11246 of file elflink.c.

{
  return SHN_COMMON;
}

Definition at line 272 of file elflink.c.

{
  flagword flags, pltflags;
  struct elf_link_hash_entry *h;
  asection *s;
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);

  /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
     .rel[a].bss sections.  */
  flags = bed->dynamic_sec_flags;

  pltflags = flags;
  if (bed->plt_not_loaded)
    /* We do not clear SEC_ALLOC here because we still want the OS to
       allocate space for the section; it's just that there's nothing
       to read in from the object file.  */
    pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
  else
    pltflags |= SEC_ALLOC | SEC_CODE | SEC_LOAD;
  if (bed->plt_readonly)
    pltflags |= SEC_READONLY;

  s = bfd_make_section_with_flags (abfd, ".plt", pltflags);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
    return FALSE;

  /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
     .plt section.  */
  if (bed->want_plt_sym)
    {
      h = _bfd_elf_define_linkage_sym (abfd, info, s,
                                   "_PROCEDURE_LINKAGE_TABLE_");
      elf_hash_table (info)->hplt = h;
      if (h == NULL)
       return FALSE;
    }

  s = bfd_make_section_with_flags (abfd,
                               (bed->default_use_rela_p
                                ? ".rela.plt" : ".rel.plt"),
                               flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;

  if (! _bfd_elf_create_got_section (abfd, info))
    return FALSE;

  if (bed->want_dynbss)
    {
      /* The .dynbss section is a place to put symbols which are defined
        by dynamic objects, are referenced by regular objects, and are
        not functions.  We must allocate space for them in the process
        image and use a R_*_COPY reloc to tell the dynamic linker to
        initialize them at run time.  The linker script puts the .dynbss
        section into the .bss section of the final image.  */
      s = bfd_make_section_with_flags (abfd, ".dynbss",
                                   (SEC_ALLOC
                                   | SEC_LINKER_CREATED));
      if (s == NULL)
       return FALSE;

      /* The .rel[a].bss section holds copy relocs.  This section is not
        normally needed.  We need to create it here, though, so that the
        linker will map it to an output section.  We can't just create it
        only if we need it, because we will not know whether we need it
        until we have seen all the input files, and the first time the
        main linker code calls BFD after examining all the input files
        (size_dynamic_sections) the input sections have already been
        mapped to the output sections.  If the section turns out not to
        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 (! info->shared)
       {
         s = bfd_make_section_with_flags (abfd,
                                      (bed->default_use_rela_p
                                       ? ".rela.bss" : ".rel.bss"),
                                      flags | SEC_READONLY);
         if (s == NULL
             || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
           return FALSE;
       }
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 70 of file elflink.c.

{
  flagword flags;
  asection *s;
  struct elf_link_hash_entry *h;
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  int ptralign;

  /* This function may be called more than once.  */
  s = bfd_get_section_by_name (abfd, ".got");
  if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
    return TRUE;

  switch (bed->s->arch_size)
    {
    case 32:
      ptralign = 2;
      break;

    case 64:
      ptralign = 3;
      break;

    default:
      bfd_set_error (bfd_error_bad_value);
      return FALSE;
    }

  flags = bed->dynamic_sec_flags;

  s = bfd_make_section_with_flags (abfd, ".got", flags);
  if (s == NULL
      || !bfd_set_section_alignment (abfd, s, ptralign))
    return FALSE;

  if (bed->want_got_plt)
    {
      s = bfd_make_section_with_flags (abfd, ".got.plt", flags);
      if (s == NULL
         || !bfd_set_section_alignment (abfd, s, ptralign))
       return FALSE;
    }

  if (bed->want_got_sym)
    {
      /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
        (or .got.plt) section.  We don't do this in the linker script
        because we don't want to define the symbol if we are not creating
        a global offset table.  */
      h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
      elf_hash_table (info)->hgot = h;
      if (h == NULL)
       return FALSE;
    }

  /* The first bit of the global offset table is the header.  */
  s->size += bed->got_header_size;

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 7974 of file elflink.c.

{
  if (sec->flags & SEC_DEBUGGING)
    return PRETEND;

  if (strcmp (".eh_frame", sec->name) == 0)
    return 0;

  if (strcmp (".gcc_except_table", sec->name) == 0)
    return 0;

  return COMPLAIN | PRETEND;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct elf_link_hash_entry* _bfd_elf_define_linkage_sym ( bfd abfd,
struct bfd_link_info info,
asection sec,
const char *  name 
) [read]

Definition at line 34 of file elflink.c.

{
  struct elf_link_hash_entry *h;
  struct bfd_link_hash_entry *bh;
  const struct elf_backend_data *bed;

  h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE);
  if (h != NULL)
    {
      /* Zap symbol defined in an as-needed lib that wasn't linked.
        This is a symptom of a larger problem:  Absolute symbols
        defined in shared libraries can't be overridden, because we
        lose the link to the bfd which is via the symbol section.  */
      h->root.type = bfd_link_hash_new;
    }

  bh = &h->root;
  if (!_bfd_generic_link_add_one_symbol (info, abfd, name, BSF_GLOBAL,
                                    sec, 0, NULL, FALSE,
                                    get_elf_backend_data (abfd)->collect,
                                    &bh))
    return NULL;
  h = (struct elf_link_hash_entry *) bh;
  h->def_regular = 1;
  h->type = STT_OBJECT;
  h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;

  bed = get_elf_backend_data (abfd);
  (*bed->elf_backend_hide_symbol) (info, h, TRUE);
  return h;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2638 of file elflink.c.

{
  bfd_boolean binding_stays_local_p;

  if (h == NULL)
    return FALSE;

  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 it was forced local, then clearly it's not dynamic.  */
  if (h->dynindx == -1)
    return FALSE;
  if (h->forced_local)
    return FALSE;

  /* Identify the cases where name binding rules say that a
     visible symbol resolves locally.  */
  binding_stays_local_p = info->executable || SYMBOLIC_BIND (info, h);

  switch (ELF_ST_VISIBILITY (h->other))
    {
    case STV_INTERNAL:
    case STV_HIDDEN:
      return FALSE;

    case STV_PROTECTED:
      /* Proper resolution for function pointer equality may require
        that these symbols perhaps be resolved dynamically, even though
        we should be resolving them to the current module.  */
      if (!ignore_protected || h->type != STT_FUNC)
       binding_stays_local_p = TRUE;
      break;

    default:
      break;
    }

  /* If it isn't defined locally, then clearly it's dynamic.  */
  if (!h->def_regular)
    return TRUE;

  /* Otherwise, the symbol is dynamic if binding rules don't tell
     us that it remains local.  */
  return !binding_stays_local_p;
}

Here is the caller graph for this function:

Definition at line 1669 of file elflink.c.

{
  struct elf_info_failed *eif = data;

  /* Ignore this if we won't export it.  */
  if (!eif->info->export_dynamic && !h->dynamic)
    return TRUE;

  /* Ignore indirect symbols.  These are added by the versioning code.  */
  if (h->root.type == bfd_link_hash_indirect)
    return TRUE;

  if (h->root.type == bfd_link_hash_warning)
    h = (struct elf_link_hash_entry *) h->root.u.i.link;

  if (h->dynindx == -1
      && (h->def_regular
         || h->ref_regular))
    {
      struct bfd_elf_version_tree *t;
      struct bfd_elf_version_expr *d;

      for (t = eif->verdefs; t != NULL; t = t->next)
       {
         if (t->globals.list != NULL)
           {
             d = (*t->match) (&t->globals, NULL, h->root.root.string);
             if (d != NULL)
              goto doit;
           }

         if (t->locals.list != NULL)
           {
             d = (*t->match) (&t->locals, NULL, h->root.root.string);
             if (d != NULL)
              return TRUE;
           }
       }

      if (!eif->verdefs)
       {
       doit:
         if (! bfd_elf_link_record_dynamic_symbol (eif->info, h))
           {
             eif->failed = TRUE;
             return FALSE;
           }
       }
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2337 of file elflink.c.

{
  const struct elf_backend_data *bed = NULL;

  /* If this symbol was mentioned in a non-ELF file, try to set
     DEF_REGULAR and REF_REGULAR correctly.  This is the only way to
     permit a non-ELF file to correctly refer to a symbol defined in
     an ELF dynamic object.  */
  if (h->non_elf)
    {
      while (h->root.type == bfd_link_hash_indirect)
       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)
       {
         h->ref_regular = 1;
         h->ref_regular_nonweak = 1;
       }
      else
       {
         if (h->root.u.def.section->owner != NULL
             && (bfd_get_flavour (h->root.u.def.section->owner)
                == bfd_target_elf_flavour))
           {
             h->ref_regular = 1;
             h->ref_regular_nonweak = 1;
           }
         else
           h->def_regular = 1;
       }

      if (h->dynindx == -1
         && (h->def_dynamic
             || h->ref_dynamic))
       {
         if (! bfd_elf_link_record_dynamic_symbol (eif->info, h))
           {
             eif->failed = TRUE;
             return FALSE;
           }
       }
    }
  else
    {
      /* Unfortunately, NON_ELF is only correct if the symbol
        was first seen in a non-ELF file.  Fortunately, if the symbol
        was first seen in an ELF file, we're probably OK unless the
        symbol was defined in a non-ELF file.  Catch that case here.
        FIXME: We're still in trouble if the symbol was first seen in
        a dynamic object, and then later in a non-ELF regular object.  */
      if ((h->root.type == bfd_link_hash_defined
          || h->root.type == bfd_link_hash_defweak)
         && !h->def_regular
         && (h->root.u.def.section->owner != NULL
             ? (bfd_get_flavour (h->root.u.def.section->owner)
               != bfd_target_elf_flavour)
             : (bfd_is_abs_section (h->root.u.def.section)
               && !h->def_dynamic)))
       h->def_regular = 1;
    }

  /* Backend specific symbol fixup.  */
  if (elf_hash_table (eif->info)->dynobj)
    {
      bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
      if (bed->elf_backend_fixup_symbol
         && !(*bed->elf_backend_fixup_symbol) (eif->info, h))
       return FALSE;
    }

  /* If this is a final link, and the symbol was defined as a common
     symbol in a regular object file, and there was no definition in
     any dynamic object, then the linker will have allocated space for
     the symbol in a common section but the DEF_REGULAR
     flag will not have been set.  */
  if (h->root.type == bfd_link_hash_defined
      && !h->def_regular
      && h->ref_regular
      && !h->def_dynamic
      && (h->root.u.def.section->owner->flags & DYNAMIC) == 0)
    h->def_regular = 1;

  /* 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
      && eif->info->shared
      && 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;

      force_local = (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
                   || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN);
      (*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)
    {
      const struct elf_backend_data *bed;
      bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
      (*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->u.weakdef != NULL)
    {
      struct elf_link_hash_entry *weakdef;

      weakdef = h->u.weakdef;
      if (h->root.type == bfd_link_hash_indirect)
       h = (struct elf_link_hash_entry *) h->root.u.i.link;

      BFD_ASSERT (h->root.type == bfd_link_hash_defined
                || h->root.type == bfd_link_hash_defweak);
      BFD_ASSERT (weakdef->root.type == bfd_link_hash_defined
                || weakdef->root.type == bfd_link_hash_defweak);
      BFD_ASSERT (weakdef->def_dynamic);

      /* If the real definition is defined by a regular object file,
        don't do anything special.  See the longer description in
        _bfd_elf_adjust_dynamic_symbol, below.  */
      if (weakdef->def_regular)
       h->u.weakdef = NULL;
      else
       (*bed->elf_backend_copy_indirect_symbol) (eif->info, weakdef,
                                            h);
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 10118 of file elflink.c.

{
  bfd_boolean ret;
  bfd_boolean is_eh;
  asection *group_sec;

  sec->gc_mark = 1;

  /* Mark all the sections in the group.  */
  group_sec = elf_section_data (sec)->next_in_group;
  if (group_sec && !group_sec->gc_mark)
    if (!_bfd_elf_gc_mark (info, group_sec, gc_mark_hook))
      return FALSE;

  /* Look through the section relocs.  */
  ret = TRUE;
  is_eh = strcmp (sec->name, ".eh_frame") == 0;
  if ((sec->flags & SEC_RELOC) != 0 && sec->reloc_count > 0)
    {
      Elf_Internal_Rela *relstart, *rel, *relend;
      Elf_Internal_Shdr *symtab_hdr;
      struct elf_link_hash_entry **sym_hashes;
      size_t nlocsyms;
      size_t extsymoff;
      bfd *input_bfd = sec->owner;
      const struct elf_backend_data *bed = get_elf_backend_data (input_bfd);
      Elf_Internal_Sym *isym = NULL;
      int r_sym_shift;

      symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
      sym_hashes = elf_sym_hashes (input_bfd);

      /* Read the local symbols.  */
      if (elf_bad_symtab (input_bfd))
       {
         nlocsyms = symtab_hdr->sh_size / bed->s->sizeof_sym;
         extsymoff = 0;
       }
      else
       extsymoff = nlocsyms = symtab_hdr->sh_info;

      isym = (Elf_Internal_Sym *) symtab_hdr->contents;
      if (isym == NULL && nlocsyms != 0)
       {
         isym = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, nlocsyms, 0,
                                   NULL, NULL, NULL);
         if (isym == NULL)
           return FALSE;
       }

      /* Read the relocations.  */
      relstart = _bfd_elf_link_read_relocs (input_bfd, sec, NULL, NULL,
                                       info->keep_memory);
      if (relstart == NULL)
       {
         ret = FALSE;
         goto out1;
       }
      relend = relstart + sec->reloc_count * bed->s->int_rels_per_ext_rel;

      if (bed->s->arch_size == 32)
       r_sym_shift = 8;
      else
       r_sym_shift = 32;

      for (rel = relstart; rel < relend; rel++)
       {
         unsigned long r_symndx;
         asection *rsec;
         struct elf_link_hash_entry *h;

         r_symndx = rel->r_info >> r_sym_shift;
         if (r_symndx == 0)
           continue;

         if (r_symndx >= nlocsyms
             || ELF_ST_BIND (isym[r_symndx].st_info) != STB_LOCAL)
           {
             h = sym_hashes[r_symndx - 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;
             rsec = (*gc_mark_hook) (sec, info, rel, h, NULL);
           }
         else
           {
             rsec = (*gc_mark_hook) (sec, info, rel, NULL, &isym[r_symndx]);
           }

         if (rsec && !rsec->gc_mark)
           {
             if (bfd_get_flavour (rsec->owner) != bfd_target_elf_flavour)
              rsec->gc_mark = 1;
             else if (is_eh)
              rsec->gc_mark_from_eh = 1;
             else if (!_bfd_elf_gc_mark (info, rsec, gc_mark_hook))
              {
                ret = FALSE;
                goto out2;
              }
           }
       }

    out2:
      if (elf_section_data (sec)->relocs != relstart)
       free (relstart);
    out1:
      if (isym != NULL && symtab_hdr->contents != (unsigned char *) isym)
       {
         if (! info->keep_memory)
           free (isym);
         else
           symtab_hdr->contents = (unsigned char *) isym;
       }
    }

  return ret;
}

Here is the call graph for this function:

asection* _bfd_elf_gc_mark_hook ( asection sec,
struct bfd_link_info *info  ATTRIBUTE_UNUSED,
Elf_Internal_Rela *rel  ATTRIBUTE_UNUSED,
struct elf_link_hash_entry h,
Elf_Internal_Sym *  sym 
)

Definition at line 10086 of file elflink.c.

{
  if (h != NULL)
    {
      switch (h->root.type)
       {
       case bfd_link_hash_defined:
       case bfd_link_hash_defweak:
         return h->root.u.def.section;

       case bfd_link_hash_common:
         return h->root.u.c.p->section;

       default:
         break;
       }
    }
  else
    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);

  return NULL;
}

Here is the call graph for this function:

Definition at line 5054 of file elflink.c.

{
  return !(h->forced_local
          || h->root.type == bfd_link_hash_undefined
          || h->root.type == bfd_link_hash_undefweak
          || ((h->root.type == bfd_link_hash_defined
              || h->root.type == bfd_link_hash_defweak)
              && h->root.u.def.section->output_section == NULL));
}

Here is the caller graph for this function:

void _bfd_elf_init_1_index_section ( bfd output_bfd,
struct bfd_link_info info 
)

Definition at line 5963 of file elflink.c.

{
  asection *s;

  for (s = output_bfd->sections; s != NULL; s = s->next)
    if ((s->flags & (SEC_EXCLUDE | SEC_ALLOC)) == SEC_ALLOC
       && !_bfd_elf_link_omit_section_dynsym (output_bfd, info, s))
      {
       elf_hash_table (info)->text_index_section = s;
       break;
      }
}

Here is the call graph for this function:

void _bfd_elf_init_2_index_sections ( bfd output_bfd,
struct bfd_link_info info 
)

Definition at line 5979 of file elflink.c.

{
  asection *s;

  for (s = output_bfd->sections; s != NULL; s = s->next)
    if (((s->flags & (SEC_EXCLUDE | SEC_ALLOC | SEC_READONLY))
        == (SEC_ALLOC | SEC_READONLY))
       && !_bfd_elf_link_omit_section_dynsym (output_bfd, info, s))
      {
       elf_hash_table (info)->text_index_section = s;
       break;
      }

  for (s = output_bfd->sections; s != NULL; s = s->next)
    if (((s->flags & (SEC_EXCLUDE | SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
       && !_bfd_elf_link_omit_section_dynsym (output_bfd, info, s))
      {
       elf_hash_table (info)->data_index_section = s;
       break;
      }

  if (elf_hash_table (info)->text_index_section == NULL)
    elf_hash_table (info)->text_index_section
      = elf_hash_table (info)->data_index_section;
}

Here is the call graph for this function:

Definition at line 1805 of file elflink.c.

{
  struct elf_assign_sym_version_info *sinfo;
  struct bfd_link_info *info;
  const struct elf_backend_data *bed;
  struct elf_info_failed eif;
  char *p;
  bfd_size_type amt;

  sinfo = data;
  info = sinfo->info;

  if (h->root.type == bfd_link_hash_warning)
    h = (struct elf_link_hash_entry *) h->root.u.i.link;

  /* Fix the symbol flags.  */
  eif.failed = FALSE;
  eif.info = info;
  if (! _bfd_elf_fix_symbol_flags (h, &eif))
    {
      if (eif.failed)
       sinfo->failed = TRUE;
      return FALSE;
    }

  /* We only need version numbers for symbols defined in regular
     objects.  */
  if (!h->def_regular)
    return TRUE;

  bed = get_elf_backend_data (sinfo->output_bfd);
  p = strchr (h->root.root.string, ELF_VER_CHR);
  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;
       }

      /* If there is no version string, we can just return out.  */
      if (*p == '\0')
       {
         if (hidden)
           h->hidden = 1;
         return TRUE;
       }

      /* Look for the version.  If we find it, it is no longer weak.  */
      for (t = sinfo->verdefs; t != NULL; t = t->next)
       {
         if (strcmp (t->name, p) == 0)
           {
             size_t len;
             char *alc;
             struct bfd_elf_version_expr *d;

             len = p - h->root.root.string;
             alc = bfd_malloc (len);
             if (alc == NULL)
              return FALSE;
             memcpy (alc, h->root.root.string, len - 1);
             alc[len - 1] = '\0';
             if (alc[len - 2] == ELF_VER_CHR)
              alc[len - 2] = '\0';

             h->verinfo.vertree = t;
             t->used = TRUE;
             d = NULL;

             if (t->globals.list != NULL)
              d = (*t->match) (&t->globals, NULL, alc);

             /* See if there is anything to force this symbol to
               local scope.  */
             if (d == NULL && t->locals.list != NULL)
              {
                d = (*t->match) (&t->locals, NULL, alc);
                if (d != NULL
                    && h->dynindx != -1
                    && ! info->export_dynamic)
                  (*bed->elf_backend_hide_symbol) (info, h, TRUE);
              }

             free (alc);
             break;
           }
       }

      /* If we are building an application, we need to create a
        version node for this version.  */
      if (t == NULL && info->executable)
       {
         struct bfd_elf_version_tree **pp;
         int version_index;

         /* If we aren't going to export this symbol, we don't need
            to worry about it.  */
         if (h->dynindx == -1)
           return TRUE;

         amt = sizeof *t;
         t = bfd_zalloc (sinfo->output_bfd, amt);
         if (t == NULL)
           {
             sinfo->failed = TRUE;
             return FALSE;
           }

         t->name = p;
         t->name_indx = (unsigned int) -1;
         t->used = TRUE;

         version_index = 1;
         /* Don't count anonymous version tag.  */
         if (sinfo->verdefs != NULL && sinfo->verdefs->vernum == 0)
           version_index = 0;
         for (pp = &sinfo->verdefs; *pp != NULL; pp = &(*pp)->next)
           ++version_index;
         t->vernum = version_index;

         *pp = t;

         h->verinfo.vertree = t;
       }
      else if (t == NULL)
       {
         /* We could not find the version for a symbol when
            generating a shared archive.  Return an error.  */
         (*_bfd_error_handler)
           (_("%B: undefined versioned symbol name %s"),
            sinfo->output_bfd, h->root.root.string);
         bfd_set_error (bfd_error_bad_value);
         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
     something.  */
  if (h->verinfo.vertree == NULL && sinfo->verdefs != NULL)
    {
      struct bfd_elf_version_tree *t;
      struct bfd_elf_version_tree *local_ver;
      struct bfd_elf_version_expr *d;

      /* See if can find what version this symbol is in.  If the
        symbol is supposed to be local, then don't actually register
        it.  */
      local_ver = NULL;
      for (t = sinfo->verdefs; t != NULL; t = t->next)
       {
         if (t->globals.list != NULL)
           {
             bfd_boolean matched;

             matched = FALSE;
             d = NULL;
             while ((d = (*t->match) (&t->globals, d,
                                   h->root.root.string)) != NULL)
              if (d->symver)
                matched = TRUE;
              else
                {
                  /* There is a version without definition.  Make
                     the symbol the default definition for this
                     version.  */
                  h->verinfo.vertree = t;
                  local_ver = NULL;
                  d->script = 1;
                  break;
                }
             if (d != NULL)
              break;
             else if (matched)
              /* There is no undefined version for this symbol. Hide the
                 default one.  */
              (*bed->elf_backend_hide_symbol) (info, h, TRUE);
           }

         if (t->locals.list != NULL)
           {
             d = NULL;
             while ((d = (*t->match) (&t->locals, d,
                                   h->root.root.string)) != NULL)
              {
                local_ver = t;
                /* If the match is "*", keep looking for a more
                   explicit, perhaps even global, match.
                   XXX: Shouldn't this be !d->wildcard instead?  */
                if (d->pattern[0] != '*' || d->pattern[1] != '\0')
                  break;
              }

             if (d != NULL)
              break;
           }
       }

      if (local_ver != NULL)
       {
         h->verinfo.vertree = local_ver;
         if (h->dynindx != -1
             && ! info->export_dynamic)
           {
             (*bed->elf_backend_hide_symbol) (info, h, TRUE);
           }
       }
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 158 of file elflink.c.

{
  flagword flags;
  register asection *s;
  const struct elf_backend_data *bed;

  if (! is_elf_hash_table (info->hash))
    return FALSE;

  if (elf_hash_table (info)->dynamic_sections_created)
    return TRUE;

  if (!_bfd_elf_link_create_dynstrtab (abfd, info))
    return FALSE;

  abfd = elf_hash_table (info)->dynobj;
  bed = get_elf_backend_data (abfd);

  flags = bed->dynamic_sec_flags;

  /* A dynamically linked executable has a .interp section, but a
     shared library does not.  */
  if (info->executable)
    {
      s = bfd_make_section_with_flags (abfd, ".interp",
                                   flags | SEC_READONLY);
      if (s == NULL)
       return FALSE;
    }

  /* Create sections to hold version informations.  These are removed
     if they are not needed.  */
  s = bfd_make_section_with_flags (abfd, ".gnu.version_d",
                               flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;

  s = bfd_make_section_with_flags (abfd, ".gnu.version",
                               flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, 1))
    return FALSE;

  s = bfd_make_section_with_flags (abfd, ".gnu.version_r",
                               flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;

  s = bfd_make_section_with_flags (abfd, ".dynsym",
                               flags | SEC_READONLY);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;

  s = bfd_make_section_with_flags (abfd, ".dynstr",
                               flags | SEC_READONLY);
  if (s == NULL)
    return FALSE;

  s = bfd_make_section_with_flags (abfd, ".dynamic", flags);
  if (s == NULL
      || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
    return FALSE;

  /* The special symbol _DYNAMIC is always set to the start of the
     .dynamic section.  We could set _DYNAMIC in a linker script, but we
     only want to define it if we are, in fact, creating a .dynamic
     section.  We don't want to define it if there is no .dynamic
     section, since on some ELF platforms the start up code examines it
     to decide how to initialize the process.  */
  if (!_bfd_elf_define_linkage_sym (abfd, info, s, "_DYNAMIC"))
    return FALSE;

  if (info->emit_hash)
    {
      s = bfd_make_section_with_flags (abfd, ".hash", flags | SEC_READONLY);
      if (s == NULL
         || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
       return FALSE;
      elf_section_data (s)->this_hdr.sh_entsize = bed->s->sizeof_hash_entry;
    }

  if (info->emit_gnu_hash)
    {
      s = bfd_make_section_with_flags (abfd, ".gnu.hash",
                                   flags | SEC_READONLY);
      if (s == NULL
         || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
       return FALSE;
      /* For 64-bit ELF, .gnu.hash is a non-uniform entity size section:
        4 32-bit words followed by variable count of 64-bit words, then
        variable count of 32-bit words.  */
      if (bed->s->arch_size == 64)
       elf_section_data (s)->this_hdr.sh_entsize = 0;
      else
       elf_section_data (s)->this_hdr.sh_entsize = 4;
    }

  /* Let the backend create the rest of the sections.  This lets the
     backend set the right flags.  The backend will normally create
     the .got and .plt sections.  */
  if (! (*bed->elf_backend_create_dynamic_sections) (abfd, info))
    return FALSE;

  elf_hash_table (info)->dynamic_sections_created = TRUE;

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean _bfd_elf_link_create_dynstrtab ( bfd abfd,
struct bfd_link_info info 
) [static]

Definition at line 133 of file elflink.c.

{
  struct elf_link_hash_table *hash_table;

  hash_table = elf_hash_table (info);
  if (hash_table->dynobj == NULL)
    hash_table->dynobj = abfd;

  if (hash_table->dynstr == NULL)
    {
      hash_table->dynstr = _bfd_elf_strtab_init ();
      if (hash_table->dynstr == NULL)
       return FALSE;
    }
  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1728 of file elflink.c.

{
  struct elf_find_verdep_info *rinfo = data;
  Elf_Internal_Verneed *t;
  Elf_Internal_Vernaux *a;
  bfd_size_type amt;

  if (h->root.type == bfd_link_hash_warning)
    h = (struct elf_link_hash_entry *) h->root.u.i.link;

  /* We only care about symbols defined in shared objects with version
     information.  */
  if (!h->def_dynamic
      || h->def_regular
      || h->dynindx == -1
      || h->verinfo.verdef == NULL)
    return TRUE;

  /* See if we already know about this version.  */
  for (t = elf_tdata (rinfo->output_bfd)->verref; t != NULL; t = t->vn_nextref)
    {
      if (t->vn_bfd != h->verinfo.verdef->vd_bfd)
       continue;

      for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
       if (a->vna_nodename == h->verinfo.verdef->vd_nodename)
         return TRUE;

      break;
    }

  /* This is a new version.  Add it to tree we are building.  */

  if (t == NULL)
    {
      amt = sizeof *t;
      t = bfd_zalloc (rinfo->output_bfd, amt);
      if (t == NULL)
       {
         rinfo->failed = TRUE;
         return FALSE;
       }

      t->vn_bfd = h->verinfo.verdef->vd_bfd;
      t->vn_nextref = elf_tdata (rinfo->output_bfd)->verref;
      elf_tdata (rinfo->output_bfd)->verref = t;
    }

  amt = sizeof *a;
  a = bfd_zalloc (rinfo->output_bfd, amt);

  /* Note that we are copying a string pointer here, and testing it
     above.  If bfd_elf_string_from_elf_section is ever changed to
     discard the string data when low in memory, this will have to be
     fixed.  */
  a->vna_nodename = h->verinfo.verdef->vd_nodename;

  a->vna_flags = h->verinfo.verdef->vd_flags;
  a->vna_nextptr = t->vn_auxptr;

  h->verinfo.verdef->vd_exp_refno = rinfo->vers;
  ++rinfo->vers;

  a->vna_other = h->verinfo.verdef->vd_exp_refno + 1;

  t->vn_auxptr = a;

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2319 of file elflink.c.

{
  if (info->pie
      && h->dynindx == -1
      && h->root.type == bfd_link_hash_undefweak)
    return bfd_elf_link_record_dynamic_symbol (info, h);

  return TRUE;
}

Here is the call graph for this function:

long _bfd_elf_link_lookup_local_dynindx ( struct bfd_link_info info,
bfd input_bfd,
long  input_indx 
)

Definition at line 650 of file elflink.c.

{
  struct elf_link_local_dynamic_entry *e;

  for (e = elf_hash_table (info)->dynlocal; e ; e = e->next)
    if (e->input_bfd == input_bfd && e->input_indx == input_indx)
      return e->dynindx;
  return -1;
}

Here is the caller graph for this function:

Definition at line 709 of file elflink.c.

{
  struct elf_link_hash_table *htab;

  switch (elf_section_data (p)->this_hdr.sh_type)
    {
    case SHT_PROGBITS:
    case SHT_NOBITS:
      /* If sh_type is yet undecided, assume it could be
        SHT_PROGBITS/SHT_NOBITS.  */
    case SHT_NULL:
      htab = elf_hash_table (info);
      if (p == htab->tls_sec)
       return FALSE;

      if (htab->text_index_section != NULL)
       return p != htab->text_index_section && p != htab->data_index_section;

      if (strcmp (p->name, ".got") == 0
         || strcmp (p->name, ".got.plt") == 0
         || strcmp (p->name, ".plt") == 0)
       {
         asection *ip;

         if (htab->dynobj != NULL
             && (ip = bfd_get_section_by_name (htab->dynobj, p->name)) != NULL
             && (ip->flags & SEC_LINKER_CREATED)
             && ip->output_section == p)
           return TRUE;
       }
      return FALSE;

      /* There shouldn't be section relative relocations
        against any other section.  */
    default:
      return TRUE;
    }
}

Here is the call graph for this function:

bfd_boolean _bfd_elf_link_output_relocs ( bfd output_bfd,
asection input_section,
Elf_Internal_Shdr input_rel_hdr,
Elf_Internal_Rela internal_relocs,
struct elf_link_hash_entry **rel_hash  ATTRIBUTE_UNUSED 
)

Definition at line 2248 of file elflink.c.

{
  Elf_Internal_Rela *irela;
  Elf_Internal_Rela *irelaend;
  bfd_byte *erel;
  Elf_Internal_Shdr *output_rel_hdr;
  asection *output_section;
  unsigned int *rel_countp = NULL;
  const struct elf_backend_data *bed;
  void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);

  output_section = input_section->output_section;
  output_rel_hdr = NULL;

  if (elf_section_data (output_section)->rel_hdr.sh_entsize
      == input_rel_hdr->sh_entsize)
    {
      output_rel_hdr = &elf_section_data (output_section)->rel_hdr;
      rel_countp = &elf_section_data (output_section)->rel_count;
    }
  else if (elf_section_data (output_section)->rel_hdr2
          && (elf_section_data (output_section)->rel_hdr2->sh_entsize
              == input_rel_hdr->sh_entsize))
    {
      output_rel_hdr = elf_section_data (output_section)->rel_hdr2;
      rel_countp = &elf_section_data (output_section)->rel_count2;
    }
  else
    {
      (*_bfd_error_handler)
       (_("%B: relocation size mismatch in %B section %A"),
        output_bfd, input_section->owner, input_section);
      bfd_set_error (bfd_error_wrong_object_format);
      return FALSE;
    }

  bed = get_elf_backend_data (output_bfd);
  if (input_rel_hdr->sh_entsize == bed->s->sizeof_rel)
    swap_out = bed->s->swap_reloc_out;
  else if (input_rel_hdr->sh_entsize == bed->s->sizeof_rela)
    swap_out = bed->s->swap_reloca_out;
  else
    abort ();

  erel = output_rel_hdr->contents;
  erel += *rel_countp * input_rel_hdr->sh_entsize;
  irela = internal_relocs;
  irelaend = irela + (NUM_SHDR_ENTRIES (input_rel_hdr)
                    * bed->s->int_rels_per_ext_rel);
  while (irela < irelaend)
    {
      (*swap_out) (output_bfd, irela, erel);
      irela += bed->s->int_rels_per_ext_rel;
      erel += input_rel_hdr->sh_entsize;
    }

  /* Bump the counter, so that we know where to add the next set of
     relocations.  */
  *rel_countp += NUM_SHDR_ENTRIES (input_rel_hdr);

  return TRUE;
}

Here is the call graph for this function:

Elf_Internal_Rela* _bfd_elf_link_read_relocs ( bfd abfd,
asection o,
void *  external_relocs,
Elf_Internal_Rela internal_relocs,
bfd_boolean  keep_memory 
)

Definition at line 2116 of file elflink.c.

{
  Elf_Internal_Shdr *rel_hdr;
  void *alloc1 = NULL;
  Elf_Internal_Rela *alloc2 = NULL;
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);

  if (elf_section_data (o)->relocs != NULL)
    return elf_section_data (o)->relocs;

  if (o->reloc_count == 0)
    return NULL;

  rel_hdr = &elf_section_data (o)->rel_hdr;

  if (internal_relocs == NULL)
    {
      bfd_size_type size;

      size = o->reloc_count;
      size *= bed->s->int_rels_per_ext_rel * sizeof (Elf_Internal_Rela);
      if (keep_memory)
       internal_relocs = bfd_alloc (abfd, size);
      else
       internal_relocs = alloc2 = bfd_malloc (size);
      if (internal_relocs == NULL)
       goto error_return;
    }

  if (external_relocs == NULL)
    {
      bfd_size_type size = rel_hdr->sh_size;

      if (elf_section_data (o)->rel_hdr2)
       size += elf_section_data (o)->rel_hdr2->sh_size;
      alloc1 = bfd_malloc (size);
      if (alloc1 == NULL)
       goto error_return;
      external_relocs = alloc1;
    }

  if (!elf_link_read_relocs_from_section (abfd, o, rel_hdr,
                                     external_relocs,
                                     internal_relocs))
    goto error_return;
  if (elf_section_data (o)->rel_hdr2
      && (!elf_link_read_relocs_from_section
         (abfd, o,
          elf_section_data (o)->rel_hdr2,
          ((bfd_byte *) external_relocs) + rel_hdr->sh_size,
          internal_relocs + (NUM_SHDR_ENTRIES (rel_hdr)
                           * bed->s->int_rels_per_ext_rel))))
    goto error_return;

  /* Cache the results for next time, if we can.  */
  if (keep_memory)
    elf_section_data (o)->relocs = internal_relocs;

  if (alloc1 != NULL)
    free (alloc1);

  /* Don't free alloc2, since if it was allocated we are passing it
     back (under the name of internal_relocs).  */

  return internal_relocs;

 error_return:
  if (alloc1 != NULL)
    free (alloc1);
  if (alloc2 != NULL)
    free (alloc2);
  return NULL;
}

Here is the call graph for this function:

static unsigned long _bfd_elf_link_renumber_dynsyms ( bfd output_bfd,
struct bfd_link_info info,
unsigned long section_sym_count 
) [static]

Definition at line 757 of file elflink.c.

{
  unsigned long dynsymcount = 0;

  if (info->shared || elf_hash_table (info)->is_relocatable_executable)
    {
      const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
      asection *p;
      for (p = output_bfd->sections; p ; p = p->next)
       if ((p->flags & SEC_EXCLUDE) == 0
           && (p->flags & SEC_ALLOC) != 0
           && !(*bed->elf_backend_omit_section_dynsym) (output_bfd, info, p))
         elf_section_data (p)->dynindx = ++dynsymcount;
       else
         elf_section_data (p)->dynindx = 0;
    }
  *section_sym_count = dynsymcount;

  elf_link_hash_traverse (elf_hash_table (info),
                       elf_link_renumber_local_hash_table_dynsyms,
                       &dynsymcount);

  if (elf_hash_table (info)->dynlocal)
    {
      struct elf_link_local_dynamic_entry *p;
      for (p = elf_hash_table (info)->dynlocal; p ; p = p->next)
       p->dynindx = ++dynsymcount;
    }

  elf_link_hash_traverse (elf_hash_table (info),
                       elf_link_renumber_hash_table_dynsyms,
                       &dynsymcount);

  /* There is an unused NULL entry at the head of the table which
     we must account for in our count.  Unless there weren't any
     symbols, which means we'll have no table at all.  */
  if (dynsymcount != 0)
    ++dynsymcount;

  elf_hash_table (info)->dynsymcount = dynsymcount;
  return dynsymcount;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2609 of file elflink.c.

{
  asection *sec;

  if (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)
      && ((sec = h->root.u.def.section)->flags & SEC_MERGE)
      && sec->sec_info_type == ELF_INFO_TYPE_MERGE)
    {
      bfd *output_bfd = data;

      h->root.u.def.value =
       _bfd_merged_section_offset (output_bfd,
                                &h->root.u.def.section,
                                elf_section_data (sec)->sec_info,
                                h->root.u.def.value);
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2198 of file elflink.c.

{
  bfd_size_type reloc_count;
  bfd_size_type num_rel_hashes;

  /* Figure out how many relocations there will be.  */
  if (rel_hdr == &elf_section_data (o)->rel_hdr)
    reloc_count = elf_section_data (o)->rel_count;
  else
    reloc_count = elf_section_data (o)->rel_count2;

  num_rel_hashes = o->reloc_count;
  if (num_rel_hashes < reloc_count)
    num_rel_hashes = reloc_count;

  /* That allows us to calculate the size of the section.  */
  rel_hdr->sh_size = rel_hdr->sh_entsize * reloc_count;

  /* The contents field must last into write_object_contents, so we
     allocate it with bfd_alloc rather than malloc.  Also since we
     cannot be sure that the contents will actually be filled in,
     we zero the allocated space.  */
  rel_hdr->contents = bfd_zalloc (abfd, rel_hdr->sh_size);
  if (rel_hdr->contents == NULL && rel_hdr->sh_size != 0)
    return FALSE;

  /* We only allocate one set of hash entries, so we only do it the
     first time we are called.  */
  if (elf_section_data (o)->rel_hashes == NULL
      && num_rel_hashes)
    {
      struct elf_link_hash_entry **p;

      p = bfd_zmalloc (num_rel_hashes * sizeof (struct elf_link_hash_entry *));
      if (p == NULL)
       return FALSE;

      elf_section_data (o)->rel_hashes = p;
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bfd_boolean _bfd_elf_merge_symbol ( bfd abfd,
struct bfd_link_info info,
const char *  name,
Elf_Internal_Sym *  sym,
asection **  psec,
bfd_vma pvalue,
unsigned int pold_alignment,
struct elf_link_hash_entry **  sym_hash,
bfd_boolean skip,
bfd_boolean override,
bfd_boolean type_change_ok,
bfd_boolean size_change_ok 
)

Definition at line 815 of file elflink.c.

{
  asection *sec, *oldsec;
  struct elf_link_hash_entry *h;
  struct elf_link_hash_entry *flip;
  int bind;
  bfd *oldbfd;
  bfd_boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon;
  bfd_boolean newweak, oldweak;
  const struct elf_backend_data *bed;

  *skip = FALSE;
  *override = FALSE;

  sec = *psec;
  bind = ELF_ST_BIND (sym->st_info);

  /* Silently discard TLS symbols from --just-syms.  There's no way to
     combine a static TLS block with a new TLS block for this executable.  */
  if (ELF_ST_TYPE (sym->st_info) == STT_TLS
      && sec->sec_info_type == ELF_INFO_TYPE_JUST_SYMS)
    {
      *skip = TRUE;
      return TRUE;
    }

  if (! bfd_is_und_section (sec))
    h = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, FALSE, FALSE);
  else
    h = ((struct elf_link_hash_entry *)
        bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, FALSE, FALSE));
  if (h == NULL)
    return FALSE;
  *sym_hash = h;

  /* This code is for coping with dynamic objects, and is only useful
     if we are doing an ELF link.  */
  if (info->hash->creator != abfd->xvec)
    return TRUE;

  /* For merging, we only care about real symbols.  */

  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;

  /* We have to check it for every instance since the first few may be
     refereences and not all compilers emit symbol type for undefined
     symbols.  */
  bfd_elf_link_mark_dynamic_symbol (info, h, sym);

  /* If we just created the symbol, mark it as being an ELF symbol.
     Other than that, there is nothing to do--there is no merge issue
     with a newly defined symbol--so we just return.  */

  if (h->root.type == bfd_link_hash_new)
    {
      h->non_elf = 0;
      return TRUE;
    }

  /* OLDBFD and OLDSEC are a BFD and an ASECTION associated with the
     existing symbol.  */

  switch (h->root.type)
    {
    default:
      oldbfd = NULL;
      oldsec = NULL;
      break;

    case bfd_link_hash_undefined:
    case bfd_link_hash_undefweak:
      oldbfd = h->root.u.undef.abfd;
      oldsec = NULL;
      break;

    case bfd_link_hash_defined:
    case bfd_link_hash_defweak:
      oldbfd = h->root.u.def.section->owner;
      oldsec = h->root.u.def.section;
      break;

    case bfd_link_hash_common:
      oldbfd = h->root.u.c.p->section->owner;
      oldsec = h->root.u.c.p->section;
      break;
    }

  /* In cases involving weak versioned symbols, we may wind up trying
     to merge a symbol with itself.  Catch that here, to avoid the
     confusion that results if we try to override a symbol with
     itself.  The additional tests catch cases like
     _GLOBAL_OFFSET_TABLE_, which are regular symbols defined in a
     dynamic object, which we do want to handle here.  */
  if (abfd == oldbfd
      && ((abfd->flags & DYNAMIC) == 0
         || !h->def_regular))
    return TRUE;

  /* NEWDYN and OLDDYN indicate whether the new or old symbol,
     respectively, is from a dynamic object.  */

  newdyn = (abfd->flags & DYNAMIC) != 0;

  olddyn = FALSE;
  if (oldbfd != NULL)
    olddyn = (oldbfd->flags & DYNAMIC) != 0;
  else if (oldsec != NULL)
    {
      /* This handles the special SHN_MIPS_{TEXT,DATA} section
        indices used by MIPS ELF.  */
      olddyn = (oldsec->symbol->flags & BSF_DYNAMIC) != 0;
    }

  /* NEWDEF and OLDDEF indicate whether the new or old symbol,
     respectively, appear to be a definition rather than reference.  */

  newdef = !bfd_is_und_section (sec) && !bfd_is_com_section (sec);

  olddef = (h->root.type != bfd_link_hash_undefined
           && h->root.type != bfd_link_hash_undefweak
           && h->root.type != bfd_link_hash_common);

  /* When we try to create a default indirect symbol from the dynamic
     definition with the default version, we skip it if its type and
     the type of existing regular definition mismatch.  We only do it
     if the existing regular definition won't be dynamic.  */
  if (pold_alignment == NULL
      && !info->shared
      && !info->export_dynamic
      && !h->ref_dynamic
      && newdyn
      && newdef
      && !olddyn
      && (olddef || h->root.type == bfd_link_hash_common)
      && ELF_ST_TYPE (sym->st_info) != h->type
      && ELF_ST_TYPE (sym->st_info) != STT_NOTYPE
      && h->type != STT_NOTYPE)
    {
      *skip = TRUE;
      return TRUE;
    }

  /* Check TLS symbol.  We don't check undefined symbol introduced by
     "ld -u".  */
  if ((ELF_ST_TYPE (sym->st_info) == STT_TLS || h->type == STT_TLS)
      && ELF_ST_TYPE (sym->st_info) != h->type
      && oldbfd != NULL)
    {
      bfd *ntbfd, *tbfd;
      bfd_boolean ntdef, tdef;
      asection *ntsec, *tsec;

      if (h->type == STT_TLS)
       {
         ntbfd = abfd;
         ntsec = sec;
         ntdef = newdef;
         tbfd = oldbfd;
         tsec = oldsec;
         tdef = olddef;
       }
      else
       {
         ntbfd = oldbfd;
         ntsec = oldsec;
         ntdef = olddef;
         tbfd = abfd;
         tsec = sec;
         tdef = newdef;
       }

      if (tdef && ntdef)
       (*_bfd_error_handler)
         (_("%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)
         (_("%s: TLS reference in %B mismatches non-TLS reference in %B"),
          tbfd, ntbfd, h->root.root.string);
      else if (tdef)
       (*_bfd_error_handler)
         (_("%s: TLS definition in %B section %A mismatches non-TLS reference in %B"),
          tbfd, tsec, ntbfd, h->root.root.string);
      else
       (*_bfd_error_handler)
         (_("%s: TLS reference in %B mismatches non-TLS definition in %B section %A"),
          tbfd, ntbfd, ntsec, h->root.root.string);

      bfd_set_error (bfd_error_bad_value);
      return FALSE;
    }

  /* We need to remember if a symbol has a definition in a dynamic
     object or is weak in all dynamic objects. Internal and hidden
     visibility will make it unavailable to dynamic objects.  */
  if (newdyn && !h->dynamic_def)
    {
      if (!bfd_is_und_section (sec))
       h->dynamic_def = 1;
      else
       {
         /* Check if this symbol is weak in all dynamic objects. If it
            is the first time we see it in a dynamic object, we mark
            if it is weak. Otherwise, we clear it.  */
         if (!h->ref_dynamic)
           {
             if (bind == STB_WEAK)
              h->dynamic_weak = 1;
           }
         else if (bind != STB_WEAK)
           h->dynamic_weak = 0;
       }
    }

  /* If the old symbol has non-default visibility, we ignore the new
     definition from a dynamic object.  */
  if (newdyn
      && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
      && !bfd_is_und_section (sec))
    {
      *skip = TRUE;
      /* Make sure this symbol is dynamic.  */
      h->ref_dynamic = 1;
      /* A protected symbol has external availability. Make sure it is
        recorded as dynamic.

        FIXME: Should we check type and size for protected symbol?  */
      if (ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
       return bfd_elf_link_record_dynamic_symbol (info, h);
      else
       return TRUE;
    }
  else if (!newdyn
          && ELF_ST_VISIBILITY (sym->st_other) != STV_DEFAULT
          && h->def_dynamic)
    {
      /* If the new symbol with non-default visibility comes from a
        relocatable file and the old definition comes from a dynamic
        object, we remove the old definition.  */
      if ((*sym_hash)->root.type == bfd_link_hash_indirect)
       {
         /* Handle the case where the old dynamic definition is
            default versioned.  We need to copy the symbol info from
            the symbol with default version to the normal one if it
            was referenced before.  */
         if (h->ref_regular)
           {
             const struct elf_backend_data *bed
              = get_elf_backend_data (abfd);
             struct elf_link_hash_entry *vh = *sym_hash;
             vh->root.type = h->root.type;
             h->root.type = bfd_link_hash_indirect;
             (*bed->elf_backend_copy_indirect_symbol) (info, vh, h);
             /* Protected symbols will override the dynamic definition
               with default version.  */
             if (ELF_ST_VISIBILITY (sym->st_other) == STV_PROTECTED)
              {
                h->root.u.i.link = (struct bfd_link_hash_entry *) vh;
                vh->dynamic_def = 1;
                vh->ref_dynamic = 1;
              }
             else
              {
                h->root.type = vh->root.type;
                vh->ref_dynamic = 0;
                /* We have to hide it here since it was made dynamic
                   global with extra bits when the symbol info was
                   copied from the old dynamic definition.  */
                (*bed->elf_backend_hide_symbol) (info, vh, TRUE);
              }
             h = vh;
           }
         else
           h = *sym_hash;
       }

      if ((h->root.u.undef.next || info->hash->undefs_tail == &h->root)
         && bfd_is_und_section (sec))
       {
         /* If the new symbol is undefined and the old symbol was
            also undefined before, we need to make sure
            _bfd_generic_link_add_one_symbol doesn't mess
            up the linker hash table undefs list.  Since the old
            definition came from a dynamic object, it is still on the
            undefs list.  */
         h->root.type = bfd_link_hash_undefined;
         h->root.u.undef.abfd = abfd;
       }
      else
       {
         h->root.type = bfd_link_hash_new;
         h->root.u.undef.abfd = NULL;
       }

      if (h->def_dynamic)
       {
         h->def_dynamic = 0;
         h->ref_dynamic = 1;
         h->dynamic_def = 1;
       }
      /* FIXME: Should we check type and size for protected symbol?  */
      h->size = 0;
      h->type = 0;
      return TRUE;
    }

  /* Differentiate strong and weak symbols.  */
  newweak = bind == STB_WEAK;
  oldweak = (h->root.type == bfd_link_hash_defweak
            || h->root.type == bfd_link_hash_undefweak);

  /* If a new weak symbol definition comes from a regular file and the
     old symbol comes from a dynamic library, we treat the new one as
     strong.  Similarly, an old weak symbol definition from a regular
     file is treated as strong when the new symbol comes from a dynamic
     library.  Further, an old weak symbol from a dynamic library is
     treated as strong if the new symbol is from a dynamic library.
     This reflects the way glibc's ld.so works.

     Do this before setting *type_change_ok or *size_change_ok so that
     we warn properly when dynamic library symbols are overridden.  */

  if (newdef && !newdyn && olddyn)
    newweak = FALSE;
  if (olddef && newdyn)
    oldweak = FALSE;

  /* It's OK to change the type if either the existing symbol or the
     new symbol is weak.  A type change is also OK if the old symbol
     is undefined and the new symbol is defined.  */

  if (oldweak
      || newweak
      || (newdef
         && h->root.type == bfd_link_hash_undefined))
    *type_change_ok = TRUE;

  /* It's OK to change the size if either the existing symbol or the
     new symbol is weak, or if the old symbol is undefined.  */

  if (*type_change_ok
      || h->root.type == bfd_link_hash_undefined)
    *size_change_ok = TRUE;

  /* NEWDYNCOMMON and OLDDYNCOMMON indicate whether the new or old
     symbol, respectively, appears to be a common symbol in a dynamic
     object.  If a symbol appears in an uninitialized section, and is
     not weak, and is not a function, then it may be a common symbol
     which was resolved when the dynamic object was created.  We want
     to treat such symbols specially, because they raise special
     considerations when setting the symbol size: if the symbol
     appears as a common symbol in a regular object, and the size in
     the regular object is larger, we must make sure that we use the
     larger size.  This problematic case can always be avoided in C,
     but it must be handled correctly when using Fortran shared
     libraries.

     Note that if NEWDYNCOMMON is set, NEWDEF will be set, and
     likewise for OLDDYNCOMMON and OLDDEF.

     Note that this test is just a heuristic, and that it is quite
     possible to have an uninitialized symbol in a shared object which
     is really a definition, rather than a common symbol.  This could
     lead to some minor confusion when the symbol really is a common
     symbol in some regular object.  However, I think it will be
     harmless.  */

  if (newdyn
      && newdef
      && !newweak
      && (sec->flags & SEC_ALLOC) != 0
      && (sec->flags & SEC_LOAD) == 0
      && sym->st_size > 0
      && ELF_ST_TYPE (sym->st_info) != STT_FUNC)
    newdyncommon = TRUE;
  else
    newdyncommon = FALSE;

  if (olddyn
      && olddef
      && h->root.type == bfd_link_hash_defined
      && h->def_dynamic
      && (h->root.u.def.section->flags & SEC_ALLOC) != 0
      && (h->root.u.def.section->flags & SEC_LOAD) == 0
      && h->size > 0
      && h->type != STT_FUNC)
    olddyncommon = TRUE;
  else
    olddyncommon = FALSE;

  /* We now know everything about the old and new symbols.  We ask the
     backend to check if we can merge them.  */
  bed = get_elf_backend_data (abfd);
  if (bed->merge_symbol
      && !bed->merge_symbol (info, sym_hash, h, sym, psec, pvalue,
                          pold_alignment, skip, override,
                          type_change_ok, size_change_ok,
                          &newdyn, &newdef, &newdyncommon, &newweak,
                          abfd, &sec,
                          &olddyn, &olddef, &olddyncommon, &oldweak,
                          oldbfd, &oldsec))
    return FALSE;

  /* If both the old and the new symbols look like common symbols in a
     dynamic object, set the size of the symbol to the larger of the
     two.  */

  if (olddyncommon
      && newdyncommon
      && sym->st_size != h->size)
    {
      /* Since we think we have two common symbols, issue a multiple
        common warning if desired.  Note that we only warn if the
        size is different.  If the size is the same, we simply let
        the old symbol override the new one as normally happens with
        symbols defined in dynamic objects.  */

      if (! ((*info->callbacks->multiple_common)
            (info, h->root.root.string, oldbfd, bfd_link_hash_common,
             h->size, abfd, bfd_link_hash_common, sym->st_size)))
       return FALSE;

      if (sym->st_size > h->size)
       h->size = sym->st_size;

      *size_change_ok = TRUE;
    }

  /* If we are looking at a dynamic object, and we have found a
     definition, we need to see if the symbol was already defined by
     some other object.  If so, we want to use the existing
     definition, and we do not want to report a multiple symbol
     definition error; we do this by clobbering *PSEC to be
     bfd_und_section_ptr.

     We treat a common symbol as a definition if the symbol in the
     shared library is a function, since common symbols always
     represent variables; this can cause confusion in principle, but
     any such confusion would seem to indicate an erroneous program or
     shared library.  We also permit a common symbol in a regular
     object to override a weak symbol in a shared object.  */

  if (newdyn
      && newdef
      && (olddef
         || (h->root.type == bfd_link_hash_common
             && (newweak
                || ELF_ST_TYPE (sym->st_info) == STT_FUNC))))
    {
      *override = TRUE;
      newdef = FALSE;
      newdyncommon = FALSE;

      *psec = sec = bfd_und_section_ptr;
      *size_change_ok = TRUE;

      /* If we get here when the old symbol is a common symbol, then
        we are explicitly letting it override a weak symbol or
        function in a dynamic object, and we don't want to warn about
        a type change.  If the old symbol is a defined symbol, a type
        change warning may still be appropriate.  */

      if (h->root.type == bfd_link_hash_common)
       *type_change_ok = TRUE;
    }

  /* Handle the special case of an old common symbol merging with a
     new symbol which looks like a common symbol in a shared object.
     We change *PSEC and *PVALUE to make the new symbol look like a
     common symbol, and let _bfd_generic_link_add_one_symbol do the
     right thing.  */

  if (newdyncommon
      && h->root.type == bfd_link_hash_common)
    {
      *override = TRUE;
      newdef = FALSE;
      newdyncommon = FALSE;
      *pvalue = sym->st_size;
      *psec = sec = bed->common_section (oldsec);
      *size_change_ok = TRUE;
    }

  /* Skip weak definitions of symbols that are already defined.  */
  if (newdef && olddef && newweak)
    *skip = TRUE;

  /* If the old symbol is from a dynamic object, and the new symbol is
     a definition which is not from a dynamic object, then the new
     symbol overrides the old symbol.  Symbols from regular files
     always take precedence over symbols from dynamic objects, even if
     they are defined after the dynamic object in the link.

     As above, we again permit a common symbol in a regular object to
     override a definition in a shared object if the shared object
     symbol is a function or is weak.  */

  flip = NULL;
  if (!newdyn
      && (newdef
         || (bfd_is_com_section (sec)
             && (oldweak
                || h->type == STT_FUNC)))
      && olddyn
      && olddef
      && h->def_dynamic)
    {
      /* Change the hash table entry to undefined, and let
        _bfd_generic_link_add_one_symbol do the right thing with the
        new definition.  */

      h->root.type = bfd_link_hash_undefined;
      h->root.u.undef.abfd = h->root.u.def.section->owner;
      *size_change_ok = TRUE;

      olddef = FALSE;
      olddyncommon = FALSE;

      /* We again permit a type change when a common symbol may be
        overriding a function.  */

      if (bfd_is_com_section (sec))
       *type_change_ok = TRUE;

      if ((*sym_hash)->root.type == bfd_link_hash_indirect)
       flip = *sym_hash;
      else
       /* This union may have been set to be non-NULL when this symbol
          was seen in a dynamic object.  We must force the union to be
          NULL, so that it is correct for a regular symbol.  */
       h->verinfo.vertree = NULL;
    }

  /* Handle the special case of a new common symbol merging with an
     old symbol that looks like it might be a common symbol defined in
     a shared object.  Note that we have already handled the case in
     which a new common symbol should simply override the definition
     in the shared library.  */

  if (! newdyn
      && bfd_is_com_section (sec)
      && olddyncommon)
    {
      /* It would be best if we could set the hash table entry to a
        common symbol, but we don't know what to use for the section
        or the alignment.  */
      if (! ((*info->callbacks->multiple_common)
            (info, h->root.root.string, oldbfd, bfd_link_hash_common,
             h->size, abfd, bfd_link_hash_common, sym->st_size)))
       return FALSE;

      /* If the presumed common symbol in the dynamic object is
        larger, pretend that the new symbol has its size.  */

      if (h->size > *pvalue)
       *pvalue = h->size;

      /* We need to remember the alignment required by the symbol
        in the dynamic object.  */
      BFD_ASSERT (pold_alignment);
      *pold_alignment = h->root.u.def.section->alignment_power;

      olddef = FALSE;
      olddyncommon = FALSE;

      h->root.type = bfd_link_hash_undefined;
      h->root.u.undef.abfd = h->root.u.def.section->owner;

      *size_change_ok = TRUE;
      *type_change_ok = TRUE;

      if ((*sym_hash)->root.type == bfd_link_hash_indirect)
       flip = *sym_hash;
      else
       h->verinfo.vertree = NULL;
    }

  if (flip != NULL)
    {
      /* Handle the case where we had a versioned symbol in a dynamic
        library and now find a definition in a normal object.  In this
        case, we make the versioned symbol point to the normal one.  */
      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
      flip->root.type = h->root.type;
      h->root.type = bfd_link_hash_indirect;
      h->root.u.i.link = (struct bfd_link_hash_entry *) flip;
      (*bed->elf_backend_copy_indirect_symbol) (info, flip, h);
      flip->root.u.undef.abfd = h->root.u.undef.abfd;
      if (h->def_dynamic)
       {
         h->def_dynamic = 0;
         flip->ref_dynamic = 1;
       }
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 11057 of file elflink.c.

{
  flagword flags;
  const char *name, *p;
  struct bfd_section_already_linked *l;
  struct bfd_section_already_linked_hash_entry *already_linked_list;

  if (sec->output_section == bfd_abs_section_ptr)
    return;

  flags = sec->flags;

  /* Return if it isn't a linkonce section.  A comdat group section
     also has SEC_LINK_ONCE set.  */
  if ((flags & SEC_LINK_ONCE) == 0)
    return;

  /* Don't put group member sections on our list of already linked
     sections.  They are handled as a group via their group section.  */
  if (elf_sec_group (sec) != NULL)
    return;

  /* FIXME: When doing a relocatable link, we may have trouble
     copying relocations in other sections that refer to local symbols
     in the section being discarded.  Those relocations will have to
     be converted somehow; as of this writing I'm not sure that any of
     the backends handle that correctly.

     It is tempting to instead not discard link once sections when
     doing a relocatable link (technically, they should be discarded
     whenever we are building constructors).  However, that fails,
     because the linker winds up combining all the link once sections
     into a single large link once section, which defeats the purpose
     of having link once sections in the first place.

     Also, not merging link once sections in a relocatable link
     causes trouble for MIPS ELF, which relies on link once semantics
     to handle the .reginfo section correctly.  */

  name = bfd_get_section_name (abfd, sec);

  if (CONST_STRNEQ (name, ".gnu.linkonce.")
      && (p = strchr (name + sizeof (".gnu.linkonce.") - 1, '.')) != NULL)
    p++;
  else
    p = name;

  already_linked_list = bfd_section_already_linked_table_lookup (p);

  for (l = already_linked_list->entry; l != NULL; l = l->next)
    {
      /* We may have 2 different types of sections on the list: group
        sections and linkonce sections.  Match like sections.  */
      if ((flags & SEC_GROUP) == (l->sec->flags & SEC_GROUP)
         && strcmp (name, l->sec->name) == 0
         && bfd_coff_get_comdat_section (l->sec->owner, l->sec) == NULL)
       {
         /* The section has already been linked.  See if we should
            issue a warning.  */
         switch (flags & SEC_LINK_DUPLICATES)
           {
           default:
             abort ();

           case SEC_LINK_DUPLICATES_DISCARD:
             break;

           case SEC_LINK_DUPLICATES_ONE_ONLY:
             (*_bfd_error_handler)
              (_("%B: ignoring duplicate section `%A'"),
               abfd, sec);
             break;

           case SEC_LINK_DUPLICATES_SAME_SIZE:
             if (sec->size != l->sec->size)
              (*_bfd_error_handler)
                (_("%B: duplicate section `%A' has different size"),
                 abfd, sec);
             break;

           case SEC_LINK_DUPLICATES_SAME_CONTENTS:
             if (sec->size != l->sec->size)
              (*_bfd_error_handler)
                (_("%B: duplicate section `%A' has different size"),
                 abfd, sec);
             else if (sec->size != 0)
              {
                bfd_byte *sec_contents, *l_sec_contents;

                if (!bfd_malloc_and_get_section (abfd, sec, &sec_contents))
                  (*_bfd_error_handler)
                    (_("%B: warning: could not read contents of section `%A'"),
                     abfd, sec);
                else if (!bfd_malloc_and_get_section (l->sec->owner, l->sec,
                                                 &l_sec_contents))
                  (*_bfd_error_handler)
                    (_("%B: warning: could not read contents of section `%A'"),
                     l->sec->owner, l->sec);
                else if (memcmp (sec_contents, l_sec_contents, sec->size) != 0)
                  (*_bfd_error_handler)
                    (_("%B: warning: duplicate section `%A' has different contents"),
                     abfd, sec);

                if (sec_contents)
                  free (sec_contents);
                if (l_sec_contents)
                  free (l_sec_contents);
              }
             break;
           }

         /* Set the output_section field so that lang_add_section
            does not create a lang_input_section structure for this
            section.  Since there might be a symbol in the section
            being discarded, we must retain a pointer to the section
            which we are really going to use.  */
         sec->output_section = bfd_abs_section_ptr;
         sec->kept_section = l->sec;

         if (flags & SEC_GROUP)
           {
             asection *first = elf_next_in_group (sec);
             asection *s = first;

             while (s != NULL)
              {
                s->output_section = bfd_abs_section_ptr;
                /* Record which group discards it.  */
                s->kept_section = l->sec;
                s = elf_next_in_group (s);
                /* These lists are circular.  */
                if (s == first)
                  break;
              }
           }

         return;
       }
    }

  /* A single member comdat group section may be discarded by a
     linkonce section and vice versa.  */

  if ((flags & SEC_GROUP) != 0)
    {
      asection *first = elf_next_in_group (sec);

      if (first != NULL && elf_next_in_group (first) == first)
       /* Check this single member group against linkonce sections.  */
       for (l = already_linked_list->entry; l != NULL; l = l->next)
         if ((l->sec->flags & SEC_GROUP) == 0
             && bfd_coff_get_comdat_section (l->sec->owner, l->sec) == NULL
             && bfd_elf_match_symbols_in_sections (l->sec, first, info))
           {
             first->output_section = bfd_abs_section_ptr;
             first->kept_section = l->sec;
             sec->output_section = bfd_abs_section_ptr;
             break;
           }
    }
  else
    /* Check this linkonce section against single member groups.  */
    for (l = already_linked_list->entry; l != NULL; l = l->next)
      if (l->sec->flags & SEC_GROUP)
       {
         asection *first = elf_next_in_group (l->sec);

         if (first != NULL
             && elf_next_in_group (first) == first
             && bfd_elf_match_symbols_in_sections (first, sec, info))
           {
             sec->output_section = bfd_abs_section_ptr;
             sec->kept_section = first;
             break;
           }
       }

  /* This is the first section with this name.  Record it.  */
  bfd_section_already_linked_table_insert (already_linked_list, sec);
}

Here is the call graph for this function:

Definition at line 2694 of file elflink.c.

{
  /* If it's a local sym, of course we resolve locally.  */
  if (h == NULL)
    return TRUE;

  /* Common symbols that become definitions don't get the DEF_REGULAR
     flag set, so test it first, and don't bail out.  */
  if (ELF_COMMON_DEF_P (h))
    /* Do nothing.  */;
  /* If we don't have a definition in a regular file, then we can't
     resolve locally.  The sym is either undefined or dynamic.  */
  else if (!h->def_regular)
    return FALSE;

  /* Forced local symbols resolve locally.  */
  if (h->forced_local)
    return TRUE;

  /* As do non-dynamic symbols.  */
  if (h->dynindx == -1)
    return TRUE;

  /* At this point, we know the symbol is defined and dynamic.  In an
     executable it must resolve locally, likewise when building symbolic
     shared libraries.  */
  if (info->executable || SYMBOLIC_BIND (info, h))
    return TRUE;

  /* Now deal with defined dynamic symbols in shared libraries.  Ones
     with default visibility might not resolve locally.  */
  if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
    return FALSE;

  /* However, STV_HIDDEN or STV_INTERNAL ones must be local.  */
  if (ELF_ST_VISIBILITY (h->other) != STV_PROTECTED)
    return TRUE;

  /* STV_PROTECTED non-function symbols are local.  */
  if (h->type != STT_FUNC)
    return TRUE;

  /* Function pointer equality tests may require that STV_PROTECTED
     symbols be treated as dynamic symbols, even when we know that the
     dynamic linker will resolve them locally.  */
  return local_protected;
}

Here is the caller graph for this function:

struct bfd_section* _bfd_elf_tls_setup ( bfd obfd,
struct bfd_link_info info 
) [read]

Definition at line 2748 of file elflink.c.

{
  struct bfd_section *sec, *tls;
  unsigned int align = 0;

  for (sec = obfd->sections; sec != NULL; sec = sec->next)
    if ((sec->flags & SEC_THREAD_LOCAL) != 0)
      break;
  tls = sec;

  for (; sec != NULL && (sec->flags & SEC_THREAD_LOCAL) != 0; sec = sec->next)
    if (sec->alignment_power > align)
      align = sec->alignment_power;

  elf_hash_table (info)->tls_sec = tls;

  /* Ensure the alignment of the first section is the largest alignment,
     so that the tls segment starts aligned.  */
  if (tls != NULL)
    tls->alignment_power = align;

  return tls;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bfd_boolean bfd_elf_discard_info ( bfd output_bfd,
struct bfd_link_info info 
)

Definition at line 10914 of file elflink.c.

{
  struct elf_reloc_cookie cookie;
  asection *stab, *eh;
  Elf_Internal_Shdr *symtab_hdr;
  const struct elf_backend_data *bed;
  bfd *abfd;
  unsigned int count;
  bfd_boolean ret = FALSE;

  if (info->traditional_format
      || !is_elf_hash_table (info->hash))
    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;

      eh = NULL;
      if (!info->relocatable)
       {
         eh = bfd_get_section_by_name (abfd, ".eh_frame");
         if (eh != NULL
             && (eh->size == 0
                || bfd_is_abs_section (eh->output_section)))
           eh = NULL;
       }

      stab = bfd_get_section_by_name (abfd, ".stab");
      if (stab != NULL
         && (stab->size == 0
             || bfd_is_abs_section (stab->output_section)
             || stab->sec_info_type != ELF_INFO_TYPE_STABS))
       stab = NULL;

      if (stab == NULL
         && eh == NULL
         && bed->elf_backend_discard_info == NULL)
       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 / bed->s->sizeof_sym;
         cookie.extsymoff = 0;
       }
      else
       {
         cookie.locsymcount = symtab_hdr->sh_info;
         cookie.extsymoff = symtab_hdr->sh_info;
       }

      if (bed->s->arch_size == 32)
       cookie.r_sym_shift = 8;
      else
       cookie.r_sym_shift = 32;

      cookie.locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
      if (cookie.locsyms == NULL && cookie.locsymcount != 0)
       {
         cookie.locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
                                           cookie.locsymcount, 0,
                                           NULL, NULL, NULL);
         if (cookie.locsyms == NULL)
           return FALSE;
       }

      if (stab != NULL)
       {
         cookie.rels = NULL;
         count = stab->reloc_count;
         if (count != 0)
           cookie.rels = _bfd_elf_link_read_relocs (abfd, stab, NULL, NULL,
                                               info->keep_memory);
         if (cookie.rels != NULL)
           {
             cookie.rel = cookie.rels;
             cookie.relend = cookie.rels;
             cookie.relend += count * bed->s->int_rels_per_ext_rel;
             if (_bfd_discard_section_stabs (abfd, stab,
                                         elf_section_data (stab)->sec_info,
                                         bfd_elf_reloc_symbol_deleted_p,
                                         &cookie))
              ret = TRUE;
             if (elf_section_data (stab)->relocs != cookie.rels)
              free (cookie.rels);
           }
       }

      if (eh != NULL)
       {
         cookie.rels = NULL;
         count = eh->reloc_count;
         if (count != 0)
           cookie.rels = _bfd_elf_link_read_relocs (abfd, eh, NULL, NULL,
                                               info->keep_memory);
         cookie.rel = cookie.rels;
         cookie.relend = cookie.rels;
         if (cookie.rels != NULL)
           cookie.relend += count * bed->s->int_rels_per_ext_rel;

         if (_bfd_elf_discard_section_eh_frame (abfd, info, eh,
                                           bfd_elf_reloc_symbol_deleted_p,
                                           &cookie))
           ret = TRUE;

         if (cookie.rels != NULL
             && elf_section_data (eh)->relocs != cookie.rels)
           free (cookie.rels);
       }

      if (bed->elf_backend_discard_info != NULL
         && (*bed->elf_backend_discard_info) (abfd, &cookie, info))
       ret = TRUE;

      if (cookie.locsyms != NULL
         && symtab_hdr->contents != (unsigned char *) cookie.locsyms)
       {
         if (! info->keep_memory)
           free (cookie.locsyms);
         else
           symtab_hdr->contents = (unsigned char *) cookie.locsyms;
       }
    }

  if (info->eh_frame_hdr
      && !info->relocatable
      && _bfd_elf_discard_section_eh_frame_hdr (output_bfd, info))
    ret = TRUE;

  return ret;
}

Here is the call graph for this function:

Definition at line 9035 of file elflink.c.

{
  bfd_boolean dynamic;
  bfd_boolean emit_relocs;
  bfd *dynobj;
  struct elf_final_link_info finfo;
  register asection *o;
  register struct bfd_link_order *p;
  register bfd *sub;
  bfd_size_type max_contents_size;
  bfd_size_type max_external_reloc_size;
  bfd_size_type max_internal_reloc_count;
  bfd_size_type max_sym_count;
  bfd_size_type max_sym_shndx_count;
  file_ptr off;
  Elf_Internal_Sym elfsym;
  unsigned int i;
  Elf_Internal_Shdr *symtab_hdr;
  Elf_Internal_Shdr *symtab_shndx_hdr;
  Elf_Internal_Shdr *symstrtab_hdr;
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  struct elf_outext_info eoinfo;
  bfd_boolean merged;
  size_t relativecount = 0;
  asection *reldyn = 0;
  bfd_size_type amt;

  if (! is_elf_hash_table (info->hash))
    return FALSE;

  if (info->shared)
    abfd->flags |= DYNAMIC;

  dynamic = elf_hash_table (info)->dynamic_sections_created;
  dynobj = elf_hash_table (info)->dynobj;

  emit_relocs = (info->relocatable
               || info->emitrelocations);

  finfo.info = info;
  finfo.output_bfd = abfd;
  finfo.symstrtab = _bfd_elf_stringtab_init ();
  if (finfo.symstrtab == NULL)
    return FALSE;

  if (! dynamic)
    {
      finfo.dynsym_sec = NULL;
      finfo.hash_sec = NULL;
      finfo.symver_sec = NULL;
    }
  else
    {
      finfo.dynsym_sec = bfd_get_section_by_name (dynobj, ".dynsym");
      finfo.hash_sec = bfd_get_section_by_name (dynobj, ".hash");
      BFD_ASSERT (finfo.dynsym_sec != NULL);
      finfo.symver_sec = bfd_get_section_by_name (dynobj, ".gnu.version");
      /* Note that it is OK if symver_sec is NULL.  */
    }

  finfo.contents = NULL;
  finfo.external_relocs = NULL;
  finfo.internal_relocs = NULL;
  finfo.external_syms = NULL;
  finfo.locsym_shndx = NULL;
  finfo.internal_syms = NULL;
  finfo.indices = NULL;
  finfo.sections = NULL;
  finfo.symbuf = NULL;
  finfo.symshndxbuf = NULL;
  finfo.symbuf_count = 0;
  finfo.shndxbuf_size = 0;

  /* Count up the number of relocations we will output for each output
     section, so that we know the sizes of the reloc sections.  We
     also figure out some maximum sizes.  */
  max_contents_size = 0;
  max_external_reloc_size = 0;
  max_internal_reloc_count = 0;
  max_sym_count = 0;
  max_sym_shndx_count = 0;
  merged = FALSE;
  for (o = abfd->sections; o != NULL; o = o->next)
    {
      struct bfd_elf_section_data *esdo = elf_section_data (o);
      o->reloc_count = 0;

      for (p = o->map_head.link_order; p != NULL; p = p->next)
       {
         unsigned int reloc_count = 0;
         struct bfd_elf_section_data *esdi = NULL;
         unsigned int *rel_count1;

         if (p->type == bfd_section_reloc_link_order
             || p->type == bfd_symbol_reloc_link_order)
           reloc_count = 1;
         else if (p->type == bfd_indirect_link_order)
           {
             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
               to do this so that we can identify any sections which
               the linker has decided to not include.  */
             sec->linker_mark = TRUE;

             if (sec->flags & SEC_MERGE)
              merged = TRUE;

             if (info->relocatable || info->emitrelocations)
              reloc_count = sec->reloc_count;
             else if (bed->elf_backend_count_relocs)
              {
                Elf_Internal_Rela * relocs;

                relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL,
                                                info->keep_memory);

                reloc_count = (*bed->elf_backend_count_relocs) (sec, relocs);

                if (elf_section_data (o)->relocs != relocs)
                  free (relocs);
              }

             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;

                if (elf_bad_symtab (sec->owner))
                  sym_count = (elf_tdata (sec->owner)->symtab_hdr.sh_size
                             / bed->s->sizeof_sym);
                else
                  sym_count = elf_tdata (sec->owner)->symtab_hdr.sh_info;

                if (sym_count > max_sym_count)
                  max_sym_count = sym_count;

                if (sym_count > max_sym_shndx_count
                    && elf_symtab_shndx (sec->owner) != 0)
                  max_sym_shndx_count = sym_count;

                if ((sec->flags & SEC_RELOC) != 0)
                  {
                    size_t ext_size;

                    ext_size = elf_section_data (sec)->rel_hdr.sh_size;
                    if (ext_size > max_external_reloc_size)
                     max_external_reloc_size = ext_size;
                    if (sec->reloc_count > max_internal_reloc_count)
                     max_internal_reloc_count = sec->reloc_count;
                  }
              }
           }

         if (reloc_count == 0)
           continue;

         o->reloc_count += reloc_count;

         /* MIPS may have a mix of REL and RELA relocs on sections.
            To support this curious ABI we keep reloc counts in
            elf_section_data too.  We must be careful to add the
            relocations from the input section to the right output
            count.  FIXME: Get rid of one count.  We have
            o->reloc_count == esdo->rel_count + esdo->rel_count2.  */
         rel_count1 = &esdo->rel_count;
         if (esdi != NULL)
           {
             bfd_boolean same_size;
             bfd_size_type entsize1;

             entsize1 = esdi->rel_hdr.sh_entsize;
             BFD_ASSERT (entsize1 == bed->s->sizeof_rel
                       || entsize1 == bed->s->sizeof_rela);
             same_size = !o->use_rela_p == (entsize1 == bed->s->sizeof_rel);

             if (!same_size)
              rel_count1 = &esdo->rel_count2;

             if (esdi->rel_hdr2 != NULL)
              {
                bfd_size_type entsize2 = esdi->rel_hdr2->sh_entsize;
                unsigned int alt_count;
                unsigned int *rel_count2;

                BFD_ASSERT (entsize2 != entsize1
                           && (entsize2 == bed->s->sizeof_rel
                              || entsize2 == bed->s->sizeof_rela));

                rel_count2 = &esdo->rel_count2;
                if (!same_size)
                  rel_count2 = &esdo->rel_count;

                /* The following is probably too simplistic if the
                   backend counts output relocs unusually.  */
                BFD_ASSERT (bed->elf_backend_count_relocs == NULL);
                alt_count = NUM_SHDR_ENTRIES (esdi->rel_hdr2);
                *rel_count2 += alt_count;
                reloc_count -= alt_count;
              }
           }
         *rel_count1 += reloc_count;
       }

      if (o->reloc_count > 0)
       o->flags |= SEC_RELOC;
      else
       {
         /* Explicitly clear the SEC_RELOC flag.  The linker tends to
            set it (this is probably a bug) and if it is set
            assign_section_numbers will create a reloc section.  */
         o->flags &=~ SEC_RELOC;
       }

      /* If the SEC_ALLOC flag is not set, force the section VMA to
        zero.  This is done in elf_fake_sections as well, but forcing
        the VMA to 0 here will ensure that relocs against these
        sections are handled correctly.  */
      if ((o->flags & SEC_ALLOC) == 0
         && ! o->user_set_vma)
       o->vma = 0;
    }

  if (! info->relocatable && merged)
    elf_link_hash_traverse (elf_hash_table (info),
                         _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
     to create a symbol table.  */
  bfd_get_symcount (abfd) = info->strip == strip_all ? 0 : 1;
  BFD_ASSERT (! abfd->output_has_begun);
  if (! _bfd_elf_compute_section_file_positions (abfd, info))
    goto error_return;

  /* Set sizes, and assign file positions for reloc sections.  */
  for (o = abfd->sections; o != NULL; o = o->next)
    {
      if ((o->flags & SEC_RELOC) != 0)
       {
         if (!(_bfd_elf_link_size_reloc_section
              (abfd, &elf_section_data (o)->rel_hdr, o)))
           goto error_return;

         if (elf_section_data (o)->rel_hdr2
             && !(_bfd_elf_link_size_reloc_section
                 (abfd, elf_section_data (o)->rel_hdr2, o)))
           goto error_return;
       }

      /* Now, reset REL_COUNT and REL_COUNT2 so that we can use them
        to count upwards while actually outputting the relocations.  */
      elf_section_data (o)->rel_count = 0;
      elf_section_data (o)->rel_count2 = 0;
    }

  _bfd_elf_assign_file_positions_for_relocs (abfd);

  /* We have now assigned file positions for all the sections except
     .symtab and .strtab.  We start the .symtab section at the current
     file position, and write directly to it.  We build the .strtab
     section in memory.  */
  bfd_get_symcount (abfd) = 0;
  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  /* sh_name is set in prep_headers.  */
  symtab_hdr->sh_type = SHT_SYMTAB;
  /* sh_flags, sh_addr and sh_size all start off zero.  */
  symtab_hdr->sh_entsize = bed->s->sizeof_sym;
  /* sh_link is set in assign_section_numbers.  */
  /* sh_info is set below.  */
  /* sh_offset is set just below.  */
  symtab_hdr->sh_addralign = 1 << bed->s->log_file_align;

  off = elf_tdata (abfd)->next_file_pos;
  off = _bfd_elf_assign_file_position_for_section (symtab_hdr, off, TRUE);

  /* Note that at this point elf_tdata (abfd)->next_file_pos is
     incorrect.  We do not yet know the size of the .symtab section.
     We correct next_file_pos below, after we do know the size.  */

  /* 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)
    finfo.symbuf_size = 20;
  else
    finfo.symbuf_size = max_sym_count;
  amt = finfo.symbuf_size;
  amt *= bed->s->sizeof_sym;
  finfo.symbuf = bfd_malloc (amt);
  if (finfo.symbuf == NULL)
    goto error_return;
  if (elf_numsections (abfd) > SHN_LORESERVE)
    {
      /* Wild guess at number of output symbols.  realloc'd as needed.  */
      amt = 2 * max_sym_count + elf_numsections (abfd) + 1000;
      finfo.shndxbuf_size = amt;
      amt *= sizeof (Elf_External_Sym_Shndx);
      finfo.symshndxbuf = bfd_zmalloc (amt);
      if (finfo.symshndxbuf == NULL)
       goto error_return;
    }

  /* Start writing out the symbol table.  The first symbol is always a
     dummy symbol.  */
  if (info->strip != strip_all
      || emit_relocs)
    {
      elfsym.st_value = 0;
      elfsym.st_size = 0;
      elfsym.st_info = 0;
      elfsym.st_other = 0;
      elfsym.st_shndx = SHN_UNDEF;
      if (! elf_link_output_sym (&finfo, NULL, &elfsym, bfd_und_section_ptr,
                             NULL))
       goto error_return;
    }

  /* Output a symbol for each section.  We output these even if we are
     discarding local symbols, since they are used for relocs.  These
     symbols have no names.  We store the index of each one in the
     index field of the section, so that we can find it again when
     outputting relocs.  */
  if (info->strip != strip_all
      || emit_relocs)
    {
      elfsym.st_size = 0;
      elfsym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
      elfsym.st_other = 0;
      elfsym.st_value = 0;
      for (i = 1; i < elf_numsections (abfd); i++)
       {
         o = bfd_section_from_elf_index (abfd, i);
         if (o != NULL)
           {
             o->target_index = bfd_get_symcount (abfd);
             elfsym.st_shndx = i;
             if (!info->relocatable)
              elfsym.st_value = o->vma;
             if (!elf_link_output_sym (&finfo, NULL, &elfsym, o, NULL))
              goto error_return;
           }
         if (i == SHN_LORESERVE - 1)
           i += SHN_HIRESERVE + 1 - SHN_LORESERVE;
       }
    }

  /* Allocate some memory to hold information read in from the input
     files.  */
  if (max_contents_size != 0)
    {
      finfo.contents = bfd_malloc (max_contents_size);
      if (finfo.contents == NULL)
       goto error_return;
    }

  if (max_external_reloc_size != 0)
    {
      finfo.external_relocs = bfd_malloc (max_external_reloc_size);
      if (finfo.external_relocs == NULL)
       goto error_return;
    }

  if (max_internal_reloc_count != 0)
    {
      amt = max_internal_reloc_count * bed->s->int_rels_per_ext_rel;
      amt *= sizeof (Elf_Internal_Rela);
      finfo.internal_relocs = bfd_malloc (amt);
      if (finfo.internal_relocs == NULL)
       goto error_return;
    }

  if (max_sym_count != 0)
    {
      amt = max_sym_count * bed->s->sizeof_sym;
      finfo.external_syms = bfd_malloc (amt);
      if (finfo.external_syms == NULL)
       goto error_return;

      amt = max_sym_count * sizeof (Elf_Internal_Sym);
      finfo.internal_syms = bfd_malloc (amt);
      if (finfo.internal_syms == NULL)
       goto error_return;

      amt = max_sym_count * sizeof (long);
      finfo.indices = bfd_malloc (amt);
      if (finfo.indices == NULL)
       goto error_return;

      amt = max_sym_count * sizeof (asection *);
      finfo.sections = bfd_malloc (amt);
      if (finfo.sections == NULL)
       goto error_return;
    }

  if (max_sym_shndx_count != 0)
    {
      amt = max_sym_shndx_count * sizeof (Elf_External_Sym_Shndx);
      finfo.locsym_shndx = bfd_malloc (amt);
      if (finfo.locsym_shndx == NULL)
       goto error_return;
    }

  if (elf_hash_table (info)->tls_sec)
    {
      bfd_vma base, end = 0;
      asection *sec;

      for (sec = elf_hash_table (info)->tls_sec;
          sec && (sec->flags & SEC_THREAD_LOCAL);
          sec = sec->next)
       {
         bfd_size_type size = sec->size;

         if (size == 0
             && (sec->flags & SEC_HAS_CONTENTS) == 0)
           {
             struct bfd_link_order *o = sec->map_tail.link_order;
             if (o != NULL)
              size = o->offset + o->size;
           }
         end = sec->vma + size;
       }
      base = elf_hash_table (info)->tls_sec->vma;
      end = align_power (end, elf_hash_table (info)->tls_sec->alignment_power);
      elf_hash_table (info)->tls_size = end - base;
    }

  /* Reorder SHF_LINK_ORDER sections.  */
  for (o = abfd->sections; o != NULL; o = o->next)
    {
      if (!elf_fixup_link_order (abfd, o))
       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
     would rather not keep them in memory, we handle all the
     relocations for a single input file at the same time.

     Unfortunately, there is no way to know the total number of local
     symbols until we have seen all of them, and the local symbol
     indices precede the global symbol indices.  This means that when
     we are generating relocatable output, and we see a reloc against
     a global symbol, we can not know the symbol index until we have
     finished examining all the local symbols to see which ones we are
     going to output.  To deal with this, we keep the relocations in
     memory, and don't output them until the end of the link.  This is
     an unfortunate waste of memory, but I don't see a good way around
     it.  Fortunately, it only happens when performing a relocatable
     link, which is not the common case.  FIXME: If keep_memory is set
     we could write the relocs out and then read them again; I don't
     know how bad the memory loss will be.  */

  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
    sub->output_has_begun = FALSE;
  for (o = abfd->sections; o != NULL; o = o->next)
    {
      for (p = o->map_head.link_order; p != NULL; p = p->next)
       {
         if (p->type == bfd_indirect_link_order
             && (bfd_get_flavour ((sub = p->u.indirect.section->owner))
                == bfd_target_elf_flavour)
             && elf_elfheader (sub)->e_ident[EI_CLASS] == bed->s->elfclass)
           {
             if (! sub->output_has_begun)
              {
                if (! elf_link_input_bfd (&finfo, sub))
                  goto error_return;
                sub->output_has_begun = TRUE;
              }
           }
         else if (p->type == bfd_section_reloc_link_order
                 || p->type == bfd_symbol_reloc_link_order)
           {
             if (! elf_reloc_link_order (abfd, info, o, p))
              goto error_return;
           }
         else
           {
             if (! _bfd_default_link_order (abfd, info, o, p))
              goto error_return;
           }
       }
    }

  /* Free symbol buffer if needed.  */
  if (!info->reduce_memory_overheads)
    {
      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
       if (elf_tdata (sub)->symbuf)
         {
           free (elf_tdata (sub)->symbuf);
           elf_tdata (sub)->symbuf = NULL;
         }
    }

  /* Output any global symbols that got converted to local in a
     version script or due to symbol visibility.  We do this in a
     separate step since ELF requires all local symbols to appear
     prior to any global symbols.  FIXME: We should only do this if
     some global symbols were, in fact, converted to become local.
     FIXME: Will this work correctly with the Irix 5 linker?  */
  eoinfo.failed = FALSE;
  eoinfo.finfo = &finfo;
  eoinfo.localsyms = TRUE;
  elf_link_hash_traverse (elf_hash_table (info), elf_link_output_extsym,
                       &eoinfo);
  if (eoinfo.failed)
    return FALSE;

  /* If backend needs to output some local symbols not present in the hash
     table, do it now.  */
  if (bed->elf_backend_output_arch_local_syms)
    {
      typedef bfd_boolean (*out_sym_func)
       (void *, const char *, Elf_Internal_Sym *, asection *,
        struct elf_link_hash_entry *);

      if (! ((*bed->elf_backend_output_arch_local_syms)
            (abfd, info, &finfo, (out_sym_func) elf_link_output_sym)))
       return FALSE;
    }

  /* That wrote out all the local symbols.  Finish up the symbol table
     with the global symbols. Even if we want to strip everything we
     can, we still need to deal with those global symbols that got
     converted to local in a version script.  */

  /* The sh_info field records the index of the first non local symbol.  */
  symtab_hdr->sh_info = bfd_get_symcount (abfd);

  if (dynamic
      && finfo.dynsym_sec->output_section != bfd_abs_section_ptr)
    {
      Elf_Internal_Sym sym;
      bfd_byte *dynsym = finfo.dynsym_sec->contents;
      long last_local = 0;

      /* Write out the section symbols for the output sections.  */
      if (info->shared || elf_hash_table (info)->is_relocatable_executable)
       {
         asection *s;

         sym.st_size = 0;
         sym.st_name = 0;
         sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
         sym.st_other = 0;

         for (s = abfd->sections; s != NULL; s = s->next)
           {
             int indx;
             bfd_byte *dest;
             long dynindx;

             dynindx = elf_section_data (s)->dynindx;
             if (dynindx <= 0)
              continue;
             indx = elf_section_data (s)->this_idx;
             BFD_ASSERT (indx > 0);
             sym.st_shndx = indx;
             if (! check_dynsym (abfd, &sym))
              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)
       {
         struct elf_link_local_dynamic_entry *e;
         for (e = elf_hash_table (info)->dynlocal; e ; e = e->next)
           {
             asection *s;
             bfd_byte *dest;

             sym.st_size = e->isym.st_size;
             sym.st_other = e->isym.st_other;

             /* Copy the internal symbol as is.
               Note that we saved a word of storage and overwrote
               the original st_name with the dynstr_index.  */
             sym = e->isym;

             if (e->isym.st_shndx != SHN_UNDEF
                && (e->isym.st_shndx < SHN_LORESERVE
                    || e->isym.st_shndx > SHN_HIRESERVE))
              {
                s = bfd_section_from_elf_index (e->input_bfd,
                                            e->isym.st_shndx);

                sym.st_shndx =
                  elf_section_data (s->output_section)->this_idx;
                if (! check_dynsym (abfd, &sym))
                  return FALSE;
                sym.st_value = (s->output_section->vma
                              + s->output_offset
                              + 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 (finfo.dynsym_sec->output_section)->this_hdr.sh_info =
       last_local + 1;
    }

  /* We get the global symbols from the hash table.  */
  eoinfo.failed = FALSE;
  eoinfo.localsyms = FALSE;
  eoinfo.finfo = &finfo;
  elf_link_hash_traverse (elf_hash_table (info), elf_link_output_extsym,
                       &eoinfo);
  if (eoinfo.failed)
    return FALSE;

  /* If backend needs to output some symbols not present in the hash
     table, do it now.  */
  if (bed->elf_backend_output_arch_syms)
    {
      typedef bfd_boolean (*out_sym_func)
       (void *, const char *, Elf_Internal_Sym *, asection *,
        struct elf_link_hash_entry *);

      if (! ((*bed->elf_backend_output_arch_syms)
            (abfd, info, &finfo, (out_sym_func) elf_link_output_sym)))
       return FALSE;
    }

  /* Flush all symbols to the file.  */
  if (! elf_link_flush_output_syms (&finfo, bed))
    return FALSE;

  /* Now we know the size of the symtab section.  */
  off += symtab_hdr->sh_size;

  symtab_shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
  if (symtab_shndx_hdr->sh_name != 0)
    {
      symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
      symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
      symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
      amt = bfd_get_symcount (abfd) * sizeof (Elf_External_Sym_Shndx);
      symtab_shndx_hdr->sh_size = amt;

      off = _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr,
                                                 off, TRUE);

      if (bfd_seek (abfd, symtab_shndx_hdr->sh_offset, SEEK_SET) != 0
         || (bfd_bwrite (finfo.symshndxbuf, amt, abfd) != amt))
       return FALSE;
    }


  /* Finish up and write out the symbol string table (.strtab)
     section.  */
  symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
  /* sh_name was set in prep_headers.  */
  symstrtab_hdr->sh_type = SHT_STRTAB;
  symstrtab_hdr->sh_flags = 0;
  symstrtab_hdr->sh_addr = 0;
  symstrtab_hdr->sh_size = _bfd_stringtab_size (finfo.symstrtab);
  symstrtab_hdr->sh_entsize = 0;
  symstrtab_hdr->sh_link = 0;
  symstrtab_hdr->sh_info = 0;
  /* sh_offset is set just below.  */
  symstrtab_hdr->sh_addralign = 1;

  off = _bfd_elf_assign_file_position_for_section (symstrtab_hdr, off, TRUE);
  elf_tdata (abfd)->next_file_pos = off;

  if (bfd_get_symcount (abfd) > 0)
    {
      if (bfd_seek (abfd, symstrtab_hdr->sh_offset, SEEK_SET) != 0
         || ! _bfd_stringtab_emit (abfd, finfo.symstrtab))
       return FALSE;
    }

  /* Adjust the relocs to have the correct symbol indices.  */
  for (o = abfd->sections; o != NULL; o = o->next)
    {
      if ((o->flags & SEC_RELOC) == 0)
       continue;

      elf_link_adjust_relocs (abfd, &elf_section_data (o)->rel_hdr,
                           elf_section_data (o)->rel_count,
                           elf_section_data (o)->rel_hashes);
      if (elf_section_data (o)->rel_hdr2 != NULL)
       elf_link_adjust_relocs (abfd, elf_section_data (o)->rel_hdr2,
                            elf_section_data (o)->rel_count2,
                            (elf_section_data (o)->rel_hashes
                             + elf_section_data (o)->rel_count));

      /* Set the reloc_count field to 0 to prevent write_relocs from
        trying to swap the relocs out itself.  */
      o->reloc_count = 0;
    }

  if (dynamic && info->combreloc && dynobj != NULL)
    relativecount = elf_link_sort_relocs (abfd, info, &reldyn);

  /* If we are linking against a dynamic object, or generating a
     shared library, finish up the dynamic linking information.  */
  if (dynamic)
    {
      bfd_byte *dyncon, *dynconend;

      /* Fix up .dynamic entries.  */
      o = bfd_get_section_by_name (dynobj, ".dynamic");
      BFD_ASSERT (o != NULL);

      dyncon = o->contents;
      dynconend = o->contents + o->size;
      for (; dyncon < dynconend; dyncon += bed->s->sizeof_dyn)
       {
         Elf_Internal_Dyn dyn;
         const char *name;
         unsigned int type;

         bed->s->swap_dyn_in (dynobj, dyncon, &dyn);

         switch (dyn.d_tag)
           {
           default:
             continue;
           case DT_NULL:
             if (relativecount > 0 && dyncon + bed->s->sizeof_dyn < dynconend)
              {
                switch (elf_section_data (reldyn)->this_hdr.sh_type)
                  {
                  case SHT_REL: dyn.d_tag = DT_RELCOUNT; break;
                  case SHT_RELA: dyn.d_tag = DT_RELACOUNT; break;
                  default: continue;
                  }
                dyn.d_un.d_val = relativecount;
                relativecount = 0;
                break;
              }
             continue;

           case DT_INIT:
             name = info->init_function;
             goto get_sym;
           case DT_FINI:
             name = info->fini_function;
           get_sym:
             {
              struct elf_link_hash_entry *h;

              h = elf_link_hash_lookup (elf_hash_table (info), name,
                                     FALSE, FALSE, TRUE);
              if (h != NULL
                  && (h->root.type == bfd_link_hash_defined
                     || h->root.type == bfd_link_hash_defweak))
                {
                  dyn.d_un.d_val = h->root.u.def.value;
                  o = h->root.u.def.section;
                  if (o->output_section != NULL)
                    dyn.d_un.d_val += (o->output_section->vma
                                    + o->output_offset);
                  else
                    {
                     /* The symbol is imported from another shared
                        library and does not apply to this one.  */
                     dyn.d_un.d_val = 0;
                    }
                  break;
                }
             }
             continue;

           case DT_PREINIT_ARRAYSZ:
             name = ".preinit_array";
             goto get_size;
           case DT_INIT_ARRAYSZ:
             name = ".init_array";
             goto get_size;
           case DT_FINI_ARRAYSZ:
             name = ".fini_array";
           get_size:
             o = bfd_get_section_by_name (abfd, name);
             if (o == NULL)
              {
                (*_bfd_error_handler)
                  (_("%B: could not find output section %s"), abfd, name);
                goto error_return;
              }
             if (o->size == 0)
              (*_bfd_error_handler)
                (_("warning: %s section has zero size"), name);
             dyn.d_un.d_val = o->size;
             break;

           case DT_PREINIT_ARRAY:
             name = ".preinit_array";
             goto get_vma;
           case DT_INIT_ARRAY:
             name = ".init_array";
             goto get_vma;
           case DT_FINI_ARRAY:
             name = ".fini_array";
             goto get_vma;

           case DT_HASH:
             name = ".hash";
             goto get_vma;
           case DT_GNU_HASH:
             name = ".gnu.hash";
             goto get_vma;
           case DT_STRTAB:
             name = ".dynstr";
             goto get_vma;
           case DT_SYMTAB:
             name = ".dynsym";
             goto get_vma;
           case DT_VERDEF:
             name = ".gnu.version_d";
             goto get_vma;
           case DT_VERNEED:
             name = ".gnu.version_r";
             goto get_vma;
           case DT_VERSYM:
             name = ".gnu.version";
           get_vma:
             o = bfd_get_section_by_name (abfd, name);
             if (o == NULL)
              {
                (*_bfd_error_handler)
                  (_("%B: could not find output section %s"), abfd, name);
                goto error_return;
              }
             dyn.d_un.d_ptr = o->vma;
             break;

           case DT_REL:
           case DT_RELA:
           case DT_RELSZ:
           case DT_RELASZ:
             if (dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
              type = SHT_REL;
             else
              type = SHT_RELA;
             dyn.d_un.d_val = 0;
             for (i = 1; i < elf_numsections (abfd); i++)
              {
                Elf_Internal_Shdr *hdr;

                hdr = elf_elfsections (abfd)[i];
                if (hdr->sh_type == type
                    && (hdr->sh_flags & SHF_ALLOC) != 0)
                  {
                    if (dyn.d_tag == DT_RELSZ || dyn.d_tag == DT_RELASZ)
                     dyn.d_un.d_val += hdr->sh_size;
                    else
                     {
                       if (dyn.d_un.d_val == 0
                           || hdr->sh_addr < dyn.d_un.d_val)
                         dyn.d_un.d_val = hdr->sh_addr;
                     }
                  }
              }
             break;
           }
         bed->s->swap_dyn_out (dynobj, &dyn, dyncon);
       }
    }

  /* If we have created any dynamic sections, then output them.  */
  if (dynobj != NULL)
    {
      if (! (*bed->elf_backend_finish_dynamic_sections) (abfd, info))
       goto error_return;

      /* Check for DT_TEXTREL (late, in case the backend removes it).  */
      if (info->warn_shared_textrel && info->shared)
       {
         bfd_byte *dyncon, *dynconend;

         /* Fix up .dynamic entries.  */
         o = bfd_get_section_by_name (dynobj, ".dynamic");
         BFD_ASSERT (o != NULL);

         dyncon = o->contents;
         dynconend = o->contents + o->size;
         for (; dyncon < dynconend; dyncon += bed->s->sizeof_dyn)
           {
             Elf_Internal_Dyn dyn;

             bed->s->swap_dyn_in (dynobj, dyncon, &dyn);

             if (dyn.d_tag == DT_TEXTREL)
              {
                _bfd_error_handler
                  (_("warning: creating a DT_TEXTREL in a shared object."));
                break;
              }
           }
       }

      for (o = dynobj->sections; o != NULL; o = o->next)
       {
         if ((o->flags & SEC_HAS_CONTENTS) == 0
             || o->size == 0
             || o->output_section == bfd_abs_section_ptr)
           continue;
         if ((o->flags & SEC_LINKER_CREATED) == 0)
           {
             /* At this point, we are only interested in sections
               created by _bfd_elf_link_create_dynamic_sections.  */
             continue;
           }
         if (elf_hash_table (info)->stab_info.stabstr == o)
           continue;
         if (elf_hash_table (info)->eh_info.hdr_sec == o)
           continue;
         if ((elf_section_data (o->output_section)->this_hdr.sh_type
              != SHT_STRTAB)
             || strcmp (bfd_get_section_name (abfd, o), ".dynstr") != 0)
           {
             if (! bfd_set_section_contents (abfd, o->output_section,
                                         o->contents,
                                         (file_ptr) o->output_offset,
                                         o->size))
              goto error_return;
           }
         else
           {
             /* The contents of the .dynstr section are actually in a
               stringtab.  */
             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))
              goto error_return;
           }
       }
    }

  if (info->relocatable)
    {
      bfd_boolean failed = FALSE;

      bfd_map_over_sections (abfd, bfd_elf_set_group_contents, &failed);
      if (failed)
       goto error_return;
    }

  /* If we have optimized stabs strings, output them.  */
  if (elf_hash_table (info)->stab_info.stabstr != NULL)
    {
      if (! _bfd_write_stab_strings (abfd, &elf_hash_table (info)->stab_info))
       goto error_return;
    }

  if (info->eh_frame_hdr)
    {
      if (! _bfd_elf_write_section_eh_frame_hdr (abfd, info))
       goto error_return;
    }

  if (finfo.symstrtab != NULL)
    _bfd_stringtab_free (finfo.symstrtab);
  if (finfo.contents != NULL)
    free (finfo.contents);
  if (finfo.external_relocs != NULL)
    free (finfo.external_relocs);
  if (finfo.internal_relocs != NULL)
    free (finfo.internal_relocs);
  if (finfo.external_syms != NULL)
    free (finfo.external_syms);
  if (finfo.locsym_shndx != NULL)
    free (finfo.locsym_shndx);
  if (finfo.internal_syms != NULL)
    free (finfo.internal_syms);
  if (finfo.indices != NULL)
    free (finfo.indices);
  if (finfo.sections != NULL)
    free (finfo.sections);
  if (finfo.symbuf != NULL)
    free (finfo.symbuf);
  if (finfo.symshndxbuf != NULL)
    free (finfo.symshndxbuf);
  for (o = abfd->sections; o != NULL; o = o->next)
    {
      if ((o->flags & SEC_RELOC) != 0
         && elf_section_data (o)->rel_hashes != NULL)
       free (elf_section_data (o)->rel_hashes);
    }

  elf_tdata (abfd)->linker = TRUE;

  return TRUE;

 error_return:
  if (finfo.symstrtab != NULL)
    _bfd_stringtab_free (finfo.symstrtab);
  if (finfo.contents != NULL)
    free (finfo.contents);
  if (finfo.external_relocs != NULL)
    free (finfo.external_relocs);
  if (finfo.internal_relocs != NULL)
    free (finfo.internal_relocs);
  if (finfo.external_syms != NULL)
    free (finfo.external_syms);
  if (finfo.locsym_shndx != NULL)
    free (finfo.locsym_shndx);
  if (finfo.internal_syms != NULL)
    free (finfo.internal_syms);
  if (finfo.indices != NULL)
    free (finfo.indices);
  if (finfo.sections != NULL)
    free (finfo.sections);
  if (finfo.symbuf != NULL)
    free (finfo.symbuf);
  if (finfo.symshndxbuf != NULL)
    free (finfo.symshndxbuf);
  for (o = abfd->sections; o != NULL; o = o->next)
    {
      if ((o->flags & SEC_RELOC) != 0
         && elf_section_data (o)->rel_hashes != NULL)
       free (elf_section_data (o)->rel_hashes);
    }

  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 10837 of file elflink.c.

{
  if (!bfd_elf_gc_common_finalize_got_offsets (abfd, info))
    return FALSE;

  /* Invoke the regular ELF backend linker to do all the work.  */
  return bfd_elf_final_link (abfd, info);
}

Here is the call graph for this function:

Definition at line 10772 of file elflink.c.

{
  bfd *i;
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  bfd_vma gotoff;
  unsigned int got_elt_size = bed->s->arch_size / 8;
  struct alloc_got_off_arg gofarg;

  if (! is_elf_hash_table (info->hash))
    return FALSE;

  /* The GOT offset is relative to the .got section, but the GOT header is
     put into the .got.plt section, if the backend uses it.  */
  if (bed->want_got_plt)
    gotoff = 0;
  else
    gotoff = bed->got_header_size;

  /* Do the local .got entries first.  */
  for (i = info->input_bfds; i; i = i->link_next)
    {
      bfd_signed_vma *local_got;
      bfd_size_type j, locsymcount;
      Elf_Internal_Shdr *symtab_hdr;

      if (bfd_get_flavour (i) != bfd_target_elf_flavour)
       continue;

      local_got = elf_local_got_refcounts (i);
      if (!local_got)
       continue;

      symtab_hdr = &elf_tdata (i)->symtab_hdr;
      if (elf_bad_symtab (i))
       locsymcount = symtab_hdr->sh_size / bed->s->sizeof_sym;
      else
       locsymcount = symtab_hdr->sh_info;

      for (j = 0; j < locsymcount; ++j)
       {
         if (local_got[j] > 0)
           {
             local_got[j] = gotoff;
             gotoff += got_elt_size;
           }
         else
           local_got[j] = (bfd_vma) -1;
       }
    }

  /* Then the global .got entries.  .plt refcounts are handled by
     adjust_dynamic_symbol  */
  gofarg.gotoff = gotoff;
  gofarg.got_elt_size = got_elt_size;
  elf_link_hash_traverse (elf_hash_table (info),
                       elf_gc_allocate_got_offsets,
                       &gofarg);
  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 10463 of file elflink.c.

{
  struct bfd_link_info *info = (struct bfd_link_info *) inf;

  if (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)
      && (h->ref_dynamic
         || (!info->executable
             && h->def_regular
             && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
             && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN)))
    h->root.u.def.section->flags |= SEC_KEEP;

  return TRUE;
}
bfd_boolean bfd_elf_gc_record_vtentry ( bfd *abfd  ATTRIBUTE_UNUSED,
asection *sec  ATTRIBUTE_UNUSED,
struct elf_link_hash_entry h,
bfd_vma  addend 
)

Definition at line 10671 of file elflink.c.

{
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  unsigned int log_file_align = bed->s->log_file_align;

  if (!h->vtable)
    {
      h->vtable = bfd_zalloc (abfd, sizeof (*h->vtable));
      if (!h->vtable)
       return FALSE;
    }

  if (addend >= h->vtable->size)
    {
      size_t size, bytes, file_align;
      bfd_boolean *ptr = h->vtable->used;

      /* While the symbol is undefined, we have to be prepared to handle
        a zero size.  */
      file_align = 1 << log_file_align;
      if (h->root.type == bfd_link_hash_undefined)
       size = addend + file_align;
      else
       {
         size = h->size;
         if (addend >= size)
           {
             /* Oops!  We've got a reference past the defined end of
               the table.  This is probably a bug -- shall we warn?  */
             size = addend + file_align;
           }
       }
      size = (size + file_align - 1) & -file_align;

      /* Allocate one extra entry for use as a "done" flag for the
        consolidation pass.  */
      bytes = ((size >> log_file_align) + 1) * sizeof (bfd_boolean);

      if (ptr)
       {
         ptr = bfd_realloc (ptr - 1, bytes);

         if (ptr != NULL)
           {
             size_t oldbytes;

             oldbytes = (((h->vtable->size >> log_file_align) + 1)
                       * sizeof (bfd_boolean));
             memset (((char *) ptr) + oldbytes, 0, bytes - oldbytes);
           }
       }
      else
       ptr = bfd_zmalloc (bytes);

      if (ptr == NULL)
       return FALSE;

      /* And arrange for that done flag to be at index -1.  */
      h->vtable->used = ptr + 1;
      h->vtable->size = size;
    }

  h->vtable->used[addend >> log_file_align] = TRUE;

  return TRUE;
}

Here is the call graph for this function:

Definition at line 10609 of file elflink.c.

{
  struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
  struct elf_link_hash_entry **search, *child;
  bfd_size_type extsymcount;
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);

  /* The sh_info field of the symtab header tells us where the
     external symbols start.  We don't care about the local symbols at
     this point.  */
  extsymcount = elf_tdata (abfd)->symtab_hdr.sh_size / bed->s->sizeof_sym;
  if (!elf_bad_symtab (abfd))
    extsymcount -= elf_tdata (abfd)->symtab_hdr.sh_info;

  sym_hashes = elf_sym_hashes (abfd);
  sym_hashes_end = sym_hashes + extsymcount;

  /* Hunt down the child symbol, which is in this section at the same
     offset as the relocation.  */
  for (search = sym_hashes; search != sym_hashes_end; ++search)
    {
      if ((child = *search) != NULL
         && (child->root.type == bfd_link_hash_defined
             || child->root.type == bfd_link_hash_defweak)
         && child->root.u.def.section == sec
         && child->root.u.def.value == offset)
       goto win;
    }

  (*_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;

 win:
  if (!child->vtable)
    {
      child->vtable = bfd_zalloc (abfd, sizeof (*child->vtable));
      if (!child->vtable)
       return FALSE;
    }
  if (!h)
    {
      /* This *should* only be the absolute section.  It could potentially
        be that someone has defined a non-global vtable though, which
        would be bad.  It isn't worth paging in the local symbols to be
        sure though; that case should simply be handled by the assembler.  */

      child->vtable->parent = (struct elf_link_hash_entry *) -1;
    }
  else
    child->vtable->parent = h;

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 10485 of file elflink.c.

{
  bfd_boolean ok = TRUE;
  bfd *sub;
  elf_gc_mark_hook_fn gc_mark_hook;
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);

  if (!bed->can_gc_sections
      || info->relocatable
      || info->emitrelocations
      || !is_elf_hash_table (info->hash))
    {
      (*_bfd_error_handler)(_("Warning: gc-sections option ignored"));
      return TRUE;
    }

  /* Apply transitive closure to the vtable entry usage info.  */
  elf_link_hash_traverse (elf_hash_table (info),
                       elf_gc_propagate_vtable_entries_used,
                       &ok);
  if (!ok)
    return FALSE;

  /* Kill the vtable relocations that were not used.  */
  elf_link_hash_traverse (elf_hash_table (info),
                       elf_gc_smash_unused_vtentry_relocs,
                       &ok);
  if (!ok)
    return FALSE;

  /* Mark dynamically referenced symbols.  */
  if (elf_hash_table (info)->dynamic_sections_created)
    elf_link_hash_traverse (elf_hash_table (info),
                         bed->gc_mark_dynamic_ref,
                         info);

  /* Grovel through relocs to find out who stays ...  */
  gc_mark_hook = bed->gc_mark_hook;
  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
    {
      asection *o;

      if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
       continue;

      for (o = sub->sections; o != NULL; o = o->next)
       if ((o->flags & (SEC_EXCLUDE | SEC_KEEP)) == SEC_KEEP && !o->gc_mark)
         if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
           return FALSE;
    }

  /* Allow the backend to mark additional target specific sections.  */
  if (bed->gc_mark_extra_sections)
    bed->gc_mark_extra_sections(info, gc_mark_hook);

  /* ... again for sections marked from eh_frame.  */
  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
    {
      asection *o;

      if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
       continue;

      /* Keep .gcc_except_table.* if the associated .text.* (or the
        associated .gnu.linkonce.t.* if .text.* doesn't exist) is
        marked.  This isn't very nice, but the proper solution,
        splitting .eh_frame up and using comdat doesn't pan out
        easily due to needing special relocs to handle the
        difference of two symbols in separate sections.
        Don't keep code sections referenced by .eh_frame.  */
#define TEXT_PREFIX                ".text."
#define TEXT_PREFIX2               ".gnu.linkonce.t."
#define GCC_EXCEPT_TABLE_PREFIX           ".gcc_except_table."
      for (o = sub->sections; o != NULL; o = o->next)
       if (!o->gc_mark && o->gc_mark_from_eh && (o->flags & SEC_CODE) == 0)
         {
           if (CONST_STRNEQ (o->name, GCC_EXCEPT_TABLE_PREFIX))
             {
              char *fn_name;
              const char *sec_name;
              asection *fn_text;
              unsigned o_name_prefix_len , fn_name_prefix_len, tmp;

              o_name_prefix_len = strlen (GCC_EXCEPT_TABLE_PREFIX);
              sec_name = o->name + o_name_prefix_len;
              fn_name_prefix_len = strlen (TEXT_PREFIX);
              tmp = strlen (TEXT_PREFIX2);
              if (tmp > fn_name_prefix_len)
                fn_name_prefix_len = tmp;
              fn_name
                = bfd_malloc (fn_name_prefix_len + strlen (sec_name) + 1);
              if (fn_name == NULL)
                return FALSE;

              /* Try the first prefix.  */
              sprintf (fn_name, "%s%s", TEXT_PREFIX, sec_name);
              fn_text = bfd_get_section_by_name (sub, fn_name);

              /* Try the second prefix.  */
              if (fn_text == NULL)
                {
                  sprintf (fn_name, "%s%s", TEXT_PREFIX2, sec_name);
                  fn_text = bfd_get_section_by_name (sub, fn_name);
                }

              free (fn_name);
              if (fn_text == NULL || !fn_text->gc_mark)
                continue;
             }

           /* If not using specially named exception table section,
              then keep whatever we are using.  */
           if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
             return FALSE;
         }
    }

  /* ... and mark SEC_EXCLUDE for those that go.  */
  return elf_gc_sweep (abfd, info);
}

Here is the call graph for this function:

Definition at line 4880 of file elflink.c.

{
  switch (bfd_get_format (abfd))
    {
    case bfd_object:
      return elf_link_add_object_symbols (abfd, info);
    case bfd_archive:
      return elf_link_add_archive_symbols (abfd, info);
    default:
      bfd_set_error (bfd_error_wrong_format);
      return FALSE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bfd_elf_link_mark_dynamic_symbol ( struct bfd_link_info info,
struct elf_link_hash_entry h,
Elf_Internal_Sym *  sym 
)

Definition at line 440 of file elflink.c.

{
  struct bfd_elf_dynamic_list *d = info->dynamic_list;

  /* It may be called more than once on the same H.  */
  if(h->dynamic || info->relocatable)
    return;

  if ((info->dynamic_data
       && (h->type == STT_OBJECT
          || (sym != NULL
              && ELF_ST_TYPE (sym->st_info) == STT_OBJECT)))
      || (d != NULL 
         && h->root.type == bfd_link_hash_new
         && (*d->match) (&d->head, NULL, h->root.root.string)))
    h->dynamic = 1;
}

Here is the caller graph for this function:

Definition at line 370 of file elflink.c.

{
  if (h->dynindx == -1)
    {
      struct elf_strtab_hash *dynstr;
      char *p;
      const char *name;
      bfd_size_type indx;

      /* XXX: The ABI draft says the linker must turn hidden and
        internal symbols into STB_LOCAL symbols when producing the
        DSO. However, if ld.so honors st_other in the dynamic table,
        this would not be necessary.  */
      switch (ELF_ST_VISIBILITY (h->other))
       {
       case STV_INTERNAL:
       case STV_HIDDEN:
         if (h->root.type != bfd_link_hash_undefined
             && h->root.type != bfd_link_hash_undefweak)
           {
             h->forced_local = 1;
             if (!elf_hash_table (info)->is_relocatable_executable)
              return TRUE;
           }

       default:
         break;
       }

      h->dynindx = elf_hash_table (info)->dynsymcount;
      ++elf_hash_table (info)->dynsymcount;

      dynstr = elf_hash_table (info)->dynstr;
      if (dynstr == NULL)
       {
         /* Create a strtab to hold the dynamic symbol names.  */
         elf_hash_table (info)->dynstr = dynstr = _bfd_elf_strtab_init ();
         if (dynstr == NULL)
           return FALSE;
       }

      /* We don't put any version information in the dynamic string
        table.  */
      name = h->root.root.string;
      p = strchr (name, ELF_VER_CHR);
      if (p != NULL)
       /* We know that the p points into writable memory.  In fact,
          there are only a few symbols that have read-only names, being
          those like _GLOBAL_OFFSET_TABLE_ that are created specially
          by the backends.  Most symbols will have names pointing into
          an ELF string table read from a file, or to objalloc memory.  */
       *p = 0;

      indx = _bfd_elf_strtab_add (dynstr, name, p != NULL);

      if (p != NULL)
       *p = ELF_VER_CHR;

      if (indx == (bfd_size_type) -1)
       return FALSE;
      h->dynstr_index = indx;
    }

  return TRUE;
}

Here is the call graph for this function:

int bfd_elf_link_record_local_dynamic_symbol ( struct bfd_link_info info,
bfd input_bfd,
long  input_indx 
)

Definition at line 562 of file elflink.c.

{
  bfd_size_type amt;
  struct elf_link_local_dynamic_entry *entry;
  struct elf_link_hash_table *eht;
  struct elf_strtab_hash *dynstr;
  unsigned long dynstr_index;
  char *name;
  Elf_External_Sym_Shndx eshndx;
  char esym[sizeof (Elf64_External_Sym)];

  if (! is_elf_hash_table (info->hash))
    return 0;

  /* See if the entry exists already.  */
  for (entry = elf_hash_table (info)->dynlocal; entry ; entry = entry->next)
    if (entry->input_bfd == input_bfd && entry->input_indx == input_indx)
      return 1;

  amt = sizeof (*entry);
  entry = bfd_alloc (input_bfd, amt);
  if (entry == NULL)
    return 0;

  /* Go find the symbol, so that we can find it's name.  */
  if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
                          1, input_indx, &entry->isym, esym, &eshndx))
    {
      bfd_release (input_bfd, entry);
      return 0;
    }

  if (entry->isym.st_shndx != SHN_UNDEF
      && (entry->isym.st_shndx < SHN_LORESERVE
         || entry->isym.st_shndx > SHN_HIRESERVE))
    {
      asection *s;

      s = bfd_section_from_elf_index (input_bfd, entry->isym.st_shndx);
      if (s == NULL || bfd_is_abs_section (s->output_section))
       {
         /* We can still bfd_release here as nothing has done another
            bfd_alloc.  We can't do this later in this function.  */
         bfd_release (input_bfd, entry);
         return 2;
       }
    }

  name = (bfd_elf_string_from_elf_section
         (input_bfd, elf_tdata (input_bfd)->symtab_hdr.sh_link,
          entry->isym.st_name));

  dynstr = elf_hash_table (info)->dynstr;
  if (dynstr == NULL)
    {
      /* Create a strtab to hold the dynamic symbol names.  */
      elf_hash_table (info)->dynstr = dynstr = _bfd_elf_strtab_init ();
      if (dynstr == NULL)
       return 0;
    }

  dynstr_index = _bfd_elf_strtab_add (dynstr, name, FALSE);
  if (dynstr_index == (unsigned long) -1)
    return 0;
  entry->isym.st_name = dynstr_index;

  eht = elf_hash_table (info);

  entry->next = eht->dynlocal;
  eht->dynlocal = entry;
  entry->input_bfd = input_bfd;
  entry->input_indx = input_indx;
  eht->dynsymcount++;

  /* Whatever binding the symbol had before, it's now local.  */
  entry->isym.st_info
    = ELF_ST_INFO (STB_LOCAL, ELF_ST_TYPE (entry->isym.st_info));

  /* The dynindx will be set at the end of size_dynamic_sections.  */

  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bfd_elf_perform_complex_relocation ( bfd *output_bfd  ATTRIBUTE_UNUSED,
struct bfd_link_info info,
bfd input_bfd,
asection input_section,
bfd_byte contents,
Elf_Internal_Rela rel,
Elf_Internal_Sym *  local_syms,
asection **  local_sections 
)

Definition at line 6939 of file elflink.c.

{
  const struct elf_backend_data * bed;
  Elf_Internal_Shdr * symtab_hdr;
  asection * sec;
  bfd_vma relocation = 0, shift, x;
  bfd_vma r_symndx;
  bfd_vma mask;
  unsigned long start, oplen, len, wordsz, 
    chunksz, lsb0_p, signed_p, trunc_p;

  /*  Perform this reloc, since it is complex.
      (this is not to say that it necessarily refers to a complex
      symbol; merely that it is a self-describing CGEN based reloc.
      i.e. the addend has the complete reloc information (bit start, end,
      word size, etc) encoded within it.).  */ 
  r_symndx = ELF32_R_SYM (rel->r_info);
  bed = get_elf_backend_data (input_bfd);
  if (bed->s->arch_size == 64)
    r_symndx >>= 24;

#ifdef DEBUG
  printf ("Performing complex relocation %ld...\n", r_symndx);
#endif

  symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
  if (r_symndx < symtab_hdr->sh_info)
    {
      /* The symbol is local.  */
      Elf_Internal_Sym * sym;

      sym = local_syms + r_symndx;
      sec = local_sections [r_symndx];
      relocation = sym->st_value;
      if (sym->st_shndx > SHN_UNDEF && 
         sym->st_shndx < SHN_LORESERVE)
       relocation += (sec->output_offset +
                     sec->output_section->vma);
    }
  else
    {
      /* The symbol is global.  */
      struct elf_link_hash_entry **sym_hashes;
      struct elf_link_hash_entry * h;

      sym_hashes = elf_sym_hashes (input_bfd);
      h = sym_hashes [r_symndx];

      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)
       {
         sec = h->root.u.def.section;
         relocation = h->root.u.def.value;

         if (! bfd_is_abs_section (sec))
           relocation += (sec->output_section->vma 
                        + sec->output_offset); 
       }
      if (h->root.type == bfd_link_hash_undefined
         && !((*info->callbacks->undefined_symbol)
              (info, h->root.root.string, input_bfd,
              input_section, rel->r_offset,
              info->unresolved_syms_in_objects == RM_GENERATE_ERROR
              || ELF_ST_VISIBILITY (h->other))))
       return;
    }

  decode_complex_addend (& start, & oplen, & len, & wordsz, 
                      & chunksz, & lsb0_p, & signed_p, 
                      & trunc_p, rel->r_addend);

  mask = (((1L << (len - 1)) - 1) << 1) | 1;

  if (lsb0_p)
    shift = (start + 1) - len;
  else
    shift = (8 * wordsz) - (start + len);

  x = get_value (wordsz, chunksz, input_bfd, contents + rel->r_offset);        

#ifdef DEBUG
  printf ("Doing complex reloc: "
         "lsb0? %ld, signed? %ld, trunc? %ld, wordsz %ld, "
         "chunksz %ld, start %ld, len %ld, oplen %ld\n"
         "    dest: %8.8lx, mask: %8.8lx, reloc: %8.8lx\n",
         lsb0_p, signed_p, trunc_p, wordsz, chunksz, start, len,
         oplen, x, mask,  relocation);
#endif

  if (! trunc_p)
    {
      /* Now do an overflow check.  */
      if (bfd_check_overflow ((signed_p ? 
                            complain_overflow_signed : 
                            complain_overflow_unsigned),
                           len, 0, (8 * wordsz), 
                           relocation) == bfd_reloc_overflow)
       (*_bfd_error_handler) 
         ("%s (%s + 0x%lx): relocation overflow: 0x%lx %sdoes not fit "
          "within 0x%lx", 
          input_bfd->filename, input_section->name, rel->r_offset,
          relocation, (signed_p ? "(signed) " : ""), mask);
    }
         
  /* Do the deed.  */
  x = (x & ~(mask << shift)) | ((relocation & mask) << shift);

#ifdef DEBUG
  printf ("           relocation: %8.8lx\n"
         "         shifted mask: %8.8lx\n"
         " shifted/masked reloc: %8.8lx\n"
         "               result: %8.8lx\n",
         relocation, (mask << shift), 
         ((relocation & mask) << shift), x);
#endif
  put_value (wordsz, chunksz, input_bfd, x, contents + rel->r_offset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bfd_boolean bfd_elf_record_link_assignment ( bfd output_bfd,
struct bfd_link_info info,
const char *  name,
bfd_boolean  provide,
bfd_boolean  hidden 
)

Definition at line 464 of file elflink.c.

{
  struct elf_link_hash_entry *h;
  struct elf_link_hash_table *htab;

  if (!is_elf_hash_table (info->hash))
    return TRUE;

  htab = elf_hash_table (info);
  h = elf_link_hash_lookup (htab, name, !provide, TRUE, FALSE);
  if (h == NULL)
    return provide;

  /* Since we're defining the symbol, don't let it seem to have not
     been defined.  record_dynamic_symbol and size_dynamic_sections
     may depend on this.  */
  if (h->root.type == bfd_link_hash_undefweak
      || h->root.type == bfd_link_hash_undefined)
    {
      h->root.type = bfd_link_hash_new;
      if (h->root.u.undef.next != NULL || htab->root.undefs_tail == &h->root)
       bfd_link_repair_undef_list (&htab->root);
    }

  if (h->root.type == bfd_link_hash_new)
    {
      bfd_elf_link_mark_dynamic_symbol (info, h, NULL);
      h->non_elf = 0;
    }

  /* If this symbol is being provided by the linker script, and it is
     currently defined by a dynamic object, but not by a regular
     object, then mark it as undefined so that the generic linker will
     force the correct value.  */
  if (provide
      && h->def_dynamic
      && !h->def_regular)
    h->root.type = bfd_link_hash_undefined;

  /* If this symbol is not being provided by the linker script, and it is
     currently defined by a dynamic object, but not by a regular object,
     then clear out any version information because the symbol will not be
     associated with the dynamic object any more.  */
  if (!provide
      && h->def_dynamic
      && !h->def_regular)
    h->verinfo.verdef = NULL;

  h->def_regular = 1;

  if (provide && hidden)
    {
      const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);

      h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
      (*bed->elf_backend_hide_symbol) (info, h, TRUE);
    }

  /* STV_HIDDEN and STV_INTERNAL symbols must be STB_LOCAL in shared objects
     and executables.  */
  if (!info->relocatable
      && h->dynindx != -1
      && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
         || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
    h->forced_local = 1;

  if ((h->def_dynamic
       || h->ref_dynamic
       || info->shared
       || (info->executable && elf_hash_table (info)->is_relocatable_executable))
      && h->dynindx == -1)
    {
      if (! bfd_elf_link_record_dynamic_symbol (info, h))
       return FALSE;

      /* If this is a weak defined symbol, and we know a corresponding
        real symbol from the same dynamic object, make sure the real
        symbol is also made into a dynamic symbol.  */
      if (h->u.weakdef != NULL
         && h->u.weakdef->dynindx == -1)
       {
         if (! bfd_elf_link_record_dynamic_symbol (info, h->u.weakdef))
           return FALSE;
       }
    }

  return TRUE;
}

Here is the call graph for this function:

bfd_boolean bfd_elf_reloc_symbol_deleted_p ( bfd_vma  offset,
void *  cookie 
)

Definition at line 10847 of file elflink.c.

{
  struct elf_reloc_cookie *rcookie = cookie;

  if (rcookie->bad_symtab)
    rcookie->rel = rcookie->rels;

  for (; rcookie->rel < rcookie->relend; rcookie->rel++)
    {
      unsigned long r_symndx;

      if (! rcookie->bad_symtab)
       if (rcookie->rel->r_offset > offset)
         return FALSE;
      if (rcookie->rel->r_offset != offset)
       continue;

      r_symndx = rcookie->rel->r_info >> rcookie->r_sym_shift;
      if (r_symndx == SHN_UNDEF)
       return TRUE;

      if (r_symndx >= rcookie->locsymcount
         || ELF_ST_BIND (rcookie->locsyms[r_symndx].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)
             && elf_discarded_section (h->root.u.def.section))
           return TRUE;
         else
           return FALSE;
       }
      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 = &rcookie->locsyms[r_symndx];
         if (isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE)
           {
             isec = bfd_section_from_elf_index (rcookie->abfd, isym->st_shndx);
             if (isec != NULL && elf_discarded_section (isec))
              return TRUE;
           }
       }
      return FALSE;
    }
  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bfd_boolean bfd_elf_size_dynamic_sections ( bfd output_bfd,
const char *  soname,
const char *  rpath,
const char *  filter_shlib,
const char *const auxiliary_filters,
struct bfd_link_info info,
asection **  sinterpptr,
struct bfd_elf_version_tree verdefs 
)

Definition at line 5219 of file elflink.c.

{
  bfd_size_type soname_indx;
  bfd *dynobj;
  const struct elf_backend_data *bed;
  struct elf_assign_sym_version_info asvinfo;

  *sinterpptr = NULL;

  soname_indx = (bfd_size_type) -1;

  if (!is_elf_hash_table (info->hash))
    return TRUE;

  bed = get_elf_backend_data (output_bfd);
  elf_tdata (output_bfd)->relro = info->relro;
  if (info->execstack)
    elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
  else if (info->noexecstack)
    elf_tdata (output_bfd)->stack_flags = PF_R | PF_W;
  else
    {
      bfd *inputobj;
      asection *notesec = NULL;
      int exec = 0;

      for (inputobj = info->input_bfds;
          inputobj;
          inputobj = inputobj->link_next)
       {
         asection *s;

         if (inputobj->flags & (DYNAMIC | BFD_LINKER_CREATED))
           continue;
         s = bfd_get_section_by_name (inputobj, ".note.GNU-stack");
         if (s)
           {
             if (s->flags & SEC_CODE)
              exec = PF_X;
             notesec = s;
           }
         else if (bed->default_execstack)
           exec = PF_X;
       }
      if (notesec)
       {
         elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | exec;
         if (exec && info->relocatable
             && notesec->output_section != bfd_abs_section_ptr)
           notesec->output_section->flags |= SEC_CODE;
       }
    }

  /* Any syms created from now on start with -1 in
     got.refcount/offset and plt.refcount/offset.  */
  elf_hash_table (info)->init_got_refcount
    = elf_hash_table (info)->init_got_offset;
  elf_hash_table (info)->init_plt_refcount
    = elf_hash_table (info)->init_plt_offset;

  /* The backend may have to create some sections regardless of whether
     we're dynamic or not.  */
  if (bed->elf_backend_always_size_sections
      && ! (*bed->elf_backend_always_size_sections) (output_bfd, info))
    return FALSE;

  if (! _bfd_elf_maybe_strip_eh_frame_hdr (info))
    return FALSE;

  dynobj = elf_hash_table (info)->dynobj;

  /* If there were no dynamic objects in the link, there is nothing to
     do here.  */
  if (dynobj == NULL)
    return TRUE;

  if (elf_hash_table (info)->dynamic_sections_created)
    {
      struct elf_info_failed eif;
      struct elf_link_hash_entry *h;
      asection *dynstr;
      struct bfd_elf_version_tree *t;
      struct bfd_elf_version_expr *d;
      asection *s;
      bfd_boolean all_defined;

      *sinterpptr = bfd_get_section_by_name (dynobj, ".interp");
      BFD_ASSERT (*sinterpptr != NULL || !info->executable);

      if (soname != NULL)
       {
         soname_indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
                                        soname, TRUE);
         if (soname_indx == (bfd_size_type) -1
             || !_bfd_elf_add_dynamic_entry (info, DT_SONAME, soname_indx))
           return FALSE;
       }

      if (info->symbolic)
       {
         if (!_bfd_elf_add_dynamic_entry (info, DT_SYMBOLIC, 0))
           return FALSE;
         info->flags |= DF_SYMBOLIC;
       }

      if (rpath != NULL)
       {
         bfd_size_type indx;

         indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, rpath,
                                  TRUE);
         if (indx == (bfd_size_type) -1
             || !_bfd_elf_add_dynamic_entry (info, DT_RPATH, indx))
           return FALSE;

         if  (info->new_dtags)
           {
             _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr, indx);
             if (!_bfd_elf_add_dynamic_entry (info, DT_RUNPATH, indx))
              return FALSE;
           }
       }

      if (filter_shlib != NULL)
       {
         bfd_size_type indx;

         indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
                                  filter_shlib, TRUE);
         if (indx == (bfd_size_type) -1
             || !_bfd_elf_add_dynamic_entry (info, DT_FILTER, indx))
           return FALSE;
       }

      if (auxiliary_filters != NULL)
       {
         const char * const *p;

         for (p = auxiliary_filters; *p != NULL; p++)
           {
             bfd_size_type indx;

             indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
                                     *p, TRUE);
             if (indx == (bfd_size_type) -1
                || !_bfd_elf_add_dynamic_entry (info, DT_AUXILIARY, indx))
              return FALSE;
           }
       }

      eif.info = info;
      eif.verdefs = verdefs;
      eif.failed = FALSE;

      /* If we are supposed to export all symbols into the dynamic symbol
        table (this is not the normal case), then do so.  */
      if (info->export_dynamic
         || (info->executable && info->dynamic))
       {
         elf_link_hash_traverse (elf_hash_table (info),
                              _bfd_elf_export_symbol,
                              &eif);
         if (eif.failed)
           return FALSE;
       }

      /* Make all global versions with definition.  */
      for (t = verdefs; t != NULL; t = t->next)
       for (d = t->globals.list; d != NULL; d = d->next)
         if (!d->symver && d->symbol)
           {
             const char *verstr, *name;
             size_t namelen, verlen, newlen;
             char *newname, *p;
             struct elf_link_hash_entry *newh;

             name = d->symbol;
             namelen = strlen (name);
             verstr = t->name;
             verlen = strlen (verstr);
             newlen = namelen + verlen + 3;

             newname = bfd_malloc (newlen);
             if (newname == NULL)
              return FALSE;
             memcpy (newname, name, namelen);

             /* Check the hidden versioned definition.  */
             p = newname + namelen;
             *p++ = ELF_VER_CHR;
             memcpy (p, verstr, verlen + 1);
             newh = elf_link_hash_lookup (elf_hash_table (info),
                                      newname, FALSE, FALSE,
                                      FALSE);
             if (newh == NULL
                || (newh->root.type != bfd_link_hash_defined
                    && newh->root.type != bfd_link_hash_defweak))
              {
                /* Check the default versioned definition.  */
                *p++ = ELF_VER_CHR;
                memcpy (p, verstr, verlen + 1);
                newh = elf_link_hash_lookup (elf_hash_table (info),
                                          newname, FALSE, FALSE,
                                          FALSE);
              }
             free (newname);

             /* Mark this version if there is a definition and it is
               not defined in a shared object.  */
             if (newh != NULL
                && !newh->def_dynamic
                && (newh->root.type == bfd_link_hash_defined
                    || newh->root.type == bfd_link_hash_defweak))
              d->symver = 1;
           }

      /* Attach all the symbols to their version information.  */
      asvinfo.output_bfd = output_bfd;
      asvinfo.info = info;
      asvinfo.verdefs = verdefs;
      asvinfo.failed = FALSE;

      elf_link_hash_traverse (elf_hash_table (info),
                           _bfd_elf_link_assign_sym_version,
                           &asvinfo);
      if (asvinfo.failed)
       return FALSE;

      if (!info->allow_undefined_version)
       {
         /* Check if all global versions have a definition.  */
         all_defined = TRUE;
         for (t = verdefs; t != NULL; t = t->next)
           for (d = t->globals.list; d != NULL; d = d->next)
             if (!d->symver && !d->script)
              {
                (*_bfd_error_handler)
                  (_("%s: undefined version: %s"),
                   d->pattern, t->name);
                all_defined = FALSE;
              }

         if (!all_defined)
           {
             bfd_set_error (bfd_error_bad_value);
             return FALSE;
           }
       }

      /* Find all symbols which were defined in a dynamic object and make
        the backend pick a reasonable value for them.  */
      elf_link_hash_traverse (elf_hash_table (info),
                           _bfd_elf_adjust_dynamic_symbol,
                           &eif);
      if (eif.failed)
       return FALSE;

      /* Add some entries to the .dynamic section.  We fill in some of the
        values later, in bfd_elf_final_link, but we must add the entries
        now so that we know the final size of the .dynamic section.  */

      /* If there are initialization and/or finalization functions to
        call then add the corresponding DT_INIT/DT_FINI entries.  */
      h = (info->init_function
          ? elf_link_hash_lookup (elf_hash_table (info),
                               info->init_function, FALSE,
                               FALSE, FALSE)
          : NULL);
      if (h != NULL
         && (h->ref_regular
             || h->def_regular))
       {
         if (!_bfd_elf_add_dynamic_entry (info, DT_INIT, 0))
           return FALSE;
       }
      h = (info->fini_function
          ? elf_link_hash_lookup (elf_hash_table (info),
                               info->fini_function, FALSE,
                               FALSE, FALSE)
          : NULL);
      if (h != NULL
         && (h->ref_regular
             || h->def_regular))
       {
         if (!_bfd_elf_add_dynamic_entry (info, DT_FINI, 0))
           return FALSE;
       }

      s = bfd_get_section_by_name (output_bfd, ".preinit_array");
      if (s != NULL && s->linker_has_input)
       {
         /* DT_PREINIT_ARRAY is not allowed in shared library.  */
         if (! info->executable)
           {
             bfd *sub;
             asection *o;

             for (sub = info->input_bfds; sub != NULL;
                 sub = sub->link_next)
              for (o = sub->sections; o != NULL; o = o->next)
                if (elf_section_data (o)->this_hdr.sh_type
                    == SHT_PREINIT_ARRAY)
                  {
                    (*_bfd_error_handler)
                     (_("%B: .preinit_array section is not allowed in DSO"),
                      sub);
                    break;
                  }

             bfd_set_error (bfd_error_nonrepresentable_section);
             return FALSE;
           }

         if (!_bfd_elf_add_dynamic_entry (info, DT_PREINIT_ARRAY, 0)
             || !_bfd_elf_add_dynamic_entry (info, DT_PREINIT_ARRAYSZ, 0))
           return FALSE;
       }
      s = bfd_get_section_by_name (output_bfd, ".init_array");
      if (s != NULL && s->linker_has_input)
       {
         if (!_bfd_elf_add_dynamic_entry (info, DT_INIT_ARRAY, 0)
             || !_bfd_elf_add_dynamic_entry (info, DT_INIT_ARRAYSZ, 0))
           return FALSE;
       }
      s = bfd_get_section_by_name (output_bfd, ".fini_array");
      if (s != NULL && s->linker_has_input)
       {
         if (!_bfd_elf_add_dynamic_entry (info, DT_FINI_ARRAY, 0)
             || !_bfd_elf_add_dynamic_entry (info, DT_FINI_ARRAYSZ, 0))
           return FALSE;
       }

      dynstr = bfd_get_section_by_name (dynobj, ".dynstr");
      /* If .dynstr is excluded from the link, we don't want any of
        these tags.  Strictly, we should be checking each section
        individually;  This quick check covers for the case where
        someone does a /DISCARD/ : { *(*) }.  */
      if (dynstr != NULL && dynstr->output_section != bfd_abs_section_ptr)
       {
         bfd_size_type strsize;

         strsize = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
         if ((info->emit_hash
              && !_bfd_elf_add_dynamic_entry (info, DT_HASH, 0))
             || (info->emit_gnu_hash
                && !_bfd_elf_add_dynamic_entry (info, DT_GNU_HASH, 0))
             || !_bfd_elf_add_dynamic_entry (info, DT_STRTAB, 0)
             || !_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))
           return FALSE;
       }
    }

  /* The backend must work out the sizes of all the other dynamic
     sections.  */
  if (bed->elf_backend_size_dynamic_sections
      && ! (*bed->elf_backend_size_dynamic_sections) (output_bfd, info))
    return FALSE;

  if (elf_hash_table (info)->dynamic_sections_created)
    {
      unsigned long section_sym_count;
      asection *s;

      /* Set up the version definition section.  */
      s = bfd_get_section_by_name (dynobj, ".gnu.version_d");
      BFD_ASSERT (s != NULL);

      /* We may have created additional version definitions if we are
        just linking a regular application.  */
      verdefs = asvinfo.verdefs;

      /* Skip anonymous version tag.  */
      if (verdefs != NULL && verdefs->vernum == 0)
       verdefs = verdefs->next;

      if (verdefs == NULL && !info->create_default_symver)
       s->flags |= SEC_EXCLUDE;
      else
       {
         unsigned int cdefs;
         bfd_size_type size;
         struct bfd_elf_version_tree *t;
         bfd_byte *p;
         Elf_Internal_Verdef def;
         Elf_Internal_Verdaux defaux;
         struct bfd_link_hash_entry *bh;
         struct elf_link_hash_entry *h;
         const char *name;

         cdefs = 0;
         size = 0;

         /* Make space for the base version.  */
         size += sizeof (Elf_External_Verdef);
         size += sizeof (Elf_External_Verdaux);
         ++cdefs;

         /* Make space for the default version.  */
         if (info->create_default_symver)
           {
             size += sizeof (Elf_External_Verdef);
             ++cdefs;
           }

         for (t = verdefs; t != NULL; t = t->next)
           {
             struct bfd_elf_version_deps *n;

             size += sizeof (Elf_External_Verdef);
             size += sizeof (Elf_External_Verdaux);
             ++cdefs;

             for (n = t->deps; n != NULL; n = n->next)
              size += sizeof (Elf_External_Verdaux);
           }

         s->size = size;
         s->contents = bfd_alloc (output_bfd, s->size);
         if (s->contents == NULL && s->size != 0)
           return FALSE;

         /* Fill in the version definition section.  */

         p = s->contents;

         def.vd_version = VER_DEF_CURRENT;
         def.vd_flags = VER_FLG_BASE;
         def.vd_ndx = 1;
         def.vd_cnt = 1;
         if (info->create_default_symver)
           {
             def.vd_aux = 2 * sizeof (Elf_External_Verdef);
             def.vd_next = sizeof (Elf_External_Verdef);
           }
         else
           {
             def.vd_aux = sizeof (Elf_External_Verdef);
             def.vd_next = (sizeof (Elf_External_Verdef)
                          + sizeof (Elf_External_Verdaux));
           }

         if (soname_indx != (bfd_size_type) -1)
           {
             _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr,
                                  soname_indx);
             def.vd_hash = bfd_elf_hash (soname);
             defaux.vda_name = soname_indx;
             name = soname;
           }
         else
           {
             bfd_size_type indx;

             name = lbasename (output_bfd->filename);
             def.vd_hash = bfd_elf_hash (name);
             indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
                                     name, FALSE);
             if (indx == (bfd_size_type) -1)
              return FALSE;
             defaux.vda_name = indx;
           }
         defaux.vda_next = 0;

         _bfd_elf_swap_verdef_out (output_bfd, &def,
                                (Elf_External_Verdef *) p);
         p += sizeof (Elf_External_Verdef);
         if (info->create_default_symver)
           {
             /* Add a symbol representing this version.  */
             bh = NULL;
             if (! (_bfd_generic_link_add_one_symbol
                   (info, dynobj, name, BSF_GLOBAL, bfd_abs_section_ptr,
                    0, NULL, FALSE,
                    get_elf_backend_data (dynobj)->collect, &bh)))
              return FALSE;
             h = (struct elf_link_hash_entry *) bh;
             h->non_elf = 0;
             h->def_regular = 1;
             h->type = STT_OBJECT;
             h->verinfo.vertree = NULL;

             if (! bfd_elf_link_record_dynamic_symbol (info, h))
              return FALSE;

             /* Create a duplicate of the base version with the same
               aux block, but different flags.  */
             def.vd_flags = 0;
             def.vd_ndx = 2;
             def.vd_aux = sizeof (Elf_External_Verdef);
             if (verdefs)
              def.vd_next = (sizeof (Elf_External_Verdef)
                            + sizeof (Elf_External_Verdaux));
             else
              def.vd_next = 0;
             _bfd_elf_swap_verdef_out (output_bfd, &def,
                                   (Elf_External_Verdef *) p);
             p += sizeof (Elf_External_Verdef);
           }
         _bfd_elf_swap_verdaux_out (output_bfd, &defaux,
                                 (Elf_External_Verdaux *) p);
         p += sizeof (Elf_External_Verdaux);

         for (t = verdefs; t != NULL; t = t->next)
           {
             unsigned int cdeps;
             struct bfd_elf_version_deps *n;

             cdeps = 0;
             for (n = t->deps; n != NULL; n = n->next)
              ++cdeps;

             /* Add a symbol representing this version.  */
             bh = NULL;
             if (! (_bfd_generic_link_add_one_symbol
                   (info, dynobj, t->name, BSF_GLOBAL, bfd_abs_section_ptr,
                    0, NULL, FALSE,
                    get_elf_backend_data (dynobj)->collect, &bh)))
              return FALSE;
             h = (struct elf_link_hash_entry *) bh;
             h->non_elf = 0;
             h->def_regular = 1;
             h->type = STT_OBJECT;
             h->verinfo.vertree = t;

             if (! bfd_elf_link_record_dynamic_symbol (info, h))
              return FALSE;

             def.vd_version = VER_DEF_CURRENT;
             def.vd_flags = 0;
             if (t->globals.list == NULL
                && t->locals.list == NULL
                && ! t->used)
              def.vd_flags |= VER_FLG_WEAK;
             def.vd_ndx = t->vernum + (info->create_default_symver ? 2 : 1);
             def.vd_cnt = cdeps + 1;
             def.vd_hash = bfd_elf_hash (t->name);
             def.vd_aux = sizeof (Elf_External_Verdef);
             def.vd_next = 0;
             if (t->next != NULL)
              def.vd_next = (sizeof (Elf_External_Verdef)
                            + (cdeps + 1) * sizeof (Elf_External_Verdaux));

             _bfd_elf_swap_verdef_out (output_bfd, &def,
                                   (Elf_External_Verdef *) p);
             p += sizeof (Elf_External_Verdef);

             defaux.vda_name = h->dynstr_index;
             _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr,
                                  h->dynstr_index);
             defaux.vda_next = 0;
             if (t->deps != NULL)
              defaux.vda_next = sizeof (Elf_External_Verdaux);
             t->name_indx = defaux.vda_name;

             _bfd_elf_swap_verdaux_out (output_bfd, &defaux,
                                    (Elf_External_Verdaux *) p);
             p += sizeof (Elf_External_Verdaux);

             for (n = t->deps; n != NULL; n = n->next)
              {
                if (n->version_needed == NULL)
                  {
                    /* This can happen if there was an error in the
                      version script.  */
                    defaux.vda_name = 0;
                  }
                else
                  {
                    defaux.vda_name = n->version_needed->name_indx;
                    _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr,
                                         defaux.vda_name);
                  }
                if (n->next == NULL)
                  defaux.vda_next = 0;
                else
                  defaux.vda_next = sizeof (Elf_External_Verdaux);

                _bfd_elf_swap_verdaux_out (output_bfd, &defaux,
                                        (Elf_External_Verdaux *) p);
                p += sizeof (Elf_External_Verdaux);
              }
           }

         if (!_bfd_elf_add_dynamic_entry (info, DT_VERDEF, 0)
             || !_bfd_elf_add_dynamic_entry (info, DT_VERDEFNUM, cdefs))
           return FALSE;

         elf_tdata (output_bfd)->cverdefs = cdefs;
       }

      if ((info->new_dtags && info->flags) || (info->flags & DF_STATIC_TLS))
       {
         if (!_bfd_elf_add_dynamic_entry (info, DT_FLAGS, info->flags))
           return FALSE;
       }
      else if (info->flags & DF_BIND_NOW)
       {
         if (!_bfd_elf_add_dynamic_entry (info, DT_BIND_NOW, 0))
           return FALSE;
       }

      if (info->flags_1)
       {
         if (info->executable)
           info->flags_1 &= ~ (DF_1_INITFIRST
                            | DF_1_NODELETE
                            | DF_1_NOOPEN);
         if (!_bfd_elf_add_dynamic_entry (info, DT_FLAGS_1, info->flags_1))
           return FALSE;
       }

      /* Work out the size of the version reference section.  */

      s = bfd_get_section_by_name (dynobj, ".gnu.version_r");
      BFD_ASSERT (s != NULL);
      {
       struct elf_find_verdep_info sinfo;

       sinfo.output_bfd = output_bfd;
       sinfo.info = info;
       sinfo.vers = elf_tdata (output_bfd)->cverdefs;
       if (sinfo.vers == 0)
         sinfo.vers = 1;
       sinfo.failed = FALSE;

       elf_link_hash_traverse (elf_hash_table (info),
                            _bfd_elf_link_find_version_dependencies,
                            &sinfo);

       if (elf_tdata (output_bfd)->verref == NULL)
         s->flags |= SEC_EXCLUDE;
       else
         {
           Elf_Internal_Verneed *t;
           unsigned int size;
           unsigned int crefs;
           bfd_byte *p;

           /* Build the version definition section.  */
           size = 0;
           crefs = 0;
           for (t = elf_tdata (output_bfd)->verref;
               t != NULL;
               t = t->vn_nextref)
             {
              Elf_Internal_Vernaux *a;

              size += sizeof (Elf_External_Verneed);
              ++crefs;
              for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
                size += sizeof (Elf_External_Vernaux);
             }

           s->size = size;
           s->contents = bfd_alloc (output_bfd, s->size);
           if (s->contents == NULL)
             return FALSE;

           p = s->contents;
           for (t = elf_tdata (output_bfd)->verref;
               t != NULL;
               t = t->vn_nextref)
             {
              unsigned int caux;
              Elf_Internal_Vernaux *a;
              bfd_size_type indx;

              caux = 0;
              for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
                ++caux;

              t->vn_version = VER_NEED_CURRENT;
              t->vn_cnt = caux;
              indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
                                       elf_dt_name (t->vn_bfd) != NULL
                                       ? elf_dt_name (t->vn_bfd)
                                       : lbasename (t->vn_bfd->filename),
                                       FALSE);
              if (indx == (bfd_size_type) -1)
                return FALSE;
              t->vn_file = indx;
              t->vn_aux = sizeof (Elf_External_Verneed);
              if (t->vn_nextref == NULL)
                t->vn_next = 0;
              else
                t->vn_next = (sizeof (Elf_External_Verneed)
                            + caux * sizeof (Elf_External_Vernaux));

              _bfd_elf_swap_verneed_out (output_bfd, t,
                                      (Elf_External_Verneed *) p);
              p += sizeof (Elf_External_Verneed);

              for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
                {
                  a->vna_hash = bfd_elf_hash (a->vna_nodename);
                  indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
                                          a->vna_nodename, FALSE);
                  if (indx == (bfd_size_type) -1)
                    return FALSE;
                  a->vna_name = indx;
                  if (a->vna_nextptr == NULL)
                    a->vna_next = 0;
                  else
                    a->vna_next = sizeof (Elf_External_Vernaux);

                  _bfd_elf_swap_vernaux_out (output_bfd, a,
                                          (Elf_External_Vernaux *) p);
                  p += sizeof (Elf_External_Vernaux);
                }
             }

           if (!_bfd_elf_add_dynamic_entry (info, DT_VERNEED, 0)
              || !_bfd_elf_add_dynamic_entry (info, DT_VERNEEDNUM, crefs))
             return FALSE;

           elf_tdata (output_bfd)->cverrefs = crefs;
         }
      }

      if ((elf_tdata (output_bfd)->cverrefs == 0
          && elf_tdata (output_bfd)->cverdefs == 0)
         || _bfd_elf_link_renumber_dynsyms (output_bfd, info,
                                        &section_sym_count) == 0)
       {
         s = bfd_get_section_by_name (dynobj, ".gnu.version");
         s->flags |= SEC_EXCLUDE;
       }
    }
  return TRUE;
}

Here is the call graph for this function:

Definition at line 6006 of file elflink.c.

{
  const struct elf_backend_data *bed;

  if (!is_elf_hash_table (info->hash))
    return TRUE;

  bed = get_elf_backend_data (output_bfd);
  (*bed->elf_backend_init_index_section) (output_bfd, info);

  if (elf_hash_table (info)->dynamic_sections_created)
    {
      bfd *dynobj;
      asection *s;
      bfd_size_type dynsymcount;
      unsigned long section_sym_count;
      unsigned int dtagcount;

      dynobj = elf_hash_table (info)->dynobj;

      /* Assign dynsym indicies.  In a shared library we generate a
        section symbol for each output section, which come first.
        Next come all of the back-end allocated local dynamic syms,
        followed by the rest of the global symbols.  */

      dynsymcount = _bfd_elf_link_renumber_dynsyms (output_bfd, info,
                                              &section_sym_count);

      /* Work out the size of the symbol version section.  */
      s = bfd_get_section_by_name (dynobj, ".gnu.version");
      BFD_ASSERT (s != NULL);
      if (dynsymcount != 0
         && (s->flags & SEC_EXCLUDE) == 0)
       {
         s->size = dynsymcount * sizeof (Elf_External_Versym);
         s->contents = bfd_zalloc (output_bfd, s->size);
         if (s->contents == NULL)
           return FALSE;

         if (!_bfd_elf_add_dynamic_entry (info, DT_VERSYM, 0))
           return FALSE;
       }

      /* Set the size of the .dynsym and .hash sections.  We counted
        the number of dynamic symbols in elf_link_add_object_symbols.
        We will build the contents of .dynsym and .hash when we build
        the final symbol table, because until then we do not know the
        correct value to give the symbols.  We built the .dynstr
        section as we went along in elf_link_add_object_symbols.  */
      s = bfd_get_section_by_name (dynobj, ".dynsym");
      BFD_ASSERT (s != NULL);
      s->size = dynsymcount * bed->s->sizeof_sym;

      if (dynsymcount != 0)
       {
         s->contents = bfd_alloc (output_bfd, s->size);
         if (s->contents == NULL)
           return FALSE;

         /* The first entry in .dynsym is a dummy symbol.
            Clear all the section syms, in case we don't output them all.  */
         ++section_sym_count;
         memset (s->contents, 0, section_sym_count * bed->s->sizeof_sym);
       }

      elf_hash_table (info)->bucketcount = 0;

      /* Compute the size of the hashing table.  As a side effect this
        computes the hash values for all the names we export.  */
      if (info->emit_hash)
       {
         unsigned long int *hashcodes;
         unsigned long int *hashcodesp;
         bfd_size_type amt;
         unsigned long int nsyms;
         size_t bucketcount;
         size_t hash_entry_size;

         /* Compute the hash values for all exported symbols.  At the same
            time store the values in an array so that we could use them for
            optimizations.  */
         amt = dynsymcount * sizeof (unsigned long int);
         hashcodes = bfd_malloc (amt);
         if (hashcodes == NULL)
           return FALSE;
         hashcodesp = hashcodes;

         /* Put all hash values in HASHCODES.  */
         elf_link_hash_traverse (elf_hash_table (info),
                              elf_collect_hash_codes, &hashcodesp);

         nsyms = hashcodesp - hashcodes;
         bucketcount
           = compute_bucket_count (info, hashcodes, nsyms, 0);
         free (hashcodes);

         if (bucketcount == 0)
           return FALSE;

         elf_hash_table (info)->bucketcount = bucketcount;

         s = bfd_get_section_by_name (dynobj, ".hash");
         BFD_ASSERT (s != NULL);
         hash_entry_size = elf_section_data (s)->this_hdr.sh_entsize;
         s->size = ((2 + bucketcount + dynsymcount) * hash_entry_size);
         s->contents = bfd_zalloc (output_bfd, s->size);
         if (s->contents == NULL)
           return FALSE;

         bfd_put (8 * hash_entry_size, output_bfd, bucketcount, s->contents);
         bfd_put (8 * hash_entry_size, output_bfd, dynsymcount,
                 s->contents + hash_entry_size);
       }

      if (info->emit_gnu_hash)
       {
         size_t i, cnt;
         unsigned char *contents;
         struct collect_gnu_hash_codes cinfo;
         bfd_size_type amt;
         size_t bucketcount;

         memset (&cinfo, 0, sizeof (cinfo));

         /* Compute the hash values for all exported symbols.  At the same
            time store the values in an array so that we could use them for
            optimizations.  */
         amt = dynsymcount * 2 * sizeof (unsigned long int);
         cinfo.hashcodes = bfd_malloc (amt);
         if (cinfo.hashcodes == NULL)
           return FALSE;

         cinfo.hashval = cinfo.hashcodes + dynsymcount;
         cinfo.min_dynindx = -1;
         cinfo.output_bfd = output_bfd;
         cinfo.bed = bed;

         /* Put all hash values in HASHCODES.  */
         elf_link_hash_traverse (elf_hash_table (info),
                              elf_collect_gnu_hash_codes, &cinfo);

         bucketcount
           = compute_bucket_count (info, cinfo.hashcodes, cinfo.nsyms, 1);

         if (bucketcount == 0)
           {
             free (cinfo.hashcodes);
             return FALSE;
           }

         s = bfd_get_section_by_name (dynobj, ".gnu.hash");
         BFD_ASSERT (s != NULL);

         if (cinfo.nsyms == 0)
           {
             /* Empty .gnu.hash section is special.  */
             BFD_ASSERT (cinfo.min_dynindx == -1);
             free (cinfo.hashcodes);
             s->size = 5 * 4 + bed->s->arch_size / 8;
             contents = bfd_zalloc (output_bfd, s->size);
             if (contents == NULL)
              return FALSE;
             s->contents = contents;
             /* 1 empty bucket.  */
             bfd_put_32 (output_bfd, 1, contents);
             /* SYMIDX above the special symbol 0.  */
             bfd_put_32 (output_bfd, 1, contents + 4);
             /* Just one word for bitmask.  */
             bfd_put_32 (output_bfd, 1, contents + 8);
             /* Only hash fn bloom filter.  */
             bfd_put_32 (output_bfd, 0, contents + 12);
             /* No hashes are valid - empty bitmask.  */
             bfd_put (bed->s->arch_size, output_bfd, 0, contents + 16);
             /* No hashes in the only bucket.  */
             bfd_put_32 (output_bfd, 0,
                       contents + 16 + bed->s->arch_size / 8);
           }
         else
           {
             unsigned long int maskwords, maskbitslog2;
             BFD_ASSERT (cinfo.min_dynindx != -1);

             maskbitslog2 = bfd_log2 (cinfo.nsyms) + 1;
             if (maskbitslog2 < 3)
              maskbitslog2 = 5;
             else if ((1 << (maskbitslog2 - 2)) & cinfo.nsyms)
              maskbitslog2 = maskbitslog2 + 3;
             else
              maskbitslog2 = maskbitslog2 + 2;
             if (bed->s->arch_size == 64)
              {
                if (maskbitslog2 == 5)
                  maskbitslog2 = 6;
                cinfo.shift1 = 6;
              }
             else
              cinfo.shift1 = 5;
             cinfo.mask = (1 << cinfo.shift1) - 1;
             cinfo.shift2 = maskbitslog2;
             cinfo.maskbits = 1 << maskbitslog2;
             maskwords = 1 << (maskbitslog2 - cinfo.shift1);
             amt = bucketcount * sizeof (unsigned long int) * 2;
             amt += maskwords * sizeof (bfd_vma);
             cinfo.bitmask = bfd_malloc (amt);
             if (cinfo.bitmask == NULL)
              {
                free (cinfo.hashcodes);
                return FALSE;
              }

             cinfo.counts = (void *) (cinfo.bitmask + maskwords);
             cinfo.indx = cinfo.counts + bucketcount;
             cinfo.symindx = dynsymcount - cinfo.nsyms;
             memset (cinfo.bitmask, 0, maskwords * sizeof (bfd_vma));

             /* Determine how often each hash bucket is used.  */
             memset (cinfo.counts, 0, bucketcount * sizeof (cinfo.counts[0]));
             for (i = 0; i < cinfo.nsyms; ++i)
              ++cinfo.counts[cinfo.hashcodes[i] % bucketcount];

             for (i = 0, cnt = cinfo.symindx; i < bucketcount; ++i)
              if (cinfo.counts[i] != 0)
                {
                  cinfo.indx[i] = cnt;
                  cnt += cinfo.counts[i];
                }
             BFD_ASSERT (cnt == dynsymcount);
             cinfo.bucketcount = bucketcount;
             cinfo.local_indx = cinfo.min_dynindx;

             s->size = (4 + bucketcount + cinfo.nsyms) * 4;
             s->size += cinfo.maskbits / 8;
             contents = bfd_zalloc (output_bfd, s->size);
             if (contents == NULL)
              {
                free (cinfo.bitmask);
                free (cinfo.hashcodes);
                return FALSE;
              }

             s->contents = contents;
             bfd_put_32 (output_bfd, bucketcount, contents);
             bfd_put_32 (output_bfd, cinfo.symindx, contents + 4);
             bfd_put_32 (output_bfd, maskwords, contents + 8);
             bfd_put_32 (output_bfd, cinfo.shift2, contents + 12);
             contents += 16 + cinfo.maskbits / 8;

             for (i = 0; i < bucketcount; ++i)
              {
                if (cinfo.counts[i] == 0)
                  bfd_put_32 (output_bfd, 0, contents);
                else
                  bfd_put_32 (output_bfd, cinfo.indx[i], contents);
                contents += 4;
              }

             cinfo.contents = contents;

             /* Renumber dynamic symbols, populate .gnu.hash section.  */
             elf_link_hash_traverse (elf_hash_table (info),
                                  elf_renumber_gnu_hash_syms, &cinfo);

             contents = s->contents + 16;
             for (i = 0; i < maskwords; ++i)
              {
                bfd_put (bed->s->arch_size, output_bfd, cinfo.bitmask[i],
                        contents);
                contents += bed->s->arch_size / 8;
              }

             free (cinfo.bitmask);
             free (cinfo.hashcodes);
           }
       }

      s = bfd_get_section_by_name (dynobj, ".dynstr");
      BFD_ASSERT (s != NULL);

      elf_finalize_dynstr (output_bfd, info);

      s->size = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);

      for (dtagcount = 0; dtagcount <= info->spare_dynamic_tags; ++dtagcount)
       if (!_bfd_elf_add_dynamic_entry (info, DT_NULL, 0))
         return FALSE;
    }

  return TRUE;
}

Here is the call graph for this function:

static bfd_boolean check_dynsym ( bfd abfd,
Elf_Internal_Sym *  sym 
) [static]

Definition at line 7421 of file elflink.c.

{
  if (sym->st_shndx > SHN_HIRESERVE)
    {
      /* The gABI doesn't support dynamic symbols in output sections
         beyond 64k.  */
      (*_bfd_error_handler)
       (_("%B: Too many sections: %d (>= %d)"),
        abfd, bfd_count_sections (abfd), SHN_LORESERVE);
      bfd_set_error (bfd_error_nonrepresentable_section);
      return FALSE;
    }
  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int compare_link_order ( const void *  a,
const void *  b 
) [static]

Definition at line 8927 of file elflink.c.

{
  bfd_vma apos;
  bfd_vma bpos;

  apos = elf_get_linked_section_vma (*(struct bfd_link_order **)a);
  bpos = elf_get_linked_section_vma (*(struct bfd_link_order **)b);
  if (apos < bpos)
    return -1;
  return apos > bpos;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static size_t compute_bucket_count ( struct bfd_link_info info,
unsigned long int hashcodes,
unsigned long int  nsyms,
int  gnu_hash 
) [static]

Definition at line 5085 of file elflink.c.

{
  size_t dynsymcount = elf_hash_table (info)->dynsymcount;
  size_t best_size = 0;
  unsigned long int i;
  bfd_size_type amt;

  /* We have a problem here.  The following code to optimize the table
     size requires an integer type with more the 32 bits.  If
     BFD_HOST_U_64_BIT is set we know about such a type.  */
#ifdef BFD_HOST_U_64_BIT
  if (info->optimize)
    {
      size_t minsize;
      size_t maxsize;
      BFD_HOST_U_64_BIT best_chlen = ~((BFD_HOST_U_64_BIT) 0);
      bfd *dynobj = elf_hash_table (info)->dynobj;
      const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
      unsigned long int *counts;

      /* Possible optimization parameters: if we have NSYMS symbols we say
        that the hashing table must at least have NSYMS/4 and at most
        2*NSYMS buckets.  */
      minsize = nsyms / 4;
      if (minsize == 0)
       minsize = 1;
      best_size = maxsize = nsyms * 2;
      if (gnu_hash)
       {
         if (minsize < 2)
           minsize = 2;
         if ((best_size & 31) == 0)
           ++best_size;
       }

      /* Create array where we count the collisions in.  We must use bfd_malloc
        since the size could be large.  */
      amt = maxsize;
      amt *= sizeof (unsigned long int);
      counts = bfd_malloc (amt);
      if (counts == NULL)
       return 0;

      /* Compute the "optimal" size for the hash table.  The criteria is a
        minimal chain length.  The minor criteria is (of course) the size
        of the table.  */
      for (i = minsize; i < maxsize; ++i)
       {
         /* Walk through the array of hashcodes and count the collisions.  */
         BFD_HOST_U_64_BIT max;
         unsigned long int j;
         unsigned long int fact;

         if (gnu_hash && (i & 31) == 0)
           continue;

         memset (counts, '\0', i * sizeof (unsigned long int));

         /* Determine how often each hash bucket is used.  */
         for (j = 0; j < nsyms; ++j)
           ++counts[hashcodes[j] % i];

         /* For the weight function we need some information about the
            pagesize on the target.  This is information need not be 100%
            accurate.  Since this information is not available (so far) we
            define it here to a reasonable default value.  If it is crucial
            to have a better value some day simply define this value.  */
# ifndef BFD_TARGET_PAGESIZE
#  define BFD_TARGET_PAGESIZE      (4096)
# endif

         /* We in any case need 2 + DYNSYMCOUNT entries for the size values
            and the chains.  */
         max = (2 + dynsymcount) * bed->s->sizeof_hash_entry;

# if 1
         /* Variant 1: optimize for short chains.  We add the squares
            of all the chain lengths (which favors many small chain
            over a few long chains).  */
         for (j = 0; j < i; ++j)
           max += counts[j] * counts[j];

         /* This adds penalties for the overall size of the table.  */
         fact = i / (BFD_TARGET_PAGESIZE / bed->s->sizeof_hash_entry) + 1;
         max *= fact * fact;
# else
         /* Variant 2: Optimize a lot more for small table.  Here we
            also add squares of the size but we also add penalties for
            empty slots (the +1 term).  */
         for (j = 0; j < i; ++j)
           max += (1 + counts[j]) * (1 + counts[j]);

         /* The overall size of the table is considered, but not as
            strong as in variant 1, where it is squared.  */
         fact = i / (BFD_TARGET_PAGESIZE / bed->s->sizeof_hash_entry) + 1;
         max *= fact;
# endif

         /* Compare with current best results.  */
         if (max < best_chlen)
           {
             best_chlen = max;
             best_size = i;
           }
       }

      free (counts);
    }
  else
#endif /* defined (BFD_HOST_U_64_BIT) */
    {
      /* This is the fallback solution if no 64bit type is available or if we
        are not supposed to spend much time on optimizations.  We select the
        bucket count using a fixed set of numbers.  */
      for (i = 0; elf_buckets[i] != 0; i++)
       {
         best_size = elf_buckets[i];
         if (nsyms < elf_buckets[i + 1])
           break;
       }
      if (gnu_hash && best_size < 2)
       best_size = 2;
    }

  return best_size;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void decode_complex_addend ( unsigned long start,
unsigned long oplen,
unsigned long len,
unsigned long wordsz,
unsigned long chunksz,
unsigned long lsb0_p,
unsigned long signed_p,
unsigned long trunc_p,
unsigned long  encoded 
) [static]

Definition at line 6917 of file elflink.c.

{
  * start     =  encoded        & 0x3F;
  * len       = (encoded >>  6) & 0x3F;
  * oplen     = (encoded >> 12) & 0x3F;
  * wordsz    = (encoded >> 18) & 0xF;
  * chunksz   = (encoded >> 22) & 0xF;
  * lsb0_p    = (encoded >> 27) & 1;
  * signed_p  = (encoded >> 28) & 1;
  * trunc_p   = (encoded >> 29) & 1;
}

Here is the caller graph for this function:

static int elf_add_dt_needed_tag ( bfd abfd,
struct bfd_link_info info,
const char *  soname,
bfd_boolean  do_it 
) [static]

Definition at line 2937 of file elflink.c.

{
  struct elf_link_hash_table *hash_table;
  bfd_size_type oldsize;
  bfd_size_type strindex;

  if (!_bfd_elf_link_create_dynstrtab (abfd, info))
    return -1;

  hash_table = elf_hash_table (info);
  oldsize = _bfd_elf_strtab_size (hash_table->dynstr);
  strindex = _bfd_elf_strtab_add (hash_table->dynstr, soname, FALSE);
  if (strindex == (bfd_size_type) -1)
    return -1;

  if (oldsize == _bfd_elf_strtab_size (hash_table->dynstr))
    {
      asection *sdyn;
      const struct elf_backend_data *bed;
      bfd_byte *extdyn;

      bed = get_elf_backend_data (hash_table->dynobj);
      sdyn = bfd_get_section_by_name (hash_table->dynobj, ".dynamic");
      if (sdyn != NULL)
       for (extdyn = sdyn->contents;
            extdyn < sdyn->contents + sdyn->size;
            extdyn += bed->s->sizeof_dyn)
         {
           Elf_Internal_Dyn dyn;

           bed->s->swap_dyn_in (hash_table->dynobj, extdyn, &dyn);
           if (dyn.d_tag == DT_NEEDED
              && dyn.d_un.d_val == strindex)
             {
              _bfd_elf_strtab_delref (hash_table->dynstr, strindex);
              return 1;
             }
         }
    }

  if (do_it)
    {
      if (!_bfd_elf_link_create_dynamic_sections (hash_table->dynobj, info))
       return -1;

      if (!_bfd_elf_add_dynamic_entry (info, DT_NEEDED, strindex))
       return -1;
    }
  else
    /* We were just checking for existence of the tag.  */
    _bfd_elf_strtab_delref (hash_table->dynstr, strindex);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean elf_adjust_dynstr_offsets ( struct elf_link_hash_entry h,
void *  data 
) [static]

Definition at line 3021 of file elflink.c.

{
  struct elf_strtab_hash *dynstr = data;

  if (h->root.type == bfd_link_hash_warning)
    h = (struct elf_link_hash_entry *) h->root.u.i.link;

  if (h->dynindx != -1)
    h->dynstr_index = _bfd_elf_strtab_offset (dynstr, h->dynstr_index);
  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean elf_collect_gnu_hash_codes ( struct elf_link_hash_entry h,
void *  data 
) [static]

Definition at line 4963 of file elflink.c.

{
  struct collect_gnu_hash_codes *s = data;
  const char *name;
  char *p;
  unsigned long ha;
  char *alc = NULL;

  if (h->root.type == bfd_link_hash_warning)
    h = (struct elf_link_hash_entry *) h->root.u.i.link;

  /* Ignore indirect symbols.  These are added by the versioning code.  */
  if (h->dynindx == -1)
    return TRUE;

  /* Ignore also local symbols and undefined symbols.  */
  if (! (*s->bed->elf_hash_symbol) (h))
    return TRUE;

  name = h->root.root.string;
  p = strchr (name, ELF_VER_CHR);
  if (p != NULL)
    {
      alc = bfd_malloc (p - name + 1);
      memcpy (alc, name, p - name);
      alc[p - name] = '\0';
      name = alc;
    }

  /* Compute the hash value.  */
  ha = bfd_elf_gnu_hash (name);

  /* Store the found hash value in the array for compute_bucket_count,
     and also for .dynsym reordering purposes.  */
  s->hashcodes[s->nsyms] = ha;
  s->hashval[h->dynindx] = ha;
  ++s->nsyms;
  if (s->min_dynindx < 0 || s->min_dynindx > h->dynindx)
    s->min_dynindx = h->dynindx;

  if (alc != NULL)
    free (alc);

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean elf_collect_hash_codes ( struct elf_link_hash_entry h,
void *  data 
) [static]

Definition at line 4898 of file elflink.c.

{
  unsigned long **valuep = data;
  const char *name;
  char *p;
  unsigned long ha;
  char *alc = NULL;

  if (h->root.type == bfd_link_hash_warning)
    h = (struct elf_link_hash_entry *) h->root.u.i.link;

  /* Ignore indirect symbols.  These are added by the versioning code.  */
  if (h->dynindx == -1)
    return TRUE;

  name = h->root.root.string;
  p = strchr (name, ELF_VER_CHR);
  if (p != NULL)
    {
      alc = bfd_malloc (p - name + 1);
      memcpy (alc, name, p - name);
      alc[p - name] = '\0';
      name = alc;
    }

  /* Compute the hash value.  */
  ha = bfd_elf_hash (name);

  /* Store the found hash value in the array given as the argument.  */
  *(*valuep)++ = ha;

  /* And store it in the struct so that we can put it in the hash table
     later.  */
  h->u.elf_hash_value = ha;

  if (alc != NULL)
    free (alc);

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean elf_finalize_dynstr ( bfd output_bfd,
struct bfd_link_info info 
) [static]

Definition at line 3037 of file elflink.c.

{
  struct elf_link_hash_table *hash_table = elf_hash_table (info);
  struct elf_link_local_dynamic_entry *entry;
  struct elf_strtab_hash *dynstr = hash_table->dynstr;
  bfd *dynobj = hash_table->dynobj;
  asection *sdyn;
  bfd_size_type size;
  const struct elf_backend_data *bed;
  bfd_byte *extdyn;

  _bfd_elf_strtab_finalize (dynstr);
  size = _bfd_elf_strtab_size (dynstr);

  bed = get_elf_backend_data (dynobj);
  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
  BFD_ASSERT (sdyn != NULL);

  /* Update all .dynamic entries referencing .dynstr strings.  */
  for (extdyn = sdyn->contents;
       extdyn < sdyn->contents + sdyn->size;
       extdyn += bed->s->sizeof_dyn)
    {
      Elf_Internal_Dyn dyn;

      bed->s->swap_dyn_in (dynobj, extdyn, &dyn);
      switch (dyn.d_tag)
       {
       case DT_STRSZ:
         dyn.d_un.d_val = size;
         break;
       case DT_NEEDED:
       case DT_SONAME:
       case DT_RPATH:
       case DT_RUNPATH:
       case DT_FILTER:
       case DT_AUXILIARY:
         dyn.d_un.d_val = _bfd_elf_strtab_offset (dynstr, dyn.d_un.d_val);
         break;
       default:
         continue;
       }
      bed->s->swap_dyn_out (dynobj, &dyn, extdyn);
    }

  /* Now update local dynamic symbols.  */
  for (entry = hash_table->dynlocal; entry ; entry = entry->next)
    entry->isym.st_name = _bfd_elf_strtab_offset (dynstr,
                                            entry->isym.st_name);

  /* And the rest of dynamic symbols.  */
  elf_link_hash_traverse (hash_table, elf_adjust_dynstr_offsets, dynstr);

  /* Adjust version definitions.  */
  if (elf_tdata (output_bfd)->cverdefs)
    {
      asection *s;
      bfd_byte *p;
      bfd_size_type i;
      Elf_Internal_Verdef def;
      Elf_Internal_Verdaux defaux;

      s = bfd_get_section_by_name (dynobj, ".gnu.version_d");
      p = s->contents;
      do
       {
         _bfd_elf_swap_verdef_in (output_bfd, (Elf_External_Verdef *) p,
                               &def);
         p += sizeof (Elf_External_Verdef);
         if (def.vd_aux != sizeof (Elf_External_Verdef))
           continue;
         for (i = 0; i < def.vd_cnt; ++i)
           {
             _bfd_elf_swap_verdaux_in (output_bfd,
                                   (Elf_External_Verdaux *) p, &defaux);
             defaux.vda_name = _bfd_elf_strtab_offset (dynstr,
                                                 defaux.vda_name);
             _bfd_elf_swap_verdaux_out (output_bfd,
                                    &defaux, (Elf_External_Verdaux *) p);
             p += sizeof (Elf_External_Verdaux);
           }
       }
      while (def.vd_next);
    }

  /* Adjust version references.  */
  if (elf_tdata (output_bfd)->verref)
    {
      asection *s;
      bfd_byte *p;
      bfd_size_type i;
      Elf_Internal_Verneed need;
      Elf_Internal_Vernaux needaux;

      s = bfd_get_section_by_name (dynobj, ".gnu.version_r");
      p = s->contents;
      do
       {
         _bfd_elf_swap_verneed_in (output_bfd, (Elf_External_Verneed *) p,
                                &need);
         need.vn_file = _bfd_elf_strtab_offset (dynstr, need.vn_file);
         _bfd_elf_swap_verneed_out (output_bfd, &need,
                                 (Elf_External_Verneed *) p);
         p += sizeof (Elf_External_Verneed);
         for (i = 0; i < need.vn_cnt; ++i)
           {
             _bfd_elf_swap_vernaux_in (output_bfd,
                                   (Elf_External_Vernaux *) p, &needaux);
             needaux.vna_name = _bfd_elf_strtab_offset (dynstr,
                                                  needaux.vna_name);
             _bfd_elf_swap_vernaux_out (output_bfd,
                                    &needaux,
                                    (Elf_External_Vernaux *) p);
             p += sizeof (Elf_External_Vernaux);
           }
       }
      while (need.vn_next);
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean elf_fixup_link_order ( bfd abfd,
asection o 
) [static]

Definition at line 8946 of file elflink.c.

{
  int seen_linkorder;
  int seen_other;
  int n;
  struct bfd_link_order *p;
  bfd *sub;
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  unsigned elfsec;
  struct bfd_link_order **sections;
  asection *s, *other_sec, *linkorder_sec;
  bfd_vma offset;

  other_sec = NULL;
  linkorder_sec = NULL;
  seen_other = 0;
  seen_linkorder = 0;
  for (p = o->map_head.link_order; p != NULL; p = p->next)
    {
      if (p->type == bfd_indirect_link_order)
       {
         s = p->u.indirect.section;
         sub = s->owner;
         if (bfd_get_flavour (sub) == bfd_target_elf_flavour
             && elf_elfheader (sub)->e_ident[EI_CLASS] == bed->s->elfclass
             && (elfsec = _bfd_elf_section_from_bfd_section (sub, s))
             && elfsec < elf_numsections (sub)
             && elf_elfsections (sub)[elfsec]->sh_flags & SHF_LINK_ORDER)
           {
             seen_linkorder++;
             linkorder_sec = s;
           }
         else
           {
             seen_other++;
             other_sec = s;
           }
       }
      else
       seen_other++;

      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);
         else
           (*_bfd_error_handler) (_("%A has both ordered and unordered sections"),
                               o);
         bfd_set_error (bfd_error_bad_value);
         return FALSE;
       }
    }

  if (!seen_linkorder)
    return TRUE;

  sections = (struct bfd_link_order **)
    xmalloc (seen_linkorder * sizeof (struct bfd_link_order *));
  seen_linkorder = 0;

  for (p = o->map_head.link_order; p != NULL; p = p->next)
    {
      sections[seen_linkorder++] = p;
    }
  /* Sort the input sections in the order of their linked section.  */
  qsort (sections, seen_linkorder, sizeof (struct bfd_link_order *),
        compare_link_order);

  /* Change the offsets of the sections.  */
  offset = 0;
  for (n = 0; n < seen_linkorder; n++)
    {
      s = sections[n]->u.indirect.section;
      offset &= ~(bfd_vma)((1 << s->alignment_power) - 1);
      s->output_offset = offset;
      sections[n]->offset = offset;
      offset += sections[n]->size;
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean elf_gc_allocate_got_offsets ( struct elf_link_hash_entry h,
void *  arg 
) [static]

Definition at line 10750 of file elflink.c.

{
  struct alloc_got_off_arg *gofarg = arg;

  if (h->root.type == bfd_link_hash_warning)
    h = (struct elf_link_hash_entry *) h->root.u.i.link;

  if (h->got.refcount > 0)
    {
      h->got.offset = gofarg->gotoff;
      gofarg->gotoff += gofarg->got_elt_size;
    }
  else
    h->got.offset = (bfd_vma) -1;

  return TRUE;
}

Here is the caller graph for this function:

Definition at line 10351 of file elflink.c.

{
  if (h->root.type == bfd_link_hash_warning)
    h = (struct elf_link_hash_entry *) h->root.u.i.link;

  /* Those that are not vtables.  */
  if (h->vtable == NULL || h->vtable->parent == NULL)
    return TRUE;

  /* Those vtables that do not have parents, we cannot merge.  */
  if (h->vtable->parent == (struct elf_link_hash_entry *) -1)
    return TRUE;

  /* If we've already been done, exit.  */
  if (h->vtable->used && h->vtable->used[-1])
    return TRUE;

  /* Make sure the parent's table is up to date.  */
  elf_gc_propagate_vtable_entries_used (h->vtable->parent, okp);

  if (h->vtable->used == NULL)
    {
      /* None of this table's entries were referenced.  Re-use the
        parent's table.  */
      h->vtable->used = h->vtable->parent->vtable->used;
      h->vtable->size = h->vtable->parent->vtable->size;
    }
  else
    {
      size_t n;
      bfd_boolean *cu, *pu;

      /* Or the parent's entries into ours.  */
      cu = h->vtable->used;
      cu[-1] = TRUE;
      pu = h->vtable->parent->vtable->used;
      if (pu != NULL)
       {
         const struct elf_backend_data *bed;
         unsigned int log_file_align;

         bed = get_elf_backend_data (h->root.u.def.section->owner);
         log_file_align = bed->s->log_file_align;
         n = h->vtable->parent->vtable->size >> log_file_align;
         while (n--)
           {
             if (*pu)
              *cu = TRUE;
             pu++;
             cu++;
           }
       }
    }

  return TRUE;
}

Here is the caller graph for this function:

static bfd_boolean elf_gc_smash_unused_vtentry_relocs ( struct elf_link_hash_entry h,
void *  okp 
) [static]

Definition at line 10409 of file elflink.c.

{
  asection *sec;
  bfd_vma hstart, hend;
  Elf_Internal_Rela *relstart, *relend, *rel;
  const struct elf_backend_data *bed;
  unsigned int log_file_align;

  if (h->root.type == bfd_link_hash_warning)
    h = (struct elf_link_hash_entry *) h->root.u.i.link;

  /* Take care of both those symbols that do not describe vtables as
     well as those that are not loaded.  */
  if (h->vtable == NULL || h->vtable->parent == NULL)
    return TRUE;

  BFD_ASSERT (h->root.type == bfd_link_hash_defined
             || h->root.type == bfd_link_hash_defweak);

  sec = h->root.u.def.section;
  hstart = h->root.u.def.value;
  hend = hstart + h->size;

  relstart = _bfd_elf_link_read_relocs (sec->owner, sec, NULL, NULL, TRUE);
  if (!relstart)
    return *(bfd_boolean *) okp = FALSE;
  bed = get_elf_backend_data (sec->owner);
  log_file_align = bed->s->log_file_align;

  relend = relstart + sec->reloc_count * bed->s->int_rels_per_ext_rel;

  for (rel = relstart; rel < relend; ++rel)
    if (rel->r_offset >= hstart && rel->r_offset < hend)
      {
       /* If the entry is in use, do nothing.  */
       if (h->vtable->used
           && (rel->r_offset - hstart) < h->vtable->size)
         {
           bfd_vma entry = (rel->r_offset - hstart) >> log_file_align;
           if (h->vtable->used[entry])
             continue;
         }
       /* Otherwise, kill it.  */
       rel->r_offset = rel->r_info = rel->r_addend = 0;
      }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean elf_gc_sweep ( bfd abfd,
struct bfd_link_info info 
) [static]

Definition at line 10272 of file elflink.c.

{
  bfd *sub;
  const struct elf_backend_data *bed =