Automatic date update in version.in
[platform/upstream/binutils.git] / bfd / xsym.c
index dd1ffd7..4e2a8ab 100644 (file)
@@ -1,6 +1,5 @@
 /* xSYM symbol-file support for BFD.
-   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-   2009 Free Software Foundation, Inc.
+   Copyright (C) 1999-2014 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
-#include "alloca-conf.h"
+/* xSYM is the debugging format used by CodeWarrior on Mac OS classic.  */
+
 #include "sysdep.h"
+#include "alloca-conf.h"
 #include "xsym.h"
 #include "bfd.h"
 #include "libbfd.h"
@@ -32,6 +33,7 @@
 #define bfd_sym_bfd_is_target_special_symbol       ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
 #define bfd_sym_get_lineno                          _bfd_nosymbols_get_lineno
 #define bfd_sym_find_nearest_line                   _bfd_nosymbols_find_nearest_line
+#define bfd_sym_find_line                           _bfd_nosymbols_find_line
 #define bfd_sym_find_inliner_info                   _bfd_nosymbols_find_inliner_info
 #define bfd_sym_bfd_make_debug_symbol               _bfd_nosymbols_bfd_make_debug_symbol
 #define bfd_sym_read_minisymbols                    _bfd_generic_read_minisymbols
 #define bfd_sym_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
 #define bfd_sym_bfd_relax_section                   bfd_generic_relax_section
 #define bfd_sym_bfd_gc_sections                     bfd_generic_gc_sections
+#define bfd_sym_bfd_lookup_section_flags            bfd_generic_lookup_section_flags
 #define bfd_sym_bfd_merge_sections                  bfd_generic_merge_sections
 #define bfd_sym_bfd_is_group_section                bfd_generic_is_group_section
 #define bfd_sym_bfd_discard_group                   bfd_generic_discard_group
 #define bfd_sym_section_already_linked              _bfd_generic_section_already_linked
 #define bfd_sym_bfd_define_common_symbol            bfd_generic_define_common_symbol
 #define bfd_sym_bfd_link_hash_table_create          _bfd_generic_link_hash_table_create
-#define bfd_sym_bfd_link_hash_table_free            _bfd_generic_link_hash_table_free
 #define bfd_sym_bfd_link_add_symbols                _bfd_generic_link_add_symbols
 #define bfd_sym_bfd_link_just_syms                  _bfd_generic_link_just_syms
 #define bfd_sym_bfd_copy_link_hash_symbol_type \
@@ -84,11 +86,11 @@ static unsigned long
 compute_offset (unsigned long first_page,
                unsigned long page_size,
                unsigned long entry_size,
-               unsigned long index)
+               unsigned long sym_index)
 {
   unsigned long entries_per_page = page_size / entry_size;
-  unsigned long page_number = first_page + (index / entries_per_page);
-  unsigned long page_offset = (index % entries_per_page) * entry_size;
+  unsigned long page_number = first_page + (sym_index / entries_per_page);
+  unsigned long page_offset = (sym_index % entries_per_page) * entry_size;
 
   return (page_number * page_size) + page_offset;
 }
@@ -530,7 +532,7 @@ bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
 int
 bfd_sym_fetch_resources_table_entry (bfd *abfd,
                                     bfd_sym_resources_table_entry *entry,
-                                    unsigned long index)
+                                    unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *);
   unsigned long offset;
@@ -542,7 +544,7 @@ bfd_sym_fetch_resources_table_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -566,7 +568,7 @@ bfd_sym_fetch_resources_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -581,7 +583,7 @@ bfd_sym_fetch_resources_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_modules_table_entry (bfd *abfd,
                                   bfd_sym_modules_table_entry *entry,
-                                  unsigned long index)
+                                  unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *);
   unsigned long offset;
@@ -593,7 +595,7 @@ bfd_sym_fetch_modules_table_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -617,7 +619,7 @@ bfd_sym_fetch_modules_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -632,7 +634,7 @@ bfd_sym_fetch_modules_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
                                           bfd_sym_file_references_table_entry *entry,
-                                          unsigned long index)
+                                          unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *);
   unsigned long offset;
@@ -644,7 +646,7 @@ bfd_sym_fetch_file_references_table_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -667,7 +669,7 @@ bfd_sym_fetch_file_references_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -682,7 +684,7 @@ bfd_sym_fetch_file_references_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
                                             bfd_sym_contained_modules_table_entry *entry,
-                                            unsigned long index)
+                                            unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *);
   unsigned long offset;
