Add OpenRISC support
[deliverable/binutils-gdb.git] / bfd / nlmcode.h
index a53c67b691c50b0388fe7286630db12cc1790fff..04ba2a0281714d0ab7af7d3b64a725d4429f4b75 100644 (file)
@@ -1,5 +1,5 @@
 /* NLM (NetWare Loadable Module) executable support for BFD.
-   Copyright (C) 1993 Free Software Foundation, Inc.
+   Copyright 1993, 1994, 1995, 1998, 2000 Free Software Foundation, Inc.
 
    Written by Fred Fish @ Cygnus Support, using ELF support as the
    template.
@@ -18,9 +18,8 @@ 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 <string.h>            /* For strrchr and friends */
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
@@ -53,9 +52,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define nlm_write_object_contents      nlmNAME(write_object_contents)
 
 #define nlm_swap_fixed_header_in(abfd,src,dst) \
-  (nlm_swap_fixed_header_in_func(abfd))(abfd,src,dst)
+  (nlm_swap_fixed_header_in_func(abfd)) (abfd,src,dst)
 #define nlm_swap_fixed_header_out(abfd,src,dst) \
-  (nlm_swap_fixed_header_out_func(abfd))(abfd,src,dst)
+  (nlm_swap_fixed_header_out_func(abfd)) (abfd,src,dst)
 
 /* Forward declarations of static functions */
 
@@ -114,12 +113,9 @@ nlm_object_p (abfd)
 
   /* Read in the fixed length portion of the NLM header in external format.  */
 
-  x_fxdhdr = (PTR) malloc (nlm_fixed_header_size (abfd));
+  x_fxdhdr = (PTR) bfd_malloc ((size_t) nlm_fixed_header_size (abfd));
   if (x_fxdhdr == NULL)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      goto got_no_match;
-    }
+    goto got_no_match;
 
   if (bfd_read ((PTR) x_fxdhdr, nlm_fixed_header_size (abfd), 1, abfd) !=
       nlm_fixed_header_size (abfd))
@@ -136,10 +132,7 @@ nlm_object_p (abfd)
   new_tdata = ((struct nlm_obj_tdata *)
               bfd_zalloc (abfd, sizeof (struct nlm_obj_tdata)));
   if (new_tdata == NULL)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      goto got_no_match;
-    }
+    goto got_no_match;
 
   nlm_tdata (abfd) = new_tdata;
 
@@ -149,7 +142,7 @@ nlm_object_p (abfd)
   x_fxdhdr = NULL;
 
   /* Check to see if we have an NLM file for this backend by matching
-     the NLM signature. */
+     the NLM signature.  */
 
   signature = nlm_signature (abfd);
   if (signature != NULL
@@ -230,7 +223,7 @@ got_no_match:
   return (NULL);
 }
 
-/* Add a section to the bfd. */
+/* Add a section to the bfd.  */
 
 static boolean
 add_bfd_section (abfd, name, offset, size, flags)
@@ -247,7 +240,7 @@ add_bfd_section (abfd, name, offset, size, flags)
     {
       return (false);
     }
-  newsect->vma = 0;            /* NLM's are relocatable. */
+  newsect->vma = 0;            /* NLM's are relocatable.  */
   newsect->_raw_size = size;
   newsect->filepos = offset;
   newsect->flags = flags;
@@ -256,7 +249,7 @@ add_bfd_section (abfd, name, offset, size, flags)
 }
 
 /* Read and swap in the variable length header.  All the fields must
-   exist in the NLM, and must exist in the order they are read here. */
+   exist in the NLM, and must exist in the order they are read here.  */
 
 static boolean
 nlm_swap_variable_header_in (abfd)
