[llvm] 33f2686 - [llvm-jitlink] Only use candidate library extensions during library search.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 22 23:16:18 PST 2025
Author: Lang Hames
Date: 2025-02-23T18:16:10+11:00
New Revision: 33f2686beda0a5e677eb0e4c386e5f72b8c2573c
URL: https://github.com/llvm/llvm-project/commit/33f2686beda0a5e677eb0e4c386e5f72b8c2573c
DIFF: https://github.com/llvm/llvm-project/commit/33f2686beda0a5e677eb0e4c386e5f72b8c2573c.diff
LOG: [llvm-jitlink] Only use candidate library extensions during library search.
While processing library link options that check search paths (-lx, -hidden-lx,
etc.) we shouldn't generate candidate paths with extensions that are invalid
for the option being visited (e.g. -hidden-lx only applies to archives, so we
shouldn't generate candidates with `.so` extensions).
Note: Candidate extensions should probably be further filtered based on the OS
of the executing process. This patch is a step in the right direction though.
Added:
Modified:
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index d6fd06c52c212..0421b86480254 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -2141,7 +2141,7 @@ static Error addLibraries(Session &S,
std::string LibName;
bool IsPath = false;
unsigned Position;
- StringRef *CandidateExtensions;
+ ArrayRef<StringRef> CandidateExtensions;
enum { Standard, Hidden } Modifier;
};
@@ -2157,7 +2157,7 @@ static Error addLibraries(Session &S,
LL.LibName = InputFile.str();
LL.IsPath = true;
LL.Position = InputFiles.getPosition(InputFileItr - InputFiles.begin());
- LL.CandidateExtensions = nullptr;
+ LL.CandidateExtensions = {};
LL.Modifier = LibraryLoad::Standard;
LibraryLoadQueue.push_back(std::move(LL));
}
@@ -2169,7 +2169,7 @@ static Error addLibraries(Session &S,
LL.LibName = *LibItr;
LL.IsPath = true;
LL.Position = LoadHidden.getPosition(LibItr - LoadHidden.begin());
- LL.CandidateExtensions = nullptr;
+ LL.CandidateExtensions = {};
LL.Modifier = LibraryLoad::Hidden;
LibraryLoadQueue.push_back(std::move(LL));
}
@@ -2286,12 +2286,12 @@ static Error addLibraries(Session &S,
auto CurJDSearchPaths = JDSearchPaths[&JD];
for (StringRef SearchPath :
concat<StringRef>(CurJDSearchPaths, SystemSearchPaths)) {
- for (const char *LibExt : {".dylib", ".so", ".dll", ".a", ".lib"}) {
+ for (auto LibExt : LL.CandidateExtensions) {
SmallVector<char, 256> LibPath;
LibPath.reserve(SearchPath.size() + strlen("lib") + LL.LibName.size() +
- strlen(LibExt) + 2); // +2 for pathsep, null term.
+ LibExt.size() + 2); // +2 for pathsep, null term.
llvm::copy(SearchPath, std::back_inserter(LibPath));
- if (StringRef(LibExt) != ".lib" && StringRef(LibExt) != ".dll")
+ if (LibExt != ".lib" && LibExt != ".dll")
sys::path::append(LibPath, "lib" + LL.LibName + LibExt);
else
sys::path::append(LibPath, LL.LibName + LibExt);
More information about the llvm-commits
mailing list