20#define DEBUG_TYPE "orc"
35 uint8_t EhFramePtrEnc = 0;
53 (
sizeof(Version) +
sizeof(EhFramePtrEnc) +
sizeof(FDECountEnc) +
55 (absolute ?
sizeof(
uint64_t) :
sizeof(EHFrameRelocation)));
56 std::string HeaderContent(HeaderSize,
'\0');
59 reinterpret_cast<uint8_t *
>(HeaderContent.data()), HeaderSize),
62 return std::move(Err);
64 return std::move(Err);
66 return std::move(Err);
68 return std::move(Err);
72 return std::move(Err);
75 return std::move(Err);
80constexpr StringRef RegisterPerfStartSymbolName =
81 "llvm_orc_registerJITLoaderPerfStart";
82constexpr StringRef RegisterPerfEndSymbolName =
83 "llvm_orc_registerJITLoaderPerfEnd";
84constexpr StringRef RegisterPerfImplSymbolName =
85 "llvm_orc_registerJITLoaderPerfImpl";
88getCodeLoadRecord(
const Symbol &
Sym, std::atomic<uint64_t> &CodeIndex) {
93 Record.Prefix.Id = PerfJITRecordType::JIT_CODE_LOAD;
101 Record.CodeIndex = CodeIndex++;
115static std::optional<PerfJITDebugInfoRecord>
122 <<
" at address " <<
Addr.getValue() <<
" with size "
126 SAddr,
Size, DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
133 Record.Prefix.Id = PerfJITRecordType::JIT_CODE_DEBUG_INFO;
135 for (
const auto &Entry : LInfo) {
136 auto Addr = Entry.first;
141 Record.Entries.push_back({
Addr, Entry.second.Line,
142 Entry.second.Discriminator,
143 Entry.second.FileName});
145 size_t EntriesBytes = (2
149 for (
const auto &Entry :
Record.Entries) {
152 EntriesBytes += Entry.Name.size() + 1;
154 Record.Prefix.TotalSize = EntriesBytes;
156 <<
"Total size: " <<
Record.Prefix.TotalSize <<
"\n"
157 <<
"Nr entries: " <<
Record.Entries.size() <<
"\n");
164 Record.Prefix.Id = PerfJITRecordType::JIT_CODE_UNWINDING_INFO;
165 Record.Prefix.TotalSize = 0;
166 auto Eh_frame =
G.findSectionByName(
".eh_frame");
171 if (!
G.getTargetTriple().isOSBinFormatELF()) {
172 LLVM_DEBUG(
dbgs() <<
"Not an ELF file, will not emit unwinding info\n");
176 auto EHFrameSize = SR.getSize();
177 auto Eh_frame_hdr =
G.findSectionByName(
".eh_frame_hdr");
180 auto Hdr = createX64EHFrameHeader(*Eh_frame,
G.getEndianness(),
true);
182 return Hdr.takeError();
183 Record.EHFrameHdr = std::move(*Hdr);
188 Record.EHFrameHdrAddr = 0;
190 Record.UnwindDataSize = EHFrameSize +
Record.EHFrameHdrSize;
195 Record.EHFrameHdrSize = SR.getSize();
196 Record.UnwindDataSize = EHFrameSize +
Record.EHFrameHdrSize;
208 <<
"Total size: " <<
Record.Prefix.TotalSize <<
"\n"
209 <<
"Unwind size: " <<
Record.UnwindDataSize <<
"\n"
210 <<
"EHFrame size: " << EHFrameSize <<
"\n"
211 <<
"EHFrameHdr size: " <<
Record.EHFrameHdrSize <<
"\n");
216 std::atomic<uint64_t> &CodeIndex,
218 std::unique_ptr<DWARFContext> DC;
224 EmitDebugInfo =
false;
226 DC = std::move(EDC->first);
227 DCBacking = std::move(EDC->second);
231 for (
auto Sym :
G.defined_symbols()) {
242 auto UWR = getUnwindingRecord(
G);
260 : EPC(EPC), RegisterPerfStartAddr(RegisterPerfStartAddr),
261 RegisterPerfEndAddr(RegisterPerfEndAddr),
262 RegisterPerfImplAddr(RegisterPerfImplAddr), CodeIndex(0),
275 EmitDebugInfo, EmitUnwindInfo);
276 G.allocActions().push_back(
279 RegisterPerfImplAddr, Batch)),
289 return make_error<StringError>(
290 "Perf support only available for ELF LinkGraphs!",
297 {{ES.intern(RegisterPerfStartSymbolName), &StartAddr},
298 {ES.intern(RegisterPerfEndSymbolName), &EndAddr},
299 {ES.intern(RegisterPerfImplSymbolName), &ImplAddr}}))
300 return std::move(Err);
301 return std::make_unique<PerfSupportPlugin>(EPC, StartAddr, EndAddr, ImplAddr,
302 EmitDebugInfo, EmitUnwindInfo);
static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info)
Provides write only access to a subclass of WritableBinaryStream.
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
DILineInfoTable getLineInfoForAddressRange(object::SectionedAddress Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier()) override
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
const RecordVal * getValue(const Init *Name) 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.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Section & getSection() const
Return the parent section for this block.
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.
SectionOrdinal getOrdinal() const
Returns the ordinal for this section.
bool isCallable() const
Returns true is this symbol is callable.
StringRef getName() const
Returns the name of this symbol (empty if the symbol is anonymous).
orc::ExecutorAddr getAddress() const
Returns the address of this symbol.
Block & getBlock()
Return the Block for this Symbol (Symbol must be defined).
orc::ExecutorAddrDiff getSize() const
Returns the size of this symbol.
bool hasName() const
Returns true if this symbol has a name.
An ExecutionSession represents a running JIT program.
void reportError(Error Err)
Report a error for this execution session.
Represents an address in the executor process.
uint64_t getValue() const
ExecutorProcessControl supports interaction with a JIT target process.
const Triple & getTargetTriple() const
Return the Triple for the target process.
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
ExecutionSession & getExecutionSession()
Return the ExecutionSession associated with this instance.
Represents a JIT'd dynamic library.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &G, jitlink::PassConfiguration &Config) override
static Expected< std::unique_ptr< PerfSupportPlugin > > Create(ExecutorProcessControl &EPC, JITDylib &JD, bool EmitDebugInfo, bool EmitUnwindInfo)
PerfSupportPlugin(ExecutorProcessControl &EPC, ExecutorAddr RegisterPerfStartAddr, ExecutorAddr RegisterPerfEndAddr, ExecutorAddr RegisterPerfImplAddr, bool EmitDebugInfo, bool EmitUnwindInfo)
A utility class for serializing to a blob from a variadic list.
static Expected< WrapperFunctionCall > Create(ExecutorAddr FnAddr, const ArgTs &...Args)
Create a WrapperFunctionCall using the given SPS serializer to serialize the arguments.
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
void lookupAndRecordAddrs(unique_function< void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, std::vector< std::pair< SymbolStringPtr, ExecutorAddr * > > Pairs, SymbolLookupFlags LookupFlags=SymbolLookupFlags::RequiredSymbol)
Record addresses of the given symbols in the given ExecutorAddrs.
Expected< std::pair< std::unique_ptr< DWARFContext >, StringMap< std::unique_ptr< MemoryBuffer > > > > createDWARFContext(jitlink::LinkGraph &G)
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
PerfJITRecordPrefix Prefix
std::vector< PerfJITDebugInfoRecord > DebugInfoRecords
PerfJITCodeUnwindingInfoRecord UnwindingRecord
std::vector< PerfJITCodeLoadRecord > CodeLoadRecords