2 Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Written by Steve Chamberlain of Cygnus Support.
5 This file is part of GLD, the Gnu Linker.
7 GLD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GLD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GLD; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "libiberty.h"
26 #ifdef ANSI_PROTOTYPES
45 static void finfo
PARAMS ((FILE *, const char *, ...));
55 %S print script file and linenumber
56 %E current bfd error or errno
57 %I filename from a lang_input_statement_type
58 %B filename from a bfd
60 %X no object output, fail return
62 %v hex bfd_vma, no leading zeros
63 %C clever filename:linenumber with function
64 %D like %C, but no function name
65 %G like %D, but only function name
66 %R info about a relent
67 %s arbitrary string, like printf
68 %d integer, like printf
69 %u integer, like printf
78 if (output_bfd
!= NULL
79 && bfd_get_symbol_leading_char (output_bfd
) == string
[0])
82 /* This is a hack for better error reporting on XCOFF. */
86 res
= cplus_demangle (string
, 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
);
151 const char *name
= va_arg (arg
, const char *);
153 if (name
== (const char *) NULL
)
154 fprintf (fp
, "no symbol");
159 demangled
= demangle (name
);
160 fprintf (fp
, "%s", demangled
);
167 /* filename from a bfd */
169 bfd
*abfd
= va_arg (arg
, bfd
*);
170 if (abfd
->my_archive
)
171 fprintf (fp
, "%s(%s)", abfd
->my_archive
->filename
,
174 fprintf (fp
, "%s", abfd
->filename
);
184 /* print program name */
185 fprintf (fp
, "%s", program_name
);
189 /* current bfd error or errno */
190 fprintf (fp
, bfd_errmsg (bfd_get_error ()));
194 /* filename from a lang_input_statement_type */
196 lang_input_statement_type
*i
;
198 i
= va_arg (arg
, lang_input_statement_type
*);
199 if (bfd_my_archive (i
->the_bfd
) != NULL
)
201 bfd_get_filename (bfd_my_archive (i
->the_bfd
)));
202 fprintf (fp
, "%s", i
->local_sym_name
);
203 if (bfd_my_archive (i
->the_bfd
) == NULL
204 && strcmp (i
->local_sym_name
, i
->filename
) != 0)
205 fprintf (fp
, " (%s)", i
->filename
);
210 /* print script file and linenumber */
212 fprintf (fp
, "--defsym %s", lex_string
);
213 else if (ldfile_input_filename
!= NULL
)
214 fprintf (fp
, "%s:%u", ldfile_input_filename
, lineno
);
216 fprintf (fp
, "built in linker script:%u", lineno
);
220 /* Print all that's interesting about a relent */
222 arelent
*relent
= va_arg (arg
, arelent
*);
224 finfo (fp
, "%s+0x%v (type %s)",
225 (*(relent
->sym_ptr_ptr
))->name
,
227 relent
->howto
->name
);
234 /* Clever filename:linenumber with function name if possible,
235 or section name as a last resort. The arguments are a BFD,
236 a section, and an offset. */
238 static bfd
*last_bfd
;
239 static char *last_file
= NULL
;
240 static char *last_function
= NULL
;
244 lang_input_statement_type
*entry
;
246 const char *filename
;
247 const char *functionname
;
248 unsigned int linenumber
;
249 boolean discard_last
;
251 abfd
= va_arg (arg
, bfd
*);
252 section
= va_arg (arg
, asection
*);
253 offset
= va_arg (arg
, bfd_vma
);
255 entry
= (lang_input_statement_type
*) abfd
->usrdata
;
256 if (entry
!= (lang_input_statement_type
*) NULL
257 && entry
->asymbols
!= (asymbol
**) NULL
)
258 asymbols
= entry
->asymbols
;
264 symsize
= bfd_get_symtab_upper_bound (abfd
);
266 einfo ("%B%F: could not read symbols\n", abfd
);
267 asymbols
= (asymbol
**) xmalloc (symsize
);
268 symbol_count
= bfd_canonicalize_symtab (abfd
, asymbols
);
269 if (symbol_count
< 0)
270 einfo ("%B%F: could not read symbols\n", abfd
);
271 if (entry
!= (lang_input_statement_type
*) NULL
)
273 entry
->asymbols
= asymbols
;
274 entry
->symbol_count
= symbol_count
;
279 if (bfd_find_nearest_line (abfd
, section
, asymbols
, offset
,
280 &filename
, &functionname
,
283 if (functionname
!= NULL
&& fmt
[-1] == 'G')
285 finfo (fp
, "%B:", abfd
);
287 && strcmp (filename
, bfd_get_filename (abfd
)) != 0)
288 fprintf (fp
, "%s:", filename
);
289 finfo (fp
, "%T", functionname
);
291 else if (functionname
!= NULL
&& fmt
[-1] == 'C')
293 if (filename
== (char *) NULL
)
294 filename
= abfd
->filename
;
298 || last_function
== NULL
300 || strcmp (last_file
, filename
) != 0
301 || strcmp (last_function
, functionname
) != 0)
303 /* We use abfd->filename in this initial line,
304 in case filename is a .h file or something
305 similarly unhelpful. */
306 finfo (fp
, "%B: In function `%T':\n",
310 if (last_file
!= NULL
)
312 last_file
= buystring (filename
);
313 if (last_function
!= NULL
)
314 free (last_function
);
315 last_function
= buystring (functionname
);
317 discard_last
= false;
319 fprintf (fp
, "%s:%u", filename
, linenumber
);
321 finfo (fp
, "%s(%s+0x%v)", filename
, section
->name
,
324 else if (filename
== NULL
325 || strcmp (filename
, abfd
->filename
) == 0)
327 finfo (fp
, "%B(%s+0x%v)", abfd
, section
->name
, offset
);
329 finfo (fp
, ":%u", linenumber
);
331 else if (linenumber
!= 0)
332 finfo (fp
, "%B:%s:%u", abfd
, filename
, linenumber
);
334 finfo (fp
, "%B(%s+0x%v):%s", abfd
, section
->name
, offset
,
338 finfo (fp
, "%B(%s+0x%v)", abfd
, section
->name
, offset
);
343 if (last_file
!= NULL
)
348 if (last_function
!= NULL
)
350 free (last_function
);
351 last_function
= NULL
;
358 /* arbitrary string, like printf */
359 fprintf (fp
, "%s", va_arg (arg
, char *));
363 /* integer, like printf */
364 fprintf (fp
, "%d", va_arg (arg
, int));
368 /* unsigned integer, like printf */
369 fprintf (fp
, "%u", va_arg (arg
, unsigned int));
379 /* Format info message and print on stdout. */
381 /* (You would think this should be called just "info", but then you
382 would hosed by LynxOS, which defines that name in its libc.) */
386 info_msg (const char *fmt
, ...)
398 fmt
= va_arg (arg
, const char *);
403 vfinfo (stdout
, fmt
, arg
);
407 /* ('e' for error.) Format info message and print on stderr. */
411 einfo (const char *fmt
, ...)
423 fmt
= va_arg (arg
, const char *);
428 vfinfo (stderr
, fmt
, arg
);
433 info_assert (file
, line
)
437 einfo ("%F%P: internal error %s %d\n", file
, line
);
444 size_t l
= strlen(x
)+1;
445 char *r
= xmalloc(l
);
450 /* ('m' for map) Format info message and print on map. */
454 minfo (const char *fmt
, ...)
465 fmt
= va_arg (arg
, const char *);
470 vfinfo (config
.map_file
, fmt
, arg
);
476 finfo (FILE *file
, const char *fmt
, ...)
489 file
= va_arg (arg
, FILE *);
490 fmt
= va_arg (arg
, const char *);
495 vfinfo (file
, fmt
, arg
);
499 /* Functions to print the link map. */
504 fprintf (config
.map_file
, " ");
510 fprintf (config
.map_file
, "\n");
514 print_address (value
)
517 fprintf_vma (config
.map_file
, value
);