Skip to content

Conversation

@franc0is
Copy link
Member

@franc0is franc0is commented May 9, 2019

Add the first post in the "code size" series. This first post focuses on measuring code size, before optimizing.

@franc0is franc0is changed the title WIP - Code size post #1 New Post: Code size #1 May 10, 2019
Copy link
Member

@chrisc11 chrisc11 left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bss

Copy link
Member Author

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
Copy link
Member

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%

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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 ?

Copy link
Member Author

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
Copy link
Member

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

Copy link
Member Author

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
Copy link
Member

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 :(

Copy link
Member Author

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
Copy link
Member

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)

Copy link
Member Author

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

@franc0is franc0is merged commit 614a480 into master May 14, 2019
@franc0is franc0is deleted the code-size-1 branch May 14, 2019 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants