Menu

#90 LTO Support in FreeRTOS

closed
nobody
None
5
2020-02-25
2015-04-08
No

I recently tried using gcc 4.9 and Link time optimization(LTO) to build my project using the GCC FreeRTOS cortex m3 port, but failed because of the inline assembly inside of the port. vTaskSwitchContext and potentially other functions that are only referenced inside of inline assembly seem to get removed during linking, causing the build to fail.

I understand the need to aggressively optimize important routines, but would it be possible to call functions in native C rather than inline assembly without sacrificing too much? I can add some build output when I'm back at the correct computer.

I didn't check the whole code base for this but another problem I've had with other libraries is symbols used for branch/jumps inside of inline assembly can have name collisions when building with LTO. Problem is described in more detail at http://stackoverflow.com/questions/878770/assembly-compilation-error-gcc4-2-4-win-gcc4-3-3-fail

Discussion

  • Andrey Korol

    Andrey Korol - 2015-07-03

    As temporary fix for GCC i just added atribute "used" in function declaration in task.h:

    __attribute__ ((used)) void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
    
     

    Last edit: Andrey Korol 2015-07-03
  • HS2

    HS2 - 2016-06-30

    Using Atmel GCC toolchain 5.3.1 for ARM-CM3 and FreeRTOS v9.0.0:
    When using whole-program resp. link-time-optimization (LTO) the optimizer might omit some low-level data/code.
    Since the optimizer is (C/C++)compiler based (I guess) this behaviour is understandable to a certain degree.
    In my case the interrupt vector table (ususally defined as global structure in a C module with startup code) was silently discarded and the resulting (elf) executable was corrupt.

    This is resolved by attaching __attribute__((used)) to its definiton.
    example:
    const DeviceVectors exception_table __attribute__((used, aligned(1 << SCB_VTOR_TBLOFF_Pos), section(".vectors"))) = { .... };

    And I got this additional problem:
    ... In function PendSV_Handler:
    ... undefined reference to vTaskSwitchContext

    vTaskSwitchContext is only used in inline assembler function xPortPendSVHandler.
    Obviously the assembly call to vTaskSwitchContext is (currently) not fully recognized by the compiler/linker and optimzed out.

    This is resolved as already proposed by Andrey by attaching __attribute__((used)) to the declaration of vTaskSwitchContext in task.h.

    Proposal:
    Please add a portable macro similar to the follwoing example to portmacro.h.

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

    and tag the affected C-functions (only called by inline assembler code) with it.

    Thanks !

     

    Last edit: HS2 2016-06-30
  • Richard Barry

    Richard Barry - 2020-02-25
    • status: open --> closed
     
  • Richard Barry

    Richard Barry - 2020-02-25

    Recent versions are biulding with LTO.

     

Log in to post a comment.