[clang] 7ce8d2e - [clang][flang][windows] Prefer user-provided library paths (-L) (#90758)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 16 05:47:52 PDT 2024
Author: David Truby
Date: 2024-05-16T13:47:48+01:00
New Revision: 7ce8d2e5fb9cc5f6f9de214584170a8cf01b98de
URL: https://github.com/llvm/llvm-project/commit/7ce8d2e5fb9cc5f6f9de214584170a8cf01b98de
DIFF: https://github.com/llvm/llvm-project/commit/7ce8d2e5fb9cc5f6f9de214584170a8cf01b98de.diff
LOG: [clang][flang][windows] Prefer user-provided library paths (-L) (#90758)
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.
Added:
clang/test/Driver/flang/msvc-link.f90
Modified:
clang/lib/Driver/ToolChains/MSVC.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index fbf2f45b54384..b7021d4b996dd 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))
diff --git a/clang/test/Driver/flang/msvc-link.f90 b/clang/test/Driver/flang/msvc-link.f90
new file mode 100644
index 0000000000000..536da2599431f
--- /dev/null
+++ b/clang/test/Driver/flang/msvc-link.f90
@@ -0,0 +1,5 @@
+! RUN: %clang --driver-mode=flang -target x86_64-pc-windows-msvc -### %s -Ltest 2>&1 | FileCheck %s
+!
+! Test that user provided paths come before the Flang runtimes
+! CHECK: "-libpath:test"
+! CHECK: "-libpath:{{.*(\\|/)}}lib"
More information about the cfe-commits
mailing list