Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Support --dependent-lib= #63741

Closed
h-vetinari opened this issue Jul 7, 2023 · 4 comments · Fixed by #72519
Closed

[flang] Support --dependent-lib= #63741

h-vetinari opened this issue Jul 7, 2023 · 4 comments · Fixed by #72519

Comments

@h-vetinari
Copy link
Contributor

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 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

@h-vetinari
Copy link
Contributor Author

@EugeneZelenko, could you please mark this as flang-related?

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 10, 2023

@llvm/issue-subscribers-flang-driver

@DavidTruby
Copy link
Member

I'm hoping to fix this with #70833

@DavidTruby
Copy link
Member

#70833 didn't quite fix this correctly but I believe #72519 does

DavidTruby added a commit that referenced this issue Nov 23, 2023
This patch uses the added --dependent-lib support to add the relevant
runtimes on MSVC targets as `/DEFAULTLIB:` sections in the object file
rather than on the link line. This should help CMake support for flang
on Windows.

Fixes #63741 
Fixes #68017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants