gdb/:
[deliverable/binutils-gdb.git] / bfd / elfxx-ia64.c
index 32dea4c6149629dc5b8eb9c09eb2c3a1264847cc..c25294c0fddc5b599f4c6044eb072f4618edf902 100644 (file)
@@ -1,5 +1,5 @@
 /* IA-64 support for 64-bit ELF
-   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
    Free Software Foundation, Inc.
    Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
 
@@ -7,7 +7,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
-#include "bfd.h"
 #include "sysdep.h"
+#include "bfd.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
 #include "opcode/ia64.h"
@@ -613,6 +614,22 @@ elfNN_ia64_reloc_type_lookup (abfd, bfd_code)
   return lookup_howto (rtype);
 }
 
+static reloc_howto_type *
+elfNN_ia64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+                             const char *r_name)
+{
+  unsigned int i;
+
+  for (i = 0;
+       i < sizeof (ia64_howto_table) / sizeof (ia64_howto_table[0]);
+       i++)
+    if (ia64_howto_table[i].name != NULL
+       && strcasecmp (ia64_howto_table[i].name, r_name) == 0)
+      return &ia64_howto_table[i];
+
+  return NULL;
+}
+
 /* Given a ELF reloc, return the matching HOWTO structure.  */
 
 static void
@@ -1424,22 +1441,15 @@ elfNN_ia64_relax_ldxmov (contents, off)
 /* Return TRUE if NAME is an unwind table section name.  */
 
 static inline bfd_boolean
-is_unwind_section_name (abfd, name)
-       bfd *abfd;
-       const char *name;
+is_unwind_section_name (bfd *abfd, const char *name)
 {
-  size_t len1, len2, len3;
-
   if (elfNN_ia64_hpux_vec (abfd->xvec)
       && !strcmp (name, ELF_STRING_ia64_unwind_hdr))
     return FALSE;
 
-  len1 = sizeof (ELF_STRING_ia64_unwind) - 1;
-  len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
-  len3 = sizeof (ELF_STRING_ia64_unwind_once) - 1;
-  return ((strncmp (name, ELF_STRING_ia64_unwind, len1) == 0
-          && strncmp (name, ELF_STRING_ia64_unwind_info, len2) != 0)
-         || strncmp (name, ELF_STRING_ia64_unwind_once, len3) == 0);
+  return ((CONST_STRNEQ (name, ELF_STRING_ia64_unwind)
+          && ! CONST_STRNEQ (name, ELF_STRING_ia64_unwind_info))
+         || CONST_STRNEQ (name, ELF_STRING_ia64_unwind_once));
 }
 
 /* Handle an IA-64 specific section when reading an object file.  This
@@ -2216,7 +2226,7 @@ addend_compare (const void *xp, const void *yp)
   const struct elfNN_ia64_dyn_sym_info *y
     = (const struct elfNN_ia64_dyn_sym_info *) yp;
 
-  return x->addend - y->addend;
+  return x->addend < y->addend ? -1 : x->addend > y->addend ? 1 : 0;
 }
 
 /* Sort elfNN_ia64_dyn_sym_info array and remove duplicates.  */
