https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63486
Bug ID: 63486
Summary: Magic Statics lock guard does not include registration
into atexit handler
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mira.suk at centrum dot cz
void test()
{
static std::string x;
}
If I'm reading assembly right _cxa_atexit handler is not called inside lock
which could result in static variable being destructed multiple times.
Is compiled into following with -g3
|0x401312 <test()> push %rbp
│
│0x401313 <test()+1> mov %rsp,%rbp
│
│0x401316 <test()+4> push %r12
│
│0x401318 <test()+6> push %rbx
│
|0x401319 <test()+7> lea 0x202e10(%rip),%rax # 0x604130
<_ZGVZ4testvE1x>
│
│0x401320 <test()+14> movzbl (%rax),%eax
│
│0x401323 <test()+17> test %al,%al
│
│0x401325 <test()+19> jne 0x401398 <test()+134>
│
│0x401327 <test()+21> lea 0x202e02(%rip),%rdi # 0x604130
<_ZGVZ4testvE1x>
│
│0x40132e <test()+28> callq 0x400c40 <__cxa_guard_acquire@plt>
│
│0x401333 <test()+33> test %eax,%eax
│
│0x401335 <test()+35> setne %al
│
│0x401338 <test()+38> test %al,%al
│
│0x40133a <test()+40> je 0x401398 <test()+134>
│
│0x40133c <test()+42> mov $0x0,%r12d
│
│0x401342 <test()+48> lea 0x202dff(%rip),%rdi # 0x604148
<_ZZ4testvE1x>
│
│0x401349 <test()+55> callq 0x400c20 <_ZNSsC1Ev@plt>
│
│0x40134e <test()+60> lea 0x202ddb(%rip),%rdi # 0x604130
<_ZGVZ4testvE1x>
│
│0x401355 <test()+67> callq 0x400cb0 <__cxa_guard_release@plt>
│
│0x40135a <test()+72> lea 0x202d87(%rip),%rdx # 0x6040e8
│
│0x401361 <test()+79> lea 0x202de0(%rip),%rsi # 0x604148
<_ZZ4testvE1x>
│
│0x401368 <test()+86> mov 0x202c81(%rip),%rax # 0x603ff0
│
│0x40136f <test()+93> mov %rax,%rdi
│
│0x401372 <test()+96> callq 0x400ef1 <__cxa_atexit(void (*)(void*),
void*, void*)>
│
│0x401377 <test()+101> jmp 0x401398 <test()+134>
│
│0x401379 <test()+103> mov %rax,%rbx
│
│0x40137c <test()+106> test %r12b,%r12b
│
│0x40137f <test()+109> jne 0x40138d <test()+123>
│
│0x401381 <test()+111> lea 0x202da8(%rip),%rdi # 0x604130
<_ZGVZ4testvE1x>
│
│0x401388 <test()+118> callq 0x400d10 <__cxa_guard_abort@plt>
│
│0x40138d <test()+123> mov %rbx,%rax
│
│0x401390 <test()+126> mov %rax,%rdi
│
│0x401393 <test()+129> callq 0x400d70 <_Unwind_Resume@plt>
│
│0x401398 <test()+134> pop %rbx
│
│0x401399 <test()+135> pop %r12
│
│0x40139b <test()+137> pop %rbp
│
