2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 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 the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "libiberty.h"
28 #ifdef ANSI_PROTOTYPES
43 static void vfinfo PARAMS ((FILE *, const char *, va_list));
49 %S print script file and linenumber
50 %E current bfd error or errno
51 %I filename from a lang_input_statement_type
52 %B filename from a bfd
54 %X no object output, fail return
56 %v hex bfd_vma, no leading zeros
57 %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
58 %C clever filename:linenumber with function
59 %D like %C, but no function name
60 %G like %D, but only function name
61 %R info about a relent
62 %s arbitrary string, like printf
63 %d integer, like printf
64 %u integer, like printf
73 if (output_bfd != NULL
74 && bfd_get_symbol_leading_char (output_bfd) == string[0])
77 /* This is a hack for better error reporting on XCOFF, or the MS PE
78 format. Xcoff has a single '.', while the NT PE for PPC has
79 '..'. So we remove all of them. */
80 while (string[0] == '.')
83 res = cplus_demangle (string, DMGL_ANSI | DMGL_PARAMS);
84 return res ? res : xstrdup (string);
93 boolean fatal = false;
97 while (*fmt != '%' && *fmt != '\0')
109 fprintf (fp, "%%%c", fmt[-1]);
118 /* no object output, fail return */
119 config.make_executable = false;
125 bfd_vma value = va_arg (arg, bfd_vma);
126 fprintf_vma (fp, value);
131 /* hex bfd_vma, no leading zeros */
135 bfd_vma value = va_arg (arg, bfd_vma);
136 sprintf_vma (p, value);
146 /* hex bfd_vma with 0x with no leading zeroes taking up
154 value = va_arg (arg, bfd_vma);
155 sprintf_vma (buf, value);
156 for (p = buf; *p == '0'; ++p)
166 fprintf (fp, "0x%s", p);
173 const char *name = va_arg (arg, const char *);
175 if (name == (const char *) NULL || *name == 0)
176 fprintf (fp, _("no symbol"));
177 else if (! demangling)
178 fprintf (fp, "%s", name);
183 demangled = demangle (name);
184 fprintf (fp, "%s", demangled);
191 /* filename from a bfd */
193 bfd *abfd = va_arg (arg, bfd *);
194 if (abfd->my_archive)
195 fprintf (fp, "%s(%s)", abfd->my_archive->filename,
198 fprintf (fp, "%s", abfd->filename);
203 /* Error is fatal. */
208 /* Print program name. */
209 fprintf (fp, "%s", program_name);
213 /* current bfd error or errno */
214 fprintf (fp, "%s", bfd_errmsg (bfd_get_error ()));
218 /* filename from a lang_input_statement_type */
220 lang_input_statement_type *i;
222 i = va_arg (arg, lang_input_statement_type *);
223 if (bfd_my_archive (i->the_bfd) != NULL)
225 bfd_get_filename (bfd_my_archive (i->the_bfd)));
226 fprintf (fp, "%s", i->local_sym_name);
227 if (bfd_my_archive (i->the_bfd) == NULL
228 && strcmp (i->local_sym_name, i->filename) != 0)
229 fprintf (fp, " (%s)", i->filename);
234 /* Print script file and linenumber. */
236 fprintf (fp, "--defsym %s", lex_string);
237 else if (ldfile_input_filename != NULL)
238 fprintf (fp, "%s:%u", ldfile_input_filename, lineno);
240 fprintf (fp, _("built in linker script:%u"), lineno);
244 /* Print all that's interesting about a relent. */
246 arelent *relent = va_arg (arg, arelent *);
248 lfinfo (fp, "%s+0x%v (type %s)",
249 (*(relent->sym_ptr_ptr))->name,
251 relent->howto->name);
258 /* Clever filename:linenumber with function name if possible,
259 or section name as a last resort. The arguments are a BFD,
260 a section, and an offset. */
262 static bfd *last_bfd;
263 static char *last_file = NULL;
264 static char *last_function = NULL;
268 lang_input_statement_type *entry;
270 const char *filename;
271 const char *functionname;
272 unsigned int linenumber;
273 boolean discard_last;
275 abfd = va_arg (arg, bfd *);
276 section = va_arg (arg, asection *);
277 offset = va_arg (arg, bfd_vma);
279 entry = (lang_input_statement_type *) abfd->usrdata;
280 if (entry != (lang_input_statement_type *) NULL
281 && entry->asymbols != (asymbol **) NULL)
282 asymbols = entry->asymbols;
288 symsize = bfd_get_symtab_upper_bound (abfd);
290 einfo (_("%B%F: could not read symbols\n"), abfd);
291 asymbols = (asymbol **) xmalloc (symsize);
292 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
293 if (symbol_count < 0)
294 einfo (_("%B%F: could not read symbols\n"), abfd);
295 if (entry != (lang_input_statement_type *) NULL)
297 entry->asymbols = asymbols;
298 entry->symbol_count = symbol_count;
303 if (bfd_find_nearest_line (abfd, section, asymbols, offset,
304 &filename, &functionname,
307 if (functionname != NULL && fmt[-1] == 'G')
309 lfinfo (fp, "%B:", abfd);
311 && strcmp (filename, bfd_get_filename (abfd)) != 0)
312 fprintf (fp, "%s:", filename);
313 lfinfo (fp, "%T", functionname);
315 else if (functionname != NULL && fmt[-1] == 'C')
317 if (filename == (char *) NULL)
318 filename = abfd->filename;
322 || last_function == NULL
324 || strcmp (last_file, filename) != 0
325 || strcmp (last_function, functionname) != 0)
327 /* We use abfd->filename in this initial line,
328 in case filename is a .h file or something
329 similarly unhelpful. */
330 lfinfo (fp, _("%B: In function `%T':\n"),
334 if (last_file != NULL)
336 last_file = xstrdup (filename);
337 if (last_function != NULL)
338 free (last_function);
339 last_function = xstrdup (functionname);
341 discard_last = false;
343 fprintf (fp, "%s:%u", filename, linenumber);
345 lfinfo (fp, "%s(%s+0x%v)", filename, section->name,
348 else if (filename == NULL
349 || strcmp (filename, abfd->filename) == 0)
351 lfinfo (fp, "%B(%s+0x%v)", abfd, section->name,
354 lfinfo (fp, ":%u", linenumber);
356 else if (linenumber != 0)
357 lfinfo (fp, "%B:%s:%u", abfd, filename, linenumber);
359 lfinfo (fp, "%B(%s+0x%v):%s", abfd, section->name,
363 lfinfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
368 if (last_file != NULL)
373 if (last_function != NULL)
375 free (last_function);
376 last_function = NULL;
383 /* arbitrary string, like printf */
384 fprintf (fp, "%s", va_arg (arg, char *));
388 /* integer, like printf */
389 fprintf (fp, "%d", va_arg (arg, int));
393 /* unsigned integer, like printf */
394 fprintf (fp, "%u", va_arg (arg, unsigned int));
400 if (config.fatal_warnings)
401 config.make_executable = false;
407 /* Format info message and print on stdout. */
409 /* (You would think this should be called just "info", but then you
410 would hosed by LynxOS, which defines that name in its libc.) */
413 info_msg VPARAMS ((const char *fmt, ...))
416 VA_FIXEDARG (arg, const char *, fmt);
418 vfinfo (stdout, fmt, arg);
422 /* ('e' for error.) Format info message and print on stderr. */
425 einfo VPARAMS ((const char *fmt, ...))
428 VA_FIXEDARG (arg, const char *, fmt);
430 vfinfo (stderr, fmt, arg);
435 info_assert (file, line)
439 einfo (_("%F%P: internal error %s %d\n"), file, line);
442 /* ('m' for map) Format info message and print on map. */
445 minfo VPARAMS ((const char *fmt, ...))
448 VA_FIXEDARG (arg, const char *, fmt);
450 vfinfo (config.map_file, fmt, arg);
455 lfinfo VPARAMS ((FILE *file, const char *fmt, ...))
458 VA_FIXEDARG (arg, FILE *, file);
459 VA_FIXEDARG (arg, const char *, fmt);
461 vfinfo (file, fmt, arg);
465 /* Functions to print the link map. */
470 fprintf (config.map_file, " ");
476 fprintf (config.map_file, "\n");
479 /* A more or less friendly abort message. In ld.h abort is defined to
480 call this function. */
483 ld_abort (file, line, fn)
489 einfo (_("%P: internal error: aborting at %s line %d in %s\n"),
492 einfo (_("%P: internal error: aborting at %s line %d\n"),
494 einfo (_("%P%F: please report this bug\n"));