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, 675 Mass Ave, Cambridge, MA 02139, USA. */
38 static const char *demangle PARAMS ((const char *string,
39 int remove_underscore));
45 %S print script file and linenumber
46 %E current bfd error or errno
47 %I filename from a lang_input_statement_type
48 %B filename from a bfd
50 %X no object output, fail return
52 %v hex bfd_vma, no leading zeros
53 %C clever filename:linenumber with function
54 %D like %C, but no function name
55 %R info about a relent
56 %s arbitrary string, like printf
57 %d integer, like printf
61 demangle (string, remove_underscore)
63 int remove_underscore;
66 if (remove_underscore && output_bfd)
68 if (bfd_get_symbol_leading_char (output_bfd) == string[0])
71 /* Note that there's a memory leak here, we keep buying memory
72 for demangled names, and never free. But if you have so many
73 errors that you run out of VM with the error messages, then
74 there's something up */
75 res = cplus_demangle (string, DMGL_ANSI|DMGL_PARAMS);
76 return res ? res : string;
85 boolean fatal = false;
89 while (*fmt != '%' && *fmt != '\0')
101 fprintf(fp,"%%%c", fmt[-1]);
110 /* no object output, fail return */
111 config.make_executable = false;
117 bfd_vma value = va_arg(arg, bfd_vma);
118 fprintf_vma(fp, value);
123 /* hex bfd_vma, no leading zeros */
127 bfd_vma value = va_arg (arg, bfd_vma);
128 sprintf_vma (p, value);
140 const char *name = va_arg (arg, const char *);
142 if (name != (const char *) NULL)
143 fprintf (fp, "%s", demangle (name, 1));
145 fprintf (fp, "no symbol");
150 /* filename from a bfd */
152 bfd *abfd = va_arg(arg, bfd *);
153 if (abfd->my_archive) {
154 fprintf(fp,"%s(%s)", abfd->my_archive->filename,
158 fprintf(fp,"%s", abfd->filename);
169 /* print program name */
170 fprintf(fp,"%s", program_name);
174 /* current bfd error or errno */
175 fprintf(fp, bfd_errmsg(bfd_get_error ()));
179 /* filename from a lang_input_statement_type */
181 lang_input_statement_type *i =
182 va_arg(arg,lang_input_statement_type *);
184 if (i->the_bfd->my_archive)
185 fprintf(fp, "(%s)", i->the_bfd->my_archive->filename);
186 fprintf(fp,"%s", i->local_sym_name);
191 /* print script file and linenumber */
193 if (ldfile_input_filename) {
194 fprintf(fp,"%s:%u", ldfile_input_filename, lineno );
200 /* Print all that's interesting about a relent */
202 arelent *relent = va_arg(arg, arelent *);
204 finfo (fp, "%s+0x%v (type %s)",
205 (*(relent->sym_ptr_ptr))->name,
207 relent->howto->name);
213 /* Clever filename:linenumber with function name if possible,
214 or section name as a last resort. The arguments are a BFD,
215 a section, and an offset. */
217 static char *last_file = NULL;
218 static char *last_function = NULL;
222 lang_input_statement_type *entry;
224 const char *filename;
225 const char *functionname;
226 unsigned int linenumber;
227 boolean discard_last;
229 abfd = va_arg (arg, bfd *);
230 section = va_arg (arg, asection *);
231 offset = va_arg (arg, bfd_vma);
233 entry = (lang_input_statement_type *) abfd->usrdata;
234 if (entry != (lang_input_statement_type *) NULL
235 && entry->asymbols != (asymbol **) NULL)
236 asymbols = entry->asymbols;
242 symsize = bfd_get_symtab_upper_bound (abfd);
244 einfo ("%B%F: could not read symbols", abfd);
245 asymbols = (asymbol **) xmalloc (symsize);
246 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
247 if (symbol_count < 0)
248 einfo ("%B%F: could not read symbols", abfd);
249 if (entry != (lang_input_statement_type *) NULL)
251 entry->asymbols = asymbols;
252 entry->symbol_count = symbol_count;
257 if (bfd_find_nearest_line (abfd, section, asymbols, offset,
258 &filename, &functionname, &linenumber))
260 if (filename == (char *) NULL)
261 filename = abfd->filename;
263 if (functionname != NULL && fmt[-1] == 'C')
265 if (last_file == NULL
266 || last_function == NULL
267 || strcmp (last_file, filename) != 0
268 || strcmp (last_function, functionname) != 0)
270 fprintf (fp, "%s: In function `%s':\n", filename,
271 demangle (functionname, 1));
272 if (last_file != NULL)
274 last_file = buystring (filename);
275 if (last_function != NULL)
276 free (last_function);
277 last_function = buystring (functionname);
279 discard_last = false;
280 fprintf (fp, "%s:%u", filename, linenumber);
282 else if (linenumber != 0)
283 fprintf (fp, "%s:%u", filename, linenumber);
285 finfo (fp, "%s(%s+0x%v)", filename, section->name, offset);
288 finfo (fp, "%s(%s+0x%v)", abfd->filename, section->name, offset);
292 if (last_file != NULL)
297 if (last_function != NULL)
299 free (last_function);
300 last_function = NULL;
307 /* arbitrary string, like printf */
308 fprintf(fp,"%s", va_arg(arg, char *));
312 /* integer, like printf */
313 fprintf(fp,"%d", va_arg(arg, int));
323 /* Format info message and print on stdout. */
325 /* (You would think this should be called just "info", but then you would
326 hosed by LynxOS, which defines that name in its libc.) */
328 void info_msg(va_alist)
334 fmt = va_arg(arg, char *);
335 vfinfo(stdout, fmt, arg);
339 /* ('e' for error.) Format info message and print on stderr. */
347 fmt = va_arg(arg, char *);
348 vfinfo(stderr, fmt, arg);
353 info_assert(file, line)
357 einfo("%F%P: internal error %s %d\n", file,line);
364 size_t l = strlen(x)+1;
365 char *r = xmalloc(l);
371 /* ('m' for map) Format info message and print on map. */
379 fmt = va_arg(arg, char *);
380 vfinfo(config.map_file, fmt, arg);
393 file = va_arg (arg, FILE *);
394 fmt = va_arg (arg, char *);
395 vfinfo (file, fmt, arg);
401 /*----------------------------------------------------------------------
402 Functions to print the link map
408 fprintf(config.map_file, " ");
413 fprintf(config.map_file, "\n");
416 print_address (value)
419 fprintf_vma(config.map_file, value);