diff --git a/llvm/tools/llvm-jitlink/CMakeLists.txt b/llvm/tools/llvm-jitlink/CMakeLists.txt --- a/llvm/tools/llvm-jitlink/CMakeLists.txt +++ b/llvm/tools/llvm-jitlink/CMakeLists.txt @@ -24,4 +24,22 @@ llvm-jitlink-macho.cpp ) +# If compiler-rt is enabled in this build and the ORC runtime target +# for our platform exists, we can default enable the UseOrcRuntime option +# in llvm-jitlink. +if (APPLE AND CMAKE_SYSTEM_NAME MATCHES Darwin) + # We cannot use get_target_property() here, because compiler-rt is configured + # after LLVM (so the respective target doesn't exist yet). Instead we use a + # generator expression, which evaluates after all targets were configured. + # For that to work we add a manual generation-step for the config file below. + set(USE_ORC_RUNTIME_DEFAULT $) +else() + set(USE_ORC_RUNTIME_DEFAULT 0) +endif() + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/llvm-jitlink-config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/llvm-jitlink-config.h.conf @ONLY) +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/llvm-jitlink-config.h + INPUT ${CMAKE_CURRENT_BINARY_DIR}/llvm-jitlink-config.h.conf) + export_executable_symbols(llvm-jitlink) diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-config.h.in b/llvm/tools/llvm-jitlink/llvm-jitlink-config.h.in new file mode 100644 --- /dev/null +++ b/llvm/tools/llvm-jitlink/llvm-jitlink-config.h.in @@ -0,0 +1 @@ +#define LLVM_JITLINK_USE_ORC_RUNTIME_DEFAULT @USE_ORC_RUNTIME_DEFAULT@ diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -50,6 +50,8 @@ #include #endif // LLVM_ON_UNIX +#include "llvm-jitlink-config.h" + #define DEBUG_TYPE "llvm_jitlink" using namespace llvm; @@ -155,10 +157,10 @@ "oop-executor-connect", cl::desc("Connect to an out-of-process executor via TCP")); -// TODO: Default to false if compiler-rt is not built. -static cl::opt UseOrcRuntime("use-orc-runtime", - cl::desc("Do not required/load ORC runtime"), - cl::init(true)); +static cl::opt + UseOrcRuntime("use-orc-runtime", + cl::desc("Do not required/load ORC runtime"), + cl::init(LLVM_JITLINK_USE_ORC_RUNTIME_DEFAULT)); static cl::opt OrcRuntimePath("orc-runtime-path", cl::desc("Add orc runtime to session"), @@ -1101,7 +1103,14 @@ "lib/clang/12.0.0/lib/darwin/libclang_rt.orc_osx.a"); OrcRuntimePath = DefaultOrcRuntimePath.str().str(); } + + if (!sys::fs::exists(OrcRuntimePath)) + return make_error( + formatv("Cannot find static archive for ORC runtime: {0}", + OrcRuntimePath), + inconvertibleErrorCode()); } + return Error::success(); }