[clang] [clang][flang][windows] Prefer user-provided library paths (-L) (PR #90758)
David Truby via cfe-commits
cfe-commits at lists.llvm.org
Mon May 13 06:46:53 PDT 2024
https://github.com/DavidTruby updated https://github.com/llvm/llvm-project/pull/90758
>From 9763281019c1fb27714243450d7a6879e91dcb28 Mon Sep 17 00:00:00 2001
From: David Truby <david at truby.dev>
Date: Wed, 1 May 2024 19:41:47 +0100
Subject: [PATCH 1/3] [clang][flang][windows] Prefer user-provided library
paths (-L)
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.
---
clang/lib/Driver/ToolChains/MSVC.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
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))
>From 30d175dff6b88ab4e74f73358c2074bb3354b345 Mon Sep 17 00:00:00 2001
From: David Truby <david at truby.dev>
Date: Fri, 3 May 2024 14:29:45 +0100
Subject: [PATCH 2/3] Add tests
---
clang/test/Driver/flang/msvc-link.f90 | 8 ++++++++
clang/test/Driver/msvc-link.cpp | 7 +++++++
2 files changed, 15 insertions(+)
create mode 100644 clang/test/Driver/flang/msvc-link.f90
create mode 100644 clang/test/Driver/msvc-link.cpp
diff --git a/clang/test/Driver/flang/msvc-link.f90 b/clang/test/Driver/flang/msvc-link.f90
new file mode 100644
index 0000000000000..6a1af043e9d2b
--- /dev/null
+++ b/clang/test/Driver/flang/msvc-link.f90
@@ -0,0 +1,8 @@
+! REQUIRES: system-windows
+!
+! 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"
+! CHECK: "-libpath:{{.*}}\\lib"
+! CHECK: "-libpath:{{.*}}\\lib\\clang\\{{[0-9]+}}\\lib\\windows"
diff --git a/clang/test/Driver/msvc-link.cpp b/clang/test/Driver/msvc-link.cpp
new file mode 100644
index 0000000000000..4d53fe49782e5
--- /dev/null
+++ b/clang/test/Driver/msvc-link.cpp
@@ -0,0 +1,7 @@
+// REQUIRES: system-windows
+//
+// RUN: %clang -### %s -Ltest 2>&1 | FileCheck %s
+//
+// Test that user provided paths come before compiler-rt
+// CHECK: "-libpath:test"
+// CHECK: "-libpath:{{.*}}\\lib\\clang\\{{[0-9]+}}\\lib\\windows"
>From f5f13766b19e3aba61a84bc72d85707e52976e00 Mon Sep 17 00:00:00 2001
From: David Truby <david.truby at arm.com>
Date: Mon, 13 May 2024 13:46:07 +0000
Subject: [PATCH 3/3] Remove c test and make Fortran test not require windows
---
clang/test/Driver/flang/msvc-link.f90 | 9 +++------
clang/test/Driver/msvc-link.cpp | 7 -------
2 files changed, 3 insertions(+), 13 deletions(-)
delete mode 100644 clang/test/Driver/msvc-link.cpp
diff --git a/clang/test/Driver/flang/msvc-link.f90 b/clang/test/Driver/flang/msvc-link.f90
index 6a1af043e9d2b..536da2599431f 100644
--- a/clang/test/Driver/flang/msvc-link.f90
+++ b/clang/test/Driver/flang/msvc-link.f90
@@ -1,8 +1,5 @@
-! REQUIRES: system-windows
+! RUN: %clang --driver-mode=flang -target x86_64-pc-windows-msvc -### %s -Ltest 2>&1 | FileCheck %s
!
-! RUN: %clang --driver-mode=flang -### %s -Ltest 2>&1 | FileCheck %s
-!
-! Test that user provided paths come before the Flang runtimes and compiler-rt
+! Test that user provided paths come before the Flang runtimes
! CHECK: "-libpath:test"
-! CHECK: "-libpath:{{.*}}\\lib"
-! CHECK: "-libpath:{{.*}}\\lib\\clang\\{{[0-9]+}}\\lib\\windows"
+! CHECK: "-libpath:{{.*(\\|/)}}lib"
diff --git a/clang/test/Driver/msvc-link.cpp b/clang/test/Driver/msvc-link.cpp
deleted file mode 100644
index 4d53fe49782e5..0000000000000
--- a/clang/test/Driver/msvc-link.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-// REQUIRES: system-windows
-//
-// RUN: %clang -### %s -Ltest 2>&1 | FileCheck %s
-//
-// Test that user provided paths come before compiler-rt
-// CHECK: "-libpath:test"
-// CHECK: "-libpath:{{.*}}\\lib\\clang\\{{[0-9]+}}\\lib\\windows"
More information about the cfe-commits
mailing list