public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Destructors not called for c++11 thread_local objects
@ 2014-08-01 17:33 Ryan Johnson
  2014-08-01 17:42 ` Larry Hall (Cygwin)
  0 siblings, 1 reply; 3+ messages in thread
From: Ryan Johnson @ 2014-08-01 17:33 UTC (permalink / raw)
  To: cygwin

Hi all,

(Please CC me in replies, I'm not subscribed to the list)

Question: is this a Cygwin bug, gcc bug, or somebody else's bug entirely?

The following STC shows the problem:

$ cat bug.cpp
#include <cstdio>
static thread_local struct X {
     int x;
     X() { puts("hi"); }
     ~X() { puts("bye!"); }
} x;
int main() { x.x = 0; }

$ g++ -std=gnu++11 -Wall -g bug.cpp && ./a
hi

A quick inspection of the assembly code shows no call to 
__cxa_thread_atexit in __tls_init, where the same code compiled on 
linux, with the same version of gcc, has it right. This is odd, because 
the function does seem to be available in cygwin's libstdc++:

$ nm /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/libstdc++.a | grep thread_atexit
0000000000000000 d .data$_ZZ19__cxa_thread_atexitE4once
0000000000000000 p .pdata$__cxa_thread_atexit
0000000000000000 t .text$__cxa_thread_atexit
0000000000000000 r .xdata$__cxa_thread_atexit
0000000000000000 T __cxa_thread_atexit
0000000000000000 d _ZZ19__cxa_thread_atexitE4once

Here's the linux version of __tls_init:
> __tls_init:
> .LFB19:
>         cmpb    $0, %fs:__tls_guard@tpoff
>         je      .L7
>         rep; ret
> .L7:
>         subq    $8, %rsp
>         movl    $.LC1, %edi
>         movb    $1, %fs:__tls_guard@tpoff
>         call    puts
>         movq    %fs:0, %rsi
>         movl    $__dso_handle, %edx
>         movl    $_ZN1XD1Ev, %edi
>         addq    $8, %rsp
>         addq    $_ZL1x@tpoff, %rsi
>         jmp     __cxa_thread_atexit
vs. the same for cygwin:
> __tls_init:
>         subq    $40, %rsp
>         leaq    __emutls_v.__tls_guard(%rip), %rcx
>         call    __emutls_get_address
>         cmpb    $0, (%rax)
>         je      .L27
>         addq    $40, %rsp
>         ret
> .L27:
>         leaq    .LC0(%rip), %rcx
>         movb    $1, (%rax)
>         addq    $40, %rsp
>         jmp     puts

Relevant packages installed:
binutils                              2.24.51-4
cygwin                                1.7.30-1
gcc-core                              4.8.3-2
gcc-g++                               4.8.3-2
libstdc++6                            4.8.3-2

(I realize I'm a version behind on cygwin1.dll, but I don't think that's 
the problem here)

Thoughts?
Ryan


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Destructors not called for c++11 thread_local objects
  2014-08-01 17:33 Destructors not called for c++11 thread_local objects Ryan Johnson
@ 2014-08-01 17:42 ` Larry Hall (Cygwin)
  2014-08-01 18:17   ` Corinna Vinschen
  0 siblings, 1 reply; 3+ messages in thread
From: Larry Hall (Cygwin) @ 2014-08-01 17:42 UTC (permalink / raw)
  To: cygwin

On 08/01/2014 01:32 PM, Ryan Johnson wrote:
> Hi all,
>
> (Please CC me in replies, I'm not subscribed to the list)
>
> Question: is this a Cygwin bug, gcc bug, or somebody else's bug entirely?
>
> The following STC shows the problem:
>
> $ cat bug.cpp
> #include <cstdio>
> static thread_local struct X {
>      int x;
>      X() { puts("hi"); }
>      ~X() { puts("bye!"); }
> } x;
> int main() { x.x = 0; }
>
> $ g++ -std=gnu++11 -Wall -g bug.cpp && ./a
> hi
>
> A quick inspection of the assembly code shows no call to __cxa_thread_atexit
> in __tls_init, where the same code compiled on linux, with the same version
> of gcc, has it right. This is odd, because the function does seem to be
> available in cygwin's libstdc++:
>
> $ nm /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/libstdc++.a | grep thread_atexit
> 0000000000000000 d .data$_ZZ19__cxa_thread_atexitE4once
> 0000000000000000 p .pdata$__cxa_thread_atexit
> 0000000000000000 t .text$__cxa_thread_atexit
> 0000000000000000 r .xdata$__cxa_thread_atexit
> 0000000000000000 T __cxa_thread_atexit
> 0000000000000000 d _ZZ19__cxa_thread_atexitE4once
>
> Here's the linux version of __tls_init:
>> __tls_init:
>> .LFB19:
>>         cmpb    $0, %fs:__tls_guard@tpoff
>>         je      .L7
>>         rep; ret
>> .L7:
>>         subq    $8, %rsp
>>         movl    $.LC1, %edi
>>         movb    $1, %fs:__tls_guard@tpoff
>>         call    puts
>>         movq    %fs:0, %rsi
>>         movl    $__dso_handle, %edx
>>         movl    $_ZN1XD1Ev, %edi
>>         addq    $8, %rsp
>>         addq    $_ZL1x@tpoff, %rsi
>>         jmp     __cxa_thread_atexit
> vs. the same for cygwin:
>> __tls_init:
>>         subq    $40, %rsp
>>         leaq    __emutls_v.__tls_guard(%rip), %rcx
>>         call    __emutls_get_address
>>         cmpb    $0, (%rax)
>>         je      .L27
>>         addq    $40, %rsp
>>         ret
>> .L27:
>>         leaq    .LC0(%rip), %rcx
>>         movb    $1, (%rax)
>>         addq    $40, %rsp
>>         jmp     puts
>
> Relevant packages installed:
> binutils                              2.24.51-4
> cygwin                                1.7.30-1
> gcc-core                              4.8.3-2
> gcc-g++                               4.8.3-2
> libstdc++6                            4.8.3-2
>
> (I realize I'm a version behind on cygwin1.dll, but I don't think that's the
> problem here)
>
> Thoughts?


Well it's not a general gcc problem because the same code on Linux with
version 4.8.3 works for me.

-- 
Larry

_____________________________________________________________________

A: Yes.
 > Q: Are you sure?
 >> A: Because it reverses the logical flow of conversation.
 >>> Q: Why is top posting annoying in email?

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Destructors not called for c++11 thread_local objects
  2014-08-01 17:42 ` Larry Hall (Cygwin)
