]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/bfd.c
Proper bound check in _bfd_doprnt_scan
[thirdparty/binutils-gdb.git] / bfd / bfd.c
index 26143f91debc21d886b4cf01e8fcf6ba1d46f418..35f748c3f9c69d2443af695d7bff4aea9d702d51 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1,5 +1,5 @@
 /* Generic BFD library interface and support routines.
-   Copyright (C) 1990-2016 Free Software Foundation, Inc.
+   Copyright (C) 1990-2017 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -46,7 +46,7 @@ CODE_FRAGMENT
 .
 .enum bfd_plugin_format
 .  {
-.    bfd_plugin_uknown = 0,
+.    bfd_plugin_unknown = 0,
 .    bfd_plugin_yes = 1,
 .    bfd_plugin_no = 2
 .  };
@@ -180,8 +180,9 @@ CODE_FRAGMENT
 .
 .  {* Flags bits to be saved in bfd_preserve_save.  *}
 .#define BFD_FLAGS_SAVED \
-.  (BFD_IN_MEMORY | BFD_COMPRESS | BFD_DECOMPRESS | BFD_PLUGIN \
-.   | BFD_COMPRESS_GABI | BFD_CONVERT_ELF_COMMON | BFD_USE_ELF_STT_COMMON)
+.  (BFD_IN_MEMORY | BFD_COMPRESS | BFD_DECOMPRESS | BFD_LINKER_CREATED \
+.   | BFD_PLUGIN | BFD_COMPRESS_GABI | BFD_CONVERT_ELF_COMMON \
+.   | BFD_USE_ELF_STT_COMMON)
 .
 .  {* Flags bits which are for BFD use only.  *}
 .#define BFD_FLAGS_FOR_BFD_USE_MASK \
@@ -496,32 +497,47 @@ FUNCTION
        bfd_set_error
 
 SYNOPSIS
-       void bfd_set_error (bfd_error_type error_tag, ...);
+       void bfd_set_error (bfd_error_type error_tag);
 
 DESCRIPTION
        Set the BFD error condition to be @var{error_tag}.
-       If @var{error_tag} is bfd_error_on_input, then this function
-       takes two more parameters, the input bfd where the error
-       occurred, and the bfd_error_type error.
+
+       @var{error_tag} must not be bfd_error_on_input.  Use
+       bfd_set_input_error for input errors instead.
 */
 
 void
-bfd_set_error (bfd_error_type error_tag, ...)
+bfd_set_error (bfd_error_type error_tag)
 {
   bfd_error = error_tag;
-  if (error_tag == bfd_error_on_input)
-    {
-      /* This is an error that occurred during bfd_close when
-        writing an archive, but on one of the input files.  */
-      va_list ap;
-
-      va_start (ap, error_tag);
-      input_bfd = va_arg (ap, bfd *);
-      input_error = (bfd_error_type) va_arg (ap, int);
-      if (input_error >= bfd_error_on_input)
-       abort ();
-      va_end (ap);
-    }
+  if (bfd_error >= bfd_error_on_input)
+    abort ();
+}
+
+/*
+FUNCTION
+       bfd_set_input_error
+
+SYNOPSIS
+       void bfd_set_input_error (bfd *input, bfd_error_type error_tag);
+
+DESCRIPTION
+
+       Set the BFD error condition to be bfd_error_on_input.
+       @var{input} is the input bfd where the error occurred, and
+       @var{error_tag} the bfd_error_type error.
+*/
+
+void
+bfd_set_input_error (bfd *input, bfd_error_type error_tag)
+{
+  /* This is an error that occurred during bfd_close when writing an
+     archive, but on one of the input files.  */
+  bfd_error = bfd_error_on_input;
+  input_bfd = input;
+  input_error = error_tag;
+  if (input_error >= bfd_error_on_input)
+    abort ();
 }
 
 /*
@@ -598,11 +614,11 @@ SUBSECTION
        problem.  They call a BFD error handler function.  This
        function may be overridden by the program.
 
-       The BFD error handler acts like printf.
+       The BFD error handler acts like vprintf.
 
 CODE_FRAGMENT
 .
-.typedef void (*bfd_error_handler_type) (const char *, ...);
+.typedef void (*bfd_error_handler_type) (const char *, va_list);
 .
 */
 
