Skip to main content
gfxfloro
Associate III
January 17, 2023
Solved

Placing data at a specific section causes extreme size increase

Hi,

I am trying to have data at a specific location in flash. To do this I have defined my section in the linker script as follows:

 .info_data 0x08004674 :
 {
 . = ALIGN(4);
 KEEP(*(.info_data))
 . = ALIGN(4);
 } >FLASH

with FLASH starting at 0x0800 0000 and having a size of 18KB.

The data to be placed is defined in a .h file like this:

 uint32_t volatile const info __attribute__((section(".info_data"))) = 0x12345678;

This works, but it causes the file to be significantly larger.

If I don't inlcude the data, the hex file ends at address 0x0800 3820, so well within the 18 KB range. However including this data causes the linker to stop with the main code at 0x0800 307C, places info_data at 0x0800 4674 and then places the rest of the code from 0x0800 4678 to 0x0800 4E1C. (I extended FLASH to 20KB size, to test this).

Why does the linker leave so much empty space between the start of info_data? Is there anything I can do to minimize this? I tried with -fno-function-sections and -fno-data-sections but that didn't help.

    This topic has been closed for replies.
    KnarfB
    KnarfBBest answer
    Super User
    January 17, 2023

    Where did you put thoses lines in the linker script? At the end of all flash stuff?

    hth

    KnarfB

    2 replies

    KnarfB
    KnarfBBest answer
    Super User
    January 17, 2023

    Where did you put thoses lines in the linker script? At the end of all flash stuff?

    hth

    KnarfB

    gfxfloro
    gfxfloroAuthor
    Associate III
    January 17, 2023

    Ah no I put it somewhere inbetween. Now I placed it after everything that mentions FLASH even the RAM at> FLASH part, now it works.

    I would have never guessed that the placement in the file would have an effect.

    Thanks!