Link Time Optimization useful?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
ExXec
Posts: 71
Joined: Sat Oct 20, 2018 4:02 pm

Link Time Optimization useful?

Post by ExXec » Tue Jul 02, 2019 2:18 pm

Hey
I was wondering if enabling link time optimization would be useful for -Os or not at all?

stijn
Posts: 339
Joined: Thu Apr 24, 2014 9:13 am

Re: Link Time Optimization useful?

Post by stijn » Tue Jul 02, 2019 3:10 pm

It might be, or not. You'd have to measure for your particular case whether the effects (possibly increases code size, possible enhances perfromance, or maybe not) are noticable.

ExXec
Posts: 71
Joined: Sat Oct 20, 2018 4:02 pm

Re: Link Time Optimization useful?

Post by ExXec » Wed Jul 03, 2019 8:58 pm

I tried it and the setup was a little difficult first, because you need to invoke gcc with the -Wl option instead of calling the linker directly (which I didn't know).
But I got it to work and it shaved another 3kB (~3%) off the binary (from 154kB with -Os to 151kB with -flto and -Os),
might be useful for some boards with limited space (like mine)

I will keep this settings for now and try them out a little.

User avatar
jimmo
Posts: 427
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Link Time Optimization useful?

Post by jimmo » Wed Jul 03, 2019 10:32 pm

I seem to remember some LTO related issues with the GC, because it makes it hard to track root pointers. This may be fixed though. You should search the github PR and Issue history for LTO

stijn
Posts: 339
Joined: Thu Apr 24, 2014 9:13 am

Re: Link Time Optimization useful?

Post by stijn » Thu Jul 04, 2019 7:21 am

jimmo wrote:
Wed Jul 03, 2019 10:32 pm
I seem to remember some LTO related issues with the GC, because it makes it hard to track root pointers. This may be fixed though. You should search the github PR and Issue history for LTO
The NRF port has LTO on by default and so does the msvc port since it's existence; there was an issue with the latter which has been fixed recently so you're probably referring to this one: https://github.com/micropython/micropython/issues/4652 (it was very hard to reproduce though, we run large-scalish applications with the msvc port for many hours each day on 10+ different machines and have been doing so for like 3 years already, and never encountered this one). tldr; it's always possible a new bug related to LTO is found, but chances are fairly small.

ExXec
Posts: 71
Joined: Sat Oct 20, 2018 4:02 pm

Re: Link Time Optimization useful?

Post by ExXec » Thu Jul 04, 2019 11:26 am

jimmo wrote:
Wed Jul 03, 2019 10:32 pm
I seem to remember some LTO related issues with the GC, because it makes it hard to track root pointers. This may be fixed though. You should search the github PR and Issue history for LTO
If this would be the case, it should throw in an "out of memory" error eventually, right?

stijn
Posts: 339
Joined: Thu Apr 24, 2014 9:13 am

Re: Link Time Optimization useful?

Post by stijn » Thu Jul 04, 2019 11:32 am

Not exactly, 'issues with GC' is broader than that. For example see the link to the github issue: the issue there was undefined behaviour basically resulting in an assertion failure.

Post Reply