Skip to content

Commit 33f2686

Browse files
committed
[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.
1 parent 21939c4 commit 33f2686

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ static Error addLibraries(Session &S,
21412141
std::string LibName;
21422142
bool IsPath = false;
21432143
unsigned Position;
2144-
StringRef *CandidateExtensions;
2144+
ArrayRef<StringRef> CandidateExtensions;
21452145
enum { Standard, Hidden } Modifier;
21462146
};
21472147

@@ -2157,7 +2157,7 @@ static Error addLibraries(Session &S,
21572157
LL.LibName = InputFile.str();
21582158
LL.IsPath = true;
21592159
LL.Position = InputFiles.getPosition(InputFileItr - InputFiles.begin());
2160-
LL.CandidateExtensions = nullptr;
2160+
LL.CandidateExtensions = {};
21612161
LL.Modifier = LibraryLoad::Standard;
21622162
LibraryLoadQueue.push_back(std::move(LL));
21632163
}
@@ -2169,7 +2169,7 @@ static Error addLibraries(Session &S,
21692169
LL.LibName = *LibItr;
21702170
LL.IsPath = true;
21712171
LL.Position = LoadHidden.getPosition(LibItr - LoadHidden.begin());
2172-
LL.CandidateExtensions = nullptr;
2172+
LL.CandidateExtensions = {};
21732173
LL.Modifier = LibraryLoad::Hidden;
21742174
LibraryLoadQueue.push_back(std::move(LL));
21752175
}
@@ -2286,12 +2286,12 @@ static Error addLibraries(Session &S,
22862286
auto CurJDSearchPaths = JDSearchPaths[&JD];
22872287
for (StringRef SearchPath :
22882288
concat<StringRef>(CurJDSearchPaths, SystemSearchPaths)) {
2289-
for (const char *LibExt : {".dylib", ".so", ".dll", ".a", ".lib"}) {
2289+
for (auto LibExt : LL.CandidateExtensions) {
22902290
SmallVector<char, 256> LibPath;
22912291
LibPath.reserve(SearchPath.size() + strlen("lib") + LL.LibName.size() +
2292-
strlen(LibExt) + 2); // +2 for pathsep, null term.
2292+
LibExt.size() + 2); // +2 for pathsep, null term.
22932293
llvm::copy(SearchPath, std::back_inserter(LibPath));
2294-
if (StringRef(LibExt) != ".lib" && StringRef(LibExt) != ".dll")
2294+
if (LibExt != ".lib" && LibExt != ".dll")
22952295
sys::path::append(LibPath, "lib" + LL.LibName + LibExt);
22962296
else
22972297
sys::path::append(LibPath, LL.LibName + LibExt);

0 commit comments

Comments
 (0)