size.c revision 91041
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"));
8789857Sobrien  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;
31933965Sjdp
32033965Sjdp  for (;;)
32133965Sjdp    {
32233965Sjdp      bfd_set_error (bfd_error_no_error);
32333965Sjdp
32433965Sjdp      arfile = bfd_openr_next_archived_file (file, arfile);
32533965Sjdp      if (arfile == NULL)
32633965Sjdp	{
32733965Sjdp	  if (bfd_get_error () != bfd_error_no_more_archived_files)
32833965Sjdp	    {
32933965Sjdp	      bfd_nonfatal (bfd_get_filename (file));
33033965Sjdp	      return_code = 2;
33133965Sjdp	    }
33233965Sjdp	  break;
33333965Sjdp	}
33433965Sjdp
33533965Sjdp      display_bfd (arfile);
33689857Sobrien      /* Don't close the archive elements; we need them for next_archive.  */
33733965Sjdp    }
33833965Sjdp}
33933965Sjdp
34033965Sjdpstatic void
34133965Sjdpdisplay_file (filename)
34233965Sjdp     char *filename;
34333965Sjdp{
34433965Sjdp  bfd *file = bfd_openr (filename, target);
34589857Sobrien
34633965Sjdp  if (file == NULL)
34733965Sjdp    {
34833965Sjdp      bfd_nonfatal (filename);
34933965Sjdp      return_code = 1;
35033965Sjdp      return;
35133965Sjdp    }
35233965Sjdp
35333965Sjdp  if (bfd_check_format (file, bfd_archive) == true)
35433965Sjdp    display_archive (file);
35533965Sjdp  else
35633965Sjdp    display_bfd (file);
35733965Sjdp
35833965Sjdp  if (bfd_close (file) == false)
35933965Sjdp    {
36033965Sjdp      bfd_nonfatal (filename);
36133965Sjdp      return_code = 1;
36233965Sjdp      return;
36333965Sjdp    }
36433965Sjdp}
36533965Sjdp
36633965Sjdp/* This is what lexical functions are for.  */
36733965Sjdp
36838889Sjdpstatic int
36938889Sjdpsize_number (num)
37038889Sjdp     bfd_size_type num;
37138889Sjdp{
37238889Sjdp  char buffer[40];
37389857Sobrien
37438889Sjdp  sprintf (buffer,
37538889Sjdp	   (radix == decimal ? "%lu" :
37638889Sjdp	   ((radix == octal) ? "0%lo" : "0x%lx")),
37738889Sjdp	   (unsigned long) num);
37838889Sjdp
37938889Sjdp  return strlen (buffer);
38038889Sjdp}
38138889Sjdp
38238889Sjdp#if 0
38338889Sjdp
38438889Sjdp/* This is not used.  */
38538889Sjdp
38633965Sjdpstatic void
38733965Sjdplprint_number (width, num)
38833965Sjdp     int width;
38933965Sjdp     bfd_size_type num;
39033965Sjdp{
39138889Sjdp  char buffer[40];
39289857Sobrien
39338889Sjdp  sprintf (buffer,
39438889Sjdp	   (radix == decimal ? "%lu" :
39538889Sjdp	   ((radix == octal) ? "0%lo" : "0x%lx")),
39638889Sjdp	   (unsigned long) num);
39738889Sjdp
39838889Sjdp  printf ("%-*s", width, buffer);
39933965Sjdp}
40033965Sjdp
40138889Sjdp#endif
40238889Sjdp
40333965Sjdpstatic void
40433965Sjdprprint_number (width, num)
40533965Sjdp     int width;
40633965Sjdp     bfd_size_type num;
40733965Sjdp{
40838889Sjdp  char buffer[40];
40989857Sobrien
41038889Sjdp  sprintf (buffer,
41138889Sjdp	   (radix == decimal ? "%lu" :
41238889Sjdp	   ((radix == octal) ? "0%lo" : "0x%lx")),
41338889Sjdp	   (unsigned long) num);
41438889Sjdp
41538889Sjdp  printf ("%*s", width, buffer);
41633965Sjdp}
41733965Sjdp
41833965Sjdpstatic bfd_size_type bsssize;
41933965Sjdpstatic bfd_size_type datasize;
42033965Sjdpstatic bfd_size_type textsize;
42133965Sjdp
42233965Sjdpstatic void
42333965Sjdpberkeley_sum (abfd, sec, ignore)
42460484Sobrien     bfd *abfd ATTRIBUTE_UNUSED;
42533965Sjdp     sec_ptr sec;
42660484Sobrien     PTR ignore ATTRIBUTE_UNUSED;
42733965Sjdp{
42833965Sjdp  flagword flags;
42933965Sjdp  bfd_size_type size;
43033965Sjdp
43133965Sjdp  flags = bfd_get_section_flags (abfd, sec);
43233965Sjdp  if ((flags & SEC_ALLOC) == 0)
43333965Sjdp    return;
43433965Sjdp
43533965Sjdp  size = bfd_get_section_size_before_reloc (sec);
43633965Sjdp  if ((flags & SEC_CODE) != 0 || (flags & SEC_READONLY) != 0)
43733965Sjdp    textsize += size;
43833965Sjdp  else if ((flags & SEC_HAS_CONTENTS) != 0)
43933965Sjdp    datasize += size;
44033965Sjdp  else
44133965Sjdp    bsssize += size;
44233965Sjdp}
44333965Sjdp
44433965Sjdpstatic void
44533965Sjdpprint_berkeley_format (abfd)
44633965Sjdp     bfd *abfd;
44733965Sjdp{
44833965Sjdp  static int files_seen = 0;
44933965Sjdp  bfd_size_type total;
45033965Sjdp
45133965Sjdp  bsssize = 0;
45233965Sjdp  datasize = 0;
45333965Sjdp  textsize = 0;
45433965Sjdp
45533965Sjdp  bfd_map_over_sections (abfd, berkeley_sum, (PTR) NULL);
45633965Sjdp
45733965Sjdp  if (files_seen++ == 0)
45833965Sjdp#if 0
45933965Sjdp    /* Intel doesn't like bss/stk because they don't have core files.  */
46038889Sjdp    puts ((radix == octal) ? "   text\t   data\tbss/stk\t    oct\t    hex\tfilename" :
46138889Sjdp	  "   text\t   data\tbss/stk\t    dec\t    hex\tfilename");
46233965Sjdp#else
46338889Sjdp    puts ((radix == octal) ? "   text\t   data\t    bss\t    oct\t    hex\tfilename" :
46438889Sjdp	  "   text\t   data\t    bss\t    dec\t    hex\tfilename");
46533965Sjdp#endif
46633965Sjdp
46733965Sjdp  total = textsize + datasize + bsssize;
46833965Sjdp
46989857Sobrien  if (show_totals)
47089857Sobrien    {
47189857Sobrien      total_textsize += textsize;
47289857Sobrien      total_datasize += datasize;
47389857Sobrien      total_bsssize  += bsssize;
47489857Sobrien    }
47589857Sobrien
47638889Sjdp  rprint_number (7, textsize);
47738889Sjdp  putchar ('\t');
47838889Sjdp  rprint_number (7, datasize);
47938889Sjdp  putchar ('\t');
48038889Sjdp  rprint_number (7, bsssize);
48138889Sjdp  printf (((radix == octal) ? "\t%7lo\t%7lx\t" : "\t%7lu\t%7lx\t"),
48233965Sjdp	  (unsigned long) total, (unsigned long) total);
48333965Sjdp
48433965Sjdp  fputs (bfd_get_filename (abfd), stdout);
48589857Sobrien
48633965Sjdp  if (bfd_my_archive (abfd))
48733965Sjdp    printf (" (ex %s)", bfd_get_filename (bfd_my_archive (abfd)));
48833965Sjdp}
48933965Sjdp
49033965Sjdp/* I REALLY miss lexical functions! */
49133965Sjdpbfd_size_type svi_total = 0;
49238889Sjdpbfd_vma svi_maxvma = 0;
49338889Sjdpint svi_namelen = 0;
49438889Sjdpint svi_vmalen = 0;
49538889Sjdpint svi_sizelen = 0;
49633965Sjdp
49733965Sjdpstatic void
49838889Sjdpsysv_internal_sizer (file, sec, ignore)
49960484Sobrien     bfd *file ATTRIBUTE_UNUSED;
50038889Sjdp     sec_ptr sec;
50160484Sobrien     PTR ignore ATTRIBUTE_UNUSED;
50238889Sjdp{
50338889Sjdp  bfd_size_type size = bfd_section_size (file, sec);
50489857Sobrien
50589857Sobrien  if (   ! bfd_is_abs_section (sec)
50689857Sobrien      && ! bfd_is_com_section (sec)
50789857Sobrien      && ! bfd_is_und_section (sec))
50838889Sjdp    {
50938889Sjdp      int namelen = strlen (bfd_section_name (file, sec));
51089857Sobrien
51138889Sjdp      if (namelen > svi_namelen)
51238889Sjdp	svi_namelen = namelen;
51338889Sjdp
51438889Sjdp      svi_total += size;
51589857Sobrien
51638889Sjdp      if (bfd_section_vma (file, sec) > svi_maxvma)
51738889Sjdp	svi_maxvma = bfd_section_vma (file, sec);
51838889Sjdp    }
51938889Sjdp}
52038889Sjdp
52138889Sjdpstatic void
52233965Sjdpsysv_internal_printer (file, sec, ignore)
52360484Sobrien     bfd *file ATTRIBUTE_UNUSED;
52433965Sjdp     sec_ptr sec;
52560484Sobrien     PTR ignore ATTRIBUTE_UNUSED;
52633965Sjdp{
52733965Sjdp  bfd_size_type size = bfd_section_size (file, sec);
52889857Sobrien
52989857Sobrien  if (   ! bfd_is_abs_section (sec)
53089857Sobrien      && ! bfd_is_com_section (sec)
53189857Sobrien      && ! bfd_is_und_section (sec))
53233965Sjdp    {
53333965Sjdp      svi_total += size;
53433965Sjdp
53538889Sjdp      printf ("%-*s   ", svi_namelen, bfd_section_name (file, sec));
53638889Sjdp      rprint_number (svi_sizelen, size);
53738889Sjdp      printf ("   ");
53838889Sjdp      rprint_number (svi_vmalen, bfd_section_vma (file, sec));
53933965Sjdp      printf ("\n");
54033965Sjdp    }
54133965Sjdp}
54233965Sjdp
54333965Sjdpstatic void
54433965Sjdpprint_sysv_format (file)
54533965Sjdp     bfd *file;
54633965Sjdp{
54789857Sobrien  /* Size all of the columns.  */
54833965Sjdp  svi_total = 0;
54938889Sjdp  svi_maxvma = 0;
55038889Sjdp  svi_namelen = 0;
55138889Sjdp  bfd_map_over_sections (file, sysv_internal_sizer, (PTR) NULL);
55238889Sjdp  svi_vmalen = size_number ((bfd_size_type)svi_maxvma);
55389857Sobrien
55438889Sjdp  if ((size_t) svi_vmalen < sizeof ("addr") - 1)
55538889Sjdp    svi_vmalen = sizeof ("addr")-1;
55633965Sjdp
55738889Sjdp  svi_sizelen = size_number (svi_total);
55838889Sjdp  if ((size_t) svi_sizelen < sizeof ("size") - 1)
55938889Sjdp    svi_sizelen = sizeof ("size")-1;
56038889Sjdp
56138889Sjdp  svi_total = 0;
56233965Sjdp  printf ("%s  ", bfd_get_filename (file));
56389857Sobrien
56433965Sjdp  if (bfd_my_archive (file))
56533965Sjdp    printf (" (ex %s)", bfd_get_filename (bfd_my_archive (file)));
56633965Sjdp
56738889Sjdp  printf (":\n%-*s   %*s   %*s\n", svi_namelen, "section",
56838889Sjdp	  svi_sizelen, "size", svi_vmalen, "addr");
56989857Sobrien
57033965Sjdp  bfd_map_over_sections (file, sysv_internal_printer, (PTR) NULL);
57133965Sjdp
57238889Sjdp  printf ("%-*s   ", svi_namelen, "Total");
57338889Sjdp  rprint_number (svi_sizelen, svi_total);
57433965Sjdp  printf ("\n\n");
57533965Sjdp}
57633965Sjdp
57733965Sjdpstatic void
57833965Sjdpprint_sizes (file)
57933965Sjdp     bfd *file;
58033965Sjdp{
58133965Sjdp  if (berkeley_format)
58233965Sjdp    print_berkeley_format (file);
58333965Sjdp  else
58433965Sjdp    print_sysv_format (file);
58533965Sjdp}
586