This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12943] New: array static-init failure under -fpic, -fPIC
- From: "gcc-bugzilla at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Nov 2003 16:31:48 -0000
- Subject: [Bug c++/12943] New: array static-init failure under -fpic, -fPIC
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12943
Summary: array static-init failure under -fpic, -fPIC
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ncm-nospam at cantrip dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i486-pc-linux-gnu
GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu
Static linker initialization fails to initialize struct members,
under hard-to-describe circumstances.
Specifically: in a static array initialization where array elements
are structs, and where some struct members are implicitly initialized
to zero, certain struct members that are *explicitly* initialized get
zero-initialized anyhow.
To reproduce the failure, it appears that:
o "-fpic" or "-fPIC" is necessary (but we have failures w/o -fpic).
o letting the compiler implicitly zero-initialize at least
one struct member in all elements is necessary.
o a forward-reference to the initialized value is necessary (or a
string literal).
o fewer than five array elements is necessary (but we have seen it
with more).
Under "-O0" the failure does not seem to occur.
In gcc-3.0 the failure does not seem to occur.
In gcc-3.4 snapshots the failure *does* still occur.
Environment:
System: Linux ipc 2.4.21-rc1-ac2 #3 SMP Mon Apr 28 18:55:42 EDT 2003 i686 unknown unknown GNU/Linux
Architecture: i686
host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
How-To-Repeat:
Paste lines below into a shell. Correct output is
1 This is a message
2 This is a message
Erroneous output looks like
1 This is a message
2 <NULL>
----------------
sed 's/^ //' >initbug.cc <<' EOF'
// Compile this with 'g++ -O1 -fpic', and see what happens
// compiled as C, the problem does not occur.
#include <stdio.h>
struct StringHolder {
int m_index;
char const * const message_pointer;
int extra; // this member is necessary to expose bug
};
extern char const * const Message;
StringHolder array_of_holders[] = {
{ 1, Message }, // default-initializing Stringholder::extra
{ 2, Message },
{ -1, 0 }
};
int main()
{
StringHolder* ptr = array_of_holders;
while(ptr->m_index >= 0) {
printf("%d\t", ptr->m_index);
if (ptr->message_pointer == NULL)
printf("<NULL>\n");
else
printf("%s\n", ptr->message_pointer);
++ptr;
}
}
char const * const Message = "This is a message";
EOF
g++ -O1 -fpic initbug.cc
./a.out