tizen 2.4 release
[external/binutils.git] / bfd / vms-alpha.c
index 8b98560..5ff5bfd 100644 (file)
@@ -1,6 +1,5 @@
 /* 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, 2011  Free Software Foundation, Inc.
+   Copyright (C) 1996-2014 Free Software Foundation, Inc.
 
    Initial version written by Klaus Kaempf (kkaempf@rmi.de)
    Major rewrite by Adacore.
@@ -331,10 +330,6 @@ struct vms_private_data_struct
 
   /* linkage index counter used by conditional store commands */
   unsigned int vms_linkage_index;
-
-  /* see tc-alpha.c of gas for a description.  */
-  int flag_hash_long_names;    /* -+, hash instead of truncate */
-  int flag_show_after_trunc;   /* -H, show hashing/truncation */
 };
 
 #define PRIV2(abfd, name) \
@@ -2479,10 +2474,7 @@ alpha_vms_object_p (bfd *abfd)
   PRIV (recrd.rec) = buf;
 
   if (bfd_bread (buf, test_len, abfd) != test_len)
-    {
-      bfd_set_error (bfd_error_file_truncated);
-      goto error_ret;
-    }
+    goto err_wrong_format;
 
   /* Is it an image?  */
   if ((bfd_getl32 (buf) == EIHD__K_MAJORID)
@@ -2507,7 +2499,6 @@ alpha_vms_object_p (bfd *abfd)
           if (buf == NULL)
             {
               PRIV (recrd.buf) = NULL;
-              bfd_set_error (bfd_error_no_memory);
               goto error_ret;
             }
           PRIV (recrd.buf) = buf;
@@ -2522,10 +2513,7 @@ alpha_vms_object_p (bfd *abfd)
       while (remaining > 0)
         {
           if (bfd_bread (buf + read_so_far, to_read, abfd) != to_read)
-            {
-              bfd_set_error (bfd_error_file_truncated);
-              goto err_wrong_format;
-            }
+           goto err_wrong_format;
 
           read_so_far += to_read;
           remaining -= to_read;
@@ -2686,88 +2674,6 @@ _bfd_vms_write_eeom (bfd *abfd)
   return TRUE;
 }
 
-/* This hash routine borrowed from GNU-EMACS, and strengthened
-   slightly.  ERY.  */
-
-static int
-hash_string (const char *ptr)
-{
-  const unsigned char *p = (unsigned char *) ptr;
-  const unsigned char *end = p + strlen (ptr);
-  unsigned char c;
-  int hash = 0;
-
-  while (p != end)
-    {
-      c = *p++;
-      hash = ((hash << 3) + (hash << 15) + (hash >> 28) + c);
-    }
-  return hash;
-}
-
-/* Generate a length-hashed VMS symbol name (limited to maxlen chars).  */
-
-static char *
-_bfd_vms_length_hash_symbol (bfd *abfd, const char *in, int maxlen)
-{
-  unsigned long result;
-  int in_len;
-  char *new_name;
-  const char *old_name;
-  int i;
-  static char outbuf[EOBJ__C_SYMSIZ + 1];
-  char *out = outbuf;
-
-#if VMS_DEBUG
-  vms_debug (4, "_bfd_vms_length_hash_symbol \"%s\"\n", in);
-#endif
-
-  if (maxlen > EOBJ__C_SYMSIZ)
-    maxlen = EOBJ__C_SYMSIZ;
-
-  /* Save this for later.  */
-  new_name = out;
-
-  /* We may need to truncate the symbol, save the hash for later.  */
-  in_len = strlen (in);
-
-  result = (in_len > maxlen) ? hash_string (in) : 0;
-
-  old_name = in;
-
-  /* Do the length checking.  */
-  if (in_len <= maxlen)
-    i = in_len;
-  else
-    {
-      if (PRIV (flag_hash_long_names))
-       i = maxlen - 9;
-      else
-       i = maxlen;
-    }
-
-  strncpy (out, in, (size_t) i);
-  in += i;
-  out += i;
-
-  if ((in_len > maxlen)
-      && PRIV (flag_hash_long_names))
-    sprintf (out, "_%08lx", result);
-  else
-    *out = 0;
-
-#if VMS_DEBUG
-  vms_debug (4, "--> [%d]\"%s\"\n", (int)strlen (outbuf), outbuf);
-#endif
-
-  if (in_len > maxlen
-       && PRIV (flag_hash_long_names)
-       && PRIV (flag_show_after_trunc))
-    printf (_("Symbol %s replaced by %s\n"), old_name, new_name);
-
-  return outbuf;
-}
-
 static void
 vector_grow1 (struct vector_type *vec, size_t elsz)
 {
@@ -3241,7 +3147,6 @@ alpha_vms_write_exec (bfd *abfd)
       for (i = 0; i < PRIV (gsd_sym_count); i++)
         {
           struct vms_symbol_entry *sym = PRIV (syms)[i];
-          char *hash;
           bfd_vma val;
           bfd_vma ep;
 
@@ -3268,8 +3173,7 @@ alpha_vms_write_exec (bfd *abfd)
          _bfd_vms_output_quad (recwr, ep);
          _bfd_vms_output_quad (recwr, val);
          _bfd_vms_output_long (recwr, 0);
-          hash = _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ__C_SYMSIZ);
-          _bfd_vms_output_counted (recwr, hash);
+          _bfd_vms_output_counted (recwr, sym->name);
           _bfd_vms_output_end_subrec (recwr);
           if ((i % 5) == 4)
             _bfd_vms_output_end (abfd, recwr);
@@ -3364,8 +3268,6 @@ _bfd_vms_write_egsd (bfd *abfd)
          else if ((*sname == 'l') && (strcmp (sname, "lcomm") == 0))
            sname = EVAX_LOCAL_NAME;
        }
-      else
-       sname = _bfd_vms_length_hash_symbol (abfd, sname, EOBJ__C_SECSIZ);
 
       if (bfd_is_com_section (section))
        new_flags = (EGPS__V_OVR | EGPS__V_REL | EGPS__V_GBL | EGPS__V_RD
@@ -3405,18 +3307,13 @@ _bfd_vms_write_egsd (bfd *abfd)
 
   for (symnum = 0; symnum < abfd->symcount; symnum++)
     {
-      char *hash;
-
       symbol = abfd->outsymbols[symnum];
       old_flags = symbol->flags;
 
       /* Work-around a missing feature:  consider __main as the main entry
          point.  */
-      if (*(symbol->name) == '_')
-       {
-         if (strcmp (symbol->name, "__main") == 0)
-           bfd_set_start_address (abfd, (bfd_vma)symbol->value);
-       }
+      if (symbol->name[0] == '_' && strcmp (symbol->name, "__main") == 0)
+       bfd_set_start_address (abfd, (bfd_vma)symbol->value);
 
       /* Only put in the GSD the global and the undefined symbols.  */
       if (old_flags & BSF_FILE)
@@ -3509,8 +3406,7 @@ _bfd_vms_write_egsd (bfd *abfd)
          _bfd_vms_output_long (recwr, ca_psindx);
          _bfd_vms_output_long (recwr, psindx);
        }
-      hash = _bfd_vms_length_hash_symbol (abfd, symbol->name, EOBJ__C_SYMSIZ);
-      _bfd_vms_output_counted (recwr, hash);
+      _bfd_vms_output_counted (recwr, symbol->name);
 
       _bfd_vms_output_end_subrec (recwr);
     }
@@ -3528,8 +3424,6 @@ _bfd_vms_write_ehdr (bfd *abfd)
 {
   asymbol *symbol;
   unsigned int symnum;
-  int had_case = 0;
-  int had_file = 0;
   struct vms_rec_wr *recwr = &PRIV (recwr);
 
   vms_debug2 ((2, "vms_write_ehdr (%p)\n", abfd));
@@ -3549,22 +3443,9 @@ _bfd_vms_write_ehdr (bfd *abfd)
 
       if (symbol->flags & BSF_FILE)
        {
-         if (CONST_STRNEQ ((char *)symbol->name, "<CASE:"))
-           {
-             PRIV (flag_hash_long_names) = symbol->name[6] - '0';
-             PRIV (flag_show_after_trunc) = symbol->name[7] - '0';
-
-             if (had_file)
-               break;
-             had_case = 1;
-             continue;
-           }
-
          _bfd_vms_output_dump (recwr, (unsigned char *) symbol->name,
                                (int) strlen (symbol->name));
-         if (had_case)
-           break;
-         had_file = 1;
+         break;
        }
     }
 
@@ -3800,7 +3681,6 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
              asection *sec = sym->section;
              bfd_boolean defer = defer_reloc_p (rptr);
              unsigned int slen;
-             char *hash;
 
              if (pass2_in_progress)
                {
@@ -3839,13 +3719,11 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                    {
                      bfd_vma addend = rptr->addend;
                      slen = strlen ((char *) sym->name);
-                     hash = _bfd_vms_length_hash_symbol
-                        (abfd, sym->name, EOBJ__C_SYMSIZ);
                      etir_output_check (abfd, section, curr_addr, slen);
                      if (addend)
                        {
                          _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
-                         _bfd_vms_output_counted (recwr, hash);
+                         _bfd_vms_output_counted (recwr, sym->name);
                          _bfd_vms_output_end_subrec (recwr);
                          _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
                          _bfd_vms_output_long (recwr, (unsigned long) addend);
@@ -3859,7 +3737,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                        {
                          _bfd_vms_output_begin_subrec
                             (recwr, ETIR__C_STO_GBL_LW);
-                         _bfd_vms_output_counted (recwr, hash);
+                         _bfd_vms_output_counted (recwr, sym->name);
                          _bfd_vms_output_end_subrec (recwr);
                        }
                    }
@@ -3894,13 +3772,11 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                    {
                      bfd_vma addend = rptr->addend;
                      slen = strlen ((char *) sym->name);
-                     hash = _bfd_vms_length_hash_symbol
-                        (abfd, sym->name, EOBJ__C_SYMSIZ);
                      etir_output_check (abfd, section, curr_addr, slen);
                      if (addend)
                        {
                          _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
-                         _bfd_vms_output_counted (recwr, hash);
+                         _bfd_vms_output_counted (recwr, sym->name);
                          _bfd_vms_output_end_subrec (recwr);
                          _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
                          _bfd_vms_output_quad (recwr, addend);
@@ -3913,7 +3789,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                      else
                        {
                          _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_GBL);
-                         _bfd_vms_output_counted (recwr, hash);
+                         _bfd_vms_output_counted (recwr, sym->name);
                          _bfd_vms_output_end_subrec (recwr);
                        }
                    }
@@ -3950,20 +3826,16 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                    (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);
+                 _bfd_vms_output_counted (recwr, sym->name);
                  _bfd_vms_output_byte (recwr, 0);
                  _bfd_vms_output_end_subrec (recwr);
                  break;
 
                case ALPHA_R_CODEADDR:
                  slen = strlen ((char *) sym->name);
-                 hash = _bfd_vms_length_hash_symbol
-                    (abfd, sym->name, EOBJ__C_SYMSIZ);
                  etir_output_check (abfd, section, curr_addr, slen);
                  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA);
-                 _bfd_vms_output_counted (recwr, hash);
+                 _bfd_vms_output_counted (recwr, sym->name);
                  _bfd_vms_output_end_subrec (recwr);
                  break;
 
@@ -3981,9 +3853,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  _bfd_vms_output_long
                    (recwr, (unsigned long) section->target_index);
                  _bfd_vms_output_quad (recwr, rptr->addend);
-                 _bfd_vms_output_counted
-                   (recwr, _bfd_vms_length_hash_symbol
-                     (abfd, udata->origname, EOBJ__C_SYMSIZ));
+                 _bfd_vms_output_counted (recwr, udata->origname);
                  _bfd_vms_output_end_subrec (recwr);
                  break;
 
@@ -4006,9 +3876,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  _bfd_vms_output_long
                    (recwr, (unsigned long) udata->bsym->section->target_index);
                  _bfd_vms_output_quad (recwr, rptr->addend);
-                 _bfd_vms_output_counted
-                   (recwr, _bfd_vms_length_hash_symbol
-                     (abfd, udata->origname, EOBJ__C_SYMSIZ));
+                 _bfd_vms_output_counted (recwr, udata->origname);
                  _bfd_vms_output_end_subrec (recwr);
                  break;
 
@@ -4026,9 +3894,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  _bfd_vms_output_long
                    (recwr, (unsigned long) section->target_index);
                  _bfd_vms_output_quad (recwr, rptr->addend);
-                 _bfd_vms_output_counted
-                   (recwr, _bfd_vms_length_hash_symbol
-                     (abfd, udata->origname, EOBJ__C_SYMSIZ));
+                 _bfd_vms_output_counted (recwr, udata->origname);
                  _bfd_vms_output_end_subrec (recwr);
                  break;
 
@@ -4709,10 +4575,14 @@ module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
    location.  */
 
 static bfd_boolean
-_bfd_vms_find_nearest_dst_line (bfd *abfd, asection *section,
-                               asymbol **symbols ATTRIBUTE_UNUSED,
-                               bfd_vma offset, const char **file,
-                               const char **func, unsigned int *line)
+_bfd_vms_find_nearest_line (bfd *abfd,
+                           asymbol **symbols ATTRIBUTE_UNUSED,
+                           asection *section,
+                           bfd_vma offset,
+                           const char **file,
+                           const char **func,
+                           unsigned int *line,
+                           unsigned int *discriminator)
 {
   struct module *module;
 
@@ -4722,6 +4592,8 @@ _bfd_vms_find_nearest_dst_line (bfd *abfd, asection *section,
   *file = NULL;
   *func = NULL;
   *line = 0;
+  if (discriminator)
+    *discriminator = 0;
 
   /* We can't do anything if there is no DST (debug symbol table).  */
   if (PRIV (dst_section) == NULL)
@@ -6044,7 +5916,7 @@ evax_bfd_print_etir (FILE *file, const char *name,
                      unsigned char *rec, unsigned int rec_len)
 {
   unsigned int off = sizeof (struct vms_egsd);
-  unsigned int sec_len;
+  unsigned int sec_len = 0;
 
   fprintf (file, _("  %s (len=%u+%u):\n"), name,
            (unsigned)(rec_len - sizeof (struct vms_eobjrec)),
@@ -7849,7 +7721,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)
@@ -8759,7 +8631,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
     {
       bfd *startbfd = NULL;
 
-      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+      for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
         {
           /* Consider only VMS object files.  */
           if (sub->xvec != abfd->xvec)
@@ -8863,7 +8735,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
     dmt = NULL;
 
   /* Read all sections from the inputs.  */
-  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+  for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
     {
       if (sub->flags & DYNAMIC)
         {
@@ -8914,7 +8786,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
           unsigned int off = 0;
 
           /* For each object file (ie for each module).  */
-          for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+          for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
             {
               asection *sub_dst;
               struct vms_dmt_header *dmth = NULL;
@@ -9118,7 +8990,8 @@ vms_new_section_hook (bfd * abfd, asection *section)
   vms_debug2 ((1, "vms_new_section_hook (%p, [%d]%s)\n",
                abfd, section->index, section->name));
 
-  bfd_set_section_alignment (abfd, section, 0);
+  if (! bfd_set_section_alignment (abfd, section, 0))
+    return FALSE;
 
   vms_debug2 ((7, "%d: %s\n", section->index, section->name));
 
@@ -9228,7 +9101,6 @@ static bfd_boolean
 vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
                             const char *name)
 {
-  vms_debug2 ((1, "vms_bfd_is_local_label_name (%p, %s)\n", abfd, name));
   return name[0] == '$';
 }
 \f
@@ -9321,7 +9193,8 @@ bfd_vms_get_data (bfd *abfd)
 #define alpha_vms_get_lineno               _bfd_nosymbols_get_lineno
 #define alpha_vms_find_inliner_info        _bfd_nosymbols_find_inliner_info
 #define alpha_vms_bfd_make_debug_symbol    _bfd_nosymbols_bfd_make_debug_symbol
-#define alpha_vms_find_nearest_line        _bfd_vms_find_nearest_dst_line
+#define alpha_vms_find_nearest_line        _bfd_vms_find_nearest_line
+#define alpha_vms_find_line                _bfd_nosymbols_find_line
 #define alpha_vms_bfd_is_local_label_name  vms_bfd_is_local_label_name
 
 /* Generic table.  */
@@ -9344,7 +9217,6 @@ bfd_vms_get_data (bfd *abfd)
   _bfd_generic_section_already_linked
 
 #define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol
-#define alpha_vms_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
 #define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms
 #define alpha_vms_bfd_copy_link_hash_symbol_type \
   _bfd_generic_copy_link_hash_symbol_type
@@ -9360,7 +9232,7 @@ bfd_vms_get_data (bfd *abfd)
 #define alpha_vms_canonicalize_dynamic_reloc \
   _bfd_nodynamic_canonicalize_dynamic_reloc
 
-const bfd_target vms_alpha_vec =
+const bfd_target alpha_vms_vec =
 {
   "vms-alpha",                 /* Name.  */
   bfd_target_evax_flavour,