Bug 14342

Summary: [gold] symbol 'std::__once_callable' used as both __thread and non-__thread
Product: binutils Reporter: Vincenzo Innocente <vincenzo.innocente>
Component: goldAssignee: Ian Lance Taylor <ian>
Status: RESOLVED FIXED    
Severity: critical CC: ccoutant, compnerd, cryptooctoploid, dushistov, hubicka, markus
Priority: P2    
Version: 2.22   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Vincenzo Innocente 2012-07-09 23:37:25 UTC
crospost from gcc http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53895

with
GNU gold (GNU Binutils 2.22.52.20120515) 1.11
and a recent gcc
gcc version 4.7.2 20120629 (prerelease) [gcc-4_7-branch revision 189081] (GCC)
gcc version 4.8.0 20120708 (experimental) [trunk revision 189362] (GCC) 

I get

c++ thread.cpp -pthread -std=gnu++0x -O2 -flto
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: error:
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../lib64/libstdc++.so:
symbol 'std::__once_call' used as both __thread and non-__thread
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: /tmp/innocent/ccd0XlxC.o:
previous definition here
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: error:
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../lib64/libstdc++.so:
symbol 'std::__once_callable' used as both __thread and non-__thread
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: /tmp/innocent/ccd0XlxC.o:
previous definition here
collect2: error: ld returned 1 exit status

works w/o lto or with BFD linker.

Please refers to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53895 for details and code example
Comment 1 Jan Hubicka 2013-08-10 09:33:47 UTC
This problem now reprduce with mainline GCC indirect call profiling test
gcc.dg/tree-prof/crossmodule-indircall-1.c:

evans:/abuild/jh/trunk-3/build-inst11-check/gcc/:[2]# ./xgcc -B ./ -O3 -flto -fprofile-generate ../../gcc/testsuite/gcc.dg/tree-prof/crossmodule-indircall-1*.c --save-temps
/abuild/jh/trunk-install/x86_64-unknown-linux-gnu/bin/ld: crossmodule-indircall-1.o: previous definition here
/abuild/jh/trunk-install/x86_64-unknown-linux-gnu/bin/ld: error: ./libgcov.a(_gcov_indirect_call_profiler.o): symbol '__gcov_indirect_call_callee' used as both __thread and non-__thread
/abuild/jh/trunk-install/x86_64-unknown-linux-gnu/bin/ld: crossmodule-indircall-1.o: previous definition here

while it links just fine with GNU-ld or with gold and -fno-lto.
The symbol is used as TLS symbol.  non-LTO uses:

crossmodule-indircall-1.s:      movq    __gcov_indirect_call_callee@gottpoff(%rip), %r12
crossmodule-indircall-1a.s:     movq    __gcov_indirect_call_callee@gottpoff(%rip), %rax

LTO uses:

ccsUXr3s.ltrans0.s:     movq    __gcov_indirect_call_callee@gottpoff(%rip), %rbp

and libgcc definition is:

        leaq    __gcov_indirect_call_callee@tlsgd(%rip), %rdi
        .globl  __gcov_indirect_call_callee
        .type   __gcov_indirect_call_callee, @object
        .size   __gcov_indirect_call_callee, 8
__gcov_indirect_call_callee:
        .long   __gcov_indirect_call_callee@dtpoff, 0
        .string "__gcov_indirect_call_callee"

I am not an expert on TLS, but it seems all right to me, since all goes through tls and gottpoff or dtpoff.

I am not really happy about leaving -fprofile-generate broken with -flto on mainline. Is there a workaround? I really need this TLS variable...
Comment 2 Cary Coutant 2013-08-12 17:37:46 UTC
> This problem now reprduce with mainline GCC indirect call profiling test
> gcc.dg/tree-prof/crossmodule-indircall-1.c:
>
> evans:/abuild/jh/trunk-3/build-inst11-check/gcc/:[2]# ./xgcc -B ./ -O3 -flto
> -fprofile-generate
> ../../gcc/testsuite/gcc.dg/tree-prof/crossmodule-indircall-1*.c --save-temps
> /abuild/jh/trunk-install/x86_64-unknown-linux-gnu/bin/ld:
> crossmodule-indircall-1.o: previous definition here
> /abuild/jh/trunk-install/x86_64-unknown-linux-gnu/bin/ld: error:
> ./libgcov.a(_gcov_indirect_call_profiler.o): symbol
> '__gcov_indirect_call_callee' used as both __thread and non-__thread
> /abuild/jh/trunk-install/x86_64-unknown-linux-gnu/bin/ld:
> crossmodule-indircall-1.o: previous definition here

I get:

.../gold/ld-new: error: crossmodule-indircall-1.o: multiple definition of 'main'
.../gold/ld-new: crossmodule-indircall-1a.o: previous definition here

If I add -DDOJOB=1 to the command line, though, it works for me.

Are you using a recent version of gold? I think the TLS problem should
have been fixed with this patch:

    http://sourceware.org/ml/binutils/2013-06/msg00139.html

-cary
Comment 3 hubicka 2013-08-17 21:48:16 UTC
> Are you using a recent version of gold? I think the TLS problem should
> have been fixed with this patch:
> 
>     http://sourceware.org/ml/binutils/2013-06/msg00139.html

This indeed looks like exactly the problem I hit.  I checked only the
release versions of gold, not trunk, so guess it is fixed now.

Was the same problem fixed on GNU ld side, too?

Honza
Comment 4 Cary Coutant 2013-08-19 16:45:14 UTC
>> Are you using a recent version of gold? I think the TLS problem should
>> have been fixed with this patch:
>>
>>     http://sourceware.org/ml/binutils/2013-06/msg00139.html
>
> This indeed looks like exactly the problem I hit.  I checked only the
> release versions of gold, not trunk, so guess it is fixed now.
>
> Was the same problem fixed on GNU ld side, too?

I thought GNU ld didn't have this bug, but I'll check.

-cary
Comment 5 hubicka 2013-08-20 19:11:55 UTC
> I thought GNU ld didn't have this bug, but I'll check.
It reproduced for me for both GNU ld and gold in the latest release version.

The testcase seen by GCC may be different from normal file, since libgcov is runtime
library (there is some magic of passing it down to linker and allow new references
to it to be born at LTO plugin).  The way to disable workaround I put in place in mainline GCC is to
turn flag_lto into 0 in all occurences in tree-profile.c
It should trigger failure of ./gcc.dg/tree-prof/crossmodule-indircall-1.c

Honza
Comment 6 Jackie Rosen 2014-02-16 19:42:44 UTC
*** Bug 260998 has been marked as a duplicate of this bug. ***
Seen from the domain http://volichat.com
Page where seen: http://volichat.com/adult-chat-rooms
Marked for reference. Resolved as fixed @bugzilla.
Comment 7 Markus Trippelsdorf 2014-09-26 08:49:51 UTC
Fixed in binutils-2.24.