* readelf.c (get_machine_flags): Add detection of EF_MIPS_32BITMODE.
[binutils-gdb.git] / bfd / elfxx-ia64.c
index f0f64f654412425af84d3a28b1ac4803d499a91c..027361071693fcbc359cac5493e0eb852957382b 100644 (file)
@@ -138,6 +138,7 @@ struct elfNN_ia64_link_hash_table
   asection *rel_pltoff_sec;    /* dynamic relocation section for same */
 
   bfd_size_type minplt_entries;        /* number of minplt entries */
+  unsigned reltext : 1;                /* are there relocs against readonly sections? */
 
   struct elfNN_ia64_local_hash_table loc_hash_table;
 };
@@ -161,6 +162,8 @@ static boolean is_unwind_section_name
   PARAMS ((const char *));
 static boolean elfNN_ia64_section_from_shdr
   PARAMS ((bfd *, ElfNN_Internal_Shdr *, char *));
+static boolean elfNN_ia64_section_flags
+  PARAMS ((flagword *, ElfNN_Internal_Shdr *));
 static boolean elfNN_ia64_fake_sections
   PARAMS ((bfd *abfd, ElfNN_Internal_Shdr *hdr, asection *sec));
 static void elfNN_ia64_final_write_processing
@@ -179,6 +182,8 @@ static boolean elfNN_ia64_aix_link_add_symbols
   PARAMS ((bfd *abfd, struct bfd_link_info *info));
 static int elfNN_ia64_additional_program_headers
   PARAMS ((bfd *abfd));
+static boolean elfNN_ia64_modify_segment_map
+  PARAMS ((bfd *));
 static boolean elfNN_ia64_is_local_label_name
   PARAMS ((bfd *abfd, const char *name));
 static boolean elfNN_ia64_dynamic_symbol_p
@@ -192,11 +197,19 @@ static struct bfd_hash_entry *elfNN_ia64_new_loc_hash_entry
 static struct bfd_hash_entry *elfNN_ia64_new_elf_hash_entry
   PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
           const char *string));
+static void elfNN_ia64_hash_copy_indirect
+  PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
+static void elfNN_ia64_hash_hide_symbol
+  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
 static struct bfd_link_hash_table *elfNN_ia64_hash_table_create
   PARAMS ((bfd *abfd));
 static struct elfNN_ia64_local_hash_entry *elfNN_ia64_local_hash_lookup
   PARAMS ((struct elfNN_ia64_local_hash_table *table, const char *string,
           boolean create, boolean copy));
