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
74 bfd_boolean fatal
= FALSE
;
78 while (*fmt
!= '%' && *fmt
!= '\0')
90 fprintf (fp
, "%%%c", fmt
[-1]);
99 /* no object output, fail return */
100 config
.make_executable
= FALSE
;
106 bfd_vma value
= va_arg (arg
, bfd_vma
);
107 fprintf_vma (fp
, value
);
112 /* hex bfd_vma, no leading zeros */
116 bfd_vma value
= va_arg (arg
, bfd_vma
);
117 sprintf_vma (p
, value
);
127 /* hex bfd_vma with 0x with no leading zeroes taking up
135 value
= va_arg (arg
, bfd_vma
);
136 sprintf_vma (buf
, value
);
137 for (p
= buf
; *p
== '0'; ++p
)
147 fprintf (fp
, "0x%s", p
);
154 const char *name
= va_arg (arg
, const char *);
156 if (name
== (const char *) NULL
|| *name
== 0)
157 fprintf (fp
, _("no symbol"));
158 else if (! demangling
)
159 fprintf (fp
, "%s", name
);
164 demangled
= demangle (name
);
165 fprintf (fp
, "%s", demangled
);
172 /* filename from a bfd */
174 bfd
*abfd
= va_arg (arg
, bfd
*);
175 if (abfd
->my_archive
)
176 fprintf (fp
, "%s(%s)", abfd
->my_archive
->filename
,
179 fprintf (fp
, "%s", abfd
->filename
);
184 /* Error is fatal. */
189 /* Print program name. */
190 fprintf (fp
, "%s", program_name
);
194 /* current bfd error or errno */
195 fprintf (fp
, "%s", bfd_errmsg (bfd_get_error ()));
199 /* filename from a lang_input_statement_type */
201 lang_input_statement_type
*i
;
203 i
= va_arg (arg
, lang_input_statement_type
*);
204 if (bfd_my_archive (i
->the_bfd
) != NULL
)
206 bfd_get_filename (bfd_my_archive (i
->the_bfd
)));
207 fprintf (fp
, "%s", i
->local_sym_name
);
208 if (bfd_my_archive (i
->the_bfd
) == NULL
209 && strcmp (i
->local_sym_name
, i
->filename
) != 0)
210 fprintf (fp
, " (%s)", i
->filename
);
215 /* Print script file and linenumber. */
217 fprintf (fp
, "--defsym %s", lex_string
);
218 else if (ldfile_input_filename
!= NULL
)
219 fprintf (fp
, "%s:%u", ldfile_input_filename
, lineno
);
221 fprintf (fp
, _("built in linker script:%u"), lineno
);
225 /* Print all that's interesting about a relent. */
227 arelent
*relent
= va_arg (arg
, arelent
*);
229 lfinfo (fp
, "%s+0x%v (type %s)",
230 (*(relent
->sym_ptr_ptr
))->name
,
232 relent
->howto
->name
);
239 /* Clever filename:linenumber with function name if possible.
240 The arguments are a BFD, a section, and an offset. */
242 static bfd
*last_bfd
;
243 static char *last_file
= NULL
;
244 static char *last_function
= NULL
;
248 lang_input_statement_type
*entry
;
250 const char *filename
;
251 const char *functionname
;
252 unsigned int linenumber
;
253 bfd_boolean discard_last
;
255 abfd
= va_arg (arg
, bfd
*);
256 section
= va_arg (arg
, asection
*);
257 offset
= va_arg (arg
, bfd_vma
);
259 entry
= (lang_input_statement_type
*) abfd
->usrdata
;
260 if (entry
!= (lang_input_statement_type
*) NULL
261 && entry
->asymbols
!= (asymbol
**) NULL
)
262 asymbols
= entry
->asymbols
;
268 symsize
= bfd_get_symtab_upper_bound (abfd
);
270 einfo (_("%B%F: could not read symbols\n"), abfd
);
271 asymbols
= (asymbol
**) xmalloc (symsize
);
272 symbol_count
= bfd_canonicalize_symtab (abfd
, asymbols
);
273 if (symbol_count
< 0)
274 einfo (_("%B%F: could not read symbols\n"), abfd
);
275 if (entry
!= (lang_input_statement_type
*) NULL
)
277 entry
->asymbols
= asymbols
;
278 entry
->symbol_count
= symbol_count
;
282 lfinfo (fp
, "%B(%s+0x%v)", abfd
, section
->name
, offset
);
285 if (bfd_find_nearest_line (abfd
, section
, asymbols
, offset
,
286 &filename
, &functionname
,
289 bfd_boolean need_colon
= TRUE
;
291 if (functionname
!= NULL
&& fmt
[-1] == 'C')
295 || last_function
== NULL
298 && strcmp (last_file
, filename
) != 0)
299 || strcmp (last_function
, functionname
) != 0)
301 lfinfo (fp
, _(": In function `%T':\n"),
306 if (last_file
!= NULL
)
310 last_file
= xstrdup (filename
);
311 if (last_function
!= NULL
)
312 free (last_function
);
313 last_function
= xstrdup (functionname
);
315 discard_last
= FALSE
;
318 if (filename
!= NULL
)
322 fputs (filename
, fp
);
325 if (functionname
!= NULL
&& fmt
[-1] == 'G')
326 lfinfo (fp
, ":%T", functionname
);
327 else if (filename
!= NULL
&& linenumber
!= 0)
328 fprintf (fp
, ":%u", linenumber
);
331 if (asymbols
!= NULL
&& entry
== NULL
)
337 if (last_file
!= NULL
)
342 if (last_function
!= NULL
)
344 free (last_function
);
345 last_function
= NULL
;
352 /* arbitrary string, like printf */
353 fprintf (fp
, "%s", va_arg (arg
, char *));
357 /* integer, like printf */
358 fprintf (fp
, "%d", va_arg (arg
, int));
362 /* unsigned integer, like printf */
363 fprintf (fp
, "%u", va_arg (arg
, unsigned int));
369 if (config
.fatal_warnings
)
370 config
.make_executable
= FALSE
;
376 /* Wrapper around cplus_demangle. Strips leading underscores and
377 other such chars that would otherwise confuse the demangler. */
386 if (output_bfd
!= NULL
387 && bfd_get_symbol_leading_char (output_bfd
) == name
[0])
390 /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF
391 or the MS PE format. These formats have a number of leading '.'s
392 on at least some symbols, so we remove all dots to avoid
393 confusing the demangler. */
398 res
= cplus_demangle (p
, DMGL_ANSI
| DMGL_PARAMS
);
401 size_t dots
= p
- name
;
403 /* Now put back any stripped dots. */
406 size_t len
= strlen (res
) + 1;
407 char *add_dots
= xmalloc (len
+ dots
);
409 memcpy (add_dots
, name
, dots
);
410 memcpy (add_dots
+ dots
, res
, len
);
416 return xstrdup (name
);
419 /* Format info message and print on stdout. */
421 /* (You would think this should be called just "info", but then you
422 would hosed by LynxOS, which defines that name in its libc.) */
425 info_msg
VPARAMS ((const char *fmt
, ...))
428 VA_FIXEDARG (arg
, const char *, fmt
);
430 vfinfo (stdout
, fmt
, arg
);
434 /* ('e' for error.) Format info message and print on stderr. */
437 einfo
VPARAMS ((const char *fmt
, ...))
440 VA_FIXEDARG (arg
, const char *, fmt
);
442 vfinfo (stderr
, fmt
, arg
);
447 info_assert (file
, line
)
451 einfo (_("%F%P: internal error %s %d\n"), file
, line
);
454 /* ('m' for map) Format info message and print on map. */
457 minfo
VPARAMS ((const char *fmt
, ...))
460 VA_FIXEDARG (arg
, const char *, fmt
);
462 vfinfo (config
.map_file
, fmt
, arg
);
467 lfinfo
VPARAMS ((FILE *file
, const char *fmt
, ...))
470 VA_FIXEDARG (arg
, FILE *, file
);
471 VA_FIXEDARG (arg
, const char *, fmt
);
473 vfinfo (file
, fmt
, arg
);
477 /* Functions to print the link map. */
482 fprintf (config
.map_file
, " ");
488 fprintf (config
.map_file
, "\n");
491 /* A more or less friendly abort message. In ld.h abort is defined to
492 call this function. */
495 ld_abort (file
, line
, fn
)
501 einfo (_("%P: internal error: aborting at %s line %d in %s\n"),
504 einfo (_("%P: internal error: aborting at %s line %d\n"),
506 einfo (_("%P%F: please report this bug\n"));
511 error_handler
VPARAMS ((int id ATTRIBUTE_UNUSED
, const char *fmt
, ...))
514 VA_FIXEDARG (arg
, const char *, fmt
);
516 vfinfo (stderr
, fmt
, arg
);