daily update
[deliverable/binutils-gdb.git] / bfd / vms-alpha.c
index 53d0f153f925b3efd06db2b4fecdfc9f260694bb..3383b0f65da1f77bb397c054628e8121fb529a41 100644 (file)
@@ -1,6 +1,6 @@
 /* vms.c -- BFD back-end for EVAX (openVMS/Alpha) files.
    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+   2006, 2007, 2008, 2009, 2010, 2011  Free Software Foundation, Inc.
 
    Initial version written by Klaus Kaempf (kkaempf@rmi.de)
    Major rewrite by Adacore.
@@ -304,6 +304,7 @@ struct vms_private_data_struct
 
   struct module *modules;              /* list of all compilation units */
 
+  /* The DST section.  */
   asection *dst_section;
 
   unsigned int dst_ptr_offsets_count;  /* # of offsets in following array  */
@@ -329,7 +330,7 @@ struct vms_private_data_struct
   struct vms_internal_eisd_map *gbl_eisd_tail;
 
   /* linkage index counter used by conditional store commands */
-  int vms_linkage_index;
+  unsigned int vms_linkage_index;
 
   /* see tc-alpha.c of gas for a description.  */
   int flag_hash_long_names;    /* -+, hash instead of truncate */
@@ -439,7 +440,7 @@ struct alpha_vms_link_hash_table
 {
   struct bfd_link_hash_table root;
 
-  /* Vector of shared libaries.  */
+  /* Vector of shared libraries.  */
   struct vector_type shrlibs;
 
   /* Fixup section.  */
@@ -992,7 +993,7 @@ static const struct sec_flags_struct evax_section_flags[] =
       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
       SEC_DATA,
       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
-      SEC_IN_MEMORY | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }
+      SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }
   };
 
 /* Retrieve BFD section flags by name and size.  */
