Skip to content

Linker directives within the .drectve section of generated COFF object files are unnecessarily quoted, slowing down MSVC LINK.EXE significantly #68245

@januszn

Description

@januszn

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

return isAlnum(C) || C == '_' || C == '@';
, 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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions