2 Copyright (C) 1991 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. */
33 extern char *program_name;
35 extern FILE *ldlex_input_stack;
36 extern char *ldfile_input_filename;
37 extern ld_config_type config;
42 extern char *sys_errlist[];
50 %S print script file and linenumber
51 %E current bfd error or errno
52 %I filename from a lang_input_statement_type
53 %B filename from a bfd
55 %X no object output, fail return
57 %v hex bfd_vma, no leading zeros
58 %C Clever filename:linenumber
59 %R info about a relent
62 extern bfd *output_bfd;
65 demangle(string, remove_underscore)
67 int remove_underscore;
70 if (remove_underscore && output_bfd)
72 if (bfd_get_symbol_leading_char(output_bfd) == string[0])
75 /* Note that there's a memory leak here, we keep buying memory
76 for demangled names, and never free. But if you have so many
77 errors that you run out of VM with the error messages, then
78 there's something up */
79 res = cplus_demangle(string, DMGL_ANSI|DMGL_PARAMS);
80 return res ? res : string;
89 boolean fatal = false;
93 while (*fmt != '%' && *fmt != '\0')
105 config.make_executable = false;
110 bfd_vma value = va_arg(arg, bfd_vma);
111 fprintf_vma(fp, value);
119 bfd_vma value = va_arg (arg, bfd_vma);
120 sprintf_vma (p, value);
131 asymbol *symbol = va_arg(arg, asymbol *);
134 asection *section = symbol->section;
135 char *cplusname = demangle(symbol->name, 1);
136 CONST char *section_name = section->name;
137 if (section != &bfd_und_section)
139 fprintf(fp,"%s (%s)", cplusname, section_name);
143 fprintf(fp,"%s", cplusname);
148 fprintf(fp,"no symbol");
155 bfd *abfd = va_arg(arg, bfd *);
156 if (abfd->my_archive) {
157 fprintf(fp,"%s(%s)", abfd->my_archive->filename,
161 fprintf(fp,"%s", abfd->filename);
171 fprintf(fp,"%s", program_name);
175 /* Replace with the most recent errno explanation */
176 fprintf(fp, bfd_errmsg(bfd_error));
181 lang_input_statement_type *i =
182 va_arg(arg,lang_input_statement_type *);
184 fprintf(fp,"%s", i->local_sym_name);
189 /* Print source script file and line number */
191 extern unsigned int lineno;
192 if (ldfile_input_filename == (char *)NULL) {
193 fprintf(fp,"command line");
196 fprintf(fp,"%s:%u", ldfile_input_filename, lineno );
202 /* Print all that's interesting about a relent */
204 arelent *relent = va_arg(arg, arelent *);
206 finfo (fp, "%s+0x%v (type %s)",
207 (*(relent->sym_ptr_ptr))->name,
209 relent->howto->name);
215 CONST char *filename;
216 CONST char *functionname;
219 unsigned int linenumber;
220 bfd *abfd = va_arg(arg, bfd *);
221 asection *section = va_arg(arg, asection *);
222 asymbol **symbols = va_arg(arg, asymbol **);
223 bfd_vma offset = va_arg(arg, bfd_vma);
225 if (bfd_find_nearest_line(abfd,
233 if (filename == (char *)NULL)
234 filename = abfd->filename;
235 if (functionname != (char *)NULL)
237 cplus_name = demangle(functionname, 1);
238 fprintf(fp,"%s:%u: (%s)", filename, linenumber, cplus_name);
241 else if (linenumber != 0)
242 fprintf(fp,"%s:%u", filename, linenumber);
244 finfo (fp, "%s(%s+0x%v)", filename, section->name, offset);
248 finfo (fp, "%s(%s+0x%v)", abfd->filename, section->name, offset);
253 fprintf(fp,"%s", va_arg(arg, char *));
257 fprintf(fp,"%d", va_arg(arg, int));
261 fprintf(fp,"%s", va_arg(arg, char *));
269 extern char *output_filename;
272 char *new = malloc(strlen(output_filename)+2);
273 extern bfd *output_bfd;
275 strcpy(new, output_filename);
276 if (output_bfd && output_bfd->iostream)
277 fclose((FILE *)(output_bfd->iostream));
284 /* Format info message and print on stdout. */
292 fmt = va_arg(arg, char *);
293 vfinfo(stdout, fmt, arg);
297 /* ('e' for error.) Format info message and print on stderr. */
305 fmt = va_arg(arg, char *);
306 vfinfo(stderr, fmt, arg);
310 /* Warn about a symbol NEWSYM being multiply defined with another symbol OLDSYM.
311 MESSAGE1 and MESSAGE2 should look something like:
312 "%C: warning: multiple commons of `%s'\n"
313 "%C: warning: previous common here\n" */
316 multiple_warn (message1, newsym, message2, oldsym)
322 lang_input_statement_type *stat;
323 asymbol **stat_symbols;
325 stat = (lang_input_statement_type *) bfd_asymbol_bfd (newsym)->usrdata;
326 stat_symbols = stat ? stat->asymbols : 0;
329 bfd_asymbol_bfd (newsym), newsym->section, stat_symbols, newsym->value,
330 demangle (newsym->name, 1));
332 stat = (lang_input_statement_type *) bfd_asymbol_bfd (oldsym)->usrdata;
333 stat_symbols = stat ? stat->asymbols : 0;
336 bfd_asymbol_bfd (oldsym), oldsym->section, stat_symbols, oldsym->value);
340 info_assert(file, line)
344 einfo("%F%P internal error %s %d\n", file,line);
347 /* Return a newly-allocated string
348 whose contents concatenate those of S1, S2, S3. */
356 size_t len1 = strlen (s1);
357 size_t len2 = strlen (s2);
358 size_t len3 = strlen (s3);
359 char *result = ldmalloc (len1 + len2 + len3 + 1);
362 memcpy(result, s1, len1);
364 memcpy(result+len1, s2, len2);
366 memcpy(result+len1+len2, s2, len3);
367 *(result + len1 + len2 + len3) = 0;
377 PTR result = malloc ((int)size);
379 if (result == (char *)NULL && size != 0)
380 einfo("%F%P virtual memory exhausted\n");
389 return ldmalloc(size);
394 ldrealloc (ptr, size)
398 PTR result = realloc (ptr, (int)size);
400 if (result == (char *)NULL && size != 0)
401 einfo("%F%P virtual memory exhausted\n");
411 return ldrealloc(ptr, size);
419 size_t l = strlen(x)+1;
420 char *r = ldmalloc(l);
426 /* ('m' for map) Format info message and print on map. */
434 fmt = va_arg(arg, char *);
435 vfinfo(config.map_file, fmt, arg);
448 file = va_arg (arg, FILE *);
449 fmt = va_arg (arg, char *);
450 vfinfo (file, fmt, arg);
456 /*----------------------------------------------------------------------
457 Functions to print the link map
463 fprintf(config.map_file, " ");
468 fprintf(config.map_file, "\n");
471 print_address (value)
474 fprintf_vma(config.map_file, value);