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

    <tr>
        <th>Summary</th>
        <td>
            lld-link not respecting /NODEFAULTLIB with a conflicting /DEFAULTLIB
        </td>
    </tr>

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

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

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

<pre>
    I'm trying to use lld-link to link [C# NativeAOT](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/) apps targeting Windows on Linux, the tooling for which generates an rsp for link.exe that looks something like this:
```
"obj/Release/net8.0/win-x64/native/Hello.obj"
/OUT:"bin/Release/net8.0/win-x64/native/Hello.exe"
/DEF:"obj/Release/net8.0/win-x64/native/Hello.def"
"/home/aaronr/.nuget/packages/runtime.win-x64.microsoft.dotnet.ilcompiler/8.0.7/sdk/bootstrapper.obj"
"/home/aaronr/.nuget/packages/runtime.win-x64.microsoft.dotnet.ilcompiler/8.0.7/sdk/Runtime.WorkstationGC.lib"
"/home/aaronr/.nuget/packages/runtime.win-x64.microsoft.dotnet.ilcompiler/8.0.7/sdk/eventpipe-disabled.lib"
"/home/aaronr/.nuget/packages/runtime.win-x64.microsoft.dotnet.ilcompiler/8.0.7/sdk/Runtime.VxsortEnabled.lib"
"/home/aaronr/.nuget/packages/runtime.win-x64.microsoft.dotnet.ilcompiler/8.0.7/sdk/System.Globalization.Native.Aot.lib"
"/home/aaronr/.nuget/packages/runtime.win-x64.microsoft.dotnet.ilcompiler/8.0.7/sdk/System.IO.Compression.Native.Aot.lib"
"advapi32.lib"
"bcrypt.lib"
"crypt32.lib"
"iphlpapi.lib"
"kernel32.lib"
"mswsock.lib"
"ncrypt.lib"
"normaliz.lib"
"ntdll.lib"
"ole32.lib"
"oleaut32.lib"
"secur32.lib"
"user32.lib"
"version.lib"
"ws2_32.lib"
/NOLOGO /MANIFEST:NO
/DEBUG
/INCREMENTAL:NO
/SUBSYSTEM:CONSOLE
/ENTRY:wmainCRTStartup /NOIMPLIB
/NATVIS:"/home/aaronr/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.7/build/NativeAOT.natvis"
/NODEFAULTLIB:libucrt.lib
/DEFAULTLIB:ucrt.lib
/OPT:REF
/OPT:ICF
```
(all I do with this is pass it into lld-link with -flavor link and paths to the vctoolsdir and winsdkdir that I have locally)

Based on some debugging, lld-link seems to be ignoring the `/nodefaultlib:libucrt.lib` and linking it anyway due to dependencies on libcmt.lib, which contains the directive `/defaultlib:libucrt.lib` and "overrides" the nodefaultlib given in the rsp, contrary to what the docs for these parameters say should happen. This causes there to be duplicate symbols with an output that does not work.
Deleting/renaming libucrt.lib so it cannot be found to be linked solves the problem and makes everything work, but I would much prefer to not have to do that. 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVt9v4j4S_2vMy4goNYXCAw-Ukh5SC6tCd7VPJyceEi-ObdlOKPfXn2zSX7B3392XXakq8sx4Ph_PTGaGOSdKhTglw1syvOuxxlfaTr8JxfXBXaXzRS_X_DhdEnpTg7dHoUrwGhqHICXvS6H24Rx_yfB2TugAVsyLFmfrLRneETquvDeODGaEZoRmEplVSS0Kq53e-aTQNaEZqn7jCM249go9oVmhLYYzGqkDKKGZim77TPvoaQLMGAee2RJ9oNWRBq3gQajmhdA5-ArBay2DfqctHCpRVFCiQss8OmAKrDNRFZ6Q4AuCr5gHqfXegdM1-ipclmIfNCI-JL0j6YyM0u7vdKRU5z8IzZ5QInOBvEI_TlJCs4NQ_ZfR9dsbCM3-hVLqJN6grw6y9fM2xonmQv2mJ3zBj57uFtnJ0-9z4rj74IkSmlW6DmrGrFaW0CxRTRmTZFixZyWGxNlGeVFj0rn9kOBTShMhC10bITF4GCdpckNo5vie0CzX2jtvmTFoz0LyJ-CfurvftN07z7zQ6n6eSJH_YR7YovJGGOxz4Vg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