~ubuntu-branches/ubuntu/hoary/binutils/hoary

« back to all changes in this revision

Viewing changes to bfd/elf32-cris.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-03-18 13:07:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050318130752-j4i37zgqclj53b94
Tags: 2.15-5ubuntu2
debian/rules: Call pkgstriptranslations if present (the package does not
use debhelper, thus it does not happen automatically).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* CRIS-specific support for 32-bit ELF.
2
 
   Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
2
   Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3
3
   Contributed by Axis Communications AB.
4
4
   Written by Hans-Peter Nilsson, based on elf32-fr30.c
5
5
   PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
847
847
        {
848
848
          sym = local_syms + r_symndx;
849
849
          sec = local_sections [r_symndx];
850
 
          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
 
850
          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
851
851
 
852
852
          symname = (bfd_elf_string_from_elf_section
853
853
                     (input_bfd, symtab_hdr->sh_link, sym->st_name));
859
859
          bfd_boolean warned;
860
860
          bfd_boolean unresolved_reloc;
861
861
 
862
 
          RELOC_FOR_GLOBAL_SYMBOL (h, sym_hashes, r_symndx, symtab_hdr, relocation, sec, unresolved_reloc, info, warned);
 
862
          RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
 
863
                                   r_symndx, symtab_hdr, sym_hashes,
 
864
                                   h, sec, relocation,
 
865
                                   unresolved_reloc, warned);
863
866
 
