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[];
47 %S print script file and linenumber
48 %E current bfd error or errno
49 %I filename from a lang_input_statement_type
50 %B filename from a bfd
52 %X no object output, fail return
54 %C Clever filename:linenumber
55 %R info about a relent
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;
95 cplus_demangle(symbol->name, DMGL_ANSI|DMGL_PARAMS);
96 CONST char *section_name = section->name;
97 if (section != &bfd_und_section)
99 fprintf(fp,"%s (%s)", cplusname ? cplusname :
100 symbol->name, section_name);
104 fprintf(fp,"%s", cplusname ? cplusname : symbol->name);
115 fprintf(fp,"no symbol");
121 bfd *abfd = va_arg(arg, bfd *);
122 if (abfd->my_archive) {
123 fprintf(fp,"%s(%s)", abfd->my_archive->filename,
127 fprintf(fp,"%s", abfd->filename);
136 fprintf(fp,"%s", program_name);
139 /* Replace with the most recent errno explanation */
142 fprintf(fp, bfd_errmsg(bfd_error));
148 lang_input_statement_type *i =
149 va_arg(arg,lang_input_statement_type *);
151 fprintf(fp,"%s", i->local_sym_name);
155 /* Print source script file and line number */
160 extern unsigned int lineno;
161 if (ldfile_input_filename == (char *)NULL) {
162 fprintf(fp,"command line");
165 fprintf(fp,"%s:%u", ldfile_input_filename, lineno );
172 /* Print all that's interesting about a relent */
174 arelent *relent = va_arg(arg, arelent *);
176 fprintf(fp,"%s+0x%x (type %s)",
177 (*(relent->sym_ptr_ptr))->name,
179 relent->howto->name);
190 CONST char *filename;
191 CONST char *functionname;
194 unsigned int linenumber;
195 bfd *abfd = va_arg(arg, bfd *);
196 asection *section = va_arg(arg, asection *);
197 asymbol **symbols = va_arg(arg, asymbol **);
198 bfd_vma offset = va_arg(arg, bfd_vma);
200 if (bfd_find_nearest_line(abfd,
208 if (filename == (char *)NULL)
209 filename = abfd->filename;
210 if (functionname != (char *)NULL)
212 cplus_name = cplus_demangle(functionname, DMGL_ANSI|DMGL_PARAMS);
213 fprintf(fp,"%s:%u: (%s)", filename, linenumber,
214 cplus_name? cplus_name: functionname);
221 else if (linenumber != 0)
222 fprintf(fp,"%s:%u", filename, linenumber);
224 fprintf(fp,"%s(%s+%0x)", filename,
230 fprintf(fp,"%s(%s+%0x)", abfd->filename,
238 fprintf(fp,"%s", va_arg(arg, char *));
241 fprintf(fp,"%d", va_arg(arg, int));
244 fprintf(fp,"%s", va_arg(arg, char *));
251 extern char *output_filename;
254 char *new = malloc(strlen(output_filename)+2);
255 extern bfd *output_bfd;
257 strcpy(new, output_filename);
258 if (output_bfd && output_bfd->iostream)
259 fclose((FILE *)(output_bfd->iostream));
266 /* Format info message and print on stdout. */
274 fmt = va_arg(arg, char *);
275 vfinfo(stdout, fmt, arg);
279 /* ('e' for error.) Format info message and print on stderr. */
287 fmt = va_arg(arg, char *);
288 vfinfo(stderr, fmt, arg);
293 info_assert(file, line)
297 einfo("%F%P internal error %s %d\n", file,line);
300 /* Return a newly-allocated string
301 whose contents concatenate those of S1, S2, S3. */
304 DEFUN(concat, (s1, s2, s3),
309 bfd_size_type len1 = strlen (s1);
310 bfd_size_type len2 = strlen (s2);
311 bfd_size_type len3 = strlen (s3);
312 char *result = ldmalloc (len1 + len2 + len3 + 1);
315 memcpy(result, s1, len1);
317 memcpy(result+len1, s2, len2);
319 memcpy(result+len1+len2, s2, len3);
320 *(result + len1 + len2 + len3) = 0;
327 DEFUN(ldmalloc, (size),
330 PTR result = malloc ((int)size);
332 if (result == (char *)NULL && size != 0)
333 einfo("%F%P virtual memory exhausted\n");
339 DEFUN(xmalloc,(size),
342 return ldmalloc(size);
347 DEFUN(ldrealloc, (ptr, size),
351 PTR result = realloc (ptr, (int)size);
353 if (result == (char *)NULL && size != 0)
354 einfo("%F%P virtual memory exhausted\n");
361 char *DEFUN(buystring,(x),
364 bfd_size_type l = strlen(x)+1;
365 char *r = ldmalloc(l);
371 /* ('m' for map) Format info message and print on map. */
379 fmt = va_arg(arg, char *);
380 vfinfo(config.map_file, fmt, arg);
389 /*----------------------------------------------------------------------
390 Functions to print the link map
394 DEFUN_VOID(print_space)
396 fprintf(config.map_file, " ");
401 fprintf(config.map_file, "\n");
404 DEFUN(print_address,(value),
407 fprintf_vma(config.map_file, value);