bfd/
[deliverable/binutils-gdb.git] / bfd / elf64-alpha.c
index 095e94a634d2dc9c7948b3c0c946341523185d31..60deadb8dd5d4805446fff042fa93d6c7bc568c8 100644 (file)
@@ -112,14 +112,15 @@ struct alpha_elf_link_hash_entry
   int flags;
 
   /* Contexts in which a literal was referenced.  */
-#define ALPHA_ELF_LINK_HASH_LU_ADDR    0x01
-#define ALPHA_ELF_LINK_HASH_LU_MEM     0x02
-#define ALPHA_ELF_LINK_HASH_LU_BYTE    0x04
-#define ALPHA_ELF_LINK_HASH_LU_JSR     0x08
-#define ALPHA_ELF_LINK_HASH_LU_TLSGD   0x10
-#define ALPHA_ELF_LINK_HASH_LU_TLSLDM  0x20
-#define ALPHA_ELF_LINK_HASH_LU_FUNC    0x38
-#define ALPHA_ELF_LINK_HASH_TLS_IE     0x40
+#define ALPHA_ELF_LINK_HASH_LU_ADDR     0x01
+#define ALPHA_ELF_LINK_HASH_LU_MEM      0x02
+#define ALPHA_ELF_LINK_HASH_LU_BYTE     0x04
+#define ALPHA_ELF_LINK_HASH_LU_JSR      0x08
+#define ALPHA_ELF_LINK_HASH_LU_TLSGD    0x10
+#define ALPHA_ELF_LINK_HASH_LU_TLSLDM   0x20
+#define ALPHA_ELF_LINK_HASH_LU_JSRDIRECT 0x40
+#define ALPHA_ELF_LINK_HASH_LU_PLT      0x38
+#define ALPHA_ELF_LINK_HASH_TLS_IE      0x80
 
   /* Used to implement multiple .got subsections.  */
   struct alpha_elf_got_entry
@@ -1203,26 +1204,23 @@ static bfd_boolean
 elf64_alpha_create_got_section (bfd *abfd,
                                struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
+  flagword flags;
   asection *s;
 
-  if ((s = bfd_get_section_by_name (abfd, ".got")))
-    {
-      /* Check for a non-linker created .got?  */
-      if (alpha_elf_tdata (abfd)->got == NULL)
-       alpha_elf_tdata (abfd)->got = s;
-      return TRUE;
-    }
-
-  s = bfd_make_section_with_flags (abfd, ".got", (SEC_ALLOC | SEC_LOAD
-                                                 | SEC_HAS_CONTENTS
-                                                 | SEC_IN_MEMORY
-                                                 | SEC_LINKER_CREATED));
+  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
+          | SEC_LINKER_CREATED);
+  s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
   if (s == NULL
       || !bfd_set_section_alignment (abfd, s, 3))
     return FALSE;
 
   alpha_elf_tdata (abfd)->got = s;
 
+  /* Make sure the object's gotobj is set to itself so that we default
+     to every object with its own .got.  We'll merge .gots later once
+     we've collected each object's info.  */
+  alpha_elf_tdata (abfd)->gotobj = abfd;
+
   return TRUE;
 }
 
@@ -1232,49 +1230,36 @@ static bfd_boolean
 elf64_alpha_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
 {
   asection *s;
+  flagword flags;
   struct elf_link_hash_entry *h;
-  struct bfd_link_hash_entry *bh;
 
   /* We need to create .plt, .rela.plt, .got, and .rela.got sections.  */
 
-  s = bfd_make_section_with_flags (abfd, ".plt",
-                                  (SEC_ALLOC | SEC_LOAD | SEC_CODE
-                                   | SEC_HAS_CONTENTS
-                                   | SEC_IN_MEMORY
-                                   | SEC_LINKER_CREATED
-                                   | (elf64_alpha_use_secureplt
-                                      ? SEC_READONLY : 0)));
+  flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY
+          | SEC_LINKER_CREATED
+          | (elf64_alpha_use_secureplt ? SEC_READONLY : 0));
+  s = bfd_make_section_anyway_with_flags (abfd, ".plt", flags);
   if (s == NULL || ! bfd_set_section_alignment (abfd, s, 4))
     return FALSE;
 
   /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
      .plt section.  */