@@ -694,7 +696,7 @@ bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -717,7 +719,7 @@ bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -732,7 +734,7 @@ bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
                                               bfd_sym_contained_variables_table_entry *entry,
-                                              unsigned long index)
+                                              unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *);
   unsigned long offset;
@@ -744,7 +746,7 @@ bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -767,7 +769,7 @@ bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -782,7 +784,7 @@ bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
                                                bfd_sym_contained_statements_table_entry *entry,
-                                               unsigned long index)
+                                               unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *);
   unsigned long offset;
@@ -794,7 +796,7 @@ bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -817,7 +819,7 @@ bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -832,7 +834,7 @@ bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
                                            bfd_sym_contained_labels_table_entry *entry,
-                                           unsigned long index)
+                                           unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *);
   unsigned long offset;
@@ -844,7 +846,7 @@ bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -867,7 +869,7 @@ bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -882,7 +884,7 @@ bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
                                           bfd_sym_contained_types_table_entry *entry,
-                                          unsigned long index)
+                                          unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *);
   unsigned long offset;
@@ -894,7 +896,7 @@ bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -917,7 +919,7 @@ bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -932,7 +934,7 @@ bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
                                                 bfd_sym_file_references_index_table_entry *entry,
-                                                unsigned long index)
+                                                unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *);
   unsigned long offset;
@@ -944,7 +946,7 @@ bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -967,7 +969,7 @@ bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -982,7 +984,7 @@ bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
                                   bfd_sym_constant_pool_entry *entry,
-                                  unsigned long index)
+                                  unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *);
   unsigned long offset;
@@ -994,7 +996,7 @@ bfd_sym_fetch_constant_pool_entry (bfd *abfd,
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return -1;
 
   switch (sdata->version)
@@ -1017,7 +1019,7 @@ bfd_sym_fetch_constant_pool_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -1032,7 +1034,7 @@ bfd_sym_fetch_constant_pool_entry (bfd *abfd,
 int
 bfd_sym_fetch_type_table_entry (bfd *abfd,
                                bfd_sym_type_table_entry *entry,
-                               unsigned long index)
+                               unsigned long sym_index)
 {
   void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *);
   unsigned long offset;
@@ -1064,7 +1066,7 @@ bfd_sym_fetch_type_table_entry (bfd *abfd,
 
   offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
                           sdata->header.dshb_page_size,
-                          entry_size, index);
+                          entry_size, sym_index);
 
   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
     return -1;
