cancel
Showing results for 
Search instead for 
Did you mean: 

Why are zero initialized objects taking up space in FLASH?

CTapp.1
Senior

I have created a new project and built it. The build analyser shows:

CTapp1_0-1727282883401.png

I then added the following at file scope:

int8_t position[ 4096 ];  // Default zero initialized array

The build analyser then shows:

CTapp1_1-1727283010254.png

The 4k increase in RAM usage makes sense, but not the 4K increase in FLASH.

The console shows:

CTapp1_2-1727283100670.png

The build analyser also shows:

CTapp1_3-1727283172355.png

Why is 4k being added to the .bss section in FLASH for the position object?

1 ACCEPTED SOLUTION

Accepted Solutions
CTapp.1
Senior

I created a new project with the same configuration and copied my application code into it.

There is now no .bss in the FLASH area, as expected.

The only changes I have made to both projects are those related to peripheral configuration. The linker files are both the same and are the template files provided when the projects were created.

I can only think that something happened when I moved the project from Mac to Windows (where I am running a later version - 1.16.0).

View solution in original post

4 REPLIES 4

Probably an issue with build analyzer

Would perhaps look at what OBJCOPY, OBJDUMP or FROMELF can report about the structure and content of the ELF file.

The Linker Script should be able to partition the initialized and uninitialized portions, and the startup code should be able to do the copying from FLASH and zeroing, based on what the linker generated and the symbols it created.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Bob S
Principal

You are right, it shouldn't.

Which CubeIDE version are you using?  And which CPU (obviously one with a small amounts of memory)?  Can you post your .ioc file (if you used CubeMX to create your project) and/or a minimal (presumably "C") program that shows this issue.  Then others can see if they can replicate your results.

AScha.3
Chief III

Which chip ?

You set something strange...

on F103C8 :

I tried just to add your 4K position array, and yes, it needs 4KB ram, bss is there, nothing in flash:

AScha3_0-1727287940914.png

with optimizer on -O2 .

The linker script should have it in ram - did you change it ?

  .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
If you feel a post has answered your question, please click "Accept as Solution".
CTapp.1
Senior

I created a new project with the same configuration and copied my application code into it.

There is now no .bss in the FLASH area, as expected.

The only changes I have made to both projects are those related to peripheral configuration. The linker files are both the same and are the template files provided when the projects were created.

I can only think that something happened when I moved the project from Mac to Windows (where I am running a later version - 1.16.0).