<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63741>63741</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Support `--dependent-lib=`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
h-vetinari
</td>
</tr>
</table>
<pre>
Splitting this off of #60730 to make it more actionable.
Aside from the issues `__udivti3` (probably related to 128bit support, see #63712), there's an issue of using flang on windows to compile against the MSVC runtime, which comes in different flavours (mainly shared vs static, but also debug vs release). In particular, it seems that flang defaults to using the static library, which is incompatible with some other bits of our infra.
The windows switches between shared/static use the flags `/MD` vs `/MT`. To this end, he clang driver has [`ProcessVSRuntimeLibrary`](https://github.com/llvm/llvm-project/blob/llvmorg-16.0.6/clang/lib/Driver/ToolChains/Clang.cpp#L4403-L4466) plus an option to pass `--dependent-lib=...` to the frontend driver.
Based on what's encoded in `ProcessVSRuntimeLibrary` (and matching information I found elsewhere), the equivalent of `/MD` would then be
```
-D_MT -D_DLL -Xflang --dependent-lib=msvcrt
```
However, `flang-new -fc1` doesn't have a similar option to `--dependent-lib` AFAICT.
Trying to somehow monkey-patch things through the current interface, I see that it still wants to use the wrong (static) VS Runtime lib.
```
>flang-new -flang-experimental-exec hello_world.f90 -l path\to\clang_rt.builtins-x86_64.lib -D_MT -D_DLL -Wl,/DEFAULTLIB:msvcrt.lib
LINK : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
```
IIUC, it would be required to provide an equivalent to clang's `-Xclang --dependent-lib=` also for flang. Since flang uses the clang driver underneath, it's hopefully not too complicated to pipe this through?
CC @klausler @banach-space
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVtFu27gS_Rr6ZSBBpmTJfvCDY9e4Rt3ei5u027eAokYWtxSpJSmr-fvFUE7rYLMLLBA4E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