[examples][ORC] Make sure eh-frame registration code is linked into an example.
authorLang Hames <lhames@gmail.com>
Wed, 19 Oct 2022 21:58:57 +0000 (14:58 -0700)
committerLang Hames <lhames@gmail.com>
Wed, 19 Oct 2022 22:03:42 +0000 (15:03 -0700)
Since aedeb8d5570, which switched to EPC-based eh-frame registration, the
eh-frame registration functions need to be forcibly linked into the target
process.

We need a general solution to this problem, but for now just force it in this
example to fix the test failures in
https://green.lab.llvm.org/green/job/clang-stage1-RA/31497

rdar://101083784

llvm/examples/OrcV2Examples/LLJITWithThinLTOSummaries/LLJITWithThinLTOSummaries.cpp

index a7cb4fc..32c49f6 100644 (file)
@@ -37,6 +37,7 @@
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
 #include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/ModuleSummaryIndex.h"
@@ -172,6 +173,12 @@ Expected<ThreadSafeModule> loadModule(StringRef Path,
   return ThreadSafeModule(std::move(*M), std::move(TSCtx));
 }
 
+// Make sure the eh-frame registration functions get linked into the binary.
+LLVM_ATTRIBUTE_USED void linkComponents() {
+  errs() << (void *)&llvm_orc_registerEHFrameSectionWrapper
+         << (void *)&llvm_orc_deregisterEHFrameSectionWrapper;
+}
+
 int main(int Argc, char *Argv[]) {
   InitLLVM X(Argc, Argv);