Home | History | Annotate | Line # | Download | only in ld
ldmisc.c revision 1.8
      1  1.1  christos /* ldmisc.c
      2  1.8  christos    Copyright (C) 1991-2022 Free Software Foundation, Inc.
      3  1.1  christos    Written by Steve Chamberlain of Cygnus Support.
      4  1.1  christos 
      5  1.1  christos    This file is part of the GNU Binutils.
      6  1.1  christos 
      7  1.1  christos    This program is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10  1.1  christos    (at your option) any later version.
     11  1.1  christos 
     12  1.1  christos    This program is distributed in the hope that it will be useful,
     13  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos    GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with this program; if not, write to the Free Software
     19  1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20  1.1  christos    MA 02110-1301, USA.  */
     21  1.1  christos 
     22  1.1  christos #include "sysdep.h"
     23  1.1  christos #include "bfd.h"
     24  1.1  christos #include "bfdlink.h"
     25  1.1  christos #include "libiberty.h"
     26  1.7  christos #include "ctf-api.h"
     27  1.6  christos #include "safe-ctype.h"
     28  1.1  christos #include "filenames.h"
     29  1.1  christos #include "demangle.h"
     30  1.1  christos #include <stdarg.h>
     31  1.1  christos #include "ld.h"
     32  1.1  christos #include "ldmisc.h"
     33  1.1  christos #include "ldexp.h"
     34  1.1  christos #include "ldlang.h"
     35  1.1  christos #include <ldgram.h>
     36  1.1  christos #include "ldlex.h"
     37  1.1  christos #include "ldmain.h"
     38  1.1  christos #include "ldfile.h"
     39  1.1  christos 
     40  1.1  christos /*
     41  1.1  christos  %% literal %
     42  1.1  christos  %C clever filename:linenumber with function
     43  1.1  christos  %D like %C, but no function name
     44  1.1  christos  %E current bfd error or errno
     45  1.1  christos  %F error is fatal
     46  1.1  christos  %G like %D, but only function name
     47  1.1  christos  %H like %C but in addition emit section+offset
     48  1.1  christos  %P print program name
     49  1.1  christos  %V hex bfd_vma
     50  1.1  christos  %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
     51  1.1  christos  %X no object output, fail return
     52  1.1  christos  %d integer, like printf
     53  1.1  christos  %ld long, like printf
     54  1.1  christos  %lu unsigned long, like printf
     55  1.1  christos  %p native (host) void* pointer, like printf
     56  1.6  christos  %pA section name from a section
     57  1.6  christos  %pB filename from a bfd
     58  1.6  christos  %pI filename from a lang_input_statement_type
     59  1.6  christos  %pR info about a relent
     60  1.6  christos  %pS print script file and linenumber from etree_type.
     61  1.6  christos  %pT symbol name
     62  1.8  christos  %pU print script file without linenumber from etree_type.
     63  1.1  christos  %s arbitrary string, like printf
     64  1.1  christos  %u integer, like printf
     65  1.1  christos  %v hex bfd_vma, no leading zeros
     66  1.1  christos */
     67  1.1  christos 
     68  1.1  christos void
     69  1.8  christos vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning)
     70  1.1  christos {
     71  1.8  christos   bool fatal = false;
     72  1.6  christos   const char *scan;
     73  1.6  christos   int arg_type;
     74  1.6  christos   unsigned int arg_count = 0;
     75  1.6  christos   unsigned int arg_no;
     76  1.6  christos   union vfinfo_args
     77  1.6  christos   {
     78  1.6  christos     int i;
     79  1.6  christos     long l;
     80  1.6  christos     void *p;
     81  1.6  christos     bfd_vma v;
     82  1.6  christos     struct {
     83  1.6  christos       bfd *abfd;
     84  1.6  christos       asection *sec;
     85  1.6  christos       bfd_vma off;
     86  1.6  christos     } reladdr;
     87  1.6  christos     enum
     88  1.6  christos       {
     89  1.6  christos 	Bad,
     90  1.6  christos 	Int,
     91  1.6  christos 	Long,
     92  1.6  christos 	Ptr,
     93  1.6  christos 	Vma,
     94  1.6  christos 	RelAddr
     95  1.6  christos       } type;
     96  1.6  christos   } args[9];
     97  1.6  christos 
     98  1.6  christos   for (arg_no = 0; arg_no < sizeof (args) / sizeof (args[0]); arg_no++)
     99  1.6  christos     args[arg_no].type = Bad;
    100  1.6  christos 
    101  1.6  christos   arg_count = 0;
    102  1.6  christos   scan = fmt;
    103  1.6  christos   while (*scan != '\0')
    104  1.6  christos     {
    105  1.6  christos       while (*scan != '%' && *scan != '\0')
    106  1.6  christos 	scan++;
    107  1.6  christos 
    108  1.6  christos       if (*scan == '%')
    109  1.6  christos 	{
    110  1.6  christos 	  scan++;
    111  1.6  christos 
    112  1.6  christos 	  arg_no = arg_count;
    113  1.6  christos 	  if (*scan != '0' && ISDIGIT (*scan) && scan[1] == '$')
    114  1.6  christos 	    {
    115  1.6  christos 	      arg_no = *scan - '1';
    116  1.6  christos 	      scan += 2;
    117  1.6  christos 	    }
    118  1.6  christos 
    119  1.6  christos 	  arg_type = Bad;
    120  1.6  christos 	  switch (*scan++)
    121  1.6  christos 	    {
    122  1.6  christos 	    case '\0':
    123  1.6  christos 	      --scan;
    124  1.6  christos 	      break;
    125  1.6  christos 
    126  1.6  christos 	    case 'V':
    127  1.6  christos 	    case 'v':
    128  1.6  christos 	    case 'W':
    129  1.6  christos 	      arg_type = Vma;
    130  1.6  christos 	      break;
    131  1.6  christos 
    132  1.6  christos 	    case 's':
    133  1.6  christos 	      arg_type = Ptr;
    134  1.6  christos 	      break;
    135  1.6  christos 
    136  1.6  christos 	    case 'p':
    137  1.6  christos 	      if (*scan == 'A' || *scan == 'B' || *scan == 'I'
    138  1.6  christos 		  || *scan == 'R' || *scan == 'S' || *scan ==  'T')
    139  1.6  christos 		scan++;
    140  1.6  christos 	      arg_type = Ptr;
    141  1.6  christos 	      break;
    142  1.6  christos 
    143  1.6  christos 	    case 'C':
    144  1.6  christos 	    case 'D':
    145  1.6  christos 	    case 'G':
    146  1.6  christos 	    case 'H':
    147  1.6  christos 	      arg_type = RelAddr;
    148  1.6  christos 	      break;
    149  1.6  christos 
    150  1.6  christos 	    case 'd':
    151  1.6  christos 	    case 'u':
    152  1.6  christos 	      arg_type = Int;
    153  1.6  christos 	      break;
    154  1.6  christos 
    155  1.6  christos 	    case 'l':
    156  1.6  christos 	      if (*scan == 'd' || *scan == 'u')
    157  1.6  christos 		{
    158  1.6  christos 		  ++scan;
    159  1.6  christos 		  arg_type = Long;
    160  1.6  christos 		}
    161  1.6  christos 	      break;
    162  1.6  christos 
    163  1.6  christos 	    default:
    164  1.6  christos 	      break;
    165  1.6  christos 	    }
    166  1.6  christos 	  if (arg_type != Bad)
    167  1.6  christos 	    {
    168  1.6  christos 	      if (arg_no >= sizeof (args) / sizeof (args[0]))
    169  1.6  christos 		abort ();
    170  1.6  christos 	      args[arg_no].type = arg_type;
    171  1.6  christos 	      ++arg_count;
    172  1.6  christos 	    }
    173  1.6  christos 	}
    174  1.6  christos     }
    175  1.1  christos 
    176  1.6  christos   for (arg_no = 0; arg_no < arg_count; arg_no++)
    177  1.6  christos     {
    178  1.6  christos       switch (args[arg_no].type)
    179  1.6  christos 	{
    180  1.6  christos 	case Int:
    181  1.6  christos 	  args[arg_no].i = va_arg (ap, int);
    182  1.6  christos 	  break;
    183  1.6  christos 	case Long:
    184  1.6  christos 	  args[arg_no].l = va_arg (ap, long);
    185  1.6  christos 	  break;
    186  1.6  christos 	case Ptr:
    187  1.6  christos 	  args[arg_no].p = va_arg (ap, void *);
    188  1.6  christos 	  break;
    189  1.6  christos 	case Vma:
    190  1.6  christos 	  args[arg_no].v = va_arg (ap, bfd_vma);
    191  1.6  christos 	  break;
    192  1.6  christos 	case RelAddr:
    193  1.6  christos 	  args[arg_no].reladdr.abfd = va_arg (ap, bfd *);
    194  1.6  christos 	  args[arg_no].reladdr.sec = va_arg (ap, asection *);
    195  1.6  christos 	  args[arg_no].reladdr.off = va_arg (ap, bfd_vma);
    196  1.6  christos 	  break;
    197  1.6  christos 	default:
    198  1.6  christos 	  abort ();
    199  1.6  christos 	}
    200  1.6  christos     }
    201  1.6  christos 
    202  1.6  christos   arg_count = 0;
    203  1.1  christos   while (*fmt != '\0')
    204  1.1  christos     {
    205  1.1  christos       const char *str = fmt;
    206  1.1  christos       while (*fmt != '%' && *fmt != '\0')
    207  1.1  christos 	fmt++;
    208  1.1  christos       if (fmt != str)
    209  1.1  christos 	if (fwrite (str, 1, fmt - str, fp))
    210  1.1  christos 	  {
    211  1.1  christos 	    /* Ignore.  */
    212  1.1  christos 	  }
    213  1.1  christos 
    214  1.1  christos       if (*fmt == '%')
    215  1.1  christos 	{
    216  1.1  christos 	  fmt++;
    217  1.6  christos 
    218  1.6  christos 	  arg_no = arg_count;
    219  1.6  christos 	  if (*fmt != '0' && ISDIGIT (*fmt) && fmt[1] == '$')
    220  1.6  christos 	    {
    221  1.6  christos 	      arg_no = *fmt - '1';
    222  1.6  christos 	      fmt += 2;
    223  1.6  christos 	    }
    224  1.6  christos 
    225  1.1  christos 	  switch (*fmt++)
    226  1.1  christos 	    {
    227  1.6  christos 	    case '\0':
    228  1.6  christos 	      --fmt;
    229  1.6  christos 	      /* Fall through.  */
    230  1.6  christos 
    231  1.1  christos 	    case '%':
    232  1.1  christos 	      /* literal % */
    233  1.1  christos 	      putc ('%', fp);
    234  1.1  christos 	      break;
    235  1.1  christos 
    236  1.1  christos 	    case 'X':
    237  1.1  christos 	      /* no object output, fail return */
    238  1.8  christos 	      config.make_executable = false;
    239  1.1  christos 	      break;
    240  1.1  christos 
    241  1.1  christos 	    case 'V':
    242  1.1  christos 	      /* hex bfd_vma */
    243  1.1  christos 	      {
    244  1.6  christos 		bfd_vma value = args[arg_no].v;
    245  1.6  christos 		++arg_count;
    246  1.1  christos 		fprintf_vma (fp, value);
    247  1.1  christos 	      }
    248  1.1  christos 	      break;
    249  1.1  christos 
    250  1.1  christos 	    case 'v':
    251  1.1  christos 	      /* hex bfd_vma, no leading zeros */
    252  1.1  christos 	      {
    253  1.1  christos 		char buf[100];
    254  1.1  christos 		char *p = buf;
    255  1.6  christos 		bfd_vma value = args[arg_no].v;
    256  1.6  christos 		++arg_count;
    257  1.1  christos 		sprintf_vma (p, value);
    258  1.1  christos 		while (*p == '0')
    259  1.1  christos 		  p++;
    260  1.1  christos 		if (!*p)
    261  1.1  christos 		  p--;
    262  1.1  christos 		fputs (p, fp);
    263  1.1  christos 	      }
    264  1.1  christos 	      break;
    265  1.1  christos 
    266  1.1  christos 	    case 'W':
    267  1.1  christos 	      /* hex bfd_vma with 0x with no leading zeroes taking up
    268  1.1  christos 		 8 spaces.  */
    269  1.1  christos 	      {
    270  1.1  christos 		char buf[100];
    271  1.1  christos 		bfd_vma value;
    272  1.1  christos 		char *p;
    273  1.1  christos 		int len;
    274  1.1  christos 
    275  1.6  christos 		value = args[arg_no].v;
    276  1.6  christos 		++arg_count;
    277  1.1  christos 		sprintf_vma (buf, value);
    278  1.1  christos 		for (p = buf; *p == '0'; ++p)
    279  1.1  christos 		  ;
    280  1.1  christos 		if (*p == '\0')
    281  1.1  christos 		  --p;
    282  1.1  christos 		len = strlen (p);
    283  1.1  christos 		while (len < 8)
    284  1.1  christos 		  {
    285  1.1  christos 		    putc (' ', fp);
    286  1.1  christos 		    ++len;
    287  1.1  christos 		  }
    288  1.1  christos 		fprintf (fp, "0x%s", p);
    289  1.1  christos 	      }
    290  1.1  christos 	      break;
    291  1.1  christos 
    292  1.1  christos 	    case 'F':
    293  1.1  christos 	      /* Error is fatal.  */
    294  1.8  christos 	      fatal = true;
    295  1.1  christos 	      break;
    296  1.1  christos 
    297  1.1  christos 	    case 'P':
    298  1.1  christos 	      /* Print program name.  */
    299  1.1  christos 	      fprintf (fp, "%s", program_name);
    300  1.1  christos 	      break;
    301  1.1  christos 
    302  1.1  christos 	    case 'E':
    303  1.1  christos 	      /* current bfd error or errno */
    304  1.1  christos 	      fprintf (fp, "%s", bfd_errmsg (bfd_get_error ()));
    305  1.1  christos 	      break;
    306  1.1  christos 
    307  1.1  christos 	    case 'C':
    308  1.1  christos 	    case 'D':
    309  1.1  christos 	    case 'G':
    310  1.1  christos 	    case 'H':
    311  1.1  christos 	      /* Clever filename:linenumber with function name if possible.
    312  1.1  christos 		 The arguments are a BFD, a section, and an offset.  */
    313  1.1  christos 	      {
    314  1.1  christos 		static bfd *last_bfd;
    315  1.6  christos 		static char *last_file;
    316  1.6  christos 		static char *last_function;
    317  1.1  christos 		bfd *abfd;
    318  1.1  christos 		asection *section;
    319  1.1  christos 		bfd_vma offset;
    320  1.1  christos 		asymbol **asymbols = NULL;
    321  1.1  christos 		const char *filename;
    322  1.1  christos 		const char *functionname;
    323  1.1  christos 		unsigned int linenumber;
    324  1.8  christos 		bool discard_last;
    325  1.8  christos 		bool done;
    326  1.7  christos 		bfd_error_type last_bfd_error = bfd_get_error ();
    327  1.1  christos 
    328  1.6  christos 		abfd = args[arg_no].reladdr.abfd;
    329  1.6  christos 		section = args[arg_no].reladdr.sec;
    330  1.6  christos 		offset = args[arg_no].reladdr.off;
    331  1.6  christos 		++arg_count;
    332  1.1  christos 
    333  1.1  christos 		if (abfd != NULL)
    334  1.1  christos 		  {
    335  1.1  christos 		    if (!bfd_generic_link_read_symbols (abfd))
    336  1.6  christos 		      einfo (_("%F%P: %pB: could not read symbols: %E\n"), abfd);
    337  1.1  christos 
    338  1.1  christos 		    asymbols = bfd_get_outsymbols (abfd);
    339  1.1  christos 		  }
    340  1.1  christos 
    341  1.1  christos 		/* The GNU Coding Standard requires that error messages
    342  1.1  christos 		   be of the form:
    343  1.3  christos 
    344  1.1  christos 		     source-file-name:lineno: message
    345  1.1  christos 
    346  1.1  christos 		   We do not always have a line number available so if
    347  1.1  christos 		   we cannot find them we print out the section name and
    348  1.1  christos 		   offset instead.  */
    349  1.8  christos 		discard_last = true;
    350  1.1  christos 		if (abfd != NULL
    351  1.1  christos 		    && bfd_find_nearest_line (abfd, section, asymbols, offset,
    352  1.1  christos 					      &filename, &functionname,
    353  1.1  christos 					      &linenumber))
    354  1.1  christos 		  {
    355  1.1  christos 		    if (functionname != NULL
    356  1.1  christos 			&& (fmt[-1] == 'C' || fmt[-1] == 'H'))
    357  1.1  christos 		      {
    358  1.1  christos 			/* Detect the case where we are printing out a
    359  1.1  christos 			   message for the same function as the last
    360  1.1  christos 			   call to vinfo ("%C").  In this situation do
    361  1.1  christos 			   not print out the ABFD filename or the
    362  1.1  christos 			   function name again.  Note - we do still
    363  1.1  christos 			   print out the source filename, as this will
    364  1.1  christos 			   allow programs that parse the linker's output
    365  1.1  christos 			   (eg emacs) to correctly locate multiple
    366  1.1  christos 			   errors in the same source file.  */
    367  1.1  christos 			if (last_bfd == NULL
    368  1.1  christos 			    || last_function == NULL
    369  1.1  christos 			    || last_bfd != abfd
    370  1.6  christos 			    || (last_file == NULL) != (filename == NULL)
    371  1.1  christos 			    || (filename != NULL
    372  1.1  christos 				&& filename_cmp (last_file, filename) != 0)
    373  1.1  christos 			    || strcmp (last_function, functionname) != 0)
    374  1.1  christos 			  {
    375  1.6  christos 			    lfinfo (fp, _("%pB: in function `%pT':\n"),
    376  1.1  christos 				    abfd, functionname);
    377  1.1  christos 
    378  1.1  christos 			    last_bfd = abfd;
    379  1.8  christos 			    free (last_file);
    380  1.1  christos 			    last_file = NULL;
    381  1.1  christos 			    if (filename)
    382  1.1  christos 			      last_file = xstrdup (filename);
    383  1.8  christos 			    free (last_function);
    384  1.1  christos 			    last_function = xstrdup (functionname);
    385  1.1  christos 			  }
    386  1.8  christos 			discard_last = false;
    387  1.1  christos 		      }
    388  1.1  christos 		    else
    389  1.6  christos 		      lfinfo (fp, "%pB:", abfd);
    390  1.1  christos 
    391  1.1  christos 		    if (filename != NULL)
    392  1.1  christos 		      fprintf (fp, "%s:", filename);
    393  1.1  christos 
    394  1.1  christos 		    done = fmt[-1] != 'H';
    395  1.1  christos 		    if (functionname != NULL && fmt[-1] == 'G')
    396  1.6  christos 		      lfinfo (fp, "%pT", functionname);
    397  1.1  christos 		    else if (filename != NULL && linenumber != 0)
    398  1.3  christos 		      fprintf (fp, "%u%s", linenumber, done ? "" : ":");
    399  1.1  christos 		    else
    400  1.8  christos 		      done = false;
    401  1.1  christos 		  }
    402  1.1  christos 		else
    403  1.1  christos 		  {
    404  1.6  christos 		    lfinfo (fp, "%pB:", abfd);
    405  1.8  christos 		    done = false;
    406  1.1  christos 		  }
    407  1.1  christos 		if (!done)
    408  1.6  christos 		  lfinfo (fp, "(%pA+0x%v)", section, offset);
    409  1.7  christos 		bfd_set_error (last_bfd_error);
    410  1.1  christos 
    411  1.1  christos 		if (discard_last)
    412  1.1  christos 		  {
    413  1.1  christos 		    last_bfd = NULL;
    414  1.8  christos 		    free (last_file);
    415  1.8  christos 		    last_file = NULL;
    416  1.8  christos 		    free (last_function);
    417  1.8  christos 		    last_function = NULL;
    418  1.1  christos 		  }
    419  1.1  christos 	      }
    420  1.1  christos 	      break;
    421  1.1  christos 
    422  1.1  christos 	    case 'p':
    423  1.6  christos 	      if (*fmt == 'A')
    424  1.6  christos 		{
    425  1.6  christos 		  /* section name from a section */
    426  1.6  christos 		  asection *sec;
    427  1.6  christos 		  bfd *abfd;
    428  1.6  christos 
    429  1.6  christos 		  fmt++;
    430  1.6  christos 		  sec = (asection *) args[arg_no].p;
    431  1.6  christos 		  ++arg_count;
    432  1.7  christos 		  fprintf (fp, "%s", sec->name);
    433  1.6  christos 		  abfd = sec->owner;
    434  1.7  christos 		  if (abfd != NULL)
    435  1.7  christos 		    {
    436  1.7  christos 		      const char *group = bfd_group_name (abfd, sec);
    437  1.7  christos 		      if (group != NULL)
    438  1.7  christos 			fprintf (fp, "[%s]", group);
    439  1.7  christos 		    }
    440  1.6  christos 		}
    441  1.6  christos 	      else if (*fmt == 'B')
    442  1.6  christos 		{
    443  1.6  christos 		  /* filename from a bfd */
    444  1.6  christos 		  bfd *abfd = (bfd *) args[arg_no].p;
    445  1.6  christos 
    446  1.6  christos 		  fmt++;
    447  1.6  christos 		  ++arg_count;
    448  1.6  christos 		  if (abfd == NULL)
    449  1.6  christos 		    fprintf (fp, "%s generated", program_name);
    450  1.6  christos 		  else if (abfd->my_archive != NULL
    451  1.6  christos 			   && !bfd_is_thin_archive (abfd->my_archive))
    452  1.8  christos 		    fprintf (fp, "%s(%s)",
    453  1.8  christos 			     bfd_get_filename (abfd->my_archive),
    454  1.8  christos 			     bfd_get_filename (abfd));
    455  1.6  christos 		  else
    456  1.8  christos 		    fprintf (fp, "%s", bfd_get_filename (abfd));
    457  1.6  christos 		}
    458  1.6  christos 	      else if (*fmt == 'I')
    459  1.6  christos 		{
    460  1.6  christos 		  /* filename from a lang_input_statement_type */
    461  1.6  christos 		  lang_input_statement_type *i;
    462  1.6  christos 
    463  1.6  christos 		  fmt++;
    464  1.6  christos 		  i = (lang_input_statement_type *) args[arg_no].p;
    465  1.6  christos 		  ++arg_count;
    466  1.7  christos 		  if (i->the_bfd != NULL
    467  1.7  christos 		      && i->the_bfd->my_archive != NULL
    468  1.6  christos 		      && !bfd_is_thin_archive (i->the_bfd->my_archive))
    469  1.8  christos 		    fprintf (fp, "(%s)%s",
    470  1.8  christos 			     bfd_get_filename (i->the_bfd->my_archive),
    471  1.7  christos 			     i->local_sym_name);
    472  1.7  christos 		  else
    473  1.7  christos 		    fprintf (fp, "%s", i->filename);
    474  1.6  christos 		}
    475  1.6  christos 	      else if (*fmt == 'R')
    476  1.6  christos 		{
    477  1.6  christos 		  /* Print all that's interesting about a relent.  */
    478  1.6  christos 		  arelent *relent = (arelent *) args[arg_no].p;
    479  1.6  christos 
    480  1.6  christos 		  fmt++;
    481  1.6  christos 		  ++arg_count;
    482  1.6  christos 		  lfinfo (fp, "%s+0x%v (type %s)",
    483  1.6  christos 			  (*(relent->sym_ptr_ptr))->name,
    484  1.6  christos 			  relent->addend,
    485  1.6  christos 			  relent->howto->name);
    486  1.6  christos 		}
    487  1.8  christos 	      else if (*fmt == 'S' || *fmt == 'U')
    488  1.6  christos 		{
    489  1.8  christos 		  /* Print script file and perhaps the associated linenumber.  */
    490  1.6  christos 		  etree_type node;
    491  1.6  christos 		  etree_type *tp = (etree_type *) args[arg_no].p;
    492  1.6  christos 
    493  1.6  christos 		  fmt++;
    494  1.6  christos 		  ++arg_count;
    495  1.6  christos 		  if (tp == NULL)
    496  1.6  christos 		    {
    497  1.6  christos 		      tp = &node;
    498  1.6  christos 		      tp->type.filename = ldlex_filename ();
    499  1.6  christos 		      tp->type.lineno = lineno;
    500  1.6  christos 		    }
    501  1.8  christos 		  if (tp->type.filename != NULL && fmt[-1] == 'S')
    502  1.6  christos 		    fprintf (fp, "%s:%u", tp->type.filename, tp->type.lineno);
    503  1.8  christos 		  else if (tp->type.filename != NULL && fmt[-1] == 'U')
    504  1.8  christos 		    fprintf (fp, "%s", tp->type.filename);
    505  1.6  christos 		}
    506  1.6  christos 	      else if (*fmt == 'T')
    507  1.6  christos 		{
    508  1.6  christos 		  /* Symbol name.  */
    509  1.6  christos 		  const char *name = (const char *) args[arg_no].p;
    510  1.6  christos 
    511  1.6  christos 		  fmt++;
    512  1.6  christos 		  ++arg_count;
    513  1.6  christos 		  if (name == NULL || *name == 0)
    514  1.6  christos 		    {
    515  1.6  christos 		      fprintf (fp, _("no symbol"));
    516  1.6  christos 		      break;
    517  1.6  christos 		    }
    518  1.6  christos 		  else if (demangling)
    519  1.6  christos 		    {
    520  1.6  christos 		      char *demangled;
    521  1.6  christos 
    522  1.6  christos 		      demangled = bfd_demangle (link_info.output_bfd, name,
    523  1.6  christos 						DMGL_ANSI | DMGL_PARAMS);
    524  1.6  christos 		      if (demangled != NULL)
    525  1.6  christos 			{
    526  1.6  christos 			  fprintf (fp, "%s", demangled);
    527  1.6  christos 			  free (demangled);
    528  1.6  christos 			  break;
    529  1.6  christos 			}
    530  1.6  christos 		    }
    531  1.6  christos 		  fprintf (fp, "%s", name);
    532  1.6  christos 		}
    533  1.6  christos 	      else
    534  1.6  christos 		{
    535  1.6  christos 		  /* native (host) void* pointer, like printf */
    536  1.6  christos 		  fprintf (fp, "%p", args[arg_no].p);
    537  1.6  christos 		  ++arg_count;
    538  1.6  christos 		}
    539  1.1  christos 	      break;
    540  1.1  christos 
    541  1.1  christos 	    case 's':
    542  1.1  christos 	      /* arbitrary string, like printf */
    543  1.6  christos 	      fprintf (fp, "%s", (char *) args[arg_no].p);
    544  1.6  christos 	      ++arg_count;
    545  1.1  christos 	      break;
    546  1.1  christos 
    547  1.1  christos 	    case 'd':
    548  1.1  christos 	      /* integer, like printf */
    549  1.6  christos 	      fprintf (fp, "%d", args[arg_no].i);
    550  1.6  christos 	      ++arg_count;
    551  1.1  christos 	      break;
    552  1.1  christos 
    553  1.1  christos 	    case 'u':
    554  1.1  christos 	      /* unsigned integer, like printf */
    555  1.6  christos 	      fprintf (fp, "%u", args[arg_no].i);
    556  1.6  christos 	      ++arg_count;
    557  1.1  christos 	      break;
    558  1.1  christos 
    559  1.1  christos 	    case 'l':
    560  1.1  christos 	      if (*fmt == 'd')
    561  1.1  christos 		{
    562  1.6  christos 		  fprintf (fp, "%ld", args[arg_no].l);
    563  1.6  christos 		  ++arg_count;
    564  1.1  christos 		  ++fmt;
    565  1.1  christos 		  break;
    566  1.1  christos 		}
    567  1.1  christos 	      else if (*fmt == 'u')
    568  1.1  christos 		{
    569  1.6  christos 		  fprintf (fp, "%lu", args[arg_no].l);
    570  1.6  christos 		  ++arg_count;
    571  1.1  christos 		  ++fmt;
    572  1.1  christos 		  break;
    573  1.1  christos 		}
    574  1.6  christos 	      /* Fallthru */
    575  1.1  christos 
    576  1.1  christos 	    default:
    577  1.1  christos 	      fprintf (fp, "%%%c", fmt[-1]);
    578  1.1  christos 	      break;
    579  1.1  christos 	    }
    580  1.1  christos 	}
    581  1.1  christos     }
    582  1.1  christos 
    583  1.1  christos   if (is_warning && config.fatal_warnings)
    584  1.8  christos     config.make_executable = false;
    585  1.1  christos 
    586  1.1  christos   if (fatal)
    587  1.1  christos     xexit (1);
    588  1.1  christos }
    589  1.1  christos 
    590  1.1  christos /* Format info message and print on stdout.  */
    591  1.1  christos 
    592  1.1  christos /* (You would think this should be called just "info", but then you
    593  1.1  christos    would be hosed by LynxOS, which defines that name in its libc.)  */
    594  1.1  christos 
    595  1.1  christos void
    596  1.1  christos info_msg (const char *fmt, ...)
    597  1.1  christos {
    598  1.1  christos   va_list arg;
    599  1.1  christos 
    600  1.1  christos   va_start (arg, fmt);
    601  1.8  christos   vfinfo (stdout, fmt, arg, false);
    602  1.1  christos   va_end (arg);
    603  1.1  christos }
    604  1.1  christos 
    605  1.1  christos /* ('e' for error.) Format info message and print on stderr.  */
    606  1.1  christos 
    607  1.1  christos void
    608  1.1  christos einfo (const char *fmt, ...)
    609  1.1  christos {
    610  1.1  christos   va_list arg;
    611  1.1  christos 
    612  1.1  christos   fflush (stdout);
    613  1.1  christos   va_start (arg, fmt);
    614  1.8  christos   vfinfo (stderr, fmt, arg, true);
    615  1.1  christos   va_end (arg);
    616  1.1  christos   fflush (stderr);
    617  1.1  christos }
    618  1.1  christos 
    619  1.1  christos void
    620  1.1  christos info_assert (const char *file, unsigned int line)
    621  1.1  christos {
    622  1.1  christos   einfo (_("%F%P: internal error %s %d\n"), file, line);
    623  1.1  christos }
    624  1.1  christos 
    625  1.1  christos /* ('m' for map) Format info message and print on map.  */
    626  1.1  christos 
    627  1.1  christos void
    628  1.1  christos minfo (const char *fmt, ...)
    629  1.1  christos {
    630  1.1  christos   if (config.map_file != NULL)
    631  1.1  christos     {
    632  1.1  christos       va_list arg;
    633  1.1  christos 
    634  1.1  christos       va_start (arg, fmt);
    635  1.3  christos       if (fmt[0] == '%' && fmt[1] == '!' && fmt[2] == 0)
    636  1.3  christos 	{
    637  1.3  christos 	  /* Stash info about --as-needed shared libraries.  Print
    638  1.3  christos 	     later so they don't appear intermingled with archive
    639  1.3  christos 	     library info.  */
    640  1.3  christos 	  struct asneeded_minfo *m = xmalloc (sizeof *m);
    641  1.3  christos 
    642  1.3  christos 	  m->next = NULL;
    643  1.3  christos 	  m->soname = va_arg (arg, const char *);
    644  1.3  christos 	  m->ref = va_arg (arg, bfd *);
    645  1.3  christos 	  m->name = va_arg (arg, const char *);
    646  1.3  christos 	  *asneeded_list_tail = m;
    647  1.3  christos 	  asneeded_list_tail = &m->next;
    648  1.3  christos 	}
    649  1.3  christos       else
    650  1.8  christos 	vfinfo (config.map_file, fmt, arg, false);
    651  1.1  christos       va_end (arg);
    652  1.1  christos     }
    653  1.1  christos }
    654  1.1  christos 
    655  1.1  christos void
    656  1.1  christos lfinfo (FILE *file, const char *fmt, ...)
    657  1.1  christos {
    658  1.1  christos   va_list arg;
    659  1.1  christos 
    660  1.1  christos   va_start (arg, fmt);
    661  1.8  christos   vfinfo (file, fmt, arg, false);
    662  1.1  christos   va_end (arg);
    663  1.1  christos }
    664  1.1  christos 
    665  1.1  christos /* Functions to print the link map.  */
    667  1.1  christos 
    668  1.1  christos void
    669  1.1  christos print_space (void)
    670  1.1  christos {
    671  1.1  christos   fprintf (config.map_file, " ");
    672  1.1  christos }
    673  1.1  christos 
    674  1.1  christos void
    675  1.1  christos print_nl (void)
    676  1.1  christos {
    677  1.1  christos   fprintf (config.map_file, "\n");
    678  1.1  christos }
    679  1.1  christos 
    680  1.1  christos /* A more or less friendly abort message.  In ld.h abort is defined to
    681  1.1  christos    call this function.  */
    682  1.1  christos 
    683  1.1  christos void
    684  1.1  christos ld_abort (const char *file, int line, const char *fn)
    685  1.1  christos {
    686  1.3  christos   if (fn != NULL)
    687  1.1  christos     einfo (_("%P: internal error: aborting at %s:%d in %s\n"),
    688  1.1  christos 	   file, line, fn);
    689  1.3  christos   else
    690  1.1  christos     einfo (_("%P: internal error: aborting at %s:%d\n"),
    691  1.6  christos 	   file, line);
    692  1.1  christos   einfo (_("%F%P: please report this bug\n"));
    693  1.1  christos   xexit (1);
    694                }
    695