-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][flang][windows] Prefer user-provided library paths (-L) #90758
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
Conversation
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: David Truby (DavidTruby) ChangesCurrently the paths to compiler-rt and the Flang runtimes from the LLVM build/install directory are preferred over any user-provided library paths. This means a user can't override compiler-rt or the Flang runtimes with custom versions. This patch changes the link order to prefer library paths specified with -L over the LLVM paths. This matches the behaviour of clang and flang on Linux. Full diff: https://github.com/llvm/llvm-project/pull/90758.diff 1 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index fbf2f45b543844..b7021d4b996ddd 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -134,6 +134,10 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Args.MakeArgString(std::string("-libpath:") + WindowsSdkLibPath));
}
+ if (!C.getDriver().IsCLMode() && Args.hasArg(options::OPT_L))
+ for (const auto &LibPath : Args.getAllArgValues(options::OPT_L))
+ CmdArgs.push_back(Args.MakeArgString("-libpath:" + LibPath));
+
if (C.getDriver().IsFlangMode()) {
addFortranRuntimeLibraryPath(TC, Args, CmdArgs);
addFortranRuntimeLibs(TC, Args, CmdArgs);
@@ -154,10 +158,6 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (TC.getVFS().exists(CRTPath))
CmdArgs.push_back(Args.MakeArgString("-libpath:" + CRTPath));
- if (!C.getDriver().IsCLMode() && Args.hasArg(options::OPT_L))
- for (const auto &LibPath : Args.getAllArgValues(options::OPT_L))
- CmdArgs.push_back(Args.MakeArgString("-libpath:" + LibPath));
-
CmdArgs.push_back("-nologo");
if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
|
Thanks. Can you add a test? Possibly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
I've left some nits, feel free to ignore
@@ -0,0 +1,8 @@ | |||
! REQUIRES: system-windows | |||
! | |||
! RUN: %clang --driver-mode=flang -### %s -Ltest 2>&1 | FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] test
-> random_test_dir
or something else that will make this stand out a bit more (makes parsing tests a bit easier)
! RUN: %clang --driver-mode=flang -### %s -Ltest 2>&1 | FileCheck %s | ||
! | ||
! Test that user provided paths come before the Flang runtimes and compiler-rt | ||
! CHECK: "-libpath:test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering how to check that there's no -libapth
before -libpath:test
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
。
clang/test/Driver/msvc-link.cpp
Outdated
@@ -0,0 +1,7 @@ | |||
// REQUIRES: system-windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests to existing msvc-link.c instead of a new file. Specify --target=
to avoid reliance on the default target triple and avoid the need of REQUIRES.
The code checks whether the directory is present With Since there is no good way to test this, I'm fine with the patch without a test. |
Hi, I'm not sure I understand exactly what you mean by without a test; do you mean I should just remove the tests I tried to add or is there some extra behaviour that you're talking about that can't be tested? |
Currently the paths to compiler-rt and the Flang runtimes from the LLVM build/install directory are preferred over any user-provided library paths. This means a user can't override compiler-rt or the Flang runtimes with custom versions. This patch changes the link order to prefer library paths specified with -L over the LLVM paths. This matches the behaviour of clang and flang on Linux.
I've left the flang test as the flang directory doesn't change with |
That's matches how I read that suggestion re From what I can tell, you've already made all the changes requested from @MaskRay . If there are no new comments today, I suggest landing this. |
Currently the paths to compiler-rt and the Flang runtimes from the LLVM build/install directory are preferred over any user-provided library paths. This means a user can't override compiler-rt or the Flang runtimes with custom versions.
This patch changes the link order to prefer library paths specified with -L over the LLVM paths. This matches the behaviour of clang and flang on Linux.