* aoutx.h (NAME(aout,slurp_symbol_table)): Don't return an error
authorIan Lance Taylor <ian@airs.com>
Wed, 19 Oct 1994 05:30:15 +0000 (05:30 +0000)
committerIan Lance Taylor <ian@airs.com>
Wed, 19 Oct 1994 05:30:15 +0000 (05:30 +0000)
if there are no symbols.
* coffgen.c (coff_get_normalized_symtab): Likewise.
* hp300hpux.c (MY(slurp_symbol_table)): Likewise.

bfd/ChangeLog
bfd/aoutx.h
bfd/coffgen.c

index 84c6f1ecc3560589557da7d511eb47b114187545..9609b0b5cd06b27c7f92ff717cdc7efe54df26f7 100644 (file)
@@ -1,3 +1,10 @@
+Wed Oct 19 01:26:39 1994  Ian Lance Taylor  (ian@tweedledumb.cygnus.com)
+
+       * aoutx.h (NAME(aout,slurp_symbol_table)): Don't return an error
+       if there are no symbols.
+       * coffgen.c (coff_get_normalized_symtab): Likewise.
+       * hp300hpux.c (MY(slurp_symbol_table)): Likewise.
+
 Tue Oct 18 12:56:43 1994  Ian Lance Taylor  <ian@sanguine.cygnus.com>
 
        * aout-target.h (MY_bfd_copy_private_section_data): Only copy
index 042472d5929cb3b48d82f9e868de3be29155108e..2923c802ad40d42bb5958a15037c0867b6fca5e5 100644 (file)
@@ -794,6 +794,11 @@ adjust_o_magic (abfd, execp)
 
   /* Text.  */
   obj_textsec(abfd)->filepos = pos;
+  if (!obj_textsec(abfd)->user_set_vma)
+    obj_textsec(abfd)->vma = vma;
+  else
+    vma = obj_textsec(abfd)->vma;
+
   pos += obj_textsec(abfd)->_raw_size;
   vma += obj_textsec(abfd)->_raw_size;
 
@@ -1664,7 +1669,7 @@ NAME(aout,translate_symbol_table) (abfd, in, ext, count, str, strsize, dynamic)
       in->desc = bfd_h_get_16 (abfd, ext->e_desc);
       in->other = bfd_h_get_8 (abfd, ext->e_other);
       in->type = bfd_h_get_8 (abfd,  ext->e_type);
-      in->symbol.udata = 0;
+      in->symbol.udata.p = NULL;
 
       if (! translate_from_native_sym_flags (abfd, in))
        return false;
@@ -1697,21 +1702,16 @@ NAME(aout,slurp_symbol_table) (abfd)
   if (! aout_get_external_symbols (abfd))
     return false;
 
-  if (obj_aout_external_sym_count (abfd) == 0)
-    {
-      bfd_set_error (bfd_error_no_symbols);
-      return false;
-    }
-
   cached_size = (obj_aout_external_sym_count (abfd)
                 * sizeof (aout_symbol_type));
   cached = (aout_symbol_type *) malloc (cached_size);
-  if (cached == NULL)
+  if (cached == NULL && cached_size != 0)
     {
       bfd_set_error (bfd_error_no_memory);
       return false;
     }
-  memset (cached, 0, cached_size);
+  if (cached_size != 0)
+    memset (cached, 0, cached_size);
 
   /* Convert from external symbol information to internal.  */
   if (! (NAME(aout,translate_symbol_table)
@@ -3980,10 +3980,12 @@ aout_link_write_other_symbol (h, data)
 
   h->written = true;
 
-  if (finfo->info->strip == strip_all
-      || (finfo->info->strip == strip_some
-         && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
-                             false, false) == NULL))
+  /* An indx of -2 means the symbol must be written.  */
+  if (h->indx != -2
+      && (finfo->info->strip == strip_all
+         || (finfo->info->strip == strip_some
+             && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
+                                 false, false) == NULL)))
     return true;
 
   switch (h->root.type)
