1 /* nm.c -- Describe symbol table of a rel file. 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 3 2001, 2002, 2003 4 Free Software Foundation, Inc. 5 6 This file is part of GNU Binutils. 7 8 This program 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 of the License, or 11 (at your option) any later version. 12 13 This program 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. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 21 02111-1307, USA. */ 22 23 #include "bfd.h" 24 #include "progress.h" 25 #include "bucomm.h" 26 #include "budemang.h" 27 #include "getopt.h" 28 #include "aout/stab_gnu.h" 29 #include "aout/ranlib.h" 30 #include "demangle.h" 31 #include "libiberty.h" 32 #include "elf-bfd.h" 33 #include "elf/common.h" 34 35 /* When sorting by size, we use this structure to hold the size and a 36 pointer to the minisymbol. */ 37 38 struct size_sym 39 { 40 const void *minisym; 41 bfd_vma size; 42 }; 43 44 /* When fetching relocs, we use this structure to pass information to 45 get_relocs. */ 46 47 struct get_relocs_info 48 { 49 asection **secs; 50 arelent ***relocs; 51 long *relcount; 52 asymbol **syms; 53 }; 54 55 struct extended_symbol_info 56 { 57 symbol_info *sinfo; 58 bfd_vma ssize; 59 elf_symbol_type *elfinfo; 60 /* FIXME: We should add more fields for Type, Line, Section. */ 61 }; 62 #define SYM_NAME(sym) (sym->sinfo->name) 63 #define SYM_VALUE(sym) (sym->sinfo->value) 64 #define SYM_TYPE(sym) (sym->sinfo->type) 65 #define SYM_STAB_NAME(sym) (sym->sinfo->stab_name) 66 #define SYM_STAB_DESC(sym) (sym->sinfo->stab_desc) 67 #define SYM_STAB_OTHER(sym) (sym->sinfo->stab_other) 68 #define SYM_SIZE(sym) \ 69 (sym->elfinfo ? sym->elfinfo->internal_elf_sym.st_size: sym->ssize) 70 71 static void usage (FILE *, int); 72 static void set_print_radix (char *); 73 static void set_output_format (char *); 74 static void display_archive (bfd *); 75 static bfd_boolean display_file (char *); 76 static void display_rel_file (bfd *, bfd *); 77 static long filter_symbols (bfd *, bfd_boolean, void *, long, unsigned int); 78 static long sort_symbols_by_size 79 (bfd *, bfd_boolean, void *, long, unsigned int, struct size_sym **); 80 static void print_symbols 81 (bfd *, bfd_boolean, void *, long, unsigned int, bfd *); 82 static void print_size_symbols 83 (bfd *, bfd_boolean, struct size_sym *, long, bfd *); 84 static void print_symname (const char *, const char *, bfd *); 85 static void print_symbol (bfd *, asymbol *, bfd_vma ssize, bfd *); 86 static void print_symdef_entry (bfd *); 87 88 /* The sorting functions. */ 89 static int numeric_forward (const void *, const void *); 90 static int numeric_reverse (const void *, const void *); 91 static int non_numeric_forward (const void *, const void *); 92 static int non_numeric_reverse (const void *, const void *); 93 static int size_forward1 (const void *, const void *); 94 static int size_forward2 (const void *, const void *); 95 96 /* The output formatting functions. */ 97 static void print_object_filename_bsd (char *); 98 static void print_object_filename_sysv (char *); 99 static void print_object_filename_posix (char *); 100 static void print_archive_filename_bsd (char *); 101 static void print_archive_filename_sysv (char *); 102 static void print_archive_filename_posix (char *); 103 static void print_archive_member_bsd (char *, const char *); 104 static void print_archive_member_sysv (char *, const char *); 105 static void print_archive_member_posix (char *, const char *); 106 static void print_symbol_filename_bsd (bfd *, bfd *); 107 static void print_symbol_filename_sysv (bfd *, bfd *); 108 static void print_symbol_filename_posix (bfd *, bfd *); 109 static void print_value (bfd *, bfd_vma); 110 static void print_symbol_info_bsd (struct extended_symbol_info *, bfd *); 111 static void print_symbol_info_sysv (struct extended_symbol_info *, bfd *); 112 static void print_symbol_info_posix (struct extended_symbol_info *, bfd *); 113 static void get_relocs (bfd *, asection *, void *); 114 static const char * get_symbol_type (unsigned int); 115 116 /* Support for different output formats. */ 117 struct output_fns 118 { 119 /* Print the name of an object file given on the command line. */ 120 void (*print_object_filename) (char *); 121 122 /* Print the name of an archive file given on the command line. */ 123 void (*print_archive_filename) (char *); 124 125 /* Print the name of an archive member file. */ 126 void (*print_archive_member) (char *, const char *); 127 128 /* Print the name of the file (and archive, if there is one) 129 containing a symbol. */ 130 void (*print_symbol_filename) (bfd *, bfd *); 131 132 /* Print a line of information about a symbol. */ 133 void (*print_symbol_info) (struct extended_symbol_info *, bfd *); 134 }; 135 136 static struct output_fns formats[] = 137 { 138 {print_object_filename_bsd, 139 print_archive_filename_bsd, 140 print_archive_member_bsd, 141 print_symbol_filename_bsd, 142 print_symbol_info_bsd}, 143 {print_object_filename_sysv, 144 print_archive_filename_sysv, 145 print_archive_member_sysv, 146 print_symbol_filename_sysv, 147 print_symbol_info_sysv}, 148 {print_object_filename_posix, 149 print_archive_filename_posix, 150 print_archive_member_posix, 151 print_symbol_filename_posix, 152 print_symbol_info_posix} 153 }; 154 155 /* Indices in `formats'. */ 156 #define FORMAT_BSD 0 157 #define FORMAT_SYSV 1 158 #define FORMAT_POSIX 2 159 #define FORMAT_DEFAULT FORMAT_BSD 160 161 /* The output format to use. */ 162 static struct output_fns *format = &formats[FORMAT_DEFAULT]; 163 164 /* Command options. */ 165 166 static int do_demangle = 0; /* Pretty print C++ symbol names. */ 167 static int external_only = 0; /* Print external symbols only. */ 168 static int defined_only = 0; /* Print defined symbols only. */ 169 static int no_sort = 0; /* Don't sort; print syms in order found. */ 170 static int print_debug_syms = 0;/* Print debugger-only symbols too. */ 171 static int print_armap = 0; /* Describe __.SYMDEF data in archive files. */ 172 static int print_size = 0; /* Print size of defined symbols. */ 173 static int reverse_sort = 0; /* Sort in downward(alpha or numeric) order. */ 174 static int sort_numerically = 0;/* Sort in numeric rather than alpha order. */ 175 static int sort_by_size = 0; /* Sort by size of symbol. */ 176 static int undefined_only = 0; /* Print undefined symbols only. */ 177 static int dynamic = 0; /* Print dynamic symbols. */ 178 static int show_version = 0; /* Show the version number. */ 179 static int show_stats = 0; /* Show statistics. */ 180 static int line_numbers = 0; /* Print line numbers for symbols. */ 181 182 /* When to print the names of files. Not mutually exclusive in SYSV format. */ 183 static int filename_per_file = 0; /* Once per file, on its own line. */ 184 static int filename_per_symbol = 0; /* Once per symbol, at start of line. */ 185 186 /* Print formats for printing a symbol value. */ 187 #ifndef BFD64 188 static char value_format[] = "%08lx"; 189 #else 190 #if BFD_HOST_64BIT_LONG 191 static char value_format[] = "%016lx"; 192 #else 193 /* We don't use value_format for this case. */ 194 #endif 195 #endif 196 #ifdef BFD64 197 static int print_width = 16; 198 #else 199 static int print_width = 8; 200 #endif 201 static int print_radix = 16; 202 /* Print formats for printing stab info. */ 203 static char other_format[] = "%02x"; 204 static char desc_format[] = "%04x"; 205 206 static char *target = NULL; 207 208 /* Used to cache the line numbers for a BFD. */ 209 static bfd *lineno_cache_bfd; 210 static bfd *lineno_cache_rel_bfd; 211 212 #define OPTION_TARGET 200 213 214 static struct option long_options[] = 215 { 216 {"debug-syms", no_argument, &print_debug_syms, 1}, 217 {"demangle", optional_argument, 0, 'C'}, 218 {"dynamic", no_argument, &dynamic, 1}, 219 {"extern-only", no_argument, &external_only, 1}, 220 {"format", required_argument, 0, 'f'}, 221 {"help", no_argument, 0, 'h'}, 222 {"line-numbers", no_argument, 0, 'l'}, 223 {"no-cplus", no_argument, &do_demangle, 0}, /* Linux compatibility. */ 224 {"no-demangle", no_argument, &do_demangle, 0}, 225 {"no-sort", no_argument, &no_sort, 1}, 226 {"numeric-sort", no_argument, &sort_numerically, 1}, 227 {"portability", no_argument, 0, 'P'}, 228 {"print-armap", no_argument, &print_armap, 1}, 229 {"print-file-name", no_argument, 0, 'o'}, 230 {"print-size", no_argument, 0, 'S'}, 231 {"radix", required_argument, 0, 't'}, 232 {"reverse-sort", no_argument, &reverse_sort, 1}, 233 {"size-sort", no_argument, &sort_by_size, 1}, 234 {"stats", no_argument, &show_stats, 1}, 235 {"target", required_argument, 0, OPTION_TARGET}, 236 {"defined-only", no_argument, &defined_only, 1}, 237 {"undefined-only", no_argument, &undefined_only, 1}, 238 {"version", no_argument, &show_version, 1}, 239 {0, no_argument, 0, 0} 240 }; 241 242 /* Some error-reporting functions. */ 243 244 static void 245 usage (FILE *stream, int status) 246 { 247 fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name); 248 fprintf (stream, _(" List symbols in [file(s)] (a.out by default).\n")); 249 fprintf (stream, _(" The options are:\n\ 250 -a, --debug-syms Display debugger-only symbols\n\ 251 -A, --print-file-name Print name of the input file before every symbol\n\ 252 -B Same as --format=bsd\n\ 253 -C, --demangle[=STYLE] Decode low-level symbol names into user-level names\n\ 254 The STYLE, if specified, can be `auto' (the default),\n\ 255 `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\ 256 or `gnat'\n\ 257 --no-demangle Do not demangle low-level symbol names\n\ 258 -D, --dynamic Display dynamic symbols instead of normal symbols\n\ 259 --defined-only Display only defined symbols\n\ 260 -e (ignored)\n\ 261 -f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd',\n\ 262 `sysv' or `posix'. The default is `bsd'\n\ 263 -g, --extern-only Display only external symbols\n\ 264 -l, --line-numbers Use debugging information to find a filename and\n\ 265 line number for each symbol\n\ 266 -n, --numeric-sort Sort symbols numerically by address\n\ 267 -o Same as -A\n\ 268 -p, --no-sort Do not sort the symbols\n\ 269 -P, --portability Same as --format=posix\n\ 270 -r, --reverse-sort Reverse the sense of the sort\n\ 271 -S, --print-size Print size of defined symbols\n\ 272 -s, --print-armap Include index for symbols from archive members\n\ 273 --size-sort Sort symbols by size\n\ 274 -t, --radix=RADIX Use RADIX for printing symbol values\n\ 275 --target=BFDNAME Specify the target object format as BFDNAME\n\ 276 -u, --undefined-only Display only undefined symbols\n\ 277 -X 32_64 (ignored)\n\ 278 -h, --help Display this information\n\ 279 -V, --version Display this program's version number\n\ 280 \n")); 281 list_supported_targets (program_name, stream); 282 if (status == 0) 283 fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO); 284 exit (status); 285 } 286 287 /* Set the radix for the symbol value and size according to RADIX. */ 288 289 static void 290 set_print_radix (char *radix) 291 { 292 switch (*radix) 293 { 294 case 'x': 295 break; 296 case 'd': 297 case 'o': 298 if (*radix == 'd') 299 print_radix = 10; 300 else 301 print_radix = 8; 302 #ifndef BFD64 303 value_format[4] = *radix; 304 #else 305 #if BFD_HOST_64BIT_LONG 306 value_format[5] = *radix; 307 #else 308 /* This case requires special handling for octal and decimal 309 printing. */ 310 #endif 311 #endif 312 other_format[3] = desc_format[3] = *radix; 313 break; 314 default: 315 fatal (_("%s: invalid radix"), radix); 316 } 317 } 318 319 static void 320 set_output_format (char *f) 321 { 322 int i; 323 324 switch (*f) 325 { 326 case 'b': 327 case 'B': 328 i = FORMAT_BSD; 329 break; 330 case 'p': 331 case 'P': 332 i = FORMAT_POSIX; 333 break; 334 case 's': 335 case 'S': 336 i = FORMAT_SYSV; 337 break; 338 default: 339 fatal (_("%s: invalid output format"), f); 340 } 341 format = &formats[i]; 342 } 343 344 int main (int, char **); 345 346 int 347 main (int argc, char **argv) 348 { 349 int c; 350 int retval; 351 352 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) 353 setlocale (LC_MESSAGES, ""); 354 #endif 355 #if defined (HAVE_SETLOCALE) 356 setlocale (LC_CTYPE, ""); 357 setlocale (LC_COLLATE, ""); 358 #endif 359 bindtextdomain (PACKAGE, LOCALEDIR); 360 textdomain (PACKAGE); 361 362 program_name = *argv; 363 xmalloc_set_program_name (program_name); 364 365 START_PROGRESS (program_name, 0); 366 367 expandargv (&argc, &argv); 368 369 bfd_init (); 370 set_default_bfd_target (); 371 372 while ((c = getopt_long (argc, argv, "aABCDef:gHhlnopPrSst:uvVvX:", 373 long_options, (int *) 0)) != EOF) 374 { 375 switch (c) 376 { 377 case 'a': 378 print_debug_syms = 1; 379 break; 380 case 'A': 381 case 'o': 382 filename_per_symbol = 1; 383 break; 384 case 'B': /* For MIPS compatibility. */ 385 set_output_format ("bsd"); 386 break; 387 case 'C': 388 do_demangle = 1; 389 if (optarg != NULL) 390 { 391 enum demangling_styles style; 392 393 style = cplus_demangle_name_to_style (optarg); 394 if (style == unknown_demangling) 395 fatal (_("unknown demangling style `%s'"), 396 optarg); 397 398 cplus_demangle_set_style (style); 399 } 400 break; 401 case 'D': 402 dynamic = 1; 403 break; 404 case 'e': 405 /* Ignored for HP/UX compatibility. */ 406 break; 407 case 'f': 408 set_output_format (optarg); 409 break; 410 case 'g': 411 external_only = 1; 412 break; 413 case 'H': 414 case 'h': 415 usage (stdout, 0); 416 case 'l': 417 line_numbers = 1; 418 break; 419 case 'n': 420 case 'v': 421 sort_numerically = 1; 422 break; 423 case 'p': 424 no_sort = 1; 425 break; 426 case 'P': 427 set_output_format ("posix"); 428 break; 429 case 'r': 430 reverse_sort = 1; 431 break; 432 case 's': 433 print_armap = 1; 434 break; 435 case 'S': 436 print_size = 1; 437 break; 438 case 't': 439 set_print_radix (optarg); 440 break; 441 case 'u': 442 undefined_only = 1; 443 break; 444 case 'V': 445 show_version = 1; 446 break; 447 case 'X': 448 /* Ignored for (partial) AIX compatibility. On AIX, the 449 argument has values 32, 64, or 32_64, and specifies that 450 only 32-bit, only 64-bit, or both kinds of objects should 451 be examined. The default is 32. So plain AIX nm on a 452 library archive with both kinds of objects will ignore 453 the 64-bit ones. For GNU nm, the default is and always 454 has been -X 32_64, and other options are not supported. */ 455 if (strcmp (optarg, "32_64") != 0) 456 fatal (_("Only -X 32_64 is supported")); 457 break; 458 459 case OPTION_TARGET: /* --target */ 460 target = optarg; 461 break; 462 463 case 0: /* A long option that just sets a flag. */ 464 break; 465 466 default: 467 usage (stderr, 1); 468 } 469 } 470 471 if (show_version) 472 print_version ("nm"); 473 474 if (sort_by_size && undefined_only) 475 { 476 non_fatal (_("Using the --size-sort and --undefined-only options together")); 477 non_fatal (_("will produce no output, since undefined symbols have no size.")); 478 return 0; 479 } 480 481 /* OK, all options now parsed. If no filename specified, do a.out. */ 482 if (optind == argc) 483 return !display_file ("a.out"); 484 485 retval = 0; 486 487 if (argc - optind > 1) 488 filename_per_file = 1; 489 490 /* We were given several filenames to do. */ 491 while (optind < argc) 492 { 493 PROGRESS (1); 494 if (!display_file (argv[optind++])) 495 retval++; 496 } 497 498 END_PROGRESS (program_name); 499 500 #ifdef HAVE_SBRK 501 if (show_stats) 502 { 503 char *lim = (char *) sbrk (0); 504 505 non_fatal (_("data size %ld"), (long) (lim - (char *) &environ)); 506 } 507 #endif 508 509 exit (retval); 510 return retval; 511 } 512 513 static const char * 514 get_symbol_type (unsigned int type) 515 { 516 static char buff [32]; 517 518 switch (type) 519 { 520 case STT_NOTYPE: return "NOTYPE"; 521 case STT_OBJECT: return "OBJECT"; 522 case STT_FUNC: return "FUNC"; 523 case STT_SECTION: return "SECTION"; 524 case STT_FILE: return "FILE"; 525 case STT_COMMON: return "COMMON"; 526 case STT_TLS: return "TLS"; 527 default: 528 if (type >= STT_LOPROC && type <= STT_HIPROC) 529 sprintf (buff, _("<processor specific>: %d"), type); 530 else if (type >= STT_LOOS && type <= STT_HIOS) 531 sprintf (buff, _("<OS specific>: %d"), type); 532 else 533 sprintf (buff, _("<unknown>: %d"), type); 534 return buff; 535 } 536 } 537 538 static void 539 display_archive (bfd *file) 540 { 541 bfd *arfile = NULL; 542 bfd *last_arfile = NULL; 543 char **matching; 544 545 (*format->print_archive_filename) (bfd_get_filename (file)); 546 547 if (print_armap) 548 print_symdef_entry (file); 549 550 for (;;) 551 { 552 PROGRESS (1); 553 554 arfile = bfd_openr_next_archived_file (file, arfile); 555 556 if (arfile == NULL) 557 { 558 if (bfd_get_error () != bfd_error_no_more_archived_files) 559 bfd_fatal (bfd_get_filename (file)); 560 break; 561 } 562 563 if (bfd_check_format_matches (arfile, bfd_object, &matching)) 564 { 565 char buf[30]; 566 567 bfd_sprintf_vma (arfile, buf, (bfd_vma) -1); 568 print_width = strlen (buf); 569 (*format->print_archive_member) (bfd_get_filename (file), 570 bfd_get_filename (arfile)); 571 display_rel_file (arfile, file); 572 } 573 else 574 { 575 bfd_nonfatal (bfd_get_filename (arfile)); 576 if (bfd_get_error () == bfd_error_file_ambiguously_recognized) 577 { 578 list_matching_formats (matching); 579 free (matching); 580 } 581 } 582 583 if (last_arfile != NULL) 584 { 585 bfd_close (last_arfile); 586 lineno_cache_bfd = NULL; 587 lineno_cache_rel_bfd = NULL; 588 } 589 last_arfile = arfile; 590 } 591 592 if (last_arfile != NULL) 593 { 594 bfd_close (last_arfile); 595 lineno_cache_bfd = NULL; 596 lineno_cache_rel_bfd = NULL; 597 } 598 } 599 600 static bfd_boolean 601 display_file (char *filename) 602 { 603 bfd_boolean retval = TRUE; 604 bfd *file; 605 char **matching; 606 607 if (get_file_size (filename) < 1) 608 return FALSE; 609 610 file = bfd_openr (filename, target); 611 if (file == NULL) 612 { 613 bfd_nonfatal (filename); 614 return FALSE; 615 } 616 617 if (bfd_check_format (file, bfd_archive)) 618 { 619 display_archive (file); 620 } 621 else if (bfd_check_format_matches (file, bfd_object, &matching)) 622 { 623 char buf[30]; 624 625 bfd_sprintf_vma (file, buf, (bfd_vma) -1); 626 print_width = strlen (buf); 627 (*format->print_object_filename) (filename); 628 display_rel_file (file, NULL); 629 } 630 else 631 { 632 bfd_nonfatal (filename); 633 if (bfd_get_error () == bfd_error_file_ambiguously_recognized) 634 { 635 list_matching_formats (matching); 636 free (matching); 637 } 638 retval = FALSE; 639 } 640 641 if (!bfd_close (file)) 642 bfd_fatal (filename); 643 644 lineno_cache_bfd = NULL; 645 lineno_cache_rel_bfd = NULL; 646 647 return retval; 648 } 649 650 /* These globals are used to pass information into the sorting 651 routines. */ 652 static bfd *sort_bfd; 653 static bfd_boolean sort_dynamic; 654 static asymbol *sort_x; 655 static asymbol *sort_y; 656 657 /* Symbol-sorting predicates */ 658 #define valueof(x) ((x)->section->vma + (x)->value) 659 660 /* Numeric sorts. Undefined symbols are always considered "less than" 661 defined symbols with zero values. Common symbols are not treated 662 specially -- i.e., their sizes are used as their "values". */ 663 664 static int 665 numeric_forward (const void *P_x, const void *P_y) 666 { 667 asymbol *x, *y; 668 asection *xs, *ys; 669 670 x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x); 671 y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y); 672 if (x == NULL || y == NULL) 673 bfd_fatal (bfd_get_filename (sort_bfd)); 674 675 xs = bfd_get_section (x); 676 ys = bfd_get_section (y); 677 678 if (bfd_is_und_section (xs)) 679 { 680 if (! bfd_is_und_section (ys)) 681 return -1; 682 } 683 else if (bfd_is_und_section (ys)) 684 return 1; 685 else if (valueof (x) != valueof (y)) 686 return valueof (x) < valueof (y) ? -1 : 1; 687 688 return non_numeric_forward (P_x, P_y); 689 } 690 691 static int 692 numeric_reverse (const void *x, const void *y) 693 { 694 return - numeric_forward (x, y); 695 } 696 697 static int 698 non_numeric_forward (const void *P_x, const void *P_y) 699 { 700 asymbol *x, *y; 701 const char *xn, *yn; 702 703 x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x); 704 y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y); 705 if (x == NULL || y == NULL) 706 bfd_fatal (bfd_get_filename (sort_bfd)); 707 708 xn = bfd_asymbol_name (x); 709 yn = bfd_asymbol_name (y); 710 711 if (yn == NULL) 712 return xn != NULL; 713 if (xn == NULL) 714 return -1; 715 716 #ifdef HAVE_STRCOLL 717 /* Solaris 2.5 has a bug in strcoll. 718 strcoll returns invalid values when confronted with empty strings. */ 719 if (*yn == '\0') 720 return *xn != '\0'; 721 if (*xn == '\0') 722 return -1; 723 724 return strcoll (xn, yn); 725 #else 726 return strcmp (xn, yn); 727 #endif 728 } 729 730 static int 731 non_numeric_reverse (const void *x, const void *y) 732 { 733 return - non_numeric_forward (x, y); 734 } 735 736 static int (*(sorters[2][2])) (const void *, const void *) = 737 { 738 { non_numeric_forward, non_numeric_reverse }, 739 { numeric_forward, numeric_reverse } 740 }; 741 742 /* This sort routine is used by sort_symbols_by_size. It is similar 743 to numeric_forward, but when symbols have the same value it sorts 744 by section VMA. This simplifies the sort_symbols_by_size code 745 which handles symbols at the end of sections. Also, this routine 746 tries to sort file names before other symbols with the same value. 747 That will make the file name have a zero size, which will make 748 sort_symbols_by_size choose the non file name symbol, leading to 749 more meaningful output. For similar reasons, this code sorts 750 gnu_compiled_* and gcc2_compiled before other symbols with the same 751 value. */ 752 753 static int 754 size_forward1 (const void *P_x, const void *P_y) 755 { 756 asymbol *x, *y; 757 asection *xs, *ys; 758 const char *xn, *yn; 759 size_t xnl, ynl; 760 int xf, yf; 761 762 x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x); 763 y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y); 764 if (x == NULL || y == NULL) 765 bfd_fatal (bfd_get_filename (sort_bfd)); 766 767 xs = bfd_get_section (x); 768 ys = bfd_get_section (y); 769 770 if (bfd_is_und_section (xs)) 771 abort (); 772 if (bfd_is_und_section (ys)) 773 abort (); 774 775 if (valueof (x) != valueof (y)) 776 return valueof (x) < valueof (y) ? -1 : 1; 777 778 if (xs->vma != ys->vma) 779 return xs->vma < ys->vma ? -1 : 1; 780 781 xn = bfd_asymbol_name (x); 782 yn = bfd_asymbol_name (y); 783 xnl = strlen (xn); 784 ynl = strlen (yn); 785 786 /* The symbols gnu_compiled and gcc2_compiled convey even less 787 information than the file name, so sort them out first. */ 788 789 xf = (strstr (xn, "gnu_compiled") != NULL 790 || strstr (xn, "gcc2_compiled") != NULL); 791 yf = (strstr (yn, "gnu_compiled") != NULL 792 || strstr (yn, "gcc2_compiled") != NULL); 793 794 if (xf && ! yf) 795 return -1; 796 if (! xf && yf) 797 return 1; 798 799 /* We use a heuristic for the file name. It may not work on non 800 Unix systems, but it doesn't really matter; the only difference 801 is precisely which symbol names get printed. */ 802 803 #define file_symbol(s, sn, snl) \ 804 (((s)->flags & BSF_FILE) != 0 \ 805 || ((sn)[(snl) - 2] == '.' \ 806 && ((sn)[(snl) - 1] == 'o' \ 807 || (sn)[(snl) - 1] == 'a'))) 808 809 xf = file_symbol (x, xn, xnl); 810 yf = file_symbol (y, yn, ynl); 811 812 if (xf && ! yf) 813 return -1; 814 if (! xf && yf) 815 return 1; 816 817 return non_numeric_forward (P_x, P_y); 818 } 819 820 /* This sort routine is used by sort_symbols_by_size. It is sorting 821 an array of size_sym structures into size order. */ 822 823 static int 824 size_forward2 (const void *P_x, const void *P_y) 825 { 826 const struct size_sym *x = (const struct size_sym *) P_x; 827 const struct size_sym *y = (const struct size_sym *) P_y; 828 829 if (x->size < y->size) 830 return reverse_sort ? 1 : -1; 831 else if (x->size > y->size) 832 return reverse_sort ? -1 : 1; 833 else 834 return sorters[0][reverse_sort] (x->minisym, y->minisym); 835 } 836 837 /* Sort the symbols by size. ELF provides a size but for other formats 838 we have to make a guess by assuming that the difference between the 839 address of a symbol and the address of the next higher symbol is the 840 size. */ 841 842 static long 843 sort_symbols_by_size (bfd *abfd, bfd_boolean dynamic, void *minisyms, 844 long symcount, unsigned int size, 845 struct size_sym **symsizesp) 846 { 847 struct size_sym *symsizes; 848 bfd_byte *from, *fromend; 849 asymbol *sym = NULL; 850 asymbol *store_sym, *store_next; 851 852 qsort (minisyms, symcount, size, size_forward1); 853 854 /* We are going to return a special set of symbols and sizes to 855 print. */ 856 symsizes = (struct size_sym *) xmalloc (symcount * sizeof (struct size_sym)); 857 *symsizesp = symsizes; 858 859 /* Note that filter_symbols has already removed all absolute and 860 undefined symbols. Here we remove all symbols whose size winds 861 up as zero. */ 862 from = (bfd_byte *) minisyms; 863 fromend = from + symcount * size; 864 865 store_sym = sort_x; 866 store_next = sort_y; 867 868 if (from < fromend) 869 { 870 sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const void *) from, 871 store_sym); 872 if (sym == NULL) 873 bfd_fatal (bfd_get_filename (abfd)); 874 } 875 876 for (; from < fromend; from += size) 877 { 878 asymbol *next; 879 asection *sec; 880 bfd_vma sz; 881 asymbol *temp; 882 883 if (from + size < fromend) 884 { 885 next = bfd_minisymbol_to_symbol (abfd, 886 dynamic, 887 (const void *) (from + size), 888 store_next); 889 if (next == NULL) 890 bfd_fatal (bfd_get_filename (abfd)); 891 } 892 else 893 next = NULL; 894 895 sec = bfd_get_section (sym); 896 897 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) 898 sz = ((elf_symbol_type *) sym)->internal_elf_sym.st_size; 899 else if (bfd_is_com_section (sec)) 900 sz = sym->value; 901 else 902 { 903 if (from + size < fromend 904 && sec == bfd_get_section (next)) 905 sz = valueof (next) - valueof (sym); 906 else 907 sz = (bfd_get_section_vma (abfd, sec) 908 + bfd_section_size (abfd, sec) 909 - valueof (sym)); 910 } 911 912 if (sz != 0) 913 { 914 symsizes->minisym = (const void *) from; 915 symsizes->size = sz; 916 ++symsizes; 917 } 918 919 sym = next; 920 921 temp = store_sym; 922 store_sym = store_next; 923 store_next = temp; 924 } 925 926 symcount = symsizes - *symsizesp; 927 928 /* We must now sort again by size. */ 929 qsort ((void *) *symsizesp, symcount, sizeof (struct size_sym), size_forward2); 930 931 return symcount; 932 } 933 934 /* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. */ 935 936 static void 937 display_rel_file (bfd *abfd, bfd *archive_bfd) 938 { 939 long symcount; 940 void *minisyms; 941 unsigned int size; 942 struct size_sym *symsizes; 943 944 if (! dynamic) 945 { 946 if (!(bfd_get_file_flags (abfd) & HAS_SYMS)) 947 { 948 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd)); 949 return; 950 } 951 } 952 953 symcount = bfd_read_minisymbols (abfd, dynamic, &minisyms, &size); 954 if (symcount < 0) 955 bfd_fatal (bfd_get_filename (abfd)); 956 957 if (symcount == 0) 958 { 959 non_fatal (_("%s: no symbols"), bfd_get_filename (abfd)); 960 return; 961 } 962 963 /* Discard the symbols we don't want to print. 964 It's OK to do this in place; we'll free the storage anyway 965 (after printing). */ 966 967 symcount = filter_symbols (abfd, dynamic, minisyms, symcount, size); 968 969 symsizes = NULL; 970 if (! no_sort) 971 { 972 sort_bfd = abfd; 973 sort_dynamic = dynamic; 974 sort_x = bfd_make_empty_symbol (abfd); 975 sort_y = bfd_make_empty_symbol (abfd); 976 if (sort_x == NULL || sort_y == NULL) 977 bfd_fatal (bfd_get_filename (abfd)); 978 979 if (! sort_by_size) 980 qsort (minisyms, symcount, size, 981 sorters[sort_numerically][reverse_sort]); 982 else 983 symcount = sort_symbols_by_size (abfd, dynamic, minisyms, symcount, 984 size, &symsizes); 985 } 986 987 if (! sort_by_size) 988 print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd); 989 else 990 print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd); 991 992 free (minisyms); 993 } 994 995 /* Choose which symbol entries to print; 996 compact them downward to get rid of the rest. 997 Return the number of symbols to be printed. */ 998 999 static long 1000 filter_symbols (bfd *abfd, bfd_boolean dynamic, void *minisyms, 1001 long symcount, unsigned int size) 1002 { 1003 bfd_byte *from, *fromend, *to; 1004 asymbol *store; 1005 1006 store = bfd_make_empty_symbol (abfd); 1007 if (store == NULL) 1008 bfd_fatal (bfd_get_filename (abfd)); 1009 1010 from = (bfd_byte *) minisyms; 1011 fromend = from + symcount * size; 1012 to = (bfd_byte *) minisyms; 1013 1014 for (; from < fromend; from += size) 1015 { 1016 int keep = 0; 1017 asymbol *sym; 1018 1019 PROGRESS (1); 1020 1021 sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const void *) from, store); 1022 if (sym == NULL) 1023 bfd_fatal (bfd_get_filename (abfd)); 1024 1025 if (undefined_only) 1026 keep = bfd_is_und_section (sym->section); 1027 else if (external_only) 1028 keep = ((sym->flags & BSF_GLOBAL) != 0 1029 || (sym->flags & BSF_WEAK) != 0 1030 || bfd_is_und_section (sym->section) 1031 || bfd_is_com_section (sym->section)); 1032 else 1033 keep = 1; 1034 1035 if (keep 1036 && ! print_debug_syms 1037 && (sym->flags & BSF_DEBUGGING) != 0) 1038 keep = 0; 1039 1040 if (keep 1041 && sort_by_size 1042 && (bfd_is_abs_section (sym->section) 1043 || bfd_is_und_section (sym->section))) 1044 keep = 0; 1045 1046 if (keep 1047 && defined_only) 1048 { 1049 if (bfd_is_und_section (sym->section)) 1050 keep = 0; 1051 } 1052 1053 if (keep) 1054 { 1055 memcpy (to, from, size); 1056 to += size; 1057 } 1058 } 1059 1060 return (to - (bfd_byte *) minisyms) / size; 1061 } 1062 1063 /* Print symbol name NAME, read from ABFD, with printf format FORMAT, 1064 demangling it if requested. */ 1065 1066 static void 1067 print_symname (const char *format, const char *name, bfd *abfd) 1068 { 1069 if (do_demangle && *name) 1070 { 1071 char *res = demangle (abfd, name); 1072 1073 printf (format, res); 1074 free (res); 1075 return; 1076 } 1077 1078 printf (format, name); 1079 } 1080 1081 /* Print the symbols. If ARCHIVE_BFD is non-NULL, it is the archive 1082 containing ABFD. */ 1083 1084 static void 1085 print_symbols (bfd *abfd, bfd_boolean dynamic, void *minisyms, long symcount, 1086 unsigned int size, bfd *archive_bfd) 1087 { 1088 asymbol *store; 1089 bfd_byte *from, *fromend; 1090 1091 store = bfd_make_empty_symbol (abfd); 1092 if (store == NULL) 1093 bfd_fatal (bfd_get_filename (abfd)); 1094 1095 from = (bfd_byte *) minisyms; 1096 fromend = from + symcount * size; 1097 for (; from < fromend; from += size) 1098 { 1099 asymbol *sym; 1100 1101 sym = bfd_minisymbol_to_symbol (abfd, dynamic, from, store); 1102 if (sym == NULL) 1103 bfd_fatal (bfd_get_filename (abfd)); 1104 1105 print_symbol (abfd, sym, (bfd_vma) 0, archive_bfd); 1106 } 1107 } 1108 1109 /* Print the symbols when sorting by size. */ 1110 1111 static void 1112 print_size_symbols (bfd *abfd, bfd_boolean dynamic, 1113 struct size_sym *symsizes, long symcount, 1114 bfd *archive_bfd) 1115 { 1116 asymbol *store; 1117 struct size_sym *from, *fromend; 1118 1119 store = bfd_make_empty_symbol (abfd); 1120 if (store == NULL) 1121 bfd_fatal (bfd_get_filename (abfd)); 1122 1123 from = symsizes; 1124 fromend = from + symcount; 1125 for (; from < fromend; from++) 1126 { 1127 asymbol *sym; 1128 bfd_vma ssize; 1129 1130 sym = bfd_minisymbol_to_symbol (abfd, dynamic, from->minisym, store); 1131 if (sym == NULL) 1132 bfd_fatal (bfd_get_filename (abfd)); 1133 1134 /* For elf we have already computed the correct symbol size. */ 1135 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) 1136 ssize = from->size; 1137 else 1138 ssize = from->size - bfd_section_vma (abfd, bfd_get_section (sym)); 1139 1140 print_symbol (abfd, sym, ssize, archive_bfd); 1141 } 1142 } 1143 1144 /* Print a single symbol. */ 1145 1146 static void 1147 print_symbol (bfd *abfd, asymbol *sym, bfd_vma ssize, bfd *archive_bfd) 1148 { 1149 symbol_info syminfo; 1150 struct extended_symbol_info info; 1151 1152 PROGRESS (1); 1153 1154 (*format->print_symbol_filename) (archive_bfd, abfd); 1155 1156 bfd_get_symbol_info (abfd, sym, &syminfo); 1157 info.sinfo = &syminfo; 1158 info.ssize = ssize; 1159 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) 1160 info.elfinfo = (elf_symbol_type *) sym; 1161 else 1162 info.elfinfo = NULL; 1163 (*format->print_symbol_info) (&info, abfd); 1164 1165 if (line_numbers) 1166 { 1167 static asymbol **syms; 1168 static long symcount; 1169 const char *filename, *functionname; 1170 unsigned int lineno; 1171 1172 /* We need to get the canonical symbols in order to call 1173 bfd_find_nearest_line. This is inefficient, but, then, you 1174 don't have to use --line-numbers. */ 1175 if (abfd != lineno_cache_bfd && syms != NULL) 1176 { 1177 free (syms); 1178 syms = NULL; 1179 } 1180 if (syms == NULL) 1181 { 1182 long symsize; 1183 1184 symsize = bfd_get_symtab_upper_bound (abfd); 1185 if (symsize < 0) 1186 bfd_fatal (bfd_get_filename (abfd)); 1187 syms = (asymbol **) xmalloc (symsize); 1188 symcount = bfd_canonicalize_symtab (abfd, syms); 1189 if (symcount < 0) 1190 bfd_fatal (bfd_get_filename (abfd)); 1191 lineno_cache_bfd = abfd; 1192 } 1193 1194 if (bfd_is_und_section (bfd_get_section (sym))) 1195 { 1196 static asection **secs; 1197 static arelent ***relocs; 1198 static long *relcount; 1199 static unsigned int seccount; 1200 unsigned int i; 1201 const char *symname; 1202 1203 /* For an undefined symbol, we try to find a reloc for the 1204 symbol, and print the line number of the reloc. */ 1205 if (abfd != lineno_cache_rel_bfd && relocs != NULL) 1206 { 1207 for (i = 0; i < seccount; i++) 1208 if (relocs[i] != NULL) 1209 free (relocs[i]); 1210 free (secs); 1211 free (relocs); 1212 free (relcount); 1213 secs = NULL; 1214 relocs = NULL; 1215 relcount = NULL; 1216 } 1217 1218 if (relocs == NULL) 1219 { 1220 struct get_relocs_info info; 1221 1222 seccount = bfd_count_sections (abfd); 1223 1224 secs = (asection **) xmalloc (seccount * sizeof *secs); 1225 relocs = (arelent ***) xmalloc (seccount * sizeof *relocs); 1226 relcount = (long *) xmalloc (seccount * sizeof *relcount); 1227 1228 info.secs = secs; 1229 info.relocs = relocs; 1230 info.relcount = relcount; 1231 info.syms = syms; 1232 bfd_map_over_sections (abfd, get_relocs, (void *) &info); 1233 lineno_cache_rel_bfd = abfd; 1234 } 1235 1236 symname = bfd_asymbol_name (sym); 1237 for (i = 0; i < seccount; i++) 1238 { 1239 long j; 1240 1241 for (j = 0; j < relcount[i]; j++) 1242 { 1243 arelent *r; 1244 1245 r = relocs[i][j]; 1246 if (r->sym_ptr_ptr != NULL 1247 && (*r->sym_ptr_ptr)->section == sym->section 1248 && (*r->sym_ptr_ptr)->value == sym->value 1249 && strcmp (symname, 1250 bfd_asymbol_name (*r->sym_ptr_ptr)) == 0 1251 && bfd_find_nearest_line (abfd, secs[i], syms, 1252 r->address, &filename, 1253 &functionname, &lineno) 1254 && filename != NULL) 1255 { 1256 /* We only print the first one we find. */ 1257 printf ("\t%s:%u", filename, lineno); 1258 i = seccount; 1259 break; 1260 } 1261 } 1262 } 1263 } 1264 else if (bfd_get_section (sym)->owner == abfd) 1265 { 1266 if (bfd_find_nearest_line (abfd, bfd_get_section (sym), syms, 1267 sym->value, &filename, &functionname, 1268 &lineno) 1269 && filename != NULL 1270 && lineno != 0) 1271 { 1272 printf ("\t%s:%u", filename, lineno); 1273 } 1274 } 1275 } 1276 1277 putchar ('\n'); 1278 } 1279 1280 /* The following 3 groups of functions are called unconditionally, 1281 once at the start of processing each file of the appropriate type. 1282 They should check `filename_per_file' and `filename_per_symbol', 1283 as appropriate for their output format, to determine whether to 1284 print anything. */ 1285 1286 /* Print the name of an object file given on the command line. */ 1287 1288 static void 1289 print_object_filename_bsd (char *filename) 1290 { 1291 if (filename_per_file && !filename_per_symbol) 1292 printf ("\n%s:\n", filename); 1293 } 1294 1295 static void 1296 print_object_filename_sysv (char *filename) 1297 { 1298 if (undefined_only) 1299 printf (_("\n\nUndefined symbols from %s:\n\n"), filename); 1300 else 1301 printf (_("\n\nSymbols from %s:\n\n"), filename); 1302 if (print_width == 8) 1303 printf (_("\ 1304 Name Value Class Type Size Line Section\n\n")); 1305 else 1306 printf (_("\ 1307 Name Value Class Type Size Line Section\n\n")); 1308 } 1309 1310 static void 1311 print_object_filename_posix (char *filename) 1312 { 1313 if (filename_per_file && !filename_per_symbol) 1314 printf ("%s:\n", filename); 1315 } 1316 1317 /* Print the name of an archive file given on the command line. */ 1318 1319 static void 1320 print_archive_filename_bsd (char *filename) 1321 { 1322 if (filename_per_file) 1323 printf ("\n%s:\n", filename); 1324 } 1325 1326 static void 1327 print_archive_filename_sysv (char *filename ATTRIBUTE_UNUSED) 1328 { 1329 } 1330 1331 static void 1332 print_archive_filename_posix (char *filename ATTRIBUTE_UNUSED) 1333 { 1334 } 1335 1336 /* Print the name of an archive member file. */ 1337 1338 static void 1339 print_archive_member_bsd (char *archive ATTRIBUTE_UNUSED, 1340 const char *filename) 1341 { 1342 if (!filename_per_symbol) 1343 printf ("\n%s:\n", filename); 1344 } 1345 1346 static void 1347 print_archive_member_sysv (char *archive, const char *filename) 1348 { 1349 if (undefined_only) 1350 printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive, filename); 1351 else 1352 printf (_("\n\nSymbols from %s[%s]:\n\n"), archive, filename); 1353 if (print_width == 8) 1354 printf (_("\ 1355 Name Value Class Type Size Line Section\n\n")); 1356 else 1357 printf (_("\ 1358 Name Value Class Type Size Line Section\n\n")); 1359 } 1360 1361 static void 1362 print_archive_member_posix (char *archive, const char *filename) 1363 { 1364 if (!filename_per_symbol) 1365 printf ("%s[%s]:\n", archive, filename); 1366 } 1367 1368 /* Print the name of the file (and archive, if there is one) 1369 containing a symbol. */ 1370 1371 static void 1372 print_symbol_filename_bsd (bfd *archive_bfd, bfd *abfd) 1373 { 1374 if (filename_per_symbol) 1375 { 1376 if (archive_bfd) 1377 printf ("%s:", bfd_get_filename (archive_bfd)); 1378 printf ("%s:", bfd_get_filename (abfd)); 1379 } 1380 } 1381 1382 static void 1383 print_symbol_filename_sysv (bfd *archive_bfd, bfd *abfd) 1384 { 1385 if (filename_per_symbol) 1386 { 1387 if (archive_bfd) 1388 printf ("%s:", bfd_get_filename (archive_bfd)); 1389 printf ("%s:", bfd_get_filename (abfd)); 1390 } 1391 } 1392 1393 static void 1394 print_symbol_filename_posix (bfd *archive_bfd, bfd *abfd) 1395 { 1396 if (filename_per_symbol) 1397 { 1398 if (archive_bfd) 1399 printf ("%s[%s]: ", bfd_get_filename (archive_bfd), 1400 bfd_get_filename (abfd)); 1401 else 1402 printf ("%s: ", bfd_get_filename (abfd)); 1403 } 1404 } 1405 1406 /* Print a symbol value. */ 1407 1408 static void 1409 print_value (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma val) 1410 { 1411 #if ! defined (BFD64) || BFD_HOST_64BIT_LONG 1412 printf (value_format, val); 1413 #else 1414 /* We have a 64 bit value to print, but the host is only 32 bit. */ 1415 if (print_radix == 16) 1416 bfd_fprintf_vma (abfd, stdout, val); 1417 else 1418 { 1419 char buf[30]; 1420 char *s; 1421 1422 s = buf + sizeof buf; 1423 *--s = '\0'; 1424 while (val > 0) 1425 { 1426 *--s = (val % print_radix) + '0'; 1427 val /= print_radix; 1428 } 1429 while ((buf + sizeof buf - 1) - s < 16) 1430 *--s = '0'; 1431 printf ("%s", s); 1432 } 1433 #endif 1434 } 1435 1436 /* Print a line of information about a symbol. */ 1437 1438 static void 1439 print_symbol_info_bsd (struct extended_symbol_info *info, bfd *abfd) 1440 { 1441 if (bfd_is_undefined_symclass (SYM_TYPE (info))) 1442 { 1443 if (print_width == 16) 1444 printf (" "); 1445 printf (" "); 1446 } 1447 else 1448 { 1449 /* Normally we print the value of the symbol. If we are printing the 1450 size or sorting by size then we print its size, except for the 1451 (weird) special case where both flags are defined, in which case we 1452 print both values. This conforms to documented behaviour. */ 1453 if (sort_by_size && !print_size) 1454 print_value (abfd, SYM_SIZE (info)); 1455 else 1456 print_value (abfd, SYM_VALUE (info)); 1457 1458 if (print_size && SYM_SIZE (info)) 1459 { 1460 printf (" "); 1461 print_value (abfd, SYM_SIZE (info)); 1462 } 1463 } 1464 1465 printf (" %c", SYM_TYPE (info)); 1466 1467 if (SYM_TYPE (info) == '-') 1468 { 1469 /* A stab. */ 1470 printf (" "); 1471 printf (other_format, SYM_STAB_OTHER (info)); 1472 printf (" "); 1473 printf (desc_format, SYM_STAB_DESC (info)); 1474 printf (" %5s", SYM_STAB_NAME (info)); 1475 } 1476 print_symname (" %s", SYM_NAME (info), abfd); 1477 } 1478 1479 static void 1480 print_symbol_info_sysv (struct extended_symbol_info *info, bfd *abfd) 1481 { 1482 print_symname ("%-20s|", SYM_NAME (info), abfd); 1483 1484 if (bfd_is_undefined_symclass (SYM_TYPE (info))) 1485 { 1486 if (print_width == 8) 1487 printf (" "); 1488 else 1489 printf (" "); 1490 } 1491 else 1492 print_value (abfd, SYM_VALUE (info)); 1493 1494 printf ("| %c |", SYM_TYPE (info)); 1495 1496 if (SYM_TYPE (info) == '-') 1497 { 1498 /* A stab. */ 1499 printf ("%18s| ", SYM_STAB_NAME (info)); /* (C) Type. */ 1500 printf (desc_format, SYM_STAB_DESC (info)); /* Size. */ 1501 printf ("| |"); /* Line, Section. */ 1502 } 1503 else 1504 { 1505 /* Type, Size, Line, Section */ 1506 if (info->elfinfo) 1507 printf ("%18s|", 1508 get_symbol_type (ELF_ST_TYPE (info->elfinfo->internal_elf_sym.st_info))); 1509 else 1510 printf (" |"); 1511 1512 if (SYM_SIZE (info)) 1513 print_value (abfd, SYM_SIZE (info)); 1514 else 1515 { 1516 if (print_width == 8) 1517 printf (" "); 1518 else 1519 printf (" "); 1520 } 1521 1522 if (info->elfinfo) 1523 printf("| |%s", info->elfinfo->symbol.section->name); 1524 else 1525 printf("| |"); 1526 } 1527 } 1528 1529 static void 1530 print_symbol_info_posix (struct extended_symbol_info *info, bfd *abfd) 1531 { 1532 print_symname ("%s ", SYM_NAME (info), abfd); 1533 printf ("%c ", SYM_TYPE (info)); 1534 1535 if (bfd_is_undefined_symclass (SYM_TYPE (info))) 1536 printf (" "); 1537 else 1538 { 1539 print_value (abfd, SYM_VALUE (info)); 1540 printf (" "); 1541 if (SYM_SIZE (info)) 1542 print_value (abfd, SYM_SIZE (info)); 1543 } 1544 } 1545 1546 static void 1547 print_symdef_entry (bfd *abfd) 1548 { 1549 symindex idx = BFD_NO_MORE_SYMBOLS; 1550 carsym *thesym; 1551 bfd_boolean everprinted = FALSE; 1552 1553 for (idx = bfd_get_next_mapent (abfd, idx, &thesym); 1554 idx != BFD_NO_MORE_SYMBOLS; 1555 idx = bfd_get_next_mapent (abfd, idx, &thesym)) 1556 { 1557 bfd *elt; 1558 if (!everprinted) 1559 { 1560 printf (_("\nArchive index:\n")); 1561 everprinted = TRUE; 1562 } 1563 elt = bfd_get_elt_at_index (abfd, idx); 1564 if (elt == NULL) 1565 bfd_fatal ("bfd_get_elt_at_index"); 1566 if (thesym->name != (char *) NULL) 1567 { 1568 print_symname ("%s", thesym->name, abfd); 1569 printf (" in %s\n", bfd_get_filename (elt)); 1570 } 1571 } 1572 } 1573 1574 /* This function is used to get the relocs for a particular section. 1575 It is called via bfd_map_over_sections. */ 1576 1577 static void 1578 get_relocs (bfd *abfd, asection *sec, void *dataarg) 1579 { 1580 struct get_relocs_info *data = (struct get_relocs_info *) dataarg; 1581 1582 *data->secs = sec; 1583 1584 if ((sec->flags & SEC_RELOC) == 0) 1585 { 1586 *data->relocs = NULL; 1587 *data->relcount = 0; 1588 } 1589 else 1590 { 1591 long relsize; 1592 1593 relsize = bfd_get_reloc_upper_bound (abfd, sec); 1594 if (relsize < 0) 1595 bfd_fatal (bfd_get_filename (abfd)); 1596 1597 *data->relocs = (arelent **) xmalloc (relsize); 1598 *data->relcount = bfd_canonicalize_reloc (abfd, sec, *data->relocs, 1599 data->syms); 1600 if (*data->relcount < 0) 1601 bfd_fatal (bfd_get_filename (abfd)); 1602 } 1603 1604 ++data->secs; 1605 ++data->relocs; 1606 ++data->relcount; 1607 } 1608