]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - ld/ldmisc.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / ldmisc.c
index 848e227b0523bc610e2f1bf237632af79614ea4c..5d7012e50b12da9a54d3b891a86d3f6a8997e81c 100644 (file)
@@ -1,5 +1,5 @@
 /* ldmisc.c
-   Copyright (C) 1991-2019 Free Software Foundation, Inc.
+   Copyright (C) 1991-2023 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support.
 
    This file is part of the GNU Binutils.
@@ -47,7 +47,7 @@
  %H like %C but in addition emit section+offset
  %P print program name
  %V hex bfd_vma
- %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
+ %W hex bfd_vma with 0x with no leading zeros taking up 10 spaces
  %X no object output, fail return
  %d integer, like printf
  %ld long, like printf
  %pR info about a relent
  %pS print script file and linenumber from etree_type.
  %pT symbol name
+ %pU print script file without linenumber from etree_type.
  %s arbitrary string, like printf
  %u integer, like printf
  %v hex bfd_vma, no leading zeros
 */
 
 void
-vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
+vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning)
 {
-  bfd_boolean fatal = FALSE;
+  bool fatal = false;
   const char *scan;
   int arg_type;
   unsigned int arg_count = 0;
@@ -94,6 +95,9 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
       } type;
   } args[9];
 
+  if (is_warning && config.no_warnings)
+    return;
+  
   for (arg_no = 0; arg_no < sizeof (args) / sizeof (args[0]); arg_no++)
     args[arg_no].type = Bad;
 
@@ -234,63 +238,48 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
 
            case 'X':
              /* no object output, fail return */
-             config.make_executable = FALSE;
+             config.make_executable = false;
              break;
 
            case 'V':
              /* hex bfd_vma */
              {
-               bfd_vma value = args[arg_no].v;
+               char buf[32];
+               bfd_vma value;
+
+               value = args[arg_no].v;
                ++arg_count;
-               fprintf_vma (fp, value);
+               bfd_sprintf_vma (link_info.output_bfd, buf, value);
+               fprintf (fp, "%s", buf);
              }
              break;
 
            case 'v':
              /* hex bfd_vma, no leading zeros */
              {
-               char buf[100];
-               char *p = buf;
-               bfd_vma value = args[arg_no].v;
+               uint64_t value = args[arg_no].v;
                ++arg_count;
-               sprintf_vma (p, value);
-               while (*p == '0')
-                 p++;
-               if (!*p)
-                 p--;
-               fputs (p, fp);
+               fprintf (fp, "%" PRIx64, value);
              }
              break;
 
            case 'W':
              /* hex bfd_vma with 0x with no leading zeroes taking up
-                8 spaces.  */
+                10 spaces (including the 0x).  */
              {
-               char buf[100];
-               bfd_vma value;
-               char *p;
-               int len;
+               char buf[32];
+               uint64_t value;
 
                value = args[arg_no].v;
                ++arg_count;
-               sprintf_vma (buf, value);
-               for (p = buf; *p == '0'; ++p)
-                 ;
-               if (*p == '\0')
-                 --p;
-               len = strlen (p);
-               while (len < 8)
-                 {
-                   putc (' ', fp);
-                   ++len;
-                 }
-               fprintf (fp, "0x%s", p);
+               sprintf (buf, "0x%" PRIx64, value);
+               fprintf (fp, "%10s", buf);
              }
              break;
 
            case 'F':
              /* Error is fatal.  */
-             fatal = TRUE;
+             fatal = true;
              break;
 
            case 'P':
@@ -320,8 +309,9 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                const char *filename;
                const char *functionname;
                unsigned int linenumber;
-               bfd_boolean discard_last;
-               bfd_boolean done;
+               bool discard_last;
+               bool done;
+               bfd_error_type last_bfd_error = bfd_get_error ();
 
                abfd = args[arg_no].reladdr.abfd;
                section = args[arg_no].reladdr.sec;
@@ -344,7 +334,7 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                   We do not always have a line number available so if
                   we cannot find them we print out the section name and
                   offset instead.  */
-               discard_last = TRUE;
+               discard_last = true;
                if (abfd != NULL
                    && bfd_find_nearest_line (abfd, section, asymbols, offset,
                                              &filename, &functionname,
@@ -374,16 +364,14 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                                    abfd, functionname);
 
                            last_bfd = abfd;
-                           if (last_file != NULL)
-                             free (last_file);
+                           free (last_file);
                            last_file = NULL;
                            if (filename)
                              last_file = xstrdup (filename);
-                           if (last_function != NULL)
-                             free (last_function);
+                           free (last_function);
                            last_function = xstrdup (functionname);
                          }
