https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127947
Bug ID: 127947
Summary: Uninitialised static local variables are placed in
.bss, despite -fno-zero-initialized-in-bss
Product: gcc
Version: 12.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: simon.willcocks at gmx dot de
Target Milestone: ---
I put in the earliest version I could, but building a whole version 16.2 just
to find out if this is still a problem is ridiculous. A seven line C file
demonstrates what I've found.
/tmp$ cat x.c ; gcc -c x.c -o x.o -fno-zero-initialized-in-bss ; objdump
--disassemble-all -x x.o | grep whereami ; arm-none-eabi-gcc -c x.c -o x.o
-fno-zero-initialized-in-bss ; arm-none-eabi-objdump --disassemble-all -x x.o |
grep whereami
int * afunc()
{
static int * whereami = 0; // Explicit initialisation
asm ( "nop" : "=r" (whereami) );
return whereami;
}
0000000000000000 l O .data 0000000000000008 whereami.0
0000000000000000 <whereami.0>:
00000000 l O .data 00000004 whereami.0
00000000 <whereami.0>:
/tmp$ fg
vi x.c
[1]+ Stopped vi x.c
/tmp$ cat x.c ; gcc -c x.c -o x.o -fno-zero-initialized-in-bss ; objdump
--disassemble-all -x x.o | grep whereami ; arm-none-eabi-gcc -c x.c -o x.o
-fno-zero-initialized-in-bss ; arm-none-eabi-objdump --disassemble-all -x x.o |
grep whereami
int * afunc()
{
static int * whereami; // No/implicit initialisation
asm ( "nop" : "=r" (whereami) );
return whereami;
}
0000000000000000 l O .bss 0000000000000008 whereami.0
0000000000000000 <whereami.0>:
00000000 l .bss 00000004 whereami.0
00000000 <whereami.0>:
/tmp$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
/tmp$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (15:10.3-2021.07-4) 10.3.1 20210621 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.