38#define DEBUG_TYPE "orc"
53 : Name(Name), WorkingMem(
std::
move(Alloc)),
54 MemMgr(Ctx.getMemoryManager()), ES(ES) {
55 FinalizeFuture = FinalizePromise.get_future();
60 std::vector<FinalizedAlloc> Allocs;
61 Allocs.push_back(std::move(Alloc));
62 if (
Error Err = MemMgr.deallocate(std::move(Allocs)))
63 ES.reportError(std::move(Err));
76 return SegInfo.WorkingMem;
86 FinalizePromise.set_value(TargetMem);
90 FinalizePromise.set_value(std::move(Err));
98 template <
typename ELFT>
107 std::promise<MSVCPExpected<ExecutorAddrRange>> FinalizePromise;
108 std::future<MSVCPExpected<ExecutorAddrRange>> FinalizeFuture;
113template <
typename ELFT>
115 using SectionHeader =
typename ELFT::Shdr;
129 for (
const SectionHeader &Header : *Sections) {
138 const_cast<SectionHeader &
>(Header).sh_addr =
139 static_cast<typename ELFT::uint
>(LoadAddress.
getValue());
143 dbgs() <<
"Section load-addresses in debug object for \"" <<
getName()
145 for (
const SectionHeader &Header : *Sections) {
147 if (
uint64_t Addr = Header.sh_addr) {
157 unsigned char Class, Endian;
168 "Invalid endian in 32-bit ELF object file: %x", Endian));
177 "Invalid endian in 64-bit ELF object file: %x", Endian));
181 "Invalid arch in ELF object file: %x",
187 bool RequireDebugSections,
188 bool AutoRegisterCode,
Error &Err)
189 : ES(ES), RequireDebugSections(RequireDebugSections),
190 AutoRegisterCode(AutoRegisterCode) {
193 Err = ES.getExecutorProcessControl().getBootstrapSymbols(
200#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME, OPTION) \
202#include "llvm/BinaryFormat/Dwarf.def"
203#undef HANDLE_DWARF_SECTION
213 if (
G.getTargetTriple().getObjectFormat() !=
Triple::ELF)
223 Ctx.getMemoryManager(), ES.getSymbolStringPool(), ES.getTargetTriple(),
224 Ctx.getJITLinkDylib(), {{MemProt::Read, Segment}});
226 ES.reportError(
Alloc.takeError());
230 std::lock_guard<std::mutex> Lock(PendingObjsLock);
231 assert(PendingObjs.count(&MR) == 0 &&
"One debug object per materialization");
232 PendingObjs[&MR] = std::make_unique<DebugObject>(
233 InputObj.getBufferIdentifier(), std::move(*
Alloc), Ctx, ES);
236 memcpy(Buffer.
data(), InputObj.getBufferStart(),
Size);
240ELFDebugObjectPlugin::getPendingDebugObj(MaterializationResponsibility &MR) {
241 std::lock_guard<std::mutex> Lock(PendingObjsLock);
242 auto It = PendingObjs.find(&MR);
243 return It == PendingObjs.end() ? nullptr : It->second.get();
249 if (!getPendingDebugObj(MR))
253 size_t SectionsPatched = 0;
254 bool HasDebugSections =
false;
256 assert(DebugObj &&
"Don't inject passes if we have no debug object");
262 [&
G, &SectionsPatched, &HasDebugSections](
StringRef Name) {
263 SectionsPatched += 1;
265 HasDebugSections =
true;
266 Section *S =
G.findSectionByName(Name);
267 assert(S &&
"No graph section for object section");
271 if (!SectionsPatched) {
272 LLVM_DEBUG(
dbgs() <<
"Skipping debug registration for LinkGraph '"
273 <<
G.getName() <<
"': no debug info\n");
277 if (RequireDebugSections && !HasDebugSections) {
278 LLVM_DEBUG(
dbgs() <<
"Skipping debug registration for LinkGraph '"
279 <<
G.getName() <<
"': no debug info\n");
313 return R.takeError();
318 std::lock_guard<std::mutex> LockPending(PendingObjsLock);
319 std::lock_guard<std::mutex> LockRegistered(RegisteredObjsLock);
320 auto It = PendingObjs.find(&MR);
321 RegisteredObjs[K].push_back(std::move(It->second));
322 PendingObjs.erase(It);
332 G.allocActions().push_back(
333 {
cantFail(WrapperFunctionCall::Create<
334 SPSArgList<SPSExecutorAddrRange, bool>>(
335 RegistrationAction, *R, AutoRegisterCode)),
342 std::lock_guard<std::mutex> Lock(PendingObjsLock);
343 PendingObjs.erase(&MR);
352 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
353 auto SrcIt = RegisteredObjs.find(SrcKey);
354 if (SrcIt != RegisteredObjs.end()) {
357 for (std::unique_ptr<DebugObject> &DebugObj : SrcIt->second)
358 RegisteredObjs[DstKey].push_back(std::move(DebugObj));
359 RegisteredObjs.erase(SrcIt);
367 std::lock_guard<std::mutex> Lock(RegisteredObjsLock);
368 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.
size_t getBufferSize() 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)
void visitSections(GetLoadAddressFn Callback)
void reportError(Error Err)
Expected< ExecutorAddrRange > awaitTargetMem()
void reportTargetMem(ExecutorAddrRange TargetMem)
StringRef getName() const
void failMaterialization(Error Err)
SimpleSegmentAlloc & getTargetAlloc()
MutableArrayRef< char > getMutBuffer()
DebugObject(StringRef Name, SimpleSegmentAlloc Alloc, JITLinkContext &Ctx, ExecutionSession &ES)
llvm::unique_function< ExecutorAddr(StringRef)> GetLoadAddressFn
void visitSectionLoadAddresses(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.
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.