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
54 %R info about a relent
55 %s arbitrary string, like printf
56 %d integer, like printf
60 demangle (string, remove_underscore)
62 int remove_underscore;
65 if (remove_underscore && output_bfd)
67 if (bfd_get_symbol_leading_char (output_bfd) == string[0])
70 /* Note that there's a memory leak here, we keep buying memory
71 for demangled names, and never free. But if you have so many
72 errors that you run out of VM with the error messages, then
73 there's something up */
74 res = cplus_demangle (string, DMGL_ANSI|DMGL_PARAMS);
75 return res ? res : string;
84 boolean fatal = false;
88 while (*fmt != '%' && *fmt != '\0')
100 fprintf(fp,"%%%c", fmt[-1]);
109 /* no object output, fail return */
110 config.make_executable = false;
116 bfd_vma value = va_arg(arg, bfd_vma);
117 fprintf_vma(fp, value);
122 /* hex bfd_vma, no leading zeros */
126 bfd_vma value = va_arg (arg, bfd_vma);
127 sprintf_vma (p, value);
139 const char *name = va_arg (arg, const char *);
141 if (name != (const char *) NULL)
142 fprintf (fp, "%s", demangle (name, 1));
144 fprintf (fp, "no symbol");
149 /* filename from a bfd */
151 bfd *abfd = va_arg(arg, bfd *);
152 if (abfd->my_archive) {
153 fprintf(fp,"%s(%s)", abfd->my_archive->filename,
157 fprintf(fp,"%s", abfd->filename);
168 /* print program name */
169 fprintf(fp,"%s", program_name);
173 /* current bfd error or errno */
174 fprintf(fp, bfd_errmsg(bfd_get_error ()));
178 /* filename from a lang_input_statement_type */
180 lang_input_statement_type *i =
181 va_arg(arg,lang_input_statement_type *);
183 if (i->the_bfd->my_archive)
184 fprintf(fp, "(%s)", i->the_bfd->my_archive->filename);
185 fprintf(fp,"%s", i->local_sym_name);
190 /* print script file and linenumber */
192 if (ldfile_input_filename) {
193 fprintf(fp,"%s:%u", ldfile_input_filename, lineno );
199 /* Print all that's interesting about a relent */
201 arelent *relent = va_arg(arg, arelent *);
203 finfo (fp, "%s+0x%v (type %s)",
204 (*(relent->sym_ptr_ptr))->name,
206 relent->howto->name);
211 /* Clever filename:linenumber with function name if possible,
212 or section name as a last resort. The arguments are a BFD,
213 a section, and an offset. */
218 lang_input_statement_type *entry;
220 const char *filename;
221 const char *functionname;
222 unsigned int linenumber;
224 abfd = va_arg (arg, bfd *);
225 section = va_arg (arg, asection *);
226 offset = va_arg (arg, bfd_vma);
228 entry = (lang_input_statement_type *) abfd->usrdata;
229 if (entry != (lang_input_statement_type *) NULL
230 && entry->asymbols != (asymbol **) NULL)
231 asymbols = entry->asymbols;
237 symsize = bfd_get_symtab_upper_bound (abfd);
239 einfo ("%B%F: could not read symbols", abfd);
240 asymbols = (asymbol **) xmalloc (symsize);
241 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
242 if (symbol_count < 0)
243 einfo ("%B%F: could not read symbols", abfd);
244 if (entry != (lang_input_statement_type *) NULL)
246 entry->asymbols = asymbols;
247 entry->symbol_count = symbol_count;
251 if (bfd_find_nearest_line (abfd, section, asymbols, offset,
252 &filename, &functionname, &linenumber))
254 if (filename == (char *) NULL)
255 filename = abfd->filename;
257 if (functionname != (char *)NULL)
258 fprintf (fp, "%s:%u: %s", filename, linenumber,
259 demangle (functionname, 1));
260 else if (linenumber != 0)
261 fprintf (fp, "%s:%u", filename, linenumber);
263 finfo (fp, "%s(%s+0x%v)", filename, section->name, offset);
267 finfo (fp, "%s(%s+0x%v)", abfd->filename, section->name, offset);
272 /* arbitrary string, like printf */
273 fprintf(fp,"%s", va_arg(arg, char *));
277 /* integer, like printf */
278 fprintf(fp,"%d", va_arg(arg, int));
288 /* Format info message and print on stdout. */
290 /* (You would think this should be called just "info", but then you would
291 hosed by LynxOS, which defines that name in its libc.) */
293 void info_msg(va_alist)
299 fmt = va_arg(arg, char *);
300 vfinfo(stdout, fmt, arg);
304 /* ('e' for error.) Format info message and print on stderr. */
312 fmt = va_arg(arg, char *);
313 vfinfo(stderr, fmt, arg);
318 info_assert(file, line)
322 einfo("%F%P: internal error %s %d\n", file,line);
329 size_t l = strlen(x)+1;
330 char *r = xmalloc(l);
336 /* ('m' for map) Format info message and print on map. */
344 fmt = va_arg(arg, char *);
345 vfinfo(config.map_file, fmt, arg);
358 file = va_arg (arg, FILE *);
359 fmt = va_arg (arg, char *);
360 vfinfo (file, fmt, arg);
366 /*----------------------------------------------------------------------
367 Functions to print the link map
373 fprintf(config.map_file, " ");
378 fprintf(config.map_file, "\n");
381 print_address (value)
384 fprintf_vma(config.map_file, value);