-  bh = NULL;
-  if (! (_bfd_generic_link_add_one_symbol
-        (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
-         (bfd_vma) 0, (const char *) NULL, FALSE,
-         get_elf_backend_data (abfd)->collect, &bh)))
-    return FALSE;
-  h = (struct elf_link_hash_entry *) bh;
-  h->def_regular = 1;
-  h->type = STT_OBJECT;
-
-  if (info->shared && ! bfd_elf_link_record_dynamic_symbol (info, h))
+  h = _bfd_elf_define_linkage_sym (abfd, info, s,
+                                  "_PROCEDURE_LINKAGE_TABLE_");
+  elf_hash_table (info)->hplt = h;
+  if (h == NULL)
     return FALSE;
 
-  s = bfd_make_section_with_flags (abfd, ".rela.plt",
-                                  (SEC_ALLOC | SEC_LOAD
-                                   | SEC_HAS_CONTENTS
-                                   | SEC_IN_MEMORY
-                                   | SEC_LINKER_CREATED
-                                   | SEC_READONLY));
+  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
+          | SEC_LINKER_CREATED | SEC_READONLY);
+  s = bfd_make_section_anyway_with_flags (abfd, ".rela.plt", flags);
   if (s == NULL || ! bfd_set_section_alignment (abfd, s, 3))
     return FALSE;
 
   if (elf64_alpha_use_secureplt)
     {
-      s = bfd_make_section_with_flags (abfd, ".got.plt",
-                                      SEC_ALLOC | SEC_LINKER_CREATED);
+      flags = SEC_ALLOC | SEC_LINKER_CREATED;
+      s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
       if (s == NULL || ! bfd_set_section_alignment (abfd, s, 3))
        return FALSE;
     }
@@ -1282,15 +1267,15 @@ elf64_alpha_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
   /* We may or may not have created a .got section for this object, but
      we definitely havn't done the rest of the work.  */
 
-  if (!elf64_alpha_create_got_section (abfd, info))
-    return FALSE;
+  if (alpha_elf_tdata(abfd)->gotobj == NULL)
+    {
+      if (!elf64_alpha_create_got_section (abfd, info))
+       return FALSE;
+    }
 
-  s = bfd_make_section_with_flags (abfd, ".rela.got",
-                                  (SEC_ALLOC | SEC_LOAD
-                                   | SEC_HAS_CONTENTS
-                                   | SEC_IN_MEMORY
-                                   | SEC_LINKER_CREATED
-                                   | SEC_READONLY));
+  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
+          | SEC_LINKER_CREATED | SEC_READONLY);
+  s = bfd_make_section_anyway_with_flags (abfd, ".rela.got", flags);
   if (s == NULL
       || !bfd_set_section_alignment (abfd, s, 3))
     return FALSE;
@@ -1299,21 +1284,11 @@ elf64_alpha_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
      dynobj's .got section.  We don't do this in the linker script
      because we don't want to define the symbol if we are not creating
      a global offset table.  */
-  bh = NULL;
-  if (!(_bfd_generic_link_add_one_symbol
-       (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL,
-        alpha_elf_tdata(abfd)->got, (bfd_vma) 0, (const char *) NULL,
-        FALSE, get_elf_backend_data (abfd)->collect, &bh)))
-    return FALSE;
-  h = (struct elf_link_hash_entry *) bh;
-  h->def_regular = 1;
-  h->type = STT_OBJECT;
-
-  if (info->shared
-      && ! bfd_elf_link_record_dynamic_symbol (info, h))
-    return FALSE;
-
+  h = _bfd_elf_define_linkage_sym (abfd, info, alpha_elf_tdata(abfd)->got,
+                                  "_GLOBAL_OFFSET_TABLE_");
   elf_hash_table (info)->hgot = h;
+  if (h == NULL)
+    return FALSE;
 
   return TRUE;
 }
