169039Sben/* size.c -- report size of various sections of an executable file. 269039Sben Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 369039Sben 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 469039Sben Free Software Foundation, Inc. 569039Sben 669039Sben This file is part of GNU Binutils. 769039Sben 869039Sben This program is free software; you can redistribute it and/or modify 969039Sben it under the terms of the GNU General Public License as published by 1069039Sben the Free Software Foundation; either version 3 of the License, or 1169039Sben (at your option) any later version. 1269039Sben 1369039Sben This program is distributed in the hope that it will be useful, 1469039Sben but WITHOUT ANY WARRANTY; without even the implied warranty of 1569039Sben MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1669039Sben GNU General Public License for more details. 1769039Sben 1869039Sben You should have received a copy of the GNU General Public License 1969039Sben along with this program; if not, write to the Free Software 2069039Sben Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 2169039Sben MA 02110-1301, USA. */ 2269039Sben 2369039Sben/* Extensions/incompatibilities: 2469039Sben o - BSD output has filenames at the end. 2569039Sben o - BSD output can appear in different radicies. 2669039Sben o - SysV output has less redundant whitespace. Filename comes at end. 27267309Sbjk o - SysV output doesn't show VMA which is always the same as the PMA. 2869039Sben o - We also handle core files. 2969039Sben o - We also handle archives. 3069039Sben If you write shell scripts which manipulate this info then you may be 3169039Sben out of luck; there's no --compatibility or --pedantic option. */ 3271212Sru 3369039Sben#include "sysdep.h" 3469039Sben#include "bfd.h" 3569039Sben#include "libiberty.h" 36151201Syar#include "getopt.h" 37151201Syar#include "bucomm.h" 38151201Syar 39151201Syar#ifndef BSD_DEFAULT 40151201Syar#define BSD_DEFAULT 1 41151201Syar#endif 42151201Syar 43151201Syar/* Program options. */ 44151201Syar 45151201Syarstatic enum 46151201Syar { 47151201Syar decimal, octal, hex 48151201Syar } 49151201Syarradix = decimal; 5071212Sru 5169039Sben/* 0 means use AT&T-style output. */ 52151201Syarstatic int berkeley_format = BSD_DEFAULT; 53151201Syar 54151201Syarstatic int show_version = 0; 55151201Syarstatic int show_help = 0; 56151201Syarstatic int show_totals = 0; 57151201Syarstatic int show_common = 0; 58151201Syar 59151201Syarstatic bfd_size_type common_size; 60151201Syarstatic bfd_size_type total_bsssize; 61151201Syarstatic bfd_size_type total_datasize; 6269039Sbenstatic bfd_size_type total_textsize; 63151201Syar 6469039Sben/* Program exit status. */ 65151201Syarstatic int return_code = 0; 66151201Syar 67151201Syarstatic char *target = NULL; 68151201Syar 69151201Syar/* Forward declarations. */ 70151201Syar 71151201Syarstatic void display_file (char *); 72151201Syarstatic void rprint_number (int, bfd_size_type); 73151201Syarstatic void print_sizes (bfd * file); 74151201Syar 75151201Syarstatic void 76151201Syarusage (FILE *stream, int status) 77151201Syar{ 78151201Syar fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name); 79151201Syar fprintf (stream, _(" Displays the sizes of sections inside binary files\n")); 80151201Syar fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n")); 81151201Syar fprintf (stream, _(" The options are:\n\ 82151201Syar -A|-B --format={sysv|berkeley} Select output style (default is %s)\n\ 83151201Syar -o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex\n\ 84151201Syar -t --totals Display the total sizes (Berkeley only)\n\ 85151201Syar --common Display total size for *COM* syms\n\ 8671212Sru --target=<bfdname> Set the binary file format\n\ 87151201Syar @<file> Read options from <file>\n\ 8869039Sben -h --help Display this information\n\ 89151201Syar -v --version Display the program's version\n\ 90151201Syar\n"), 91151201Syar#if BSD_DEFAULT 92151201Syar "berkeley" 93151201Syar#else 9469039Sben "sysv" 95151201Syar#endif 96151201Syar); 9771212Sru list_supported_targets (program_name, stream); 9869039Sben if (REPORT_BUGS_TO[0] && status == 0) 99151201Syar fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO); 100151201Syar exit (status); 101151201Syar} 10271212Sru 10369039Sben#define OPTION_FORMAT (200) 104151201Syar#define OPTION_RADIX (OPTION_FORMAT + 1) 105151201Syar#define OPTION_TARGET (OPTION_RADIX + 1) 106151201Syar 10769039Sbenstatic struct option long_options[] = 10871212Sru{ 10971212Sru {"common", no_argument, &show_common, 1}, 11071212Sru {"format", required_argument, 0, OPTION_FORMAT}, 11169039Sben {"radix", required_argument, 0, OPTION_RADIX}, 11271212Sru {"target", required_argument, 0, OPTION_TARGET}, 11369039Sben {"totals", no_argument, &show_totals, 1}, 11479727Sschweikh {"version", no_argument, &show_version, 1}, 11571212Sru {"help", no_argument, &show_help, 1}, 11669039Sben {0, no_argument, 0, 0} 11771212Sru}; 11896588Skeramida 11969039Sbenint main (int, char **); 12069039Sben 12169039Sbenint 12269039Sbenmain (int argc, char **argv) 12371212Sru{ 12471212Sru int temp; 12569039Sben int c; 126119519Smarcel 127119519Smarcel#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) 128119519Smarcel setlocale (LC_MESSAGES, ""); 129119519Smarcel#endif 130119519Smarcel#if defined (HAVE_SETLOCALE) 131119519Smarcel setlocale (LC_CTYPE, ""); 132119519Smarcel#endif 133119519Smarcel bindtextdomain (PACKAGE, LOCALEDIR); 134119519Smarcel textdomain (PACKAGE); 135119519Smarcel 13671212Sru program_name = *argv; 13776109Sdd xmalloc_set_program_name (program_name); 13871212Sru 139131754Sru expandargv (&argc, &argv); 14081854Sdd 141131466Sdes bfd_init (); 142131466Sdes set_default_bfd_target (); 14371212Sru 14471212Sru while ((c = getopt_long (argc, argv, "ABHhVvdfotx", long_options, 14571212Sru (int *) 0)) != EOF) 146243670Seadler switch (c) 14771212Sru { 14871212Sru case OPTION_FORMAT: 14971212Sru switch (*optarg) 15082604Salex { 15169039Sben case 'B': 15294581Sdd case 'b': 15369039Sben berkeley_format = 1; 154107174Strhodes break; 155107174Strhodes case 'S': 156107174Strhodes case 's': 157107383Sru berkeley_format = 0; 158107383Sru break; 159107174Strhodes default: 160107174Strhodes non_fatal (_("invalid argument to --format: %s"), optarg); 161107174Strhodes usage (stderr, 1); 162107174Strhodes } 163107174Strhodes break; 164107174Strhodes 165243670Seadler case OPTION_TARGET: 166107174Strhodes target = optarg; 167107174Strhodes break; 168107174Strhodes 169107174Strhodes case OPTION_RADIX: 170107174Strhodes#ifdef ANSI_LIBRARIES 171107174Strhodes temp = strtol (optarg, NULL, 10); 172107174Strhodes#else 173107174Strhodes temp = atol (optarg); 174107383Sru#endif 175107383Sru switch (temp) 176107174Strhodes { 177107174Strhodes case 10: 178107174Strhodes radix = decimal; 179107174Strhodes break; 18071212Sru case 8: 18176109Sdd radix = octal; 18271212Sru break; 18371212Sru case 16: 18471212Sru radix = hex; 18571212Sru break; 18671212Sru default: 18771212Sru non_fatal (_("Invalid radix: %s\n"), optarg); 18871212Sru usage (stderr, 1); 18971212Sru } 19069039Sben break; 19169039Sben 19269039Sben case 'A': 19371212Sru berkeley_format = 0; 19476109Sdd break; 19571212Sru case 'B': 196120093Ssheldonh berkeley_format = 1; 19769039Sben break; 198249952Sbdrewery case 'v': 19969039Sben case 'V': 200120093Ssheldonh show_version = 1; 201120093Ssheldonh break; 202120093Ssheldonh case 'd': 20371212Sru radix = decimal; 20476109Sdd break; 20571212Sru case 'x': 20669039Sben radix = hex; 20771212Sru break; 20869039Sben case 'o': 209107174Strhodes radix = octal; 210107174Strhodes break; 211107174Strhodes case 't': 212107174Strhodes show_totals = 1; 213107174Strhodes break; 214107174Strhodes case 'f': /* FIXME : For sysv68, `-f' means `full format', i.e. 215107383Sru `[fname:] M(.text) + N(.data) + O(.bss) + P(.comment) = Q' 216107174Strhodes where `fname: ' appears only if there are >= 2 input files, 217107174Strhodes and M, N, O, P, Q are expressed in decimal by default, 218107174Strhodes hexa or octal if requested by `-x' or `-o'. 219107383Sru Just to make things interesting, Solaris also accepts -f, 220107383Sru which prints out the size of each allocatable section, the 22171212Sru name of the section, and the total of the section sizes. */ 22276109Sdd /* For the moment, accept `-f' silently, and ignore it. */ 22371212Sru break; 22471212Sru case 0: 22571212Sru break; 22671212Sru case 'h': 22771212Sru case 'H': 228152793Sjkoshy case '?': 229152793Sjkoshy usage (stderr, 1); 230152793Sjkoshy } 231152793Sjkoshy 232152793Sjkoshy if (show_version) 233152793Sjkoshy print_version ("size"); 234152793Sjkoshy if (show_help) 235152793Sjkoshy usage (stdout, 0); 236152793Sjkoshy 237152793Sjkoshy if (optind == argc) 238152793Sjkoshy display_file ("a.out"); 239152793Sjkoshy else 24071212Sru for (; optind < argc;) 24176109Sdd display_file (argv[optind++]); 24271212Sru 24371212Sru if (show_totals && berkeley_format) 24471212Sru { 24576109Sdd bfd_size_type total = total_textsize + total_datasize + total_bsssize; 24671212Sru 24771212Sru rprint_number (7, total_textsize); 248223148Sru putchar('\t'); 249223148Sru rprint_number (7, total_datasize); 250223148Sru putchar('\t'); 251223148Sru rprint_number (7, total_bsssize); 252223148Sru printf (((radix == octal) ? "\t%7lo\t%7lx\t" : "\t%7lu\t%7lx\t"), 253223148Sru (unsigned long) total, (unsigned long) total); 254223148Sru fputs ("(TOTALS)\n", stdout); 255223148Sru } 256228418Sgjb 257228418Sgjb return return_code; 258228418Sgjb} 259228418Sgjb 260228418Sgjb/* Total size required for common symbols in ABFD. */ 261228418Sgjb 26269039Sbenstatic void 263152607Sjkoshycalculate_common_size (bfd *abfd) 26469039Sben{ 26569039Sben asymbol **syms = NULL; 26669039Sben long storage, symcount; 267152793Sjkoshy 268152793Sjkoshy common_size = 0; 269152793Sjkoshy if ((bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC | HAS_SYMS)) != HAS_SYMS) 270152793Sjkoshy return; 271152793Sjkoshy 272152793Sjkoshy storage = bfd_get_symtab_upper_bound (abfd); 273152793Sjkoshy if (storage < 0) 274152793Sjkoshy bfd_fatal (bfd_get_filename (abfd)); 27571212Sru if (storage) 27676109Sdd syms = (asymbol **) xmalloc (storage); 27771212Sru 27871212Sru symcount = bfd_canonicalize_symtab (abfd, syms); 27971212Sru if (symcount < 0) 28071212Sru bfd_fatal (bfd_get_filename (abfd)); 28181749Sobrien 28282151Sjkh while (--symcount >= 0) 28376109Sdd { 28471212Sru asymbol *sym = syms[symcount]; 28571160Sben 28671212Sru if (bfd_is_com_section (sym->section) 28771212Sru && (sym->flags & BSF_SECTION_SYM) == 0) 28871212Sru common_size += sym->value; 28971160Sben } 29071160Sben free (syms); 29182226Sdd} 29271160Sben 29371212Sru/* Display stats on file or archive member ABFD. */ 29478686Sdd 29571160Sbenstatic void 29671160Sbendisplay_bfd (bfd *abfd) 29771160Sben{ 29871160Sben char **matching; 29971160Sben 30071160Sben if (bfd_check_format (abfd, bfd_archive)) 30171160Sben /* An archive within an archive. */ 302107174Strhodes return; 303107174Strhodes 304107174Strhodes if (bfd_check_format_matches (abfd, bfd_object, &matching)) 305200597Simp { 306200597Simp print_sizes (abfd); 307200597Simp printf ("\n"); 308200597Simp return; 309200597Simp } 310200597Simp 31171212Sru if (bfd_get_error () == bfd_error_file_ambiguously_recognized) 31276109Sdd { 31371212Sru bfd_nonfatal (bfd_get_filename (abfd)); 31469039Sben list_matching_formats (matching); 31569039Sben free (matching); 31671212Sru return_code = 3; 31771212Sru return; 31876109Sdd } 31971212Sru 32071212Sru if (bfd_check_format_matches (abfd, bfd_core, &matching)) 32169039Sben { 32271212Sru const char *core_cmd; 323200597Simp 324200597Simp print_sizes (abfd); 325200597Simp fputs (" (core file", stdout); 326200597Simp 327200597Simp core_cmd = bfd_core_file_failing_command (abfd); 328200597Simp if (core_cmd) 32971212Sru printf (" invoked as %s", core_cmd); 33076109Sdd 33171212Sru puts (")\n"); 332152793Sjkoshy return; 333152793Sjkoshy } 334152793Sjkoshy 335152793Sjkoshy bfd_nonfatal (bfd_get_filename (abfd)); 336152793Sjkoshy 337152793Sjkoshy if (bfd_get_error () == bfd_error_file_ambiguously_recognized) 338152793Sjkoshy { 339152793Sjkoshy list_matching_formats (matching); 340152793Sjkoshy free (matching); 341152793Sjkoshy } 342152793Sjkoshy 343152793Sjkoshy return_code = 3; 344152793Sjkoshy} 34569039Sben 346152607Sjkoshystatic void 34769039Sbendisplay_archive (bfd *file) 34869039Sben{ 34969039Sben bfd *arfile = (bfd *) NULL; 350162050Sru bfd *last_arfile = (bfd *) NULL; 351162050Sru 352162050Sru for (;;) 353162050Sru { 354162050Sru bfd_set_error (bfd_error_no_error); 355162050Sru 356162050Sru arfile = bfd_openr_next_archived_file (file, arfile); 357162050Sru if (arfile == NULL) 358162050Sru { 359162050Sru if (bfd_get_error () != bfd_error_no_more_archived_files) 360162050Sru { 361162050Sru bfd_nonfatal (bfd_get_filename (file)); 362162050Sru return_code = 2; 363162050Sru } 364162050Sru break; 365162050Sru } 366162050Sru 367162050Sru display_bfd (arfile); 368162050Sru 369162050Sru if (last_arfile != NULL) 370162050Sru bfd_close (last_arfile); 371162050Sru last_arfile = arfile; 372162050Sru } 373162050Sru 374162050Sru if (last_arfile != NULL) 375162050Sru bfd_close (last_arfile); 376162050Sru} 377162050Sru 378162050Srustatic void 37996436Snectardisplay_file (char *filename) 38096436Snectar{ 381114333Smarkm bfd *file; 38297486Sru 38396436Snectar if (get_file_size (filename) < 1) 38497387Stjr { 38597387Stjr return_code = 1; 38697387Stjr return; 38797387Stjr } 38897387Stjr 38997387Stjr file = bfd_openr (filename, target); 39097387Stjr if (file == NULL) 39197387Stjr { 392162050Sru bfd_nonfatal (filename); 393162050Sru return_code = 1; 394162050Sru return; 395162050Sru } 396162050Sru 397162050Sru if (bfd_check_format (file, bfd_archive)) 398162050Sru display_archive (file); 399162050Sru else 400162050Sru display_bfd (file); 401162050Sru 402162050Sru if (!bfd_close (file)) 403162050Sru { 404162050Sru bfd_nonfatal (filename); 405162050Sru return_code = 1; 406170103Ssimokawa return; 407170103Ssimokawa } 408170103Ssimokawa} 409170103Ssimokawa 410228419Sgjbstatic int 411170103Ssimokawasize_number (bfd_size_type num) 412170103Ssimokawa{ 413170103Ssimokawa char buffer[40]; 414170103Ssimokawa 415170103Ssimokawa sprintf (buffer, 416170103Ssimokawa (radix == decimal ? "%" BFD_VMA_FMT "u" : 417196727Smaxim ((radix == octal) ? "0%" BFD_VMA_FMT "o" : "0x%" BFD_VMA_FMT "x")), 418196727Smaxim num); 419196727Smaxim 420196727Smaxim return strlen (buffer); 421196727Smaxim} 422196727Smaxim 42371212Srustatic void 42476109Sddrprint_number (int width, bfd_size_type num) 42571212Sru{ 426152793Sjkoshy char buffer[40]; 427152793Sjkoshy 428152793Sjkoshy sprintf (buffer, 429152793Sjkoshy (radix == decimal ? "%" BFD_VMA_FMT "u" : 430152793Sjkoshy ((radix == octal) ? "0%" BFD_VMA_FMT "o" : "0x%" BFD_VMA_FMT "x")), 431152793Sjkoshy num); 432152793Sjkoshy 433152793Sjkoshy printf ("%*s", width, buffer); 434152793Sjkoshy} 435152793Sjkoshy 436152793Sjkoshystatic bfd_size_type bsssize; 437152793Sjkoshystatic bfd_size_type datasize; 438152793Sjkoshystatic bfd_size_type textsize; 439152793Sjkoshy 440139120Srustatic void 44176109Sddberkeley_sum (bfd *abfd ATTRIBUTE_UNUSED, sec_ptr sec, 44271212Sru void *ignore ATTRIBUTE_UNUSED) 44371212Sru{ 44471212Sru flagword flags; 445139112Sru bfd_size_type size; 446138880Strhodes 447155503Sbrueffer flags = bfd_get_section_flags (abfd, sec); 448138880Strhodes if ((flags & SEC_ALLOC) == 0) 449138880Strhodes return; 450138880Strhodes 451151552Strhodes size = bfd_get_section_size (sec); 452151552Strhodes if ((flags & SEC_CODE) != 0 || (flags & SEC_READONLY) != 0) 453151552Strhodes textsize += size; 454151552Strhodes else if ((flags & SEC_HAS_CONTENTS) != 0) 455139118Sru datasize += size; 456138880Strhodes else 457139118Sru bsssize += size; 458139118Sru} 459139118Sru 460139118Srustatic void 461139118Sruprint_berkeley_format (bfd *abfd) 462138880Strhodes{ 463138880Strhodes static int files_seen = 0; 464139118Sru bfd_size_type total; 465139118Sru 466139118Sru bsssize = 0; 467138880Strhodes datasize = 0; 468138880Strhodes textsize = 0; 469139118Sru 470139118Sru bfd_map_over_sections (abfd, berkeley_sum, NULL); 47176109Sdd 47271212Sru bsssize += common_size; 47371212Sru if (files_seen++ == 0) 474139118Sru puts ((radix == octal) ? " text\t data\t bss\t oct\t hex\tfilename" : 47572918Sgshapiro " text\t data\t bss\t dec\t hex\tfilename"); 47676109Sdd 47781241Sru total = textsize + datasize + bsssize; 47881241Sru 47981241Sru if (show_totals) 48081241Sru { 48181241Sru total_textsize += textsize; 48281241Sru total_datasize += datasize; 48381241Sru total_bsssize += bsssize; 48481241Sru } 485235337Sgjb 48672918Sgshapiro rprint_number (7, textsize); 487170752Sgshapiro putchar ('\t'); 488170752Sgshapiro rprint_number (7, datasize); 489170752Sgshapiro putchar ('\t'); 490170752Sgshapiro rprint_number (7, bsssize); 491170752Sgshapiro printf (((radix == octal) ? "\t%7lo\t%7lx\t" : "\t%7lu\t%7lx\t"), 492170752Sgshapiro (unsigned long) total, (unsigned long) total); 493170752Sgshapiro 494170752Sgshapiro fputs (bfd_get_filename (abfd), stdout); 49571212Sru 49676109Sdd if (bfd_my_archive (abfd)) 49771212Sru printf (" (ex %s)", bfd_get_filename (bfd_my_archive (abfd))); 49871212Sru} 49971212Sru 50071212Sru/* I REALLY miss lexical functions! */ 50171212Srubfd_size_type svi_total = 0; 50269039Sbenbfd_vma svi_maxvma = 0; 50369039Sbenint svi_namelen = 0; 50469039Sbenint svi_vmalen = 0; 50569039Sbenint svi_sizelen = 0; 50669039Sben 507152793Sjkoshystatic void 50876109Sddsysv_internal_sizer (bfd *file ATTRIBUTE_UNUSED, sec_ptr sec, 509152793Sjkoshy void *ignore ATTRIBUTE_UNUSED) 510152793Sjkoshy{ 511152793Sjkoshy bfd_size_type size = bfd_section_size (file, sec); 512152793Sjkoshy 513152793Sjkoshy if ( ! bfd_is_abs_section (sec) 514152793Sjkoshy && ! bfd_is_com_section (sec) 515152793Sjkoshy && ! bfd_is_und_section (sec)) 516152793Sjkoshy { 517152793Sjkoshy int namelen = strlen (bfd_section_name (file, sec)); 518152793Sjkoshy 51971212Sru if (namelen > svi_namelen) 52071212Sru svi_namelen = namelen; 52176109Sdd 52271212Sru svi_total += size; 52371212Sru 52471212Sru if (bfd_section_vma (file, sec) > svi_maxvma) 52571212Sru svi_maxvma = bfd_section_vma (file, sec); 526152793Sjkoshy } 52776109Sdd} 528152793Sjkoshy 529152793Sjkoshystatic void 530152793Sjkoshysysv_one_line (const char *name, bfd_size_type size, bfd_vma vma) 53190803Sgshapiro{ 532152793Sjkoshy printf ("%-*s ", svi_namelen, name); 533152793Sjkoshy rprint_number (svi_sizelen, size); 534152793Sjkoshy printf (" "); 535152793Sjkoshy rprint_number (svi_vmalen, vma); 536152793Sjkoshy printf ("\n"); 537152793Sjkoshy} 538152793Sjkoshy 539152793Sjkoshystatic void 540152793Sjkoshysysv_internal_printer (bfd *file ATTRIBUTE_UNUSED, sec_ptr sec, 541152793Sjkoshy void *ignore ATTRIBUTE_UNUSED) 542152793Sjkoshy{ 543152793Sjkoshy bfd_size_type size = bfd_section_size (file, sec); 544152793Sjkoshy 545152793Sjkoshy if ( ! bfd_is_abs_section (sec) 546170752Sgshapiro && ! bfd_is_com_section (sec) 547170752Sgshapiro && ! bfd_is_und_section (sec)) 548170752Sgshapiro { 549170752Sgshapiro svi_total += size; 550228419Sgjb 551170752Sgshapiro sysv_one_line (bfd_section_name (file, sec), 552170752Sgshapiro size, 553170752Sgshapiro bfd_section_vma (file, sec)); 554170752Sgshapiro } 555170752Sgshapiro} 556170752Sgshapiro 557170752Sgshapirostatic void 558170752Sgshapiroprint_sysv_format (bfd *file) 559170752Sgshapiro{ 560170752Sgshapiro /* Size all of the columns. */ 561170752Sgshapiro svi_total = 0; 562170752Sgshapiro svi_maxvma = 0; 563170752Sgshapiro svi_namelen = 0; 564170752Sgshapiro bfd_map_over_sections (file, sysv_internal_sizer, NULL); 565170752Sgshapiro if (show_common) 566152793Sjkoshy { 567152793Sjkoshy if (svi_namelen < (int) sizeof ("*COM*") - 1) 568152793Sjkoshy svi_namelen = sizeof ("*COM*") - 1; 569152793Sjkoshy svi_total += common_size; 570152793Sjkoshy } 571152793Sjkoshy 572152793Sjkoshy svi_vmalen = size_number ((bfd_size_type)svi_maxvma); 573152793Sjkoshy 574152793Sjkoshy if ((size_t) svi_vmalen < sizeof ("addr") - 1) 575152793Sjkoshy svi_vmalen = sizeof ("addr")-1; 576152793Sjkoshy 577152793Sjkoshy svi_sizelen = size_number (svi_total); 578152793Sjkoshy if ((size_t) svi_sizelen < sizeof ("size") - 1) 579152793Sjkoshy svi_sizelen = sizeof ("size")-1; 58090803Sgshapiro 58190803Sgshapiro svi_total = 0; 58290803Sgshapiro printf ("%s ", bfd_get_filename (file)); 58390803Sgshapiro 58490803Sgshapiro if (bfd_my_archive (file)) 58590803Sgshapiro printf (" (ex %s)", bfd_get_filename (bfd_my_archive (file))); 58690803Sgshapiro 58790803Sgshapiro printf (":\n%-*s %*s %*s\n", svi_namelen, "section", 58890803Sgshapiro svi_sizelen, "size", svi_vmalen, "addr"); 58992500Sru 590170752Sgshapiro bfd_map_over_sections (file, sysv_internal_printer, NULL); 591170752Sgshapiro if (show_common) 592170752Sgshapiro { 593170752Sgshapiro svi_total += common_size; 594170752Sgshapiro sysv_one_line ("*COM*", common_size, 0); 595170752Sgshapiro } 596170752Sgshapiro 597170752Sgshapiro printf ("%-*s ", svi_namelen, "Total"); 598170752Sgshapiro rprint_number (svi_sizelen, svi_total); 599170752Sgshapiro printf ("\n\n"); 600170752Sgshapiro} 601170752Sgshapiro 602152793Sjkoshystatic void 60397200Sgshapiroprint_sizes (bfd *file) 604152793Sjkoshy{ 605152793Sjkoshy if (show_common) 606152793Sjkoshy calculate_common_size (file); 607152793Sjkoshy if (berkeley_format) 608152793Sjkoshy print_berkeley_format (file); 609152793Sjkoshy else 610152793Sjkoshy print_sysv_format (file); 611152793Sjkoshy} 612152793Sjkoshy