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. */
43 %S print script file and linenumber
44 %E current bfd error or errno
45 %I filename from a lang_input_statement_type
46 %B filename from a bfd
48 %X no object output, fail return
50 %v hex bfd_vma, no leading zeros
51 %C Clever filename:linenumber
52 %R info about a relent
53 %s arbitrary string, like printf
54 %d integer, like printf
58 demangle(string
, remove_underscore
)
60 int remove_underscore
;
63 if (remove_underscore
&& output_bfd
)
65 if (bfd_get_symbol_leading_char(output_bfd
) == string
[0])
68 /* Note that there's a memory leak here, we keep buying memory
69 for demangled names, and never free. But if you have so many
70 errors that you run out of VM with the error messages, then
71 there's something up */
72 res
= cplus_demangle(string
, DMGL_ANSI
|DMGL_PARAMS
);
73 return res
? res
: string
;
82 boolean fatal
= false;
86 while (*fmt
!= '%' && *fmt
!= '\0')
98 fprintf(fp
,"%%%c", fmt
[-1]);
107 /* no object output, fail return */
108 config
.make_executable
= false;
114 bfd_vma value
= va_arg(arg
, bfd_vma
);
115 fprintf_vma(fp
, value
);
120 /* hex bfd_vma, no leading zeros */
124 bfd_vma value
= va_arg (arg
, bfd_vma
);
125 sprintf_vma (p
, value
);
135 /* symbol table entry */
137 asymbol
*symbol
= va_arg(arg
, asymbol
*);
140 asection
*section
= symbol
->section
;
141 char *cplusname
= demangle(symbol
->name
, 1);
142 CONST
char *section_name
= section
->name
;
143 if (section
!= &bfd_und_section
)
145 fprintf(fp
,"%s (%s)", cplusname
, section_name
);
149 fprintf(fp
,"%s", cplusname
);
154 fprintf(fp
,"no symbol");
160 /* filename from a bfd */
162 bfd
*abfd
= va_arg(arg
, bfd
*);
163 if (abfd
->my_archive
) {
164 fprintf(fp
,"%s(%s)", abfd
->my_archive
->filename
,
168 fprintf(fp
,"%s", abfd
->filename
);
179 /* print program name */
180 fprintf(fp
,"%s", program_name
);
184 /* current bfd error or errno */
185 fprintf(fp
, bfd_errmsg(bfd_error
));
189 /* filename from a lang_input_statement_type */
191 lang_input_statement_type
*i
=
192 va_arg(arg
,lang_input_statement_type
*);
194 fprintf(fp
,"%s", i
->local_sym_name
);
199 /* print script file and linenumber */
201 if (ldfile_input_filename
== (char *)NULL
) {
202 fprintf(fp
,"command line");
205 fprintf(fp
,"%s:%u", ldfile_input_filename
, lineno
);
211 /* Print all that's interesting about a relent */
213 arelent
*relent
= va_arg(arg
, arelent
*);
215 finfo (fp
, "%s+0x%v (type %s)",
216 (*(relent
->sym_ptr_ptr
))->name
,
218 relent
->howto
->name
);
223 /* Clever filename:linenumber with function name if possible,
224 or section name as a last resort */
226 CONST
char *filename
;
227 CONST
char *functionname
;
230 unsigned int linenumber
;
231 bfd
*abfd
= va_arg(arg
, bfd
*);
232 asection
*section
= va_arg(arg
, asection
*);
233 asymbol
**symbols
= va_arg(arg
, asymbol
**);
234 bfd_vma offset
= va_arg(arg
, bfd_vma
);
236 if (bfd_find_nearest_line(abfd
,
244 if (filename
== (char *)NULL
)
245 filename
= abfd
->filename
;
246 if (functionname
!= (char *)NULL
)
248 cplus_name
= demangle(functionname
, 1);
249 fprintf(fp
,"%s:%u: %s", filename
, linenumber
, cplus_name
);
252 else if (linenumber
!= 0)
253 fprintf(fp
,"%s:%u", filename
, linenumber
);
255 finfo (fp
, "%s(%s+0x%v)", filename
, section
->name
, offset
);
259 finfo (fp
, "%s(%s+0x%v)", abfd
->filename
, section
->name
, offset
);
264 /* arbitrary string, like printf */
265 fprintf(fp
,"%s", va_arg(arg
, char *));
269 /* integer, like printf */
270 fprintf(fp
,"%d", va_arg(arg
, int));
280 if (output_bfd
&& output_bfd
->iostream
)
281 fclose((FILE *)(output_bfd
->iostream
));
282 if (delete_output_file_on_failure
)
283 unlink (output_filename
);
289 /* Format info message and print on stdout. */
291 /* (You would think this should be called just "info", but then you would
292 hosed by LynxOS, which defines that name in its libc.) */
294 void info_msg(va_alist
)
300 fmt
= va_arg(arg
, char *);
301 vfinfo(stdout
, fmt
, arg
);
305 /* ('e' for error.) Format info message and print on stderr. */
313 fmt
= va_arg(arg
, char *);
314 vfinfo(stderr
, fmt
, arg
);
318 /* Warn about a symbol NEWSYM being multiply defined with another symbol OLDSYM.
319 MESSAGE1 and MESSAGE2 should look something like:
320 "%C: warning: multiple commons of `%s'\n"
321 "%C: warning: previous common here\n" */
324 multiple_warn (message1
, newsym
, message2
, oldsym
)
330 lang_input_statement_type
*stat
;
331 asymbol
**stat_symbols
;
333 stat
= (lang_input_statement_type
*) bfd_asymbol_bfd (newsym
)->usrdata
;
334 stat_symbols
= stat
? stat
->asymbols
: 0;
337 bfd_asymbol_bfd (newsym
), newsym
->section
, stat_symbols
, newsym
->value
,
338 demangle (newsym
->name
, 1));
340 stat
= (lang_input_statement_type
*) bfd_asymbol_bfd (oldsym
)->usrdata
;
341 stat_symbols
= stat
? stat
->asymbols
: 0;
344 bfd_asymbol_bfd (oldsym
), oldsym
->section
, stat_symbols
, oldsym
->value
);
348 info_assert(file
, line
)
352 einfo("%F%P: internal error %s %d\n", file
,line
);
355 /* Return a newly-allocated string
356 whose contents concatenate those of S1, S2, S3. */
364 size_t len1
= strlen (s1
);
365 size_t len2
= strlen (s2
);
366 size_t len3
= strlen (s3
);
367 char *result
= ldmalloc (len1
+ len2
+ len3
+ 1);
370 memcpy(result
, s1
, len1
);
372 memcpy(result
+len1
, s2
, len2
);
374 memcpy(result
+len1
+len2
, s2
, len3
);
375 *(result
+ len1
+ len2
+ len3
) = 0;
385 PTR result
= malloc ((int)size
);
387 if (result
== (char *)NULL
&& size
!= 0)
388 einfo("%F%P: virtual memory exhausted\n");
397 return ldmalloc(size
);
402 ldrealloc (ptr
, size
)
406 PTR result
= realloc (ptr
, (int)size
);
408 if (result
== (char *)NULL
&& size
!= 0)
409 einfo("%F%P: virtual memory exhausted\n");
419 return ldrealloc(ptr
, size
);
427 size_t l
= strlen(x
)+1;
428 char *r
= ldmalloc(l
);
434 /* ('m' for map) Format info message and print on map. */
442 fmt
= va_arg(arg
, char *);
443 vfinfo(config
.map_file
, fmt
, arg
);
456 file
= va_arg (arg
, FILE *);
457 fmt
= va_arg (arg
, char *);
458 vfinfo (file
, fmt
, arg
);
464 /*----------------------------------------------------------------------
465 Functions to print the link map
471 fprintf(config
.map_file
, " ");
476 fprintf(config
.map_file
, "\n");
479 print_address (value
)
482 fprintf_vma(config
.map_file
, value
);