* configure: Ignore new autoconf configure options.
[binutils-gdb.git] / bfd / coff-alpha.c
index 1bbfbdbed110aad8e8ad07c87a8e20cb063b5bdf..4ad7077fa621cde622440e06aa658ab71d3dd413 100644 (file)
@@ -17,7 +17,7 @@ GNU General Public License for more details.
 
 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "bfd.h"
 #include "sysdep.h"
@@ -35,6 +35,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 static const bfd_target *alpha_ecoff_object_p PARAMS ((bfd *));
 static boolean alpha_ecoff_bad_format_hook PARAMS ((bfd *abfd, PTR filehdr));
+static PTR alpha_ecoff_mkobject_hook PARAMS ((bfd *, PTR filehdr, PTR aouthdr));
 static void alpha_ecoff_swap_reloc_in PARAMS ((bfd *, PTR,
                                              struct internal_reloc *));
 static void alpha_ecoff_swap_reloc_out PARAMS ((bfd *,
@@ -54,6 +55,8 @@ static bfd_vma alpha_convert_external_reloc
 static boolean alpha_relocate_section PARAMS ((bfd *, struct bfd_link_info *,
                                               bfd *, asection *,
                                               bfd_byte *, PTR));
+static boolean alpha_adjust_headers
+  PARAMS ((bfd *, struct internal_filehdr *, struct internal_aouthdr *));
 \f
 /* ECOFF has COFF sections, but the debugging information is stored in
    a completely different format.  ECOFF targets use some of the
@@ -472,6 +475,40 @@ alpha_ecoff_bad_format_hook (abfd, filehdr)
 
   return true;
 }
+
+/* This is a hook called by coff_real_object_p to create any backend
+   specific information.  */
+
+static PTR
+alpha_ecoff_mkobject_hook (abfd, filehdr, aouthdr)
+     bfd *abfd;
+     PTR filehdr;
+     PTR aouthdr;
+{
+  PTR ecoff;
+
+  ecoff = _bfd_ecoff_mkobject_hook (abfd, filehdr, aouthdr);
+
+  if (ecoff != NULL)
+    {
+      struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
+
+      /* Set additional BFD flags according to the object type from the
+        machine specific file header flags.  */
+      switch (internal_f->f_flags & F_ALPHA_OBJECT_TYPE_MASK)
+       {
+       case F_ALPHA_SHARABLE:
+         abfd->flags |= DYNAMIC;
+         break;
+       case F_ALPHA_CALL_SHARED:
+         /* Always executable if using shared libraries as the run time
+            loader might resolve undefined references.  */
+         abfd->flags |= (DYNAMIC | EXEC_P);
+         break;
+       }
+    }
+  return ecoff;
+}
 \f
 /* Reloc handling.  */
 
@@ -516,11 +553,10 @@ alpha_ecoff_swap_reloc_in (abfd, ext_ptr, intern)
       /* The IGNORE reloc generally follows a GPDISP reloc, and is
         against the .lita section.  The section is irrelevant.  */
       if (! intern->r_extern &&
-         (intern->r_symndx == RELOC_SECTION_NONE
-          || intern->r_symndx == RELOC_SECTION_ABS))
+         intern->r_symndx == RELOC_SECTION_ABS)
        abort ();
       if (! intern->r_extern && intern->r_symndx == RELOC_SECTION_LITA)
-       intern->r_symndx = RELOC_SECTION_NONE;
+       intern->r_symndx = RELOC_SECTION_ABS;
     }
 }
 
@@ -545,7 +581,7 @@ alpha_ecoff_swap_reloc_out (abfd, intern, dst)
     }
   else if (intern->r_type == ALPHA_R_IGNORE
           && ! intern->r_extern
-          && intern->r_symndx == RELOC_SECTION_NONE)
+          && intern->r_symndx == RELOC_SECTION_ABS)
     {
       symndx = RELOC_SECTION_LITA;
       size = intern->r_size;
@@ -641,7 +677,7 @@ alpha_adjust_reloc_in (abfd, intern, rptr)
         some reason the address of this reloc type is not adjusted by
         the section vma.  We record the gp value for this object file
         here, for convenience when doing the GPDISP relocation.  */
-      rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
+      rptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
       rptr->address = intern->r_vaddr;
       rptr->addend = ecoff_data (abfd)->gp;
       break;
@@ -684,8 +720,6 @@ alpha_adjust_reloc_out (abfd, rel, intern)
 
     case ALPHA_R_IGNORE:
       intern->r_vaddr = rel->address;
-      if (intern->r_symndx == RELOC_SECTION_ABS)
-       intern->r_symndx = RELOC_SECTION_NONE;
       break;
 
     default:
@@ -725,12 +759,9 @@ alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
 
   if (reloc_size < 0)
     goto error_return;
-  reloc_vector = (arelent **) malloc (reloc_size);
+  reloc_vector = (arelent **) bfd_malloc (reloc_size);
   if (reloc_vector == NULL && reloc_size != 0)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      goto error_return;
-    }
+    goto error_return;
 
   if (! bfd_get_section_contents (input_bfd, input_section, data,
                                  (file_ptr) 0, input_section->_raw_size))
