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

« back to all changes in this revision

Viewing changes to bfd/elfxx-ia64.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
/* IA-64 support for 64-bit ELF
2
 
   Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
2
   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
 
3
   Free Software Foundation, Inc.
3
4
   Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5
 
5
6
   This file is part of BFD, the Binary File Descriptor library.
24
25
#include "elf-bfd.h"
25
26
#include "opcode/ia64.h"
26
27
#include "elf/ia64.h"
 
28
#include "objalloc.h"
 
29
#include "hashtab.h"
27
30
 
28
31
/* THE RULES for all the stuff the linker creates --
29
32
 
51
54
                descriptor for a MIN_PLT entry, and requires one IPLT reloc.
52
55
 
53
56
  MIN_PLT       Created by PLTOFF entries against dynamic symbols.  This
54
 
                does not reqire dynamic relocations.  */
 
57
                does not require dynamic relocations.  */
55
58
 
56
59
#define NELEMS(a)       ((int) (sizeof (a) / sizeof ((a)[0])))
57
60
 
79
82
  bfd_vma dtpmod_offset;
80
83
  bfd_vma dtprel_offset;
81
84
 
82
 
  /* The symbol table entry, if any, that this was derrived from.  */
 
85
  /* The symbol table entry, if any, that this was derived from.  */
83
86
  struct elf_link_hash_entry *h;
84
87
 
85
88
  /* Used to count non-got, non-plt relocations for delayed sizing
90
93
    asection *srel;
91
94
    int type;
92
95
    int count;
 
96
 
 
97
    /* Is this reloc against readonly section? */
 
98
    bfd_boolean reltext;
93
99
  } *reloc_entries;
94
100
 
95
101
  /* TRUE when the section contents have been updated.  */
115
121
 
116
122
struct elfNN_ia64_local_hash_entry
117
123
{
118
 
  struct bfd_hash_entry root;
 
124
  int id;
 
125
  unsigned int r_sym;
119
126
  struct elfNN_ia64_dyn_sym_info *info;
120
127
 
121
128
  /* TRUE if this hash entry's addends was translated for
123
130
  unsigned sec_merge_done : 1;
124
131
};
125
132
 
126
 
struct elfNN_ia64_local_hash_table
127
 
{
128
 
  struct bfd_hash_table root;
129
 
  /* No additional fields for now.  */
130
 
};
131
 
 
132
133
struct elfNN_ia64_link_hash_entry
133
134
{
134
135
  struct elf_link_hash_entry root;
153
154
  unsigned self_dtpmod_done : 1;/* has self DTPMOD entry been finished? */
154
155
  bfd_vma self_dtpmod_offset;   /* .got offset to self DTPMOD entry */
155
156
 
156
 
  struct elfNN_ia64_local_hash_table loc_hash_table;
 
157
  htab_t loc_hash_table;
 
158
  void *loc_hash_memory;
157
159
};
158
160
 
159
161
struct elfNN_ia64_allocate_data
190
192
static void elfNN_ia64_final_write_processing
191
193
  PARAMS ((bfd *abfd, bfd_boolean linker));
192
194
static bfd_boolean elfNN_ia64_add_symbol_hook
193
 
  PARAMS ((bfd *abfd, struct bfd_link_info *info, const Elf_Internal_Sym *sym,
 
195
  PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Sym *sym,
194
196
           const char **namep, flagword *flagsp, asection **secp,
195
197
           bfd_vma *valp));
196
198
static int elfNN_ia64_additional_program_headers
197
199
  PARAMS ((bfd *abfd));
198
200
static bfd_boolean elfNN_ia64_modify_segment_map
199
 
  PARAMS ((bfd *));
 
201
  PARAMS ((bfd *, struct bfd_link_info *));
200
202
static bfd_boolean elfNN_ia64_is_local_label_name
201
203
  PARAMS ((bfd *abfd, const char *name));
202
204
static bfd_boolean elfNN_ia64_dynamic_symbol_p
203
205
  PARAMS ((struct elf_link_hash_entry *h, struct bfd_link_info *info, int));
204
 
static bfd_boolean elfNN_ia64_local_hash_table_init
205
 
  PARAMS ((struct elfNN_ia64_local_hash_table *ht, bfd *abfd,
206
 
           new_hash_entry_func new));
207
 
static struct bfd_hash_entry *elfNN_ia64_new_loc_hash_entry
208
 
  PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
209
 
           const char *string));
210
206
static struct bfd_hash_entry *elfNN_ia64_new_elf_hash_entry
211
207
  PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
212
208
           const char *string));
215
211
           struct elf_link_hash_entry *));
216
212
static void elfNN_ia64_hash_hide_symbol
217
213
  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean));
 
214
static hashval_t elfNN_ia64_local_htab_hash PARAMS ((const void *));
 
215
static int elfNN_ia64_local_htab_eq PARAMS ((const void *ptr1,
 
216
                                             const void *ptr2));
