33#define DEBUG_TYPE "orc"
48template <
typename ELFT>
54 : Header(const_cast<typename ELFT::
Shdr *>(Header)) {}
62 typename ELFT::Shdr *Header;
65template <
typename ELFT>
69 static_cast<typename ELFT::uint
>(
Range.getStart().getValue());
72template <
typename ELFT>
74 const char *
Name)
const {
77 const uint8_t *HeaderPtr =
reinterpret_cast<uint8_t *
>(Header);
78 if (HeaderPtr < Start || HeaderPtr +
sizeof(
typename ELFT::Shdr) >
End)
79 return make_error<StringError>(
80 formatv(
"{0} section header at {1:x16} not within bounds of the "
81 "given debug object buffer [{2:x16} - {3:x16}]",
82 Name, &Header->sh_addr, Start,
End),
84 if (Header->sh_offset + Header->sh_size > Buffer.
size())
85 return make_error<StringError>(
86 formatv(
"{0} section data [{1:x16} - {2:x16}] not within bounds of "
87 "the given debug object buffer [{3:x16} - {4:x16}]",
88 Name, Start + Header->sh_offset,
89 Start + Header->sh_offset + Header->sh_size, Start,
End),
94template <
typename ELFT>
136 std::vector<FinalizedAlloc> Allocs;
137 Allocs.push_back(std::move(Alloc));
165 assert(!Alloc &&
"Cannot finalize more than once");
170 SimpleSegAlloc->finalize(
171 [
this, DebugObjRange,
174 Alloc = std::move(*FA);
175 OnFinalize(DebugObjRange);
180 OnFinalize(SimpleSegAlloc.takeError());
201 template <
typename ELFT>
207 template <
typename ELFT>
212 static std::unique_ptr<WritableMemoryBuffer>
222 std::unique_ptr<WritableMemoryBuffer> Buffer;
227#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
229#include "llvm/BinaryFormat/Dwarf.def"
230#undef HANDLE_DWARF_SECTION
237std::unique_ptr<WritableMemoryBuffer>
251template <
typename ELFT>
259 std::unique_ptr<ELFDebugObject> DebugObj(
260 new ELFDebugObject(CopyBuffer(Buffer, Err),
MemMgr,
JD, ES));
262 return std::move(Err);
272 for (
const SectionHeader &Header : *Sections) {
275 return Name.takeError();
288 auto Wrapped = std::make_unique<ELFDebugObjectSection<ELFT>>(&Header);
289 if (
Error Err = DebugObj->recordSection(*
Name, std::move(Wrapped)))
290 return std::move(Err);
293 return std::move(DebugObj);
299 unsigned char Class,
Endian;
325 dbgs() <<
"Section load-addresses in debug object for \""
327 for (
const auto &KV : Sections)
328 KV.second->dump(
dbgs(), KV.first());
352 DebugObjSection->setTargetMemoryRange(TargetMem);
355template <
typename ELFT>
360 bool Inserted = Sections.try_emplace(
Name, std::move(
Section)).second;
364 <<
" (duplicate name)\n");
369 auto It = Sections.find(
Name);
370 return It == Sections.end() ? nullptr : It->second.get();
379 switch (
G.getTargetTriple().getObjectFormat()) {
392 bool RequireDebugSections,
bool AutoRegisterCode)
394 RequireDebugSections(RequireDebugSections),
395 AutoRegisterCode(AutoRegisterCode) {}
406 std::lock_guard<std::mutex> Lock(PendingObjsLock);
407 assert(PendingObjs.count(&MR) == 0 &&
408 "Cannot have more than one pending debug object per "
409 "MaterializationResponsibility");
413 if (*DebugObj ==
nullptr)
416 LLVM_DEBUG(
dbgs() <<
"Skipping debug registration for LinkGraph '"
417 <<
G.getName() <<
"': no debug info\n");
420 PendingObjs[&MR] = std::move(*DebugObj);
422 ES.reportError(DebugObj.takeError());
430 std::lock_guard<std::mutex> Lock(PendingObjsLock);
431 auto It = PendingObjs.find(&MR);
432 if (It == PendingObjs.end())
449 std::lock_guard<std::mutex> Lock(PendingObjsLock);
450 auto It = PendingObjs.find(&MR);
451 if (It == PendingObjs.end())
458 std::promise<MSVCPError> FinalizePromise;
459 std::future<MSVCPError> FinalizeErr = FinalizePromise.get_future();
461 It->second->finalizeAsync(
465 FinalizePromise.set_value(TargetMem.
takeError());
469 Target->registerDebugObject(*TargetMem, AutoRegisterCode)) {
470 FinalizePromise.set_value(std::move(Err));
477 assert(PendingObjs.count(&MR) &&
"We still hold PendingObjsLock");
478 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
479 RegisteredObjs[K].push_back(std::move(PendingObjs[&MR]));
480 PendingObjs.erase(&MR);
484 return FinalizeErr.get();
489 std::lock_guard<std::mutex> Lock(PendingObjsLock);
490 PendingObjs.erase(&MR);
499 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
500 auto SrcIt = RegisteredObjs.find(SrcKey);
501 if (SrcIt != RegisteredObjs.end()) {
504 for (std::unique_ptr<DebugObject> &DebugObj : SrcIt->second)
505 RegisteredObjs[DstKey].push_back(std::move(DebugObj));
506 RegisteredObjs.erase(SrcIt);
514 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
515 RegisteredObjs.erase(Key);
This file defines the StringMap class.
static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096), cl::Hidden)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
Provides a library for accessing information about this process and other processes on the operating ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
size_t getBufferSize() const
StringRef getBufferIdentifier() const
const char * getBufferStart() const
StringRef getBuffer() const
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
const unsigned char * bytes_end() const
constexpr size_t size() const
size - Get the string size.
const unsigned char * bytes_begin() const
Target - Wrapper for Target specific information.
static std::unique_ptr< WritableMemoryBuffer > getNewUninitMemBuffer(size_t Size, const Twine &BufferName="", std::optional< Align > Alignment=std::nullopt)
Allocate a new MemoryBuffer of the specified size that is not initialized.
Holds context for a single jitLink invocation.
const JITLinkDylib * getJITLinkDylib() const
Return the JITLinkDylib that this link is targeting, if any.
virtual JITLinkMemoryManager & getMemoryManager()=0
Return the MemoryManager to be used for this link.
Represents a finalized allocation.
Represents an allocation which has not been finalized yet.
Manages allocations of JIT memory.
virtual void deallocate(std::vector< FinalizedAlloc > Allocs, OnDeallocatedFunction OnDeallocated)=0
Deallocate a list of allocation objects.
iterator_range< section_iterator > sections()
Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...
Represents an object file section.
static void Create(JITLinkMemoryManager &MemMgr, const JITLinkDylib *JD, SegmentMap Segments, OnCreatedFunction OnCreated)
static Expected< ELFFile > create(StringRef Object)
Creates and manages DebugObjects for JITLink artifacts.
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override
Error notifyFailed(MaterializationResponsibility &MR) override
Error notifyEmitted(MaterializationResponsibility &MR) override
~DebugObjectManagerPlugin()
void notifyMaterializing(MaterializationResponsibility &MR, jitlink::LinkGraph &G, jitlink::JITLinkContext &Ctx, MemoryBufferRef InputObject) override
void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &LG, jitlink::PassConfiguration &PassConfig) override
DebugObjectManagerPlugin(ExecutionSession &ES, std::unique_ptr< DebugObjectRegistrar > Target)
virtual void setTargetMemoryRange(SectionRange Range)=0
virtual void dump(raw_ostream &OS, StringRef Name)
virtual ~DebugObjectSection()=default
The plugin creates a debug object from when JITLink starts processing the corresponding LinkGraph.
JITLinkMemoryManager & MemMgr
bool hasFlags(DebugObjectFlags F) const
void finalizeAsync(FinalizeContinuation OnFinalize)
virtual Expected< SimpleSegmentAlloc > finalizeWorkingMemory()=0
std::function< void(Expected< ExecutorAddrRange >)> FinalizeContinuation
void clearFlags(DebugObjectFlags F)
virtual void reportSectionTargetMemoryRange(StringRef Name, SectionRange TargetMem)
void setFlags(DebugObjectFlags F)
DebugObject(JITLinkMemoryManager &MemMgr, const JITLinkDylib *JD, ExecutionSession &ES)
Error validateInBounds(StringRef Buffer, const char *Name) const
void setTargetMemoryRange(SectionRange Range) override
void dump(raw_ostream &OS, StringRef Name) override
ELFDebugObjectSection(const typename ELFT::Shdr *Header)
The current implementation of ELFDebugObject replicates the approach used in RuntimeDyld: It patches ...
Error recordSection(StringRef Name, std::unique_ptr< ELFDebugObjectSection< ELFT > > Section)
DebugObjectSection * getSection(StringRef Name)
Expected< SimpleSegmentAlloc > finalizeWorkingMemory() override
void reportSectionTargetMemoryRange(StringRef Name, SectionRange TargetMem) override
StringRef getBuffer() const
static Expected< std::unique_ptr< DebugObject > > Create(MemoryBufferRef Buffer, JITLinkContext &Ctx, ExecutionSession &ES)
An ExecutionSession represents a running JIT program.
void reportError(Error Err)
Report a error for this execution session.
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
static unsigned getPageSizeEstimate()
Get the process's estimated page size.
std::pair< unsigned char, unsigned char > getElfArchType(StringRef Object)
static const std::set< StringRef > DwarfSectionNames
static Expected< std::unique_ptr< DebugObject > > createDebugObjectFromBuffer(ExecutionSession &ES, LinkGraph &G, JITLinkContext &Ctx, MemoryBufferRef ObjBuffer)
Creates a debug object based on the input object file from ObjectLinkingLayerJITLinkContext.
static bool isDwarfSection(StringRef SectionName)
@ ReportFinalSectionLoadAddresses
This is an optimization pass for GlobalISel generic memory operations.
std::error_code make_error_code(BitcodeError E)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
auto formatv(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< Ts >(Vals))...))>
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
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.
Represents an address range in the exceutor process.