864
867
          if (unresolved_reloc
865
868
              /* Perhaps we should detect the cases that
957
960
             statically linking PIC code, or when using -Bsymbolic.  Check
958
961
             that we instead have a GOT entry as done for us by
959
962
             elf_cris_adjust_dynamic_symbol, and drop through into the
960
 
             ordinary GOT cases.  */
961
 
          if (h != NULL && h->got.offset == (bfd_vma) -1)
 
963
             ordinary GOT cases.  This must not happen for the
 
964
             executable, because any reference it does to a function
 
965
             that is satisfied by a DSO must generate a PLT.  We assume
 
966
             these call-specific relocs don't address non-functions.  */
 
967
          if (h != NULL
 
968
              && (h->got.offset == (bfd_vma) -1
 
969
                  || (!info->shared
 
970
                      && !((h->elf_link_hash_flags
 
971
                            & ELF_LINK_HASH_DEF_REGULAR) != 0
 
972
                           || ((h->elf_link_hash_flags
 
973
                                & ELF_LINK_HASH_DEF_DYNAMIC) == 0
 
974
                              && h->root.type == bfd_link_hash_undefweak)))))
962
975
            {
963
976
              (*_bfd_error_handler)
964
 
                (_("%s: No PLT nor GOT for relocation %s against symbol `%s' from %s section"),
 
977
                ((h->got.offset == (bfd_vma) -1)
 
978
                 ? _("%s: No PLT nor GOT for relocation %s against\
 
979
 symbol `%s' from %s section")
 
980
                 : _("%s: No PLT for relocation %s against\
 
981
 symbol `%s' from %s section"),
965
982
                 bfd_archive_filename (input_bfd),
966
983
                 cris_elf_howto_table[r_type].name,
967
984
                 symname[0] != '\0' ? symname : _("[whose name is lost]"),
993
1010
 
994
1011
                if (!elf_hash_table (info)->dynamic_sections_created
995
1012
                    || (! info->shared
996
 
                        && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
 
1013
                        && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
 
1014
                            || h->type == STT_FUNC
 
1015
                            || (h->elf_link_hash_flags
 
1016
                                & ELF_LINK_HASH_NEEDS_PLT)))
997
1017
                    || (info->shared
998
1018
                        && (info->symbolic || h->dynindx == -1)
999
1019
                        && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1000
1020
                  {
1001
1021
                    /* This wasn't checked above for ! info->shared, but
1002
 
                       must hold there if we get here; the symbol must be
1003
 
                       defined in the regular program, or be undefweak.  */
 
1022
                       must hold there if we get here; the symbol must
 
1023
                       be defined in the regular program or be undefweak
 
1024
                       or be a function or otherwise need a PLT.  */
1004
1025
                    BFD_ASSERT (!elf_hash_table (info)->dynamic_sections_created
1005
1026
                                || info->shared
1006
1027
                                || (h->elf_link_hash_flags
1007
1028
                                    & ELF_LINK_HASH_DEF_REGULAR) != 0
 
1029
                                || h->type == STT_FUNC
 
1030
                                || (h->elf_link_hash_flags
 
1031
                                    & ELF_LINK_HASH_NEEDS_PLT)
1008
1032
                                || h->root.type == bfd_link_hash_undefweak);
1009
1033
 
1010
1034
                    /* This is actually a static link, or it is a
1292
1316
                    {
1293
1317
                      long indx;
1294
1318
 
1295
 
                      if (h == NULL)
1296
 
                        sec = local_sections[r_symndx];
1297
 
                      else
1298
 
                        {
1299
 
                          BFD_ASSERT (h->root.type == bfd_link_hash_defined
1300
 
                                      || (h->root.type
1301
 
                                          == bfd_link_hash_defweak));
1302
 
                          sec = h->root.u.def.section;
1303
 
                        }
1304
 
                      if (sec != NULL && bfd_is_abs_section (sec))
 
1319
                      if (bfd_is_abs_section (sec))
1305
1320
                        indx = 0;
1306
1321
                      else if (sec == NULL || sec->owner == NULL)
1307
1322
                        {
1427
1442
         to this function.  Note that we embed knowledge that "incoming"
1428
1443
         .got goes after .got.plt in the output without padding (pointer
1429
1444
         aligned).  However, that knowledge is present in several other
1430
 
         places too, here and in elflink.h at least.  */
 
1445
         places too.  */
1431
1446
      bfd_vma got_offset
1432
1447
        = (has_gotplt
1433
1448
           ? gotplt_offset
1517
1532
        }
1518
1533
    }
1519
1534
 
1520
 
  /* We don't emit .got relocs for symbols that aren't in the
1521
 
     dynamic-symbols table for an ordinary program and are either defined
1522
 
     by the program or are undefined weak symbols.  */
 
1535
  /* For an ordinary program, we emit .got relocs only for symbols that
 
1536
     are in the dynamic-symbols table and are either defined by the
 
1537
     program or are undefined weak symbols, or are function symbols
 
1538
     where we do not output a PLT: the PLT reloc was output above and all
 
1539
     references to the function symbol are redirected to the PLT.  */
1523
1540
  if (h->got.offset != (bfd_vma) -1
1524
1541
      && (info->shared
1525
1542
          || (h->dynindx != -1
 
1543
              && h->plt.offset == (bfd_vma) -1
1526
1544
              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
1527
1545
              && h->root.type != bfd_link_hash_undefweak)))
1528
1546
    {
1779
1797
  struct elf_link_hash_entry **sym_hashes;
1780
1798
  bfd_signed_vma *local_got_refcounts;
1781
1799
  const Elf_Internal_Rela *rel, *relend;
1782
 
  unsigned long r_symndx;
1783
 
  struct elf_link_hash_entry *h;
1784
1800
  bfd *dynobj;
1785
1801
  asection *sgot;
1786
1802
  asection *srelgot;
1787
1803
 
1788
 
  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1789
 
  sym_hashes = elf_sym_hashes (abfd);
1790
 
  local_got_refcounts = elf_local_got_refcounts (abfd);
1791
 
 
1792
1804
  dynobj = elf_hash_table (info)->dynobj;
1793
1805
  if (dynobj == NULL)
1794
1806
    return TRUE;
1795
1807
 
 
1808
  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
 
1809
  sym_hashes = elf_sym_hashes (abfd);
 
1810
  local_got_refcounts = elf_local_got_refcounts (abfd);
 
1811
 
1796
1812
  sgot = bfd_get_section_by_name (dynobj, ".got");
1797
1813
  srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1798
1814
 
1799
1815
  relend = relocs + sec->reloc_count;
1800
1816
  for (rel = relocs; rel < relend; rel++)
1801
1817
    {
 
1818
      unsigned long r_symndx;
 
1819
      struct elf_link_hash_entry *h;
 
1820
 
1802
1821
      switch (ELF32_R_TYPE (rel->r_info))
1803
1822
        {
1804
1823
        case R_CRIS_16_GOT:
1843
1862
          r_symndx = ELF32_R_SYM (rel->r_info);
1844
1863
          if (r_symndx < symtab_hdr->sh_info)
1845
1864
            goto local_got_reloc;
1846
 
 
 
1865
          /* Fall through.  */
1847
1866
        case R_CRIS_32_PLT_GOTREL:
1848
1867
          /* FIXME: We don't garbage-collect away the .got section.  */
1849
1868
          if (local_got_refcounts != NULL)
1850
1869
            local_got_refcounts[-1]--;
1851
1870
          /* Fall through.  */
1852
 
 
1853
1871
        case R_CRIS_8_PCREL:
1854
1872
        case R_CRIS_16_PCREL:
1855
1873
        case R_CRIS_32_PCREL:
1934
1952
   want to do this:
1935
1953
 
1936
1954
   - When all PLT references are GOTPLT references, and there are GOT
1937
 
     references.  We don't have to generate a PLT at all.
 
1955
     references, and this is not the executable.  We don't have to
 
1956
     generate a PLT at all.
1938
1957
 
1939
 
   - When there are both (ordinary) PLT references and GOT references.
 
1958
   - When there are both (ordinary) PLT references and GOT references,
 
1959
     and this isn't the executable.
1940
1960
     We want to make the PLT reference use the ordinary GOT entry rather
1941
 
     than a run-time dynamically resolved GOTPLT entry (since the GOT
1942
 
     entry will have to be resolved at startup anyway).
 
1961
     than R_CRIS_JUMP_SLOT, a run-time dynamically resolved GOTPLT entry,
 
1962
     since the GOT entry will have to be resolved at startup anyway.
1943
1963
 
1944
1964
   Though the latter case is handled when room for the PLT is allocated,
1945
1965
   not here.
1946
1966
 
 
1967
   By folding into the GOT, we may need a round-trip to a PLT in the
 
1968
   executable for calls, a loss in performance.  Still, losing a
 
1969
   reloc is a win in size and at least in start-up time.
 
1970
 
1947
1971
   Note that this function is called before symbols are forced local by
1948
1972
   version scripts.  The differing cases are handled by
1949
1973
   elf_cris_hide_symbol.  */
2050
2074
                                           info);
2051
2075
        }
2052
2076
 
2053
 
      /* If there are only GOT references and GOTPLT references to this
2054
 
         PLT entry, get rid of the PLT.  */
2055
 
      if (! elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry *)
2056
 
                                          h, info))
 
2077
      /* If we had a R_CRIS_GLOB_DAT that didn't have to point to a PLT;
 
2078
         where a pointer-equivalent symbol was unimportant (i.e. more
 
2079
         like R_CRIS_JUMP_SLOT after symbol evaluation) we could get rid
 
2080
         of the PLT.  We can't for the executable, because the GOT
 
2081
         entries will point to the PLT there (and be constant).  */
 
2082
      if (info->shared
 
2083
          && !elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry*)
 
2084
                                            h, info))
2057
2085
        return FALSE;
2058
2086
 
2059
2087
      /* GC or folding may have rendered this entry unused.  */
2067
2095
      /* Make sure this symbol is output as a dynamic symbol.  */
2068
2096
      if (h->dynindx == -1)
2069
2097
        {
2070
 
          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
 
2098
          if (! bfd_elf_link_record_dynamic_symbol (info, h))
2071
2099
            return FALSE;
2072
2100
        }
2073
2101
 
2091
2119
 
2092
2120
      /* If there's already a GOT entry, use that, not a .got.plt.  A
2093
2121
         GOT field still has a reference count when we get here; it's
2094
 
         not yet changed to an offset.  */
2095
 
      if (h->got.refcount > 0)
 
2122
         not yet changed to an offset.  We can't do this for an
 
2123
         executable, because then the reloc associated with the PLT
 
2124
         would get a non-PLT reloc pointing to the PLT.  FIXME: Move
 
2125
         this to elf_cris_try_fold_plt_to_got.  */
 
2126
      if (info->shared && h->got.refcount > 0)
2096
2127
        {
2097
2128
          h->got.refcount += h->plt.refcount;
2098
2129
 
2391
2422
                  /* Make sure this symbol is output as a dynamic symbol.  */
2392
2423
                  if (h->dynindx == -1)
2393
2424
                    {
2394
 
                      if (!bfd_elf32_link_record_dynamic_symbol (info, h))
 
2425
                      if (!bfd_elf_link_record_dynamic_symbol (info, h))
2395
2426
                        return FALSE;
2396
2427
                    }
2397
2428
 
2608
2639
        /* This relocation describes the C++ object vtable hierarchy.
2609
2640
           Reconstruct it for later use during GC.  */
2610
2641
        case R_CRIS_GNU_VTINHERIT:
2611
 
          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
 
2642
          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2612
2643
            return FALSE;
2613
2644
          break;
2614
2645
 
2615
2646
        /* This relocation describes which C++ vtable entries are actually
2616
2647
           used.  Record for later use during GC.  */
2617
2648
        case R_CRIS_GNU_VTENTRY:
2618
 
          if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
 
2649
          if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2619
2650
            return FALSE;
2620
2651
          break;
2621
2652
 
2647
2678
  if (elf_hash_table (info)->dynamic_sections_created)
2648
2679
    {
2649
2680
      /* Set the contents of the .interp section to the interpreter.  */
2650
 
      if (!info->shared)
 
2681
      if (info->executable)
2651
2682
        {
2652
2683
          s = bfd_get_section_by_name (dynobj, ".interp");
2653
2684
          BFD_ASSERT (s != NULL);
2778
2809
         the .dynamic section.  The DT_DEBUG entry is filled in by the
2779
2810
         dynamic linker and used by the debugger.  */
2780
2811
#define add_dynamic_entry(TAG, VAL) \
2781
 
  bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
2812
  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2782
2813
 
2783
2814
      if (!info->shared)
2784
2815
        {
2865
2896
 
2866
2897
  /* If we're not creating a shared library and have a symbol which is
2867
2898
     referred to by .got references, but the symbol is defined locally,
2868
 
     (or rather, not not defined by a DSO) then lose the reloc for the
2869
 
     .got (don't allocate room for it).  */
2870
 
  if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0)
 
2899
     (or rather, not defined by a DSO) then lose the reloc for the .got
 
2900
     (don't allocate room for it).  Likewise for relocs for something
 
2901
     for which we create a PLT.  */
 
2902
  if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
 
2903
      || h->root.plt.refcount > 0)
2871
2904
    {
2872
2905
      if (h->root.got.refcount > 0
2873
2906
          /* The size of this section is only valid and in sync with the
2893
2926
         introduce new problems.  Of course we don't do this if we're
2894
2927
         exporting all dynamic symbols.  */
2895
2928
      if (! info->export_dynamic
2896
 
          && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
 
2929
          && (h->root.elf_link_hash_flags
 
2930
              & (ELF_LINK_HASH_DEF_DYNAMIC|ELF_LINK_HASH_REF_DYNAMIC)) == 0)
2897
2931
        {
2898
2932
          h->root.dynindx = -1;
2899
2933
          _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
3056
3090
#define elf_backend_create_dynamic_sections \
3057
3091
        _bfd_elf_create_dynamic_sections
3058
3092
#define bfd_elf32_bfd_final_link \
3059
 
        _bfd_elf32_gc_common_final_link
 
3093
        bfd_elf_gc_common_final_link
3060
3094
#define elf_backend_hide_symbol                 elf_cris_hide_symbol
3061
3095
#define elf_backend_reloc_type_class            elf_cris_reloc_type_class
3062
3096
 
3064
3098
#define elf_backend_plt_readonly        1
3065
3099
#define elf_backend_want_plt_sym        0
3066
3100
#define elf_backend_got_header_size     12
3067
 
#define elf_backend_plt_header_size     PLT_ENTRY_SIZE
3068
3101
 
3069
3102
/* Later, we my want to optimize RELA entries into REL entries for dynamic
3070
3103
   linking and libraries (if it's a win of any significance).  Until then,