[llvm-commits] [PATCH] generate ABI-compliant sections for uninitialized static data members in template instantiations
Kristof Beyls
kristof.beyls at arm.com
Mon Feb 20 08:14:18 PST 2012
The attached patch fixes a problem where LLVM doesn't generate .bss sections
in a C++ ABI-compliant way.
Would someone be able to review and apply the patch if fine?
Thanks,
Kristof
Here is some background information:
The following section of the generic C++ ABI
(http://sourcery.mentor.com/public/cxx-abi/abi.html#vague-itemplate) states:
"""
5.2.6 Instantiated Templates
An instantiation of a class template requires:
....
* Any static member data object is emitted in a COMDAT identified by its
mangled name, in any object file with a reference to its name symbol.
....
"""
However, for uninitialized static member data objects in instantiated
templates, LLVM does not produce a COMDAT.
For the following test case:
template<class T> struct C {
static int i;
static int j;
};
template<class T> int C<T>::i;
template<class T> int C<T>::j = 12;
void f(C<int> c) { c.i++; c.j++; }
LLVM produces the following assembler output for the template instantiations
of C<T>::i and C<T>::j:
.type _ZN1CIiE1iE,%object @ @_ZN1CIiE1iE
.bss
.weak _ZN1CIiE1iE
.align 2
_ZN1CIiE1iE:
.long 0 @ 0x0
.size _ZN1CIiE1iE, 4
.type _ZN1CIiE1jE,%object @ @_ZN1CIiE1jE
.section .data._ZN1CIiE1jE,"aGw",%progbits,_ZN1CIiE1jE,comdat
.weak _ZN1CIiE1jE
.align 2
_ZN1CIiE1jE:
.long 12 @ 0xc
.size _ZN1CIiE1jE, 4
Note that for C<T>::i (mangled: _ZN1CIiE1iE), no comdat section is produced.
OTOH, for C<T>::j, a comdat section is produced.
The correct behaviour would be to produce the following section for C<T>::i
.type _ZN1CIiE1iE,%object @ @_ZN1CIiE1iE
.section .bss._ZN1CIiE1jE,"aGw",%nobits,_ZN1CIiE1jE,comdat
.weak _ZN1CIiE1iE
.align 2
_ZN1CIiE1iE:
.long 0 @ 0x0
.size _ZN1CIiE1iE, 4
This is also what gcc produces.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cxx_weak_odr_bss.patch
Type: application/octet-stream
Size: 2090 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120220/9a52c3a3/attachment.obj>
More information about the llvm-commits
mailing list