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. */
38 extern char *program_name
;
40 extern FILE *ldlex_input_stack
;
41 extern char *ldfile_input_filename
;
42 extern ld_config_type config
;
48 einfo("%P%F: %S %s\n",arg
);
53 extern char *sys_errlist
[];
58 %S print script file and linenumber
59 %E current bfd error or errno
60 %I filename from a lang_input_statement_type
61 %B filename from a bfd
63 %X no object output, fail return
65 %C Clever filename:linenumber
66 %R info about a relent
75 extern char *cplus_demangle();
76 boolean fatal
= false;
79 while (*fmt
!= '%' && *fmt
!= '\0')
90 config
.make_executable
= false;
94 bfd_vma value
= va_arg(arg
, bfd_vma
);
95 fprintf_vma(fp
, value
);
100 asymbol
*symbol
= va_arg(arg
, asymbol
*);
105 asection
*section
= symbol
->section
;
106 char *cplusname
= cplus_demangle(symbol
->name
, 1);
107 CONST
char *section_name
= section
->name
;
108 if (section
!= &bfd_und_section
)
110 fprintf(fp
,"%s (%s)", cplusname
? cplusname
:
111 symbol
->name
, section_name
);
115 fprintf(fp
,"%s", cplusname
? cplusname
: symbol
->name
);
126 fprintf(fp
,"no symbol");
132 bfd
*abfd
= va_arg(arg
, bfd
*);
133 if (abfd
->my_archive
) {
134 fprintf(fp
,"%s(%s)", abfd
->my_archive
->filename
,
138 fprintf(fp
,"%s", abfd
->filename
);
147 fprintf(fp
,"%s", program_name
);
150 /* Replace with the most recent errno explanation */
153 fprintf(fp
, bfd_errmsg(bfd_error
));
159 lang_input_statement_type
*i
=
160 va_arg(arg
,lang_input_statement_type
*);
162 fprintf(fp
,"%s", i
->local_sym_name
);
166 /* Print source script file and line number */
171 extern unsigned int lineno
;
172 if (ldfile_input_filename
== (char *)NULL
) {
173 fprintf(fp
,"command line");
176 fprintf(fp
,"%s:%u", ldfile_input_filename
, lineno
);
183 /* Print all that's interesting about a relent */
185 arelent
*relent
= va_arg(arg
, arelent
*);
187 fprintf(fp
,"%s+0x%x (type %s)",
188 (*(relent
->sym_ptr_ptr
))->name
,
190 relent
->howto
->name
);
201 CONST
char *filename
;
202 CONST
char *functionname
;
205 unsigned int linenumber
;
206 bfd
*abfd
= va_arg(arg
, bfd
*);
207 asection
*section
= va_arg(arg
, asection
*);
208 asymbol
**symbols
= va_arg(arg
, asymbol
**);
209 bfd_vma offset
= va_arg(arg
, bfd_vma
);
211 if (bfd_find_nearest_line(abfd
,
219 if (filename
== (char *)NULL
)
220 filename
= abfd
->filename
;
221 if (functionname
!= (char *)NULL
)
223 cplus_name
= cplus_demangle(functionname
, 1);
224 fprintf(fp
,"%s:%u: (%s)", filename
, linenumber
,
225 cplus_name
? cplus_name
: functionname
);
232 else if (linenumber
!= 0)
233 fprintf(fp
,"%s:%u", filename
, linenumber
);
235 fprintf(fp
,"%s(%s+%0x)", filename
,
241 fprintf(fp
,"%s(%s+%0x)", abfd
->filename
,
249 fprintf(fp
,"%s", va_arg(arg
, char *));
252 fprintf(fp
,"%d", va_arg(arg
, int));
255 fprintf(fp
,"%s", va_arg(arg
, char *));
261 extern char *output_filename
;
263 unlink(output_filename
);
268 /* Format info message and print on stdout. */
276 fmt
= va_arg(arg
, char *);
277 vfinfo(stdout
, fmt
, arg
);
281 /* ('e' for error.) Format info message and print on stderr. */
289 fmt
= va_arg(arg
, char *);
290 vfinfo(stderr
, fmt
, arg
);
295 info_assert(file
, line
)
299 einfo("%F%P internal error %s %d\n", file
,line
);
302 /* Return a newly-allocated string
303 whose contents concatenate those of S1, S2, S3. */
306 DEFUN(concat
, (s1
, s2
, s3
),
311 bfd_size_type len1
= strlen (s1
);
312 bfd_size_type len2
= strlen (s2
);
313 bfd_size_type len3
= strlen (s3
);
314 char *result
= ldmalloc (len1
+ len2
+ len3
+ 1);
317 memcpy(result
, s1
, len1
);
319 memcpy(result
+len1
, s2
, len2
);
321 memcpy(result
+len1
+len2
, s2
, len3
);
322 *(result
+ len1
+ len2
+ len3
) = 0;
330 DEFUN(ldmalloc
, (size
),
333 PTR result
= malloc ((int)size
);
335 if (result
== (char *)NULL
&& size
!= 0)
336 einfo("%F%P virtual memory exhausted\n");
343 DEFUN(ldrealloc
, (ptr
, size
),
347 PTR result
= realloc (ptr
, (int)size
);
349 if (result
== (char *)NULL
&& size
!= 0)
350 einfo("%F%P virtual memory exhausted\n");
357 char *DEFUN(buystring
,(x
),
360 bfd_size_type l
= strlen(x
)+1;
361 char *r
= ldmalloc(l
);
367 /* ('m' for map) Format info message and print on map. */
375 fmt
= va_arg(arg
, char *);
376 vfinfo(config
.map_file
, fmt
, arg
);
385 /*----------------------------------------------------------------------
386 Functions to print the link map
390 DEFUN_VOID(print_space
)
392 fprintf(config
.map_file
, " ");
397 fprintf(config
.map_file
, "\n");
400 DEFUN(print_address
,(value
),
403 fprintf_vma(config
.map_file
, value
);