s/struct _serial_t/struct serial/
[deliverable/binutils-gdb.git] / bfd / bfd.c
index 5a23c5d690f406cbd8245cf3345273ff2b83bd18..0c2cc0cbef9c8d64e7b36cc49872cd7a165222b2 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1,5 +1,7 @@
 /* Generic BFD library interface and support routines.
-   Copyright (C) 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+   2000, 2001
+   Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -32,10 +34,10 @@ SECTION
 
 CODE_FRAGMENT
 .
-.struct _bfd 
+.struct _bfd
 .{
 .    {* The filename the application opened the BFD with.  *}
-.    CONST char *filename;                
+.    CONST char *filename;
 .
 .    {* A pointer to the target jump table.             *}
 .    const struct bfd_target *xvec;
@@ -68,7 +70,7 @@ CODE_FRAGMENT
 .    {* When a file is closed by the caching routines, BFD retains
 .       state information on the file here: *}
 .
-.    file_ptr where;              
+.    file_ptr where;
 .
 .    {* and here: (``once'' means at least once) *}
 .
@@ -81,7 +83,7 @@ CODE_FRAGMENT
 .
 .    {* File modified time, if mtime_set is true: *}
 .
-.    long mtime;          
+.    long mtime;
 .
 .    {* Reserved for an unimplemented file locking extension.*}
 .
@@ -100,13 +102,13 @@ CODE_FRAGMENT
 .
 .    {* Format_specific flags*}
 .
-.    flagword flags;              
+.    flagword flags;
 .
 .    {* Currently my_archive is tested before adding origin to
 .       anything. I believe that this can become always an add of
 .       origin, with origin set to 0 for non archive files.   *}
 .
-.    file_ptr origin;             
+.    file_ptr origin;
 .
 .    {* Remember when output has begun, to stop strange things
 .       from happening. *}
@@ -118,7 +120,7 @@ CODE_FRAGMENT
 .    {* The number of sections *}
 .    unsigned int section_count;
 .
-.    {* Stuff only useful for object files: 
+.    {* Stuff only useful for object files:
 .       The start address. *}
 .    bfd_vma start_address;
 .
@@ -126,17 +128,17 @@ CODE_FRAGMENT
 .    unsigned int symcount;
 .
 .    {* Symbol table for output BFD (with symcount entries) *}
-.    struct symbol_cache_entry  **outsymbols;             
+.    struct symbol_cache_entry  **outsymbols;
 .
 .    {* Pointer to structure which contains architecture information*}
 .    const struct bfd_arch_info *arch_info;
 .
 .    {* Stuff only useful for archives:*}
-.    PTR arelt_data;              
+.    PTR arelt_data;
 .    struct _bfd *my_archive;     {* The containing archive BFD.  *}
 .    struct _bfd *next;           {* The next BFD in the archive.  *}
 .    struct _bfd *archive_head;   {* The first BFD in the archive.  *}
-.    boolean has_armap;           
+.    boolean has_armap;
 .
 .    {* A chain of BFD structures involved in a link.  *}
 .    struct _bfd *link_next;
@@ -147,7 +149,7 @@ CODE_FRAGMENT
 .
 .    {* Used by the back end to hold private data. *}
 .
-.    union 
+.    union
 .      {
 .      struct aout_data_struct *aout_data;
 .      struct artdata *aout_ar_data;
@@ -166,6 +168,7 @@ CODE_FRAGMENT
 .      struct nlm_obj_tdata *nlm_obj_data;
 .      struct bout_data_struct *bout_data;
 .      struct sun_core_struct *sun_core_data;
+.      struct sco5_core_struct *sco5_core_data;
 .      struct trad_core_struct *trad_core_data;
 .      struct som_data_struct *som_data;
 .      struct hpux_core_struct *hpux_core_data;
@@ -178,12 +181,14 @@ CODE_FRAGMENT
 .      struct netbsd_core_struct *netbsd_core_data;
 .      PTR any;
 .      } tdata;
-.  
+.
 .    {* Used by the application to hold private data*}
 .    PTR usrdata;
 .
-.    {* Where all the allocated stuff under this BFD goes *}
-.    struct obstack memory;
+.  {* Where all the allocated stuff under this BFD goes.  This is a
+.     struct objalloc *, but we use PTR to avoid requiring the inclusion of
+.     objalloc.h.  *}
+.    PTR memory;
 .};
 .
 */
