I work with GCC-ARM-Embedded and FreeRTOS.
FreeRTOS has the function vTaskSwitchContext()
which is used only in some
inline assembler code.
The problem is: When I use LTO, GCC does not consider the inline assembler code and thinks the function is not used, thus removes it. The linker then fails because the function call in the inline assembler code cannot be resolved.
I would apply __attribute__((used))
but I don't want to touch the FreeRTOS code (it's generated by STM32CubeMX).
I tried putting this in my code, but actually GCC is smart enough to not allow this to work:
if(false)
vTaskSwitchContext();
Is there some way to tell GCC in a different source file, or via parameter, that this function should not be removed?
Example
// file1.c
void vTaskSwitchContext( void )
{
...
}
// file2.c
void xPortPendSVHandler( void )
{
__asm volatile
(
...
" isb \n"
" bl vTaskSwitchContext \n"
" mov r0, #0 \n"
...
);
}
For some reason, the solution that Dietrich proposed didn't work for me. I'm using Infineon's DAVE 4 (basically eclipse with a fancy code generation plugin for their line of XMC microcontrollers), which may be the reason why it didn't work. For me, I had to call vTaskSwitchContext()
after vTaskStartScheduler()
:
int main(){
initializationCode();
vTaskStartScheduler();
//Code never reaches here
vTaskSwitchContext();
}
Try calling the function from a separate function which is marked used
.
void dummyFunction(void) __attribute__((used));
// Never called.
void dummyFunction(void) {
vTaskSwitchContext();
}
You can add -Wl,--undefined=vTaskSwitchContext
to your LDFLAGS
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With