+static boolean elfNN_ia64_global_dyn_sym_thunk
+  PARAMS ((struct bfd_hash_entry *, PTR));
+static boolean elfNN_ia64_local_dyn_sym_thunk
+  PARAMS ((struct bfd_hash_entry *, PTR));
 static void elfNN_ia64_dyn_sym_traverse
   PARAMS ((struct elfNN_ia64_link_hash_table *ia64_info,
           boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR),
@@ -265,6 +278,8 @@ static bfd_vma set_pltoff_entry
   PARAMS ((bfd *abfd, struct bfd_link_info *info,
           struct elfNN_ia64_dyn_sym_info *dyn_i,
           bfd_vma value, boolean));
+static int elfNN_ia64_unwind_entry_compare
+  PARAMS ((const PTR, const PTR));
 static boolean elfNN_ia64_final_link
   PARAMS ((bfd *abfd, struct bfd_link_info *info));
 static boolean elfNN_ia64_relocate_section
@@ -285,6 +300,8 @@ static boolean elfNN_ia64_merge_private_bfd_data
   PARAMS ((bfd *ibfd, bfd *obfd));
 static boolean elfNN_ia64_print_private_bfd_data
   PARAMS ((bfd *abfd, PTR ptr));
+static enum elf_reloc_type_class elfNN_ia64_reloc_type_class
+  PARAMS ((int));
 \f
 /* ia64-specific relocation */
 
@@ -360,6 +377,8 @@ static reloc_howto_type ia64_howto_table[] =
 
     IA64_HOWTO (R_IA64_LTOFF_FPTR22, "LTOFF_FPTR22", 0, false, true),
     IA64_HOWTO (R_IA64_LTOFF_FPTR64I, "LTOFF_FPTR64I", 0, false, true),
+    IA64_HOWTO (R_IA64_LTOFF_FPTR32MSB, "LTOFF_FPTR32MSB", 2, false, true),
+    IA64_HOWTO (R_IA64_LTOFF_FPTR32LSB, "LTOFF_FPTR32LSB", 2, false, true),
     IA64_HOWTO (R_IA64_LTOFF_FPTR64MSB, "LTOFF_FPTR64MSB", 4, false, true),
     IA64_HOWTO (R_IA64_LTOFF_FPTR64LSB, "LTOFF_FPTR64LSB", 4, false, true),
 
@@ -480,6 +499,8 @@ elfNN_ia64_reloc_type_lookup (abfd, bfd_code)
 
     case BFD_RELOC_IA64_LTOFF_FPTR22:  rtype = R_IA64_LTOFF_FPTR22; break;
     case BFD_RELOC_IA64_LTOFF_FPTR64I: rtype = R_IA64_LTOFF_FPTR64I; break;
+    case BFD_RELOC_IA64_LTOFF_FPTR32MSB: rtype = R_IA64_LTOFF_FPTR32MSB; break;
+    case BFD_RELOC_IA64_LTOFF_FPTR32LSB: rtype = R_IA64_LTOFF_FPTR32LSB; break;
     case BFD_RELOC_IA64_LTOFF_FPTR64MSB: rtype = R_IA64_LTOFF_FPTR64MSB; break;
     case BFD_RELOC_IA64_LTOFF_FPTR64LSB: rtype = R_IA64_LTOFF_FPTR64LSB; break;
 
@@ -1112,7 +1133,7 @@ elfNN_ia64_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
 {
   if (sym->st_shndx == SHN_COMMON
       && !info->relocateable
-      && sym->st_size <= (unsigned) bfd_get_gp_size (abfd))
+      && sym->st_size <= elf_gp_size (abfd))
     {
       /* Common symbols less than or equal to -G nn bytes are
         automatically put into .sbss.  */
@@ -1161,10 +1182,9 @@ elfNN_ia64_aix_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
 {
   if (strcmp (*namep, "__GLOB_DATA_PTR") == 0)
     {
-      /* Define __GLOB_DATA_PTR.  This is expected to be a linker-defined
-        symbol by the Aix C runtime startup code.  Define the symbol
-        when it is encountered.  IBM sez no one else should use it b/c it is
-        undocumented.  */
+      /* Define __GLOB_DATA_PTR when it is encountered.  This is expected to
+        be a linker-defined symbol by the Aix C runtime startup code. IBM sez
+        no one else should use it b/c it is undocumented.  */
       struct elf_link_hash_entry *h;
 
       h = (struct elf_link_hash_entry *) bfd_link_hash_lookup (info->hash, *namep, false, false, false);
@@ -1177,7 +1197,8 @@ elfNN_ia64_aix_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
          ia64_info = elfNN_ia64_hash_table (info);
          
          if (!(_bfd_generic_link_add_one_symbol
-               (info, abfd, *namep, BSF_GLOBAL, ia64_info->got_sec,
+               (info, abfd, *namep, BSF_GLOBAL, 
+                bfd_get_section_by_name (abfd, ".bss"),
                 bed->got_symbol_offset, (const char *) NULL, false,
                 bed->collect, (struct bfd_link_hash_entry **) &h)))
            return false;
@@ -1185,8 +1206,7 @@ elfNN_ia64_aix_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
          h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
          h->type = STT_OBJECT;
          
-         if (info->shared
-             && ! _bfd_elf_link_record_dynamic_symbol (info, h))
+         if (! _bfd_elf_link_record_dynamic_symbol (info, h))
            return false;
        }
 
@@ -1198,9 +1218,8 @@ elfNN_ia64_aix_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
       
       /* SHN_AIX_SYSCALL: Treat this as any other symbol.  The special symbol
         is only relevant when compiling code for extended system calls.
-        Replace the "special" section with .text, if possible. */
-      /* FIXME need to determine the proper section instead of defaulting to
-        .text.  */
+        Replace the "special" section with .text, if possible. 
+        Note that these symbols are always assumed to be in .text. */
       for (i = 1; i < elf_elfheader (abfd)->e_shnum; i++)
        {
          asection * sec = bfd_section_from_elf_index (abfd, i);
@@ -1555,7 +1574,7 @@ elfNN_ia64_hash_table_create (abfd)
 {
   struct elfNN_ia64_link_hash_table *ret;
 
-  ret = bfd_alloc (abfd, sizeof (*ret));
+  ret = bfd_zalloc (abfd, sizeof (*ret));
   if (!ret)
     return 0;
   if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
@@ -1721,7 +1740,8 @@ get_dyn_sym_info (ia64_info, h, abfd, rel, create)
       len += 10;       /* %p slop */
 
       addr_name = alloca (len);
-      sprintf (addr_name, "%p:%lx", (void *) abfd, ELFNN_R_SYM (rel->r_info));
+      sprintf (addr_name, "%p:%lx",
+              (void *) abfd, (unsigned long) ELFNN_R_SYM (rel->r_info));
 
       /* Collect the canonical entry data for this address.  */
       loc_h = elfNN_ia64_local_hash_lookup (&ia64_info->loc_hash_table,
@@ -1899,6 +1919,9 @@ get_reloc_section (abfd, ia64_info, sec, create)
        return NULL;
     }
 
+  if (sec->flags & SEC_READONLY)
+    ia64_info->reltext = 1;
+
   return srel;
 }
 
@@ -2009,6 +2032,8 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
 
        case R_IA64_LTOFF_FPTR22:
        case R_IA64_LTOFF_FPTR64I:
+       case R_IA64_LTOFF_FPTR32MSB:
+       case R_IA64_LTOFF_FPTR32LSB:
        case R_IA64_LTOFF_FPTR64MSB:
        case R_IA64_LTOFF_FPTR64LSB:
          need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR;
@@ -2019,9 +2044,7 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
        case R_IA64_FPTR32LSB:
        case R_IA64_FPTR64MSB:
        case R_IA64_FPTR64LSB:
-         if (elfNN_ia64_aix_vec (abfd->xvec))
-           need_entry = NEED_FPTR | NEED_DYNREL;
-         else if (info->shared || h)
+         if (info->shared || h || elfNN_ia64_aix_vec (abfd->xvec))
            need_entry = NEED_FPTR | NEED_DYNREL;
          else
            need_entry = NEED_FPTR;
@@ -2071,10 +2094,8 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
        case R_IA64_DIR64LSB:
          /* Shared objects will always need at least a REL relocation.  */
          if (info->shared || maybe_dynamic
-             /* On AIX, we always need a relocation, but make sure
-                __GLOB_DATA_PTR doesn't get an entry.  */ 
              || (elfNN_ia64_aix_vec (abfd->xvec)
-                 && (!h || strcmp (h->root.root.string, 
+                 && (!h || strcmp (h->root.root.string,
                                    "__GLOB_DATA_PTR") != 0)))
            need_entry = NEED_DYNREL;
          dynrel_type = R_IA64_DIR64LSB;
@@ -2198,7 +2219,9 @@ allocate_global_data_got (dyn_i, data)
   if (dyn_i->want_got
       && ! dyn_i->want_fptr
       && (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info)
-         || elfNN_ia64_aix_vec (x->info->hash->creator)))
+         || (elfNN_ia64_aix_vec (x->info->hash->creator)
+             && (!dyn_i->h || strcmp (dyn_i->h->root.root.string,
+                                      "__GLOB_DATA_PTR") != 0))))
      {
        dyn_i->got_offset = x->ofs;
        x->ofs += 8;
@@ -2412,7 +2435,10 @@ allocate_dynrel_entries (dyn_i, data)
 
   ia64_info = elfNN_ia64_hash_table (x->info);
   dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info)
-    || elfNN_ia64_aix_vec (x->info->hash->creator);
+    || (elfNN_ia64_aix_vec (x->info->hash->creator)
+       /* Don't allocate an entry for __GLOB_DATA_PTR */
+       && (!dyn_i->h || strcmp (dyn_i->h->root.root.string,
+         "__GLOB_DATA_PTR") != 0));
   shared = x->info->shared;
 
   /* Take care of the normal data relocations.  */
@@ -2515,7 +2541,6 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
   struct elfNN_ia64_link_hash_table *ia64_info;
   asection *sec;
   bfd *dynobj;
-  boolean reltext = false;
   boolean relplt = false;
 
   dynobj = elf_hash_table(info)->dynobj;
@@ -2672,24 +2697,6 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
            {
              if (!strip)
                {
-                 const char *outname;
-                 asection *target;
-
-                 /* If this relocation section applies to a read only
-                    section, then we probably need a DT_TEXTREL entry.  */
-                 outname = bfd_get_section_name (output_bfd,
-                                                 sec->output_section);
-                 if (outname[4] == 'a')
-                   outname += 5;
-                 else
-                   outname += 4;
-
-                 target = bfd_get_section_by_name (output_bfd, outname);
-                 if (target != NULL
-                     && (target->flags & SEC_READONLY) != 0
-                     && (target->flags & SEC_ALLOC) != 0)
-                   reltext = true;
-
                  /* We use the reloc_count field as a counter if we need to
                     copy relocs into the output file.  */
                  sec->reloc_count = 0;
@@ -2743,7 +2750,7 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
                                            sizeof (ElfNN_External_Rela)))
        return false;
 
-      if (reltext)
+      if (ia64_info->reltext)
        {
          if (! bfd_elfNN_add_dynamic_entry (info, DT_TEXTREL, 0))
            return false;
@@ -2815,6 +2822,7 @@ elfNN_ia64_install_value (abfd, hit_addr, val, r_type)
     case R_IA64_GPREL32MSB:
     case R_IA64_FPTR32MSB:
     case R_IA64_PCREL32MSB:
+    case R_IA64_LTOFF_FPTR32MSB:
     case R_IA64_SEGREL32MSB:
     case R_IA64_SECREL32MSB:
     case R_IA64_LTV32MSB:
@@ -2825,6 +2833,7 @@ elfNN_ia64_install_value (abfd, hit_addr, val, r_type)
     case R_IA64_GPREL32LSB:
     case R_IA64_FPTR32LSB:
     case R_IA64_PCREL32LSB:
+    case R_IA64_LTOFF_FPTR32LSB:
     case R_IA64_SEGREL32LSB:
     case R_IA64_SECREL32LSB:
     case R_IA64_LTV32LSB:
@@ -3181,8 +3190,8 @@ static bfd *elfNN_ia64_unwind_entry_compare_bfd;
 
 static int
 elfNN_ia64_unwind_entry_compare (a, b)
-     PTR a;
-     PTR b;
+     const PTR a;
+     const PTR b;
 {
   bfd_vma av, bv;
 
@@ -3528,11 +3537,9 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
          /* Install a dynamic relocation for this reloc.  */
          if ((dynamic_symbol_p || info->shared
               || (elfNN_ia64_aix_vec (info->hash->creator)
-                  /* We want REL relocation for _GLOB_DATA_PTR, which would
-                     otherwise be an IMM64, which isn't handled below.  The
-                     symbol comes from the C runtime.  */
-                  && (!h || 
-                      strcmp (h->root.root.string, "__GLOB_DATA_PTR") != 0)))
+                  /* Don't emit relocs for __GLOB_DATA_PTR on AIX. */
+                  && (!h || strcmp (h->root.root.string, 
+                                    "__GLOB_DATA_PTR") != 0)))
              && (input_section->flags & SEC_ALLOC) != 0)
            {
              unsigned int dyn_r_type;
@@ -3681,6 +3688,8 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
 
        case R_IA64_LTOFF_FPTR22:
        case R_IA64_LTOFF_FPTR64I:
+       case R_IA64_LTOFF_FPTR32MSB:
+       case R_IA64_LTOFF_FPTR32LSB:
        case R_IA64_LTOFF_FPTR64MSB:
        case R_IA64_LTOFF_FPTR64LSB:
          {
@@ -4302,6 +4311,27 @@ elfNN_ia64_print_private_bfd_data (abfd, ptr)
   _bfd_elf_print_private_bfd_data (abfd, ptr);
   return true;
 }
+
+static enum elf_reloc_type_class
+elfNN_ia64_reloc_type_class (type)
+     int type;
+{
+  switch (type)
+    {
+    case R_IA64_REL32MSB:
+    case R_IA64_REL32LSB:
+    case R_IA64_REL64MSB:
+    case R_IA64_REL64LSB:
+      return reloc_class_relative;
+    case R_IA64_IPLTMSB:
+    case R_IA64_IPLTLSB:
+      return reloc_class_plt;
+    case R_IA64_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
 \f
 #define TARGET_LITTLE_SYM              bfd_elfNN_ia64_little_vec
 #define TARGET_LITTLE_NAME             "elfNN-ia64-little"
@@ -4378,6 +4408,7 @@ elfNN_ia64_print_private_bfd_data (abfd, ptr)
 #define elf_backend_want_dynbss                0
 #define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect
 #define elf_backend_hide_symbol                elfNN_ia64_hash_hide_symbol
+#define elf_backend_reloc_type_class   elfNN_ia64_reloc_type_class
 
 #include "elfNN-target.h"