@@ -1129,14 +1130,15 @@ _bfd_vms_slurp_egsd (bfd *abfd)
           /* Program section definition.  */
          {
             struct vms_egps *egps = (struct vms_egps *)vms_rec;
-            flagword new_flags, old_flags;
+            flagword new_flags, vms_flags;
             asection *section;
 
-           old_flags = bfd_getl16 (egps->flags);
+           vms_flags = bfd_getl16 (egps->flags);
 
-            if ((old_flags & EGPS__V_REL) == 0)
+            if ((vms_flags & EGPS__V_REL) == 0)
               {
-                /* Use the global absolute section for all absolute sections.  */
+                /* Use the global absolute section for all
+                   absolute sections.  */
                 section = bfd_abs_section_ptr;
               }
             else
@@ -1154,17 +1156,27 @@ _bfd_vms_slurp_egsd (bfd *abfd)
                 section->size = bfd_getl32 (egps->alloc);
                 section->alignment_power = egps->align;
 
-                vms_section_data (section)->flags = old_flags;
+                vms_section_data (section)->flags = vms_flags;
                 vms_section_data (section)->no_flags = 0;
 
                 new_flags = vms_secflag_by_name (evax_section_flags, name,
                                                  section->size > 0);
-                if (!(old_flags & EGPS__V_NOMOD) && section->size > 0)
+                if (section->size > 0)
+                  new_flags |= SEC_LOAD;
+                if (!(vms_flags & EGPS__V_NOMOD) && section->size > 0)
                   {
+                    /* Set RELOC and HAS_CONTENTS if the section is not
+                       demand-zero and not empty.  */
                     new_flags |= SEC_HAS_CONTENTS;
-                    if (old_flags & EGPS__V_REL)
+                    if (vms_flags & EGPS__V_REL)
                       new_flags |= SEC_RELOC;
                   }
+                if (vms_flags & EGPS__V_EXE)
+                  {
+                    /* Set CODE if section is executable.  */
+                    new_flags |= SEC_CODE;
+                    new_flags &= ~SEC_DATA;
+                  }
                 if (!bfd_set_section_flags (abfd, section, new_flags))
                   return FALSE;
 
@@ -2425,7 +2437,7 @@ vms_initialize (bfd * abfd)
 static const struct bfd_target *
 alpha_vms_object_p (bfd *abfd)
 {
-  PTR tdata_save = abfd->tdata.any;
+  void *tdata_save = abfd->tdata.any;
   unsigned int test_len;
   unsigned char *buf;
 
@@ -2648,7 +2660,7 @@ _bfd_vms_write_eeom (bfd *abfd)
   _bfd_vms_output_alignment (recwr, 2);
 
   _bfd_vms_output_begin (recwr, EOBJ__C_EEOM);
-  _bfd_vms_output_long (recwr, (unsigned long) (PRIV (vms_linkage_index) >> 1));
+  _bfd_vms_output_long (recwr, PRIV (vms_linkage_index + 1) >> 1);
   _bfd_vms_output_byte (recwr, 0);     /* Completion code.  */
   _bfd_vms_output_byte (recwr, 0);     /* Fill byte.  */
 
@@ -2908,7 +2920,7 @@ alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec)
   if (sec->flags & SEC_RELOC)
     eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
 
-  if (!(sec->flags & SEC_LOAD))
+  if (!(sec->flags & SEC_HAS_CONTENTS))
     {
       eisd->u.eisd.flags |= EISD__M_DZRO;
       eisd->u.eisd.flags &= ~EISD__M_CRF;
@@ -3724,7 +3736,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
 
   _bfd_vms_output_alignment (recwr, 4);
 
-  PRIV (vms_linkage_index) = 1;
+  PRIV (vms_linkage_index) = 0;
 
   for (section = abfd->sections; section; section = section->next)
     {
@@ -3935,8 +3947,9 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  etir_output_check (abfd, section, curr_addr, 64);
                  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB);
                  _bfd_vms_output_long
-                   (recwr, (unsigned long) PRIV (vms_linkage_index));
-                 PRIV (vms_linkage_index) += 2;
+                   (recwr, (unsigned long) rptr->addend);
+                  if (rptr->addend > PRIV (vms_linkage_index))
+                    PRIV (vms_linkage_index) = rptr->addend;
                  hash = _bfd_vms_length_hash_symbol
                     (abfd, sym->name, EOBJ__C_SYMSIZ);
                  _bfd_vms_output_counted (recwr, hash);
@@ -3962,13 +3975,11 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL);
                  _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
                  _bfd_vms_output_long
-                   (recwr,
-                     (unsigned long) udata->enbsym->section->target_index);
+                   (recwr, (unsigned long) section->target_index);
                  _bfd_vms_output_quad (recwr, rptr->address);
                  _bfd_vms_output_long (recwr, (unsigned long) 0x47ff041f);
                  _bfd_vms_output_long
-                   (recwr,
-                     (unsigned long) udata->enbsym->section->target_index);
+                   (recwr, (unsigned long) section->target_index);
                  _bfd_vms_output_quad (recwr, rptr->addend);
                  _bfd_vms_output_counted
                    (recwr, _bfd_vms_length_hash_symbol
@@ -3989,8 +4000,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  _bfd_vms_output_long
                    (recwr, (unsigned long) udata->lkindex + 1);
                  _bfd_vms_output_long
-                   (recwr,
-                     (unsigned long) udata->enbsym->section->target_index);
+                   (recwr, (unsigned long) section->target_index);
                  _bfd_vms_output_quad (recwr, rptr->address);
                  _bfd_vms_output_long (recwr, (unsigned long) 0x237B0000);
                  _bfd_vms_output_long
@@ -4010,13 +4020,11 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL);
                  _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
                  _bfd_vms_output_long
-                   (recwr,
-                     (unsigned long) udata->enbsym->section->target_index);
+                   (recwr, (unsigned long) section->target_index);
                  _bfd_vms_output_quad (recwr, rptr->address);
                  _bfd_vms_output_long (recwr, (unsigned long) 0xD3400000);
                  _bfd_vms_output_long
-                   (recwr,
-                     (unsigned long) udata->enbsym->section->target_index);
+                   (recwr, (unsigned long) section->target_index);
                  _bfd_vms_output_quad (recwr, rptr->addend);
                  _bfd_vms_output_counted
                    (recwr, _bfd_vms_length_hash_symbol
@@ -4617,6 +4625,11 @@ build_module_list (bfd *abfd)
       /* We don't have a DMT section so this must be an object.  Parse
         the module right now in order to compute its start address and
         end address.  */
+      void *dst = PRIV (dst_section)->contents;
+
+      if (dst == NULL)
+        return NULL;
+
       module = new_module (abfd);
       parse_module (abfd, module, PRIV (dst_section)->contents, -1);
       list = module;
@@ -4710,9 +4723,11 @@ _bfd_vms_find_nearest_dst_line (bfd *abfd, asection *section,
   *func = NULL;
   *line = 0;
 
+  /* We can't do anything if there is no DST (debug symbol table).  */
   if (PRIV (dst_section) == NULL)
     return FALSE;
 
+  /* Create the module list - if not already done.  */
   if (PRIV (modules) == NULL)
     {
       PRIV (modules) = build_module_list (abfd);
@@ -5087,7 +5102,14 @@ alpha_vms_slurp_relocs (bfd *abfd)
                 (*_bfd_error_handler) (_("Invalid section index in ETIR"));
                 return FALSE;
               }
+
             sec = PRIV (sections)[cur_psect];
+            if (sec == bfd_abs_section_ptr)
+              {
+                (*_bfd_error_handler) (_("Relocation for non-REL psect"));
+                return FALSE;
+              }
+
             vms_sec = vms_section_data (sec);
 
             /* Allocate a reloc entry.  */
@@ -5098,7 +5120,7 @@ alpha_vms_slurp_relocs (bfd *abfd)
                     vms_sec->reloc_max = 64;
                     sec->relocation = bfd_zmalloc
                       (vms_sec->reloc_max * sizeof (arelent));
-                }
+                  }
                 else
                   {
                     vms_sec->reloc_max *= 2;
@@ -7827,7 +7849,7 @@ evax_bfd_print_image (bfd *abfd, FILE *file)
         }
       if (lpfixoff != 0)
         {
-          fprintf (file, _(" Linkage Pairs Referece Fixups:\n"));
+          fprintf (file, _(" Linkage Pairs Reference Fixups:\n"));
           evax_bfd_print_reference_fixups (file, buf + lpfixoff);
         }
       if (chgprtoff)
@@ -8581,20 +8603,31 @@ alpha_vms_build_fixups (struct bfd_link_info *info)
   return TRUE;
 }
 
