-
Notifications
You must be signed in to change notification settings - Fork 3k
Compiler profiles for size optimization #2973
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
Compiler profiles for size optimization #2973
Conversation
The default profile in mbed-os optimizes for size on GCC byt for speed on ARMCC and IAR. Add a profile which optimizes for size on all compilers. This file is just a copy of default.json with the different optimization targets. Before (ARMCC, default.json): Total Static RAM memory (data + bss): 72112 bytes Total RAM memory (data + bss + heap + stack): 72112 bytes Total Flash memory (text + data + misc): 358112 bytes After (ARMCC, size.json): Total Static RAM memory (data + bss): 72112 bytes Total RAM memory (data + bss + heap + stack): 72112 bytes Total Flash memory (text + data + misc): 314359 bytes Before (IAR, default.json): Total Static RAM memory (data + bss): 70088 bytes Total RAM memory (data + bss + heap + stack): 168392 bytes Total Flash memory (text + data + misc): 309739 bytes After (IAR, size.json) Total Static RAM memory (data + bss): 70092 bytes Total RAM memory (data + bss + heap + stack): 168396 bytes Total Flash memory (text + data + misc): 290523 bytes
…bled On some cases the mbed-os's debug profile is unusable, as it disables all optimizations to get best possible debugging environment which may make the code too big to actually fit into system. This new profile is based on the debug.json, but it enables the lowest level of compiler optimizations along with the debug flag. Debugging with this may not be optimal, but on some cases it is actually possible at all. Before (GCC 5.4.1, debug.json): Total Static RAM memory (data + bss): 74144 bytes Total RAM memory (data + bss + heap + stack): 139684 bytes Total Flash memory (text + data + misc): 598554 bytes After (GCC 5.4.1, debug_size.json): Total Static RAM memory (data + bss): 73624 bytes Total RAM memory (data + bss + heap + stack): 139164 bytes Total Flash memory (text + data + misc): 392197 bytes Before (ARMCC 5.06u3, debug.json): Total Static RAM memory (data + bss): 72100 bytes Total RAM memory (data + bss + heap + stack): 72100 bytes Total Flash memory (text + data + misc): 412428 bytes After (ARMCC 5.06u3, debug_size.json): Static RAM memory (data + bss): 72112 bytes Total RAM memory (data + bss + heap + stack): 72112 bytes Total Flash memory (text + data + misc): 334792 bytes Before (IAR, debug.json): Total Static RAM memory (data + bss): 70115 bytes Total RAM memory (data + bss + heap + stack): 168419 bytes Total Flash memory (text + data + misc): 407543 bytes After (IAR, debug_size.json): Total Static RAM memory (data + bss): 70115 bytes Total RAM memory (data + bss + heap + stack): 168419 bytes Total Flash memory (text + data + misc): 377093 bytes
As a side note, the debug build compiled with ARMCC for K64F fails to load properly by gdb, but binary still does work without debugger. The same happens with stock debug.json and the cloned debug-size.json. Gdb shows this warning when it starts: |
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.
It seems fine to me.
The only question I have is the default setting for GCC_ARM already optimizes for size. Does anyone have concerns about this causing confusion?
This is a good start. We need some docs about the design principles behind each one and a second set of eyes that the right settings are chosen across the toolchains. Dont want to see people flipping these back and forth. If needed local profiles can be used rather than a collection of similar but different ones. @c1728p9 |
Something like |
The debug-size kind of profile is something that we need every time a debug session is needed. IMHO, it truely should be part of mbed os, as the problem is same on many real world applications which do their best to add as much as features as ROM allows. |
@TeroJaasko Can you review referenced PR by @c1728p9 please? And agree if that one makes sense and this one will be an addition ? Or ? |
The profiles look good to me. Please address @c1728p9. I'm up for the size profile. Note that the more profiles we have, the more confusing it would get. |
This looks ready. Can we get this merged ? |
@TeroJaasko @c1728p9 @teetak01 Please work together to get this and #3005 unified. Less profiles are better and local profiles should be encouraged. Profiles without docs and description statement are not helpful. Next we'll see samgro01-profile.json checked in and so on. Also, need verification that the flags are profiles are best picked across each toolchain. Report of build output for each would be nice. |
@@ -0,0 +1,44 @@ | |||
{ |
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.
Size doesn't really imply big or small. Maybe rename this file to small.json
or something which implies that this is smaller than the default?
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.
These profiles need docs. Feel free to pull the DOCs from pr #3005.
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin", | ||
"-ffunction-sections", "-fdata-sections", "-funsigned-char", | ||
"-MMD", "-fno-delete-null-pointer-checks", | ||
"-fomit-frame-pointer", "-O1", "-g"], |
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.
With -O1
the optimization level is changed from the size.json configuration. This is one more configuration to verify. I would recommend sticking with just one size profile.
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin", | ||
"-ffunction-sections", "-fdata-sections", "-funsigned-char", | ||
"-MMD", "-fno-delete-null-pointer-checks", | ||
"-fomit-frame-pointer", "-O1", "-g"], |
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.
I believe the reason debug symbols aren't turn on in all configurations is because this increases build sizes too much for testing and the online IDE. @screamerbg, @bridadan or @0xc0170 can you confirm this? If debug symbols could be turned on/off independent of the profile the each of the profiles wouldn't need have a corresponding "debug-*" profile to add symbols. This would be especially useful if the binary output doesn't change (which it shouldn't).
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.
@c1728p9 That's correct. Good catch!
@TeroJaasko can you please work with @c1728p9 to get comments resolved or close this out and make requests against #3005 |
Description
This pull request adds two new compiler profiles, one for size optimization for release builds and one for minimally optimized debug build.
Status
READY/IN DEVELOPMENT/HOLD
Migrations
If this PR changes any APIs or behaviors, give a short description of what API users should do when this PR is merged.
NO
Related PRs
List related PRs against other branches:
Todos
Deploy notes
Steps to test or reproduce
mbed compile -m K64F -t ARM --profile mbed-os/tools/profiles/size.json
mbed compile -m K64F -t GCC_ARM --profile mbed-os/tools/profiles/debug-size.json