Skip to content

Commit 92126ca

Browse files
authored
[LLD] [COFF] Prefer paths specified with -libpath: over toolchain paths (#78039)
The main reason for adding the toolchain paths early was to prefer libraries from the toolchain over ones from MSVC (primarily for compiler-rt builtins). But if the user specifies a directory explicitly with the -libpath: option, that should be preferred over the built-in default paths. This fixes an issue raised at https://discourse.llvm.org/t/lld-prefers-system-llvm-libraries-to-user-provided-ones-on-windows/76148.
1 parent 4fcefbd commit 92126ca

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

lld/COFF/Driver.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,15 +1548,13 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
15481548
{
15491549
llvm::TimeTraceScope timeScope2("Search paths");
15501550
searchPaths.emplace_back("");
1551+
for (auto *arg : args.filtered(OPT_libpath))
1552+
searchPaths.push_back(arg->getValue());
15511553
if (!config->mingw) {
15521554
// Prefer the Clang provided builtins over the ones bundled with MSVC.
15531555
// In MinGW mode, the compiler driver passes the necessary libpath
15541556
// options explicitly.
15551557
addClangLibSearchPaths(argsArr[0]);
1556-
}
1557-
for (auto *arg : args.filtered(OPT_libpath))
1558-
searchPaths.push_back(arg->getValue());
1559-
if (!config->mingw) {
15601558
// Don't automatically deduce the lib path from the environment or MSVC
15611559
// installations when operating in mingw mode. (This also makes LLD ignore
15621560
// winsysroot and vctoolsdir arguments.)

lld/test/COFF/print-search-paths.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj
3-
# RUN: lld-link -safeseh:no /dll /noentry /winsysroot:%t.dir/sysroot /vctoolsversion:1.1.1.1 /winsdkversion:10.0.1 %t.obj -print-search-paths | FileCheck -DSYSROOT=%t.dir %s
3+
# RUN: lld-link -safeseh:no /dll /noentry /winsysroot:%t.dir/sysroot /vctoolsversion:1.1.1.1 /winsdkversion:10.0.1 /libpath:custom-dir %t.obj -print-search-paths | FileCheck -DSYSROOT=%t.dir %s
44
# RUN: llvm-mc -triple i686-windows-msvc %s -filetype=obj -o %t_32.obj
55
# RUN: lld-link -safeseh:no /dll /noentry /winsysroot:%t.dir/sysroot /vctoolsversion:1.1.1.1 /winsdkversion:10.0.1 %t_32.obj -print-search-paths | FileCheck -DSYSROOT=%t.dir -check-prefix=X86 %s
66
# CHECK: Library search paths:
77
# CHECK-NEXT: (cwd)
8+
# CHECK-NEXT: custom-dir
89
# CHECK-NEXT: [[CPATH:.*]]lib{{[/\\]}}clang{{[/\\]}}{{[0-9]+}}{{[/\\]}}lib{{[/\\]}}windows
910
# CHECK-NEXT: [[CPATH]]lib{{[/\\]}}clang{{[/\\]}}{{[0-9]+}}{{[/\\]}}lib
1011
# CHECK-NEXT: [[CPATH]]lib

0 commit comments

Comments
 (0)