LLVM  16.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  Optional<ExecutorAddr> RegistrationFunctionsDylib) {
22  // FIXME: Proper mangling here -- we really need to decouple linker mangling
23  // from DataLayout.
24 
25  // Find the addresses of the registration/deregistration functions in the
26  // executor process.
27  auto &EPC = ES.getExecutorProcessControl();
28 
29  if (!RegistrationFunctionsDylib) {
30  if (auto D = EPC.loadDylib(nullptr))
31  RegistrationFunctionsDylib = *D;
32  else
33  return D.takeError();
34  }
35 
36  std::string RegisterWrapperName, DeregisterWrapperName;
37  if (EPC.getTargetTriple().isOSBinFormatMachO()) {
38  RegisterWrapperName += '_';
39  DeregisterWrapperName += '_';
40  }
41  RegisterWrapperName += "llvm_orc_registerEHFrameSectionWrapper";
42  DeregisterWrapperName += "llvm_orc_deregisterEHFrameSectionWrapper";
43 
44  SymbolLookupSet RegistrationSymbols;
45  RegistrationSymbols.add(EPC.intern(RegisterWrapperName));
46  RegistrationSymbols.add(EPC.intern(DeregisterWrapperName));
47 
48  auto Result =
49  EPC.lookupSymbols({{*RegistrationFunctionsDylib, RegistrationSymbols}});
50  if (!Result)
51  return Result.takeError();
52 
53  assert(Result->size() == 1 && "Unexpected number of dylibs in result");
54  assert((*Result)[0].size() == 2 &&
55  "Unexpected number of addresses in result");
56 
57  auto RegisterEHFrameWrapperFnAddr = (*Result)[0][0];
58  auto DeregisterEHFrameWrapperFnAddr = (*Result)[0][1];
59 
60  return std::make_unique<EPCEHFrameRegistrar>(
61  ES, ExecutorAddr(RegisterEHFrameWrapperFnAddr),
62  ExecutorAddr(DeregisterEHFrameWrapperFnAddr));
63 }
64 
66  return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
67  RegisterEHFrameWrapperFnAddr, EHFrameSection);
68 }
69 
71  ExecutorAddrRange EHFrameSection) {
72  return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
73  DeregisterEHFrameWrapperFnAddr, EHFrameSection);
74 }
75 
76 } // end namespace orc
77 } // end namespace llvm
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:31
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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::Optional
Definition: APInt.h:33
llvm::orc::EPCEHFrameRegistrar::deregisterEHFrames
Error deregisterEHFrames(ExecutorAddrRange EHFrameSection) override
Definition: EPCEHFrameRegistrar.cpp:70
llvm::orc::shared::SPSTuple
SPS tag type for tuples.
Definition: SimplePackedSerialization.h:195
EPCEHFrameRegistrar.h
llvm::orc::EPCEHFrameRegistrar::Create
static Expected< std::unique_ptr< EPCEHFrameRegistrar > > Create(ExecutionSession &ES, Optional< ExecutorAddr > RegistrationFunctionsDylib=std::nullopt)
Create from a ExecutorProcessControl instance alone.
Definition: EPCEHFrameRegistrar.cpp:20
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:191
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
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:1408
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:1715
llvm::orc::EPCEHFrameRegistrar::registerEHFrames
Error registerEHFrames(ExecutorAddrRange EHFrameSection) override
Definition: EPCEHFrameRegistrar.cpp:65
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:1365
Core.h
BinaryStreamWriter.h