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

    <tr>
        <th>Summary</th>
        <td>
            [lld-link] linker option error: -arm64xsameaddress:__dyn_tls_dtor is not allowed in .drectve (msvcrt.lib(tlsdtor.obj))
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          co-neco
      </td>
    </tr>
</table>

<pre>
    Environment: 
- VS 2022 with latest MSVC toolset(v14314.43.34808), and Windows SDK version(10.0.22621.0).
- Arm64 Windows PC.

I want to build ARM64EC version of V8 engine, but failed with following error:

> Studio/2022/Professional/VC/Tools/MSVC/14.43.34808/lib/ARM64" "-libpath:../../../../../../../../Program Files (x86)/Windows Kits/10/lib/10.0.22621.0/ucrt/arm64" "-libpath:../../../../../../../../Program Files (x86)/Windows Kits/10/lib/10.0.22621.0/um/arm64" /MACHINE:ARM64EC "/IMPLIB:./third_party_abseil-cpp_absl.dll.lib" /DLL "/PDB:./third_party_abseil-cpp_absl.dll.pdb" "@./third_party_abseil-cpp_absl.dll.rsp"
lld-link: error: ignoring unknown argument: -arm64xsameaddress:__dyn_tls_dtor
lld-link: error: -arm64xsameaddress:__dyn_tls_dtor is not allowed in .drectve (msvcrt.lib(tlsdtor.obj))

In tlsdtor.cpp, there is a linker option:
`#ifdef _M_ARM64EC
#pragma comment (linker, "-arm64xsameaddress:__dyn_tls_dtor")
#endif`
It seems that Microsoft VS added arm64xsameaddress option to support some arm64EC compatibility, but lld-link did not notice the fact.

After that, I tested a minimal program hello.cpp with following content:
`#include <iostream>

#pragma comment (linker, "-arm64xsameaddress:__dyn_tls_dtor")

int main() {
 std::cout << "Hello, World!" << std::endl;
    return 0;
}`

If I use MSVC cl.exe and link.exe, it was successful:
> cl /c /WX- /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /EHsc /MDd /GS /fp:precise /arm64EC hello.cpp
link /MACHINE:ARM64EC hello.obj
Run hello.exe and the output was 'Hello, World!'.

But If I use clang-cl and  lld-link, it complained following error:
> clang-cl.exe /c /WX- /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /EHsc /MDd /GS /fp:precise /arm64EC hello.cpp
lld-link /MACHINE:ARM64EC hello.obj
lld-link: warning: ignoring unknown argument: -arm64xsameaddress:__dyn_tls_dtor
lld-link: error: -arm64xsameaddress:__dyn_tls_dtor is not allowed in .drectve (hello.obj).

Another question: 
Here, I used clang-cl from LLVM github latest release version:
> clang-cl.exe -v
clang version 20.1.0
Target: aarch64-pc-windows-msvc
Thread model: posix

But If I use clang-cl from VS 2022 installed version, compile any .cpp file would complain as follow:
> clang-cl -v
clang version 19.1.1
Target: aarch64-pc-windows-msvc
Thread model: posix

> clang-cl.exe /c /WX- /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /EHsc /MDd /GS /fp:precise /arm64EC hello.cpp
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
error: no_builtin attribute has no effect on defaulted or deleted functions
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

This might be the same problem as the linker option error.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWM1y47gRfhro0iUWCer3oAMtiTuutWem1rOe3FQg0JSwCwIMAFrjt081Sck7WW_iqqSSOfgiEST7Q_fXv6AIQR8t4obNb9h8NxFdPDm_kW5qUbpJ5dTzZm-ftHe2QRtZXgBLiyk8PgBPOYezjicwImKIcP_wuIXonAkYGV89ZbM8myWzPMlnq3TF-JrxLQir4Ku2yp0DPOx-hif0QTvL-CpLkzThfMGzJGV8nfT7FL5ZzK4Cn7d0l6XFLZyFjRAdVJ02Copf7hez_faCBq6GxxWgPWqLtGvVRaiFNqgGjWtnjDtrewT03nmWFwMuy_fwEDulHeMlGch4-dm7GgPBCsN4-bhlvPxCVjJeksmMl9-ZWRpdMV72KjHOgXE-NbpqRTyxvEgSxss3_Hz27uhFA6U2GIDx1bfVoqewvJDxs46kQpZet_yewbKTPjJeCqLw_6tI870a5X2x_XD7cc_y4uI41lN9e__57vaGlGO8jCft1aEVPj4fRBVQm6lsW7o0iTIm6bfq4XZ3dyPA591bpVs1SnM2S98i4ENLL6eFMWpqtP2dcuESPaCP1nmKp87-bt3ZgvDH7pIx0972b0E0KJTyGALLi8NBPdtDNOGgovN_hfsGUdABrIsgKKRRgbaQKI8yPiG5qwlP0seBrVU0gUQSV_3W-3A9ppOFyxPZtpQw8YQeCVkA6YQeXBspT4dMWaSM57pWWMPh_jA6kR7wvPXi2AiQriHzSYMBgFApAt_ABblyPaChVbqm7dLiNkJAbALEk4hwr6V3wdWRSpFQChX8CXnUmcpE6NrW-QjBNTi8uN-Sjq2IutJGx-dLmbi4AZRWPa_WRS2RGIFayDhWoKKO6HtVSPAWqAKSDtBoqxthoB3z5oTGOKL1nyuPdDYOAfLCqJWmUwgs32oXokfRsHw_lqb_LrVpoW2ERmgqvYyvgS1vWFpAiIo0ygvpukiKsLwH_0Bm0EZfnTe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