2004-10-30 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / ld / ldmisc.c
index a2e496da9c07552c88548ea178e9d6787ef995a1..5f7d0e99aac1531d79df0dfd32fe6d5f77d8a267 100644 (file)
@@ -1,6 +1,6 @@
 /* ldmisc.c
-   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2002, 2003
+   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+   2002, 2003, 2004
    Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support.
 
    02111-1307, USA.  */
 
 #include "bfd.h"
+#include "bfdlink.h"
 #include "sysdep.h"
 #include "libiberty.h"
 #include "demangle.h"
-
-#ifdef ANSI_PROTOTYPES
 #include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
 #include "ld.h"
 #include "ldmisc.h"
 #include "ldexp.h"
 #include "ldlex.h"
 #include "ldmain.h"
 #include "ldfile.h"
-
-static void vfinfo PARAMS ((FILE *, const char *, va_list));
+#include "elf-bfd.h"
 
 /*
  %% literal %
+ %A section name from a section
+ %B filename from a bfd
+ %C clever filename:linenumber with function
+ %D like %C, but no function name
+ %E current bfd error or errno
  %F error is fatal
+ %G like %D, but only function name
+ %I filename from a lang_input_statement_type
  %P print program name
+ %R info about a relent
  %S print script file and linenumber
- %E current bfd error or errno
- %I filename from a lang_input_statement_type
- %B filename from a bfd
  %T symbol name
- %X no object output, fail return
  %V hex bfd_vma
- %v hex bfd_vma, no leading zeros
  %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
- %C clever filename:linenumber with function
- %D like %C, but no function name
- %G like %D, but only function name
- %R info about a relent
- %s arbitrary string, like printf
+ %X no object output, fail return
  %d integer, like printf
+ %s arbitrary string, like printf
  %u integer, like printf
+ %v hex bfd_vma, no leading zeros
 */
 
 static void
-vfinfo (fp, fmt, arg)
-     FILE *fp;
-     const char *fmt;
-     va_list arg;
+vfinfo (FILE *fp, const char *fmt, va_list arg)
 {
   bfd_boolean fatal = FALSE;
 
@@ -125,7 +117,7 @@ vfinfo (fp, fmt, arg)
 
            case 'W':
              /* hex bfd_vma with 0x with no leading zeroes taking up
-                 8 spaces.  */
+                8 spaces.  */
              {
                char buf[100];
                bfd_vma value;
@@ -153,7 +145,7 @@ vfinfo (fp, fmt, arg)
              {
                const char *name = va_arg (arg, const char *);
 
-               if (name == (const char *) NULL || *name == 0)
+               if (name == NULL || *name == 0)
                  fprintf (fp, _("no symbol"));
                else if (! demangling)
                  fprintf (fp, "%s", name);
@@ -168,6 +160,30 @@ vfinfo (fp, fmt, arg)
              }
              break;
 
+           case 'A':
+             /* section name from a section */
+             {
+               asection *sec = va_arg (arg, asection *);
+               bfd *abfd = sec->owner;
+               const char *group = NULL;
+               struct coff_comdat_info *ci;
+
+               fprintf (fp, "%s", sec->name);
+               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)
+                 fprintf (fp, "[%s]", group);
+             }
+             break;
+
            case 'B':
              /* filename from a bfd */
              {
@@ -268,7 +284,7 @@ vfinfo (fp, fmt, arg)
                    symsize = bfd_get_symtab_upper_bound (abfd);
                    if (symsize < 0)
                      einfo (_("%B%F: could not read symbols\n"), abfd);
-                   asymbols = (asymbol **) xmalloc (symsize);
+                   asymbols = xmalloc (symsize);
                    symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
                    if (symbol_count < 0)
                      einfo (_("%B%F: could not read symbols\n"), abfd);
@@ -279,7 +295,7 @@ vfinfo (fp, fmt, arg)
                      }
                  }
 