@@ -954,7 +985,7 @@ alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
            /* Figure out the relocation of this symbol.  */
            symbol = *rel->sym_ptr_ptr;
 
-           if (symbol->section == &bfd_und_section)
+           if (bfd_is_und_section (symbol->section))
              r = bfd_reloc_undefined;
 
            if (bfd_is_com_section (symbol->section))
@@ -1014,7 +1045,7 @@ alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
            /* Figure out the relocation of this symbol.  */
            symbol = *rel->sym_ptr_ptr;
 
-           if (symbol->section == &bfd_und_section)
+           if (bfd_is_und_section (symbol->section))
              r = bfd_reloc_undefined;
 
            if (bfd_is_com_section (symbol->section))
@@ -1047,7 +1078,7 @@ alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
            /* Figure out the relocation of this symbol.  */
            symbol = *rel->sym_ptr_ptr;
 
-           if (symbol->section == &bfd_und_section)
+           if (bfd_is_und_section (symbol->section))
              r = bfd_reloc_undefined;
 
            if (bfd_is_com_section (symbol->section))
@@ -1131,7 +1162,7 @@ alpha_ecoff_get_relocated_section_contents (abfd, link_info, link_order,
 
 /* Get the howto structure for a generic reloc type.  */
 
-static CONST struct reloc_howto_struct *
+static reloc_howto_type *
 alpha_bfd_reloc_type_lookup (abfd, code)
      bfd *abfd;
      bfd_reloc_code_real_type code;
@@ -1195,7 +1226,7 @@ alpha_bfd_reloc_type_lookup (abfd, code)
       break;
 #endif
     default:
-      return (CONST struct reloc_howto_struct *) NULL;
+      return (reloc_howto_type *) NULL;
     }
 
   return &alpha_howto_table[alpha_type];
@@ -1218,7 +1249,8 @@ alpha_convert_external_reloc (output_bfd, info, input_bfd, ext_rel, h)
 
   BFD_ASSERT (info->relocateable);
 
-  if (h->root.type == bfd_link_hash_defined)
+  if (h->root.type == bfd_link_hash_defined
+      || h->root.type == bfd_link_hash_defweak)
     {
       asection *hsec;
       const char *name;
@@ -1271,6 +1303,8 @@ alpha_convert_external_reloc (output_bfd, info, input_bfd, ext_rel, h)
        case 'r':
          if (strcmp (name, ".rdata") == 0)
            r_symndx = RELOC_SECTION_RDATA;
+         else if (strcmp (name, ".rconst") == 0)
+           r_symndx = RELOC_SECTION_RCONST;
          break;
        case 's':
          if (strcmp (name, ".sdata") == 0)
@@ -1350,10 +1384,7 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
                                      (NUM_RELOC_SECTIONS
                                       * sizeof (asection *))));
       if (!symndx_to_section)
-       {
-         bfd_set_error (bfd_error_no_memory);
-         return false;
-       }
+       return false;
 
       symndx_to_section[RELOC_SECTION_NONE] = NULL;
       symndx_to_section[RELOC_SECTION_TEXT] =
@@ -1382,7 +1413,9 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
        bfd_get_section_by_name (input_bfd, ".fini");
       symndx_to_section[RELOC_SECTION_LITA] =
        bfd_get_section_by_name (input_bfd, ".lita");
-      symndx_to_section[RELOC_SECTION_ABS] = &bfd_abs_section;
+      symndx_to_section[RELOC_SECTION_ABS] = bfd_abs_section_ptr;
+      symndx_to_section[RELOC_SECTION_RCONST] =
+       bfd_get_section_by_name (input_bfd, ".rconst");
 
       ecoff_data (input_bfd)->symndx_to_section = symndx_to_section;
     }