@@ -264,7 +257,7 @@ nlm_swap_variable_header_in (abfd)
 {
   unsigned char temp[NLM_TARGET_LONG_SIZE];
 
-  /* Read the description length and text members. */
+  /* Read the description length and text members.  */
 
   if (bfd_read ((PTR) & nlm_variable_header (abfd)->descriptionLength,
                sizeof (nlm_variable_header (abfd)->descriptionLength),
@@ -274,22 +267,22 @@ nlm_swap_variable_header_in (abfd)
   if (bfd_read ((PTR) nlm_variable_header (abfd)->descriptionText,
                nlm_variable_header (abfd)->descriptionLength + 1,
                1, abfd) !=
-      nlm_variable_header (abfd)->descriptionLength + 1)
+      (bfd_size_type) nlm_variable_header (abfd)->descriptionLength + 1)
     return (false);
 
-  /* Read and convert the stackSize field. */
+  /* Read and convert the stackSize field.  */
 
   if (bfd_read ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
     return (false);
   nlm_variable_header (abfd)->stackSize = get_word (abfd, (bfd_byte *) temp);
 
-  /* Read and convert the reserved field. */
+  /* Read and convert the reserved field.  */
 
   if (bfd_read ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
     return (false);
   nlm_variable_header (abfd)->reserved = get_word (abfd, (bfd_byte *) temp);
 
-  /* Read the oldThreadName field.  This field is a fixed length string. */
+  /* Read the oldThreadName field.  This field is a fixed length string.  */
 
   if (bfd_read ((PTR) nlm_variable_header (abfd)->oldThreadName,
                sizeof (nlm_variable_header (abfd)->oldThreadName),
@@ -297,7 +290,7 @@ nlm_swap_variable_header_in (abfd)
       sizeof (nlm_variable_header (abfd)->oldThreadName))
     return (false);
 
-  /* Read the screen name length and text members. */
+  /* Read the screen name length and text members.  */
 
   if (bfd_read ((PTR) & nlm_variable_header (abfd)->screenNameLength,
                sizeof (nlm_variable_header (abfd)->screenNameLength),
@@ -307,10 +300,10 @@ nlm_swap_variable_header_in (abfd)
   if (bfd_read ((PTR) nlm_variable_header (abfd)->screenName,
                nlm_variable_header (abfd)->screenNameLength + 1,
                1, abfd) !=
-      nlm_variable_header (abfd)->screenNameLength + 1)
+      (bfd_size_type) nlm_variable_header (abfd)->screenNameLength + 1)
     return (false);
 
-  /* Read the thread name length and text members. */
+  /* Read the thread name length and text members.  */
 
   if (bfd_read ((PTR) & nlm_variable_header (abfd)->threadNameLength,
                sizeof (nlm_variable_header (abfd)->threadNameLength),
@@ -320,7 +313,7 @@ nlm_swap_variable_header_in (abfd)
   if (bfd_read ((PTR) nlm_variable_header (abfd)->threadName,
                nlm_variable_header (abfd)->threadNameLength + 1,
                1, abfd) !=
-      nlm_variable_header (abfd)->threadNameLength + 1)
+      (bfd_size_type) nlm_variable_header (abfd)->threadNameLength + 1)
     return (false);
   return (true);
 }
@@ -334,7 +327,7 @@ nlm_swap_variable_header_out (abfd)
 {
   unsigned char temp[NLM_TARGET_LONG_SIZE];
 
-  /* Write the description length and text members. */
+  /* Write the description length and text members.  */
 
   if (bfd_write ((PTR) & nlm_variable_header (abfd)->descriptionLength,
                 sizeof (nlm_variable_header (abfd)->descriptionLength),
@@ -344,24 +337,24 @@ nlm_swap_variable_header_out (abfd)
   if (bfd_write ((PTR) nlm_variable_header (abfd)->descriptionText,
                 nlm_variable_header (abfd)->descriptionLength + 1,
                 1, abfd) !=
-      nlm_variable_header (abfd)->descriptionLength + 1)
+      (bfd_size_type) nlm_variable_header (abfd)->descriptionLength + 1)
     return (false);
 
-  /* Convert and write the stackSize field. */
+  /* Convert and write the stackSize field.  */
 
   put_word (abfd, (bfd_vma) nlm_variable_header (abfd)->stackSize,
            (bfd_byte *) temp);
   if (bfd_write ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
     return (false);
 
-  /* Convert and write the reserved field. */
+  /* Convert and write the reserved field.  */
 
   put_word (abfd, (bfd_vma) nlm_variable_header (abfd)->reserved,
            (bfd_byte *) temp);
   if (bfd_write ((PTR) temp, sizeof (temp), 1, abfd) != sizeof (temp))
     return (false);
 
-  /* Write the oldThreadName field.  This field is a fixed length string. */
+  /* Write the oldThreadName field.  This field is a fixed length string.  */
 
   if (bfd_write ((PTR) nlm_variable_header (abfd)->oldThreadName,
                 sizeof (nlm_variable_header (abfd)->oldThreadName),
@@ -369,7 +362,7 @@ nlm_swap_variable_header_out (abfd)
       sizeof (nlm_variable_header (abfd)->oldThreadName))
     return (false);
 
-  /* Write the screen name length and text members. */
+  /* Write the screen name length and text members.  */
 
   if (bfd_write ((PTR) & nlm_variable_header (abfd)->screenNameLength,
                 sizeof (nlm_variable_header (abfd)->screenNameLength),
@@ -379,10 +372,10 @@ nlm_swap_variable_header_out (abfd)
   if (bfd_write ((PTR) nlm_variable_header (abfd)->screenName,
                 nlm_variable_header (abfd)->screenNameLength + 1,
                 1, abfd) !=
-      nlm_variable_header (abfd)->screenNameLength + 1)
+      (bfd_size_type) nlm_variable_header (abfd)->screenNameLength + 1)
     return (false);
 
-  /* Write the thread name length and text members. */
+  /* Write the thread name length and text members.  */
 
   if (bfd_write ((PTR) & nlm_variable_header (abfd)->threadNameLength,
                 sizeof (nlm_variable_header (abfd)->threadNameLength),
@@ -392,7 +385,7 @@ nlm_swap_variable_header_out (abfd)
   if (bfd_write ((PTR) nlm_variable_header (abfd)->threadName,
                 nlm_variable_header (abfd)->threadNameLength + 1,
                 1, abfd) !=
-      nlm_variable_header (abfd)->threadNameLength + 1)
+      (bfd_size_type) nlm_variable_header (abfd)->threadNameLength + 1)
     return (false);
   return (true);
 }
@@ -404,7 +397,7 @@ nlm_swap_variable_header_out (abfd)
    of the auxiliary headers are, except by finding something that doesn't
    look like a known auxiliary header.  This means that the first new type
    of auxiliary header added will break all existing tools that don't
-   recognize it. */
+   recognize it.  */
 
 static boolean
 nlm_swap_auxiliary_headers_in (abfd)
@@ -518,11 +511,12 @@ nlm_swap_auxiliary_headers_in (abfd)
                                 ->copyrightMessageLength),
                        1, 1, abfd) != 1)
            return (false);
-         /* The copyright message is a variable length string. */
+         /* The copyright message is a variable length string.  */
          if (bfd_read ((PTR) nlm_copyright_header (abfd)->copyrightMessage,
                    nlm_copyright_header (abfd)->copyrightMessageLength + 1,
                        1, abfd) !=
-             nlm_copyright_header (abfd)->copyrightMessageLength + 1)
+             ((bfd_size_type)
+              nlm_copyright_header (abfd)->copyrightMessageLength + 1))
            return (false);
        }
       else if (strncmp (tempstr, "CuStHeAd", 8) == 0)
@@ -584,10 +578,7 @@ nlm_swap_auxiliary_headers_in (abfd)
              hdrLength -= 2 * NLM_TARGET_LONG_SIZE + 8;
              hdr = bfd_alloc (abfd, hdrLength);
              if (hdr == NULL)
-               {
-                 bfd_set_error (bfd_error_no_memory);
-                 return false;
-               }
+               return false;
              if (bfd_read (hdr, 1, hdrLength, abfd) != hdrLength)
                return false;
            }
@@ -608,10 +599,7 @@ nlm_swap_auxiliary_headers_in (abfd)
                return false;
              contents = (bfd_byte *) bfd_alloc (abfd, dataLength);
              if (contents == NULL)
-               {
-                 bfd_set_error (bfd_error_no_memory);
-                 return false;
-               }
+               return false;
              if (bfd_read (contents, 1, dataLength, abfd) != dataLength)
                return false;
              if (bfd_seek (abfd, pos, SEEK_SET) != 0)
@@ -832,7 +820,6 @@ nlm_swap_auxiliary_headers_out (abfd)
        return false;
     }
 
-
   /* Write out the copyright header if there is one.  */
   if (find_nonzero ((PTR) nlm_copyright_header (abfd),
                    sizeof (Nlm_Internal_Copyright_Header)))
@@ -847,11 +834,12 @@ nlm_swap_auxiliary_headers_out (abfd)
        nlm_copyright_header (abfd)->copyrightMessageLength;
       if (bfd_write ((PTR) thdr.copyrightMessageLength, 1, 1, abfd) != 1)
        return false;
-      /* The copyright message is a variable length string. */
+      /* The copyright message is a variable length string.  */
       if (bfd_write ((PTR) nlm_copyright_header (abfd)->copyrightMessage,
                     nlm_copyright_header (abfd)->copyrightMessageLength + 1,
                     1, abfd) !=
-         nlm_copyright_header (abfd)->copyrightMessageLength + 1)
+         ((bfd_size_type)
+          nlm_copyright_header (abfd)->copyrightMessageLength + 1))
        return false;
     }
 
@@ -922,7 +910,7 @@ nlm_swap_auxiliary_headers_out (abfd)
 
    Return the number of bytes required to hold the symtab vector, based on
    the count plus 1, since we will NULL terminate the vector allocated based
-   on this size. */
+   on this size.  */
 
 long
 nlm_get_symtab_upper_bound (abfd)
@@ -941,7 +929,7 @@ nlm_get_symtab_upper_bound (abfd)
 }
 
 /* Note that bfd_get_symcount is guaranteed to be zero if slurping the
-   symbol table fails. */
+   symbol table fails.  */
 
 long
 nlm_get_symtab (abfd, alocation)
@@ -982,7 +970,7 @@ nlm_make_empty_symbol (abfd)
 
 void
 nlm_get_symbol_info (ignore_abfd, symbol, ret)
-     bfd *ignore_abfd;
+     bfd *ignore_abfd ATTRIBUTE_UNUSED;
      asymbol *symbol;
      symbol_info *ret;
 {
@@ -993,7 +981,7 @@ nlm_get_symbol_info (ignore_abfd, symbol, ret)
 
 void
 nlm_print_symbol (abfd, afile, symbol, how)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      PTR afile;
      asymbol *symbol;
      bfd_print_symbol_type how;
@@ -1059,7 +1047,7 @@ nlm_slurp_symbol_table (abfd)
      Note that we allocate the initial bfd canonical symbol buffer based on a
      one-to-one mapping of the NLM symbols to canonical symbols.  We actually
      use all the NLM symbols, so there will be no space left over at the end.
-     When we have all the symbols, we build the caller's pointer vector. */
+     When we have all the symbols, we build the caller's pointer vector.  */
 
   abfd->symcount = 0;
   i_fxdhdrp = nlm_fixed_header (abfd);
@@ -1077,15 +1065,12 @@ nlm_slurp_symbol_table (abfd)
   sym = ((nlm_symbol_type *)
         bfd_zalloc (abfd, totsymcount * sizeof (nlm_symbol_type)));
   if (!sym)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      return false;
-    }
+    return false;
   nlm_set_symbols (abfd, sym);
 
   /* We use the bfd's symcount directly as the control count, so that early
      termination of the loop leaves the symcount correct for the symbols that
-     were read. */
+     were read.  */
 
   set_public_section_func = nlm_set_public_section_func (abfd);
   symcount = i_fxdhdrp->numberOfPublics;
@@ -1097,10 +1082,7 @@ nlm_slurp_symbol_table (abfd)
       sym->symbol.the_bfd = abfd;
       sym->symbol.name = bfd_alloc (abfd, symlength + 1);
       if (!sym->symbol.name)
-       {
-         bfd_set_error (bfd_error_no_memory);
-         return false;
-       }
+       return false;
       if (bfd_read ((PTR) sym->symbol.name, symlength, 1, abfd)
          != symlength)
        return (false);
@@ -1156,10 +1138,7 @@ nlm_slurp_symbol_table (abfd)
          sym->symbol.the_bfd = abfd;
          sym->symbol.name = bfd_alloc (abfd, symlength + 1);
          if (!sym->symbol.name)
-           {
-             bfd_set_error (bfd_error_no_memory);
-             return false;
-           }
+           return false;
          if (bfd_read ((PTR) sym->symbol.name, symlength, 1, abfd)
              != symlength)
            return (false);
@@ -1180,7 +1159,7 @@ nlm_slurp_symbol_table (abfd)
            }
          else
            {
-             sym->symbol.section = &bfd_abs_section;
+             sym->symbol.section = bfd_abs_section_ptr;
            }
          sym->rcnt = 0;
          abfd->symcount++;
