2 Copyright (C) 1991, 1993 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. */
37 static const char *demangle PARAMS ((const char *string,
38 int remove_underscore));
44 %S print script file and linenumber
45 %E current bfd error or errno
46 %I filename from a lang_input_statement_type
47 %B filename from a bfd
49 %X no object output, fail return
51 %v hex bfd_vma, no leading zeros
52 %C Clever filename:linenumber
53 %R info about a relent
54 %s arbitrary string, like printf
55 %d integer, like printf
59 demangle (string, remove_underscore)
61 int remove_underscore;
64 if (remove_underscore && output_bfd)
66 if (bfd_get_symbol_leading_char (output_bfd) == string[0])
69 /* Note that there's a memory leak here, we keep buying memory
70 for demangled names, and never free. But if you have so many
71 errors that you run out of VM with the error messages, then
72 there's something up */
73 res = cplus_demangle (string, DMGL_ANSI|DMGL_PARAMS);
74 return res ? res : string;
83 boolean fatal = false;
87 while (*fmt != '%' && *fmt != '\0')
99 fprintf(fp,"%%%c", fmt[-1]);
108 /* no object output, fail return */
109 config.make_executable = false;
115 bfd_vma value = va_arg(arg, bfd_vma);
116 fprintf_vma(fp, value);
121 /* hex bfd_vma, no leading zeros */
125 bfd_vma value = va_arg (arg, bfd_vma);
126 sprintf_vma (p, value);
138 const char *name = va_arg (arg, const char *);
140 if (name != (const char *) NULL)
141 fprintf (fp, "%s", demangle (name, 1));
143 fprintf (fp, "no symbol");
148 /* filename from a bfd */
150 bfd *abfd = va_arg(arg, bfd *);
151 if (abfd->my_archive) {
152 fprintf(fp,"%s(%s)", abfd->my_archive->filename,
156 fprintf(fp,"%s", abfd->filename);
167 /* print program name */
168 fprintf(fp,"%s", program_name);
172 /* current bfd error or errno */
173 fprintf(fp, bfd_errmsg(bfd_error));
177 /* filename from a lang_input_statement_type */
179 lang_input_statement_type *i =
180 va_arg(arg,lang_input_statement_type *);
182 if (i->the_bfd->my_archive)
183 fprintf(fp, "(%s)", i->the_bfd->my_archive->filename);
184 fprintf(fp,"%s", i->local_sym_name);
189 /* print script file and linenumber */
191 if (ldfile_input_filename == (char *)NULL) {
192 fprintf(fp,"command line");
195 fprintf(fp,"%s:%u", ldfile_input_filename, lineno );
201 /* Print all that's interesting about a relent */
203 arelent *relent = va_arg(arg, arelent *);
205 finfo (fp, "%s+0x%v (type %s)",
206 (*(relent->sym_ptr_ptr))->name,
208 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. */
220 lang_input_statement_type *entry;
222 const char *filename;
223 const char *functionname;
224 unsigned int linenumber;
226 abfd = va_arg (arg, bfd *);
227 section = va_arg (arg, asection *);
228 offset = va_arg (arg, bfd_vma);
230 entry = (lang_input_statement_type *) abfd->usrdata;
231 if (entry != (lang_input_statement_type *) NULL
232 && entry->asymbols != (asymbol **) NULL)
233 asymbols = entry->asymbols;
236 unsigned int symsize;
237 unsigned int symbol_count;
239 symsize = get_symtab_upper_bound (abfd);
240 asymbols = (asymbol **) ldmalloc (symsize);
241 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
242 if (entry != (lang_input_statement_type *) NULL)
244 entry->asymbols = asymbols;
245 entry->symbol_count = symbol_count;
249 if (bfd_find_nearest_line (abfd, section, asymbols, offset,
250 &filename, &functionname, &linenumber))
252 if (filename == (char *) NULL)
253 filename = abfd->filename;
255 if (functionname != (char *)NULL)
256 fprintf (fp, "%s:%u: %s", filename, linenumber,
257 demangle (functionname, 1));
258 else if (linenumber != 0)
259 fprintf (fp, "%s:%u", filename, linenumber);
261 finfo (fp, "%s(%s+0x%v)", filename, section->name, offset);
265 finfo (fp, "%s(%s+0x%v)", abfd->filename, section->name, offset);
270 /* arbitrary string, like printf */
271 fprintf(fp,"%s", va_arg(arg, char *));
275 /* integer, like printf */
276 fprintf(fp,"%d", va_arg(arg, int));
286 if (output_bfd && output_bfd->iostream)
287 fclose((FILE *)(output_bfd->iostream));
288 if (delete_output_file_on_failure)
289 unlink (output_filename);
295 /* Format info message and print on stdout. */
297 /* (You would think this should be called just "info", but then you would
298 hosed by LynxOS, which defines that name in its libc.) */
300 void info_msg(va_alist)
306 fmt = va_arg(arg, char *);
307 vfinfo(stdout, fmt, arg);
311 /* ('e' for error.) Format info message and print on stderr. */
319 fmt = va_arg(arg, char *);
320 vfinfo(stderr, fmt, arg);
324 /* Warn about a symbol NEWSYM being multiply defined with another symbol OLDSYM.
325 MESSAGE1 and MESSAGE2 should look something like:
326 "%C: warning: multiple commons of `%s'\n"
327 "%C: warning: previous common here\n" */
330 multiple_warn (message1, newsym, message2, oldsym)
336 lang_input_statement_type *inp_stat;
337 asymbol **stat_symbols;
339 inp_stat = (lang_input_statement_type *) bfd_asymbol_bfd (newsym)->usrdata;
340 stat_symbols = inp_stat ? inp_stat->asymbols : 0;
343 bfd_asymbol_bfd (newsym), newsym->section, stat_symbols, newsym->value,
344 demangle (newsym->name, 1));
346 inp_stat = (lang_input_statement_type *) bfd_asymbol_bfd (oldsym)->usrdata;
347 stat_symbols = inp_stat ? inp_stat->asymbols : 0;
350 bfd_asymbol_bfd (oldsym), oldsym->section, stat_symbols, oldsym->value);
354 info_assert(file, line)
358 einfo("%F%P: internal error %s %d\n", file,line);
361 /* Return a newly-allocated string
362 whose contents concatenate those of S1, S2, S3. */
370 size_t len1 = strlen (s1);
371 size_t len2 = strlen (s2);
372 size_t len3 = strlen (s3);
373 char *result = ldmalloc (len1 + len2 + len3 + 1);
376 memcpy(result, s1, len1);
378 memcpy(result+len1, s2, len2);
380 memcpy(result+len1+len2, s2, len3);
381 *(result + len1 + len2 + len3) = 0;
391 PTR result = malloc ((int)size);
393 if (result == (char *)NULL && size != 0)
394 einfo("%F%P: virtual memory exhausted\n");
403 return ldmalloc ((size_t) size);
408 ldrealloc (ptr, size)
412 PTR result = realloc (ptr, (int)size);
414 if (result == (char *)NULL && size != 0)
415 einfo("%F%P: virtual memory exhausted\n");
425 return ldrealloc (ptr, (size_t) size);
433 size_t l = strlen(x)+1;
434 char *r = ldmalloc(l);
440 /* ('m' for map) Format info message and print on map. */
448 fmt = va_arg(arg, char *);
449 vfinfo(config.map_file, fmt, arg);
462 file = va_arg (arg, FILE *);
463 fmt = va_arg (arg, char *);
464 vfinfo (file, fmt, arg);
470 /*----------------------------------------------------------------------
471 Functions to print the link map
477 fprintf(config.map_file, " ");
482 fprintf(config.map_file, "\n");
485 print_address (value)
488 fprintf_vma(config.map_file, value);