218
217
static struct bfd_link_hash_table *elfNN_ia64_hash_table_create
219
218
  PARAMS ((bfd *abfd));
220
 
static struct elfNN_ia64_local_hash_entry *elfNN_ia64_local_hash_lookup
221
 
  PARAMS ((struct elfNN_ia64_local_hash_table *table, const char *string,
222
 
           bfd_boolean create, bfd_boolean copy));
 
219
static void elfNN_ia64_hash_table_free
 
220
  PARAMS ((struct bfd_link_hash_table *hash));
223
221
static bfd_boolean elfNN_ia64_global_dyn_sym_thunk
224
222
  PARAMS ((struct bfd_hash_entry *, PTR));
225
 
static bfd_boolean elfNN_ia64_local_dyn_sym_thunk
226
 
  PARAMS ((struct bfd_hash_entry *, PTR));
 
223
static int elfNN_ia64_local_dyn_sym_thunk
 
224
  PARAMS ((void **, PTR));
227
225
static void elfNN_ia64_dyn_sym_traverse
228
226
  PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info,
229
227
           bfd_boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR),
249
247
static asection *get_reloc_section
250
248
  PARAMS ((bfd *abfd, struct elfNN_ia64_link_hash_table *ia64_info,
251
249
           asection *sec, bfd_boolean create));
252
 
static bfd_boolean count_dyn_reloc
253
 
  PARAMS ((bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i,
254
 
           asection *srel, int type));
255
250
static bfd_boolean elfNN_ia64_check_relocs
256
251
  PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
257
252
           const Elf_Internal_Rela *relocs));
641
636
static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] =
642
637
{
643
638
  0x0b, 0x78, 0x00, 0x02, 0x00, 0x24,  /*   [MMI]       addl r15=0,r1;;    */
644
 
  0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0,  /*               ld8 r16=[r15],8    */
 
639
  0x00, 0x41, 0x3c, 0x70, 0x29, 0xc0,  /*               ld8.acq r16=[r15],8*/
645
640
  0x01, 0x08, 0x00, 0x84,              /*               mov r14=r1;;       */
646
641
  0x11, 0x08, 0x00, 0x1e, 0x18, 0x10,  /*   [MIB]       ld8 r1=[r15]       */
647
642
  0x60, 0x80, 0x04, 0x80, 0x03, 0x00,  /*               mov b6=r16         */
678
673
  oor_branch_size = itanium ? sizeof (oor_ip) : sizeof (oor_brl);
679
674
}
680
675
 
 
676
static void
 
677
elfNN_ia64_relax_brl (bfd *abfd, bfd_byte *contents, bfd_vma off)
 
678
{
 
679
  int template;
 
680
  bfd_byte *hit_addr;
 
681
  bfd_vma t0, t1, i0, i1, i2;
 
682
 
 
683
  hit_addr = (bfd_byte *) (contents + off);
 
684
  hit_addr -= (long) hit_addr & 0x3;
 
685
  t0 = bfd_get_64 (abfd, hit_addr);
 
686
  t1 = bfd_get_64 (abfd, hit_addr + 8);
 
687
 
 
688
  /* Keep the instruction in slot 0. */
 
689
  i0 = (t0 >> 5) & 0x1ffffffffffLL;
 
690
  /* Use nop.b for slot 1. */
 
691
  i1 = 0x4000000000LL;
 
692
  /* For slot 2, turn brl into br by masking out bit 40.  */
 
693
  i2 = (t1 >> 23) & 0x0ffffffffffLL;
 
694
 
 
695
  /* Turn a MLX bundle into a MBB bundle with the same stop-bit
 
696
     variety.  */
 
697
  template = 0x12;
 
698
  if ((t0 & 0x1fLL) == 5)
 
699
    template += 1;
 
700
  t0 = (i1 << 46) | (i0 << 5) | template;
 
701
  t1 = (i2 << 23) | (i1 >> 18);
 
702
 
 
703
  bfd_put_64 (abfd, t0, hit_addr);
 
704
  bfd_put_64 (abfd, t1, hit_addr + 8);
 
705
}
681
706
 
682
707
/* These functions do relaxation for IA-64 ELF.  */
683
708
 
713
738
  *again = FALSE;
714
739
 
715
740
  /* Don't even try to relax for non-ELF outputs.  */
716
 
  if (link_info->hash->creator->flavour != bfd_target_elf_flavour)
 
741
  if (!is_elf_hash_table (link_info->hash))
717
742
    return FALSE;
718
743
 
719
744
  /* Nothing to do if there are no relocations or there is no need for
720
745
     the relax finalize pass.  */
