<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58232>58232</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lld 15] "duplicate symbol: guard variable" errors when mixing gcc and clang .o files
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Romain-Geissler-1A
      </td>
    </tr>
</table>

<pre>
    Hi,

After having upgraded from lld 13 to lld 15, it looks like in certain cases mixing gcc and clang object files doesn't seem to work anymore.

Here is a reduced reproducer from some code using initially Boost asio:

Content of test.h:
```
#pragma once

template <typename T> class tss_ptr
{   
    public:
        tss_ptr() {}
        
        static thread_local T* value_;
};

template <typename T> thread_local T* tss_ptr<T>::value_;

template <typename Value> class call_stack
{
    public:
        static tss_ptr<int> top_;
};      

template <typename Value> tss_ptr<int> call_stack<Value>::top_;

inline int top_of_thread_call_stack()
{
    return *call_stack<int>::top_.value_;

```

Content of test.cpp:
```
#include "test.h"
```

And then try to compile: once with gcc, once with clang, and link both object together using lld (ok, this is silly, as there is no `main`, but this is a reduced scenario of something bigger to expose the error):

```
clang++ -fno-pie -fno-PIE -fno-pic -fno-PIC -o "clang.o" -c "test.cpp"
g++ -fno-pie -fno-PIE -fno-pic -fno-PIC -o "gcc.o" -c "test.cpp"
g++ -no-pie -fuse-ld=lld -o "test" clang.o gcc.o
```

which yields this error:

```
ld.lld: error: duplicate symbol: guard variable for call_stack<int>::top_
>>> defined at test.cpp
>>>            clang.o:(guard variable for call_stack<int>::top_)
>>> defined at test.cpp
>>>            gcc.o:(.bss._ZGVN10call_stackIiE4top_E+0x0)
collect2: error: ld returned 1 exit status
Makefile:6: recipe for target 'test' failed
make: *** [test] Error 1
```

It used to be ok with clang + lld 13.

Note: I used the release LLVM 15.0.2 compiled from source. clang is configured to target the gcc toolchain. gcc was also compiled from source, from a recent commit of the release branch of gcc 11.

If you cannot reproduce, I can provide the two .o files.

I don't know if it's linked, but on the gcc.o file, the guard variable is a "gnu unique symbol". It may (or may not, I don't know) be a problem similar to this mold issue: https://github.com/rui314/mold/issues/524

Cheers,
Romain
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVktv2zgQ_jXyZWDBoiy7PvjgPLYN0BaLxaKHXgJKpGyuKVFLUnH873eGlPxI06RdQ7BIivPNgzMfpzTiuP6kEnabzO6S2Sb-b2ovLez4k2q30Hdby4UUUFvTgNYCshy8iaMCJUF50MbsHWi1l6BaqKT1nN7cSQeNeiacbVUBbwVUmuPMlP_IykOtNO4QRro2YUsPTsqGwA_G7nH3sTFWppemfZIWVTjgYKXoKzTLys4aGtpooTONhMoICb0jvapVXnGtj3BjjPPAnTJJvrkEvTWtl60HU4OXzqe78_fFbHjilOWd5duGg2kreQnhZdNp7iUk-a0_drLlaMXfSX5P_joH3rnHzttBZHkDAHGMA-j6UqvqpBSG3yjDPiRsBSiULO-ud1zPnOdeVeB3VnLxqE3FNZrANvDEdS8fk_xmVH93Hr9j_Y9go1X5LW0go_PNSwU_B_1GO89hQVT9iHZX-1Nk3g3L6ObJDtX6YKrpXvp4GaVfMeoHzAv78ttxW_T5Wl34V61WLVWAD8aY-nEI3wVMOMxXnLXS97YFjPCVzmjHWWP641nC66n6amZXXfdGbqu20j0WTsLYUAeMvQG-wWr2O9mCt0cq2so0HdYzKgjlAQfld1T2xBHnhVD_tERkgPHaQ2lweSAEb7YSMe1QvEQyGDKzJwG_w8LHxyms5oDgSH8khNYAmtcg7ZCV-LHs_UnizBauwiO3ylBEiClwB6op1XaLOtEH-dwZJwkWpLXG0mFdk8WLUAzu3OAD07o1007JOPjz4X5cqcaVW5gaCm-QSg2OYFqd4k2nM0b89zEx0r-GeALsnZxqkeR3FOYIQlKEMRgIEfTnOXDYqWoHRyW1cDHcMWxvxkyLVJPezWkziL7DWqfCdMemNJrWtj23AsnLKl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