@@ -610,179 +626,539 @@ CODE_FRAGMENT
 
 static const char *_bfd_error_program_name;
 
-/* This is the default routine to handle BFD error messages.
-   Like fprintf (stderr, ...), but also handles some extra format specifiers.
+/* Support for positional parameters.  */
 
-   %A section name from section.  For group components, print group name too.
-   %B file name from bfd.  For archive components, prints archive too.
+union _bfd_doprnt_args
+{
+  int i;
+  long l;
+  long long ll;
+  double d;
+  long double ld;
+  void *p;
+  enum
+  {
+    Int,
+    Long,
+    LongLong,
+    Double,
+    LongDouble,
+    Ptr
+  } type;
+};
 
-   Note - because these two extra format specifiers require special handling
-   they are scanned for and processed in this function, before calling
-   vfprintf.  This means that the *arguments* for these format specifiers
-   must be the first ones in the variable argument list, regardless of where
-   the specifiers appear in the format string.  Thus for example calling
-   this function with a format string of:
+/* This macro and _bfd_doprnt taken from libiberty _doprnt.c, tidied a
+   little and extended to handle '%A', '%B' and positional parameters.
+   'L' as a modifer for integer formats is used for bfd_vma and
+   bfd_size_type args, which vary in size depending on BFD
+   configuration.  */
+
+#define PRINT_TYPE(TYPE, FIELD) \
+  do                                                           \
+    {                                                          \
+      TYPE value = (TYPE) args[arg_no].FIELD;                  \
+      result = fprintf (stream, specifier, value);             \
+    } while (0)
+
+static int
+_bfd_doprnt (FILE *stream, const char *format, union _bfd_doprnt_args *args)
+{
+  const char *ptr = format;
+  char specifier[128];
+  int total_printed = 0;
+  unsigned int arg_count = 0;
 
-      "blah %s blah %A blah %d blah %B"
+  while (*ptr != '\0')
+    {
+      int result;
 
-   would involve passing the arguments as:
+      if (*ptr != '%')
+       {
+         /* While we have regular characters, print them.  */
+         char *end = strchr (ptr, '%');
+         if (end != NULL)
+           result = fprintf (stream, "%.*s", (int) (end - ptr), ptr);
+         else
+           result = fprintf (stream, "%s", ptr);
+         ptr += result;
+       }
+      else if (ptr[1] == '%')
+       {
+         fputc ('%', stream);
+         result = 1;
+         ptr += 2;
+       }
+      else
+       {
+         /* We have a format specifier!  */
+         char *sptr = specifier;
+         int wide_width = 0, short_width = 0;
+         unsigned int arg_no;
 
-      "blah %s blah %A blah %d blah %B",
-        asection_for_the_%A,
-       bfd_for_the_%B,
-       string_for_the_%s,
-       integer_for_the_%d);
- */
+         /* Copy the % and move forward.  */
+         *sptr++ = *ptr++;
 
-void
-_bfd_default_error_handler (const char *fmt, ...)
-{
-  va_list ap;
-  char *bufp;
-  const char *new_fmt, *p;
-  size_t avail = 1000;
-  char buf[1000];
+         /* Check for a positional parameter.  */
+         arg_no = -1u;
+         if (*ptr != '0' && ISDIGIT (*ptr) && ptr[1] == '$')
+           {
+             arg_no = *ptr - '1';
+             ptr += 2;
+           }
 
-  /* PR 4992: Don't interrupt output being sent to stdout.  */
-  fflush (stdout);
+         /* Move past flags.  */
+         while (strchr ("-+ #0", *ptr))
+           *sptr++ = *ptr++;
 
-  if (_bfd_error_program_name != NULL)
-    fprintf (stderr, "%s: ", _bfd_error_program_name);
-  else
-    fprintf (stderr, "BFD: ");
+         if (*ptr == '*')
+           {
+             int value;
+             unsigned int arg_index;
 
-  va_start (ap, fmt);
-  new_fmt = fmt;
-  bufp = buf;
+             ptr++;
+             arg_index = arg_count;
+             if (*ptr != '0' && ISDIGIT (*ptr) && ptr[1] == '$')
+               {
+                 arg_index = *ptr - '1';
+                 ptr += 2;
+               }
+             value = abs (args[arg_index].i);
+             arg_count++;
+             sptr += sprintf (sptr, "%d", value);
+           }
+         else
+           /* Handle explicit numeric value.  */
+           while (ISDIGIT (*ptr))
+             *sptr++ = *ptr++;
 
-  /* Reserve enough space for the existing format string.  */
-  avail -= strlen (fmt) + 1;
-  if (avail > 1000)
-    _exit (EXIT_FAILURE);
+         /* Precision.  */
+         if (*ptr == '.')
+           {
+             /* Copy and go past the period.  */
+             *sptr++ = *ptr++;
+             if (*ptr == '*')
+               {
+                 int value;
+                 unsigned int arg_index;
 
-  p = fmt;
-  while (1)
-    {
-      char *q;
-      size_t len, extra, trim;
+                 ptr++;
+                 arg_index = arg_count;
+                 if (*ptr != '0' && ISDIGIT (*ptr) && ptr[1] == '$')
+                   {
+                     arg_index = *ptr - '1';
+                     ptr += 2;
+                   }
+                 value = abs (args[arg_index].i);
+                 arg_count++;
+                 sptr += sprintf (sptr, "%d", value);
+               }
+             else
+               /* Handle explicit numeric value.  */
+               while (ISDIGIT (*ptr))
+                 *sptr++ = *ptr++;
+           }
+         while (strchr ("hlL", *ptr))
+           {
+             switch (*ptr)
+               {
+               case 'h':
+                 short_width = 1;
+                 break;
+               case 'l':
+                 wide_width++;
+                 break;
+               case 'L':
+                 wide_width = 2;
+                 break;
+               default:
+                 abort();
+               }
+             *sptr++ = *ptr++;
+           }
 
-      p = strchr (p, '%');
-      if (p == NULL || p[1] == '\0')
-       {
-         if (new_fmt == buf)
+         /* Copy the type specifier, and NULL terminate.  */
+         *sptr++ = *ptr++;
+         *sptr = '\0';
+         if ((int) arg_no < 0)
+           arg_no = arg_count;
+
+         switch (ptr[-1])
            {
-             len = strlen (fmt);
-             memcpy (bufp, fmt, len + 1);
+           case 'd':
+           case 'i':
+           case 'o':
+           case 'u':
+           case 'x':
+           case 'X':
+           case 'c':
+             {
+               /* Short values are promoted to int, so just copy it
+                  as an int and trust the C library printf to cast it
+                  to the right width.  */
+               if (short_width)
+                 PRINT_TYPE (int, i);
+               else
+                 {
+                   /* L modifier for bfd_vma or bfd_size_type may be
+                      either long long or long.  */
+                   if (ptr[-2] == 'L')
+                     {
+                       sptr[-2] = 'l';
+                       if (BFD_ARCH_SIZE < 64 || BFD_HOST_64BIT_LONG)
+                         wide_width = 1;
+                       else
+                         {
+                           sptr[-1] = 'l';
+                           *sptr++ = ptr[-1];
+                           *sptr = '\0';
+                         }
+                     }
+
+                   switch (wide_width)
+                     {
+                     case 0:
+                       PRINT_TYPE (int, i);
+                       break;
+                     case 1:
+                       PRINT_TYPE (long, l);
+                       break;
+                     case 2:
+                     default:
+#if defined (__MSVCRT__)
+                       sptr[-3] = 'I';
+                       sptr[-2] = '6';
+                       sptr[-1] = '4';
+                       *sptr++ = ptr[-1];
+                       *sptr = '\0';
+#endif
+#if defined (__GNUC__) || defined (HAVE_LONG_LONG)
+                       PRINT_TYPE (long long, ll);
+#else
+                       /* Fake it and hope for the best.  */
+                       PRINT_TYPE (long, l);
+#endif
+                       break;
+                     }
+                 }
+             }
+             break;
+           case 'f':
+           case 'e':
+           case 'E':
+           case 'g':
+           case 'G':
+             {
+               if (wide_width == 0)
+                 PRINT_TYPE (double, d);
+               else
+                 {
+#if defined (__GNUC__) || defined (HAVE_LONG_DOUBLE)
+                   PRINT_TYPE (long double, ld);
+#else
+                   /* Fake it and hope for the best.  */
+                   PRINT_TYPE (double, d);
+#endif
+                 }
+             }
+             break;
+           case 's':
+             PRINT_TYPE (char *, p);
+             break;
+           case 'p':
+             PRINT_TYPE (void *, p);
+             break;
+           case 'A':
+             {
+               asection *sec;
+               bfd *abfd;
+               const char *group = NULL;
+               struct coff_comdat_info *ci;
+
+               sec = (asection *) args[arg_no].p;
+               if (sec == NULL)
+                 /* Invoking %A with a null section pointer is an
+                    internal error.  */
+                 abort ();
+               abfd = sec->owner;
+               if (abfd != NULL
+                   && bfd_get_flavour (abfd) == bfd_target_elf_flavour
+                   && elf_next_in_group (sec) != NULL
+                   && (sec->flags & SEC_GROUP) == 0)
+                 group = elf_group_name (sec);
+               else if (abfd != NULL
+                        && bfd_get_flavour (abfd) == bfd_target_coff_flavour
+                        && (ci = bfd_coff_get_comdat_section (sec->owner,
+                                                              sec)) != NULL)
+                 group = ci->name;
+               if (group != NULL)
+                 result = fprintf (stream, "%s[%s]", sec->name, group);
+               else
+                 result = fprintf (stream, "%s", sec->name);
+             }
+             break;
+           case 'B':
+             {
+               bfd *abfd;
+
+               abfd = (bfd *) args[arg_no].p;
+               if (abfd == NULL)
+                 /* Invoking %B with a null bfd pointer is an
+                    internal error.  */
+                 abort ();
+               else if (abfd->my_archive
+                        && !bfd_is_thin_archive (abfd->my_archive))
+                 result = fprintf (stream, "%s(%s)",
+                                   abfd->my_archive->filename, abfd->filename);
+               else
+                 result = fprintf (stream, "%s", abfd->filename);
+             }
+             break;
+           default:
+             abort();
            }
-         break;
+         arg_count++;
        }
+      if (result == -1)
+       return -1;
+      total_printed += result;
+    }
 
-      if (p[1] == 'A' || p[1] == 'B')
+  return total_printed;
+}
+
+/* First pass over FORMAT to gather ARGS.  Returns number of args.  */
+
+static unsigned int
+_bfd_doprnt_scan (const char *format, union _bfd_doprnt_args *args)
+{
+  const char *ptr = format;
+  unsigned int arg_count = 0;
+
+  while (*ptr != '\0')
+    {
+      if (*ptr != '%')
        {
-         len = p - fmt;
-         memcpy (bufp, fmt, len);
-         bufp += len;
-         fmt = p + 2;
-         new_fmt = buf;
-
-         /* If we run out of space, tough, you lose your ridiculously
-            long file or section name.  It's not safe to try to alloc
-            memory here;  We might be printing an out of memory message.  */
-         if (avail == 0)
+         ptr = strchr (ptr, '%');
+         if (ptr == NULL)
+           break;
+       }
+      else if (ptr[1] == '%')
+       ptr += 2;
+      else
+       {
+         int wide_width = 0, short_width = 0;
+         unsigned int arg_no;
+
+         ptr++;
+
+         /* Check for a positional parameter.  */
+         arg_no = -1u;
+         if (*ptr != '0' && ISDIGIT (*ptr) && ptr[1] == '$')
            {
-             *bufp++ = '*';
-             *bufp++ = '*';
-             *bufp = '\0';
+             arg_no = *ptr - '1';
+             ptr += 2;
            }
-         else
-           {
-             if (p[1] == 'B')
-               {
-                 bfd *abfd = va_arg (ap, bfd *);
 
-                 if (abfd == NULL)
-                   /* Invoking %B with a null bfd pointer is an internal error.  */
-                   abort ();
-                 else if (abfd->my_archive
-                          && !bfd_is_thin_archive (abfd->my_archive))
-                   snprintf (bufp, avail, "%s(%s)",
-                             abfd->my_archive->filename, abfd->filename);
-                 else
-                   snprintf (bufp, avail, "%s", abfd->filename);
-               }
-             else
-               {
-                 asection *sec = va_arg (ap, asection *);
-                 bfd *abfd;
-                 const char *group = NULL;
-                 struct coff_comdat_info *ci;
+         /* Move past flags.  */
+         while (strchr ("-+ #0", *ptr))
+           ptr++;
 
-                 if (sec == NULL)
-                   /* Invoking %A with a null section pointer is an internal error.  */
-                   abort ();
-                 abfd = sec->owner;
-                 if (abfd != NULL
-                     && bfd_get_flavour (abfd) == bfd_target_elf_flavour
-                     && elf_next_in_group (sec) != NULL
-                     && (sec->flags & SEC_GROUP) == 0)
-                   group = elf_group_name (sec);
-                 else if (abfd != NULL
-                          && bfd_get_flavour (abfd) == bfd_target_coff_flavour
-                          && (ci = bfd_coff_get_comdat_section (sec->owner,
-                                                                sec)) != NULL)
-                   group = ci->name;
-                 if (group != NULL)
-                   snprintf (bufp, avail, "%s[%s]", sec->name, group);
-                 else
-                   snprintf (bufp, avail, "%s", sec->name);
-               }
-             len = strlen (bufp);
-             avail = avail - len + 2;
-
-             /* We need to replace any '%' we printed by "%%".
-                First count how many.  */
-             q = bufp;
-             bufp += len;
-             extra = 0;
-             while ((q = strchr (q, '%')) != NULL)
+         if (*ptr == '*')
+           {
+             unsigned int arg_index;
+
+             ptr++;
+             arg_index = arg_count;
+             if (*ptr != '0' && ISDIGIT (*ptr) && ptr[1] == '$')
                {
-                 ++q;
-                 ++extra;
+                 arg_index = *ptr - '1';
+                 ptr += 2;
                }
+             if (arg_index >= 9)
+               abort ();
+             args[arg_index].type = Int;
+             arg_count++;
+           }
+         else
+           /* Handle explicit numeric value.  */
+           while (ISDIGIT (*ptr))
+             ptr++;
 
-             /* If there isn't room, trim off the end of the string.  */
-             q = bufp;
-             bufp += extra;
-             if (extra > avail)
+         /* Precision.  */
+         if (*ptr == '.')
+           {
+             ptr++;
+             if (*ptr == '*')
                {
-                 trim = extra - avail;
-                 bufp -= trim;
-                 do
+                 unsigned int arg_index;
+
+                 ptr++;
+                 arg_index = arg_count;
+                 if (*ptr != '0' && ISDIGIT (*ptr) && ptr[1] == '$')
                    {
-                     if (*--q == '%')
-                       --extra;
+                     arg_index = *ptr - '1';
+                     ptr += 2;
                    }
-                 while (--trim != 0);
-                 *q = '\0';
-                 avail = extra;
+                 if (arg_index >= 9)
+                   abort ();
+                 args[arg_index].type = Int;
+                 arg_count++;
                }
-             avail -= extra;
-
-             /* Now double all '%' chars, shuffling the string as we go.  */
-             while (extra != 0)
+             else
+               /* Handle explicit numeric value.  */
+               while (ISDIGIT (*ptr))
+                 ptr++;
+           }
+         while (strchr ("hlL", *ptr))
+           {
+             switch (*ptr)
                {
-                 while ((q[extra] = *q) != '%')
-                   --q;
-                 q[--extra] = '%';
-                 --q;
+               case 'h':
+                 short_width = 1;
+                 break;
+               case 'l':
+                 wide_width++;
+                 break;
+               case 'L':
+                 wide_width = 2;
+                 break;
+               default:
+                 abort();
                }
+             ptr++;
+           }
+
+         ptr++;
+         if ((int) arg_no < 0)
+           arg_no = arg_count;
+
+         if (arg_no >= 9)
+           abort ();
+         switch (ptr[-1])
+           {
+           case 'd':
+           case 'i':
+           case 'o':
+           case 'u':
+           case 'x':
+           case 'X':
+           case 'c':
+             {
+               if (short_width)
+                 args[arg_no].type = Int;
+               else
+                 {
+                   if (ptr[-2] == 'L')
+                     {
+                       if (BFD_ARCH_SIZE < 64 || BFD_HOST_64BIT_LONG)
+                         wide_width = 1;
+                     }
+
+                   switch (wide_width)
+                     {
+                     case 0:
+                       args[arg_no].type = Int;
+                       break;
+                     case 1:
+                       args[arg_no].type = Long;
+                       break;
+                     case 2:
+                     default:
+#if defined (__GNUC__) || defined (HAVE_LONG_LONG)
+                       args[arg_no].type = LongLong;
+#else
+                       args[arg_no].type = Long;
+#endif
+                       break;
+                     }
+                 }
+             }
+             break;
+           case 'f':
+           case 'e':
+           case 'E':
+           case 'g':
+           case 'G':
+             {
+               if (wide_width == 0)
+                 args[arg_no].type = Double;
+               else
+                 {
+#if defined (__GNUC__) || defined (HAVE_LONG_DOUBLE)
+                   args[arg_no].type = LongDouble;
+#else
+                   args[arg_no].type = Double;
+#endif
+                 }
+             }
+             break;
+           case 's':
+           case 'p':
+           case 'A':
+           case 'B':
+             args[arg_no].type = Ptr;
+             break;
+           default:
+             abort();
            }
+         arg_count++;
        }
-      p = p + 2;
     }
 
-  vfprintf (stderr, new_fmt, ap);
-  va_end (ap);
+  return arg_count;
+}
+
+/* This is the default routine to handle BFD error messages.
+   Like fprintf (stderr, ...), but also handles some extra format specifiers.
+
+   %A section name from section.  For group components, prints group name too.
+   %B file name from bfd.  For archive components, prints archive too.
+
+   Beware: Only supports a maximum of 9 format arguments.  */
+
+static void
+error_handler_internal (const char *fmt, va_list ap)
+{
+  int i, arg_count;
+  union _bfd_doprnt_args args[9];
+
+  arg_count = _bfd_doprnt_scan (fmt, args);
+  for (i = 0; i < arg_count; i++)
+    {
+      switch (args[i].type)
+       {
+       case Int:
+         args[i].i = va_arg (ap, int);
+         break;
+       case Long:
+         args[i].l = va_arg (ap, long);
+         break;
+       case LongLong:
+         args[i].ll = va_arg (ap, long long);
+         break;
+       case Double:
+         args[i].d = va_arg (ap, double);
+         break;
+       case LongDouble:
+         args[i].ld = va_arg (ap, long double);
+         break;
+       case Ptr:
+         args[i].p = va_arg (ap, void *);
+         break;
+       default:
+         abort ();
+       }
+    }
+
+  /* PR 4992: Don't interrupt output being sent to stdout.  */
+  fflush (stdout);
+
+  if (_bfd_error_program_name != NULL)
+    fprintf (stderr, "%s: ", _bfd_error_program_name);
+  else
+    fprintf (stderr, "BFD: ");
+
+  _bfd_doprnt (stderr, fmt, args);
 
   /* On AIX, putc is implemented as a macro that triggers a -Wunused-value
      warning, so use the fputc function to avoid it.  */
@@ -796,7 +1172,17 @@ _bfd_default_error_handler (const char *fmt, ...)
    function pointer permits a program linked against BFD to intercept
    the messages and deal with them itself.  */
 
-bfd_error_handler_type _bfd_error_handler = _bfd_default_error_handler;
+static bfd_error_handler_type _bfd_error_internal = error_handler_internal;
+
+void
+_bfd_error_handler (const char *fmt, ...)
+{
+  va_list ap;
+
+  va_start (ap, fmt);
+  _bfd_error_internal (fmt, ap);
+  va_end (ap);
+}
 
 /*
 FUNCTION
@@ -815,8 +1201,8 @@ bfd_set_error_handler (bfd_error_handler_type pnew)
 {
   bfd_error_handler_type pold;
 
-  pold = _bfd_error_handler;
-  _bfd_error_handler = pnew;
+  pold = _bfd_error_internal;
+  _bfd_error_internal = pnew;
   return pold;
 }
 
@@ -840,23 +1226,6 @@ bfd_set_error_program_name (const char *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 (void)
-{
-  return _bfd_error_handler;
-}
-
 /*
 SUBSECTION
        BFD assert handler
@@ -891,14 +1260,14 @@ _bfd_default_assert_handler (const char *bfd_formatmsg,
                             int bfd_line)
 
 {
-  (*_bfd_error_handler) (bfd_formatmsg, bfd_version, bfd_file, bfd_line);
+  _bfd_error_handler (bfd_formatmsg, bfd_version, bfd_file, bfd_line);
 }
 
 /* Similar to _bfd_error_handler, a program can decide to exit on an
    internal BFD error.  We use a non-variadic type to simplify passing
    on parameters to other functions, e.g. _bfd_error_handler.  */
 
-bfd_assert_handler_type _bfd_assert_handler = _bfd_default_assert_handler;
+static bfd_assert_handler_type _bfd_assert_handler = _bfd_default_assert_handler;
 
 /*
 FUNCTION
@@ -921,23 +1290,6 @@ bfd_set_assert_handler (bfd_assert_handler_type pnew)
   _bfd_assert_handler = pnew;
   return pold;
 }
-
-/*
-FUNCTION
-       bfd_get_assert_handler
-
-SYNOPSIS
-       bfd_assert_handler_type bfd_get_assert_handler (void);
-
-DESCRIPTION
-       Return the BFD assert handler function.
-*/
-
-bfd_assert_handler_type
-bfd_get_assert_handler (void)
-{
-  return _bfd_assert_handler;
-}
 \f
 /*
 INODE
@@ -1026,18 +1378,10 @@ DESCRIPTION
        section @var{sec} to the values @var{rel} and @var{count}.
        The argument @var{abfd} is ignored.
 
+.#define bfd_set_reloc(abfd, asect, location, count) \
+.     BFD_SEND (abfd, _bfd_set_reloc, (abfd, asect, location, count))
 */
 
-void
-bfd_set_reloc (bfd *ignore_abfd ATTRIBUTE_UNUSED,
-              sec_ptr asect,
-              arelent **location,
-              unsigned int count)
-{
-  asect->orelocation = location;
-  asect->reloc_count = count;
-}
-
 /*
 FUNCTION
        bfd_set_file_flags
@@ -1086,6 +1430,7 @@ bfd_set_file_flags (bfd *abfd, flagword flags)
 void
 bfd_assert (const char *file, int line)
 {
+  /* xgettext:c-format */
   (*_bfd_assert_handler) (_("BFD %s assertion fail %s:%d"),
                          BFD_VERSION_STRING, file, line);
 }
@@ -1097,14 +1442,16 @@ void
 _bfd_abort (const char *file, int line, const char *fn)
 {
   if (fn != NULL)
-    (*_bfd_error_handler)
+    _bfd_error_handler
+      /* xgettext:c-format */
       (_("BFD %s internal error, aborting at %s:%d in %s\n"),
        BFD_VERSION_STRING, file, line, fn);
   else
-    (*_bfd_error_handler)
+    _bfd_error_handler
+      /* xgettext:c-format */
       (_("BFD %s internal error, aborting at %s:%d\n"),
        BFD_VERSION_STRING, file, line);
-  (*_bfd_error_handler) (_("Please report this bug.\n"));
+  _bfd_error_handler (_("Please report this bug.\n"));
   _exit (EXIT_FAILURE);
 }
 
@@ -1330,7 +1677,7 @@ bfd_scan_vma (const char *string, const char **end, int base)
   if (sizeof (bfd_vma) <= sizeof (unsigned long))
     return strtoul (string, (char **) end, base);
 
-#ifdef HAVE_STRTOULL
+#if defined (HAVE_STRTOULL) && defined (HAVE_LONG_LONG)
   if (sizeof (bfd_vma) <= sizeof (unsigned long long))
     return strtoull (string, (char **) end, base);
 #endif
@@ -1433,27 +1780,6 @@ DESCRIPTION
 
 */
 
-/*
-FUNCTION
-       bfd_merge_private_bfd_data
-
-SYNOPSIS
-       bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
-
-DESCRIPTION
-       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:
-
-       o <<bfd_error_no_memory>> -
-       Not enough memory exists to create private data for @var{obfd}.
-
-.#define bfd_merge_private_bfd_data(ibfd, obfd) \
-.     BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
-.              (ibfd, obfd))
-
-*/
-
 /*
 FUNCTION
        bfd_set_private_flags