721
746
  if ((sec->flags & SEC_RELOC) == 0
722
747
      || sec->reloc_count == 0
723
 
      || (link_info->relax_finalizing
 
748
      || (!link_info->need_relax_finalize
724
749
          && sec->need_finalize_relax == 0))
725
750
    return TRUE;
726
751
 
771
796
        case R_IA64_PCREL21BI:
772
797
        case R_IA64_PCREL21M:
773
798
        case R_IA64_PCREL21F:
774
 
          if (link_info->relax_finalizing)
 
799
          /* In the finalize pass, all br relaxations are done. We can
 
800
             skip it. */
 
801
          if (!link_info->need_relax_finalize)
775
802
            continue;
776
803
          is_branch = TRUE;
777
804
          break;
778
805
 
 
806
        case R_IA64_PCREL60B:
 
807
          /* We can't optimize brl to br before the finalize pass since
 
808
             br relaxations will increase the code size. Defer it to
 
809
             the finalize pass.  */
 
810
          if (link_info->need_relax_finalize)
 
811
            {
 
812
              sec->need_finalize_relax = 1;
 
813
              continue;
 
814
            }
 
815
          is_branch = TRUE;
 
816
          break;
 
817
 
779
818
        case R_IA64_LTOFF22X:
780
819
        case R_IA64_LDXMOV:
781
 
          if (!link_info->relax_finalizing)
 
820
          /* We can't relax ldx/mov before the finalize pass since
 
821
             br relaxations will increase the code size. Defer it to
 
822
             the finalize pass.  */
 
823
          if (link_info->need_relax_finalize)
782
824
            {
783
825
              sec->need_finalize_relax = 1;
784
826
              continue;
810
852
 
811
853
          isym = isymbuf + ELFNN_R_SYM (irel->r_info);
812
854
          if (isym->st_shndx == SHN_UNDEF)
813
 
            continue;   /* We can't do anthing with undefined symbols.  */
 
855
            continue;   /* We can't do anything with undefined symbols.  */
814
856
          else if (isym->st_shndx == SHN_ABS)
815
857
            tsec = bfd_abs_section_ptr;
816
858
          else if (isym->st_shndx == SHN_COMMON)
858
900
 
859
901
          else
860
902
            {
861
 
              /* We can't do anthing with undefined symbols.  */
 
903
              /* We can't do anything with undefined symbols.  */
862
904
              if (h->root.type == bfd_link_hash_undefined
863
905
                  || h->root.type == bfd_link_hash_undefweak)
864
906
                continue;
882
924
 
883
925
      if (is_branch)
884
926
        {
 
927
          bfd_signed_vma offset;
 
928
 
885
929
          reladdr = (sec->output_section->vma
886
930
                     + sec->output_offset
887
931
                     + roff) & (bfd_vma) -4;
889
933
          /* If the branch is in range, no need to do anything.  */
890
934
          if ((bfd_signed_vma) (symaddr - reladdr) >= -0x1000000
891
935
              && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0)
 
936
            {
 
937
              /* If the 60-bit branch is in 21-bit range, optimize it. */
 
938
              if (r_type == R_IA64_PCREL60B)
 
939
                {
 
940
                  elfNN_ia64_relax_brl (abfd, contents, roff);
 
941
 
 
942
                  irel->r_info
 
943
                    = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
 
944
                                    R_IA64_PCREL21B);
 
945
 
 
946
                  /* If the original relocation offset points to slot
 
947
                     1, change it to slot 2.  */
 
948
                  if ((irel->r_offset & 3) == 1)
 
949
                    irel->r_offset += 1;
 
950
                }
 
951
 
 
952
              continue;
 
953
            }
 
954
          else if (r_type == R_IA64_PCREL60B)
892
955
            continue;
893
956
 
894
957
          /* If the branch and target are in the same section, you've
917
980
 
918
981
              /* Resize the current section to make room for the new branch. */
919
982
              trampoff = (sec->_cooked_size + 15) & (bfd_vma) -16;
 
983
 
 
984
              /* If trampoline is out of range, there is nothing we
 
985
                 can do.  */
 
986
              offset = trampoff - (roff & (bfd_vma) -4);
 
987
              if (offset < -0x1000000 || offset > 0x0FFFFF0)
 
988
                continue;
 
989
 
920
990
              amt = trampoff + size;
921
991
              contents = (bfd_byte *) bfd_realloc (contents, amt);
922
992
              if (contents == NULL)
963
1033
            }
964
1034
          else
965
1035
            {
 
1036
              /* If trampoline is out of range, there is nothing we
 
1037
                 can do.  */
 
1038
              offset = f->trampoff - (roff & (bfd_vma) -4);
 
1039
              if (offset < -0x1000000 || offset > 0x0FFFFF0)
 
1040
                continue;
 
1041
 
966
1042
              /* Nop out the reloc, since we're finalizing things here.  */
967
1043
              irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE);
968
1044
            }
969
1045
 
970
 
          /* Fix up the existing branch to hit the trampoline.  Hope like
971
 
             hell this doesn't overflow too.  */
972
 
          if (elfNN_ia64_install_value (abfd, contents + roff,
973
 
                                        f->trampoff - (roff & (bfd_vma) -4),
 
1046
          /* Fix up the existing branch to hit the trampoline.  */
 
1047
          if (elfNN_ia64_install_value (abfd, contents + roff, offset,
974
1048
                                        r_type) != bfd_reloc_ok)
975
1049
            goto error_return;
976
1050
 
1079
1153
      /* ??? Resize .rela.got too.  */
1080
1154
    }
1081
1155
 
1082
 
  if (link_info->relax_finalizing)
 
1156
  if (!link_info->need_relax_finalize)
1083
1157
    sec->need_finalize_relax = 0;
1084
1158
 
1085
1159
  *again = changed_contents || changed_relocs;
1356
1430
elfNN_ia64_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
1357
1431
     bfd *abfd;
1358
1432
     struct bfd_link_info *info;
1359
 
     const Elf_Internal_Sym *sym;
 
1433
     Elf_Internal_Sym *sym;
1360
1434
     const char **namep ATTRIBUTE_UNUSED;
1361
1435
     flagword *flagsp ATTRIBUTE_UNUSED;
1362
1436
     asection **secp;
1411
1485
}
1412
1486
 
1413
1487
static bfd_boolean
1414
 
elfNN_ia64_modify_segment_map (abfd)
 
1488
elfNN_ia64_modify_segment_map (abfd, info)
1415
1489
     bfd *abfd;
 
1490
     struct bfd_link_info *info ATTRIBUTE_UNUSED;
1416
1491
{
1417
1492
  struct elf_segment_map *m, **pm;
1418
1493
  Elf_Internal_Shdr *hdr;
1552
1627
  return _bfd_elf_dynamic_symbol_p (h, info, ignore_protected);
1553
1628
}
1554
1629
 
1555
 
static bfd_boolean
1556
 
elfNN_ia64_local_hash_table_init (ht, abfd, new)
1557
 
     struct elfNN_ia64_local_hash_table *ht;
1558
 
     bfd *abfd ATTRIBUTE_UNUSED;
1559
 
     new_hash_entry_func new;
1560
 
{
1561
 
  memset (ht, 0, sizeof (*ht));
1562
 
  return bfd_hash_table_init (&ht->root, new);
1563
 
}
1564
 
 
1565
 
static struct bfd_hash_entry*
1566
 
elfNN_ia64_new_loc_hash_entry (entry, table, string)
1567
 
     struct bfd_hash_entry *entry;
1568
 
     struct bfd_hash_table *table;
1569
 
     const char *string;
1570
 
{
1571
 
  struct elfNN_ia64_local_hash_entry *ret;
1572
 
  ret = (struct elfNN_ia64_local_hash_entry *) entry;
1573
 
 
1574
 
  /* Allocate the structure if it has not already been allocated by a
1575
 
     subclass.  */
1576
 
  if (!ret)
1577
 
    ret = bfd_hash_allocate (table, sizeof (*ret));
1578
 
 
1579
 
  if (!ret)
1580
 
    return 0;
1581
 
 
1582
 
  /* Initialize our local data.  All zeros, and definitely easier
1583
 
     than setting a handful of bit fields.  */
1584
 
  memset (ret, 0, sizeof (*ret));
1585
 
 
1586
 
  /* Call the allocation method of the superclass.  */
1587
 
  ret = ((struct elfNN_ia64_local_hash_entry *)
1588
 
         bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
1589
 
 
1590
 
  return (struct bfd_hash_entry *) ret;
1591
 
}
1592
 
 
1593
1630
static struct bfd_hash_entry*
1594
1631
elfNN_ia64_new_elf_hash_entry (entry, table, string)
1595
1632
     struct bfd_hash_entry *entry;
1636
1673
    (ind->root.elf_link_hash_flags
1637
1674
     & (ELF_LINK_HASH_REF_DYNAMIC
1638
1675
        | ELF_LINK_HASH_REF_REGULAR
1639
 
        | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
 
1676
        | ELF_LINK_HASH_REF_REGULAR_NONWEAK
 
1677
        | ELF_LINK_HASH_NEEDS_PLT));
1640
1678
 
1641
1679
  if (ind->root.root.type != bfd_link_hash_indirect)
1642
1680
    return;
1689
1727
    }
1690
1728
}
1691
1729
 
 
1730
/* Compute a hash of a local hash entry.  */
 