-/* Called by bfd_link_hash_traverse to fill the symbol table.
+/* Called by bfd_hash_traverse to fill the symbol table.
    Return FALSE in case of failure.  */
 
 static bfd_boolean
-alpha_vms_link_output_symbol (struct bfd_link_hash_entry *hc, void *infov)
+alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov)
 {
+  struct bfd_link_hash_entry *hc = (struct bfd_link_hash_entry *) bh;
   struct bfd_link_info *info = (struct bfd_link_info *)infov;
-  struct alpha_vms_link_hash_entry *h = (struct alpha_vms_link_hash_entry *)hc;
+  struct alpha_vms_link_hash_entry *h;
   struct vms_symbol_entry *sym;
 
+  if (hc->type == bfd_link_hash_warning)
+    {
+      hc = hc->u.i.link;
+      if (hc->type == bfd_link_hash_new)
+       return TRUE;
+    }
+  h = (struct alpha_vms_link_hash_entry *) hc;
+
   switch (h->root.type)
     {
-    case bfd_link_hash_new:
     case bfd_link_hash_undefined:
+      return TRUE;
+    case bfd_link_hash_new:
+    case bfd_link_hash_warning:
       abort ();
     case bfd_link_hash_undefweak:
       return TRUE;
@@ -8614,7 +8647,6 @@ alpha_vms_link_output_symbol (struct bfd_link_hash_entry *hc, void *infov)
     case bfd_link_hash_common:
       break;
     case bfd_link_hash_indirect:
-    case bfd_link_hash_warning:
       return TRUE;
     }
 
@@ -8720,7 +8752,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
   /* Generate the symbol table.  */
   BFD_ASSERT (PRIV (syms) == NULL);
   if (info->strip != strip_all)
-    bfd_link_hash_traverse (info->hash, alpha_vms_link_output_symbol, info);
+    bfd_hash_traverse (&info->hash->table, alpha_vms_link_output_symbol, info);
 
   /* Find the entry point.  */
   if (bfd_get_start_address (abfd) == 0)
@@ -8972,9 +9004,17 @@ alpha_vms_get_section_contents (bfd *abfd, asection *section,
       return FALSE;
     }
 
-  /* Alloc in memory and read ETIRs.  */
-  BFD_ASSERT (section->contents == NULL);
+  /* If the section is already in memory, just copy it.  */
+  if (section->flags & SEC_IN_MEMORY)
+    {
+      BFD_ASSERT (section->contents != NULL);
+      memcpy (buf, section->contents + offset, count);
+      return TRUE;
+    }
+  if (section->size == 0)
+    return TRUE;
 
+  /* Alloc in memory and read ETIRs.  */
   for (sec = abfd->sections; sec; sec = sec->next)
     {
       BFD_ASSERT (sec->contents == NULL);
@@ -8989,8 +9029,8 @@ alpha_vms_get_section_contents (bfd *abfd, asection *section,
   if (!alpha_vms_read_sections_content (abfd, NULL))
     return FALSE;
   for (sec = abfd->sections; sec; sec = sec->next)
-    if (section->contents)
-      section->flags |= SEC_IN_MEMORY;
+    if (sec->contents)
+      sec->flags |= SEC_IN_MEMORY;
   memcpy (buf, section->contents + offset, count);
   return TRUE;
 }
@@ -9083,7 +9123,7 @@ vms_new_section_hook (bfd * abfd, asection *section)
   vms_debug2 ((7, "%d: %s\n", section->index, section->name));
 
   amt = sizeof (struct vms_section_data_struct);
-  section->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
+  section->used_by_bfd = bfd_zalloc (abfd, amt);
   if (section->used_by_bfd == NULL)
     return FALSE;
 
@@ -9296,6 +9336,7 @@ bfd_vms_get_data (bfd *abfd)
 
 #define alpha_vms_bfd_relax_section bfd_generic_relax_section
 #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections
+#define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections
 #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section
 #define alpha_vms_bfd_discard_group bfd_generic_discard_group
@@ -9334,6 +9375,7 @@ const bfd_target vms_alpha_vec =
   0,                           /* symbol_leading_char.  */
   ' ',                         /* ar_pad_char.  */
   15,                          /* ar_max_namelen.  */
+  0,                           /* match priority.  */
   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   bfd_getl16, bfd_getl_signed_16, bfd_putl16,
@@ -9360,5 +9402,5 @@ const bfd_target vms_alpha_vec =
 
   NULL,
 
-  (PTR) 0
+  NULL
 };
This page took 0.049253 seconds and 4 git commands to generate.