2 Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
4 Written by Steve Chamberlain of Cygnus Support.
6 This file is part of GLD, the Gnu Linker.
8 GLD is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GLD is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GLD; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "libiberty.h"
28 #ifdef ANSI_PROTOTYPES
45 static void vfinfo
PARAMS ((FILE *, const char *, va_list));
51 %S print script file and linenumber
52 %E current bfd error or errno
53 %I filename from a lang_input_statement_type
54 %B filename from a bfd
56 %X no object output, fail return
58 %v hex bfd_vma, no leading zeros
59 %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
60 %C clever filename:linenumber with function
61 %D like %C, but no function name
62 %G like %D, but only function name
63 %R info about a relent
64 %s arbitrary string, like printf
65 %d integer, like printf
66 %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, or the MS PE */
80 /* format. Xcoff has a single '.', while the NT PE for PPC has '..'. */
81 /* So we remove all of them. */
82 while(string
[0] == '.')
85 res
= cplus_demangle (string
, DMGL_ANSI
| DMGL_PARAMS
);
86 return res
? res
: xstrdup (string
);
95 boolean fatal
= false;
99 while (*fmt
!= '%' && *fmt
!= '\0')
111 fprintf (fp
,"%%%c", fmt
[-1]);
120 /* no object output, fail return */
121 config
.make_executable
= false;
127 bfd_vma value
= va_arg (arg
, bfd_vma
);
128 fprintf_vma (fp
, value
);
133 /* hex bfd_vma, no leading zeros */
137 bfd_vma value
= va_arg (arg
, bfd_vma
);
138 sprintf_vma (p
, value
);
148 /* hex bfd_vma with 0x with no leading zeroes taking up
156 value
= va_arg (arg
, bfd_vma
);
157 sprintf_vma (buf
, value
);
158 for (p
= buf
; *p
== '0'; ++p
)
168 fprintf (fp
, "0x%s", p
);
175 const char *name
= va_arg (arg
, const char *);
177 if (name
== (const char *) NULL
|| *name
== 0)
178 fprintf (fp
, _("no symbol"));
179 else if (! demangling
)
180 fprintf (fp
, "%s", name
);
185 demangled
= demangle (name
);
186 fprintf (fp
, "%s", demangled
);
193 /* filename from a bfd */
195 bfd
*abfd
= va_arg (arg
, bfd
*);
196 if (abfd
->my_archive
)
197 fprintf (fp
, "%s(%s)", abfd
->my_archive
->filename
,
200 fprintf (fp
, "%s", abfd
->filename
);
210 /* print program name */
211 fprintf (fp
, "%s", program_name
);
215 /* current bfd error or errno */
216 fprintf (fp
, "%s", bfd_errmsg (bfd_get_error ()));
220 /* filename from a lang_input_statement_type */
222 lang_input_statement_type
*i
;
224 i
= va_arg (arg
, lang_input_statement_type
*);
225 if (bfd_my_archive (i
->the_bfd
) != NULL
)
227 bfd_get_filename (bfd_my_archive (i
->the_bfd
)));
228 fprintf (fp
, "%s", i
->local_sym_name
);
229 if (bfd_my_archive (i
->the_bfd
) == NULL
230 && strcmp (i
->local_sym_name
, i
->filename
) != 0)
231 fprintf (fp
, " (%s)", i
->filename
);
236 /* print script file and linenumber */
238 fprintf (fp
, "--defsym %s", lex_string
);
239 else if (ldfile_input_filename
!= NULL
)
240 fprintf (fp
, "%s:%u", ldfile_input_filename
, lineno
);
242 fprintf (fp
, _("built in linker script:%u"), lineno
);
246 /* Print all that's interesting about a relent */
248 arelent
*relent
= va_arg (arg
, arelent
*);
250 lfinfo (fp
, "%s+0x%v (type %s)",
251 (*(relent
->sym_ptr_ptr
))->name
,
253 relent
->howto
->name
);
260 /* Clever filename:linenumber with function name if possible,
261 or section name as a last resort. The arguments are a BFD,
262 a section, and an offset. */
264 static bfd
*last_bfd
;
265 static char *last_file
= NULL
;
266 static char *last_function
= NULL
;
270 lang_input_statement_type
*entry
;
272 const char *filename
;
273 const char *functionname
;
274 unsigned int linenumber
;
275 boolean discard_last
;
277 abfd
= va_arg (arg
, bfd
*);
278 section
= va_arg (arg
, asection
*);
279 offset
= va_arg (arg
, bfd_vma
);
281 entry
= (lang_input_statement_type
*) abfd
->usrdata
;
282 if (entry
!= (lang_input_statement_type
*) NULL
283 && entry
->asymbols
!= (asymbol
**) NULL
)
284 asymbols
= entry
->asymbols
;
290 symsize
= bfd_get_symtab_upper_bound (abfd
);
292 einfo (_("%B%F: could not read symbols\n"), abfd
);
293 asymbols
= (asymbol
**) xmalloc (symsize
);
294 symbol_count
= bfd_canonicalize_symtab (abfd
, asymbols
);
295 if (symbol_count
< 0)
296 einfo (_("%B%F: could not read symbols\n"), abfd
);
297 if (entry
!= (lang_input_statement_type
*) NULL
)
299 entry
->asymbols
= asymbols
;
300 entry
->symbol_count
= symbol_count
;
305 if (bfd_find_nearest_line (abfd
, section
, asymbols
, offset
,
306 &filename
, &functionname
,
309 if (functionname
!= NULL
&& fmt
[-1] == 'G')
311 lfinfo (fp
, "%B:", abfd
);
313 && strcmp (filename
, bfd_get_filename (abfd
)) != 0)
314 fprintf (fp
, "%s:", filename
);
315 lfinfo (fp
, "%T", functionname
);
317 else if (functionname
!= NULL
&& fmt
[-1] == 'C')
319 if (filename
== (char *) NULL
)
320 filename
= abfd
->filename
;
324 || last_function
== NULL
326 || strcmp (last_file
, filename
) != 0
327 || strcmp (last_function
, functionname
) != 0)
329 /* We use abfd->filename in this initial line,
330 in case filename is a .h file or something
331 similarly unhelpful. */
332 lfinfo (fp
, _("%B: In function `%T':\n"),
336 if (last_file
!= NULL
)
338 last_file
= buystring (filename
);
339 if (last_function
!= NULL
)
340 free (last_function
);
341 last_function
= buystring (functionname
);
343 discard_last
= false;
345 fprintf (fp
, "%s:%u", filename
, linenumber
);
347 lfinfo (fp
, "%s(%s+0x%v)", filename
, section
->name
,
350 else if (filename
== NULL
351 || strcmp (filename
, abfd
->filename
) == 0)
353 lfinfo (fp
, "%B(%s+0x%v)", abfd
, section
->name
,
356 lfinfo (fp
, ":%u", linenumber
);
358 else if (linenumber
!= 0)
359 lfinfo (fp
, "%B:%s:%u", abfd
, filename
, linenumber
);
361 lfinfo (fp
, "%B(%s+0x%v):%s", abfd
, section
->name
,
365 lfinfo (fp
, "%B(%s+0x%v)", abfd
, section
->name
, offset
);
370 if (last_file
!= NULL
)
375 if (last_function
!= NULL
)
377 free (last_function
);
378 last_function
= NULL
;
385 /* arbitrary string, like printf */
386 fprintf (fp
, "%s", va_arg (arg
, char *));
390 /* integer, like printf */
391 fprintf (fp
, "%d", va_arg (arg
, int));
395 /* unsigned integer, like printf */
396 fprintf (fp
, "%u", va_arg (arg
, unsigned int));
406 /* Format info message and print on stdout. */
408 /* (You would think this should be called just "info", but then you
409 would hosed by LynxOS, which defines that name in its libc.) */
413 info_msg (const char *fmt
, ...)
425 fmt
= va_arg (arg
, const char *);
430 vfinfo (stdout
, fmt
, arg
);
434 /* ('e' for error.) Format info message and print on stderr. */
438 einfo (const char *fmt
, ...)
450 fmt
= va_arg (arg
, const char *);
455 vfinfo (stderr
, fmt
, arg
);
460 info_assert (file
, line
)
464 einfo (_("%F%P: internal error %s %d\n"), file
, line
);
471 size_t l
= strlen(x
)+1;
472 char *r
= xmalloc(l
);
477 /* ('m' for map) Format info message and print on map. */
481 minfo (const char *fmt
, ...)
492 fmt
= va_arg (arg
, const char *);
497 vfinfo (config
.map_file
, fmt
, arg
);
503 lfinfo (FILE *file
, const char *fmt
, ...)
516 file
= va_arg (arg
, FILE *);
517 fmt
= va_arg (arg
, const char *);
522 vfinfo (file
, fmt
, arg
);
526 /* Functions to print the link map. */
531 fprintf (config
.map_file
, " ");
537 fprintf (config
.map_file
, "\n");
540 /* A more or less friendly abort message. In ld.h abort is defined to
541 call this function. */
544 ld_abort (file
, line
, fn
)
550 einfo (_("%P: internal error: aborting at %s line %d in %s\n"),
553 einfo (_("%P: internal error: aborting at %s line %d\n"),
555 einfo (_("%P%F: please report this bug\n"));