1731
 
 
1732
static hashval_t
 
1733
elfNN_ia64_local_htab_hash (ptr)
 
1734
     const void *ptr;
 
1735
{
 
1736
  struct elfNN_ia64_local_hash_entry *entry
 
1737
    = (struct elfNN_ia64_local_hash_entry *) ptr;
 
1738
 
 
1739
  return (((entry->id & 0xff) << 24) | ((entry->id & 0xff00) << 8))
 
1740
          ^ entry->r_sym ^ (entry->id >> 16);
 
1741
}
 
1742
 
 
1743
/* Compare local hash entries.  */
 
1744
 
 
1745
static int
 
1746
elfNN_ia64_local_htab_eq (ptr1, ptr2)
 
1747
     const void *ptr1, *ptr2;
 
1748
{
 
1749
  struct elfNN_ia64_local_hash_entry *entry1
 
1750
    = (struct elfNN_ia64_local_hash_entry *) ptr1;
 
1751
  struct elfNN_ia64_local_hash_entry *entry2
 
1752
    = (struct elfNN_ia64_local_hash_entry *) ptr2;
 
1753
 
 
1754
  return entry1->id == entry2->id && entry1->r_sym == entry2->r_sym;
 
1755
}
 
1756
 
1692
1757
/* Create the derived linker hash table.  The IA-64 ELF port uses this
1693
1758
   derived hash table to keep information specific to the IA-64 ElF
1694
1759
   linker (without using static variables).  */