@@ -1601,7 +1634,8 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
 
              if (! info->relocateable)
                {
-                 if (h->root.type == bfd_link_hash_defined)
+                 if (h->root.type == bfd_link_hash_defined
+                     || h->root.type == bfd_link_hash_defweak)
                    addend = (h->root.u.def.value
                              + h->root.u.def.section->output_section->vma
                              + h->root.u.def.section->output_offset);
@@ -1621,6 +1655,7 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
              else
                {
                  if (h->root.type != bfd_link_hash_defined
+                     && h->root.type != bfd_link_hash_defweak
                      && h->indx == -1)
                    {
                      /* This symbol is not being written out.  Pass
@@ -1750,6 +1785,7 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
              if (r_extern)
                {
                  if (h->root.type != bfd_link_hash_defined
+                     && h->root.type != bfd_link_hash_defweak
                      && h->indx == -1)
                    {
                      /* This symbol is not being written out.  */
@@ -1798,7 +1834,8 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
              if (r_extern)
                {
                  /* This is a reloc against a symbol.  */
-                 if (h->root.type == bfd_link_hash_defined)
+                 if (h->root.type == bfd_link_hash_defined
+                     || h->root.type == bfd_link_hash_defweak)
                    {
                      asection *hsec;
 
@@ -1895,6 +1932,23 @@ alpha_relocate_section (output_bfd, info, input_bfd, input_section,
   return true;
 }
 \f
+/* Do final adjustments to the filehdr and the aouthdr.  This routine
+   sets the dynamic bits in the file header.  */
+
+/*ARGSUSED*/
+static boolean
+alpha_adjust_headers (abfd, fhdr, ahdr)
+     bfd *abfd;
+     struct internal_filehdr *fhdr;
+     struct internal_aouthdr *ahdr;
+{
+  if ((abfd->flags & (DYNAMIC | EXEC_P)) == (DYNAMIC | EXEC_P))
+    fhdr->f_flags |= F_ALPHA_CALL_SHARED;
+  else if ((abfd->flags & DYNAMIC) != 0)
+    fhdr->f_flags |= F_ALPHA_SHARABLE;
+  return true;
+}
+\f
 /* This is the ECOFF backend structure.  The backend field of the
    target vector points to this.  */
 
@@ -1911,13 +1965,13 @@ static const struct ecoff_backend_data alpha_ecoff_backend_data =
     (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* reloc_out */
     alpha_ecoff_swap_filehdr_out, alpha_ecoff_swap_aouthdr_out,
     alpha_ecoff_swap_scnhdr_out,
-    FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true,
+    FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, 0, true,
     alpha_ecoff_swap_filehdr_in, alpha_ecoff_swap_aouthdr_in,
-    alpha_ecoff_swap_scnhdr_in, alpha_ecoff_bad_format_hook,
-    _bfd_ecoff_set_arch_mach_hook, _bfd_ecoff_mkobject_hook,
-    _bfd_ecoff_styp_to_sec_flags, _bfd_ecoff_make_section_hook,
+    alpha_ecoff_swap_scnhdr_in, NULL,
+    alpha_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook,
+    alpha_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
     _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
-    NULL, NULL
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
   },
   /* Supported architecture.  */
   bfd_arch_alpha,
@@ -1982,7 +2036,9 @@ static const struct ecoff_backend_data alpha_ecoff_backend_data =
   alpha_adjust_reloc_in,
   alpha_adjust_reloc_out,
   /* Relocate section contents while linking.  */
-  alpha_relocate_section
+  alpha_relocate_section,
+  /* Do final adjustments to filehdr and aouthdr.  */
+  alpha_adjust_headers
 };
 
 /* Looking up a reloc type is Alpha specific.  */
@@ -1992,6 +2048,10 @@ static const struct ecoff_backend_data alpha_ecoff_backend_data =
 #define _bfd_ecoff_bfd_get_relocated_section_contents \
   alpha_ecoff_get_relocated_section_contents
 
+/* Handling file windows is generic.  */
+#define _bfd_ecoff_get_section_contents_in_window \
+  _bfd_generic_get_section_contents_in_window
+
 /* Relaxing sections is generic.  */
 #define _bfd_ecoff_bfd_relax_section bfd_generic_relax_section
 
@@ -2004,14 +2064,12 @@ const bfd_target ecoffalpha_little_vec =
 
   (HAS_RELOC | EXEC_P |                /* object flags */
    HAS_LINENO | HAS_DEBUG |
-   HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
+   HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
 
-  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect
-                                                           flags */
+  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
   0,                           /* leading underscore */
   ' ',                         /* ar_pad_char */
   15,                          /* ar_max_namelen */
-  4,                           /* minimum alignment power */
   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */