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. */
25 #ifdef ANSI_PROTOTYPES
44 static void finfo PARAMS ((FILE *, const char *, ...));
49 static const char *demangle PARAMS ((const char *string,
50 int remove_underscore));
56 %S print script file and linenumber
57 %E current bfd error or errno
58 %I filename from a lang_input_statement_type
59 %B filename from a bfd
61 %X no object output, fail return
63 %v hex bfd_vma, no leading zeros
64 %C clever filename:linenumber with function
65 %D like %C, but no function name
66 %R info about a relent
67 %s arbitrary string, like printf
68 %d integer, like printf
69 %u integer, like printf
73 demangle (string, remove_underscore)
75 int remove_underscore;
81 && bfd_get_symbol_leading_char (output_bfd) == string[0])
84 /* This is a hack for better error reporting on XCOFF. */
85 if (remove_underscore && string[0] == '.')
88 /* Note that there's a memory leak here, we keep buying memory for
89 demangled names, and never free. But if you have so many errors
90 that you run out of VM with the error messages, then there's
92 res = cplus_demangle (string, DMGL_ANSI | DMGL_PARAMS);
93 return res ? res : string;
102 boolean fatal = false;
106 while (*fmt != '%' && *fmt != '\0')
118 fprintf (fp,"%%%c", fmt[-1]);
127 /* no object output, fail return */
128 config.make_executable = false;
134 bfd_vma value = va_arg (arg, bfd_vma);
135 fprintf_vma (fp, value);
140 /* hex bfd_vma, no leading zeros */
144 bfd_vma value = va_arg (arg, bfd_vma);
145 sprintf_vma (p, value);
157 const char *name = va_arg (arg, const char *);
159 if (name != (const char *) NULL)
160 fprintf (fp, "%s", demangle (name, 1));
162 fprintf (fp, "no symbol");
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);
233 /* Clever filename:linenumber with function name if possible,
234 or section name as a last resort. The arguments are a BFD,
235 a section, and an offset. */
237 static bfd *last_bfd;
238 static char *last_file = NULL;
239 static char *last_function = NULL;
243 lang_input_statement_type *entry;
245 const char *filename;
246 const char *functionname;
247 unsigned int linenumber;
248 boolean discard_last;
250 abfd = va_arg (arg, bfd *);
251 section = va_arg (arg, asection *);
252 offset = va_arg (arg, bfd_vma);
254 entry = (lang_input_statement_type *) abfd->usrdata;
255 if (entry != (lang_input_statement_type *) NULL
256 && entry->asymbols != (asymbol **) NULL)
257 asymbols = entry->asymbols;
263 symsize = bfd_get_symtab_upper_bound (abfd);
265 einfo ("%B%F: could not read symbols\n", abfd);
266 asymbols = (asymbol **) xmalloc (symsize);
267 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
268 if (symbol_count < 0)
269 einfo ("%B%F: could not read symbols\n", abfd);
270 if (entry != (lang_input_statement_type *) NULL)
272 entry->asymbols = asymbols;
273 entry->symbol_count = symbol_count;
278 if (bfd_find_nearest_line (abfd, section, asymbols, offset,
279 &filename, &functionname,
282 if (functionname != NULL && fmt[-1] == 'C')
284 if (filename == (char *) NULL)
285 filename = abfd->filename;
289 || last_function == NULL
291 || strcmp (last_file, filename) != 0
292 || strcmp (last_function, functionname) != 0)
294 /* We use abfd->filename in this initial line,
295 in case filename is a .h file or something
296 similarly unhelpful. */
297 finfo (fp, "%B: In function `%s':\n",
298 abfd, demangle (functionname, 1));
301 if (last_file != NULL)
303 last_file = buystring (filename);
304 if (last_function != NULL)
305 free (last_function);
306 last_function = buystring (functionname);
308 discard_last = false;
310 fprintf (fp, "%s:%u", filename, linenumber);
312 finfo (fp, "%s(%s+0x%v)", filename, section->name,
315 else if (filename == NULL
316 || strcmp (filename, abfd->filename) == 0)
318 finfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
320 finfo (fp, "%u", linenumber);
322 else if (linenumber != 0)
323 finfo (fp, "%B:%s:%u", abfd, filename, linenumber);
325 finfo (fp, "%B(%s+0x%v):%s", abfd, section->name, offset,
329 finfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
334 if (last_file != NULL)
339 if (last_function != NULL)
341 free (last_function);
342 last_function = NULL;
349 /* arbitrary string, like printf */
350 fprintf (fp, "%s", va_arg (arg, char *));
354 /* integer, like printf */
355 fprintf (fp, "%d", va_arg (arg, int));
359 /* unsigned integer, like printf */
360 fprintf (fp,"%u", va_arg (arg, unsigned int));
370 /* Format info message and print on stdout. */
372 /* (You would think this should be called just "info", but then you
373 would hosed by LynxOS, which defines that name in its libc.) */
377 info_msg (const char *fmt, ...)
389 fmt = va_arg (arg, const char *);
394 vfinfo (stdout, fmt, arg);
398 /* ('e' for error.) Format info message and print on stderr. */
402 einfo (const char *fmt, ...)
414 fmt = va_arg (arg, const char *);
419 vfinfo (stderr, fmt, arg);
424 info_assert (file, line)
428 einfo ("%F%P: internal error %s %d\n", file, line);
435 size_t l = strlen(x)+1;
436 char *r = xmalloc(l);
441 /* ('m' for map) Format info message and print on map. */
445 minfo (const char *fmt, ...)
456 fmt = va_arg (arg, const char *);
461 vfinfo (config.map_file, fmt, arg);
467 finfo (FILE *file, const char *fmt, ...)
480 file = va_arg (arg, FILE *);
481 fmt = va_arg (arg, const char *);
486 vfinfo (file, fmt, arg);
490 /* Functions to print the link map. */
495 fprintf (config.map_file, " ");
501 fprintf (config.map_file, "\n");
505 print_address (value)
508 fprintf_vma (config.map_file, value);