GCC10 / 9 inline functions weird behavior Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
error414
Posts: 12
Joined: Fri Jan 22, 2021 12:11 am
Has thanked: 3 times

GCC10 / 9 inline functions weird behavior

Post by error414 »

Hi Giovanni,

I use newest chibios from github downloaded from master yesterday (27.01.2021), because I read viewtopic.php?f=35&t=5678, unfortunately new version of chibios didn't solve the issue. I'm new in IoT programming so I have no clue how to fix it right way.

Issue:
unhandled exception if program is compiled with -O2 or -Os flag see "unhandled_exception.png". With "-Og" it works like a charm.

Inline optimalization log "-O2 -fopt-info-inline-all" https://pastebin.com/UPqmp9rp .
It works if I add "NOINLINE" to lines https://github.com/ChibiOS/ChibiOS/blob ... .h#L91-L92

Code: Select all

NOINLINE void __tm_calibration_init(tm_calibration_t *tcp);
   NOINLINE void chTMObjectInit(time_measurement_t *tmp);


or add " -fno-inline " flag. Flag "-finline-small-functions" does not work at all.

I tested three toolchains:
gcc-arm-none-eabi-10-2020-q4-major-win32 - does not work
gcc-arm-none-eabi-9-2019-q4-major-win32 - does not work
gcc-arm-none-eabi-7-2017-q4-major-win32- works

Board: nucleo F401RE
Devel platform: win10

I reduced program to simple shell tests:
static const ShellConfig shell_cfg1 = {
(BaseSequentialStream *)&SD2,
shell_local_commands
};


/*
* Application entry point.
*/
int main(void) {
halInit();
chSysInit();
shellInit();



while (true) {

thread_t *shelltp = chThdCreateFromHeap(NULL, 800,
"shell", NORMALPRIO + 50,
shellThread, (void *)&shell_cfg1);
chThdWait(shelltp);

chThdSleepMilliseconds(150);
palClearPad(GPIOA, GPIOA_LED_GREEN);
chThdSleepMilliseconds(100);
palSetPad(GPIOA, GPIOA_LED_GREEN);
chThdSleepMilliseconds(100 );
}
}


BTW: I use LGVL as well (but for test was removed) and it does not work at all too with GCC10 and 9 and "-O2". I didn't figure out how to fix it. ChibiOs is much more friendly for debugging. Nice piece of SW.
Attachments
unhandled_exception.png
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: GCC10 / 9 inline functions weird behavior

Post by Giovanni »

Hi,

Have you enabled debug options in chconf.h? especially stack overflow checking.

Giovanni
error414
Posts: 12
Joined: Fri Jan 22, 2021 12:11 am
Has thanked: 3 times

Re: GCC10 / 9 inline functions weird behavior

Post by error414 »

OMG, yes I had all debug options turned on :(. I disabled all and it works now.

Sorry I wasted your time ;(, it was stupid issue.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: GCC10 / 9 inline functions weird behavior

Post by Giovanni »

It could be simply a stack overflow, changing compiler and OS options can change stack usage.

Giovanni
error414
Posts: 12
Joined: Fri Jan 22, 2021 12:11 am
Has thanked: 3 times

Re: GCC10 / 9 inline functions weird behavior

Post by error414 »

Thank you very much for help. The result:

1) chibistudio + make = just works
2) clion + cmake = does not work even if I used toolchain from chibistudio or WSL, ....
3) clion + make = works if I use makefile from demo and modify it to my project

I tried grab all settings from Makefile, but it still does not work, cmake is magic black box, not as make.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: GCC10 / 9 inline functions weird behavior

Post by Giovanni »

I am an old fashioned make guy. Probably you are not doing everything you see in makefiles, check the compiler command like options in the log and compare the two.

Giovanni
error414
Posts: 12
Joined: Fri Jan 22, 2021 12:11 am
Has thanked: 3 times

Re: GCC10 / 9 inline functions weird behavior

Post by error414 »

Three days studying of make file. Finnaly it works as I want even with cmake. It was not chibios fault, just cmake is for head ache.

Big thanks for help.
Post Reply