Skip to main content
PSola.1
Associate
May 10, 2022
Solved

Even after building code with optimization level -0s. There is no change in size, it just get adjusted with .text and .data.

  • May 10, 2022
  • 2 replies
  • 2201 views

I am facing issue of memory with Stm32L432xx, So i tried option of increase optimization level from -01 to -0s.

But observe no change it just reduce in .text section... but it increased in .data segment. ultimately value is same and issue is continue

Before optimization i.e -01

 text    data     bss     dec     hex filename

  117760        11264        30064        159088        26d70      build/app-firmware.elf

After optimization level set -0s

 text    data     bss     dec     hex filename

 117480         11544         30064        159088         26d70 build/app-firmware.elf

 

This topic has been closed for replies.
Best answer by Andrew Neil

Optimisation affects the code generated. The .text section is where the generated code goes - so that's where you'd expect to see any changes!

-Os optimises for the size of generated code - smaller code might require extra RAM.

Optimisation documentation:

https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gnat_ugn_unw/Optimization-Levels.html

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

The main "consumer" of RAM is variables declared by your code, So, to reduce RAM usage, you're going to have to review your code for what is using memory, and think how you can reduce that.

The linker map file should help you with that.

Also the nm utility: https://sourceware.org/binutils/docs/binutils/nm.html

2 replies

Andrew Neil
Super User
May 10, 2022

Optimisation affects the code generated. The .text section is where the generated code goes - so that's where you'd expect to see any changes!

-Os optimises for the size of generated code - smaller code might require extra RAM.

Optimisation documentation:

https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gnat_ugn_unw/Optimization-Levels.html

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

The main "consumer" of RAM is variables declared by your code, So, to reduce RAM usage, you're going to have to review your code for what is using memory, and think how you can reduce that.

The linker map file should help you with that.

Also the nm utility: https://sourceware.org/binutils/docs/binutils/nm.html

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
PSola.1
PSola.1Author
Associate
May 16, 2022

Thanks for help @Andrew Neil (Community Member), I have re organize linker file by keeping 127k for flash and 1k for NV data

Andrew Neil
Super User
May 16, 2022

and does that help?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Markus GIRDLAND
ST Employee
May 11, 2022

To add to what Andrew mentioned, to see what consumes the most memory of your application you can use the Build Analyzer inside STM32CubeIDE. Choose "Show Byte" and sort by the "Size" column as shown in the screenshot below:

0693W00000Npl9JQAR.png 

Andrew Neil
Super User
May 11, 2022

Although @PSola.1​ seems to be concerned about RAM - not Flash?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Tesla DeLorean
Guru
May 11, 2022

Or that the 128KB FLASH of the L432RB is all consumed. Same die used for the RC device.

Optimization can't fix algorithmic issues, or compress data structures.

Will need to make things more efficient, use subroutines for repetitive code, use of structures and tables, compress or encode data better, determine scope of buffers, don't make everything global, especially stuff used once at initailization.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..