1710
1775
      return 0;
1711
1776
    }
1712
1777
 
1713
 
  if (!elfNN_ia64_local_hash_table_init (&ret->loc_hash_table, abfd,
1714
 
                                         elfNN_ia64_new_loc_hash_entry))
 
1778
  ret->loc_hash_table = htab_try_create (1024, elfNN_ia64_local_htab_hash,
 
1779
                                         elfNN_ia64_local_htab_eq, NULL);
 
1780
  ret->loc_hash_memory = objalloc_create ();
 
1781
  if (!ret->loc_hash_table || !ret->loc_hash_memory)
1715
1782
    {
1716
1783
      free (ret);
1717
1784
      return 0;
1720
1787
  return &ret->root.root;
1721
1788
}
1722
1789
 
1723
 
/* Look up an entry in a Alpha ELF linker hash table.  */
 
1790
/* Destroy IA-64 linker hash table.  */
1724
1791
 
1725
 
static INLINE struct elfNN_ia64_local_hash_entry *
1726
 
elfNN_ia64_local_hash_lookup(table, string, create, copy)
1727
 
     struct elfNN_ia64_local_hash_table *table;
1728
 
     const char *string;
1729
 
     bfd_boolean create, copy;
 
1792
static void
 
1793
elfNN_ia64_hash_table_free (hash)
 
1794
     struct bfd_link_hash_table *hash;
1730
1795
{
1731
 
  return ((struct elfNN_ia64_local_hash_entry *)
1732
 
          bfd_hash_lookup (&table->root, string, create, copy));
 
1796
  struct elfNN_ia64_link_hash_table *ia64_info
 
1797
    = (struct elfNN_ia64_link_hash_table *) hash;
 
1798
  if (ia64_info->loc_hash_table)
 
1799
    htab_delete (ia64_info->loc_hash_table);
 
1800
  if (ia64_info->loc_hash_memory)
 
1801
    objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory);
 
1802
  _bfd_generic_link_hash_table_free (hash);
1733
1803
}
1734
1804
 
1735
1805
/* Traverse both local and global hash tables.  */
1761
1831
}
1762
1832
 
1763
1833
static bfd_boolean
1764
 
elfNN_ia64_local_dyn_sym_thunk (xentry, xdata)
1765
 
     struct bfd_hash_entry *xentry;
 
1834
elfNN_ia64_local_dyn_sym_thunk (slot, xdata)
 
1835
     void **slot;
1766
1836
     PTR xdata;
1767
1837
{
1768
1838
  struct elfNN_ia64_local_hash_entry *entry
1769
 
    = (struct elfNN_ia64_local_hash_entry *) xentry;
 
1839
    = (struct elfNN_ia64_local_hash_entry *) *slot;
1770
1840
  struct elfNN_ia64_dyn_sym_traverse_data *data
1771
1841
    = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata;
1772
1842
  struct elfNN_ia64_dyn_sym_info *dyn_i;
1773
1843
 
1774
1844
  for (dyn_i = entry->info; dyn_i; dyn_i = dyn_i->next)
1775
1845
    if (! (*data->func) (dyn_i, data->data))
1776
 
      return FALSE;
1777
 
  return TRUE;
 
1846
      return 0;
 
1847
  return 1;
1778
1848
}
1779
1849
 
1780
1850
static void
1790
1860
 
1791
1861
  elf_link_hash_traverse (&ia64_info->root,
1792
1862
                          elfNN_ia64_global_dyn_sym_thunk, &xdata);
1793
 
  bfd_hash_traverse (&ia64_info->loc_hash_table.root,
1794
 
                     elfNN_ia64_local_dyn_sym_thunk, &xdata);
 
1863
  htab_traverse (ia64_info->loc_hash_table,
 
1864
                 elfNN_ia64_local_dyn_sym_thunk, &xdata);
1795
1865
}
1796
1866
 
1797
1867
static bfd_boolean
1853
1923
     const Elf_Internal_Rela *rel;
1854
1924
     bfd_boolean create;
