[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / ExecutionEngine / Orc / EPCEHFrameRegistrar.cpp
blob8cdda9ab5a15fed16cd156bdcdbb88e64c4d9b94
1 //===------ EPCEHFrameRegistrar.cpp - EPC-based eh-frame registration -----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h"
11 #include "llvm/ExecutionEngine/Orc/Core.h"
12 #include "llvm/Support/BinaryStreamWriter.h"
14 using namespace llvm::orc::shared;
16 namespace llvm {
17 namespace orc {
19 Expected<std::unique_ptr<EPCEHFrameRegistrar>>
20 EPCEHFrameRegistrar::Create(ExecutionSession &ES) {
21 // FIXME: Proper mangling here -- we really need to decouple linker mangling
22 // from DataLayout.
24 // Find the addresses of the registration/deregistration functions in the
25 // executor process.
26 auto &EPC = ES.getExecutorProcessControl();
27 auto ProcessHandle = EPC.loadDylib(nullptr);
28 if (!ProcessHandle)
29 return ProcessHandle.takeError();
31 std::string RegisterWrapperName, DeregisterWrapperName;
32 if (EPC.getTargetTriple().isOSBinFormatMachO()) {
33 RegisterWrapperName += '_';
34 DeregisterWrapperName += '_';
36 RegisterWrapperName += "llvm_orc_registerEHFrameSectionWrapper";
37 DeregisterWrapperName += "llvm_orc_deregisterEHFrameSectionWrapper";
39 SymbolLookupSet RegistrationSymbols;
40 RegistrationSymbols.add(EPC.intern(RegisterWrapperName));
41 RegistrationSymbols.add(EPC.intern(DeregisterWrapperName));
43 auto Result = EPC.lookupSymbols({{*ProcessHandle, RegistrationSymbols}});
44 if (!Result)
45 return Result.takeError();
47 assert(Result->size() == 1 && "Unexpected number of dylibs in result");
48 assert((*Result)[0].size() == 2 &&
49 "Unexpected number of addresses in result");
51 auto RegisterEHFrameWrapperFnAddr = (*Result)[0][0];
52 auto DeregisterEHFrameWrapperFnAddr = (*Result)[0][1];
54 return std::make_unique<EPCEHFrameRegistrar>(ES, RegisterEHFrameWrapperFnAddr,
55 DeregisterEHFrameWrapperFnAddr);
58 Error EPCEHFrameRegistrar::registerEHFrames(JITTargetAddress EHFrameSectionAddr,
59 size_t EHFrameSectionSize) {
60 return ES.callSPSWrapper<void(SPSExecutorAddress, uint64_t)>(
61 RegisterEHFrameWrapperFnAddr, EHFrameSectionAddr,
62 static_cast<uint64_t>(EHFrameSectionSize));
65 Error EPCEHFrameRegistrar::deregisterEHFrames(
66 JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {
67 return ES.callSPSWrapper<void(SPSExecutorAddress, uint64_t)>(
68 DeregisterEHFrameWrapperFnAddr, EHFrameSectionAddr,
69 static_cast<uint64_t>(EHFrameSectionSize));
72 } // end namespace orc
73 } // end namespace llvm