@@ -197,6 +202,7 @@ CODE_FRAGMENT
 #include <varargs.h>
 #endif
 
+#include "libiberty.h"
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "coff/internal.h"
@@ -213,8 +219,6 @@ CODE_FRAGMENT
    struct which ultimately gets passed in to the bfd.  When it arrives, copy
    it to the following struct so that the data will be available in coffcode.h
    where it is needed.  The typedef's used are defined in bfd.h */
-
-
 \f
 /*
 SECTION
@@ -263,31 +267,28 @@ CODE_FRAGMENT
 .
 */
 
-#undef strerror
-extern char *strerror();
-
 static bfd_error_type bfd_error = bfd_error_no_error;
 
 CONST char *CONST bfd_errmsgs[] = {
-                        "No error",
-                        "System call error",
-                        "Invalid bfd target",
-                        "File in wrong format",
-                        "Invalid operation",
-                        "Memory exhausted",
-                        "No symbols",
-                       "Archive has no index; run ranlib to add one",
-                        "No more archived files",
-                        "Malformed archive",
-                        "File format not recognized",
-                        "File format is ambiguous",
-                        "Section has no contents",
-                        "Nonrepresentable section on output",
-                       "Symbol needs debug section which does not exist",
-                       "Bad value",
-                       "File truncated",
-                       "File too big",
-                        "#<Invalid error code>"
+                        N_("No error"),
+                        N_("System call error"),
+                        N_("Invalid bfd target"),
+                        N_("File in wrong format"),
+                        N_("Invalid operation"),
+                        N_("Memory exhausted"),
+                        N_("No symbols"),
+                       N_("Archive has no index; run ranlib to add one"),
+                        N_("No more archived files"),
+                        N_("Malformed archive"),
+                        N_("File format not recognized"),
+                        N_("File format is ambiguous"),
+                        N_("Section has no contents"),
+                        N_("Nonrepresentable section on output"),
+                       N_("Symbol needs debug section which does not exist"),
+                       N_("Bad value"),
+                       N_("File truncated"),
+                       N_("File too big"),
+                        N_("#<Invalid error code>")
                        };
 
 /*
@@ -345,13 +346,13 @@ bfd_errmsg (error_tag)
   extern int errno;
 #endif
   if (error_tag == bfd_error_system_call)
-    return strerror (errno);
+    return xstrerror (errno);
 
   if ((((int)error_tag <(int) bfd_error_no_error) ||
        ((int)error_tag > (int)bfd_error_invalid_error_code)))
     error_tag = bfd_error_invalid_error_code;/* sanity check */
 