-               lfinfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
+               lfinfo (fp, "%B(%A+0x%v)", abfd, section, offset);
 
                discard_last = TRUE;
                if (bfd_find_nearest_line (abfd, section, asymbols, offset,
@@ -377,8 +393,7 @@ vfinfo (fp, fmt, arg)
    other such chars that would otherwise confuse the demangler.  */
 
 char *
-demangle (name)
-     const char *name;
+demangle (const char *name)
 {
   char *res;
   const char *p;
@@ -419,34 +434,32 @@ demangle (name)
 /* Format info message and print on stdout.  */
 
 /* (You would think this should be called just "info", but then you
-   would hosed by LynxOS, which defines that name in its libc.)  */
+   would be hosed by LynxOS, which defines that name in its libc.)  */
 
 void
-info_msg VPARAMS ((const char *fmt, ...))
+info_msg (const char *fmt, ...)
 {
-  VA_OPEN (arg, fmt);
-  VA_FIXEDARG (arg, const char *, fmt);
+  va_list arg;
 
+  va_start (arg, fmt);
   vfinfo (stdout, fmt, arg);
-  VA_CLOSE (arg);
+  va_end (arg);
 }
 
 /* ('e' for error.) Format info message and print on stderr.  */
 
 void
-einfo VPARAMS ((const char *fmt, ...))
+einfo (const char *fmt, ...)
 {
-  VA_OPEN (arg, fmt);
-  VA_FIXEDARG (arg, const char *, fmt);
+  va_list arg;
 
+  va_start (arg, fmt);
   vfinfo (stderr, fmt, arg);
-  VA_CLOSE (arg);
+  va_end (arg);
 }
 
 void
-info_assert (file, line)
-     const char *file;
-     unsigned int line;
+info_assert (const char *file, unsigned int line)
 {
   einfo (_("%F%P: internal error %s %d\n"), file, line);
 }
@@ -454,36 +467,35 @@ info_assert (file, line)
 /* ('m' for map) Format info message and print on map.  */
 
 void
-minfo VPARAMS ((const char *fmt, ...))
+minfo (const char *fmt, ...)
 {
-  VA_OPEN (arg, fmt);
-  VA_FIXEDARG (arg, const char *, fmt);
+  va_list arg;
 
+  va_start (arg, fmt);
   vfinfo (config.map_file, fmt, arg);
-  VA_CLOSE (arg);
+  va_end (arg);
 }
 
 void
-lfinfo VPARAMS ((FILE *file, const char *fmt, ...))
+lfinfo (FILE *file, const char *fmt, ...)
 {
-  VA_OPEN (arg, fmt);
-  VA_FIXEDARG (arg, FILE *, file);
-  VA_FIXEDARG (arg, const char *, fmt);
+  va_list arg;
 
+  va_start (arg, fmt);
   vfinfo (file, fmt, arg);
-  VA_CLOSE (arg);
+  va_end (arg);
 }
 \f
 /* Functions to print the link map.  */
 
 void
-print_space ()
+print_space (void)
 {
   fprintf (config.map_file, " ");
 }
 
 void
-print_nl ()
+print_nl (void)
 {
   fprintf (config.map_file, "\n");
 }
@@ -492,10 +504,7 @@ print_nl ()
    call this function.  */
 
 void
-ld_abort (file, line, fn)
-     const char *file;
-     int line;
-     const char *fn;
+ld_abort (const char *file, int line, const char *fn)
 {
   if (fn != NULL)
     einfo (_("%P: internal error: aborting at %s line %d in %s\n"),
@@ -506,14 +515,3 @@ ld_abort (file, line, fn)
   einfo (_("%P%F: please report this bug\n"));
   xexit (1);
 }
-
-bfd_boolean
-error_handler VPARAMS ((int id ATTRIBUTE_UNUSED, const char *fmt, ...))
-{
-  VA_OPEN (arg, fmt);
-  VA_FIXEDARG (arg, const char *, fmt);
-
-  vfinfo (stderr, fmt, arg);
-  VA_CLOSE (arg);
-  return TRUE;
-}
This page took 0.094739 seconds and 4 git commands to generate.