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 FinalizePromise.set_value(TargetMem);
85 FinalizePromise.set_value(std::move(Err));
89 if (FinalizeFuture.valid()) {
97 [ES = &this->ES](
Error Err) { ES->reportError(std::move(Err)); });
104 template <
typename ELFT>
113 std::promise<MSVCPExpected<ExecutorAddrRange>> FinalizePromise;
114 std::future<MSVCPExpected<ExecutorAddrRange>> FinalizeFuture;
119template <
typename ELFT>
121 using SectionHeader =
typename ELFT::Shdr;
133 for (
const SectionHeader &Header : *Sections) {
141 const_cast<SectionHeader &
>(Header).sh_addr =
142 static_cast<typename ELFT::uint
>(LoadAddress.
getValue());
146 dbgs() <<
"Section load-addresses in debug object for \"" << Name
148 for (
const SectionHeader &Header : *Sections) {
150 if (
uint64_t Addr = Header.sh_addr) {
162 unsigned char Class, Endian;
188 bool RequireDebugSections,
189 bool AutoRegisterCode,
Error &Err)
190 : ES(ES), RequireDebugSections(RequireDebugSections),
191 AutoRegisterCode(AutoRegisterCode) {
194 Err = ES.getExecutorProcessControl().getBootstrapSymbols(
201#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
203#include "llvm/BinaryFormat/Dwarf.def"
204#undef HANDLE_DWARF_SECTION
216 if (
G.getTargetTriple().getObjectFormat() !=
Triple::ELF)
219 unsigned char Class, Endian;
222 return ES.reportError(
224 "Skipping debug object registration: Invalid arch "
225 "0x%02x in ELF LinkGraph %s",
226 Class,
G.getName().c_str()));
228 return ES.reportError(
230 "Skipping debug object registration: Invalid endian "
231 "0x%02x in ELF LinkGraph %s",
232 Endian,
G.getName().c_str()));
241 Ctx.getMemoryManager(), ES.getSymbolStringPool(), ES.getTargetTriple(),
242 Ctx.getJITLinkDylib(), {{MemProt::Read, Segment}});
244 ES.reportError(
Alloc.takeError());
248 std::lock_guard<std::mutex> Lock(PendingObjsLock);
249 assert(PendingObjs.count(&MR) == 0 &&
"One debug object per materialization");
250 PendingObjs[&MR] = std::make_unique<DebugObject>(
251 InputObj.getBufferIdentifier(), std::move(*
Alloc), Ctx, ES);
254 memcpy(Buffer.
data(), InputObj.getBufferStart(),
Size);
258ELFDebugObjectPlugin::getPendingDebugObj(MaterializationResponsibility &MR) {
259 std::lock_guard<std::mutex> Lock(PendingObjsLock);
260 auto It = PendingObjs.find(&MR);
261 return It == PendingObjs.end() ? nullptr : It->second.get();
267 if (!getPendingDebugObj(MR))
271 size_t SectionsPatched = 0;
272 bool HasDebugSections =
false;
274 assert(DebugObj &&
"Don't inject passes if we have no debug object");
280 [&
G, &SectionsPatched, &HasDebugSections](
StringRef Name) {
281 Section *S =
G.findSectionByName(Name);
288 SectionsPatched += 1;
290 HasDebugSections =
true;
296 if (!SectionsPatched) {
297 LLVM_DEBUG(
dbgs() <<
"Skipping debug registration for LinkGraph '"
298 <<
G.getName() <<
"': no debug info\n");
302 if (RequireDebugSections && !HasDebugSections) {
303 LLVM_DEBUG(
dbgs() <<
"Skipping debug registration for LinkGraph '"
304 <<
G.getName() <<
"': no debug info\n");
318 std::lock_guard<std::mutex> Lock(PendingObjsLock);
319 auto It = PendingObjs.find(&MR);
320 if (It == PendingObjs.end()) {
347 return R.takeError();
352 std::lock_guard<std::mutex> LockPending(PendingObjsLock);
353 std::lock_guard<std::mutex> LockRegistered(RegisteredObjsLock);
354 auto It = PendingObjs.find(&MR);
355 RegisteredObjs[K].push_back(std::move(It->second));
356 PendingObjs.erase(It);
366 G.allocActions().push_back(
367 {
cantFail(WrapperFunctionCall::Create<
368 SPSArgList<SPSExecutorAddrRange, bool>>(
369 RegistrationAction, *R, AutoRegisterCode)),
376 std::lock_guard<std::mutex> Lock(PendingObjsLock);
377 auto It = PendingObjs.find(&MR);
378 It->second->releasePendingResources();
379 PendingObjs.erase(It);
388 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
389 auto SrcIt = RegisteredObjs.find(SrcKey);
390 if (SrcIt != RegisteredObjs.end()) {
393 for (std::unique_ptr<DebugObject> &DebugObj : SrcIt->second)
394 RegisteredObjs[DstKey].push_back(std::move(DebugObj));
395 RegisteredObjs.erase(SrcIt);
403 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
404 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)
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.