1

I'm working on a stm32 nucleo board. My project is composed of several different libraries.

I would like to put all uninitialized variables coming from static library (mylib.a) in a specific memory section instead of the bss section.

Here is my bss section inside the linker script:

. = ALIGN(4);
.bss :
{
    /* This is used by the startup in order to initialize the .bss section */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)

    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
} >RAM

I tried adding this section before the bss one:

. = ALIGN(4);
.mybss :
{
    /* This is used by the startup in order to initialize the .bss section */
    _smybss = .;         /* define a global symbol at bss start */
    __mybss_start__ = _smybss;
    mylib.a:*(.bss)
    mylib.a:*(.bss*)
    mylib.a:*(COMMON)

    . = ALIGN(4);
    _emybss = .;         /* define a global symbol at bss end */
    __mybss_end__ = _emybss;
} >RAM

The compiler does not complain but when I inspect with nm command the generated elf _smybss symbol is at the same address of _emybss symbol. So mybss section is empty.

Do you have any suggestion on how to achive this?

Thanks

FrankPak
  • 371
  • 1
  • 4
  • 21
  • I've found that there are "section" or "pragma" type commands that can be added to your variable declarations to perhaps do this without linker script hacking. Is this a possibilty for you? – Michael Dorgan Apr 29 '15 at 17:49
  • No this cannot be a solution since the library mylib is quite big and I'm not the manteiner of it, so I would avoid changes to that code! – FrankPak Apr 30 '15 at 15:19
  • Then it comes down to linker script trial and error. It always takes much longer than you expect to get stupid things to work right. You can also hack away at your crt0.s - or equivilent bootstrap module - to manually move stuff to where you want as well. – Michael Dorgan Apr 30 '15 at 17:25
  • It would be helpful to know which toolchain you are using including the version. From your examples I guess its GNU. – Pait May 08 '15 at 08:09
  • Possible duplicate of [placing static library answer in the beginning of flash section](http://stackoverflow.com/questions/22497953/placing-static-library-answer-in-the-beginning-of-flash-section) – LarryH Jan 24 '17 at 04:08

0 Answers0