1 //===------ EPCEHFrameRegistrar.cpp - EPC-based eh-frame registration -----===//
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
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;
19 Expected<std::unique_ptr<EPCEHFrameRegistrar>> EPCEHFrameRegistrar::Create(
21 std::optional<ExecutorAddr> RegistrationFunctionsDylib) {
22 // FIXME: Proper mangling here -- we really need to decouple linker mangling
25 // Find the addresses of the registration/deregistration functions in the
27 auto &EPC = ES.getExecutorProcessControl();
29 if (!RegistrationFunctionsDylib) {
30 if (auto D = EPC.loadDylib(nullptr))
31 RegistrationFunctionsDylib = *D;
36 std::string RegisterWrapperName, DeregisterWrapperName;
37 if (EPC.getTargetTriple().isOSBinFormatMachO()) {
38 RegisterWrapperName += '_';
39 DeregisterWrapperName += '_';
41 RegisterWrapperName += "llvm_orc_registerEHFrameSectionWrapper";
42 DeregisterWrapperName += "llvm_orc_deregisterEHFrameSectionWrapper";
44 SymbolLookupSet RegistrationSymbols;
45 RegistrationSymbols.add(EPC.intern(RegisterWrapperName));
46 RegistrationSymbols.add(EPC.intern(DeregisterWrapperName));
49 EPC.lookupSymbols({{*RegistrationFunctionsDylib, RegistrationSymbols}});
51 return Result.takeError();
53 assert(Result->size() == 1 && "Unexpected number of dylibs in result");
54 assert((*Result)[0].size() == 2 &&
55 "Unexpected number of addresses in result");
57 auto RegisterEHFrameWrapperFnAddr = (*Result)[0][0];
58 auto DeregisterEHFrameWrapperFnAddr = (*Result)[0][1];
60 return std::make_unique<EPCEHFrameRegistrar>(ES, RegisterEHFrameWrapperFnAddr,
61 DeregisterEHFrameWrapperFnAddr);
64 Error EPCEHFrameRegistrar::registerEHFrames(ExecutorAddrRange EHFrameSection) {
65 return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
66 RegisterEHFrameWrapperFnAddr, EHFrameSection);
69 Error EPCEHFrameRegistrar::deregisterEHFrames(
70 ExecutorAddrRange EHFrameSection) {
71 return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
72 DeregisterEHFrameWrapperFnAddr, EHFrameSection);
75 } // end namespace orc
76 } // end namespace llvm