Skip to main content
Rohit.1
Associate III
January 20, 2021
Question

Store variables in .data section instead of .bss section

  • January 20, 2021
  • 3 replies
  • 2060 views

I am using STM32F746G-DISCO board.

And want to store all my variables in .data section instead of .bss section.

This is just to make enough space available in .bss section for my DMAs.

My question is that how can I do this? Can any one give me some reference to start with?

This topic has been closed for replies.

3 replies

KnarfB
Super User
January 20, 2021

For gcc, you can specify the section as an attribute, see https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes.

But, .data and .bss sections have certain semantics which you should know and respect.

Fo DMA buffers you could/should create a new, separate section keeping them together in memory.

Tesla DeLorean
Guru
January 20, 2021

For GNU/GCC move the .bss and .bss.* matching patterns into the data section, or explicitly use a different section attribute to put data buffers where you want them.

Address any changes in topology in your startup.s code.

Personally I think this is a bad plan as it ***** up FLASH resources for empty blocks.

Surely would be better buffer management schemes to allocated resources, or advance memory (front of .data start address) using symbols within the linker script. ie Want 20KB, allocate it up front, advancing the placement address from 0x20000000 to 0x20005000 for example, using a symbol

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Rohit.1
Rohit.1Author
Associate III
January 21, 2021

Thanks knarfB. Tahnks Tesla Delorean.

For GNU/GCC move the .bss and .bss.* matching patterns into the data section.

How can I do this? Can you please give me any example?

Some of my variables are by default got stored in the .data section. Is there any way to store my remaining variables in .data too without making any change in the linker script.

I am not having any experience with the linker script modifications. Please guide me further.