Implement debugging of WOW64 processes
[deliverable/binutils-gdb.git] / ld / ldmisc.c
index 49aa66dffbd4dd43ad1832c5facaaf21b24db16a..b714b97105369e638f00041079f64ee3d6ff86c5 100644 (file)
@@ -1,5 +1,5 @@
 /* ldmisc.c
 /* ldmisc.c
-   Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   Copyright (C) 1991-2020 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support.
 
    This file is part of the GNU Binutils.
    Written by Steve Chamberlain of Cygnus Support.
 
    This file is part of the GNU Binutils.
@@ -23,6 +23,7 @@
 #include "bfd.h"
 #include "bfdlink.h"
 #include "libiberty.h"
 #include "bfd.h"
 #include "bfdlink.h"
 #include "libiberty.h"
+#include "ctf-api.h"
 #include "safe-ctype.h"
 #include "filenames.h"
 #include "demangle.h"
 #include "safe-ctype.h"
 #include "filenames.h"
 #include "demangle.h"
 #include "ldlex.h"
 #include "ldmain.h"
 #include "ldfile.h"
 #include "ldlex.h"
 #include "ldmain.h"
 #include "ldfile.h"
-#include "elf-bfd.h"
-#include "coff-bfd.h"
 
 /*
  %% literal %
 
 /*
  %% 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
  %H like %C but in addition emit section+offset
  %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
  %H like %C but in addition emit section+offset
- %I filename from a lang_input_statement_type
  %P print program name
  %P print program name
- %R info about a relent
- %S print script file and linenumber from etree_type.
- %T symbol name
  %V hex bfd_vma
  %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
  %X no object output, fail return
  %V hex bfd_vma
  %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
  %X no object output, fail return
  %ld long, like printf
  %lu unsigned long, like printf
  %p native (host) void* pointer, like printf
  %ld long, like printf
  %lu unsigned long, like printf
  %p native (host) void* pointer, like printf
+ %pA section name from a section
+ %pB filename from a bfd
+ %pI filename from a lang_input_statement_type
+ %pR info about a relent
+ %pS print script file and linenumber from etree_type.
+ %pT symbol name
  %s arbitrary string, like printf
  %u integer, like printf
  %v hex bfd_vma, no leading zeros
  %s arbitrary string, like printf
  %u integer, like printf
  %v hex bfd_vma, no leading zeros
@@ -129,17 +128,17 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
              arg_type = Vma;
              break;
 
              arg_type = Vma;
              break;
 
-           case 'T':
-           case 'A':
-           case 'B':
-           case 'I':
-           case 'S':
-           case 'R':
-           case 'p':
            case 's':
              arg_type = Ptr;
              break;
 
            case 's':
              arg_type = Ptr;
              break;
 
+           case 'p':
+             if (*scan == 'A' || *scan == 'B' || *scan == 'I'
+                 || *scan == 'R' || *scan == 'S' || *scan ==  'T')
+               scan++;
+             arg_type = Ptr;
+             break;
+
            case 'C':
            case 'D':
            case 'G':
            case 'C':
            case 'D':
            case 'G':
@@ -289,76 +288,6 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
              }
              break;
 
              }
              break;
 
-           case 'T':
-             /* Symbol name.  */
-             {
-               const char *name = (const char *) args[arg_no].p;
-               ++arg_count;
-               if (name == NULL || *name == 0)
-                 {
-                   fprintf (fp, _("no symbol"));
-                   break;
-                 }
-               else if (demangling)
-                 {
-                   char *demangled;
-
-                   demangled = bfd_demangle (link_info.output_bfd, name,
-                                             DMGL_ANSI | DMGL_PARAMS);
-                   if (demangled != NULL)
-                     {
-                       fprintf (fp, "%s", demangled);
-                       free (demangled);
-                       break;
-                     }
-                 }
-               fprintf (fp, "%s", name);
-             }
-             break;
-
-           case 'A':
-             /* section name from a section */
-             {
-               asection *sec;
-               bfd *abfd;
-               const char *group = NULL;
-               struct coff_comdat_info *ci;
-
-               sec = (asection *) args[arg_no].p;
-               ++arg_count;
-               abfd = sec->owner;
-               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 */
-             {
-               bfd *abfd = (bfd *) args[arg_no].p;
-               ++arg_count;
-               if (abfd == NULL)
-                 fprintf (fp, "%s generated", program_name);
-               else if (abfd->my_archive != NULL
-                        && !bfd_is_thin_archive (abfd->my_archive))
-                 fprintf (fp, "%s(%s)", abfd->my_archive->filename,
-                          abfd->filename);
-               else
-                 fprintf (fp, "%s", abfd->filename);
-             }
-             break;
-
            case 'F':
              /* Error is fatal.  */
              fatal = TRUE;
            case 'F':
              /* Error is fatal.  */
              fatal = TRUE;
@@ -374,54 +303,6 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
              fprintf (fp, "%s", bfd_errmsg (bfd_get_error ()));
              break;
 
              fprintf (fp, "%s", bfd_errmsg (bfd_get_error ()));
              break;
 
-           case 'I':
-             /* filename from a lang_input_statement_type */
-             {
-               lang_input_statement_type *i;
-
-               i = (lang_input_statement_type *) args[arg_no].p;
-               ++arg_count;
-               if (i->the_bfd->my_archive != NULL
-                   && !bfd_is_thin_archive (i->the_bfd->my_archive))
-                 fprintf (fp, "(%s)",
-                          bfd_get_filename (i->the_bfd->my_archive));
-               fprintf (fp, "%s", i->local_sym_name);
-               if ((i->the_bfd->my_archive == NULL
-                    || bfd_is_thin_archive (i->the_bfd->my_archive))
-                   && filename_cmp (i->local_sym_name, i->filename) != 0)
-                 fprintf (fp, " (%s)", i->filename);
-             }
-             break;
-
-           case 'S':
-             /* Print script file and linenumber.  */
-             {
-               etree_type node;
-               etree_type *tp = (etree_type *) args[arg_no].p;
-               ++arg_count;
-               if (tp == NULL)
-                 {
-                   tp = &node;
-                   tp->type.filename = ldlex_filename ();
-                   tp->type.lineno = lineno;
-                 }
-               if (tp->type.filename != NULL)
-                 fprintf (fp, "%s:%u", tp->type.filename, tp->type.lineno);
-             }
-             break;
-
-           case 'R':
-             /* Print all that's interesting about a relent.  */
-             {
-               arelent *relent = (arelent *) args[arg_no].p;
-               ++arg_count;
-               lfinfo (fp, "%s+0x%v (type %s)",
-                       (*(relent->sym_ptr_ptr))->name,
-                       relent->addend,
-                       relent->howto->name);
-             }
-             break;
-
            case 'C':
            case 'D':
            case 'G':
            case 'C':
            case 'D':
            case 'G':
@@ -441,6 +322,7 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                unsigned int linenumber;
                bfd_boolean discard_last;
                bfd_boolean done;
                unsigned int linenumber;
                bfd_boolean discard_last;
                bfd_boolean done;
+               bfd_error_type last_bfd_error = bfd_get_error ();
 
                abfd = args[arg_no].reladdr.abfd;
                section = args[arg_no].reladdr.sec;
 
                abfd = args[arg_no].reladdr.abfd;
                section = args[arg_no].reladdr.sec;
@@ -450,7 +332,7 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                if (abfd != NULL)
                  {
                    if (!bfd_generic_link_read_symbols (abfd))
                if (abfd != NULL)
                  {
                    if (!bfd_generic_link_read_symbols (abfd))
-                     einfo (_("%B%F: could not read symbols: %E\n"), abfd);
+                     einfo (_("%F%P: %pB: could not read symbols: %E\n"), abfd);
 
                    asymbols = bfd_get_outsymbols (abfd);
                  }
 
                    asymbols = bfd_get_outsymbols (abfd);
                  }
@@ -489,7 +371,7 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                                && filename_cmp (last_file, filename) != 0)
                            || strcmp (last_function, functionname) != 0)
                          {
                                && filename_cmp (last_file, filename) != 0)
                            || strcmp (last_function, functionname) != 0)
                          {
-                           lfinfo (fp, _("%B: In function `%T':\n"),
+                           lfinfo (fp, _("%pB: in function `%pT':\n"),
                                    abfd, functionname);
 
                            last_bfd = abfd;
                                    abfd, functionname);
 
                            last_bfd = abfd;
@@ -505,14 +387,14 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                        discard_last = FALSE;
                      }
                    else
                        discard_last = FALSE;
                      }
                    else
