This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: sizeof(function) functionality
Have you considered just doing a gcc -Wl,M to ask the linker to
generate a link map? (Invoking ld directly, I give it the -M without
going through gcc.)
Admittedly, this works only for functions of global scope, so you'd
have to expose deeper functions for the duration of the measurement.
e.g. Four functions from a current map (sorted):
.text 0x00104ce0 0x230 obj/brt_led.o
0x00104ce0 leds
0x00104d68 init_led
0x00104de8 watchdog_timer
0x00104e18 timeout
.text 0x00104f10 0xdc obj/compatibility_stubs.o
The total size of the 4 is already given (0x230), and a few lines of
awk or perl can do 0x00104e18 - 0x00104de8 = 0x30, to show that
watchdog_timer is 48 bytes long. (bc for one-off, by hand)
To report on local-scope stuff, what about doing gcc -g (to include
debugging information), then objdump -S your_object_file, to provide
a nice listing like:
00104de8 <watchdog_timer>:
void watchdog_timer(void)
{
... // Assembler omitted, to spare the
// squeamish.
}
...
00104e18 <timeout>:
void timeout(void) // Timer interrupt handler.
{
...
}
A few seconds with bc gives the size of a particular function. Again,
a few lines of awk can report on function sizes for the whole
executable.
YMMV
Regards,
Erik