-                       discard_last = FALSE;
+                       discard_last = false;
                      }
                    else
                      lfinfo (fp, "%pB:", abfd);
@@ -397,29 +385,24 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                    else if (filename != NULL && linenumber != 0)
                      fprintf (fp, "%u%s", linenumber, done ? "" : ":");
                    else
-                     done = FALSE;
+                     done = false;
                  }
                else
                  {
                    lfinfo (fp, "%pB:", abfd);
-                   done = FALSE;
+                   done = false;
                  }
                if (!done)
                  lfinfo (fp, "(%pA+0x%v)", section, offset);
+               bfd_set_error (last_bfd_error);
 
                if (discard_last)
                  {
                    last_bfd = NULL;
-                   if (last_file != NULL)
-                     {
-                       free (last_file);
-                       last_file = NULL;
-                     }
-                   if (last_function != NULL)
-                     {
-                       free (last_function);
-                       last_function = NULL;
-                     }
+                   free (last_file);
+                   last_file = NULL;
+                   free (last_function);
+                   last_function = NULL;
                  }
              }
              break;
@@ -454,10 +437,11 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                    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);
+                   fprintf (fp, "%s(%s)",
+                            bfd_get_filename (abfd->my_archive),
+                            bfd_get_filename (abfd));
                  else
-                   fprintf (fp, "%s", abfd->filename);
+                   fprintf (fp, "%s", bfd_get_filename (abfd));
                }
              else if (*fmt == 'I')
                {
@@ -470,7 +454,8 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                  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,
+                   fprintf (fp, "(%s)%s",
+                            bfd_get_filename (i->the_bfd->my_archive),
                             i->local_sym_name);
                  else
                    fprintf (fp, "%s", i->filename);
@@ -487,9 +472,9 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                          relent->addend,
                          relent->howto->name);
                }
-             else if (*fmt == 'S')
+             else if (*fmt == 'S' || *fmt == 'U')
                {
-                 /* Print script file and linenumber.  */
+                 /* Print script file and perhaps the associated linenumber.  */
                  etree_type node;
                  etree_type *tp = (etree_type *) args[arg_no].p;
 
@@ -501,8 +486,10 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                      tp->type.filename = ldlex_filename ();
                      tp->type.lineno = lineno;
                    }
-                 if (tp->type.filename != NULL)
+                 if (tp->type.filename != NULL && fmt[-1] == 'S')
                    fprintf (fp, "%s:%u", tp->type.filename, tp->type.lineno);
+                 else if (tp->type.filename != NULL && fmt[-1] == 'U')
+                   fprintf (fp, "%s", tp->type.filename);
                }
              else if (*fmt == 'T')
                {
@@ -582,7 +569,7 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
     }
 
   if (is_warning && config.fatal_warnings)
-    config.make_executable = FALSE;
+    config.make_executable = false;
 
   if (fatal)
     xexit (1);
@@ -599,7 +586,7 @@ info_msg (const char *fmt, ...)
   va_list arg;
 
   va_start (arg, fmt);
-  vfinfo (stdout, fmt, arg, FALSE);
+  vfinfo (stdout, fmt, arg, false);
   va_end (arg);
 }
 
@@ -612,7 +599,7 @@ einfo (const char *fmt, ...)
 
   fflush (stdout);
   va_start (arg, fmt);
-  vfinfo (stderr, fmt, arg, TRUE);
+  vfinfo (stderr, fmt, arg, true);
   va_end (arg);
   fflush (stderr);
 }
@@ -648,7 +635,7 @@ minfo (const char *fmt, ...)
          asneeded_list_tail = &m->next;
        }
       else
-       vfinfo (config.map_file, fmt, arg, FALSE);
+       vfinfo (config.map_file, fmt, arg, false);
       va_end (arg);
     }
 }
@@ -659,16 +646,16 @@ lfinfo (FILE *file, const char *fmt, ...)
   va_list arg;
 
   va_start (arg, fmt);
-  vfinfo (file, fmt, arg, FALSE);
+  vfinfo (file, fmt, arg, false);
   va_end (arg);
 }
 \f
 /* Functions to print the link map.  */
 
 void
-print_space (void)
+print_spaces (int count)
 {
-  fprintf (config.map_file, " ");
+  fprintf (config.map_file, "%*s", count, "");
 }
 
 void