~ubuntu-branches/debian/jessie/gdb/jessie

« back to all changes in this revision

Viewing changes to bfd/elflink.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2010-03-20 01:21:29 UTC
  • mfrom: (1.3.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320012129-t7h25y8zgr8c2369
Tags: 7.1-1
* New upstream release, including:
  - PIE support (Closes: #346409).
  - C++ improvements, including static_cast<> et al, namespace imports,
    and bug fixes in printing virtual base classes.
  - Multi-program debugging.  One GDB can now debug multiple programs
    at the same time.
  - Python scripting improvements, including gdb.parse_and_eval.
  - Updated MIPS Linux signal frame layout (Closes: #570875).
  - No internal error stepping over _dl_debug_state (Closes: #569551).
* Update to Standards-Version: 3.8.4 (no changes required).
* Include more relevant (and smaller) docs in the gdbserver package
  (Closes: #571132).
* Do not duplicate documentation in gdb64, gdb-source, and libgdb-dev.
* Fix crash when switching into TUI mode (Closes: #568489).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* ELF linking support for BFD.
2
2
   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3
 
   2005, 2006, 2007, 2008, 2009
 
3
   2005, 2006, 2007, 2008, 2009, 2010
4
4
   Free Software Foundation, Inc.
5
5
 
6
6
   This file is part of BFD, the Binary File Descriptor library.
185
185
_bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
186
186
{
187
187
  flagword flags;
188
 
  register asection *s;
 
188
  asection *s;
189
189
  const struct elf_backend_data *bed;
190
190
 
191
191
  if (! is_elf_hash_table (info->hash))
570
570
 
571
571
  if (provide && hidden)
572
572
    {
573
 
      const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
574
 
 
 
573
      bed = get_elf_backend_data (output_bfd);
575
574
      h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
576
575
      (*bed->elf_backend_hide_symbol) (info, h, TRUE);
577
576
    }
1184
1183
             was referenced before.  */
1185
1184
          if (h->ref_regular)
1186
1185
            {
1187
 
              const struct elf_backend_data *bed
1188
 
                = get_elf_backend_data (abfd);
1189
1186
              struct elf_link_hash_entry *vh = *sym_hash;
 
1187
 
1190
1188
              vh->root.type = h->root.type;
1191
1189
              h->root.type = bfd_link_hash_indirect;
1192
1190
              (*bed->elf_backend_copy_indirect_symbol) (info, vh, h);
1548
1546
      /* Handle the case where we had a versioned symbol in a dynamic
1549
1547
         library and now find a definition in a normal object.  In this
1550
1548
         case, we make the versioned symbol point to the normal one.  */
1551
 
      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1552
1549
      flip->root.type = h->root.type;
1553
1550
      flip->root.u.undef.abfd = h->root.u.undef.abfd;
1554
1551
      h->root.type = bfd_link_hash_indirect;
3234
3231
        case DT_RUNPATH:
3235
3232
        case DT_FILTER:
3236
3233
        case DT_AUXILIARY:
 
3234
        case DT_AUDIT:
 
3235
        case DT_DEPAUDIT:
3237
3236
          dyn.d_un.d_val = _bfd_elf_strtab_offset (dynstr, dyn.d_un.d_val);
3238
3237
          break;
3239
3238
        default:
3525
3524
    {
3526
3525
      asection *s;
3527
3526
      const char *soname = NULL;
 
3527
      char *audit = NULL;
3528
3528
      struct bfd_link_needed_list *rpath = NULL, *runpath = NULL;
3529
3529
      int ret;
3530
3530
 
3653
3653
                    ;
3654
3654
                  *pn = n;
3655
3655
                }
 
3656
              if (dyn.d_tag == DT_AUDIT)
 
3657
                {
 
3658
                  unsigned int tagv = dyn.d_un.d_val;
 
3659
                  audit = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
 
3660
                }
3656
3661
            }
3657
3662
 
3658
3663
          free (dynbuf);
3705
3710
         particular dynamic object more than once.  */
3706
3711
      if (ret > 0)
3707
3712
        return TRUE;
 
3713
 
 
3714
      /* Save the DT_AUDIT entry for the linker emulation code. */
 
3715
      elf_dt_audit (abfd) = audit; 
3708
3716
    }
3709
3717
 
3710
3718
  /* If this is a dynamic object, we always link against the .dynsym
3866
3874
      bfd_boolean common;
3867
3875
      unsigned int old_alignment;
3868
3876
      bfd *old_bfd;
 
3877
      bfd * undef_bfd = NULL;
3869
3878
 
3870
3879
      override = FALSE;
3871
3880
 
3990
3999
          unsigned int vernum = 0;
3991
4000
          bfd_boolean skip;
3992
4001
 
 
4002
          /* If this is a definition of a symbol which was previously
 
4003
             referenced in a non-weak manner then make a note of the bfd
 
4004
             that contained the reference.  This is used if we need to
 
4005
             refer to the source of the reference later on.  */
 
4006
          if (! bfd_is_und_section (sec))
 
4007
            {
 
4008
              h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE);
 
4009
 
 
4010
              if (h != NULL
 
4011
                  && h->root.type == bfd_link_hash_undefined
 
4012
                  && h->root.u.undef.abfd)
 
4013
                undef_bfd = h->root.u.undef.abfd;
 
4014
            }
 
4015
          
3993
4016
          if (ever == NULL)
3994
4017
            {
3995
4018
              if (info->default_imported_symver)
4097
4120
              name = newname;
4098
4121
            }
4099
4122
 
 
4123
          /* If necessary, make a second attempt to locate the bfd
 
4124
             containing an unresolved, non-weak reference to the
 
4125
             current symbol.  */
 
4126
          if (! bfd_is_und_section (sec) && undef_bfd == NULL)
 
4127
            {
 
4128
              h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE);
 
4129
 
 
4130
              if (h != NULL
 
4131
                  && h->root.type == bfd_link_hash_undefined
 
4132
                  && h->root.u.undef.abfd)
 
4133
                undef_bfd = h->root.u.undef.abfd;
 
4134
            }
 
4135
 
4100
4136
          if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec,
4101
4137
                                      &value, &old_alignment,
4102
4138
                                      sym_hash, &skip, &override,
4362
4398
          if (definition && (sec->flags & SEC_DEBUGGING) && !info->relocatable)
4363
4399
            {
4364
4400
              /* We don't want to make debug symbol dynamic.  */
4365
 
              (*bed->elf_backend_hide_symbol) (info, h, TRUE);
4366
4401
              dynsym = FALSE;
4367
4402
            }
4368
4403
 
4433
4468
              /* A symbol from a library loaded via DT_NEEDED of some
4434
4469
                 other library is referenced by a regular object.
4435
4470
                 Add a DT_NEEDED entry for it.  Issue an error if
4436
 
                 --no-add-needed is used.  */
4437
 
              if ((elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0)
 
4471
                 --no-add-needed is used and the reference was not
 
4472
                 a weak one.  */
 
4473
              if (undef_bfd != NULL
 
4474
                  && (elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0)
4438
4475
                {
4439
4476
                  (*_bfd_error_handler)
4440
 
                    (_("%s: invalid DSO for symbol `%s' definition"),
 
4477
                    (_("%B: undefined reference to symbol '%s'"),
 
4478
                     undef_bfd, name);
 
4479
                  (*_bfd_error_handler)
 
4480
                    (_("note: '%s' is defined in DSO %B so try adding it to the linker command line"),
4441
4481
                     abfd, name);
4442
 
                  bfd_set_error (bfd_error_bad_value);
 
4482
                  bfd_set_error (bfd_error_invalid_operation);
4443
4483
                  goto error_free_vers;
4444
4484
                }
4445
4485
 
5451
5491
                               const char *soname,
5452
5492
                               const char *rpath,
5453
5493
                               const char *filter_shlib,
 
5494
                               const char *audit,
 
5495
                               const char *depaudit,
5454
5496
                               const char * const *auxiliary_filters,
5455
5497
                               struct bfd_link_info *info,
5456
5498
                               asection **sinterpptr,
5603
5645
            }
5604
5646
        }
5605
5647
 
 
5648
      if (audit != NULL)
 
5649
        {
 
5650
          bfd_size_type indx;
 
5651
 
 
5652
          indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, audit,
 
5653
                                      TRUE);
 
5654
          if (indx == (bfd_size_type) -1
 
5655
              || !_bfd_elf_add_dynamic_entry (info, DT_AUDIT, indx))
 
5656
            return FALSE;
 
5657
        }
 
5658
 
 
5659
      if (depaudit != NULL)
 
5660
        {
 
5661
          bfd_size_type indx;
 
5662
 
 
5663
          indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, depaudit,
 
5664
                                      TRUE);
 
5665
          if (indx == (bfd_size_type) -1
 
5666
              || !_bfd_elf_add_dynamic_entry (info, DT_DEPAUDIT, indx))
 
5667
            return FALSE;
 
5668
        }
 
5669
 
5606
5670
      eif.info = info;
5607
5671
      eif.verdefs = verdefs;
5608
5672
      eif.failed = FALSE;
6718
6782
   struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *,
6719
6783
                                      struct bfd_hash_table *,
6720
6784
                                      const char *),
6721
 
   unsigned int entsize)
 
6785
   unsigned int entsize,
 
6786
   enum elf_target_id target_id)
