determining code size

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

geoffrey.brown
Posts: 87
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 15 times

determining code size

Postby geoffrey.brown » Fri Sep 04, 2020 1:35 pm

The standard build optimizes code size by compiling functions into separate sections and then keeping only those parts of the binary that are actually used. This works great but I have a small technical problem -- is there a convenient way to to determine the contribution to code size of various modules ?

Geoffrey

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: determining code size

Postby Giovanni » Fri Sep 04, 2020 3:58 pm

You could make a customized linker script that loads modules into separate sections, at least the module you are measuring, I think it is possible. You should also disable GC, LTO and functions alignment for the estimation to make sense.

Giovanni

psyco
Posts: 21
Joined: Fri May 22, 2020 1:40 am
Been thanked: 11 times

Re: determining code size

Postby psyco » Fri Sep 04, 2020 11:48 pm

My go-to for function and global variable sizes is:

Code: Select all

arm-none-eabi-nm --print-size --size-sort build/ch.elf


If you use C++, add a -C for demangling. By default, the second column is size.

If your modules have a prefix to all functions, it should just be a bit of post-processing to get the numbers. Do note LTO can screw around with things (mainly combining functions).


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 22 guests