1999-05-03 15:29:11 +08:00
|
|
|
|
/* size.c -- report size of various sections of an executable file.
|
2019-01-01 18:31:27 +08:00
|
|
|
|
Copyright (C) 1991-2019 Free Software Foundation, Inc.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2002-01-25 23:37:04 +08:00
|
|
|
|
This file is part of GNU Binutils.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2002-01-25 23:37:04 +08:00
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-06 00:54:46 +08:00
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2002-01-25 23:37:04 +08:00
|
|
|
|
(at your option) any later version.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2002-01-25 23:37:04 +08:00
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2002-01-25 23:37:04 +08:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
2007-07-06 00:54:46 +08:00
|
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
|
MA 02110-1301, USA. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
/* Extensions/incompatibilities:
|
|
|
|
|
o - BSD output has filenames at the end.
|
|
|
|
|
o - BSD output can appear in different radicies.
|
|
|
|
|
o - SysV output has less redundant whitespace. Filename comes at end.
|
|
|
|
|
o - SysV output doesn't show VMA which is always the same as the PMA.
|
|
|
|
|
o - We also handle core files.
|
|
|
|
|
o - We also handle archives.
|
|
|
|
|
If you write shell scripts which manipulate this info then you may be
|
2002-01-25 23:37:04 +08:00
|
|
|
|
out of luck; there's no --compatibility or --pedantic option. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2007-04-26 22:47:00 +08:00
|
|
|
|
#include "sysdep.h"
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#include "bfd.h"
|
|
|
|
|
#include "libiberty.h"
|
2002-01-30 00:46:37 +08:00
|
|
|
|
#include "getopt.h"
|
2007-04-26 22:47:00 +08:00
|
|
|
|
#include "bucomm.h"
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
#ifndef BSD_DEFAULT
|
|
|
|
|
#define BSD_DEFAULT 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Program options. */
|
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
static enum
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
decimal, octal, hex
|
2002-01-25 23:37:04 +08:00
|
|
|
|
}
|
|
|
|
|
radix = decimal;
|
|
|
|
|
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
/* Select the desired output format. */
|
|
|
|
|
enum output_format
|
|
|
|
|
{
|
|
|
|
|
FORMAT_BERKLEY,
|
|
|
|
|
FORMAT_SYSV,
|
|
|
|
|
FORMAT_GNU
|
|
|
|
|
};
|
|
|
|
|
static enum output_format selected_output_format =
|
|
|
|
|
#if BSD_DEFAULT
|
|
|
|
|
FORMAT_BERKLEY
|
|
|
|
|
#else
|
|
|
|
|
FORMAT_SYSV
|
|
|
|
|
#endif
|
|
|
|
|
;
|
2005-04-29 08:03:33 +08:00
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
static int show_version = 0;
|
|
|
|
|
static int show_help = 0;
|
|
|
|
|
static int show_totals = 0;
|
|
|
|
|
static int show_common = 0;
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
static bfd_size_type common_size;
|
2002-01-25 23:37:04 +08:00
|
|
|
|
static bfd_size_type total_bsssize;
|
|
|
|
|
static bfd_size_type total_datasize;
|
|
|
|
|
static bfd_size_type total_textsize;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
/* Program exit status. */
|
2007-07-05 17:01:28 +08:00
|
|
|
|
static int return_code = 0;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
static char *target = NULL;
|
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
/* Forward declarations. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2003-09-14 20:20:17 +08:00
|
|
|
|
static void display_file (char *);
|
|
|
|
|
static void rprint_number (int, bfd_size_type);
|
|
|
|
|
static void print_sizes (bfd * file);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
static void
|
2003-09-14 20:20:17 +08:00
|
|
|
|
usage (FILE *stream, int status)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2002-01-24 00:12:56 +08:00
|
|
|
|
fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name);
|
|
|
|
|
fprintf (stream, _(" Displays the sizes of sections inside binary files\n"));
|
2002-05-24 08:33:36 +08:00
|
|
|
|
fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n"));
|
2002-01-24 00:12:56 +08:00
|
|
|
|
fprintf (stream, _(" The options are:\n\
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
-A|-B|-G --format={sysv|berkeley|gnu} Select output style (default is %s)\n\
|
2002-11-23 16:01:51 +08:00
|
|
|
|
-o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex\n\
|
2002-01-25 23:37:04 +08:00
|
|
|
|
-t --totals Display the total sizes (Berkeley only)\n\
|
2007-07-05 17:01:28 +08:00
|
|
|
|
--common Display total size for *COM* syms\n\
|
2002-01-24 00:12:56 +08:00
|
|
|
|
--target=<bfdname> Set the binary file format\n\
|
2005-10-04 03:37:44 +08:00
|
|
|
|
@<file> Read options from <file>\n\
|
2002-01-24 00:12:56 +08:00
|
|
|
|
-h --help Display this information\n\
|
|
|
|
|
-v --version Display the program's version\n\
|
|
|
|
|
\n"),
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#if BSD_DEFAULT
|
2002-01-24 00:12:56 +08:00
|
|
|
|
"berkeley"
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#else
|
2002-01-24 00:12:56 +08:00
|
|
|
|
"sysv"
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#endif
|
2002-01-24 00:12:56 +08:00
|
|
|
|
);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
list_supported_targets (program_name, stream);
|
2007-02-17 21:33:57 +08:00
|
|
|
|
if (REPORT_BUGS_TO[0] && status == 0)
|
2000-04-04 22:32:35 +08:00
|
|
|
|
fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
exit (status);
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
#define OPTION_FORMAT (200)
|
|
|
|
|
#define OPTION_RADIX (OPTION_FORMAT + 1)
|
|
|
|
|
#define OPTION_TARGET (OPTION_RADIX + 1)
|
|
|
|
|
|
2005-04-29 08:03:33 +08:00
|
|
|
|
static struct option long_options[] =
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2007-07-05 17:01:28 +08:00
|
|
|
|
{"common", no_argument, &show_common, 1},
|
|
|
|
|
{"format", required_argument, 0, OPTION_FORMAT},
|
|
|
|
|
{"radix", required_argument, 0, OPTION_RADIX},
|
|
|
|
|
{"target", required_argument, 0, OPTION_TARGET},
|
2002-01-25 23:37:04 +08:00
|
|
|
|
{"totals", no_argument, &show_totals, 1},
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{"version", no_argument, &show_version, 1},
|
|
|
|
|
{"help", no_argument, &show_help, 1},
|
|
|
|
|
{0, no_argument, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
2003-09-14 20:20:17 +08:00
|
|
|
|
int main (int, char **);
|
2001-12-18 16:22:30 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
int
|
2003-09-14 20:20:17 +08:00
|
|
|
|
main (int argc, char **argv)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
int temp;
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
|
|
|
|
|
setlocale (LC_MESSAGES, "");
|
2001-09-19 13:33:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
#if defined (HAVE_SETLOCALE)
|
|
|
|
|
setlocale (LC_CTYPE, "");
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#endif
|
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
|
textdomain (PACKAGE);
|
|
|
|
|
|
|
|
|
|
program_name = *argv;
|
|
|
|
|
xmalloc_set_program_name (program_name);
|
2015-01-22 01:37:23 +08:00
|
|
|
|
bfd_set_error_program_name (program_name);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2005-10-01 00:37:32 +08:00
|
|
|
|
expandargv (&argc, &argv);
|
|
|
|
|
|
2018-10-15 13:40:27 +08:00
|
|
|
|
if (bfd_init () != BFD_INIT_MAGIC)
|
|
|
|
|
fatal (_("fatal error: libbfd ABI mismatch"));
|
1999-05-03 15:29:11 +08:00
|
|
|
|
set_default_bfd_target ();
|
|
|
|
|
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
while ((c = getopt_long (argc, argv, "ABGHhVvdfotx", long_options,
|
1999-05-03 15:29:11 +08:00
|
|
|
|
(int *) 0)) != EOF)
|
|
|
|
|
switch (c)
|
|
|
|
|
{
|
2007-07-05 17:01:28 +08:00
|
|
|
|
case OPTION_FORMAT:
|
1999-05-03 15:29:11 +08:00
|
|
|
|
switch (*optarg)
|
|
|
|
|
{
|
|
|
|
|
case 'B':
|
|
|
|
|
case 'b':
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
selected_output_format = FORMAT_BERKLEY;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
break;
|
|
|
|
|
case 'S':
|
|
|
|
|
case 's':
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
selected_output_format = FORMAT_SYSV;
|
|
|
|
|
break;
|
|
|
|
|
case 'G':
|
|
|
|
|
case 'g':
|
|
|
|
|
selected_output_format = FORMAT_GNU;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2000-04-07 12:34:50 +08:00
|
|
|
|
non_fatal (_("invalid argument to --format: %s"), optarg);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
usage (stderr, 1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
case OPTION_TARGET:
|
1999-05-03 15:29:11 +08:00
|
|
|
|
target = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
case OPTION_RADIX:
|
1999-05-03 15:29:11 +08:00
|
|
|
|
#ifdef ANSI_LIBRARIES
|
|
|
|
|
temp = strtol (optarg, NULL, 10);
|
|
|
|
|
#else
|
|
|
|
|
temp = atol (optarg);
|
|
|
|
|
#endif
|
|
|
|
|
switch (temp)
|
|
|
|
|
{
|
|
|
|
|
case 10:
|
|
|
|
|
radix = decimal;
|
|
|
|
|
break;
|
|
|
|
|
case 8:
|
|
|
|
|
radix = octal;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
radix = hex;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2000-04-07 12:34:50 +08:00
|
|
|
|
non_fatal (_("Invalid radix: %s\n"), optarg);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
usage (stderr, 1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'A':
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
selected_output_format = FORMAT_SYSV;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
break;
|
|
|
|
|
case 'B':
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
selected_output_format = FORMAT_BERKLEY;
|
|
|
|
|
break;
|
|
|
|
|
case 'G':
|
|
|
|
|
selected_output_format = FORMAT_GNU;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
break;
|
2002-01-24 00:12:56 +08:00
|
|
|
|
case 'v':
|
1999-05-03 15:29:11 +08:00
|
|
|
|
case 'V':
|
|
|
|
|
show_version = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'd':
|
|
|
|
|
radix = decimal;
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
radix = hex;
|
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
|
|
|
|
radix = octal;
|
|
|
|
|
break;
|
2002-01-25 23:37:04 +08:00
|
|
|
|
case 't':
|
|
|
|
|
show_totals = 1;
|
|
|
|
|
break;
|
2000-05-14 18:40:48 +08:00
|
|
|
|
case 'f': /* FIXME : For sysv68, `-f' means `full format', i.e.
|
|
|
|
|
`[fname:] M(.text) + N(.data) + O(.bss) + P(.comment) = Q'
|
|
|
|
|
where `fname: ' appears only if there are >= 2 input files,
|
|
|
|
|
and M, N, O, P, Q are expressed in decimal by default,
|
|
|
|
|
hexa or octal if requested by `-x' or `-o'.
|
|
|
|
|
Just to make things interesting, Solaris also accepts -f,
|
|
|
|
|
which prints out the size of each allocatable section, the
|
|
|
|
|
name of the section, and the total of the section sizes. */
|
|
|
|
|
/* For the moment, accept `-f' silently, and ignore it. */
|
|
|
|
|
break;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
case 0:
|
|
|
|
|
break;
|
2002-01-24 00:12:56 +08:00
|
|
|
|
case 'h':
|
|
|
|
|
case 'H':
|
1999-05-03 15:29:11 +08:00
|
|
|
|
case '?':
|
|
|
|
|
usage (stderr, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (show_version)
|
|
|
|
|
print_version ("size");
|
|
|
|
|
if (show_help)
|
|
|
|
|
usage (stdout, 0);
|
|
|
|
|
|
|
|
|
|
if (optind == argc)
|
|
|
|
|
display_file ("a.out");
|
|
|
|
|
else
|
|
|
|
|
for (; optind < argc;)
|
|
|
|
|
display_file (argv[optind++]);
|
|
|
|
|
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
if (show_totals && (selected_output_format == FORMAT_BERKLEY
|
|
|
|
|
|| selected_output_format == FORMAT_GNU))
|
2002-01-25 23:37:04 +08:00
|
|
|
|
{
|
|
|
|
|
bfd_size_type total = total_textsize + total_datasize + total_bsssize;
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
int col_width = (selected_output_format == FORMAT_BERKLEY) ? 7 : 10;
|
|
|
|
|
char sep_char = (selected_output_format == FORMAT_BERKLEY) ? '\t' : ' ';
|
|
|
|
|
|
|
|
|
|
rprint_number (col_width, total_textsize);
|
|
|
|
|
putchar(sep_char);
|
|
|
|
|
rprint_number (col_width, total_datasize);
|
|
|
|
|
putchar(sep_char);
|
|
|
|
|
rprint_number (col_width, total_bsssize);
|
|
|
|
|
putchar(sep_char);
|
|
|
|
|
if (selected_output_format == FORMAT_BERKLEY)
|
|
|
|
|
printf (((radix == octal) ? "%7lo\t%7lx" : "%7lu\t%7lx"),
|
|
|
|
|
(unsigned long) total, (unsigned long) total);
|
|
|
|
|
else
|
|
|
|
|
rprint_number (col_width, total);
|
|
|
|
|
putchar(sep_char);
|
2002-01-25 23:37:04 +08:00
|
|
|
|
fputs ("(TOTALS)\n", stdout);
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
return return_code;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
/* Total size required for common symbols in ABFD. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
calculate_common_size (bfd *abfd)
|
|
|
|
|
{
|
|
|
|
|
asymbol **syms = NULL;
|
|
|
|
|
long storage, symcount;
|
|
|
|
|
|
|
|
|
|
common_size = 0;
|
|
|
|
|
if ((bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC | HAS_SYMS)) != HAS_SYMS)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
storage = bfd_get_symtab_upper_bound (abfd);
|
|
|
|
|
if (storage < 0)
|
|
|
|
|
bfd_fatal (bfd_get_filename (abfd));
|
|
|
|
|
if (storage)
|
2009-09-10 21:40:44 +08:00
|
|
|
|
syms = (asymbol **) xmalloc (storage);
|
2007-07-05 17:01:28 +08:00
|
|
|
|
|
|
|
|
|
symcount = bfd_canonicalize_symtab (abfd, syms);
|
|
|
|
|
if (symcount < 0)
|
|
|
|
|
bfd_fatal (bfd_get_filename (abfd));
|
|
|
|
|
|
|
|
|
|
while (--symcount >= 0)
|
|
|
|
|
{
|
|
|
|
|
asymbol *sym = syms[symcount];
|
|
|
|
|
|
|
|
|
|
if (bfd_is_com_section (sym->section)
|
|
|
|
|
&& (sym->flags & BSF_SECTION_SYM) == 0)
|
|
|
|
|
common_size += sym->value;
|
|
|
|
|
}
|
|
|
|
|
free (syms);
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
/* Display stats on file or archive member ABFD. */
|
|
|
|
|
|
|
|
|
|
static void
|
2003-09-14 20:20:17 +08:00
|
|
|
|
display_bfd (bfd *abfd)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
char **matching;
|
|
|
|
|
|
|
|
|
|
if (bfd_check_format (abfd, bfd_archive))
|
|
|
|
|
/* An archive within an archive. */
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (bfd_check_format_matches (abfd, bfd_object, &matching))
|
|
|
|
|
{
|
|
|
|
|
print_sizes (abfd);
|
|
|
|
|
printf ("\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
|
|
|
|
|
{
|
|
|
|
|
bfd_nonfatal (bfd_get_filename (abfd));
|
|
|
|
|
list_matching_formats (matching);
|
|
|
|
|
free (matching);
|
|
|
|
|
return_code = 3;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bfd_check_format_matches (abfd, bfd_core, &matching))
|
|
|
|
|
{
|
2002-01-25 23:37:04 +08:00
|
|
|
|
const char *core_cmd;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
print_sizes (abfd);
|
|
|
|
|
fputs (" (core file", stdout);
|
|
|
|
|
|
|
|
|
|
core_cmd = bfd_core_file_failing_command (abfd);
|
|
|
|
|
if (core_cmd)
|
|
|
|
|
printf (" invoked as %s", core_cmd);
|
|
|
|
|
|
|
|
|
|
puts (")\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bfd_nonfatal (bfd_get_filename (abfd));
|
|
|
|
|
|
|
|
|
|
if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
|
|
|
|
|
{
|
|
|
|
|
list_matching_formats (matching);
|
|
|
|
|
free (matching);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return_code = 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-09-14 20:20:17 +08:00
|
|
|
|
display_archive (bfd *file)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
bfd *arfile = (bfd *) NULL;
|
2002-05-04 09:31:50 +08:00
|
|
|
|
bfd *last_arfile = (bfd *) NULL;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
bfd_set_error (bfd_error_no_error);
|
|
|
|
|
|
|
|
|
|
arfile = bfd_openr_next_archived_file (file, arfile);
|
|
|
|
|
if (arfile == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (bfd_get_error () != bfd_error_no_more_archived_files)
|
|
|
|
|
{
|
|
|
|
|
bfd_nonfatal (bfd_get_filename (file));
|
|
|
|
|
return_code = 2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
display_bfd (arfile);
|
2002-05-04 09:31:50 +08:00
|
|
|
|
|
|
|
|
|
if (last_arfile != NULL)
|
2015-01-06 07:13:50 +08:00
|
|
|
|
{
|
|
|
|
|
bfd_close (last_arfile);
|
|
|
|
|
|
|
|
|
|
/* PR 17512: file: a244edbc. */
|
|
|
|
|
if (last_arfile == arfile)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-04 09:31:50 +08:00
|
|
|
|
last_arfile = arfile;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
2002-05-04 09:31:50 +08:00
|
|
|
|
|
|
|
|
|
if (last_arfile != NULL)
|
|
|
|
|
bfd_close (last_arfile);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-09-14 20:20:17 +08:00
|
|
|
|
display_file (char *filename)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2003-11-07 20:19:34 +08:00
|
|
|
|
bfd *file;
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
2003-11-07 20:19:34 +08:00
|
|
|
|
if (get_file_size (filename) < 1)
|
2006-08-06 23:49:46 +08:00
|
|
|
|
{
|
|
|
|
|
return_code = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-11-07 20:19:34 +08:00
|
|
|
|
|
|
|
|
|
file = bfd_openr (filename, target);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (file == NULL)
|
|
|
|
|
{
|
|
|
|
|
bfd_nonfatal (filename);
|
|
|
|
|
return_code = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-30 16:39:46 +08:00
|
|
|
|
if (bfd_check_format (file, bfd_archive))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
display_archive (file);
|
|
|
|
|
else
|
|
|
|
|
display_bfd (file);
|
|
|
|
|
|
2002-11-30 16:39:46 +08:00
|
|
|
|
if (!bfd_close (file))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
bfd_nonfatal (filename);
|
|
|
|
|
return_code = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2003-09-14 20:20:17 +08:00
|
|
|
|
size_number (bfd_size_type num)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
char buffer[40];
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
sprintf (buffer,
|
2008-07-28 12:07:32 +08:00
|
|
|
|
(radix == decimal ? "%" BFD_VMA_FMT "u" :
|
|
|
|
|
((radix == octal) ? "0%" BFD_VMA_FMT "o" : "0x%" BFD_VMA_FMT "x")),
|
|
|
|
|
num);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
return strlen (buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-09-14 20:20:17 +08:00
|
|
|
|
rprint_number (int width, bfd_size_type num)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
char buffer[40];
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
sprintf (buffer,
|
2008-07-28 12:07:32 +08:00
|
|
|
|
(radix == decimal ? "%" BFD_VMA_FMT "u" :
|
|
|
|
|
((radix == octal) ? "0%" BFD_VMA_FMT "o" : "0x%" BFD_VMA_FMT "x")),
|
|
|
|
|
num);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
printf ("%*s", width, buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bfd_size_type bsssize;
|
|
|
|
|
static bfd_size_type datasize;
|
|
|
|
|
static bfd_size_type textsize;
|
|
|
|
|
|
|
|
|
|
static void
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
berkeley_or_gnu_sum (bfd *abfd ATTRIBUTE_UNUSED, sec_ptr sec,
|
|
|
|
|
void *ignore ATTRIBUTE_UNUSED)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
flagword flags;
|
|
|
|
|
bfd_size_type size;
|
|
|
|
|
|
|
|
|
|
flags = bfd_get_section_flags (abfd, sec);
|
|
|
|
|
if ((flags & SEC_ALLOC) == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2004-06-15 09:19:13 +08:00
|
|
|
|
size = bfd_get_section_size (sec);
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
if ((flags & SEC_CODE) != 0
|
|
|
|
|
|| (selected_output_format == FORMAT_BERKLEY
|
|
|
|
|
&& (flags & SEC_READONLY) != 0))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
textsize += size;
|
|
|
|
|
else if ((flags & SEC_HAS_CONTENTS) != 0)
|
|
|
|
|
datasize += size;
|
|
|
|
|
else
|
|
|
|
|
bsssize += size;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-24 08:33:36 +08:00
|
|
|
|
static void
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
print_berkeley_or_gnu_format (bfd *abfd)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
static int files_seen = 0;
|
|
|
|
|
bfd_size_type total;
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
int col_width = (selected_output_format == FORMAT_BERKLEY) ? 7 : 10;
|
|
|
|
|
char sep_char = (selected_output_format == FORMAT_BERKLEY) ? '\t' : ' ';
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
bsssize = 0;
|
|
|
|
|
datasize = 0;
|
|
|
|
|
textsize = 0;
|
|
|
|
|
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
bfd_map_over_sections (abfd, berkeley_or_gnu_sum, NULL);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
bsssize += common_size;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (files_seen++ == 0)
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
{
|
|
|
|
|
if (selected_output_format == FORMAT_BERKLEY)
|
|
|
|
|
puts ((radix == octal) ? " text\t data\t bss\t oct\t hex\tfilename" :
|
|
|
|
|
" text\t data\t bss\t dec\t hex\tfilename");
|
|
|
|
|
else
|
|
|
|
|
puts (" text data bss total filename");
|
|
|
|
|
}
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
total = textsize + datasize + bsssize;
|
|
|
|
|
|
2002-01-25 23:37:04 +08:00
|
|
|
|
if (show_totals)
|
|
|
|
|
{
|
|
|
|
|
total_textsize += textsize;
|
|
|
|
|
total_datasize += datasize;
|
|
|
|
|
total_bsssize += bsssize;
|
|
|
|
|
}
|
|
|
|
|
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
rprint_number (col_width, textsize);
|
|
|
|
|
putchar (sep_char);
|
|
|
|
|
rprint_number (col_width, datasize);
|
|
|
|
|
putchar (sep_char);
|
|
|
|
|
rprint_number (col_width, bsssize);
|
|
|
|
|
putchar (sep_char);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
if (selected_output_format == FORMAT_BERKLEY)
|
|
|
|
|
printf (((radix == octal) ? "%7lo\t%7lx" : "%7lu\t%7lx"),
|
|
|
|
|
(unsigned long) total, (unsigned long) total);
|
|
|
|
|
else
|
|
|
|
|
rprint_number (col_width, total);
|
|
|
|
|
|
|
|
|
|
putchar (sep_char);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
fputs (bfd_get_filename (abfd), stdout);
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
2016-06-14 11:54:37 +08:00
|
|
|
|
if (abfd->my_archive)
|
|
|
|
|
printf (" (ex %s)", bfd_get_filename (abfd->my_archive));
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* I REALLY miss lexical functions! */
|
|
|
|
|
bfd_size_type svi_total = 0;
|
|
|
|
|
bfd_vma svi_maxvma = 0;
|
|
|
|
|
int svi_namelen = 0;
|
|
|
|
|
int svi_vmalen = 0;
|
|
|
|
|
int svi_sizelen = 0;
|
|
|
|
|
|
|
|
|
|
static void
|
2003-09-14 20:20:17 +08:00
|
|
|
|
sysv_internal_sizer (bfd *file ATTRIBUTE_UNUSED, sec_ptr sec,
|
|
|
|
|
void *ignore ATTRIBUTE_UNUSED)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
bfd_size_type size = bfd_section_size (file, sec);
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
|
|
|
|
if ( ! bfd_is_abs_section (sec)
|
|
|
|
|
&& ! bfd_is_com_section (sec)
|
|
|
|
|
&& ! bfd_is_und_section (sec))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
int namelen = strlen (bfd_section_name (file, sec));
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (namelen > svi_namelen)
|
|
|
|
|
svi_namelen = namelen;
|
|
|
|
|
|
|
|
|
|
svi_total += size;
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if (bfd_section_vma (file, sec) > svi_maxvma)
|
|
|
|
|
svi_maxvma = bfd_section_vma (file, sec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
static void
|
|
|
|
|
sysv_one_line (const char *name, bfd_size_type size, bfd_vma vma)
|
|
|
|
|
{
|
|
|
|
|
printf ("%-*s ", svi_namelen, name);
|
|
|
|
|
rprint_number (svi_sizelen, size);
|
|
|
|
|
printf (" ");
|
|
|
|
|
rprint_number (svi_vmalen, vma);
|
|
|
|
|
printf ("\n");
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
static void
|
2003-09-14 20:20:17 +08:00
|
|
|
|
sysv_internal_printer (bfd *file ATTRIBUTE_UNUSED, sec_ptr sec,
|
|
|
|
|
void *ignore ATTRIBUTE_UNUSED)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
bfd_size_type size = bfd_section_size (file, sec);
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
|
|
|
|
if ( ! bfd_is_abs_section (sec)
|
|
|
|
|
&& ! bfd_is_com_section (sec)
|
|
|
|
|
&& ! bfd_is_und_section (sec))
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
|
|
|
|
svi_total += size;
|
|
|
|
|
|
2007-07-05 17:01:28 +08:00
|
|
|
|
sysv_one_line (bfd_section_name (file, sec),
|
|
|
|
|
size,
|
|
|
|
|
bfd_section_vma (file, sec));
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-09-14 20:20:17 +08:00
|
|
|
|
print_sysv_format (bfd *file)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2002-01-25 23:37:04 +08:00
|
|
|
|
/* Size all of the columns. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
svi_total = 0;
|
|
|
|
|
svi_maxvma = 0;
|
|
|
|
|
svi_namelen = 0;
|
2003-09-14 20:20:17 +08:00
|
|
|
|
bfd_map_over_sections (file, sysv_internal_sizer, NULL);
|
2007-07-05 17:01:28 +08:00
|
|
|
|
if (show_common)
|
|
|
|
|
{
|
|
|
|
|
if (svi_namelen < (int) sizeof ("*COM*") - 1)
|
|
|
|
|
svi_namelen = sizeof ("*COM*") - 1;
|
|
|
|
|
svi_total += common_size;
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
svi_vmalen = size_number ((bfd_size_type)svi_maxvma);
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
|
if ((size_t) svi_vmalen < sizeof ("addr") - 1)
|
|
|
|
|
svi_vmalen = sizeof ("addr")-1;
|
|
|
|
|
|
|
|
|
|
svi_sizelen = size_number (svi_total);
|
|
|
|
|
if ((size_t) svi_sizelen < sizeof ("size") - 1)
|
|
|
|
|
svi_sizelen = sizeof ("size")-1;
|
|
|
|
|
|
|
|
|
|
svi_total = 0;
|
|
|
|
|
printf ("%s ", bfd_get_filename (file));
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
2016-06-14 11:54:37 +08:00
|
|
|
|
if (file->my_archive)
|
|
|
|
|
printf (" (ex %s)", bfd_get_filename (file->my_archive));
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
printf (":\n%-*s %*s %*s\n", svi_namelen, "section",
|
|
|
|
|
svi_sizelen, "size", svi_vmalen, "addr");
|
2002-01-25 23:37:04 +08:00
|
|
|
|
|
2003-09-14 20:20:17 +08:00
|
|
|
|
bfd_map_over_sections (file, sysv_internal_printer, NULL);
|
2007-07-05 17:01:28 +08:00
|
|
|
|
if (show_common)
|
|
|
|
|
{
|
|
|
|
|
svi_total += common_size;
|
|
|
|
|
sysv_one_line ("*COM*", common_size, 0);
|
|
|
|
|
}
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
|
|
printf ("%-*s ", svi_namelen, "Total");
|
|
|
|
|
rprint_number (svi_sizelen, svi_total);
|
|
|
|
|
printf ("\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-09-14 20:20:17 +08:00
|
|
|
|
print_sizes (bfd *file)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
{
|
2007-07-05 17:01:28 +08:00
|
|
|
|
if (show_common)
|
|
|
|
|
calculate_common_size (file);
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
if (selected_output_format == FORMAT_SYSV)
|
1999-05-03 15:29:11 +08:00
|
|
|
|
print_sysv_format (file);
|
binutils: Add new GNU format mode to `size` utility
The size tool currently defaults to berkeley format output. However,
this output format has a weird quirk, read-only data is counted
against the text sections, not the data sections.
The code offers no real explanation for why this is, but I'm reluctant
to change it for two reasons, first, I'm assuming it probably makes
sense in some case that I'm not thinking of (maybe a target where
sections are not marked executable, and so there's no distinction
between read-only data and code), and second, the code has been this
way for at least 20 years, I worry that changing things now might
cause more confusion than it solves.
This commit then introduces a new output format for the size tool,
this new format displays the results in a similar manor to the
berkeley format, but counts read-only data in the data column, and
only executable sections are counted in the text column.
Given that this is a brand new output format I've gone ahead and
simplified things a little, while the berkeley format displays the
total twice, once in decimal and once in hex, the new display format
just displays the total in decimal. Of course, there's still the
'--radix' option which can be used to display all the results in
hexadecimal or octal.
I've called the new format 'gnu', so '--format=gnu' or '-G' are used
to access it.
binutils/ChangeLog:
* size.c (berkeley_format): Delete.
(enum output_format): New enum.
(selected_output_format): New variable.
(usage): Update to mention GNU format.
(main): Update to extract options, and select format as needed.
Handle GNU format where needed.
(berkeley_sum): Renamed to...
(berkeley_or_gnu_sum): ...this, and updated to handle both formats.
(berkeley_format): Renamed to...
(berkeley_or_gnu_format): ...this, and updated to handle both
formats.
(print_sizes): Handle GNU format.
* doc/binutils.texi (size): Document new GNU format.
* testsuite/binutils-all/size.exp: Add test of extended
functionality.
* NEWS: Mention new functionality.
2019-01-24 22:27:27 +08:00
|
|
|
|
else
|
|
|
|
|
print_berkeley_or_gnu_format (file);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
}
|