@@ -1248,10 +1227,7 @@ nlm_slurp_reloc_fixups (abfd)
   rels = (arelent *) bfd_alloc (abfd, count * sizeof (arelent));
   secs = (asection **) bfd_alloc (abfd, count * sizeof (asection *));
   if ((rels == NULL || secs == NULL) && count != 0)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      return false;
-    }
+    return false;
   nlm_relocation_fixups (abfd) = rels;
   nlm_relocation_fixup_secs (abfd) = secs;
 
@@ -1402,7 +1378,7 @@ nlm_compute_section_file_positions (abfd)
   asection *sec;
   bfd_vma text, data, bss;
   bfd_vma text_low, data_low;
-  int text_align, data_align, other_align;
+  unsigned int text_align, data_align, other_align;
   file_ptr text_ptr, data_ptr, other_ptr;
   asection *bss_sec;
   asymbol **sym_ptr_ptr;
@@ -1704,12 +1680,10 @@ nlm_write_object_contents (abfd)
   boolean (*write_prefix_func) PARAMS ((bfd *));
   unsigned char *fixed_header = NULL;
 
-  fixed_header = (unsigned char *) malloc (nlm_fixed_header_size (abfd));
+  fixed_header = ((unsigned char *)
+                 bfd_malloc ((size_t) nlm_fixed_header_size (abfd)));
   if (fixed_header == NULL)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      goto error_return;
