Skip to content

Toolchains may not keep unused variables placed with BSP_PLACE_IN_SECTION #416

@renesas-jbrabender

Description

@renesas-jbrabender

Issue

When a variable is placed in a linker section via the BSP_PLACE_IN_SECTION but is unused, the toolchains will typically discard it.
In FSP versions prior to v6.0.0, linker command files would often include a "keep" directive for memory sections which would sometimes keep unused variables. In FSP v6.0.0 and greater those keep directives are not emitted (as they were unreliable in performing the task).

Workaround

If the source code does not actually use, the section variable, you can often convince the toolchain to not optimize it out by declaring it volatile and referencing it in source code. For example:

volatile uint8_t flash_write_buffer[4096] BSP_PLACE_IN_SECTION(".data_flash") BSP_ALIGN_VARIABLE(4);
...
(void) flash_write_buffer[0];

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions