LLVM  15.0.0git
EPCEHFrameRegistrar.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 
10 
13 
14 using namespace llvm::orc::shared;
15 
16 namespace llvm {
17 namespace orc {
18 
19 Expected<std::unique_ptr<EPCEHFrameRegistrar>>
21  // FIXME: Proper mangling here -- we really need to decouple linker mangling
22  // from DataLayout.
23 
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();
30 
31  std::string RegisterWrapperName, DeregisterWrapperName;
32  if (EPC.getTargetTriple().isOSBinFormatMachO()) {
33  RegisterWrapperName += '_';
34  DeregisterWrapperName += '_';
35  }
36  RegisterWrapperName += "llvm_orc_registerEHFrameSectionWrapper";
37  DeregisterWrapperName += "llvm_orc_deregisterEHFrameSectionWrapper";
38 
39  SymbolLookupSet RegistrationSymbols;
40  RegistrationSymbols.add(EPC.intern(RegisterWrapperName));
41  RegistrationSymbols.add(EPC.intern(DeregisterWrapperName));
42 
43  auto Result = EPC.lookupSymbols({{*ProcessHandle, RegistrationSymbols}});
44  if (!Result)
45  return Result.takeError();
46 
47  assert(Result->size() == 1 && "Unexpected number of dylibs in result");
48  assert((*Result)[0].size() == 2 &&
49  "Unexpected number of addresses in result");
50 
51  auto RegisterEHFrameWrapperFnAddr = (*Result)[0][0];
52  auto DeregisterEHFrameWrapperFnAddr = (*Result)[0][1];
53 
54  return std::make_unique<EPCEHFrameRegistrar>(
55  ES, ExecutorAddr(RegisterEHFrameWrapperFnAddr),
56  ExecutorAddr(DeregisterEHFrameWrapperFnAddr));
57 }
58 
60  return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
61  RegisterEHFrameWrapperFnAddr, EHFrameSection);
62 }
63 
65  ExecutorAddrRange EHFrameSection) {
66  return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
67  DeregisterEHFrameWrapperFnAddr, EHFrameSection);
68 }
69 
70 } // end namespace orc
71 } // end namespace llvm
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:30
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::orc::SymbolLookupSet
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:175
llvm::orc::shared
Definition: ELFNixPlatform.h:245
llvm::orc::EPCEHFrameRegistrar::deregisterEHFrames
Error deregisterEHFrames(ExecutorAddrRange EHFrameSection) override
Definition: EPCEHFrameRegistrar.cpp:64
llvm::orc::shared::SPSTuple
SPS tag type for tuples.
Definition: SimplePackedSerialization.h:194
EPCEHFrameRegistrar.h
llvm::orc::SymbolLookupSet::add
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition: Core.h:236
llvm::orc::ExecutorAddrRange
Represents an address range in the exceutor process.
Definition: ExecutorAddress.h:148
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::orc::ExecutionSession::getExecutorProcessControl
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Definition: Core.h:1401
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1598
llvm::orc::EPCEHFrameRegistrar::registerEHFrames
Error registerEHFrames(ExecutorAddrRange EHFrameSection) override
Definition: EPCEHFrameRegistrar.cpp:59
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1358
llvm::orc::ExecutorProcessControl::loadDylib
virtual Expected< tpctypes::DylibHandle > loadDylib(const char *DylibPath)=0
Load the dynamic library at the given path and return a handle to it.
llvm::orc::EPCEHFrameRegistrar::Create
static Expected< std::unique_ptr< EPCEHFrameRegistrar > > Create(ExecutionSession &ES)
Create from a ExecutorProcessControl instance alone.
Definition: EPCEHFrameRegistrar.cpp:20
Core.h
BinaryStreamWriter.h