2022-01-02 06:30:17 +08:00
|
|
|
# Copyright (C) 1993-2022 Free Software Foundation, Inc.
|
1999-05-03 15:29:11 +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
|
1999-05-03 15:29:11 +08:00
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2005-05-08 22:17:41 +08:00
|
|
|
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
# Please email any bugs, comments, and/or additions to this file to:
|
|
|
|
# bug-dejagnu@prep.ai.mit.edu
|
|
|
|
|
|
|
|
# This file was written by Rob Savoye <rob@cygnus.com>
|
|
|
|
# and rewritten by Ian Lance Taylor <ian@cygnus.com>
|
|
|
|
|
|
|
|
if ![is_remote host] {
|
|
|
|
if {[which $SIZE] == 0} then {
|
|
|
|
perror "$SIZE does not exist"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send_user "Version [binutil_version $SIZE]"
|
|
|
|
|
|
|
|
|
|
|
|
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
|
2017-12-15 14:38:56 +08:00
|
|
|
fail "size (assembling)"
|
1999-05-03 15:29:11 +08:00
|
|
|
} else {
|
|
|
|
|
2017-12-15 14:38:56 +08:00
|
|
|
if [is_remote host] {
|
|
|
|
set testfile [remote_download host tmpdir/bintest.o]
|
|
|
|
} else {
|
|
|
|
set testfile tmpdir/bintest.o
|
|
|
|
}
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2017-12-15 14:38:56 +08:00
|
|
|
set dec "\[0-9\]+"
|
|
|
|
set hex "\[0-9a-fA-F\]+"
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2017-12-15 14:38:56 +08:00
|
|
|
# Test size with no arguments
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2017-12-15 14:38:56 +08:00
|
|
|
set got [binutils_run $SIZE "$SIZEFLAGS $testfile"]
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2017-12-15 14:38:56 +08:00
|
|
|
set want "($dec)\[ \]+($dec)\[ \]+($dec)\[ \]+($dec)\[ \]+($hex)\[ \]+${testfile}"
|
|
|
|
|
|
|
|
if ![regexp $want $got all text data bss dtot hextot] then {
|
1999-05-03 15:29:11 +08:00
|
|
|
fail "size (no arguments)"
|
|
|
|
} else {
|
2017-12-15 14:38:56 +08:00
|
|
|
if {$text < 8 || $data < 4} then {
|
|
|
|
# The z80-coff port defaults to a "binary" like output
|
|
|
|
# file format which does not include a data section.
|
|
|
|
setup_xfail "z80-*-coff"
|
|
|
|
fail "size (no arguments)"
|
|
|
|
} else {
|
|
|
|
pass "size (no arguments)"
|
|
|
|
}
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 14:38:56 +08:00
|
|
|
# Test size -A
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2017-12-15 14:38:56 +08:00
|
|
|
set got [binutils_run $SIZE "$SIZEFLAGS -A ${testfile}"]
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2019-11-21 18:14:54 +08:00
|
|
|
set want "${testfile}.*(text|TEXT|\\\$CODE\\\$|P)\[^\n\r\]*\[ \]($dec)\[ \]+$dec.*(\\.data|DATA|D_1)\[^\n\r\]*\[ \]($dec)\[ \]+$dec"
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2017-12-15 14:38:56 +08:00
|
|
|
if ![regexp $want $got all textname textsize dataname datasize] then {
|
1999-05-03 15:29:11 +08:00
|
|
|
fail "size -A"
|
|
|
|
} else {
|
2017-12-15 14:38:56 +08:00
|
|
|
verbose "text size: $textsize"
|
|
|
|
verbose "data size: $datasize"
|
|
|
|
if {$textsize < 8 || $datasize < 4} then {
|
|
|
|
fail "size -A"
|
|
|
|
} else {
|
|
|
|
pass "size -A"
|
|
|
|
}
|
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
|
|
|
|
|
|
|
# Test size -G
|
|
|
|
|
|
|
|
set got [binutils_run $SIZE "$SIZEFLAGS -G $testfile"]
|
|
|
|
|
|
|
|
set want "($dec)\[ \]+($dec)\[ \]+($dec)\[ \]+($dec)\[ \]+${testfile}"
|
|
|
|
|
|
|
|
if ![regexp $want $got all text data bss dtot hextot] then {
|
|
|
|
fail "size -G"
|
|
|
|
} else {
|
|
|
|
if {$text < 8 || $data < 4} then {
|
|
|
|
# The z80-coff port defaults to a "binary" like output
|
|
|
|
# file format which does not include a data section.
|
|
|
|
setup_xfail "z80-*-coff"
|
|
|
|
fail "size -G"
|
|
|
|
} else {
|
|
|
|
pass "size -G"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|