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,
196 bool AutoRegisterCode,
Error &Err)
197 : ES(ES), RequireDebugSections(RequireDebugSections),
198 AutoRegisterCode(AutoRegisterCode) {
201 Err = ES.getExecutorProcessControl().getBootstrapSymbols(
208#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
210#include "llvm/BinaryFormat/Dwarf.def"
211#undef HANDLE_DWARF_SECTION
223 if (
G.getTargetTriple().getObjectFormat() !=
Triple::ELF)
226 unsigned char Class, Endian;
229 return ES.reportError(
231 "Skipping debug object registration: Invalid arch "
232 "0x%02x in ELF LinkGraph %s",
233 Class,
G.getName().c_str()));
235 return ES.reportError(
237 "Skipping debug object registration: Invalid endian "
238 "0x%02x in ELF LinkGraph %s",
239 Endian,
G.getName().c_str()));
248 Ctx.getMemoryManager(), ES.getSymbolStringPool(), ES.getTargetTriple(),
249 Ctx.getJITLinkDylib(), {{MemProt::Read, Segment}});
251 ES.reportError(
Alloc.takeError());
255 std::lock_guard<std::mutex> Lock(PendingObjsLock);
256 assert(PendingObjs.count(&MR) == 0 &&
"One debug object per materialization");
257 PendingObjs[&MR] = std::make_unique<DebugObject>(
258 InputObj.getBufferIdentifier(), std::move(*
Alloc), Ctx, ES);
261 memcpy(Buffer.
data(), InputObj.getBufferStart(),
Size);
265ELFDebugObjectPlugin::getPendingDebugObj(MaterializationResponsibility &MR) {
266 std::lock_guard<std::mutex> Lock(PendingObjsLock);
267 auto It = PendingObjs.find(&MR);
268 return It == PendingObjs.end() ? nullptr : It->second.get();
274 if (!getPendingDebugObj(MR))
278 size_t SectionsPatched = 0;
279 bool HasDebugSections =
false;
281 assert(DebugObj &&
"Don't inject passes if we have no debug object");
287 [&
G, &SectionsPatched, &HasDebugSections](
StringRef Name) {
288 Section *S =
G.findSectionByName(Name);
295 SectionsPatched += 1;
297 HasDebugSections =
true;
303 if (!SectionsPatched) {
304 LLVM_DEBUG(
dbgs() <<
"Skipping debug registration for LinkGraph '"
305 <<
G.getName() <<
"': no debug info\n");
309 if (RequireDebugSections && !HasDebugSections) {
310 LLVM_DEBUG(
dbgs() <<
"Skipping debug registration for LinkGraph '"
311 <<
G.getName() <<
"': no debug info\n");
325 std::lock_guard<std::mutex> Lock(PendingObjsLock);
326 auto It = PendingObjs.find(&MR);
327 if (It == PendingObjs.end()) {
352 assert(DebugObj &&
"Don't inject passes if we have no debug object");
360 return R.takeError();
365 std::lock_guard<std::mutex> LockPending(PendingObjsLock);
366 std::lock_guard<std::mutex> LockRegistered(RegisteredObjsLock);
367 auto It = PendingObjs.find(&MR);
368 RegisteredObjs[K].push_back(std::move(It->second));
369 PendingObjs.erase(It);
379 G.allocActions().push_back(
380 {
cantFail(WrapperFunctionCall::Create<
381 SPSArgList<SPSExecutorAddrRange, bool>>(
382 RegistrationAction, *R, AutoRegisterCode)),
389 std::lock_guard<std::mutex> Lock(PendingObjsLock);
390 auto It = PendingObjs.find(&MR);
391 It->second->releasePendingResources();
392 PendingObjs.erase(It);
401 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
402 auto SrcIt = RegisteredObjs.find(SrcKey);
403 if (SrcIt != RegisteredObjs.end()) {
406 for (std::unique_ptr<DebugObject> &DebugObj : SrcIt->second)
407 RegisteredObjs[DstKey].push_back(std::move(DebugObj));
408 RegisteredObjs.erase(SrcIt);
416 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
417 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
size - 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
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
StringRef - 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
ELFDebugObjectPlugin(ExecutionSession &ES, bool RequireDebugSections, bool AutoRegisterCode, Error &Err)
Create the plugin for the given session and set additional options.
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override
void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &LG, jitlink::PassConfiguration &PassConfig) override
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.