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;
92 while (*fmt
!= '%' && *fmt
!= '\0')
103 config
.make_executable
= false;
107 bfd_vma value
= va_arg(arg
, bfd_vma
);
108 fprintf_vma(fp
, value
);
115 bfd_vma value
= va_arg (arg
, bfd_vma
);
116 sprintf_vma (p
, value
);
126 asymbol
*symbol
= va_arg(arg
, asymbol
*);
131 asection
*section
= symbol
->section
;
132 char *cplusname
= demangle(symbol
->name
, 1);
133 CONST
char *section_name
= section
->name
;
134 if (section
!= &bfd_und_section
)
136 fprintf(fp
,"%s (%s)", cplusname
, section_name
);
140 fprintf(fp
,"%s", cplusname
);
145 fprintf(fp
,"no symbol");
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
);
166 fprintf(fp
,"%s", program_name
);
169 /* Replace with the most recent errno explanation */
172 fprintf(fp
, bfd_errmsg(bfd_error
));
178 lang_input_statement_type
*i
=
179 va_arg(arg
,lang_input_statement_type
*);
181 fprintf(fp
,"%s", i
->local_sym_name
);
185 /* Print source script file and line number */
190 extern unsigned int lineno
;
191 if (ldfile_input_filename
== (char *)NULL
) {
192 fprintf(fp
,"command line");
195 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
);
218 CONST
char *filename
;
219 CONST
char *functionname
;
222 unsigned int linenumber
;
223 bfd
*abfd
= va_arg(arg
, bfd
*);
224 asection
*section
= va_arg(arg
, asection
*);
225 asymbol
**symbols
= va_arg(arg
, asymbol
**);
226 bfd_vma offset
= va_arg(arg
, bfd_vma
);
228 if (bfd_find_nearest_line(abfd
,
236 if (filename
== (char *)NULL
)
237 filename
= abfd
->filename
;
238 if (functionname
!= (char *)NULL
)
240 /* There is no initial '_' to remove here. */
241 cplus_name
= demangle(functionname
, 0);
242 fprintf(fp
,"%s:%u: (%s)", filename
, linenumber
, cplus_name
);
245 else if (linenumber
!= 0)
246 fprintf(fp
,"%s:%u", filename
, linenumber
);
248 finfo (fp
, "%s(%s+0x%v)", filename
, section
->name
, offset
);
252 finfo (fp
, "%s(%s+0x%v)", abfd
->filename
, section
->name
, offset
);
257 fprintf(fp
,"%s", va_arg(arg
, char *));
260 fprintf(fp
,"%d", va_arg(arg
, int));
263 fprintf(fp
,"%s", va_arg(arg
, char *));
270 extern char *output_filename
;
273 char *new = malloc(strlen(output_filename
)+2);
274 extern bfd
*output_bfd
;
276 strcpy(new, output_filename
);
277 if (output_bfd
&& output_bfd
->iostream
)
278 fclose((FILE *)(output_bfd
->iostream
));
285 /* Format info message and print on stdout. */
293 fmt
= va_arg(arg
, char *);
294 vfinfo(stdout
, fmt
, arg
);
298 /* ('e' for error.) Format info message and print on stderr. */
306 fmt
= va_arg(arg
, char *);
307 vfinfo(stderr
, fmt
, arg
);
312 info_assert(file
, line
)
316 einfo("%F%P internal error %s %d\n", file
,line
);
319 /* Return a newly-allocated string
320 whose contents concatenate those of S1, S2, S3. */
328 size_t len1
= strlen (s1
);
329 size_t len2
= strlen (s2
);
330 size_t len3
= strlen (s3
);
331 char *result
= ldmalloc (len1
+ len2
+ len3
+ 1);
334 memcpy(result
, s1
, len1
);
336 memcpy(result
+len1
, s2
, len2
);
338 memcpy(result
+len1
+len2
, s2
, len3
);
339 *(result
+ len1
+ len2
+ len3
) = 0;
349 PTR result
= malloc ((int)size
);
351 if (result
== (char *)NULL
&& size
!= 0)
352 einfo("%F%P virtual memory exhausted\n");
361 return ldmalloc(size
);
366 ldrealloc (ptr
, size
)
370 PTR result
= realloc (ptr
, (int)size
);
372 if (result
== (char *)NULL
&& size
!= 0)
373 einfo("%F%P virtual memory exhausted\n");
383 return ldrealloc(ptr
, size
);
391 size_t l
= strlen(x
)+1;
392 char *r
= ldmalloc(l
);
398 /* ('m' for map) Format info message and print on map. */
406 fmt
= va_arg(arg
, char *);
407 vfinfo(config
.map_file
, fmt
, arg
);
420 file
= va_arg (arg
, FILE *);
421 fmt
= va_arg (arg
, char *);
422 vfinfo (file
, fmt
, arg
);
428 /*----------------------------------------------------------------------
429 Functions to print the link map
435 fprintf(config
.map_file
, " ");
440 fprintf(config
.map_file
, "\n");
443 print_address (value
)
446 fprintf_vma(config
.map_file
, value
);