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

    <tr>
        <th>Summary</th>
        <td>
            Using /Zc:DllexportInlines- and md/d runtime on Windows, msvc stl functions will implicitly implemented, causing mixed link errors
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          GkvJwa
      </td>
    </tr>
</table>

<pre>
    During compilation, a link error like as following blocks me
```
1>lld-link : error : duplicate symbol: public: bool __cdecl std::ios_base::good(void) const
1>>>> defined at C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\include\xiosbase:216
1>>>> xxx.obj
1>>>> defined at MSVCP140D.dll
1>
1>lld-link : error : duplicate symbol: public: struct _Cvtvec __cdecl std::_Locinfo::_Getcvt(void) const
1>>>> defined at C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\include\xlocinfo:277
1>>>> yyy.obj
1>>>> defined at MSVCP140D.dll
1>
1>lld-link : error : duplicate symbol: public: unsigned short const * __cdecl std::_Locinfo::_W_Getdays(void) const
1>>>> defined at C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\include\xlocinfo:331
1>>>> yyy.obj
1>>>> defined at MSVCP140D.dll
1>
1>lld-link : error : duplicate symbol: public: unsigned short const * __cdecl std::_Locinfo::_W_Getmonths(void) const
1>>>> defined at C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\include\xlocinfo:349
1>>>> yyy.obj
1>>>> defined at MSVCP140D.dll
```
After my inspection and modification, I found that this error is caused by static libraries a.lib(implicitly implemented these functions), and b.lib(explicitly linked to the functions in the ms library).

The thing is, I compiled some components of chromium into static libraries(eg:a.lib), but there are some other components in the project that are compiled using msvc(eg:b.lib).
When compiling using the mdd runtime, will encounter the above link error even if use the same msvc stl library.

```
a.lib(xxx.obj/yyy.obj):
mov     rcx, [rsp+78h+var_40] ; this
call    ?_W_Getdays@_Locinfo@std@@QEBAPEBGXZ ; std::_Locinfo::_W_Getdays(void)

b.lib(link MSVCP140D.dll):
mov rcx, [rbp+120h+arg_10]
call cs:__imp_?_W_Getdays@_Locinfo@std@@QEBAPEBGXZ ; std::_Locinfo::_W_Getdays(void)
```

After further checked, I found out that it was caused by the option(/Zc:dllexportInlines-), and chromiuim adds this option when compiling with the following [is_component_build=true use_custom_libcxx=false](https://source.chromium.org/chromium/chromium/src/+/main:build/config/win/BUILD.gn;l=103)

Next, I reproduced it through the following code
```
$ cat a.cpp

#include <iostream>
#include <locale>
#include <sstream>

$ clang-cl a.cpp /c /Foa.obj /MDd /Zc:dllexportInlines-
```

```
; protected: void std::time_get<char, class std::istreambuf_iterator<char, struct std::char_traits<char>>>::_Getvals<wchar_t>(wchar_t, class std::_Locinfo const &)
public ??$_Getvals@_W@?$time_get@DV?$istreambuf_iterator@DU?$char_traits@D@std@@@std@@@std@@IEAAX_WAEBV_Locinfo@1@@Z
??$_Getvals@_W@?$time_get@DV?$istreambuf_iterator@DU?$char_traits@D@std@@@std@@@std@@IEAAX_WAEBV_Locinfo@1@@Z proc near

lea     rdx, [rsp+78h+Src] ; retstr
call ?_Getcvt@_Locinfo@std@@QEBA?AU_Cvtvec@@XZ ; std::_Locinfo::_Getcvt(void)
mov     rcx, [rsp+78h+var_58]
add     rcx, 2Ch ; ','  ; void *
lea     rdx, [rsp+78h+Src] ; Src
mov     r8d, 2Ch ; ','  ; Size
call    memcpy
mov     rcx, [rsp+78h+var_40] ; this
call ?_W_Getdays@_Locinfo@std@@QEBAPEBGXZ ; std::_Locinfo::_W_Getdays(void)
mov     rcx, rax        ; wchar_t *
call    ?_Maklocwcs@std@@YAPEA_WPEB_W@Z ; std::_Maklocwcs(wchar_t const *)
```
I read the relevant code, and for this class(_Locinfo) of stl, it is indeed possible to use it as DLLImportStaticLocalAttr, One less step library linking(msvcprtd.lib)
https://github.com/llvm/llvm-project/blob/0a6f6df5b0c3d0f2a42f013bf5cafb9b5020dcac/clang/lib/Sema/SemaDeclCXX.cpp#L6677-L6697

But if use the above method to compile, some of the static libraries compiled using clang, and the other part uses msvc to compile, will definitely encounter this compilation error when use mdd runtime.

Have any solutions for this kind of mixed compilation method and I found that msvc does not seem to support this option(/Zc:dllexportInlines-), and chromium will encounter compilation problems in the code itself if it does not add this option.

In addition, I also encountered another problem when compiling the chromium runtime using mtd and stl libraries.
[std::_Literal_zero::_Literal_zero](https://github.com/microsoft/STL/issues/4359#issuecomment-2045627013)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWFtv47j1_zTMCxFDpiRfHvLgS7z__JFtp8jMZDovBkUe2dxQpEFSjr2fvjiUZMuepNPBFttODcMWr-d-zu-Ie682BuCO5HOSL294HbbW3f3ysv__V35TWHm8W9ZOmQ0VttopzYOyhrAF5VQr80LBOeuoVi9Auael1dq-4u5CW_HiaQUkWZJkRkZJ-43DIUnvtZa38QqSztpr8EnWO60ED0D9sSqsxrldXWgl8KmwVtP1WkgQmvogSToj6UxZvy64h2a0sVYSNtlbJQmbUmGND2eypy-VUCoDkvJAF3gyX3xwduN4RVdKgyf54lclnPW2DPSz8jXX9CnUUlmSL1jCWHOgBO-VNVyTfPF5QfLFR2t1PPwUh8NskE4GaTpME5IvlBG6lkDyxUFZ3_LMhqO3-DscDgNb_PYd1pHMh2GWLAdS697eP6ZnH1wtAl0v9mEP4luNrx-tUKa07egXCGIffgKl6xPbbDx-i7_j8fgfU3ptYixK6rfWhUaHlLDZd9X_jAaQ_Oh_Kguk6fB_ywKVNWH7k9kgm_5bbXCV52dlAEerI1XG70Bg7aDcSFpZqUo0Q1tMHmhpayNp2PJAw1b51mLKU8FrD5IWR-oDD0pQrQrHnQJP-UCrgrCJqtCmKugjxUeowATAy8ADLWsT6XrCprFuGUmL9iAcTg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