LTO and Redlib?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LTO and Redlib?

977 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Muis on Thu Feb 26 05:14:34 MST 2015
My code does not depend on semi-hosting, and the release version is always compiled as Redlib (None).

Now last week I tried to debug a HardFault which occurs in my code only with LTO (Link Time Optimization) enabled (-oS). I couldn't find the reason. Today I accidently enabled 'Redlib (Nohost) for my release-build. And now LTO-compiled binaries don't give a HardFault anymore?

What can be the cause of this miraclous behaviour of None Vs NoHost?
0 Kudos
3 Replies

934 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Muis on Thu Feb 26 09:45:17 MST 2015
Let me re-phrase my question:

- My code compiles with 0 errors using 'None' as Redlib setting.
- My code compiles with 0 errors using 'Nohost' as Redlib setting.

Shouldn't both binaries behave exactly identical? They even could be binary identical byte by byte?

But different binaries are produced they behave differently too, how come?
0 Kudos

934 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Muis on Thu Feb 26 09:36:32 MST 2015
No, I am sure the HardFault is not being masked.

My code works on all optimization levels (O1 to OS) even with LTO enabled. Only when I switch from Redlib (Nohost) to Redlib (None) it becomes unstable with LTO. In release mode, the Hardfault handler isnt even executed, the firmware just freezes. In debug mode, I get Hardfaults on the weirdest places, usually VECTPT contains 'g_pfnVectors'  and the line is calling 'memset' or 'memcpy'.

It just seems the LPCXpresso wasn't prepared for LTO very well. I already had to modify the startup files to add "__attribute__ ((used" or else your own examples won't even boot when compiled with LTO.
0 Kudos

934 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Feb 26 07:06:27 MST 2015
This sounds like the change of library is either masking the Hard Fault (does your application work?) or it has changed the way that the linker is optimizing the code, so it now works.

I would recommend that you build without LTO, or try LTO with lower optimization levels.
0 Kudos