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. */
32 extern char *program_name;
34 extern FILE *ldlex_input_stack;
35 extern char *ldfile_input_filename;
36 extern ld_config_type config;
41 extern char *sys_errlist[];
46 %S print script file and linenumber
47 %E current bfd error or errno
48 %I filename from a lang_input_statement_type
49 %B filename from a bfd
51 %X no object output, fail return
53 %C Clever filename:linenumber
54 %R info about a relent
63 extern char *cplus_demangle();
64 boolean fatal = false;
67 while (*fmt != '%' && *fmt != '\0')
78 config.make_executable = false;
82 bfd_vma value = va_arg(arg, bfd_vma);
83 fprintf_vma(fp, value);
88 asymbol *symbol = va_arg(arg, asymbol *);
93 asection *section = symbol->section;
94 char *cplusname = cplus_demangle(symbol->name, 1);
95 CONST char *section_name = section->name;
96 if (section != &bfd_und_section)
98 fprintf(fp,"%s (%s)", cplusname ? cplusname :
99 symbol->name, section_name);
103 fprintf(fp,"%s", cplusname ? cplusname : symbol->name);
114 fprintf(fp,"no symbol");
120 bfd *abfd = va_arg(arg, bfd *);
121 if (abfd->my_archive) {
122 fprintf(fp,"%s(%s)", abfd->my_archive->filename,
126 fprintf(fp,"%s", abfd->filename);
135 fprintf(fp,"%s", program_name);
138 /* Replace with the most recent errno explanation */
141 fprintf(fp, bfd_errmsg(bfd_error));
147 lang_input_statement_type *i =
148 va_arg(arg,lang_input_statement_type *);
150 fprintf(fp,"%s", i->local_sym_name);
154 /* Print source script file and line number */
159 extern unsigned int lineno;
160 if (ldfile_input_filename == (char *)NULL) {
161 fprintf(fp,"command line");
164 fprintf(fp,"%s:%u", ldfile_input_filename, lineno );
171 /* Print all that's interesting about a relent */
173 arelent *relent = va_arg(arg, arelent *);
175 fprintf(fp,"%s+0x%x (type %s)",
176 (*(relent->sym_ptr_ptr))->name,
178 relent->howto->name);
189 CONST char *filename;
190 CONST char *functionname;
193 unsigned int linenumber;
194 bfd *abfd = va_arg(arg, bfd *);
195 asection *section = va_arg(arg, asection *);
196 asymbol **symbols = va_arg(arg, asymbol **);
197 bfd_vma offset = va_arg(arg, bfd_vma);
199 if (bfd_find_nearest_line(abfd,
207 if (filename == (char *)NULL)
208 filename = abfd->filename;
209 if (functionname != (char *)NULL)
211 cplus_name = cplus_demangle(functionname, 1);
212 fprintf(fp,"%s:%u: (%s)", filename, linenumber,
213 cplus_name? cplus_name: functionname);
220 else if (linenumber != 0)
221 fprintf(fp,"%s:%u", filename, linenumber);
223 fprintf(fp,"%s(%s+%0x)", filename,
229 fprintf(fp,"%s(%s+%0x)", abfd->filename,
237 fprintf(fp,"%s", va_arg(arg, char *));
240 fprintf(fp,"%d", va_arg(arg, int));
243 fprintf(fp,"%s", va_arg(arg, char *));
250 extern char *output_filename;
253 char *new = malloc(strlen(output_filename)+2);
254 extern bfd *output_bfd;
256 strcpy(new, output_filename);
257 if (output_bfd && output_bfd->iostream)
258 fclose((FILE *)(output_bfd->iostream));
265 /* Format info message and print on stdout. */
273 fmt = va_arg(arg, char *);
274 vfinfo(stdout, fmt, arg);
278 /* ('e' for error.) Format info message and print on stderr. */
286 fmt = va_arg(arg, char *);
287 vfinfo(stderr, fmt, arg);
292 info_assert(file, line)
296 einfo("%F%P internal error %s %d\n", file,line);
299 /* Return a newly-allocated string
300 whose contents concatenate those of S1, S2, S3. */
303 DEFUN(concat, (s1, s2, s3),
308 bfd_size_type len1 = strlen (s1);
309 bfd_size_type len2 = strlen (s2);
310 bfd_size_type len3 = strlen (s3);
311 char *result = ldmalloc (len1 + len2 + len3 + 1);
314 memcpy(result, s1, len1);
316 memcpy(result+len1, s2, len2);
318 memcpy(result+len1+len2, s2, len3);
319 *(result + len1 + len2 + len3) = 0;
326 DEFUN(ldmalloc, (size),
329 PTR result = malloc ((int)size);
331 if (result == (char *)NULL && size != 0)
332 einfo("%F%P virtual memory exhausted\n");
338 DEFUN(xmalloc,(size),
341 return ldmalloc(size);
346 DEFUN(ldrealloc, (ptr, size),
350 PTR result = realloc (ptr, (int)size);
352 if (result == (char *)NULL && size != 0)
353 einfo("%F%P virtual memory exhausted\n");
360 char *DEFUN(buystring,(x),
363 bfd_size_type l = strlen(x)+1;
364 char *r = ldmalloc(l);
370 /* ('m' for map) Format info message and print on map. */
378 fmt = va_arg(arg, char *);
379 vfinfo(config.map_file, fmt, arg);
388 /*----------------------------------------------------------------------
389 Functions to print the link map
393 DEFUN_VOID(print_space)
395 fprintf(config.map_file, " ");
400 fprintf(config.map_file, "\n");
403 DEFUN(print_address,(value),
406 fprintf_vma(config.map_file, value);