0

[Compiler gcc-arm-8.2-2019.01]

I have a variable in .c:int ep;I expect it is put in .bss section and having 0 initial value, but it is excluded from .bss section after I check the .map file. If I change the line to: int ep = 0; The var is put into .bss section. My guess is compiler found that the var is a writeonly, so no need initialize its value to 0. But this var is read by assembly code, also read by another program, which compiler seems not knowing and make the wrong optimize choice.

Any help on this behavior?


excluded from .bss means, in linkscript file I write:

        .bss :
        {   
                . = ALIGN(64);
                __bss_start = .;
                *(.bss)
                *(.bss.*)
                __bss_end = .;
        } > DRAM

but var ep is not between __bss_start and __bss_end, where assembly code use them to do memory clear before jump in C code

Leslie Li
  • 407
  • 7
  • 14
  • Are you looking at where it is in the object file, or in the executable? For the former, see https://stackoverflow.com/questions/16835716/bss-vs-common-what-goes-where/16836156#16836156 (note that `-fcommon` is no longer the default from gcc 10 onward). If the executable, try `objdump --syms` on it and show us the line with `ep`. – Nate Eldredge Mar 02 '21 at 04:02
  • use objdump --syms for .elf file, it shows ```ep``` is in .bss section: g O .bss 0000000000000008 ep But problem still exists, as ```ep``` is out of __bss_start/end, so assembly code can't clear its initial value – Leslie Li Mar 02 '21 at 05:14
  • If I add -fno-common cflags, ```ep``` is put between __bss_start/end – Leslie Li Mar 02 '21 at 05:16
  • 164008 g O .bss 0000000000000008 ep 164000 g .bss 0000000000000000 __bss_end – Leslie Li Mar 02 '21 at 05:22
  • It looks like a [typical default linker script](https://stackoverflow.com/questions/28688484/actual-default-linker-script-and-settings-gcc-uses) includes `*(COMMON)` within `.bss`. Yours doesn't, which is probably the problem. – Nate Eldredge Mar 02 '21 at 05:30
  • why some variables(```ep```) go to COMMON and others go to .bss? – Leslie Li Mar 02 '21 at 05:38
  • Thanks Nate's help, I think this problem is clear. – Leslie Li Mar 02 '21 at 05:47

0 Answers0