38#define DEBUG_TYPE "orc"
53 : Name(Name), WorkingMem(
std::
move(Alloc)),
54 MemMgr(Ctx.getMemoryManager()), ES(ES) {}
57 assert(!FinalizeFuture.valid());
59 std::vector<FinalizedAlloc> Allocs;
60 Allocs.push_back(std::move(Alloc));
61 if (
Error Err = MemMgr.deallocate(std::move(Allocs)))
62 ES.reportError(std::move(Err));
68 return SegInfo.WorkingMem;
72 FinalizeFuture = FinalizePromise.get_future();
73 return std::move(WorkingMem);
81 assert(FinalizeFuture.valid() &&
82 "FinalizeFuture is not valid. Perhaps there is no pending target "
83 "memory transaction?");
84 return FinalizeFuture.get();
88 FinalizePromise.set_value(TargetMem);
92 FinalizePromise.set_value(std::move(Err));
96 if (FinalizeFuture.valid()) {
104 [ES = &this->ES](
Error Err) { ES->reportError(std::move(Err)); });
111 template <
typename ELFT>
120 std::promise<MSVCPExpected<ExecutorAddrRange>> FinalizePromise;
121 std::future<MSVCPExpected<ExecutorAddrRange>> FinalizeFuture;
126template <
typename ELFT>
128 using SectionHeader =
typename ELFT::Shdr;
140 for (
const SectionHeader &Header : *Sections) {
148 const_cast<SectionHeader &
>(Header).sh_addr =
149 static_cast<typename ELFT::uint
>(LoadAddress.
getValue());
153 dbgs() <<
"Section load-addresses in debug object for \"" << Name
155 for (
const SectionHeader &Header : *Sections) {
157 if (
uint64_t Addr = Header.sh_addr) {
169 unsigned char Class, Endian;
195 bool RequireDebugSections,
197 : ES(ES), RequireDebugSections(RequireDebugSections) {
200 Err = ES.getExecutorProcessControl().getBootstrapSymbols(
207#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
209#include "llvm/BinaryFormat/Dwarf.def"
210#undef HANDLE_DWARF_SECTION
222 if (
G.getTargetTriple().getObjectFormat() !=
Triple::ELF)
225 unsigned char Class, Endian;
228 return ES.reportError(
230 "Skipping debug object registration: Invalid arch "
231 "0x%02x in ELF LinkGraph %s",
232 Class,
G.getName().c_str()));
234 return ES.reportError(
236 "Skipping debug object registration: Invalid endian "
237 "0x%02x in ELF LinkGraph %s",
238 Endian,
G.getName().c_str()));
247 Ctx.getMemoryManager(), ES.getSymbolStringPool(), ES.getTargetTriple(),
248 Ctx.getJITLinkDylib(), {{MemProt::Read, Segment}});
250 ES.reportError(
Alloc.takeError());
254 std::lock_guard<std::mutex> Lock(PendingObjsLock);
255 assert(PendingObjs.count(&MR) == 0 &&
"One debug object per materialization");
256 PendingObjs[&MR] = std::make_unique<DebugObject>(
257 InputObj.getBufferIdentifier(), std::move(*
Alloc), Ctx, ES);
260 memcpy(Buffer.
data(), InputObj.getBufferStart(),
Size);
264ELFDebugObjectPlugin::getPendingDebugObj(MaterializationResponsibility &MR) {
265 std::lock_guard<std::mutex> Lock(PendingObjsLock);
266 auto It = PendingObjs.find(&MR);
267 return It == PendingObjs.end() ? nullptr : It->second.get();
273 if (!getPendingDebugObj(MR))
277 size_t SectionsPatched = 0;
278 bool HasDebugSections =
false;
280 assert(DebugObj &&
"Don't inject passes if we have no debug object");
286 [&
G, &SectionsPatched, &HasDebugSections](
StringRef Name) {
287 Section *S =
G.findSectionByName(Name);
294 SectionsPatched += 1;
296 HasDebugSections =
true;
302 if (!SectionsPatched) {
303 LLVM_DEBUG(
dbgs() <<
"Skipping debug registration for LinkGraph '"
304 <<
G.getName() <<
"': no debug info\n");
308 if (RequireDebugSections && !HasDebugSections) {
309 LLVM_DEBUG(
dbgs() <<
"Skipping debug registration for LinkGraph '"
310 <<
G.getName() <<
"': no debug info\n");
324 std::lock_guard<std::mutex> Lock(PendingObjsLock);
325 auto It = PendingObjs.find(&MR);
326 if (It == PendingObjs.end()) {
351 assert(DebugObj &&
"Don't inject passes if we have no debug object");
359 return R.takeError();
364 std::lock_guard<std::mutex> LockPending(PendingObjsLock);
365 std::lock_guard<std::mutex> LockRegistered(RegisteredObjsLock);
366 auto It = PendingObjs.find(&MR);
367 RegisteredObjs[K].push_back(std::move(It->second));
368 PendingObjs.erase(It);
378 G.allocActions().push_back(
379 {
cantFail(WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddrRange>>(
380 RegistrationAction, *R)),
387 std::lock_guard<std::mutex> Lock(PendingObjsLock);
388 auto It = PendingObjs.find(&MR);
389 It->second->releasePendingResources();
390 PendingObjs.erase(It);
399 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
400 auto SrcIt = RegisteredObjs.find(SrcKey);
401 if (SrcIt != RegisteredObjs.end()) {
404 for (std::unique_ptr<DebugObject> &DebugObj : SrcIt->second)
405 RegisteredObjs[DstKey].push_back(std::move(DebugObj));
406 RegisteredObjs.erase(SrcIt);
414 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
415 RegisteredObjs.erase(
Key);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static bool isDwarfSection(const MCObjectFileInfo *FI, const MCSection *Section)
Provides a library for accessing information about this process and other processes on the operating ...
size_t size() const
Get the array size.
Helper for Errors used as out-parameters.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
size_t getBufferSize() const
StringRef getBuffer() const
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Represent a constant reference to a string, i.e.
Holds context for a single jitLink invocation.
Represents a finalized allocation.
Manages allocations of JIT memory.
Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...
orc::ExecutorAddr getStart() const
Represents an object file section.
A utility class for making simple allocations using JITLinkMemoryManager.
static LLVM_ABI void Create(JITLinkMemoryManager &MemMgr, std::shared_ptr< orc::SymbolStringPool > SSP, Triple TT, const JITLinkDylib *JD, SegmentMap Segments, OnCreatedFunction OnCreated)
static Expected< ELFFile > create(StringRef Object)
MutableArrayRef< char > getBuffer()
Error visitSectionLoadAddresses(GetLoadAddressFn Callback)
void releasePendingResources()
Expected< ExecutorAddrRange > awaitTargetMem()
void reportTargetMem(ExecutorAddrRange TargetMem)
bool hasPendingTargetMem() const
SimpleSegmentAlloc collectTargetAlloc()
void failMaterialization(Error Err)
DebugObject(StringRef Name, SimpleSegmentAlloc Alloc, JITLinkContext &Ctx, ExecutionSession &ES)
llvm::unique_function< ExecutorAddr(StringRef)> GetLoadAddressFn
Error visitSections(GetLoadAddressFn Callback)
void trackFinalizedAlloc(FinalizedAlloc FA)
JITLinkMemoryManager::FinalizedAlloc FinalizedAlloc
Error notifyFailed(MaterializationResponsibility &MR) override
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override
~ELFDebugObjectPlugin() override
void notifyMaterializing(MaterializationResponsibility &MR, jitlink::LinkGraph &G, jitlink::JITLinkContext &Ctx, MemoryBufferRef InputObj) override
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override
void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &LG, jitlink::PassConfiguration &PassConfig) override
ELFDebugObjectPlugin(ExecutionSession &ES, bool RequireDebugSections, Error &Err)
Create the plugin for the given session and set additional options.
An ExecutionSession represents a running JIT program.
Represents an address in the executor process.
uint64_t getValue() const
Represents a JIT'd dynamic library.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Error withResourceKeyDo(Func &&F) const
Runs the given callback under the session lock, passing in the associated ResourceKey.
static unsigned getPageSizeEstimate()
Get the process's estimated page size.
unique_function is a type-erasing functor similar to std::function.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::pair< unsigned char, unsigned char > getElfArchType(StringRef Object)
LLVM_ABI const char * RegisterJITLoaderGDBAllocActionName
static const std::set< StringRef > DwarfSectionNames
static bool isDwarfSection(StringRef SectionName)
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
LinkGraphPassList PostAllocationPasses
Post-allocation passes.
LinkGraphPassList PostFixupPasses
Post-fixup passes.
Describes a segment to be allocated.
Represents an address range in the exceutor process.