1855
1925
{
1856
 
  struct elfNN_ia64_local_hash_entry *ret;
 
1926
  struct elfNN_ia64_local_hash_entry e, *ret;
1857
1927
  asection *sec = abfd->sections;
1858
 
  char addr_name [34];
1859
 
 
1860
 
  BFD_ASSERT ((sizeof (sec->id)*2 + 1 + sizeof (unsigned long)*2 + 1) <= 34);
1861
 
  BFD_ASSERT (sec);
1862
 
 
1863
 
  /* Construct a string for use in the elfNN_ia64_local_hash_table.
1864
 
     name describes what was once anonymous memory.  */
1865
 
 
1866
 
  sprintf (addr_name, "%x:%lx",
1867
 
           sec->id, (unsigned long) ELFNN_R_SYM (rel->r_info));
1868
 
 
1869
 
  /* Collect the canonical entry data for this address.  */
1870
 
  ret = elfNN_ia64_local_hash_lookup (&ia64_info->loc_hash_table,
1871
 
                                      addr_name, create, create);
 
1928
  hashval_t h = (((sec->id & 0xff) << 24) | ((sec->id & 0xff00) << 8))
 
1929
                ^ ELFNN_R_SYM (rel->r_info) ^ (sec->id >> 16);
 
1930
  void **slot;
 
1931
 
 
1932
  e.id = sec->id;
 
1933
  e.r_sym = ELFNN_R_SYM (rel->r_info);
 
1934
  slot = htab_find_slot_with_hash (ia64_info->loc_hash_table, &e, h,
 
1935
                                   create ? INSERT : NO_INSERT);
 
1936
 
 
1937
  if (!slot)
 
1938
    return NULL;
 
1939
 
 
1940
  if (*slot)
 
1941
    return (struct elfNN_ia64_local_hash_entry *) *slot;
 
1942
 
 
1943
  ret = (struct elfNN_ia64_local_hash_entry *)
 
1944
        objalloc_alloc ((struct objalloc *) ia64_info->loc_hash_memory,
 
1945
                        sizeof (struct elfNN_ia64_local_hash_entry));
 
1946
  if (ret)
 
1947
    {
 
1948
      memset (ret, 0, sizeof (*ret));
 
1949
      ret->id = sec->id;
 
1950
      ret->r_sym = ELFNN_R_SYM (rel->r_info);
 
1951
      *slot = ret;
 
1952
    }
1872
1953
  return ret;
1873
1954
}
1874
1955
 
1953
2034
}
1954
2035
 
1955
2036
/* Create function descriptor section (.opd).  This section is called .opd
1956
 
   because it contains "official prodecure descriptors".  The "official"
 
2037
   because it contains "official procedure descriptors".  The "official"
1957
2038
   refers to the fact that these descriptors are used when taking the address
1958
2039
   of a procedure, thus ensuring a unique address for each procedure.  */
1959
2040
 
1993
2074
      if (info->pie)
1994
2075
        {
1995
2076
          asection *fptr_rel;
1996
 
          fptr_rel = bfd_make_section(abfd, ".rela.opd");
 
2077
          fptr_rel = bfd_make_section(dynobj, ".rela.opd");
1997
2078
          if (fptr_rel == NULL
1998
 
              || !bfd_set_section_flags (abfd, fptr_rel,
 
2079
              || !bfd_set_section_flags (dynobj, fptr_rel,
1999
2080
                                         (SEC_ALLOC | SEC_LOAD
2000
2081
                                          | SEC_HAS_CONTENTS
2001
2082
                                          | SEC_IN_MEMORY
2095
2176
        return NULL;
2096
2177
    }
2097
2178
 
2098
 
  if (sec->flags & SEC_READONLY)
2099
 
    ia64_info->reltext = 1;
2100
 
 
2101
2179
  return srel;
2102
2180
}
2103
2181
 
2104
2182
static bfd_boolean
2105
 
count_dyn_reloc (abfd, dyn_i, srel, type)
2106
 
     bfd *abfd;
2107
 
     struct elfNN_ia64_dyn_sym_info *dyn_i;
2108
 
     asection *srel;
2109
 
     int type;
 
2183
count_dyn_reloc (bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i,
 
2184
                 asection *srel, int type, bfd_boolean reltext)
2110
2185
{
2111
2186
  struct elfNN_ia64_dyn_reloc_entry *rent;
2112
2187
 
2127
2202
      rent->count = 0;
2128
2203
      dyn_i->reloc_entries = rent;
2129
2204
    }
 
2205
  rent->reltext = reltext;
2130
2206
  rent->count++;
2131
2207
 
2132
2208
  return TRUE;
2383
2459
             dynamic symbol table.  */
2384
2460
          if (!h && info->shared)
2385
2461
            {
2386
 
              if (! (_bfd_elfNN_link_record_local_dynamic_symbol
 
2462
              if (! (bfd_elf_link_record_local_dynamic_symbol
2387
2463
                     (info, abfd, (long) r_symndx)))
2388
2464
                return FALSE;
2389
2465
            }
2411
2487
              if (!srel)
2412
2488
                return FALSE;
2413
2489
            }
2414
 
          if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type))
 
2490
          if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type,
 
2491
                                (sec->flags & SEC_READONLY) != 0))
