cancel
Showing results for 
Search instead for 
Did you mean: 

Store variables in .data section instead of .bss section

Rohit.1
Associate II

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?

3 REPLIES 3
KnarfB
Principal III

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.

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 Venmo
Up vote any posts that you find helpful, it shows what's working..
Rohit.1
Associate II

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.