@ 2014-08-01 18:17   ` Corinna Vinschen
  0 siblings, 0 replies; 3+ messages in thread
From: Corinna Vinschen @ 2014-08-01 18:17 UTC (permalink / raw)
  To: cygwin; +Cc: Ryan Johnson

[-- Attachment #1: Type: text/plain, Size: 1599 bytes --]

On Aug  1 13:41, Larry Hall (Cygwin) wrote:
> On 08/01/2014 01:32 PM, Ryan Johnson wrote:
> >Hi all,
> >
> >(Please CC me in replies, I'm not subscribed to the list)
> >
> >Question: is this a Cygwin bug, gcc bug, or somebody else's bug entirely?
> >
> >The following STC shows the problem:
> >
> >$ cat bug.cpp
> >#include <cstdio>
> >static thread_local struct X {
> >     int x;
> >     X() { puts("hi"); }
> >     ~X() { puts("bye!"); }
> >} x;
> >int main() { x.x = 0; }
> >
> >$ g++ -std=gnu++11 -Wall -g bug.cpp && ./a
> >hi
> >
> >A quick inspection of the assembly code shows no call to __cxa_thread_atexit
> >in __tls_init, where the same code compiled on linux, with the same version
> >of gcc, has it right. This is odd, because the function does seem to be
> >available in cygwin's libstdc++:
> >
> >$ nm /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/libstdc++.a | grep thread_atexit
> >0000000000000000 d .data$_ZZ19__cxa_thread_atexitE4once
> >0000000000000000 p .pdata$__cxa_thread_atexit
> >0000000000000000 t .text$__cxa_thread_atexit
> >0000000000000000 r .xdata$__cxa_thread_atexit
> >0000000000000000 T __cxa_thread_atexit
> >0000000000000000 d _ZZ19__cxa_thread_atexitE4once
> >[...]
> 
> Well it's not a general gcc problem because the same code on Linux with
> version 4.8.3 works for me.

It seems thread_local storage needs to be implemented in GCC for the
target, and it isn't.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-01 18:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 17:33 Destructors not called for c++11 thread_local objects Ryan Johnson
2014-08-01 17:42 ` Larry Hall (Cygwin)
2014-08-01 18:17   ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).