Skip to content

Commit 631f10d

Browse files
[BOLT] make runtime respect gnu install dirs
1 parent 0995508 commit 631f10d

File tree

7 files changed

+52
-18
lines changed

7 files changed

+52
-18
lines changed

bolt/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ if(BOLT_BUILT_STANDALONE)
5151
include_directories(${LLVM_INCLUDE_DIRS})
5252
link_directories("${LLVM_LIBRARY_DIR}")
5353

54-
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
55-
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
56-
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
54+
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_INSTALL_BINDIR}" )
55+
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}/${LLVM_LIBDIR_SUFFIX}" )
56+
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}/${LLVM_LIBDIR_SUFFIX}")
5757
endif() # standalone
5858

5959
# Determine default set of targets to build -- the intersection of

bolt/include/bolt/RuntimeLibs/RuntimeLibrary.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,16 @@ class RuntimeLibrary {
5858
uint64_t RuntimeFiniAddress{0};
5959
uint64_t RuntimeStartAddress{0};
6060

61-
/// Get the full path to a runtime library specified by \p LibFileName.
61+
/// Get the full path to a runtime library specified by \p LibFileName and \p
62+
/// ToolPath.
63+
static std::string getLibPathByToolPath(StringRef ToolPath,
64+
StringRef LibFileName);
65+
66+
/// Get the full path to a runtime library by the install directory.
67+
static std::string getLibPathByInstalled(StringRef LibFileName);
68+
69+
/// Gets the full path to a runtime library based on whether it exists
70+
/// in the install libdir or runtime libdir.
6271
static std::string getLibPath(StringRef ToolPath, StringRef LibFileName);
6372

6473
/// Load a static runtime library specified by \p LibPath.

bolt/lib/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
add_compile_definitions(CMAKE_INSTALL_FULL_LIBDIR="${CMAKE_INSTALL_FULL_LIBDIR}")
2+
13
add_subdirectory(Core)
24
add_subdirectory(Passes)
35
add_subdirectory(Profile)

bolt/lib/RuntimeLibs/HugifyRuntimeLibrary.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ cl::opt<bool>
3232
"(which is what --hot-text relies on)."),
3333
cl::cat(BoltOptCategory));
3434

35-
static cl::opt<std::string> RuntimeHugifyLib(
36-
"runtime-hugify-lib",
37-
cl::desc("specify file name of the runtime hugify library"),
38-
cl::init("libbolt_rt_hugify.a"), cl::cat(BoltOptCategory));
35+
static cl::opt<std::string>
36+
RuntimeHugifyLib("runtime-hugify-lib",
37+
cl::desc("specify path of the runtime hugify library"),
38+
cl::init("libbolt_rt_hugify.a"), cl::cat(BoltOptCategory));
3939

4040
} // namespace opts
4141

bolt/lib/RuntimeLibs/InstrumentationRuntimeLibrary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace opts {
2626

2727
cl::opt<std::string> RuntimeInstrumentationLib(
2828
"runtime-instrumentation-lib",
29-
cl::desc("specify file name of the runtime instrumentation library"),
29+
cl::desc("specify path of the runtime instrumentation library"),
3030
cl::init("libbolt_rt_instr.a"), cl::cat(BoltOptCategory));
3131

3232
extern cl::opt<bool> InstrumentationFileAppendPID;

bolt/lib/RuntimeLibs/RuntimeLibrary.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ using namespace bolt;
2626

2727
void RuntimeLibrary::anchor() {}
2828

29-
std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
30-
StringRef LibFileName) {
29+
std::string RuntimeLibrary::getLibPathByToolPath(StringRef ToolPath,
30+
StringRef LibFileName) {
3131
StringRef Dir = llvm::sys::path::parent_path(ToolPath);
3232
SmallString<128> LibPath = llvm::sys::path::parent_path(Dir);
3333
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
@@ -38,13 +38,36 @@ std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
3838
llvm::sys::path::append(LibPath, "lib" LLVM_LIBDIR_SUFFIX);
3939
}
4040
llvm::sys::path::append(LibPath, LibFileName);
41-
if (!llvm::sys::fs::exists(LibPath)) {
42-
errs() << "BOLT-ERROR: library not found: " << LibPath << "\n";
43-
exit(1);
44-
}
4541
return std::string(LibPath);
4642
}
4743

44+
std::string RuntimeLibrary::getLibPathByInstalled(StringRef LibFileName) {
45+
SmallString<128> LibPath(CMAKE_INSTALL_FULL_LIBDIR);
46+
llvm::sys::path::append(LibPath, LibFileName);
47+
return std::string(LibPath);
48+
}
49+
50+
std::string RuntimeLibrary::getLibPath(StringRef ToolPath,
51+
StringRef LibFileName) {
52+
if (llvm::sys::fs::exists(LibFileName)) {
53+
return std::string(LibFileName);
54+
}
55+
56+
std::string ByTool = getLibPathByToolPath(ToolPath, LibFileName);
57+
if (llvm::sys::fs::exists(ByTool)) {
58+
return ByTool;
59+
}
60+
61+
std::string ByInstalled = getLibPathByInstalled(LibFileName);
62+
if (llvm::sys::fs::exists(ByInstalled)) {
63+
return ByInstalled;
64+
}
65+
66+
errs() << "BOLT-ERROR: library not found: " << ByTool << ", " << ByInstalled
67+
<< ", or " << LibFileName << "\n";
68+
exit(1);
69+
}
70+
4871
void RuntimeLibrary::loadLibrary(StringRef LibPath, BOLTLinker &Linker,
4972
BOLTLinker::SectionsMapper MapSections) {
5073
ErrorOr<std::unique_ptr<MemoryBuffer>> MaybeBuf =

bolt/runtime/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ target_include_directories(bolt_rt_instr PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
4646
target_compile_options(bolt_rt_hugify PRIVATE ${BOLT_RT_FLAGS})
4747
target_include_directories(bolt_rt_hugify PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
4848

49-
install(TARGETS bolt_rt_instr DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
50-
install(TARGETS bolt_rt_hugify DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
49+
install(TARGETS bolt_rt_instr DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
50+
install(TARGETS bolt_rt_hugify DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
5151

5252
if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" AND CMAKE_SYSTEM_NAME STREQUAL "Darwin")
5353
add_library(bolt_rt_instr_osx STATIC
@@ -59,5 +59,5 @@ if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" AND CMAKE_SYSTEM_NAME STREQUAL "Da
5959
target_compile_options(bolt_rt_instr_osx PRIVATE
6060
-target x86_64-apple-darwin19.6.0
6161
${BOLT_RT_FLAGS})
62-
install(TARGETS bolt_rt_instr_osx DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
62+
install(TARGETS bolt_rt_instr_osx DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}")
6363
endif()

0 commit comments

Comments
 (0)