Page 1 of 1

Link Time Optimization useful?

Posted: Tue Jul 02, 2019 2:18 pm
by ExXec
Hey
I was wondering if enabling link time optimization would be useful for -Os or not at all?

Re: Link Time Optimization useful?

Posted: Tue Jul 02, 2019 3:10 pm
by stijn
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.

Re: Link Time Optimization useful?

Posted: Wed Jul 03, 2019 8:58 pm
by ExXec
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.

Re: Link Time Optimization useful?

Posted: Wed Jul 03, 2019 10:32 pm
by jimmo
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

Re: Link Time Optimization useful?

Posted: Thu Jul 04, 2019 7:21 am
by stijn
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.

Re: Link Time Optimization useful?

Posted: Thu Jul 04, 2019 11:26 am
by ExXec
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?

Re: Link Time Optimization useful?

Posted: Thu Jul 04, 2019 11:32 am
by stijn
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.