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

    <tr>
        <th>Summary</th>
        <td>
            Linker directives within the .drectve section of generate COFF object files are unnecessarily quoted, slowing down MSVC LINK.EXE significanly
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    This was observed with vanilla Clang 16.0.6 built from source, and 16.0.5 distributed by MS with Visual Studio 2022 17.7.4, however the offending code is in the lower-level LLVM code, not Clang's. In https://github.com/llvm/llvm-project/blob/7cbf1a2591520c2491aa35339f227775f4d3adf6/llvm/lib/IR/Mangler.cpp#L194, which determines which characters in a symbol's name require it to be quoted within a linker directive, the $ and ? characters, both common in the MS ABI mangling scheme, are not exempted. This results in Clang emitting /EXPORT directives with the names quoted for most C++ symbols to be exported from a DLL. The MSVC linker has a massive performance issue with parsing .drectve sections when either linking a DLL or creating an import library from the Clang-built .OBJ files that becomes apparent when there are enough exported symbols. And since llvm-lib doesn't support the /DEF switch, using LIB.EXE from the MSVC toolchain (which just calls LINK.EXE /LIB) is required if the DLLs to be built have circular dependencies (see https://learn.microsoft.com/en-us/cpp/build/reference/using-an-import-library-and-export-file?view=msvc-170), which is the case for Unreal Editor. 

Detailed repro steps tailored for the corresponding issue in the MSVC linker are at: https://developercommunity.visualstudio.com/t/Poor-performance-linking-DLLs-with-LINK/10483519

The LLVM-side fix appears simple - don't trigger quoting names with '$' and '?' `if (TT.isWindowsMSVCEnvironment())` and I can quickly create a PR with that fix - are there perhaps issues with that approach that I'm not seeing?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVk2T2jwS_jXi0mWXkTHGBw7z5Sp2mU0qmc2-V1lqY-WVJUctQ9hfvyUZMlNz28tMgSypn08jiPTJIu5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