2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
5 Written by Steve Chamberlain of Cygnus Support.
7 This file is part of GLD, the Gnu Linker.
9 GLD is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GLD is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GLD; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "libiberty.h"
29 #ifdef ANSI_PROTOTYPES
44 static void vfinfo
PARAMS ((FILE *, const char *, va_list));
50 %S print script file and linenumber
51 %E current bfd error or errno
52 %I filename from a lang_input_statement_type
53 %B filename from a bfd
55 %X no object output, fail return
57 %v hex bfd_vma, no leading zeros
58 %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
59 %C clever filename:linenumber with function
60 %D like %C, but no function name
61 %G like %D, but only function name
62 %R info about a relent
63 %s arbitrary string, like printf
64 %d integer, like printf
65 %u integer, like printf
75 if (output_bfd
!= NULL
76 && bfd_get_symbol_leading_char (output_bfd
) == string
[0])
79 /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF
80 or the MS PE format. These formats have a number of leading '.'s
81 on at least some symbols, so we remove all dots. */
86 res
= cplus_demangle (p
, DMGL_ANSI
| DMGL_PARAMS
);
87 return res
? res
: xstrdup (string
);
96 boolean fatal
= false;
100 while (*fmt
!= '%' && *fmt
!= '\0')
112 fprintf (fp
, "%%%c", fmt
[-1]);
121 /* no object output, fail return */
122 config
.make_executable
= false;
128 bfd_vma value
= va_arg (arg
, bfd_vma
);
129 fprintf_vma (fp
, value
);
134 /* hex bfd_vma, no leading zeros */
138 bfd_vma value
= va_arg (arg
, bfd_vma
);
139 sprintf_vma (p
, value
);
149 /* hex bfd_vma with 0x with no leading zeroes taking up
157 value
= va_arg (arg
, bfd_vma
);
158 sprintf_vma (buf
, value
);
159 for (p
= buf
; *p
== '0'; ++p
)
169 fprintf (fp
, "0x%s", p
);
176 const char *name
= va_arg (arg
, const char *);
178 if (name
== (const char *) NULL
|| *name
== 0)
179 fprintf (fp
, _("no symbol"));
180 else if (! demangling
)
181 fprintf (fp
, "%s", name
);
186 demangled
= demangle (name
);
187 fprintf (fp
, "%s", demangled
);
194 /* filename from a bfd */
196 bfd
*abfd
= va_arg (arg
, bfd
*);
197 if (abfd
->my_archive
)
198 fprintf (fp
, "%s(%s)", abfd
->my_archive
->filename
,
201 fprintf (fp
, "%s", abfd
->filename
);
206 /* Error is fatal. */
211 /* Print program name. */
212 fprintf (fp
, "%s", program_name
);
216 /* current bfd error or errno */
217 fprintf (fp
, "%s", bfd_errmsg (bfd_get_error ()));
221 /* filename from a lang_input_statement_type */
223 lang_input_statement_type
*i
;
225 i
= va_arg (arg
, lang_input_statement_type
*);
226 if (bfd_my_archive (i
->the_bfd
) != NULL
)
228 bfd_get_filename (bfd_my_archive (i
->the_bfd
)));
229 fprintf (fp
, "%s", i
->local_sym_name
);
230 if (bfd_my_archive (i
->the_bfd
) == NULL
231 && strcmp (i
->local_sym_name
, i
->filename
) != 0)
232 fprintf (fp
, " (%s)", i
->filename
);
237 /* Print script file and linenumber. */
239 fprintf (fp
, "--defsym %s", lex_string
);
240 else if (ldfile_input_filename
!= NULL
)
241 fprintf (fp
, "%s:%u", ldfile_input_filename
, lineno
);
243 fprintf (fp
, _("built in linker script:%u"), lineno
);
247 /* Print all that's interesting about a relent. */
249 arelent
*relent
= va_arg (arg
, arelent
*);
251 lfinfo (fp
, "%s+0x%v (type %s)",
252 (*(relent
->sym_ptr_ptr
))->name
,
254 relent
->howto
->name
);
261 /* Clever filename:linenumber with function name if possible,
262 or section name as a last resort. The arguments are a BFD,
263 a section, and an offset. */
265 static bfd
*last_bfd
;
266 static char *last_file
= NULL
;
267 static char *last_function
= NULL
;
271 lang_input_statement_type
*entry
;
273 const char *filename
;
274 const char *functionname
;
275 unsigned int linenumber
;
276 boolean discard_last
;
278 abfd
= va_arg (arg
, bfd
*);
279 section
= va_arg (arg
, asection
*);
280 offset
= va_arg (arg
, bfd_vma
);
282 entry
= (lang_input_statement_type
*) abfd
->usrdata
;
283 if (entry
!= (lang_input_statement_type
*) NULL
284 && entry
->asymbols
!= (asymbol
**) NULL
)
285 asymbols
= entry
->asymbols
;
291 symsize
= bfd_get_symtab_upper_bound (abfd
);
293 einfo (_("%B%F: could not read symbols\n"), abfd
);
294 asymbols
= (asymbol
**) xmalloc (symsize
);
295 symbol_count
= bfd_canonicalize_symtab (abfd
, asymbols
);
296 if (symbol_count
< 0)
297 einfo (_("%B%F: could not read symbols\n"), abfd
);
298 if (entry
!= (lang_input_statement_type
*) NULL
)
300 entry
->asymbols
= asymbols
;
301 entry
->symbol_count
= symbol_count
;
306 if (bfd_find_nearest_line (abfd
, section
, asymbols
, offset
,
307 &filename
, &functionname
,
310 if (functionname
!= NULL
&& fmt
[-1] == 'G')
312 lfinfo (fp
, "%B:", abfd
);
314 && strcmp (filename
, bfd_get_filename (abfd
)) != 0)
315 fprintf (fp
, "%s:", filename
);
316 lfinfo (fp
, "%T", functionname
);
318 else if (functionname
!= NULL
&& fmt
[-1] == 'C')
320 if (filename
== (char *) NULL
)
321 filename
= abfd
->filename
;
325 || last_function
== NULL
327 || strcmp (last_file
, filename
) != 0
328 || strcmp (last_function
, functionname
) != 0)
330 /* We use abfd->filename in this initial line,
331 in case filename is a .h file or something
332 similarly unhelpful. */
333 lfinfo (fp
, _("%B: In function `%T':\n"),
337 if (last_file
!= NULL
)
339 last_file
= xstrdup (filename
);
340 if (last_function
!= NULL
)
341 free (last_function
);
342 last_function
= xstrdup (functionname
);
344 discard_last
= false;
346 fprintf (fp
, "%s:%u", filename
, linenumber
);
348 lfinfo (fp
, "%s(%s+0x%v)", filename
, section
->name
,
351 else if (filename
== NULL
352 || strcmp (filename
, abfd
->filename
) == 0)
354 lfinfo (fp
, "%B(%s+0x%v)", abfd
, section
->name
,
357 lfinfo (fp
, ":%u", linenumber
);
359 else if (linenumber
!= 0)
360 lfinfo (fp
, "%B:%s:%u", abfd
, filename
, linenumber
);
362 lfinfo (fp
, "%B(%s+0x%v):%s", abfd
, section
->name
,
366 lfinfo (fp
, "%B(%s+0x%v)", abfd
, section
->name
, offset
);
371 if (last_file
!= NULL
)
376 if (last_function
!= NULL
)
378 free (last_function
);
379 last_function
= NULL
;
386 /* arbitrary string, like printf */
387 fprintf (fp
, "%s", va_arg (arg
, char *));
391 /* integer, like printf */
392 fprintf (fp
, "%d", va_arg (arg
, int));
396 /* unsigned integer, like printf */
397 fprintf (fp
, "%u", va_arg (arg
, unsigned int));
403 if (config
.fatal_warnings
)
404 config
.make_executable
= false;
410 /* Format info message and print on stdout. */
412 /* (You would think this should be called just "info", but then you
413 would hosed by LynxOS, which defines that name in its libc.) */
416 info_msg
VPARAMS ((const char *fmt
, ...))
419 VA_FIXEDARG (arg
, const char *, fmt
);
421 vfinfo (stdout
, fmt
, arg
);
425 /* ('e' for error.) Format info message and print on stderr. */
428 einfo
VPARAMS ((const char *fmt
, ...))
431 VA_FIXEDARG (arg
, const char *, fmt
);
433 vfinfo (stderr
, fmt
, arg
);
438 info_assert (file
, line
)
442 einfo (_("%F%P: internal error %s %d\n"), file
, line
);
445 /* ('m' for map) Format info message and print on map. */
448 minfo
VPARAMS ((const char *fmt
, ...))
451 VA_FIXEDARG (arg
, const char *, fmt
);
453 vfinfo (config
.map_file
, fmt
, arg
);
458 lfinfo
VPARAMS ((FILE *file
, const char *fmt
, ...))
461 VA_FIXEDARG (arg
, FILE *, file
);
462 VA_FIXEDARG (arg
, const char *, fmt
);
464 vfinfo (file
, fmt
, arg
);
468 /* Functions to print the link map. */
473 fprintf (config
.map_file
, " ");
479 fprintf (config
.map_file
, "\n");
482 /* A more or less friendly abort message. In ld.h abort is defined to
483 call this function. */
486 ld_abort (file
, line
, fn
)
492 einfo (_("%P: internal error: aborting at %s line %d in %s\n"),
495 einfo (_("%P: internal error: aborting at %s line %d\n"),
497 einfo (_("%P%F: please report this bug\n"));