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