@@ -2225,37 +2235,62 @@ static unsigned int
 sort_dyn_sym_info (struct elfNN_ia64_dyn_sym_info *info,
                   unsigned int count)
 {
-  bfd_vma curr, prev;
-  unsigned int i, dup, diff, dest, src, len;
+  bfd_vma curr, prev, got_offset;
+  unsigned int i, kept, dup, diff, dest, src, len;
 
   qsort (info, count, sizeof (*info), addend_compare);
 
   /* Find the first duplicate.  */
   prev = info [0].addend;
+  got_offset = info [0].got_offset;
   for (i = 1; i < count; i++)
     {
       curr = info [i].addend;
       if (curr == prev)
-       break;
+       {
+         /* For duplicates, make sure that GOT_OFFSET is valid.  */
+         if (got_offset == (bfd_vma) -1)
+           got_offset = info [i].got_offset;
+         break;
+       }
+      got_offset = info [i].got_offset;
       prev = curr;
     }
 
+  /* We may move a block of elements to here.  */
+  dest = i++;
+
   /* Remove duplicates.  */
   if (i < count)
     {
-      /* We need to move a block of elements to here.  */
-      dest = i++;
       while (i < count)
        {
+         /* For duplicates, make sure that the kept one has a valid
+            got_offset.  */
+         kept = dest - 1;
+         if (got_offset != (bfd_vma) -1)
+           info [kept].got_offset = got_offset;
+
          curr = info [i].addend;
+         got_offset = info [i].got_offset;
 
          /* Move a block of elements whose first one is different from
             the previous.  */
          if (curr == prev)
            {
              for (src = i + 1; src < count; src++)
-               if (info [src].addend != curr)
-                 break;
+               {
+                 if (info [src].addend != curr)
+                   break;
+                 /* For duplicates, make sure that GOT_OFFSET is
+                    valid.  */
+                 if (got_offset == (bfd_vma) -1)
+                   got_offset = info [src].got_offset;
+               }
+
+             /* Make sure that the kept one has a valid got_offset.  */
+             if (got_offset != (bfd_vma) -1)
+               info [kept].got_offset = got_offset;
            }
          else
            src = i;
@@ -2263,13 +2298,25 @@ sort_dyn_sym_info (struct elfNN_ia64_dyn_sym_info *info,
          if (src >= count)
            break;
 
-         /* Find the next duplicate.  */
+         /* Find the next duplicate.  SRC will be kept.  */
          prev = info [src].addend;
+         got_offset = info [src].got_offset;
          for (dup = src + 1; dup < count; dup++)
            {
              curr = info [dup].addend;
              if (curr == prev)
-               break;
+               {
+                 /* Make sure that got_offset is valid.  */
+                 if (got_offset == (bfd_vma) -1)
+                   got_offset = info [dup].got_offset;
+
+                 /* For duplicates, make sure that the kept one has
+                    a valid got_offset.  */
+                 if (got_offset != (bfd_vma) -1)
+                   info [dup - 1].got_offset = got_offset;
+                 break;
+               }
+             got_offset = info [dup].got_offset;
              prev = curr;
            }
 
@@ -2280,20 +2327,41 @@ sort_dyn_sym_info (struct elfNN_ia64_dyn_sym_info *info,
          if (len == 1 && dup < count)
            {
              /* If we only move 1 element, we combine it with the next
-                one.  Find the next different one.  */
+                one.  There must be at least a duplicate.  Find the
+                next different one.  */
              for (diff = dup + 1, src++; diff < count; diff++, src++)
-               if (info [diff].addend != curr)
-                 break;
+               {
+                 if (info [diff].addend != curr)
+                   break;
+                 /* Make sure that got_offset is valid.  */
+                 if (got_offset == (bfd_vma) -1)
+                   got_offset = info [diff].got_offset;
+               }
+
+             /* Makre sure that the last duplicated one has an valid
+                offset.  */
+             BFD_ASSERT (curr == prev);
+             if (got_offset != (bfd_vma) -1)
+               info [diff - 1].got_offset = got_offset;
 
              if (diff < count)
                {
-                 /* Find the next duplicate.  */
+                 /* Find the next duplicate.  Track the current valid
+                    offset.  */
                  prev = info [diff].addend;
+                 got_offset = info [diff].got_offset;
                  for (dup = diff + 1; dup < count; dup++)
                    {
                      curr = info [dup].addend;
                      if (curr == prev)
-                       break;
+                       {
+                         /* For duplicates, make sure that GOT_OFFSET
+                            is valid.  */
+                         if (got_offset == (bfd_vma) -1)
+                           got_offset = info [dup].got_offset;
+                         break;
+                       }
+                     got_offset = info [dup].got_offset;
                      prev = curr;
                      diff++;
                    }
@@ -2310,6 +2378,19 @@ sort_dyn_sym_info (struct elfNN_ia64_dyn_sym_info *info,
 
       count = dest;
     }
+  else
+    {
+      /* When we get here, either there is no duplicate at all or
+        the only duplicate is the last element.  */
+      if (dest < count)
+       {
+         /* If the last element is a duplicate, make sure that the
+            kept one has a valid got_offset.  We also update count.  */
+         if (got_offset != (bfd_vma) -1)
+           info [dest - 1].got_offset = got_offset;
+         count = dest;
+       }
+    }
 
   return count;
 }
@@ -2432,6 +2513,7 @@ has_space:
       /* Append the new one to the array.  */
       dyn_i = info + count;
       memset (dyn_i, 0, sizeof (*dyn_i));
+      dyn_i->got_offset = (bfd_vma) -1;
       dyn_i->addend = addend;
       
       /* We increment count only since the new ones are unsorted and
@@ -2621,10 +2703,10 @@ get_reloc_section (abfd, ia64_info, sec, create)
   if (srel_name == NULL)
     return NULL;
 
-  BFD_ASSERT ((strncmp (srel_name, ".rela", 5) == 0
+  BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela")
               && strcmp (bfd_get_section_name (abfd, sec),
                          srel_name+5) == 0)
-             || (strncmp (srel_name, ".rel", 4) == 0
+             || (CONST_STRNEQ (srel_name, ".rel")
                  && strcmp (bfd_get_section_name (abfd, sec),
                             srel_name+4) == 0));
 
@@ -2741,7 +2823,7 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
         have yet been processed.  Do something with what we know, as
         this may help reduce memory usage and processing time later.  */
       maybe_dynamic = (h && ((!info->executable
-                             && (!info->symbolic
+                             && (!SYMBOLIC_BIND (info, h)
                                  || info->unresolved_syms_in_shared_libs == RM_IGNORE))
                             || !h->def_regular
                             || h->root.type == bfd_link_hash_defweak));
@@ -2913,7 +2995,7 @@ elfNN_ia64_check_relocs (abfd, info, sec, relocs)
         have yet been processed.  Do something with what we know, as
         this may help reduce memory usage and processing time later.  */
       maybe_dynamic = (h && ((!info->executable
-                             && (!info->symbolic
+                             && (!SYMBOLIC_BIND (info, h)
                                  || info->unresolved_syms_in_shared_libs == RM_IGNORE))
                             || !h->def_regular
                             || h->root.type == bfd_link_hash_defweak));
@@ -3702,7 +3784,7 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
 
          if (strcmp (name, ".got.plt") == 0)
            strip = FALSE;
-         else if (strncmp (name, ".rel", 4) == 0)
+         else if (CONST_STRNEQ (name, ".rel"))
            {
              if (!strip)
                {
@@ -4366,7 +4448,7 @@ elfNN_ia64_choose_gp (abfd, info)
        continue;
 
       lo = os->vma;
-      hi = os->vma + os->size;
+      hi = os->vma + (os->rawsize ? os->rawsize : os->size);
       if (hi < lo)
        hi = (bfd_vma) -1;
 
@@ -4564,7 +4646,6 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
 
       elf_section_data(input_section->output_section)
        ->this_hdr.sh_flags |= flags;
-      return TRUE;
     }
 
   gp_val = _bfd_get_gp_value (output_bfd);
@@ -4613,7 +4694,8 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
          sym_sec = local_sections[r_symndx];
          msec = sym_sec;
          value = _bfd_elf_rela_local_sym (output_bfd, sym, &msec, rel);
-         if ((sym_sec->flags & SEC_MERGE)
+         if (!info->relocatable
+             && (sym_sec->flags & SEC_MERGE) != 0
              && ELF_ST_TYPE (sym->st_info) == STT_SECTION
              && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
            {
@@ -4642,9 +4724,15 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
                                        - sym_sec->output_section->vma
                                        - sym_sec->output_offset;
                    }
-                 
-                 qsort (loc_h->info, loc_h->count,
-                        sizeof (*loc_h->info), addend_compare);
+
+                 /* We may have introduced duplicated entries. We need
+                    to remove them properly.  */
+                 count = sort_dyn_sym_info (loc_h->info, loc_h->count);
+                 if (count != loc_h->count)
+                   {
+                     loc_h->count = count;
+                     loc_h->sorted_count = count;
+                   }
 
                  loc_h->sec_merge_done = 1;
                }
@@ -4667,6 +4755,20 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
            continue;
        }
 
+      /* For relocs against symbols from removed linkonce sections,
+        or sections discarded by a linker script, we just want the
+        section contents zeroed.  Avoid any special processing.  */
+      if (sym_sec != NULL && elf_discarded_section (sym_sec))
+       {
+         _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+         rel->r_info = 0;
+         rel->r_addend = 0;
+         continue;
+       }
+
+      if (info->relocatable)
+       continue;
+
       hit_addr = contents + rel->r_offset;
       value += rel->r_addend;
       dynamic_symbol_p = elfNN_ia64_dynamic_symbol_p (h, info, r_type);
@@ -4998,13 +5100,6 @@ elfNN_ia64_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_IA64_SEGREL32LSB:
        case R_IA64_SEGREL64MSB:
        case R_IA64_SEGREL64LSB:
-         if (r_symndx == 0)
-           {
-             /* If the input section was discarded from the output, then
-                do nothing.  */
-             r = bfd_reloc_ok;
-           }
-         else
            {
              struct elf_segment_map *m;
              Elf_Internal_Phdr *p;
@@ -5569,9 +5664,9 @@ elfNN_ia64_reloc_type_class (rela)
 
 static const struct bfd_elf_special_section elfNN_ia64_special_sections[] =
 {
-  { ".sbss",  5, -1, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
-  { ".sdata", 6, -1, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
-  { NULL,        0, 0, 0,            0 }
+  { STRING_COMMA_LEN (".sbss"),  -1, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
+  { STRING_COMMA_LEN (".sdata"), -1, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
+  { NULL,                    0,   0, 0,            0 }
 };
 
 static bfd_boolean
@@ -5598,7 +5693,7 @@ elfNN_ia64_object_p (bfd *abfd)
       if (elf_sec_group (sec) == NULL
          && ((sec->flags & (SEC_LINK_ONCE | SEC_CODE | SEC_GROUP))
              == (SEC_LINK_ONCE | SEC_CODE))
-         && strncmp (sec->name, ".gnu.linkonce.t.", 16) == 0)
+         && CONST_STRNEQ (sec->name, ".gnu.linkonce.t."))
        {
          name = sec->name + 16;
 
@@ -5681,7 +5776,7 @@ elfNN_hpux_post_process_headers (abfd, info)
 {
   Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
 
-  i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX;
+  i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
   i_ehdrp->e_ident[EI_ABIVERSION] = 1;
 }
 
@@ -5748,6 +5843,8 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
 
 #define bfd_elfNN_bfd_reloc_type_lookup \
        elfNN_ia64_reloc_type_lookup
+#define bfd_elfNN_bfd_reloc_name_lookup \
+       elfNN_ia64_reloc_name_lookup
 #define bfd_elfNN_bfd_is_local_label_name \
        elfNN_ia64_is_local_label_name
 #define bfd_elfNN_bfd_relax_section \
@@ -5769,6 +5866,8 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
        elfNN_ia64_adjust_dynamic_symbol
 #define elf_backend_size_dynamic_sections \
        elfNN_ia64_size_dynamic_sections
+#define elf_backend_omit_section_dynsym \
+  ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
 #define elf_backend_relocate_section \
        elfNN_ia64_relocate_section
 #define elf_backend_finish_dynamic_symbol \
@@ -5800,6 +5899,7 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
 #define elf_backend_reloc_type_class   elfNN_ia64_reloc_type_class
 #define elf_backend_rela_normal                1
 #define elf_backend_special_sections   elfNN_ia64_special_sections
+#define elf_backend_default_execstack  0
 
 /* FIXME: PR 290: The Intel C compiler generates SHT_IA_64_UNWIND with
    SHF_LINK_ORDER. But it doesn't set the sh_link or sh_info fields.
@@ -5836,6 +5936,8 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
 #undef  ELF_MAXPAGESIZE
 #define ELF_MAXPAGESIZE                 0x1000  /* 4K */
 #undef ELF_COMMONPAGESIZE
+#undef ELF_OSABI
+#define ELF_OSABI                      ELFOSABI_HPUX
 
 #undef  elfNN_bed
 #define elfNN_bed elfNN_ia64_hpux_bed
This page took 0.029578 seconds and 4 git commands to generate.