@@ -4308,15 +4310,35 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
 
                  if (r_index == -1)
                    {
-                     const char *name;
-
-                     name = strings + GET_WORD (input_bfd,
-                                                syms[r_index].e_strx);
-                     if (! ((*finfo->info->callbacks->unattached_reloc)
-                            (finfo->info, name, input_bfd, input_section,
-                             r_addr)))
-                       return false;
-                     r_index = 0;
+                     if (h != NULL)
+                       {
+                         /* We decided to strip this symbol, but it
+                             turns out that we can't.  Note that we
+                             lose the other and desc information here.
+                             I don't think that will ever matter for a
+                             global symbol.  */
+                         if (h->indx < 0)
+                           {
+                             h->indx = -2;
+                             h->written = false;
+                             if (! aout_link_write_other_symbol (h,
+                                                                 (PTR) finfo))
+                               return false;
+                           }
+                         r_index = h->indx;
+                       }
+                     else
+                       {
+                         const char *name;
+
+                         name = strings + GET_WORD (input_bfd,
+                                                    syms[r_index].e_strx);
+                         if (! ((*finfo->info->callbacks->unattached_reloc)
+                                (finfo->info, name, input_bfd, input_section,
+                                 r_addr)))
+                           return false;
+                         r_index = 0;
+                       }
                    }
 
                  relocation = 0;
@@ -4597,15 +4619,35 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
 
                  if (r_index == -1)
                    {
-                     const char *name;
-
-                     name = (strings
-                             + GET_WORD (input_bfd, syms[r_index].e_strx));
-                     if (! ((*finfo->info->callbacks->unattached_reloc)
-                            (finfo->info, name, input_bfd, input_section,
-                             r_addr)))
-                       return false;
-                     r_index = 0;
+                     if (h != NULL)
+                       {
+                         /* We decided to strip this symbol, but it
+                             turns out that we can't.  Note that we
+                             lose the other and desc information here.
+                             I don't think that will ever matter for a
+                             global symbol.  */
+                         if (h->indx < 0)
+                           {
+                             h->indx = -2;
+                             h->written = false;
+                             if (! aout_link_write_other_symbol (h,
+                                                                 (PTR) finfo))
+                               return false;
+                           }
+                         r_index = h->indx;
+                       }
+                     else
+                       {
+                         const char *name;
+
+                         name = strings + GET_WORD (input_bfd,
+                                                    syms[r_index].e_strx);
+                         if (! ((*finfo->info->callbacks->unattached_reloc)
+                                (finfo->info, name, input_bfd, input_section,
+                                 r_addr)))
+                           return false;
+                         r_index = 0;
+                       }
                    }
 
                  relocation = 0;
@@ -4827,8 +4869,20 @@ aout_link_reloc_link_order (finfo, o, p)
       h = aout_link_hash_lookup (aout_hash_table (finfo->info),
                                 pr->u.name, false, false, true);
       if (h != (struct aout_link_hash_entry *) NULL
-         && h->indx == -1)
+         && h->indx >= 0)
        r_index = h->indx;
