vTaskSwitchContext() Linker error when link time optimization is enabled (-flto) on gcc and STM32

hs2sf wrote on Friday, October 04, 2019:

I’ve solved this issue in while ago by adding:

#ifndef portDONT_DISCARD
	#define portDONT_DISCARD        __attribute__(( used ))
#endif

just below the portFORCE_INLINE macro definition in GCC/…/portmacro.h
And using it for the vTaskSwitchContext declaration.

portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;

This works regardless of using or even including vTaskSuspend .
The patch in xPortStartScheduler calling vTaskSwitchContext to trick LTO never worked for me.
Just my 2ct.