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. */
25 /* this collection of routines wants to use the Unix style varargs
26 use special abbreviated portion of varargs.h */
28 /* Since macro __STDC__ is defined, the compiler will raise and error if
29 VARARGS.H from mstools\h is included. Since we only need a portion of
30 this header file, it has been incorporated into local header file
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;
78 if (remove_underscore && output_bfd)
80 if (bfd_get_symbol_leading_char (output_bfd) == string[0])
83 /* Note that there's a memory leak here, we keep buying memory
84 for demangled names, and never free. But if you have so many
85 errors that you run out of VM with the error messages, then
86 there's something up */
87 res = cplus_demangle (string, DMGL_ANSI|DMGL_PARAMS);
88 return res ? res : string;
97 boolean fatal = false;
101 while (*fmt != '%' && *fmt != '\0')
113 fprintf(fp,"%%%c", fmt[-1]);
122 /* no object output, fail return */
123 config.make_executable = false;
129 bfd_vma value = va_arg(arg, bfd_vma);
130 fprintf_vma(fp, value);
135 /* hex bfd_vma, no leading zeros */
139 bfd_vma value = va_arg (arg, bfd_vma);
140 sprintf_vma (p, value);
152 const char *name = va_arg (arg, const char *);
154 if (name != (const char *) NULL)
155 fprintf (fp, "%s", demangle (name, 1));
157 fprintf (fp, "no symbol");
162 /* filename from a bfd */
164 bfd *abfd = va_arg(arg, bfd *);
165 if (abfd->my_archive) {
166 fprintf(fp,"%s(%s)", abfd->my_archive->filename,
170 fprintf(fp,"%s", abfd->filename);
181 /* print program name */
182 fprintf(fp,"%s", program_name);
186 /* current bfd error or errno */
187 fprintf(fp, bfd_errmsg(bfd_get_error ()));
191 /* filename from a lang_input_statement_type */
193 lang_input_statement_type *i =
194 va_arg(arg,lang_input_statement_type *);
196 if (i->the_bfd->my_archive)
197 fprintf(fp, "(%s)", i->the_bfd->my_archive->filename);
198 fprintf(fp,"%s", i->local_sym_name);
203 /* print script file and linenumber */
205 fprintf (fp, "--defsym %s", lex_string);
206 else if (ldfile_input_filename != NULL)
207 fprintf (fp, "%s:%u", ldfile_input_filename, lineno);
209 fprintf (fp, "built in linker script:%u", lineno);
213 /* Print all that's interesting about a relent */
215 arelent *relent = va_arg(arg, arelent *);
217 finfo (fp, "%s+0x%v (type %s)",
218 (*(relent->sym_ptr_ptr))->name,
220 relent->howto->name);
226 /* Clever filename:linenumber with function name if possible,
227 or section name as a last resort. The arguments are a BFD,
228 a section, and an offset. */
230 static bfd *last_bfd;
231 static char *last_file = NULL;
232 static char *last_function = NULL;
236 lang_input_statement_type *entry;
238 const char *filename;
239 const char *functionname;
240 unsigned int linenumber;
241 boolean discard_last;
243 abfd = va_arg (arg, bfd *);
244 section = va_arg (arg, asection *);
245 offset = va_arg (arg, bfd_vma);
247 entry = (lang_input_statement_type *) abfd->usrdata;
248 if (entry != (lang_input_statement_type *) NULL
249 && entry->asymbols != (asymbol **) NULL)
250 asymbols = entry->asymbols;
256 symsize = bfd_get_symtab_upper_bound (abfd);
258 einfo ("%B%F: could not read symbols\n", abfd);
259 asymbols = (asymbol **) xmalloc (symsize);
260 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
261 if (symbol_count < 0)
262 einfo ("%B%F: could not read symbols\n", abfd);
263 if (entry != (lang_input_statement_type *) NULL)
265 entry->asymbols = asymbols;
266 entry->symbol_count = symbol_count;
271 if (bfd_find_nearest_line (abfd, section, asymbols, offset,
272 &filename, &functionname, &linenumber))
274 if (functionname != NULL && fmt[-1] == 'C')
276 if (filename == (char *) NULL)
277 filename = abfd->filename;
281 || last_function == NULL
283 || strcmp (last_file, filename) != 0
284 || strcmp (last_function, functionname) != 0)
286 /* We use abfd->filename in this initial line,
287 in case filename is a .h file or something
288 similarly unhelpful. */
289 finfo (fp, "%B: In function `%s':\n",
290 abfd, demangle (functionname, 1));
293 if (last_file != NULL)
295 last_file = buystring (filename);
296 if (last_function != NULL)
297 free (last_function);
298 last_function = buystring (functionname);
300 discard_last = false;
302 fprintf (fp, "%s:%u", filename, linenumber);
304 finfo (fp, "%s(%s+0x%v)", filename, section->name, offset);
306 else if (filename == NULL
307 || strcmp (filename, abfd->filename) == 0)
309 finfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
311 finfo (fp, "%u", linenumber);
313 else if (linenumber != 0)
314 finfo (fp, "%B:%s:%u", abfd, filename, linenumber);
316 finfo (fp, "%B(%s+0x%v):%s", abfd, section->name, offset,
320 finfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
325 if (last_file != NULL)
330 if (last_function != NULL)
332 free (last_function);
333 last_function = NULL;
340 /* arbitrary string, like printf */
341 fprintf(fp,"%s", va_arg(arg, char *));
345 /* integer, like printf */
346 fprintf(fp,"%d", va_arg(arg, int));
350 /* unsigned integer, like printf */
351 fprintf(fp,"%u", va_arg(arg, unsigned int));
361 /* Format info message and print on stdout. */
363 /* (You would think this should be called just "info", but then you would
364 hosed by LynxOS, which defines that name in its libc.) */
366 void info_msg(va_alist)
372 fmt = va_arg(arg, char *);
373 vfinfo(stdout, fmt, arg);
377 /* ('e' for error.) Format info message and print on stderr. */
385 fmt = va_arg(arg, char *);
386 vfinfo(stderr, fmt, arg);
391 info_assert(file, line)
395 einfo("%F%P: internal error %s %d\n", file,line);
402 size_t l = strlen(x)+1;
403 char *r = xmalloc(l);
409 /* ('m' for map) Format info message and print on map. */
417 fmt = va_arg(arg, char *);
418 vfinfo(config.map_file, fmt, arg);
431 file = va_arg (arg, FILE *);
432 fmt = va_arg (arg, char *);
433 vfinfo (file, fmt, arg);
439 /*----------------------------------------------------------------------
440 Functions to print the link map
446 fprintf(config.map_file, " ");
451 fprintf(config.map_file, "\n");
454 print_address (value)
457 fprintf_vma(config.map_file, value);