2415
2492
            return FALSE;
2416
2493
        }
2417
2494
    }
2554
2631
              BFD_ASSERT ((h->root.type == bfd_link_hash_defined)
2555
2632
                          || (h->root.type == bfd_link_hash_defweak));
2556
2633
 
2557
 
              if (!_bfd_elfNN_link_record_local_dynamic_symbol
 
2634
              if (!bfd_elf_link_record_local_dynamic_symbol
2558
2635
                    (x->info, h->root.u.def.section->owner,
2559
2636
                     global_sym_index (h)))
2560
2637
                return FALSE;
2718
2795
        default:
2719
2796
          abort ();
2720
2797
        }
 
2798
      if (rent->reltext)
 
2799
        ia64_info->reltext = 1;
2721
2800
      rent->srel->_raw_size += sizeof (ElfNN_External_Rela) * count;
2722
2801
    }
2723
2802
 
2862
2941
  data.ofs = (data.ofs + 31) & (bfd_vma) -32;
2863
2942
 
2864
2943
  elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data);
2865
 
  if (data.ofs != 0)
 
2944
  if (data.ofs != 0 || ia64_info->root.dynamic_sections_created)
2866
2945
    {
 
2946
      /* FIXME: we always reserve the memory for dynamic linker even if
 
2947
         there are no PLT entries since dynamic linker may assume the
 
2948
         reserved memory always exists.  */
 
2949
 
2867
2950
      BFD_ASSERT (ia64_info->root.dynamic_sections_created);
2868
2951
 
2869
2952
      ia64_info->plt_sec->_raw_size = data.ofs;
2928
3011
          if (strip)
2929
3012
            ia64_info->fptr_sec = NULL;
2930
3013
        }
 
3014
      else if (sec == ia64_info->rel_fptr_sec)
 
3015
        {
 
3016
          if (strip)
 
3017
            ia64_info->rel_fptr_sec = NULL;
 
3018
          else
 
3019
            /* We use the reloc_count field as a counter if we need to
 
3020
               copy relocs into the output file.  */
 
3021
            sec->reloc_count = 0;
 
3022
        }
2931
3023
      else if (sec == ia64_info->plt_sec)
