2 Copyright (C) 1991, 92, 93, 94 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
20 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #ifdef ANSI_PROTOTYPES
45 static void finfo PARAMS ((FILE *, const char *, ...));
50 static const char *demangle PARAMS ((const char *string,
51 int remove_underscore));
57 %S print script file and linenumber
58 %E current bfd error or errno
59 %I filename from a lang_input_statement_type
60 %B filename from a bfd
62 %X no object output, fail return
64 %v hex bfd_vma, no leading zeros
65 %C clever filename:linenumber with function
66 %D like %C, but no function name
67 %R info about a relent
68 %s arbitrary string, like printf
69 %d integer, like printf
70 %u integer, like printf
74 demangle (string, remove_underscore)
76 int remove_underscore;
82 && bfd_get_symbol_leading_char (output_bfd) == string[0])
85 /* This is a hack for better error reporting on XCOFF. */
86 if (remove_underscore && string[0] == '.')
89 /* Note that there's a memory leak here, we keep buying memory for
90 demangled names, and never free. But if you have so many errors
91 that you run out of VM with the error messages, then there's
93 res = cplus_demangle (string, DMGL_ANSI | DMGL_PARAMS);
94 return res ? res : string;
103 boolean fatal = false;
107 while (*fmt != '%' && *fmt != '\0')
119 fprintf(fp,"%%%c", fmt[-1]);
128 /* no object output, fail return */
129 config.make_executable = false;
135 bfd_vma value = va_arg(arg, bfd_vma);
136 fprintf_vma(fp, value);
141 /* hex bfd_vma, no leading zeros */
145 bfd_vma value = va_arg (arg, bfd_vma);
146 sprintf_vma (p, value);
158 const char *name = va_arg (arg, const char *);
160 if (name != (const char *) NULL)
161 fprintf (fp, "%s", demangle (name, 1));
163 fprintf (fp, "no symbol");
168 /* filename from a bfd */
170 bfd *abfd = va_arg(arg, bfd *);
171 if (abfd->my_archive) {
172 fprintf(fp,"%s(%s)", abfd->my_archive->filename,
176 fprintf(fp,"%s", abfd->filename);
187 /* print program name */
188 fprintf(fp,"%s", program_name);
192 /* current bfd error or errno */
193 fprintf(fp, bfd_errmsg(bfd_get_error ()));
197 /* filename from a lang_input_statement_type */
199 lang_input_statement_type *i =
200 va_arg(arg,lang_input_statement_type *);
202 if (i->the_bfd->my_archive)
203 fprintf(fp, "(%s)", i->the_bfd->my_archive->filename);
204 fprintf(fp,"%s", i->local_sym_name);
209 /* print script file and linenumber */
211 fprintf (fp, "--defsym %s", lex_string);
212 else if (ldfile_input_filename != NULL)
213 fprintf (fp, "%s:%u", ldfile_input_filename, lineno);
215 fprintf (fp, "built in linker script:%u", lineno);
219 /* Print all that's interesting about a relent */
221 arelent *relent = va_arg(arg, arelent *);
223 finfo (fp, "%s+0x%v (type %s)",
224 (*(relent->sym_ptr_ptr))->name,
226 relent->howto->name);
232 /* Clever filename:linenumber with function name if possible,
233 or section name as a last resort. The arguments are a BFD,
234 a section, and an offset. */
236 static bfd *last_bfd;
237 static char *last_file = NULL;
238 static char *last_function = NULL;
242 lang_input_statement_type *entry;
244 const char *filename;
245 const char *functionname;
246 unsigned int linenumber;
247 boolean discard_last;
249 abfd = va_arg (arg, bfd *);
250 section = va_arg (arg, asection *);
251 offset = va_arg (arg, bfd_vma);
253 entry = (lang_input_statement_type *) abfd->usrdata;
254 if (entry != (lang_input_statement_type *) NULL
255 && entry->asymbols != (asymbol **) NULL)
256 asymbols = entry->asymbols;
262 symsize = bfd_get_symtab_upper_bound (abfd);
264 einfo ("%B%F: could not read symbols\n", abfd);
265 asymbols = (asymbol **) xmalloc (symsize);
266 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
267 if (symbol_count < 0)
268 einfo ("%B%F: could not read symbols\n", abfd);
269 if (entry != (lang_input_statement_type *) NULL)
271 entry->asymbols = asymbols;
272 entry->symbol_count = symbol_count;
277 if (bfd_find_nearest_line (abfd, section, asymbols, offset,
278 &filename, &functionname, &linenumber))
280 if (functionname != NULL && fmt[-1] == 'C')
282 if (filename == (char *) NULL)
283 filename = abfd->filename;
287 || last_function == NULL
289 || strcmp (last_file, filename) != 0
290 || strcmp (last_function, functionname) != 0)
292 /* We use abfd->filename in this initial line,
293 in case filename is a .h file or something
294 similarly unhelpful. */
295 finfo (fp, "%B: In function `%s':\n",
296 abfd, demangle (functionname, 1));
299 if (last_file != NULL)
301 last_file = buystring (filename);
302 if (last_function != NULL)
303 free (last_function);
304 last_function = buystring (functionname);
306 discard_last = false;
308 fprintf (fp, "%s:%u", filename, linenumber);
310 finfo (fp, "%s(%s+0x%v)", filename, section->name, offset);
312 else if (filename == NULL
313 || strcmp (filename, abfd->filename) == 0)
315 finfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
317 finfo (fp, "%u", linenumber);
319 else if (linenumber != 0)
320 finfo (fp, "%B:%s:%u", abfd, filename, linenumber);
322 finfo (fp, "%B(%s+0x%v):%s", abfd, section->name, offset,
326 finfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
331 if (last_file != NULL)
336 if (last_function != NULL)
338 free (last_function);
339 last_function = NULL;
346 /* arbitrary string, like printf */
347 fprintf(fp,"%s", va_arg(arg, char *));
351 /* integer, like printf */
352 fprintf(fp,"%d", va_arg(arg, int));
356 /* unsigned integer, like printf */
357 fprintf(fp,"%u", va_arg(arg, unsigned int));
367 /* Format info message and print on stdout. */
369 /* (You would think this should be called just "info", but then you
370 would hosed by LynxOS, which defines that name in its libc.) */
374 info_msg (const char *fmt, ...)
386 fmt = va_arg (arg, const char *);
391 vfinfo (stdout, fmt, arg);
395 /* ('e' for error.) Format info message and print on stderr. */
399 einfo (const char *fmt, ...)
411 fmt = va_arg (arg, const char *);
416 vfinfo (stderr, fmt, arg);
421 info_assert (file, line)
425 einfo ("%F%P: internal error %s %d\n", file, line);
432 size_t l = strlen(x)+1;
433 char *r = xmalloc(l);
438 /* ('m' for map) Format info message and print on map. */
442 minfo (const char *fmt, ...)
453 fmt = va_arg (arg, const char *);
458 vfinfo (config.map_file, fmt, arg);
464 finfo (FILE *file, const char *fmt, ...)
477 file = va_arg (arg, FILE *);
478 fmt = va_arg (arg, const char *);
483 vfinfo (file, fmt, arg);
487 /* Functions to print the link map. */
492 fprintf (config.map_file, " ");
498 fprintf (config.map_file, "\n");
502 print_address (value)
505 fprintf_vma (config.map_file, value);