[lld] b6c2f10 - [lld][COFF] Find libraries with relative paths.
Tobias Hieta via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 03:09:48 PDT 2023
Author: Tobias Hieta
Date: 2023-07-14T12:09:26+02:00
New Revision: b6c2f100c23bb715edbec57a4894f1ae551cd1d4
URL: https://github.com/llvm/llvm-project/commit/b6c2f100c23bb715edbec57a4894f1ae551cd1d4
DIFF: https://github.com/llvm/llvm-project/commit/b6c2f100c23bb715edbec57a4894f1ae551cd1d4.diff
LOG: [lld][COFF] Find libraries with relative paths.
This patch is spun out of https://reviews.llvm.org/D151188
and makes it possible for lld-link to find libraries with
relative paths. This will be used later to implement the
changes to autolinking runtimes explained in #63827
Differential Revision: https://reviews.llvm.org/D155268
Added:
lld/test/COFF/relative_search_paths.test
Modified:
lld/COFF/Driver.cpp
lld/docs/ReleaseNotes.rst
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 5cefdac3395ebf..5f11d11ea72538 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -483,8 +483,7 @@ StringRef LinkerDriver::findFile(StringRef filename) {
return filename;
};
- bool hasPathSep = (filename.find_first_of("/\\") != StringRef::npos);
- if (hasPathSep)
+ if (sys::path::is_absolute(filename))
return getFilename(filename);
bool hasExt = filename.contains('.');
for (StringRef dir : searchPaths) {
diff --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst
index dea0d95e5419e2..4bd5a628d2b902 100644
--- a/lld/docs/ReleaseNotes.rst
+++ b/lld/docs/ReleaseNotes.rst
@@ -37,6 +37,12 @@ Breaking changes
COFF Improvements
-----------------
+* lld-link can now find libraries with relative paths that are relative to
+ `/libpath`. Before it would only be able to find libraries relative to the
+ current directory.
+ I.e. ``lld-link /libpath:c:\relative\root relative\path\my.lib`` where before
+ we would have to do ``lld-link /libpath:c:\relative\root\relative\path my.lib``
+
MinGW Improvements
------------------
diff --git a/lld/test/COFF/relative_search_paths.test b/lld/test/COFF/relative_search_paths.test
new file mode 100644
index 00000000000000..8c89e9aa0c6682
--- /dev/null
+++ b/lld/test/COFF/relative_search_paths.test
@@ -0,0 +1,4 @@
+We should be able to find libraries with relative search paths.
+# RUN: mkdir -p %t.dir/relative/path
+# RUN: cp %p/Inputs/std64.lib %t.dir/relative/path
+# RUN: lld-link %p/Inputs/hello64.obj /libpath:%t.dir relative/path/std64.lib /entry:main
More information about the llvm-commits
mailing list