-
Notifications
You must be signed in to change notification settings - Fork 145
New Post: Code size #1 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
| So in this program we have: | ||
| * 10800 bytes of `text`, which is code | ||
| * 104 bytes of `data`, which is statically initalized memory | ||
| * 8272 bytes of `bcc`, which is zero-initialized memory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂
|
|
||
| ### Measuring overall code size | ||
|
|
||
| The simplest way to measure code size is to inspect the different sections of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-Wl,--print-memory-usage is pretty cool too. Suffers the fate of data being lumped into ram count but at link you get something like:
Memory region Used Size Region Size %age Used
rom: 10800 B 256 KB 4.12%
ram: 8376 B 32 KB 25.56%
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note, though this is an inferior solution to size because you cannot compute your actual ROM usage from this output, since it does not break out data vs. bss
| To avoid confusion, I prefer to use a small script to compute the sizes: | ||
|
|
||
| ```bash | ||
| #!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAYBE: Might be neat to publish a python package that does this type of thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be ~1 day of work
| 00000430 00000692 t _usart_set_config | ||
| ``` | ||
|
|
||
| Here we see that our largest symbol is `_usart_set_config` which is takes 692 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is takes -> takes up or uses ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| do: | ||
|
|
||
| ```terminal | ||
| francois-mba:with-libc francois$ arm-none-eabi-nm --print-size --size-sort --radix=d build/with-libc.elf | tail -30 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAYBE: -l is nice to tack on too for line info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note, but didn't copy the output as it gets quite messy.
|
|
||
| Now open your favorite web browser at localhost:5000, and enjoy! | ||
|
|
||
| Note: You may notice that some code size will be attributed to symbols under |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically the newlib bundled with gcc doesn't build with -g fwiw :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note!
| information. As such, you'll need to make sure you've got the following CFLAGS | ||
| set: | ||
|
|
||
| * `-g`: this generates debug information which puncover requires for analysis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
puncover doesn't need it but you get some extra goodies (like macro definitions) in elf when you use -g3 (default level is 2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not going to add that here
Add the first post in the "code size" series. This first post focuses on measuring code size, before optimizing.