-    }
+    goto error_return;
 
   if (abfd->output_has_begun == false
       && nlm_compute_section_file_positions (abfd) == false)
@@ -1779,7 +1753,7 @@ nlm_write_object_contents (abfd)
          rel = *rel_ptr_ptr;
          sym = *rel->sym_ptr_ptr;
 
-         if (bfd_get_section (sym) != &bfd_und_section)
+         if (! bfd_is_und_section (bfd_get_section (sym)))
            {
              ++internal_reloc_count;
              if ((*write_import_func) (abfd, sec, rel) == false)
@@ -1800,10 +1774,7 @@ nlm_write_object_contents (abfd)
                                        (external_reloc_count
                                         * sizeof (struct reloc_and_sec)));
   if (external_relocs == (struct reloc_and_sec *) NULL)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      goto error_return;
-    }
+    goto error_return;
   i = 0;
   for (sec = abfd->sections; sec != (asection *) NULL; sec = sec->next)
     {
@@ -1822,7 +1793,7 @@ nlm_write_object_contents (abfd)
          rel = *rel_ptr_ptr;
          sym = *rel->sym_ptr_ptr;
 
-         if (bfd_get_section (sym) != &bfd_und_section)
+         if (! bfd_is_und_section (bfd_get_section (sym)))
            continue;
 
          external_relocs[i].rel = rel;
@@ -1893,7 +1864,7 @@ nlm_write_object_contents (abfd)
          sym = *sym_ptr_ptr;
 
          if ((sym->flags & (BSF_EXPORT | BSF_GLOBAL)) == 0
-             || bfd_get_section (sym) == &bfd_und_section)
+             || bfd_is_und_section (bfd_get_section (sym)))
            continue;
 
          ++c;
@@ -1978,7 +1949,7 @@ nlm_write_object_contents (abfd)
                 debugging symbol NLM does not understand at all.  */
              if ((sym->flags & (BSF_LOCAL | BSF_GLOBAL | BSF_EXPORT)) == 0
                  || (sym->flags & BSF_DEBUGGING) != 0
-                 || bfd_get_section (sym) == &bfd_und_section)
+                 || bfd_is_und_section (bfd_get_section (sym)))
                continue;
 
              ++c;
@@ -2065,7 +2036,8 @@ nlm_write_object_contents (abfd)
        goto error_return;
     }
 
-  BFD_ASSERT (bfd_tell (abfd) == nlm_optional_prefix_size (abfd));
+  BFD_ASSERT ((bfd_size_type) bfd_tell (abfd)
+             == nlm_optional_prefix_size (abfd));
 
   nlm_swap_fixed_header_out (abfd, nlm_fixed_header (abfd), fixed_header);
   if (bfd_write (fixed_header, nlm_fixed_header_size (abfd), 1, abfd)
This page took 0.03058 seconds and 4 git commands to generate.