Building the RTD with GCC Space Optimization

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

Building the RTD with GCC Space Optimization

346 Views
greenwichmeanie
Contributor III

We're using the NXP GCC 11.4 compiler and have created our own CMake build. The compilation flags were lifted from the Design Studio project. It builds and runs but if we remove the `-Os` flag we see hard faults. I wouldn't expect the removal of an optimization to change the behavior of the code (let along cause it to crash). I'd like to understand why this is. We have a functional safety application and it'll be important to understand and document this.

Thanks.

0 Kudos
Reply
3 Replies

297 Views
greenwichmeanie
Contributor III

Thanks VaneB. Point taken. We'll take a look at the release notes but I have no reason not to believe you.

For what it's worth we tracked this down. If a couple of specific optimization flags are removed (from the collection included when using -Os) then the variable below is not initialized by the C runtime initialization. It remains set to null by the time `main()` is reached (which is obviously a problem). Happens with GCC 10.2 and 11.4. If we halt the debugger and punch that address in then things are fine.

That assignment was happening before the definition of Clock_Ip_CodeInRamSetFlashWaitStates. If we move the assignment after all is well.

#ifdef CLOCK_IP_HAS_FLASH_WAIT_STATES
static SetFlashWaitStatesCallbackType Clock_Ip_SetFlashWaitStatesCallback = &Clock_Ip_CodeInRamSetFlashWaitStates;   /* Set Flash Wait States callback */
#endif

267 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @greenwichmeanie 

Thank you for sharing your findings.

0 Kudos
Reply

312 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @greenwichmeanie 

Please note that none of the currently available RTD versions for S32K devices (S32K1 and S32K3) support NXP GCC 11.4. Additionally, each RTD release note specifies the optimization level used during development and testing; most RTD releases have been validated with -Os/-Osize.

Therefore, we cannot guarantee the functionality of the drivers when using different optimization levels or toolchains than those originally tested. Furthermore, any modifications to the RTD fall outside the scope of our support.

 

BR, VaneB

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2204641%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EBuilding%20the%20RTD%20with%20GCC%20Space%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2204641%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EWe're%20using%20the%20NXP%20GCC%2011.4%20compiler%20and%20have%20created%20our%20own%20CMake%20build.%20The%20compilation%20flags%20were%20lifted%20from%20the%20Design%20Studio%20project.%20It%20builds%20and%20runs%20but%20if%20we%20remove%20the%20%60-Os%60%20flag%20we%20see%20hard%20faults.%20I%20wouldn't%20expect%20the%20removal%20of%20an%20optimization%20to%20change%20the%20behavior%20of%20the%20code%20(let%20along%20cause%20it%20to%20crash).%20I'd%20like%20to%20understand%20why%20this%20is.%20We%20have%20a%20functional%20safety%20application%20and%20it'll%20be%20important%20to%20understand%20and%20document%20this.%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2205346%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Building%20the%20RTD%20with%20GCC%20Space%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2205346%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F251884%22%20target%3D%22_blank%22%3E%40greenwichmeanie%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThank%20you%20for%20sharing%20your%20findings.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2204743%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Building%20the%20RTD%20with%20GCC%20Space%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2204743%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThanks%20VaneB.%20Point%20taken.%20We'll%20take%20a%20look%20at%20the%20release%20notes%20but%20I%20have%20no%20reason%20not%20to%20believe%20you.%3C%2FP%3E%3CP%3EFor%20what%20it's%20worth%20we%20tracked%20this%20down.%20If%20a%20couple%20of%20specific%20optimization%20flags%20are%20removed%20(from%20the%20collection%20included%20when%20using%20-Os)%20then%20the%20variable%20below%20is%20not%20initialized%20by%20the%20C%20runtime%20initialization.%20It%20remains%20set%20to%20null%20by%20the%20time%20%60main()%60%20is%20reached%20(which%20is%20obviously%20a%20problem).%20Happens%20with%20GCC%2010.2%20and%2011.4.%20If%20we%20halt%20the%20debugger%20and%20punch%20that%20address%20in%20then%20things%20are%20fine.%3C%2FP%3E%3CP%3EThat%20assignment%20was%20happening%20before%20the%20definition%20of%26nbsp%3B%3CSPAN%3EClock_Ip_CodeInRamSetFlashWaitStates.%20If%20we%20move%20the%20assignment%20after%20all%20is%20well.%3C%2FSPAN%3E%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3E%3CSPAN%20class%3D%22%22%3E%23ifdef%26nbsp%3BCLOCK_IP_HAS_FLASH_WAIT_STATES%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3Estatic%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BSetFlashWaitStatesCallbackType%26nbsp%3BClock_Ip_SetFlashWaitStatesCallback%26nbsp%3B%3D%26nbsp%3B%26amp%3BClock_Ip_CodeInRamSetFlashWaitStates%3B%26nbsp%3B%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E%2F*%26nbsp%3BSet%26nbsp%3BFlash%26nbsp%3BWait%26nbsp%3BStates%26nbsp%3Bcallback%26nbsp%3B*%2F%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3E%23endif%3C%2FSPAN%3E%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2204697%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Building%20the%20RTD%20with%20GCC%20Space%20Optimization%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2204697%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F251884%22%20target%3D%22_blank%22%3E%40greenwichmeanie%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20note%20that%20none%20of%20the%20currently%20available%20RTD%20versions%20for%20S32K%20devices%20(S32K1%20and%20S32K3)%20support%20NXP%20GCC%2011.4.%20Additionally%2C%20each%20RTD%20release%20note%20specifies%20the%20optimization%20level%20used%20during%20development%20and%20testing%3B%20most%20RTD%20releases%20have%20been%20validated%20with%20-Os%2F-Osize.%3C%2FP%3E%0A%3CP%3ETherefore%2C%20we%20cannot%20guarantee%20the%20functionality%20of%20the%20drivers%20when%20using%20different%20optimization%20levels%20or%20toolchains%20than%20those%20originally%20tested.%20Furthermore%2C%20any%20modifications%20to%20the%20RTD%20fall%20outside%20the%20scope%20of%20our%20support.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBR%2C%20VaneB%3C%2FP%3E%3C%2FLINGO-BODY%3E