size.c revision 104834
133965Sjdp/* size.c -- report size of various sections of an executable file. 289857Sobrien Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 360484Sobrien Free Software Foundation, Inc. 433965Sjdp 589857Sobrien This file is part of GNU Binutils. 633965Sjdp 789857Sobrien This program is free software; you can redistribute it and/or modify 889857Sobrien it under the terms of the GNU General Public License as published by 989857Sobrien the Free Software Foundation; either version 2 of the License, or 1089857Sobrien (at your option) any later version. 1133965Sjdp 1289857Sobrien This program is distributed in the hope that it will be useful, 1389857Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1489857Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1589857Sobrien GNU General Public License for more details. 1633965Sjdp 1789857Sobrien You should have received a copy of the GNU General Public License 1889857Sobrien along with this program; if not, write to the Free Software 1989857Sobrien Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 2033965Sjdp 2133965Sjdp/* Extensions/incompatibilities: 2233965Sjdp o - BSD output has filenames at the end. 2333965Sjdp o - BSD output can appear in different radicies. 2433965Sjdp o - SysV output has less redundant whitespace. Filename comes at end. 2533965Sjdp o - SysV output doesn't show VMA which is always the same as the PMA. 2633965Sjdp o - We also handle core files. 2733965Sjdp o - We also handle archives. 2833965Sjdp If you write shell scripts which manipulate this info then you may be 2989857Sobrien out of luck; there's no --compatibility or --pedantic option. */ 3033965Sjdp 3133965Sjdp#include "bfd.h" 3233965Sjdp#include "bucomm.h" 3333965Sjdp#include "libiberty.h" 3491041Sobrien#include "getopt.h" 3533965Sjdp 3633965Sjdp#ifndef BSD_DEFAULT 3733965Sjdp#define BSD_DEFAULT 1 3833965Sjdp#endif 3933965Sjdp 4033965Sjdp/* Program options. */ 4133965Sjdp 4233965Sjdpenum 4333965Sjdp { 4433965Sjdp decimal, octal, hex 4589857Sobrien } 4689857Sobrienradix = decimal; 4789857Sobrien 4833965Sjdpint berkeley_format = BSD_DEFAULT; /* 0 means use AT&T-style output. */ 4933965Sjdpint show_version = 0; 5033965Sjdpint show_help = 0; 5189857Sobrienint show_totals = 0; 5233965Sjdp 5389857Sobrienstatic bfd_size_type total_bsssize; 5489857Sobrienstatic bfd_size_type total_datasize; 5589857Sobrienstatic bfd_size_type total_textsize; 5689857Sobrien 5733965Sjdp/* Program exit status. */ 5833965Sjdpint return_code = 0; 5933965Sjdp 6038889Sjdpstatic char *target = NULL; 6133965Sjdp 6289857Sobrien/* Static declarations. */ 6333965Sjdp 6489857Sobrienstatic void usage PARAMS ((FILE *, int)); 6589857Sobrienstatic void display_file PARAMS ((char *)); 6689857Sobrienstatic void display_bfd PARAMS ((bfd *)); 6789857Sobrienstatic void display_archive PARAMS ((bfd *)); 6889857Sobrienstatic int size_number PARAMS ((bfd_size_type)); 6938889Sjdp#if 0 7089857Sobrienstatic void lprint_number PARAMS ((int, bfd_size_type)); 7138889Sjdp#endif 7289857Sobrienstatic void rprint_number PARAMS ((int, bfd_size_type)); 7333965Sjdpstatic void print_berkeley_format PARAMS ((bfd *)); 7489857Sobrienstatic void sysv_internal_sizer PARAMS ((bfd *, asection *, PTR)); 7533965Sjdpstatic void sysv_internal_printer PARAMS ((bfd *, asection *, PTR)); 7689857Sobrienstatic void print_sysv_format PARAMS ((bfd *)); 7789857Sobrienstatic void print_sizes PARAMS ((bfd * file)); 7889857Sobrienstatic void berkeley_sum PARAMS ((bfd *, sec_ptr, PTR)); 7933965Sjdp 8033965Sjdpstatic void 8133965Sjdpusage (stream, status) 8233965Sjdp FILE *stream; 8333965Sjdp int status; 8433965Sjdp{ 8589857Sobrien fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name); 8689857Sobrien fprintf (stream, _(" Displays the sizes of sections inside binary files\n")); 87104834Sobrien fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n")); 8889857Sobrien fprintf (stream, _(" The options are:\n\ 8989857Sobrien -A|-B --format={sysv|berkeley} Select output style (default is %s)\n\ 9089857Sobrien -o|-d|-h --radix={8|10|16} Display numbers in octal, decimal or hex\n\ 9189857Sobrien -t --totals Display the total sizes (Berkeley only)\n\ 9289857Sobrien --target=<bfdname> Set the binary file format\n\ 9389857Sobrien -h --help Display this information\n\ 9489857Sobrien -v --version Display the program's version\n\ 9589857Sobrien\n"), 9633965Sjdp#if BSD_DEFAULT 9789857Sobrien "berkeley" 9833965Sjdp#else 9989857Sobrien "sysv" 10033965Sjdp#endif 10189857Sobrien); 10233965Sjdp list_supported_targets (program_name, stream); 10333965Sjdp if (status == 0) 10460484Sobrien fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO); 10533965Sjdp exit (status); 10633965Sjdp} 10733965Sjdp 10833965Sjdpstruct option long_options[] = 10933965Sjdp{ 11033965Sjdp {"format", required_argument, 0, 200}, 11133965Sjdp {"radix", required_argument, 0, 201}, 11233965Sjdp {"target", required_argument, 0, 202}, 11389857Sobrien {"totals", no_argument, &show_totals, 1}, 11433965Sjdp {"version", no_argument, &show_version, 1}, 11533965Sjdp {"help", no_argument, &show_help, 1}, 11633965Sjdp {0, no_argument, 0, 0} 11733965Sjdp}; 11833965Sjdp 11989857Sobrienint main PARAMS ((int, char **)); 12089857Sobrien 12133965Sjdpint 12233965Sjdpmain (argc, argv) 12333965Sjdp int argc; 12433965Sjdp char **argv; 12533965Sjdp{ 12633965Sjdp int temp; 12733965Sjdp int c; 12833965Sjdp 12960484Sobrien#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) 13060484Sobrien setlocale (LC_MESSAGES, ""); 13160484Sobrien#endif 13289857Sobrien#if defined (HAVE_SETLOCALE) 13389857Sobrien setlocale (LC_CTYPE, ""); 13489857Sobrien#endif 13560484Sobrien bindtextdomain (PACKAGE, LOCALEDIR); 13660484Sobrien textdomain (PACKAGE); 13760484Sobrien 13833965Sjdp program_name = *argv; 13933965Sjdp xmalloc_set_program_name (program_name); 14033965Sjdp 14133965Sjdp bfd_init (); 14233965Sjdp set_default_bfd_target (); 14333965Sjdp 14489857Sobrien while ((c = getopt_long (argc, argv, "ABHhVvdfotx", long_options, 14533965Sjdp (int *) 0)) != EOF) 14633965Sjdp switch (c) 14733965Sjdp { 14833965Sjdp case 200: /* --format */ 14933965Sjdp switch (*optarg) 15033965Sjdp { 15133965Sjdp case 'B': 15233965Sjdp case 'b': 15333965Sjdp berkeley_format = 1; 15433965Sjdp break; 15533965Sjdp case 'S': 15633965Sjdp case 's': 15733965Sjdp berkeley_format = 0; 15833965Sjdp break; 15933965Sjdp default: 16060484Sobrien non_fatal (_("invalid argument to --format: %s"), optarg); 16133965Sjdp usage (stderr, 1); 16233965Sjdp } 16333965Sjdp break; 16433965Sjdp 16533965Sjdp case 202: /* --target */ 16633965Sjdp target = optarg; 16733965Sjdp break; 16833965Sjdp 16933965Sjdp case 201: /* --radix */ 17033965Sjdp#ifdef ANSI_LIBRARIES 17133965Sjdp temp = strtol (optarg, NULL, 10); 17233965Sjdp#else 17333965Sjdp temp = atol (optarg); 17433965Sjdp#endif 17533965Sjdp switch (temp) 17633965Sjdp { 17733965Sjdp case 10: 17833965Sjdp radix = decimal; 17933965Sjdp break; 18033965Sjdp case 8: 18133965Sjdp radix = octal; 18233965Sjdp break; 18333965Sjdp case 16: 18433965Sjdp radix = hex; 18533965Sjdp break; 18633965Sjdp default: 18760484Sobrien non_fatal (_("Invalid radix: %s\n"), optarg); 18833965Sjdp usage (stderr, 1); 18933965Sjdp } 19033965Sjdp break; 19133965Sjdp 19233965Sjdp case 'A': 19333965Sjdp berkeley_format = 0; 19433965Sjdp break; 19533965Sjdp case 'B': 19633965Sjdp berkeley_format = 1; 19733965Sjdp break; 19889857Sobrien case 'v': 19933965Sjdp case 'V': 20033965Sjdp show_version = 1; 20133965Sjdp break; 20233965Sjdp case 'd': 20333965Sjdp radix = decimal; 20433965Sjdp break; 20533965Sjdp case 'x': 20633965Sjdp radix = hex; 20733965Sjdp break; 20833965Sjdp case 'o': 20933965Sjdp radix = octal; 21033965Sjdp break; 21189857Sobrien case 't': 21289857Sobrien show_totals = 1; 21389857Sobrien break; 21477298Sobrien case 'f': /* FIXME : For sysv68, `-f' means `full format', i.e. 21577298Sobrien `[fname:] M(.text) + N(.data) + O(.bss) + P(.comment) = Q' 21677298Sobrien where `fname: ' appears only if there are >= 2 input files, 21777298Sobrien and M, N, O, P, Q are expressed in decimal by default, 21877298Sobrien hexa or octal if requested by `-x' or `-o'. 21977298Sobrien Just to make things interesting, Solaris also accepts -f, 22077298Sobrien which prints out the size of each allocatable section, the 22177298Sobrien name of the section, and the total of the section sizes. */ 22277298Sobrien /* For the moment, accept `-f' silently, and ignore it. */ 22377298Sobrien break; 22433965Sjdp case 0: 22533965Sjdp break; 22689857Sobrien case 'h': 22789857Sobrien case 'H': 22833965Sjdp case '?': 22933965Sjdp usage (stderr, 1); 23033965Sjdp } 23133965Sjdp 23233965Sjdp if (show_version) 23333965Sjdp print_version ("size"); 23433965Sjdp if (show_help) 23533965Sjdp usage (stdout, 0); 23633965Sjdp 23733965Sjdp if (optind == argc) 23833965Sjdp display_file ("a.out"); 23933965Sjdp else 24033965Sjdp for (; optind < argc;) 24133965Sjdp display_file (argv[optind++]); 24233965Sjdp 24389857Sobrien if (show_totals && berkeley_format) 24489857Sobrien { 24589857Sobrien bfd_size_type total = total_textsize + total_datasize + total_bsssize; 24689857Sobrien 24789857Sobrien rprint_number (7, total_textsize); 24889857Sobrien putchar('\t'); 24989857Sobrien rprint_number (7, total_datasize); 25089857Sobrien putchar('\t'); 25189857Sobrien rprint_number (7, total_bsssize); 25289857Sobrien printf (((radix == octal) ? "\t%7lo\t%7lx\t" : "\t%7lu\t%7lx\t"), 25389857Sobrien (unsigned long) total, (unsigned long) total); 25489857Sobrien fputs ("(TOTALS)\n", stdout); 25589857Sobrien } 25689857Sobrien 25733965Sjdp return return_code; 25833965Sjdp} 25933965Sjdp 26033965Sjdp/* Display stats on file or archive member ABFD. */ 26133965Sjdp 26233965Sjdpstatic void 26333965Sjdpdisplay_bfd (abfd) 26433965Sjdp bfd *abfd; 26533965Sjdp{ 26633965Sjdp char **matching; 26733965Sjdp 26833965Sjdp if (bfd_check_format (abfd, bfd_archive)) 26933965Sjdp /* An archive within an archive. */ 27033965Sjdp return; 27133965Sjdp 27233965Sjdp if (bfd_check_format_matches (abfd, bfd_object, &matching)) 27333965Sjdp { 27433965Sjdp print_sizes (abfd); 27533965Sjdp printf ("\n"); 27633965Sjdp return; 27733965Sjdp } 27833965Sjdp 27933965Sjdp if (bfd_get_error () == bfd_error_file_ambiguously_recognized) 28033965Sjdp { 28133965Sjdp bfd_nonfatal (bfd_get_filename (abfd)); 28233965Sjdp list_matching_formats (matching); 28333965Sjdp free (matching); 28433965Sjdp return_code = 3; 28533965Sjdp return; 28633965Sjdp } 28733965Sjdp 28833965Sjdp if (bfd_check_format_matches (abfd, bfd_core, &matching)) 28933965Sjdp { 29089857Sobrien const char *core_cmd; 29133965Sjdp 29233965Sjdp print_sizes (abfd); 29333965Sjdp fputs (" (core file", stdout); 29433965Sjdp 29533965Sjdp core_cmd = bfd_core_file_failing_command (abfd); 29633965Sjdp if (core_cmd) 29733965Sjdp printf (" invoked as %s", core_cmd); 29833965Sjdp 29933965Sjdp puts (")\n"); 30033965Sjdp return; 30133965Sjdp } 30233965Sjdp 30333965Sjdp bfd_nonfatal (bfd_get_filename (abfd)); 30433965Sjdp 30533965Sjdp if (bfd_get_error () == bfd_error_file_ambiguously_recognized) 30633965Sjdp { 30733965Sjdp list_matching_formats (matching); 30833965Sjdp free (matching); 30933965Sjdp } 31033965Sjdp 31133965Sjdp return_code = 3; 31233965Sjdp} 31333965Sjdp 31433965Sjdpstatic void 31533965Sjdpdisplay_archive (file) 31633965Sjdp bfd *file; 31733965Sjdp{ 31833965Sjdp bfd *arfile = (bfd *) NULL; 31999461Sobrien bfd *last_arfile = (bfd *) NULL; 32033965Sjdp 32133965Sjdp for (;;) 32233965Sjdp { 32333965Sjdp bfd_set_error (bfd_error_no_error); 32433965Sjdp 32533965Sjdp arfile = bfd_openr_next_archived_file (file, arfile); 32633965Sjdp if (arfile == NULL) 32733965Sjdp { 32833965Sjdp if (bfd_get_error () != bfd_error_no_more_archived_files) 32933965Sjdp { 33033965Sjdp bfd_nonfatal (bfd_get_filename (file)); 33133965Sjdp return_code = 2; 33233965Sjdp } 33333965Sjdp break; 33433965Sjdp } 33533965Sjdp 33633965Sjdp display_bfd (arfile); 33799461Sobrien 33899461Sobrien if (last_arfile != NULL) 33999461Sobrien bfd_close (last_arfile); 34099461Sobrien last_arfile = arfile; 34133965Sjdp } 34299461Sobrien 34399461Sobrien if (last_arfile != NULL) 34499461Sobrien bfd_close (last_arfile); 34533965Sjdp} 34633965Sjdp 34733965Sjdpstatic void 34833965Sjdpdisplay_file (filename) 34933965Sjdp char *filename; 35033965Sjdp{ 35133965Sjdp bfd *file = bfd_openr (filename, target); 35289857Sobrien 35333965Sjdp if (file == NULL) 35433965Sjdp { 35533965Sjdp bfd_nonfatal (filename); 35633965Sjdp return_code = 1; 35733965Sjdp return; 35833965Sjdp } 35933965Sjdp 36033965Sjdp if (bfd_check_format (file, bfd_archive) == true) 36133965Sjdp display_archive (file); 36233965Sjdp else 36333965Sjdp display_bfd (file); 36433965Sjdp 36533965Sjdp if (bfd_close (file) == false) 36633965Sjdp { 36733965Sjdp bfd_nonfatal (filename); 36833965Sjdp return_code = 1; 36933965Sjdp return; 37033965Sjdp } 37133965Sjdp} 37233965Sjdp 37333965Sjdp/* This is what lexical functions are for. */ 37433965Sjdp 37538889Sjdpstatic int 37638889Sjdpsize_number (num) 37738889Sjdp bfd_size_type num; 37838889Sjdp{ 37938889Sjdp char buffer[40]; 38089857Sobrien 38138889Sjdp sprintf (buffer, 38238889Sjdp (radix == decimal ? "%lu" : 38338889Sjdp ((radix == octal) ? "0%lo" : "0x%lx")), 38438889Sjdp (unsigned long) num); 38538889Sjdp 38638889Sjdp return strlen (buffer); 38738889Sjdp} 38838889Sjdp 38938889Sjdp#if 0 39038889Sjdp 39138889Sjdp/* This is not used. */ 39238889Sjdp 39333965Sjdpstatic void 39433965Sjdplprint_number (width, num) 39533965Sjdp int width; 39633965Sjdp bfd_size_type num; 39733965Sjdp{ 39838889Sjdp char buffer[40]; 39989857Sobrien 40038889Sjdp sprintf (buffer, 40138889Sjdp (radix == decimal ? "%lu" : 40238889Sjdp ((radix == octal) ? "0%lo" : "0x%lx")), 40338889Sjdp (unsigned long) num); 40438889Sjdp 40538889Sjdp printf ("%-*s", width, buffer); 40633965Sjdp} 40733965Sjdp 40838889Sjdp#endif 40938889Sjdp 41033965Sjdpstatic void 41133965Sjdprprint_number (width, num) 41233965Sjdp int width; 41333965Sjdp bfd_size_type num; 41433965Sjdp{ 41538889Sjdp char buffer[40]; 41689857Sobrien 41738889Sjdp sprintf (buffer, 41838889Sjdp (radix == decimal ? "%lu" : 41938889Sjdp ((radix == octal) ? "0%lo" : "0x%lx")), 42038889Sjdp (unsigned long) num); 42138889Sjdp 42238889Sjdp printf ("%*s", width, buffer); 42333965Sjdp} 42433965Sjdp 42533965Sjdpstatic bfd_size_type bsssize; 42633965Sjdpstatic bfd_size_type datasize; 42733965Sjdpstatic bfd_size_type textsize; 42833965Sjdp 42933965Sjdpstatic void 43033965Sjdpberkeley_sum (abfd, sec, ignore) 43160484Sobrien bfd *abfd ATTRIBUTE_UNUSED; 43233965Sjdp sec_ptr sec; 43360484Sobrien PTR ignore ATTRIBUTE_UNUSED; 43433965Sjdp{ 43533965Sjdp flagword flags; 43633965Sjdp bfd_size_type size; 43733965Sjdp 43833965Sjdp flags = bfd_get_section_flags (abfd, sec); 43933965Sjdp if ((flags & SEC_ALLOC) == 0) 44033965Sjdp return; 44133965Sjdp 44233965Sjdp size = bfd_get_section_size_before_reloc (sec); 44333965Sjdp if ((flags & SEC_CODE) != 0 || (flags & SEC_READONLY) != 0) 44433965Sjdp textsize += size; 44533965Sjdp else if ((flags & SEC_HAS_CONTENTS) != 0) 44633965Sjdp datasize += size; 44733965Sjdp else 44833965Sjdp bsssize += size; 44933965Sjdp} 45033965Sjdp 451104834Sobrienstatic void 45233965Sjdpprint_berkeley_format (abfd) 45333965Sjdp bfd *abfd; 45433965Sjdp{ 45533965Sjdp static int files_seen = 0; 45633965Sjdp bfd_size_type total; 45733965Sjdp 45833965Sjdp bsssize = 0; 45933965Sjdp datasize = 0; 46033965Sjdp textsize = 0; 46133965Sjdp 46233965Sjdp bfd_map_over_sections (abfd, berkeley_sum, (PTR) NULL); 46333965Sjdp 46433965Sjdp if (files_seen++ == 0) 46533965Sjdp#if 0 46633965Sjdp /* Intel doesn't like bss/stk because they don't have core files. */ 46738889Sjdp puts ((radix == octal) ? " text\t data\tbss/stk\t oct\t hex\tfilename" : 46838889Sjdp " text\t data\tbss/stk\t dec\t hex\tfilename"); 46933965Sjdp#else 47038889Sjdp puts ((radix == octal) ? " text\t data\t bss\t oct\t hex\tfilename" : 47138889Sjdp " text\t data\t bss\t dec\t hex\tfilename"); 47233965Sjdp#endif 47333965Sjdp 47433965Sjdp total = textsize + datasize + bsssize; 47533965Sjdp 47689857Sobrien if (show_totals) 47789857Sobrien { 47889857Sobrien total_textsize += textsize; 47989857Sobrien total_datasize += datasize; 48089857Sobrien total_bsssize += bsssize; 48189857Sobrien } 48289857Sobrien 48338889Sjdp rprint_number (7, textsize); 48438889Sjdp putchar ('\t'); 48538889Sjdp rprint_number (7, datasize); 48638889Sjdp putchar ('\t'); 48738889Sjdp rprint_number (7, bsssize); 48838889Sjdp printf (((radix == octal) ? "\t%7lo\t%7lx\t" : "\t%7lu\t%7lx\t"), 48933965Sjdp (unsigned long) total, (unsigned long) total); 49033965Sjdp 49133965Sjdp fputs (bfd_get_filename (abfd), stdout); 49289857Sobrien 49333965Sjdp if (bfd_my_archive (abfd)) 49433965Sjdp printf (" (ex %s)", bfd_get_filename (bfd_my_archive (abfd))); 49533965Sjdp} 49633965Sjdp 49733965Sjdp/* I REALLY miss lexical functions! */ 49833965Sjdpbfd_size_type svi_total = 0; 49938889Sjdpbfd_vma svi_maxvma = 0; 50038889Sjdpint svi_namelen = 0; 50138889Sjdpint svi_vmalen = 0; 50238889Sjdpint svi_sizelen = 0; 50333965Sjdp 50433965Sjdpstatic void 50538889Sjdpsysv_internal_sizer (file, sec, ignore) 50660484Sobrien bfd *file ATTRIBUTE_UNUSED; 50738889Sjdp sec_ptr sec; 50860484Sobrien PTR ignore ATTRIBUTE_UNUSED; 50938889Sjdp{ 51038889Sjdp bfd_size_type size = bfd_section_size (file, sec); 51189857Sobrien 51289857Sobrien if ( ! bfd_is_abs_section (sec) 51389857Sobrien && ! bfd_is_com_section (sec) 51489857Sobrien && ! bfd_is_und_section (sec)) 51538889Sjdp { 51638889Sjdp int namelen = strlen (bfd_section_name (file, sec)); 51789857Sobrien 51838889Sjdp if (namelen > svi_namelen) 51938889Sjdp svi_namelen = namelen; 52038889Sjdp 52138889Sjdp svi_total += size; 52289857Sobrien 52338889Sjdp if (bfd_section_vma (file, sec) > svi_maxvma) 52438889Sjdp svi_maxvma = bfd_section_vma (file, sec); 52538889Sjdp } 52638889Sjdp} 52738889Sjdp 52838889Sjdpstatic void 52933965Sjdpsysv_internal_printer (file, sec, ignore) 53060484Sobrien bfd *file ATTRIBUTE_UNUSED; 53133965Sjdp sec_ptr sec; 53260484Sobrien PTR ignore ATTRIBUTE_UNUSED; 53333965Sjdp{ 53433965Sjdp bfd_size_type size = bfd_section_size (file, sec); 53589857Sobrien 53689857Sobrien if ( ! bfd_is_abs_section (sec) 53789857Sobrien && ! bfd_is_com_section (sec) 53889857Sobrien && ! bfd_is_und_section (sec)) 53933965Sjdp { 54033965Sjdp svi_total += size; 54133965Sjdp 54238889Sjdp printf ("%-*s ", svi_namelen, bfd_section_name (file, sec)); 54338889Sjdp rprint_number (svi_sizelen, size); 54438889Sjdp printf (" "); 54538889Sjdp rprint_number (svi_vmalen, bfd_section_vma (file, sec)); 54633965Sjdp printf ("\n"); 54733965Sjdp } 54833965Sjdp} 54933965Sjdp 55033965Sjdpstatic void 55133965Sjdpprint_sysv_format (file) 55233965Sjdp bfd *file; 55333965Sjdp{ 55489857Sobrien /* Size all of the columns. */ 55533965Sjdp svi_total = 0; 55638889Sjdp svi_maxvma = 0; 55738889Sjdp svi_namelen = 0; 55838889Sjdp bfd_map_over_sections (file, sysv_internal_sizer, (PTR) NULL); 55938889Sjdp svi_vmalen = size_number ((bfd_size_type)svi_maxvma); 56089857Sobrien 56138889Sjdp if ((size_t) svi_vmalen < sizeof ("addr") - 1) 56238889Sjdp svi_vmalen = sizeof ("addr")-1; 56333965Sjdp 56438889Sjdp svi_sizelen = size_number (svi_total); 56538889Sjdp if ((size_t) svi_sizelen < sizeof ("size") - 1) 56638889Sjdp svi_sizelen = sizeof ("size")-1; 56738889Sjdp 56838889Sjdp svi_total = 0; 56933965Sjdp printf ("%s ", bfd_get_filename (file)); 57089857Sobrien 57133965Sjdp if (bfd_my_archive (file)) 57233965Sjdp printf (" (ex %s)", bfd_get_filename (bfd_my_archive (file))); 57333965Sjdp 57438889Sjdp printf (":\n%-*s %*s %*s\n", svi_namelen, "section", 57538889Sjdp svi_sizelen, "size", svi_vmalen, "addr"); 57689857Sobrien 57733965Sjdp bfd_map_over_sections (file, sysv_internal_printer, (PTR) NULL); 57833965Sjdp 57938889Sjdp printf ("%-*s ", svi_namelen, "Total"); 58038889Sjdp rprint_number (svi_sizelen, svi_total); 58133965Sjdp printf ("\n\n"); 58233965Sjdp} 58333965Sjdp 58433965Sjdpstatic void 58533965Sjdpprint_sizes (file) 58633965Sjdp bfd *file; 58733965Sjdp{ 58833965Sjdp if (berkeley_format) 58933965Sjdp print_berkeley_format (file); 59033965Sjdp else 59133965Sjdp print_sysv_format (file); 59233965Sjdp} 593