-                     lfinfo (fp, "%B:", abfd);
+                     lfinfo (fp, "%pB:", abfd);
 
                    if (filename != NULL)
                      fprintf (fp, "%s:", filename);
 
                    done = fmt[-1] != 'H';
                    if (functionname != NULL && fmt[-1] == 'G')
 
                    if (filename != NULL)
                      fprintf (fp, "%s:", filename);
 
                    done = fmt[-1] != 'H';
                    if (functionname != NULL && fmt[-1] == 'G')
-                     lfinfo (fp, "%T", functionname);
+                     lfinfo (fp, "%pT", functionname);
                    else if (filename != NULL && linenumber != 0)
                      fprintf (fp, "%u%s", linenumber, done ? "" : ":");
                    else
                    else if (filename != NULL && linenumber != 0)
                      fprintf (fp, "%u%s", linenumber, done ? "" : ":");
                    else
@@ -520,11 +402,12 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                  }
                else
                  {
                  }
                else
                  {
-                   lfinfo (fp, "%B:", abfd);
+                   lfinfo (fp, "%pB:", abfd);
                    done = FALSE;
                  }
                if (!done)
                    done = FALSE;
                  }
                if (!done)
-                 lfinfo (fp, "(%A+0x%v)", section, offset);
+                 lfinfo (fp, "(%pA+0x%v)", section, offset);
+               bfd_set_error (last_bfd_error);
 
                if (discard_last)
                  {
 
                if (discard_last)
                  {
@@ -544,9 +427,118 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
              break;
 
            case 'p':
              break;
 
            case 'p':
-             /* native (host) void* pointer, like printf */
-             fprintf (fp, "%p", args[arg_no].p);
-             ++arg_count;
+             if (*fmt == 'A')
+               {
+                 /* section name from a section */
+                 asection *sec;
+                 bfd *abfd;
+
+                 fmt++;
+                 sec = (asection *) args[arg_no].p;
+                 ++arg_count;
+                 fprintf (fp, "%s", sec->name);
+                 abfd = sec->owner;
+                 if (abfd != NULL)
+                   {
+                     const char *group = bfd_group_name (abfd, sec);
+                     if (group != NULL)
+                       fprintf (fp, "[%s]", group);
+                   }
+               }
+             else if (*fmt == 'B')
+               {
+                 /* filename from a bfd */
+                 bfd *abfd = (bfd *) args[arg_no].p;
+
+                 fmt++;
+                 ++arg_count;
+                 if (abfd == NULL)
+                   fprintf (fp, "%s generated", program_name);
+                 else if (abfd->my_archive != NULL
+                          && !bfd_is_thin_archive (abfd->my_archive))
+                   fprintf (fp, "%s(%s)", abfd->my_archive->filename,
+                            abfd->filename);
+                 else
+                   fprintf (fp, "%s", abfd->filename);
+               }
+             else if (*fmt == 'I')
+               {
+                 /* filename from a lang_input_statement_type */
+                 lang_input_statement_type *i;
+
+                 fmt++;
+                 i = (lang_input_statement_type *) args[arg_no].p;
+                 ++arg_count;
+                 if (i->the_bfd != NULL
+                     && i->the_bfd->my_archive != NULL
+                     && !bfd_is_thin_archive (i->the_bfd->my_archive))
+                   fprintf (fp, "(%s)%s", i->the_bfd->my_archive->filename,
+                            i->local_sym_name);
+                 else
+                   fprintf (fp, "%s", i->filename);
+               }
+             else if (*fmt == 'R')
+               {
+                 /* Print all that's interesting about a relent.  */
+                 arelent *relent = (arelent *) args[arg_no].p;
+
+                 fmt++;
+                 ++arg_count;
+                 lfinfo (fp, "%s+0x%v (type %s)",
+                         (*(relent->sym_ptr_ptr))->name,
+                         relent->addend,
+                         relent->howto->name);
+               }
+             else if (*fmt == 'S')
+               {
+                 /* Print script file and linenumber.  */
+                 etree_type node;
+                 etree_type *tp = (etree_type *) args[arg_no].p;
+
+                 fmt++;
+                 ++arg_count;
+                 if (tp == NULL)
+                   {
+                     tp = &node;
+                     tp->type.filename = ldlex_filename ();
+                     tp->type.lineno = lineno;
+                   }
+                 if (tp->type.filename != NULL)
+                   fprintf (fp, "%s:%u", tp->type.filename, tp->type.lineno);
+               }
+             else if (*fmt == 'T')
+               {
+                 /* Symbol name.  */
+                 const char *name = (const char *) args[arg_no].p;
+
+                 fmt++;
+                 ++arg_count;
+                 if (name == NULL || *name == 0)
+                   {
+                     fprintf (fp, _("no symbol"));
+                     break;
+                   }
+                 else if (demangling)
+                   {
+                     char *demangled;
+
+                     demangled = bfd_demangle (link_info.output_bfd, name,
+                                               DMGL_ANSI | DMGL_PARAMS);
+                     if (demangled != NULL)
+                       {
+                         fprintf (fp, "%s", demangled);
+                         free (demangled);
+                         break;
+                       }
+                   }
+                 fprintf (fp, "%s", name);
+               }
+             else
+               {
+                 /* native (host) void* pointer, like printf */
+                 fprintf (fp, "%p", args[arg_no].p);
+                 ++arg_count;
+               }
              break;
 
            case 's':
              break;
 
            case 's':
@@ -699,6 +691,6 @@ ld_abort (const char *file, int line, const char *fn)
   else
     einfo (_("%P: internal error: aborting at %s:%d\n"),
           file, line);
   else
     einfo (_("%P: internal error: aborting at %s:%d\n"),
           file, line);
-  einfo (_("%P%F: please report this bug\n"));
+  einfo (_("%F%P: please report this bug\n"));
   xexit (1);
 }
   xexit (1);
 }
This page took 0.028282 seconds and 4 git commands to generate.