stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.82k stars 969 forks source link

Warning: changing start of section .bss by x bytes #465

Closed lorol closed 5 years ago

lorol commented 5 years ago

Info

Board

Additional context Here is an .ino file (it needs few lib's but you can figure out) to reproduce the warning. https://gist.github.com/b41c43db7f3ac0990b5639921658f024.git The cause is a double (64-bit) var at line 96. If you are using float, no problems. If you move the position where it is declared, it may affect the warning output (or not) It works ... but the difference is: with warning it takes +4 RAM bytes more :) With corrected .bss ALIGN(4) no warnings and less memory.

Related commit: https://github.com/stm32duino/Arduino_Core_STM32/commit/d52e577c5672af925c66d25112af9667eb5eb745#commitcomment-32583137

fpistm commented 5 years ago

@lorol I have not exactly the same result with your example. With no .bss alignment I have:

Sketch uses 53696 bytes (10%) of program storage space. Maximum is 524288 bytes.
Global variables use 4596 bytes (5%) of dynamic memory, leaving 77324 bytes for local variables. Maximum is 81920 bytes.

while with ALIGN(4):

Sketch uses 53696 bytes (10%) of program storage space. Maximum is 524288 bytes.
Global variables use 4600 bytes (5%) of dynamic memory, leaving 77320 bytes for local variables. Maximum is 81920 bytes.

So I lost 4 bytes with alignment.

What I will do is to remove the warn section alignment as by default, SECTIONS command does not specify a start address for the section, let ld do the work. If a start address is specified no warn was displayed.

lorol commented 5 years ago

Hi Yes, it makes sense, if you solve the warning and the RAM is actually better managed by ld - no problems. However, on my builds:

IDE 1.8.8 STM32 1.5.0 NUCLEO L152 one double variable in sketch See here: https://gist.github.com/lorol/b41c43db7f3ac0990b5639921658f024 With this customized lib: https://github.com/lorol/AD9833-Library-Arduino

-----------------ORIGINAL ld--------------------------- / Uninitialized data section / . = ALIGN(4); .bss :

./../../arm-none-eabi/bin/ld.exe: warning: changing start of section .bss by 4 bytes

Sketch uses 54552 bytes (10%) of program storage space. Maximum is 524288 bytes. Global variables use 5016 bytes (6%) of dynamic memory, leaving 76904 bytes for local variables. Maximum is 81920 bytes.

----------------PATCHED ld---------------------------- / Uninitialized data section / . = ALIGN(4); .bss ALIGN(4) :

Sketch uses 54552 bytes (10%) of program storage space. Maximum is 524288 bytes. Global variables use 5012 bytes (6%) of dynamic memory, leaving 76908 bytes for local variables. Maximum is 81920 bytes.

fpistm commented 5 years ago

Well it is fairly depends on your sketch. With other variable addition, optimizations, ... you will have the opposite. I've build the sketch for several targets and several have the warning with different +/- 4 bytes with ALIGN(x). Then to be as generic as possible, I guess the best way is to let ld handle this.

lorol commented 5 years ago

Great!