[Bug c++/14936] New: -fdata-sections + uninitialized template data objects = spurious link errors
zack at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Tue Apr 13 10:11:00 GMT 2004
Consider the following code fragment:
template <typename T> struct S { static int i; };
template <typename T> int S<T>::i;
int j = S<double>::i;
When compiled normally, the variable S<double>::i is emitted as
.comm _ZN1SIdE1iE,4,4
which is fine. When compiled with -fdata-sections on an ELF target, however,
the same symbol is emitted in its own .bss subsection, like this:
.globl _ZN1SIdE1iE
.section .bss._ZN1SIdE1iE,"aw",@nobits
.align 4
.type _ZN1SIdE1iE,@object
.size _ZN1SIdE1iE,4
_ZN1SIdE1iE:
.zero 4
This causes a multiple-definition error from the linker if two source files
instantiate S<double> and are compiled with -fdata-sections. A linkonce section
should be used instead, as is done if S<T>::i is initialized.
--
Summary: -fdata-sections + uninitialized template data objects =
spurious link errors
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: zack at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14936
More information about the Gcc-bugs
mailing list