@@ -1082,10 +1084,8 @@ bfd_sym_fetch_type_information_table_entry (bfd *abfd,
                                            unsigned long offset)
 {
   unsigned char buf[4];
-  bfd_sym_data_struct *sdata = NULL;
 
   BFD_ASSERT (bfd_sym_valid (abfd));
-  sdata = abfd->tdata.sym_data;
 
   if (offset == 0)
     return -1;
@@ -1124,7 +1124,7 @@ bfd_sym_fetch_type_information_table_entry (bfd *abfd,
 int
 bfd_sym_fetch_type_table_information (bfd *abfd,
                                      bfd_sym_type_information_table_entry *entry,
-                                     unsigned long index)
+                                     unsigned long sym_index)
 {
   bfd_sym_type_table_entry tindex;
   bfd_sym_data_struct *sdata = NULL;
@@ -1134,10 +1134,10 @@ bfd_sym_fetch_type_table_information (bfd *abfd,
 
   if (sdata->header.dshb_tte.dti_object_count <= 99)
     return -1;
-  if (index < 100)
+  if (sym_index < 100)
     return -1;
 
-  if (bfd_sym_fetch_type_table_entry (abfd, &tindex, index - 100) < 0)
+  if (bfd_sym_fetch_type_table_entry (abfd, &tindex, sym_index - 100) < 0)
     return -1;
   if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
     return -1;
@@ -1146,30 +1146,30 @@ bfd_sym_fetch_type_table_information (bfd *abfd,
 }
 
 const unsigned char *
-bfd_sym_symbol_name (bfd *abfd, unsigned long index)
+bfd_sym_symbol_name (bfd *abfd, unsigned long sym_index)
 {
   bfd_sym_data_struct *sdata = NULL;
 
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
 
-  if (index == 0)
+  if (sym_index == 0)
     return (const unsigned char *) "";
 
-  index *= 2;
-  if ((index / sdata->header.dshb_page_size)
+  sym_index *= 2;
+  if ((sym_index / sdata->header.dshb_page_size)
       > sdata->header.dshb_nte.dti_page_count)
     return (const unsigned char *) "\09[INVALID]";
 
-  return (const unsigned char *) sdata->name_table + index;
+  return (const unsigned char *) sdata->name_table + sym_index;
 }
 
 const unsigned char *
-bfd_sym_module_name (bfd *abfd, unsigned long index)
+bfd_sym_module_name (bfd *abfd, unsigned long sym_index)
 {
   bfd_sym_modules_table_entry entry;
 
-  if (bfd_sym_fetch_modules_table_entry (abfd, &entry, index) < 0)
+  if (bfd_sym_fetch_modules_table_entry (abfd, &entry, sym_index) < 0)
     return (const unsigned char *) "\09[INVALID]";
 
   return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
@@ -1859,24 +1859,24 @@ bfd_sym_display_name_table_entry (bfd *abfd,
                                  FILE *f,
                                  unsigned char *entry)
 {
-  unsigned long index;
+  unsigned long sym_index;
   unsigned long offset;
   bfd_sym_data_struct *sdata = NULL;
 
   BFD_ASSERT (bfd_sym_valid (abfd));
   sdata = abfd->tdata.sym_data;
-  index = (entry - sdata->name_table) / 2;
+  sym_index = (entry - sdata->name_table) / 2;
 
   if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
     {
       unsigned short length = bfd_getb16 (entry + 2);
-      fprintf (f, "[%8lu] \"%.*s\"\n", index, length, entry + 4);
+      fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, length, entry + 4);
       offset = 2 + length + 1;
     }
   else
     {
       if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
-       fprintf (f, "[%8lu] \"%.*s\"\n", index, entry[0], entry + 1);
+       fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, entry[0], entry + 1);
 
       if (sdata->version >= BFD_SYM_VERSION_3_4)
        offset = entry[0] + 2;
@@ -2178,7 +2178,7 @@ void
 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
 {
   unsigned long i;
-  bfd_sym_type_table_entry index;
+  bfd_sym_type_table_entry sym_index;
   bfd_sym_type_information_table_entry entry;
   bfd_sym_data_struct *sdata = NULL;
 
@@ -2196,13 +2196,13 @@ bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
 
   for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
     {
-      if (bfd_sym_fetch_type_table_entry (abfd, &index, i - 100) < 0)
+      if (bfd_sym_fetch_type_table_entry (abfd, &sym_index, i - 100) < 0)
        fprintf (f, " [%8lu] [INVALID]\n", i);
       else
        {
-         fprintf (f, " [%8lu] (TINFO %lu) ", i, index);
+         fprintf (f, " [%8lu] (TINFO %lu) ", i, sym_index);
 
-         if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, index) < 0)
+         if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, sym_index) < 0)
            fprintf (f, "[INVALID]");
          else
            bfd_sym_print_type_information_table_entry (abfd, f, &entry);
@@ -2248,32 +2248,26 @@ bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
 const bfd_target *
 bfd_sym_object_p (bfd *abfd)
 {
-  struct bfd_preserve preserve;
   bfd_sym_version version = -1;
+  bfd_sym_data_struct *mdata;
 
-  preserve.marker = NULL;
   bfd_seek (abfd, 0, SEEK_SET);
   if (bfd_sym_read_version (abfd, &version) != 0)
     goto wrong;
 
-  preserve.marker = bfd_alloc (abfd, sizeof (bfd_sym_data_struct));
-  if (preserve.marker == NULL
-      || ! bfd_preserve_save (abfd, &preserve))
+  mdata = (bfd_sym_data_struct *) bfd_alloc (abfd, sizeof (*mdata));
+  if (mdata == NULL)
     goto fail;
 
-  if (bfd_sym_scan (abfd, version,
-                   (bfd_sym_data_struct *) preserve.marker) != 0)
+  if (bfd_sym_scan (abfd, version, mdata) != 0)
     goto wrong;
 
-  bfd_preserve_finish (abfd, &preserve);
   return abfd->xvec;
 
  wrong:
   bfd_set_error (bfd_error_wrong_format);
 
  fail:
-  if (preserve.marker != NULL)
-    bfd_preserve_restore (abfd, &preserve);
   return NULL;
 }
 
@@ -2318,6 +2312,7 @@ const bfd_target sym_vec =
   0,                           /* Symbol_leading_char.  */
   ' ',                         /* AR_pad_char.  */
   16,                          /* AR_max_namelen.  */
+  0,                           /* match priority.  */
   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* Data.  */