-
Notifications
You must be signed in to change notification settings - Fork 9
ports/nrf: Enable Link-time optimizations #118
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
Great, thanks Ayke! Ref posts on Nordic dev zone like this one: It also looks like people have been struggling getting debug symbols when using -00, due to -flto stripping out the debug symbols. Would it be an idea to only add this -flto to targets using -0s ? @tralamazza do you have any insight here? i see you have responded to the specific dev-zone question I've linked to. |
@glennrub pointed me here and asked me to share some space-saving tips I had shared with him. @tannewt and I are working on CircuitPython for Adafruit, a fork of MicroPython. Our main work is for SAMD21 (M0+) and SAMD51 (M4F). We use Scott initiated using We have also saved space by judicious use of the gcc flag We also found we were able to save a lot of space by using the For M4F, will may not save as much space, since the software implementations of single precision will not be needed, and the double-precision routines will be smaller. But I just tested the SAMD51 (M4F) port by turning Some PRs and issues of ours with more details (also see the referenced issues): adafruit#118 (LTO caused a bug-inducing rearrangment of something that should have been 32-bit-aligned but was not). Math-related: |
The only issues I ever had with lto was regarding weak symbols |
I had another try today with hints from this post (adding a few more @glennrub I compiled with all default flags otherwise which includes -Os, I think it's unrelated. @dhalbert thanks for all the ideas! We don't use floating point in this port so I doubt switching libm will help. @tralamazza good point, should try to replace those weak symbols. But then again, it works fine without SD so it can't (?) be the ISR vector. Another (unrelated) space saver I want to try is storing code/data in the first page, after the ISR pointers (just like stm32 does). That's about 800 bytes on the nRF51 but nearly 4k on nRF52 (I think). |
I noticed it does work with SD enabled (at least I get a REPL) when I first write firmware.hex and then write the SoftDevice itself. When I again write firmware.hex it hits the HardFault again on startup. So it appears that I didn't get very far using gdb. |
Ok, I made a mistake. I flashed the .elf file instead of the .hex file, which apparently resulted in overwriting some critical flash area. Flashing the .hex file solves the problem (verify_image in OpenOCD shows that both SD and firmware are properly flashed, without overwriting each other). I've also done a quick test for BLE: enabling advertising via the serial console and enabling the BLE console both work. So that means that after nRF52 is tested, I think it can be merged. |
Ah, i see. That could explain it! At the moment i'm not able to test the nrf52 target because i'm out travelling this week. I'll try to perform a test this weekend, unless someone else verifies the nrf52 target before that. Code-wise i do not see anything that should block this PR. |
Looks good to me! I tried it with a nrf52 target (pca10040), and as well with microbit just to log some numbers on memory. I froze ublupy_eddystone.py and connected over BLE REPL (nus_console), then forked the eddystone example over the BLE link. microbit: bluetooth_conf.h: MICROPY_PY_BLE_NUS (1)
pca10040: bluetooth_conf.h: MICROPY_PY_BLE_NUS (1)
|
I was experimenting with LTO. I've got it working for nRF51 without SoftDevice but couldn't get it to work when it is compiled with a SoftDevice (goes straight to a HardFault). Nonetheless, I wanted to share what I've got so far, if you're interested. Of course, it will need a lot of testing, as LTO support is relatively new and no other ports have implemented it.
It saves roughly 1kB of flash and 52 (?) bytes of RAM.