-  return bfd_errmsgs [(int)error_tag];
+  return _(bfd_errmsgs [(int)error_tag]);
 }
 
 /*
@@ -374,7 +375,7 @@ bfd_perror (message)
      CONST char *message;
 {
   if (bfd_get_error () == bfd_error_system_call)
-    perror((char *)message);            /* must be system error then... */
+    perror((char *)message);            /* must be system error then...  */
   else {
     if (message == NULL || *message == '\0')
       fprintf (stderr, "%s\n", bfd_errmsg (bfd_get_error ()));
@@ -416,6 +417,8 @@ _bfd_default_error_handler (const char *s, ...)
 
   if (_bfd_error_program_name != NULL)
     fprintf (stderr, "%s: ", _bfd_error_program_name);
+  else
+    fprintf (stderr, "BFD: ");
 
   va_start (p, s);
 
@@ -439,6 +442,8 @@ _bfd_default_error_handler (va_alist)
 
   if (_bfd_error_program_name != NULL)
     fprintf (stderr, "%s: ", _bfd_error_program_name);
+  else
+    fprintf (stderr, "BFD: ");
 
   va_start (p);
 
@@ -503,6 +508,23 @@ bfd_set_error_program_name (name)
 {
   _bfd_error_program_name = name;
 }
+
+/*
+FUNCTION
+       bfd_get_error_handler
+
+SYNOPSIS
+       bfd_error_handler_type bfd_get_error_handler (void);
+
+DESCRIPTION
+       Return the BFD error handler function.
+*/
+
+bfd_error_handler_type
+bfd_get_error_handler ()
+{
+  return _bfd_error_handler;
+}
 \f
 /*
 SECTION
@@ -523,7 +545,6 @@ DESCRIPTION
 
 */
 
-
 long
 bfd_get_reloc_upper_bound (abfd, asect)
      bfd *abfd;
@@ -560,7 +581,6 @@ DESCRIPTION
        The @var{syms} table is also needed for horrible internal magic
        reasons.
 
-
 */
 long
 bfd_canonicalize_reloc (abfd, asect, location, symbols)
@@ -591,15 +611,15 @@ DESCRIPTION
        The argument @var{abfd} is ignored.
 
 */
-/*ARGSUSED*/
+
 void
 bfd_set_reloc (ignore_abfd, asect, location, count)
-     bfd *ignore_abfd;
+     bfd *ignore_abfd ATTRIBUTE_UNUSED;
      sec_ptr asect;
      arelent **location;
      unsigned int count;
 {
-  asect->orelocation  = location;
+  asect->orelocation = location;
   asect->reloc_count = count;
 }
 
@@ -652,9 +672,104 @@ bfd_assert (file, line)
      const char *file;
      int line;
 {
-  (*_bfd_error_handler) ("bfd assertion fail %s:%d", file, line);
+  (*_bfd_error_handler) (_("bfd assertion fail %s:%d"), file, line);
 }
 
+/* A more or less friendly abort message.  In libbfd.h abort is
+   defined to call this function.  */
+
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
+void
+_bfd_abort (file, line, fn)
+     const char *file;
+     int line;
+     const char *fn;
+{
+  if (fn != NULL)
+    (*_bfd_error_handler)
+      (_("BFD internal error, aborting at %s line %d in %s\n"),
+       file, line, fn);
+  else
+    (*_bfd_error_handler)
+      (_("BFD internal error, aborting at %s line %d\n"),
+       file, line);
+  (*_bfd_error_handler) (_("Please report this bug.\n"));
+  xexit (EXIT_FAILURE);
+}
+
+/*
+FUNCTION
+       bfd_get_arch_size
+
+SYNOPSIS
+       int bfd_get_arch_size (bfd *abfd);
+
+DESCRIPTION
+       Returns the architecture address size, in bits, as determined
+       by the object file's format.  For ELF, this information is
+       included in the header.
+
+RETURNS
+       Returns the arch size in bits if known, <<-1>> otherwise.
+*/
+
+int
+bfd_get_arch_size (abfd)
+     bfd *abfd;
+{
+  if (abfd->xvec->flavour == bfd_target_elf_flavour)
+    return (get_elf_backend_data (abfd))->s->arch_size;
+
+  bfd_set_error (bfd_error_wrong_format);
+  return -1;
+}
+
+/*
+FUNCTION
+       bfd_get_sign_extend_vma
+
+SYNOPSIS
+       int bfd_get_sign_extend_vma (bfd *abfd);
+
+DESCRIPTION
+       Indicates if the target architecture "naturally" sign extends
+       an address.  Some architectures implicitly sign extend address
+       values when they are converted to types larger than the size
+       of an address.  For instance, bfd_get_start_address() will
+       return an address sign extended to fill a bfd_vma when this is
+       the case.
+
+RETURNS
+       Returns <<1>> if the target architecture is known to sign
+       extend addresses, <<0>> if the target architecture is known to
+       not sign extend addresses, and <<-1>> otherwise.
+*/
+
+int
+bfd_get_sign_extend_vma (abfd)
+     bfd *abfd;
+{
+  char *name;
+
+  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+    return (get_elf_backend_data (abfd)->sign_extend_vma);
+
+  name = bfd_get_target (abfd);
+
+  /* Return a proper value for DJGPP COFF (an x86 COFF variant).
+     This function is required for DWARF2 support, but there is
+     no place to store this information in the COFF back end.
+     Should enough other COFF targets add support for DWARF2,
+     a place will have to be found.  Until then, this hack will do.  */
+  if (strncmp (name, "coff-go32", sizeof ("coff-go32") - 1) == 0)
+    return 1;
+
+  bfd_set_error (bfd_error_wrong_format);
+  return -1;
+}
 
 /*
 FUNCTION
@@ -679,7 +794,6 @@ bfd_vma vma;
   return true;
 }
 
-
 /*
 FUNCTION
        bfd_get_mtime
@@ -731,7 +845,7 @@ DESCRIPTION
        Instead, we want to ask questions like "is this NNN byte sized
        object I'm about to try read from file offset YYY reasonable?"
        As as example of where we might do this, some object formats
-       use string tables for which the first <<sizeof(long)>> bytes of the
+       use string tables for which the first <<sizeof (long)>> bytes of the
        table contain the size of the table itself, including the size bytes.
        If an application tries to read what it thinks is one of these
        string tables, without some way to validate the size, and for
@@ -878,7 +992,7 @@ bfd_scan_vma (string, end, base)
   int digit;
 
   /* Let the host do it if possible.  */
-  if (sizeof(bfd_vma) <= sizeof(unsigned long))
+  if (sizeof (bfd_vma) <= sizeof (unsigned long))
     return (bfd_vma) strtoul (string, (char **) end, base);
 
   /* A negative base makes no sense, and we only need to go as high as hex.  */
@@ -902,14 +1016,14 @@ bfd_scan_vma (string, end, base)
       (string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X')))
     string += 2;
   /* XXX should we also skip over "0b" or "0B" if base is 2? */
-    
+
 /* Speed could be improved with a table like hex_value[] in gas.  */
 #define HEX_VALUE(c) \
-  (isxdigit(c) ?                               \
-    (isdigit(c) ?                              \
-      (c - '0') :                              \
-      (10 + c - (islower(c) ? 'a' : 'A'))) :   \
-    42)
+  (isxdigit ((unsigned char) c)                                        \
+   ? (isdigit ((unsigned char) c)                              \
+      ? (c - '0')                                              \
+      : (10 + c - (islower ((unsigned char) c) ? 'a' : 'A')))  \
+   : 42)
 
   for (value = 0; (digit = HEX_VALUE(*string)) < base; string++)
     {
@@ -930,7 +1044,7 @@ SYNOPSIS
        boolean bfd_copy_private_bfd_data(bfd *ibfd, bfd *obfd);
 
 DESCRIPTION
-       Copy private BFD information from the BFD @var{ibfd} to the 
+       Copy private BFD information from the BFD @var{ibfd} to the
        the BFD @var{obfd}.  Return <<true>> on success, <<false>> on error.
        Possible error returns are:
 
@@ -938,7 +1052,7 @@ DESCRIPTION
        Not enough memory exists to create private data for @var{obfd}.
 
 .#define bfd_copy_private_bfd_data(ibfd, obfd) \
-.     BFD_SEND (ibfd, _bfd_copy_private_bfd_data, \
+.     BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
 .              (ibfd, obfd))
 
 */
@@ -951,7 +1065,7 @@ SYNOPSIS
        boolean bfd_merge_private_bfd_data(bfd *ibfd, bfd *obfd);
 
 DESCRIPTION
-       Merge private BFD information from the BFD @var{ibfd} to the 
+       Merge private BFD information from the BFD @var{ibfd} to the
        the output file BFD @var{obfd} when linking.  Return <<true>>
        on success, <<false>> on error.  Possible error returns are:
 
@@ -959,7 +1073,7 @@ DESCRIPTION
        Not enough memory exists to create private data for @var{obfd}.
 
 .#define bfd_merge_private_bfd_data(ibfd, obfd) \
-.     BFD_SEND (ibfd, _bfd_merge_private_bfd_data, \
+.     BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
 .              (ibfd, obfd))
 
 */
@@ -1021,6 +1135,12 @@ DESCRIPTION
 .#define bfd_relax_section(abfd, section, link_info, again) \
 .       BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
 .
+.#define bfd_gc_sections(abfd, link_info) \
+.      BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
+.
+.#define bfd_merge_sections(abfd, link_info) \
+.      BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
+.
 .#define bfd_link_hash_table_create(abfd) \
 .      BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
 .
@@ -1108,7 +1228,7 @@ bfd_record_phdr (abfd, type, flags_valid, flags, at_valid, at,
   m = ((struct elf_segment_map *)
        bfd_alloc (abfd,
                  (sizeof (struct elf_segment_map)
-                  + (count - 1) * sizeof (asection *))));
+                  + ((size_t) count - 1) * sizeof (asection *))));
   if (m == NULL)
     return false;
 
This page took 0.03079 seconds and 4 git commands to generate.