I work with GCC-ARM-Embedded and FreeRTOS. FreeRTOS has a function vTaskSwitchContext() , which is used only in some built-in assembler code.
The problem is this: when I use LTO, GCC does not take into account the built-in assembler code and considers that the function is not used, thereby deleting it. The linker then fails because the function call in the inline assembler code cannot be resolved.
I would apply __attribute__((used)) , but I do not want to touch the FreeRTOS code (it is generated by STM32CubeMX).
I tried putting this in my code, but actually GCC is smart enough not to let this work:
if(false) vTaskSwitchContext();
Is it possible to specify GCC in another source file or through a parameter so that this function is not deleted?
Example
// file1.c void vTaskSwitchContext( void ) { ... } // file2.c void xPortPendSVHandler( void ) { __asm volatile ( ... " isb \n" " bl vTaskSwitchContext \n" " mov r0, #0 \n" ... ); }
source share