Skip to content

Commit 1e0a489

Browse files
authored
[BOLT] Resolve symlink for library lookup (#126386)
1 parent cf5947b commit 1e0a489

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

bolt/lib/RuntimeLibs/RuntimeLibrary.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Object/Archive.h"
1919
#include "llvm/Object/ObjectFile.h"
2020
#include "llvm/Support/Path.h"
21+
#include "llvm/Support/Program.h"
2122

2223
#define DEBUG_TYPE "bolt-rtlib"
2324

@@ -38,6 +39,23 @@ std::string RuntimeLibrary::getLibPathByToolPath(StringRef ToolPath,
3839
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
3940
}
4041
llvm::sys::path::append(LibPath, LibFileName);
42+
if (!llvm::sys::fs::exists(LibPath)) {
43+
// If it is a symlink, check the directory that the symlink points to.
44+
if (llvm::sys::fs::is_symlink_file(ToolPath)) {
45+
SmallString<256> RealPath;
46+
llvm::sys::fs::real_path(ToolPath, RealPath);
47+
if (llvm::ErrorOr<std::string> P =
48+
llvm::sys::findProgramByName(RealPath)) {
49+
outs() << "BOLT-INFO: library not found: " << LibPath << "\n"
50+
<< "BOLT-INFO: " << ToolPath << " is a symlink; will look up "
51+
<< LibFileName
52+
<< " at the target directory that the symlink points to\n";
53+
return getLibPath(*P, LibFileName);
54+
}
55+
}
56+
errs() << "BOLT-ERROR: library not found: " << LibPath << "\n";
57+
exit(1);
58+
}
4159
return std::string(LibPath);
4260
}
4361

0 commit comments

Comments
 (0)