+      else if (h != NULL)
+       {
+         /* We decided to strip this symbol, but it turns out that we
+            can't.  Note that we lose the other and desc information
+            here.  I don't think that will ever matter for a global
+            symbol.  */
+         h->indx = -2;
+         h->written = false;
+         if (! aout_link_write_other_symbol (h, (PTR) finfo))
+           return false;
+         r_index = h->indx;
+       }
       else
        {
          if (! ((*finfo->info->callbacks->unattached_reloc)
index 8e91d1c7667a3403387fe9f5676a53faf7b7d01a..c6cf11baacd9ec1ab7ed9e4a71ff2120a02868f4 100644 (file)
@@ -305,35 +305,24 @@ bfd            *abfd;
 
 long
 coff_get_symtab (abfd, alocation)
-     bfd            *abfd;
-     asymbol       **alocation;
+     bfd *abfd;
+     asymbol **alocation;
 {
-    unsigned int    counter = 0;
-    coff_symbol_type *symbase;
-    coff_symbol_type **location = (coff_symbol_type **) (alocation);
-    if (!bfd_coff_slurp_symbol_table(abfd))
-     return -1;
-
-    symbase = obj_symbols(abfd);
-    while (counter <  bfd_get_symcount(abfd))
-    {
-       /* This nasty code looks at the symbol to decide whether or
-          not it is descibes a constructor/destructor entry point. It
-          is structured this way to (hopefully) speed non matches */
-#if 0  
-       if (0 && symbase->symbol.name[9] == '$') 
-       {
-           bfd_constructor_entry(abfd, 
-                                (asymbol **)location,
-                                 symbase->symbol.name[10] == 'I' ?
-                                 "CTOR" : "DTOR");
-       }
-#endif
-       *(location++) = symbase++;
-       counter++;
-    }
-    *location++ = 0;
-    return bfd_get_symcount(abfd);
+  unsigned int counter;
+  coff_symbol_type *symbase;
+  coff_symbol_type **location = (coff_symbol_type **) alocation;
+
+  if (! bfd_coff_slurp_symbol_table (abfd))
+    return -1;
+
+  symbase = obj_symbols (abfd);
+  counter = bfd_get_symcount (abfd);
+  while (counter-- > 0)
+    *location++ = symbase++;
+
+  *location = NULL;
+
+  return bfd_get_symcount (abfd);
 }
 
 /* Set lineno_count for the output sections of a COFF file.  */
@@ -676,7 +665,7 @@ coff_fix_symbol_name (abfd, symbol, native)
    the relocs we can get the index for a symbol.  This method is a
    hack.  FIXME.  */
 
-#define set_index(symbol, idx) ((symbol)->udata = (PTR) (idx))
+#define set_index(symbol, idx) ((symbol)->udata.i = (idx))
 
 /* Write a symbol out to a COFF file.  */
 
@@ -928,6 +917,8 @@ coff_write_symbols (abfd)
        }
     }
 
+  obj_raw_syment_count (abfd) = written;
+
   /* Now write out strings */
 
   if (string_size != 0)
@@ -1280,20 +1271,14 @@ coff_get_normalized_symtab (abfd)
   char           *string_table = NULL;
   char          *debug_section = NULL;
   unsigned long   size;
-
   unsigned int raw_size;
-  if (obj_raw_syments(abfd) != (combined_entry_type *)NULL) {
-      return obj_raw_syments(abfd);
-    }
-  size = obj_raw_syment_count (abfd) * sizeof (combined_entry_type);
-  if (size == 0)
-    {
-      bfd_set_error (bfd_error_no_symbols);
-      return (NULL);
-    }
 
-  internal = (combined_entry_type *)bfd_alloc(abfd, size);
-  if (!internal)
+  if (obj_raw_syments (abfd) != NULL)
+    return obj_raw_syments (abfd);
+
+  size = obj_raw_syment_count (abfd) * sizeof (combined_entry_type);
+  internal = (combined_entry_type *) bfd_alloc (abfd, size);
+  if (internal == NULL && size != 0)
     {
       bfd_set_error (bfd_error_no_memory);
       return NULL;
@@ -1301,19 +1286,21 @@ coff_get_normalized_symtab (abfd)
   internal_end = internal + obj_raw_syment_count (abfd);
 
   symesz = bfd_coff_symesz (abfd);
-  raw_size =      obj_raw_syment_count (abfd) * symesz;
-  raw = bfd_alloc(abfd,raw_size);
-  if (!raw)
+  raw_size = obj_raw_syment_count (abfd) * symesz;
+  raw = bfd_alloc (abfd, raw_size);
+  if (raw == NULL && raw_size != 0)
     {
       bfd_set_error (bfd_error_no_memory);
       return NULL;
     }
 
-  if (bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET) == -1
-      || bfd_read(raw, raw_size, 1, abfd) != raw_size)
-      return (NULL);
+  if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) == -1
+      || bfd_read (raw, raw_size, 1, abfd) != raw_size)
+    return NULL;
+
   /* mark the end of the symbols */
   raw_end = (char *) raw + obj_raw_syment_count (abfd) * symesz;
+
   /*
     FIXME SOMEDAY.  A string table size of zero is very weird, but
     probably possible.  If one shows up, it will probably kill us.
@@ -1363,7 +1350,8 @@ coff_get_normalized_symtab (abfd)
     }
 
   /* Free all the raw stuff */
-  bfd_release(abfd, raw);
+  if (raw != NULL)
+    bfd_release (abfd, raw);
 
   for (internal_ptr = internal; internal_ptr < internal_end;
        internal_ptr ++)