2932
3024
        {
2933
3025
          if (strip)
2995
3087
          /* The DT_DEBUG entry is filled in by the dynamic linker and used
2996
3088
             by the debugger.  */
2997
3089
#define add_dynamic_entry(TAG, VAL) \
2998
 
  bfd_elfNN_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
3090
  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2999
3091
 
3000
3092
          if (!add_dynamic_entry (DT_DEBUG, 0))
3001
3093
            return FALSE;
3545
3637
elfNN_ia64_tprel_base (info)
3546
3638
     struct bfd_link_info *info;
3547
3639
{
3548
 
  struct elf_link_tls_segment *tls_segment
3549
 
    = elf_hash_table (info)->tls_segment;
 
3640
  asection *tls_sec = elf_hash_table (info)->tls_sec;
3550
3641
 
3551
 
  BFD_ASSERT (tls_segment != NULL);
3552
 
  return (tls_segment->start
3553
 
          - align_power ((bfd_vma) 16, tls_segment->align));
 
3642
  BFD_ASSERT (tls_sec != NULL);
 
3643
  return tls_sec->vma - align_power ((bfd_vma) 16, tls_sec->alignment_power);
3554
3644
}
3555
3645
 
3556
3646
/* Return the base VMA address which should be subtracted from real addresses
3561
3651
elfNN_ia64_dtprel_base (info)
3562
3652
     struct bfd_link_info *info;
3563
3653
{
3564
 
  BFD_ASSERT (elf_hash_table (info)->tls_segment != NULL);
3565
 
  return elf_hash_table (info)->tls_segment->start;
 
3654
  BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
 
3655
  return elf_hash_table (info)->tls_sec->vma;
3566
3656
}
3567
3657
 
3568
3658
/* Called through qsort to sort the .IA_64.unwind section during a
3752
3842
    }
3753
3843
 
3754
3844
  /* Invoke the regular ELF backend linker to do all the work.  */
3755
 
  if (!bfd_elfNN_bfd_final_link (abfd, info))
 
3845
  if (!bfd_elf_final_link (abfd, info))
3756
3846
    return FALSE;
3757
3847
 
3758
3848
  if (unwind_output_sec)
3849
3939
      if (r_symndx < symtab_hdr->sh_info)
3850
3940
        {
3851
3941
          /* Reloc against local symbol.  */
 
3942
          asection *msec;
3852
3943
          sym = local_syms + r_symndx;
3853
3944
          sym_sec = local_sections[r_symndx];
3854
 
          value = _bfd_elf_rela_local_sym (output_bfd, sym, sym_sec, rel);
 
3945
          msec = sym_sec;
 
3946
          value = _bfd_elf_rela_local_sym (output_bfd, sym, &msec, rel);
3855
3947
          if ((sym_sec->flags & SEC_MERGE)
3856
3948
              && ELF_ST_TYPE (sym->st_info) == STT_SECTION
3857
3949
              && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
3862
3954
              if (loc_h && ! loc_h->sec_merge_done)
3863
3955
                {
3864
3956
                  struct elfNN_ia64_dyn_sym_info *dynent;
3865
 
                  asection *msec;
3866
3957
 
3867
3958
                  for (dynent = loc_h->info; dynent; dynent = dynent->next)
3868
3959
                    {
3888
3979
        {
3889
3980
          bfd_boolean unresolved_reloc;
3890
3981
          bfd_boolean warned;
 
3982
          struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
3891
3983
 
3892
 
          RELOC_FOR_GLOBAL_SYMBOL (h, elf_sym_hashes (input_bfd),
3893
 
                                   r_symndx,
3894
 
                                   symtab_hdr, value, sym_sec,
3895
 
                                   unresolved_reloc, info,
3896
 
                                   warned);
 
3984
          RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
 
3985
                                   r_symndx, symtab_hdr, sym_hashes,
 
3986
                                   h, sym_sec, value,
 
3987
                                   unresolved_reloc, warned);
3897
3988
 
3898
3989
          if (h->root.type == bfd_link_hash_undefweak)
3899
3990
            undef_weak_ref = TRUE;
3929
4020
 
3930
4021
              BFD_ASSERT (srel != NULL);
3931
4022
 
 
4023
              switch (r_type)
 
4024
                {
 
4025
                case R_IA64_IMM14:
 
4026
                case R_IA64_IMM22:
 
4027
                case R_IA64_IMM64:
 
4028
                  /* ??? People shouldn't be doing non-pic code in
 
4029
                     shared libraries nor dynamic executables.  */
 
4030
                  (*_bfd_error_handler)
 
4031
                    (_("%s: non-pic code with imm relocation against dynamic symbol `%s'"),
 
4032
                     bfd_archive_filename (input_bfd),
 
4033
                     h->root.root.string);
 
4034
                  ret_val = FALSE;
 
4035
                  continue;
 
4036
 
 
4037
                default:
 
4038
                  break;
 
4039
                }
 
4040
 
3932
4041
              /* If we don't need dynamic symbol lookup, find a
3933
4042
                 matching RELATIVE relocation.  */
3934
4043
              dyn_r_type = r_type;
3956
4065
                      break;
3957
4066
 
3958
4067
                    default:
3959
 
                      /* We can't represent this without a dynamic symbol.
3960
 
                         Adjust the relocation to be against an output
3961
 
                         section symbol, which are always present in the
3962
 
                         dynamic symbol table.  */
3963
 
                      /* ??? People shouldn't be doing non-pic code in
3964
 
                         shared libraries.  Hork.  */
3965
 
                      (*_bfd_error_handler)
3966
 
                        (_("%s: linking non-pic code in a shared library"),
3967
 
                         bfd_archive_filename (input_bfd));
3968
 
                      ret_val = FALSE;
3969
 
                      continue;
 
4068
                      break;
3970
4069
                    }
3971
4070
                  dynindx = 0;
3972
4071
                  addend = value;
4501
4600
          /* Mark the symbol as undefined, rather than as defined in the
4502
4601
             plt section.  Leave the value alone.  */
4503
4602
          /* ??? We didn't redefine it in adjust_dynamic_symbol in the
4504
 
             first place.  But perhaps elflink.h did some for us.  */
 
4603
             first place.  But perhaps elflink.c did some for us.  */
4505
4604
          if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4506
4605
            sym->st_shndx = SHN_UNDEF;
4507
4606
        }
4871
4970
/* Stuff for the BFD linker: */
4872
4971
#define bfd_elfNN_bfd_link_hash_table_create \
4873
4972
        elfNN_ia64_hash_table_create
 
4973
#define bfd_elfNN_bfd_link_hash_table_free \
 
4974
        elfNN_ia64_hash_table_free
4874
4975
#define elf_backend_create_dynamic_sections \
4875
4976
        elfNN_ia64_create_dynamic_sections
4876
4977
#define elf_backend_check_relocs \
4899
5000
#define elf_backend_want_plt_sym        0
4900
5001
#define elf_backend_plt_alignment       5
4901
5002
#define elf_backend_got_header_size     0
4902
 
#define elf_backend_plt_header_size     PLT_HEADER_SIZE
4903
5003
#define elf_backend_want_got_plt        1
4904
5004
#define elf_backend_may_use_rel_p       1
4905
5005
#define elf_backend_may_use_rela_p      1