6722
6787
{
6723
6788
  bfd_boolean ret;
6724
6789
  int can_refcount = get_elf_backend_data (abfd)->can_refcount;
6732
6797
  table->dynsymcount = 1;
6733
6798
 
6734
6799
  ret = _bfd_link_hash_table_init (&table->root, abfd, newfunc, entsize);
 
6800
 
6735
6801
  table->root.type = bfd_link_elf_hash_table;
 
6802
  table->hash_table_id = target_id;
6736
6803
 
6737
6804
  return ret;
6738
6805
}
6750
6817
    return NULL;
6751
6818
 
6752
6819
  if (! _bfd_elf_link_hash_table_init (ret, abfd, _bfd_elf_link_hash_newfunc,
6753
 
                                       sizeof (struct elf_link_hash_entry)))
 
6820
                                       sizeof (struct elf_link_hash_entry),
 
6821
                                       GENERIC_ELF_DATA))
6754
6822
    {
6755
6823
      free (ret);
6756
6824
      return NULL;
8443
8511
 
8444
8512
          _bfd_elf_swap_versym_in (input, ever, &iver);
8445
8513
 
8446
 
          if ((iver.vs_vers & VERSYM_HIDDEN) == 0)
 
8514
          if ((iver.vs_vers & VERSYM_HIDDEN) == 0
 
8515
              && !(h->def_regular
 
8516
                   && h->forced_local))
8447
8517
            {
8448
8518
              /* If we have a non-hidden versioned sym, then it should
8449
 
                 have provided a definition for the undefined sym.  */
 
8519
                 have provided a definition for the undefined sym unless
 
8520
                 it is defined in a non-shared object and forced local.
 
8521
               */
8450
8522
              abort ();
8451
8523
            }
8452
8524
 
8511
8583
    {
8512
8584
      /* If we have an undefined symbol reference here then it must have
8513
8585
         come from a shared library that is being linked in.  (Undefined
8514
 
         references in regular files have already been handled).  */
 
8586
         references in regular files have already been handled unless
 
8587
         they are in unreferenced sections which are removed by garbage
 
8588
         collection).  */
8515
8589
      bfd_boolean ignore_undef = FALSE;
8516
8590
 
8517
8591
      /* Some symbols may be special in that the fact that they're
8522
8596
      /* If we are reporting errors for this situation then do so now.  */
8523
8597
      if (ignore_undef == FALSE
8524
8598
          && h->ref_dynamic
8525
 
          && ! h->ref_regular
 
8599
          && (!h->ref_regular || finfo->info->gc_sections)
8526
8600
          && ! elf_link_check_versioned_symbol (finfo->info, bed, h)
8527
8601
          && finfo->info->unresolved_syms_in_shared_libs != RM_IGNORE)
8528
8602
        {
8529
8603
          if (! (finfo->info->callbacks->undefined_symbol
8530
 
                 (finfo->info, h->root.root.string, h->root.u.undef.abfd,
 
8604
                 (finfo->info, h->root.root.string,
 
8605
                  h->ref_regular ? NULL : h->root.u.undef.abfd,
8531
8606
                  NULL, 0, finfo->info->unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)))
8532
8607
            {
8533
8608
              eoinfo->failed = TRUE;
8587
8662
    strip = FALSE;
8588
8663
 
8589
8664
  /* If we're stripping it, and it's not a dynamic symbol, there's
8590
 
     nothing else to do unless it is a forced local symbol.  */
 
8665
     nothing else to do unless it is a forced local symbol or a
 
8666
     STT_GNU_IFUNC symbol.  */
8591
8667
  if (strip
8592
8668
      && h->dynindx == -1
 
8669
      && h->type != STT_GNU_IFUNC
8593
8670
      && !h->forced_local)
8594
8671
    return TRUE;
8595
8672
 
8597
8674
  sym.st_size = h->size;
8598
8675
  sym.st_other = h->other;
8599
8676
  if (h->forced_local)
8600
 
    sym.st_info = ELF_ST_INFO (STB_LOCAL, h->type);
 
8677
    {
 
8678
      sym.st_info = ELF_ST_INFO (STB_LOCAL, h->type);
 
8679
      /* Turn off visibility on local symbol.  */
 
8680
      sym.st_other &= ~ELF_ST_VISIBILITY (-1);
 
8681
    }
8601
8682
  else if (h->unique_global)
8602
8683
    sym.st_info = ELF_ST_INFO (STB_GNU_UNIQUE, h->type);
8603
8684
  else if (h->root.type == bfd_link_hash_undefweak
10053
10134
  bfd_boolean emit_relocs;
10054
10135
  bfd *dynobj;
10055
10136
  struct elf_final_link_info finfo;
10056
 
  register asection *o;
10057
 
  register struct bfd_link_order *p;
10058
 
  register bfd *sub;
 
10137
  asection *o;
 
10138
  struct bfd_link_order *p;
 
10139
  bfd *sub;
10059
10140
  bfd_size_type max_contents_size;
10060
10141
  bfd_size_type max_external_reloc_size;
10061
10142
  bfd_size_type max_internal_reloc_count;
10504
10585
          if (size == 0
10505
10586
              && (sec->flags & SEC_HAS_CONTENTS) == 0)
10506
10587
            {
10507
 
              struct bfd_link_order *o = sec->map_tail.link_order;
10508
 
              if (o != NULL)
10509
 
                size = o->offset + o->size;
 
10588
              struct bfd_link_order *ord = sec->map_tail.link_order;
 
10589
 
 
10590
              if (ord != NULL)
 
10591
                size = ord->offset + ord->size;
10510
10592
            }
10511
10593
          end = sec->vma + size;
10512
10594
        }
10669
10751
              asection *s;
10670
10752
              bfd_byte *dest;
10671
10753
 
10672
 
              sym.st_size = e->isym.st_size;
10673
 
              sym.st_other = e->isym.st_other;
10674
 
 
10675
 
              /* Copy the internal symbol as is.
 
10754
              /* Copy the internal symbol and turn off visibility.
10676
10755
                 Note that we saved a word of storage and overwrote
10677
10756
                 the original st_name with the dynstr_index.  */
10678
10757
              sym = e->isym;
 
10758
              sym.st_other &= ~ELF_ST_VISIBILITY (-1);
10679
10759
 
10680
10760
              s = bfd_section_from_elf_index (e->input_bfd,
10681
10761
                                              e->isym.st_shndx);
11277
11357
                       struct elf_link_hash_entry *h,
11278
11358
                       Elf_Internal_Sym *sym)
11279
11359
{
 
11360
  const char *sec_name;
 
11361
 
11280
11362
  if (h != NULL)
11281
11363
    {
11282
11364
      switch (h->root.type)
11288
11370
        case bfd_link_hash_common:
11289
11371
          return h->root.u.c.p->section;
11290
11372
 
 
11373
        case bfd_link_hash_undefined:
 
11374
        case bfd_link_hash_undefweak:
 
11375
          /* To work around a glibc bug, keep all XXX input sections
 
11376
             when there is an as yet undefined reference to __start_XXX
 
11377
             or __stop_XXX symbols.  The linker will later define such
 
11378
             symbols for orphan input sections that have a name
 
11379
             representable as a C identifier.  */
 
11380
          if (strncmp (h->root.root.string, "__start_", 8) == 0)
 
11381
            sec_name = h->root.root.string + 8;
 
11382
          else if (strncmp (h->root.root.string, "__stop_", 7) == 0)
 
11383
            sec_name = h->root.root.string + 7;
 
11384
          else
 
11385
            sec_name = NULL;
 
11386
 
 
11387
          if (sec_name && *sec_name != '\0')
 
11388
            {
 
11389
              bfd *i;
 
11390
              
 
11391
              for (i = info->input_bfds; i; i = i->link_next)
 
11392
                {
 
11393
                  sec = bfd_get_section_by_name (i, sec_name);
 
11394
                  if (sec)
 
11395
                    sec->flags |= SEC_KEEP;
 
11396
                }
 
11397
            }
 
11398
          break;
 
11399
 
11291
11400
        default:
11292
11401
          break;
11293
11402
        }
11473
11582
              o->gc_mark = first->gc_mark;
11474
11583
            }
11475
11584
          else if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0
11476
 
                   || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)
 
11585
                   || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0
 
11586
                   || elf_section_data (o)->this_hdr.sh_type == SHT_NOTE)
11477
11587
            {
11478
 
              /* Keep debug and special sections.  */
 
11588
              /* Keep debug, special and SHT_NOTE sections.  */
11479
11589
              o->gc_mark = 1;
11480
11590
            }
11481
11591
 
12495
12605
   section does not exist it is created and attached to the DYNOBJ
12496
12606
   bfd and stored in the SRELOC field of SEC's elf_section_data
12497
12607
   structure.
12498
 
   
 
12608
 
12499
12609
   ALIGNMENT is the alignment for the newly created section and
12500
12610
   IS_RELA defines whether the name should be .rela.<SEC's name>
12501
12611
   or .rel.<SEC's name>.  The section name is looked up in the
12540
12650
 
12541
12651
  return reloc_sec;
12542
12652
}
 
12653
 
 
12654
/* Copy the ELF symbol type associated with a linker hash entry.  */
 
12655
void
 
12656
_bfd_elf_copy_link_hash_symbol_type (bfd *abfd ATTRIBUTE_UNUSED,
 
12657
    struct bfd_link_hash_entry * hdest,
 
12658
    struct bfd_link_hash_entry * hsrc)
 
12659
{
 
12660
  struct elf_link_hash_entry *ehdest = (struct elf_link_hash_entry *)hdest;
 
12661
  struct elf_link_hash_entry *ehsrc = (struct elf_link_hash_entry *)hsrc;
 
12662
 
 
12663
  ehdest->type = ehsrc->type;
 
12664
}