00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "bfd.h"
00029 #include "bfdlink.h"
00030 #include "sysdep.h"
00031 #include "libiberty.h"
00032 #include "demangle.h"
00033 #include <stdarg.h>
00034 #include "ld.h"
00035 #include "ldmisc.h"
00036 #include "ldexp.h"
00037 #include "ldlang.h"
00038 #include <ldgram.h>
00039 #include "ldlex.h"
00040 #include "ldmain.h"
00041 #include "ldfile.h"
00042 #include "elf-bfd.h"
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 static void
00068 vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
00069 {
00070 bfd_boolean fatal = FALSE;
00071
00072 while (*fmt != '\0')
00073 {
00074 while (*fmt != '%' && *fmt != '\0')
00075 {
00076 putc (*fmt, fp);
00077 fmt++;
00078 }
00079
00080 if (*fmt == '%')
00081 {
00082 fmt++;
00083 switch (*fmt++)
00084 {
00085 default:
00086 fprintf (fp, "%%%c", fmt[-1]);
00087 break;
00088
00089 case '%':
00090
00091 putc ('%', fp);
00092 break;
00093
00094 case 'X':
00095
00096 config.make_executable = FALSE;
00097 break;
00098
00099 case 'V':
00100
00101 {
00102 bfd_vma value = va_arg (arg, bfd_vma);
00103 fprintf_vma (fp, value);
00104 }
00105 break;
00106
00107 case 'v':
00108
00109 {
00110 char buf[100];
00111 char *p = buf;
00112 bfd_vma value = va_arg (arg, bfd_vma);
00113 sprintf_vma (p, value);
00114 while (*p == '0')
00115 p++;
00116 if (!*p)
00117 p--;
00118 fputs (p, fp);
00119 }
00120 break;
00121
00122 case 'W':
00123
00124
00125 {
00126 char buf[100];
00127 bfd_vma value;
00128 char *p;
00129 int len;
00130
00131 value = va_arg (arg, bfd_vma);
00132 sprintf_vma (buf, value);
00133 for (p = buf; *p == '0'; ++p)
00134 ;
00135 if (*p == '\0')
00136 --p;
00137 len = strlen (p);
00138 while (len < 8)
00139 {
00140 putc (' ', fp);
00141 ++len;
00142 }
00143 fprintf (fp, "0x%s", p);
00144 }
00145 break;
00146
00147 case 'T':
00148
00149 {
00150 const char *name = va_arg (arg, const char *);
00151
00152 if (name == NULL || *name == 0)
00153 fprintf (fp, _("no symbol"));
00154 else if (! demangling)
00155 fprintf (fp, "%s", name);
00156 else
00157 {
00158 char *demangled;
00159
00160 demangled = demangle (name);
00161 fprintf (fp, "%s", demangled);
00162 free (demangled);
00163 }
00164 }
00165 break;
00166
00167 case 'A':
00168
00169 {
00170 asection *sec = va_arg (arg, asection *);
00171 bfd *abfd = sec->owner;
00172 const char *group = NULL;
00173 struct coff_comdat_info *ci;
00174
00175 fprintf (fp, "%s", sec->name);
00176 if (abfd != NULL
00177 && bfd_get_flavour (abfd) == bfd_target_elf_flavour
00178 && elf_next_in_group (sec) != NULL
00179 && (sec->flags & SEC_GROUP) == 0)
00180 group = elf_group_name (sec);
00181 else if (abfd != NULL
00182 && bfd_get_flavour (abfd) == bfd_target_coff_flavour
00183 && (ci = bfd_coff_get_comdat_section (sec->owner,
00184 sec)) != NULL)
00185 group = ci->name;
00186 if (group != NULL)
00187 fprintf (fp, "[%s]", group);
00188 }
00189 break;
00190
00191 case 'B':
00192
00193 {
00194 bfd *abfd = va_arg (arg, bfd *);
00195
00196 if (abfd == NULL)
00197 fprintf (fp, "<none>");
00198 else if (abfd->my_archive)
00199 fprintf (fp, "%s(%s)", abfd->my_archive->filename,
00200 abfd->filename);
00201 else
00202 fprintf (fp, "%s", abfd->filename);
00203 }
00204 break;
00205
00206 case 'F':
00207
00208 fatal = TRUE;
00209 break;
00210
00211 case 'P':
00212
00213 fprintf (fp, "%s", program_name);
00214 break;
00215
00216 case 'E':
00217
00218 fprintf (fp, "%s", bfd_errmsg (bfd_get_error ()));
00219 break;
00220
00221 case 'I':
00222
00223 {
00224 lang_input_statement_type *i;
00225
00226 i = va_arg (arg, lang_input_statement_type *);
00227 if (bfd_my_archive (i->the_bfd) != NULL)
00228 fprintf (fp, "(%s)",
00229 bfd_get_filename (bfd_my_archive (i->the_bfd)));
00230 fprintf (fp, "%s", i->local_sym_name);
00231 if (bfd_my_archive (i->the_bfd) == NULL
00232 && strcmp (i->local_sym_name, i->filename) != 0)
00233 fprintf (fp, " (%s)", i->filename);
00234 }
00235 break;
00236
00237 case 'S':
00238
00239 if (parsing_defsym)
00240 fprintf (fp, "--defsym %s", lex_string);
00241 else if (ldfile_input_filename != NULL)
00242 fprintf (fp, "%s:%u", ldfile_input_filename, lineno);
00243 else
00244 fprintf (fp, _("built in linker script:%u"), lineno);
00245 break;
00246
00247 case 'R':
00248
00249 {
00250 arelent *relent = va_arg (arg, arelent *);
00251
00252 lfinfo (fp, "%s+0x%v (type %s)",
00253 (*(relent->sym_ptr_ptr))->name,
00254 relent->addend,
00255 relent->howto->name);
00256 }
00257 break;
00258
00259 case 'C':
00260 case 'D':
00261 case 'G':
00262
00263
00264 {
00265 static bfd *last_bfd;
00266 static char *last_file = NULL;
00267 static char *last_function = NULL;
00268 bfd *abfd;
00269 asection *section;
00270 bfd_vma offset;
00271 lang_input_statement_type *entry;
00272 asymbol **asymbols;
00273 const char *filename;
00274 const char *functionname;
00275 unsigned int linenumber;
00276 bfd_boolean discard_last;
00277
00278 abfd = va_arg (arg, bfd *);
00279 section = va_arg (arg, asection *);
00280 offset = va_arg (arg, bfd_vma);
00281
00282 entry = (lang_input_statement_type *) abfd->usrdata;
00283 if (entry != (lang_input_statement_type *) NULL
00284 && entry->asymbols != (asymbol **) NULL)
00285 asymbols = entry->asymbols;
00286 else
00287 {
00288 long symsize;
00289 long symbol_count;
00290
00291 symsize = bfd_get_symtab_upper_bound (abfd);
00292 if (symsize < 0)
00293 einfo (_("%B%F: could not read symbols\n"), abfd);
00294 asymbols = xmalloc (symsize);
00295 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
00296 if (symbol_count < 0)
00297 einfo (_("%B%F: could not read symbols\n"), abfd);
00298 if (entry != (lang_input_statement_type *) NULL)
00299 {
00300 entry->asymbols = asymbols;
00301 entry->symbol_count = symbol_count;
00302 }
00303 }
00304
00305
00306
00307
00308
00309
00310
00311 discard_last = TRUE;
00312 if (bfd_find_nearest_line (abfd, section, asymbols, offset,
00313 &filename, &functionname,
00314 &linenumber))
00315 {
00316 if (functionname != NULL && fmt[-1] == 'C')
00317 {
00318
00319
00320
00321
00322
00323
00324
00325 if (last_bfd == NULL
00326 || last_file == NULL
00327 || last_function == NULL
00328 || last_bfd != abfd
00329 || (filename != NULL
00330 && strcmp (last_file, filename) != 0)
00331 || strcmp (last_function, functionname) != 0)
00332 {
00333 lfinfo (fp, _("%B: In function `%T':\n"),
00334 abfd, functionname);
00335
00336 last_bfd = abfd;
00337 if (last_file != NULL)
00338 free (last_file);
00339 last_file = NULL;
00340 if (filename)
00341 last_file = xstrdup (filename);
00342 if (last_function != NULL)
00343 free (last_function);
00344 last_function = xstrdup (functionname);
00345 }
00346 discard_last = FALSE;
00347 }
00348 else
00349 lfinfo (fp, "%B:", abfd);
00350
00351 if (filename != NULL)
00352 fprintf (fp, "%s:", filename);
00353
00354 if (functionname != NULL && fmt[-1] == 'G')
00355 lfinfo (fp, "%T", functionname);
00356 else if (filename != NULL)
00357 {
00358 if (linenumber != 0)
00359 fprintf (fp, "%u", linenumber);
00360 else
00361 lfinfo (fp, "(%A+0x%v)", section, offset);
00362 }
00363 }
00364 else
00365 lfinfo (fp, "%B:(%A+0x%v)", abfd, section, offset);
00366
00367 if (asymbols != NULL && entry == NULL)
00368 free (asymbols);
00369
00370 if (discard_last)
00371 {
00372 last_bfd = NULL;
00373 if (last_file != NULL)
00374 {
00375 free (last_file);
00376 last_file = NULL;
00377 }
00378 if (last_function != NULL)
00379 {
00380 free (last_function);
00381 last_function = NULL;
00382 }
00383 }
00384 }
00385 break;
00386
00387 case 's':
00388
00389 fprintf (fp, "%s", va_arg (arg, char *));
00390 break;
00391
00392 case 'd':
00393
00394 fprintf (fp, "%d", va_arg (arg, int));
00395 break;
00396
00397 case 'u':
00398
00399 fprintf (fp, "%u", va_arg (arg, unsigned int));
00400 break;
00401 }
00402 }
00403 }
00404
00405 if (is_warning && config.fatal_warnings)
00406 config.make_executable = FALSE;
00407
00408 if (fatal)
00409 xexit (1);
00410 }
00411
00412
00413
00414
00415 char *
00416 demangle (const char *name)
00417 {
00418 char *res;
00419 const char *p;
00420
00421 if (output_bfd != NULL
00422 && bfd_get_symbol_leading_char (output_bfd) == name[0])
00423 ++name;
00424
00425
00426
00427
00428
00429 p = name;
00430 while (*p == '.')
00431 ++p;
00432
00433 res = cplus_demangle (p, DMGL_ANSI | DMGL_PARAMS);
00434 if (res)
00435 {
00436 size_t dots = p - name;
00437
00438
00439 if (dots != 0)
00440 {
00441 size_t len = strlen (res) + 1;
00442 char *add_dots = xmalloc (len + dots);
00443
00444 memcpy (add_dots, name, dots);
00445 memcpy (add_dots + dots, res, len);
00446 free (res);
00447 res = add_dots;
00448 }
00449 return res;
00450 }
00451 return xstrdup (name);
00452 }
00453
00454
00455
00456
00457
00458
00459 void
00460 info_msg (const char *fmt, ...)
00461 {
00462 va_list arg;
00463
00464 va_start (arg, fmt);
00465 vfinfo (stdout, fmt, arg, FALSE);
00466 va_end (arg);
00467 }
00468
00469
00470
00471 void
00472 einfo (const char *fmt, ...)
00473 {
00474 va_list arg;
00475
00476 va_start (arg, fmt);
00477 vfinfo (stderr, fmt, arg, TRUE);
00478 va_end (arg);
00479 }
00480
00481 void
00482 info_assert (const char *file, unsigned int line)
00483 {
00484 einfo (_("%F%P: internal error %s %d\n"), file, line);
00485 }
00486
00487
00488
00489 void
00490 minfo (const char *fmt, ...)
00491 {
00492 va_list arg;
00493
00494 va_start (arg, fmt);
00495 vfinfo (config.map_file, fmt, arg, FALSE);
00496 va_end (arg);
00497 }
00498
00499 void
00500 lfinfo (FILE *file, const char *fmt, ...)
00501 {
00502 va_list arg;
00503
00504 va_start (arg, fmt);
00505 vfinfo (file, fmt, arg, FALSE);
00506 va_end (arg);
00507 }
00508
00509
00510
00511 void
00512 print_space (void)
00513 {
00514 fprintf (config.map_file, " ");
00515 }
00516
00517 void
00518 print_nl (void)
00519 {
00520 fprintf (config.map_file, "\n");
00521 }
00522
00523
00524
00525
00526 void
00527 ld_abort (const char *file, int line, const char *fn)
00528 {
00529 if (fn != NULL)
00530 einfo (_("%P: internal error: aborting at %s line %d in %s\n"),
00531 file, line, fn);
00532 else
00533 einfo (_("%P: internal error: aborting at %s line %d\n"),
00534 file, line);
00535 einfo (_("%P%F: please report this bug\n"));
00536 xexit (1);
00537 }