Fix linker tests to work with 16-bit targets.
[deliverable/binutils-gdb.git] / ld / ldmisc.c
index e3fdac3c0e35435f357f61332da67adc9de4c7c2..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"
@@ -35,8 +36,6 @@
 #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 %
  %F error is fatal
  %G like %D, but only function name
  %H like %C but in addition emit section+offset
  %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
  %p native (host) void* pointer, like printf
  %pA section name from a section
  %pB filename from a bfd
  %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,16 +128,13 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
              arg_type = Vma;
              break;
 
              arg_type = Vma;
              break;
 
-           case 'T':
-           case 'I':
-           case 'S':
-           case 'R':
            case 's':
              arg_type = Ptr;
              break;
 
            case 'p':
            case 's':
              arg_type = Ptr;
              break;
 
            case 'p':
-             if (*scan == 'A' || *scan == 'B')
+             if (*scan == 'A' || *scan == 'B' || *scan == 'I'
+                 || *scan == 'R' || *scan == 'S' || *scan ==  'T')
                scan++;
              arg_type = Ptr;
              break;
                scan++;
              arg_type = Ptr;
              break;
@@ -292,33 +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 'F':
              /* Error is fatal.  */
              fatal = TRUE;
            case 'F':
              /* Error is fatal.  */
              fatal = TRUE;
@@ -334,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':
@@ -401,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;
@@ -410,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 (_("%pB%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);
                  }
@@ -449,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, _("%pB: In function `%T':\n"),
+                           lfinfo (fp, _("%pB: in function `%pT':\n"),
                                    abfd, functionname);
 
                            last_bfd = abfd;
                                    abfd, functionname);
 
                            last_bfd = abfd;
@@ -472,7 +394,7 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
 
                    done = fmt[-1] != 'H';
                    if (functionname != NULL && fmt[-1] == 'G')
 
                    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
@@ -485,6 +407,7 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                  }
                if (!done)
                  lfinfo (fp, "(%pA+0x%v)", section, offset);
                  }
                if (!done)
                  lfinfo (fp, "(%pA+0x%v)", section, offset);
+               bfd_set_error (last_bfd_error);
 
                if (discard_last)
                  {
 
                if (discard_last)
                  {
@@ -509,26 +432,18 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                  /* section name from a section */
                  asection *sec;
                  bfd *abfd;
                  /* section name from a section */
                  asection *sec;
                  bfd *abfd;
-                 const char *group = NULL;
-                 struct coff_comdat_info *ci;
 
                  fmt++;
                  sec = (asection *) args[arg_no].p;
                  ++arg_count;
 
                  fmt++;
                  sec = (asection *) args[arg_no].p;
                  ++arg_count;
-                 abfd = sec->owner;
                  fprintf (fp, "%s", sec->name);
                  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);
+                 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')
                {
                }
              else if (*fmt == 'B')
                {
@@ -546,6 +461,78 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                  else
                    fprintf (fp, "%s", 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 */
              else
                {
                  /* native (host) void* pointer, like printf */
@@ -704,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.033814 seconds and 4 git commands to generate.