@@ -1729,8 +1704,8 @@ elf64_alpha_want_plt (struct alpha_elf_link_hash_entry *ah)
   return ((ah->root.type == STT_FUNC
          || ah->root.root.type == bfd_link_hash_undefweak
          || ah->root.root.type == bfd_link_hash_undefined)
-         && (ah->flags & ALPHA_ELF_LINK_HASH_LU_FUNC) != 0
-         && (ah->flags & ~ALPHA_ELF_LINK_HASH_LU_FUNC) == 0);
+         && (ah->flags & ALPHA_ELF_LINK_HASH_LU_PLT) != 0
+         && (ah->flags & ~ALPHA_ELF_LINK_HASH_LU_PLT) == 0);
 }
 
 /* Handle dynamic relocations when doing an Alpha ELF link.  */
@@ -1745,7 +1720,6 @@ elf64_alpha_check_relocs (bfd *abfd, struct bfd_link_info *info,
   Elf_Internal_Shdr *symtab_hdr;
   struct alpha_elf_link_hash_entry **sym_hashes;
   const Elf_Internal_Rela *rel, *relend;
-  bfd_boolean got_created;
   bfd_size_type amt;
 
   if (info->relocatable)
@@ -1768,7 +1742,6 @@ elf64_alpha_check_relocs (bfd *abfd, struct bfd_link_info *info,
   rel_sec_name = NULL;
   symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
   sym_hashes = alpha_elf_sym_hashes(abfd);
-  got_created = FALSE;
 
   relend = relocs + sec->reloc_count;
   for (rel = relocs; rel < relend; ++rel)
@@ -1826,7 +1799,7 @@ elf64_alpha_check_relocs (bfd *abfd, struct bfd_link_info *info,
             This will be important when it comes to decide if we can
             create a .plt entry for a function symbol.  */
          while (++rel < relend && ELF64_R_TYPE (rel->r_info) == R_ALPHA_LITUSE)
-           if (rel->r_addend >= 1 && rel->r_addend <= 5)
+           if (rel->r_addend >= 1 && rel->r_addend <= 6)
              gotent_flags |= 1 << rel->r_addend;
          --rel;
 
@@ -1880,18 +1853,10 @@ elf64_alpha_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
       if (need & NEED_GOT)
        {
-         if (!got_created)
+         if (alpha_elf_tdata(abfd)->gotobj == NULL)
            {
              if (!elf64_alpha_create_got_section (abfd, info))
                return FALSE;
-
-             /* Make sure the object's gotobj is set to itself so
-                that we default to every object with its own .got.
-                We'll merge .gots later once we've collected each
-                object's info.  */
-             alpha_elf_tdata(abfd)->gotobj = abfd;
-
-             got_created = 1;
            }
        }
 
@@ -2784,7 +2749,6 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
-      bfd_boolean strip;
 
       if (!(s->flags & SEC_LINKER_CREATED))
        continue;
@@ -2793,23 +2757,11 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
         of the dynobj section names depend upon the input files.  */
       name = bfd_get_section_name (dynobj, s);
 
-      /* If we don't need this section, strip it from the output file.
-        This is to handle .rela.bss and .rela.plt.  We must create it
-        in create_dynamic_sections, because it must be created before
-        the linker maps input sections to output sections.  The
-        linker does that before adjust_dynamic_symbol is called, and
-        it is that function which decides whether anything needs to
-        go into these sections.  */
-
-      strip = FALSE;
-
       if (strncmp (name, ".rela", 5) == 0)
        {
-         strip = (s->size == 0);
-
-         if (!strip)
+         if (s->size != 0)
            {
-             if (strcmp(name, ".rela.plt") == 0)
+             if (strcmp (name, ".rela.plt") == 0)
                relplt = TRUE;
 
              /* We use the reloc_count field as a counter if we need
@@ -2817,19 +2769,30 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
              s->reloc_count = 0;
            }
        }
-      else if (strcmp (name, ".plt") != 0)
+      else if (strncmp (name, ".got", 4) != 0
+              && strcmp (name, ".plt") != 0
+              && strcmp (name, ".dynbss") != 0)
        {
          /* It's not one of our dynamic sections, so don't allocate space.  */
          continue;
        }
 
-      if (strip)
-       s->flags |= SEC_EXCLUDE;
-      else
+      if (s->size == 0)
+       {
+         /* If we don't need this section, strip it from the output file.
+            This is to handle .rela.bss and .rela.plt.  We must create it
+            in create_dynamic_sections, because it must be created before
+            the linker maps input sections to output sections.  The
+            linker does that before adjust_dynamic_symbol is called, and
+            it is that function which decides whether anything needs to
+            go into these sections.  */
+         s->flags |= SEC_EXCLUDE;
+       }
+      else if ((s->flags & SEC_HAS_CONTENTS) != 0)
        {
          /* Allocate memory for the section contents.  */
          s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
-         if (s->contents == NULL && s->size != 0)
+         if (s->contents == NULL)
            return FALSE;
        }
     }
@@ -3137,7 +3100,7 @@ elf64_alpha_relax_with_lituse (struct alpha_relax_info *info,
     {
       if (ELF64_R_TYPE (urel->r_info) != R_ALPHA_LITUSE)
        break;
-      if (urel->r_addend <= 3)
+      if (urel->r_addend <= 6)
        flags |= 1 << urel->r_addend;
     }
 
@@ -3232,6 +3195,7 @@ elf64_alpha_relax_with_lituse (struct alpha_relax_info *info,
        case LITUSE_ALPHA_JSR:
        case LITUSE_ALPHA_TLSGD:
        case LITUSE_ALPHA_TLSLDM:
+       case LITUSE_ALPHA_JSRDIRECT:
          {
            bfd_vma optdest, org;
            bfd_signed_vma odisp;
@@ -4753,8 +4717,8 @@ elf64_alpha_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
 
   /* Mark some specially defined symbols as absolute.  */
   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
-      || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
-      || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
+      || h == elf_hash_table (info)->hgot
+      || h == elf_hash_table (info)->hplt)
     sym->st_shndx = SHN_ABS;
 
   return TRUE;
@@ -5178,46 +5142,13 @@ elf64_alpha_reloc_type_class (const Elf_Internal_Rela *rela)
     }
 }
 \f
-static struct bfd_elf_special_section const
-  alpha_special_sections_s[]=
+static const struct bfd_elf_special_section elf64_alpha_special_sections[] =
 {
-  { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL },
   { ".sbss",  5, -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL },
+  { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL },
   { NULL,     0,  0, 0,            0 }
 };
 
-static struct bfd_elf_special_section const *
-  elf64_alpha_special_sections[27] =
-{
-  NULL,                                /* 'a' */
-  NULL,                                /* 'b' */
-  NULL,                                /* 'c' */
-  NULL,                                /* 'd' */
-  NULL,                                /* 'e' */
-  NULL,                                /* 'f' */
-  NULL,                                /* 'g' */
-  NULL,                                /* 'h' */
-  NULL,                                /* 'i' */
-  NULL,                                /* 'j' */
-  NULL,                                /* 'k' */
-  NULL,                                /* 'l' */
-  NULL,                                /* 'm' */
-  NULL,                                /* 'n' */
-  NULL,                                /* 'o' */
-  NULL,                                /* 'p' */
-  NULL,                                /* 'q' */
-  NULL,                                /* 'r' */
-  alpha_special_sections_s,    /* 's' */
-  NULL,                                /* 't' */
-  NULL,                                /* 'u' */
-  NULL,                                /* 'v' */
-  NULL,                                /* 'w' */
-  NULL,                                /* 'x' */
-  NULL,                                /* 'y' */
-  NULL,                                /* 'z' */
-  NULL                         /* other */
-};
-
 /* ECOFF swapping routines.  These are used when dealing with the
    .mdebug section, which is in the ECOFF debugging format.  Copied
    from elf32-mips.c.  */
This page took 0.029082 seconds and 4 git commands to generate.