19#define DEBUG_TYPE "orc"
52 (
sizeof(Version) +
sizeof(EhFramePtrEnc) +
sizeof(FDECountEnc) +
54 (absolute ?
sizeof(
uint64_t) :
sizeof(EHFrameRelocation)));
55 std::string HeaderContent(HeaderSize,
'\0');
58 reinterpret_cast<uint8_t *
>(HeaderContent.data()), HeaderSize),
61 return std::move(Err);
63 return std::move(Err);
65 return std::move(Err);
67 return std::move(Err);
71 return std::move(Err);
74 return std::move(Err);
79constexpr StringRef RegisterPerfStartSymbolName =
80 "llvm_orc_registerJITLoaderPerfStart";
81constexpr StringRef RegisterPerfEndSymbolName =
82 "llvm_orc_registerJITLoaderPerfEnd";
83constexpr StringRef RegisterPerfImplSymbolName =
84 "llvm_orc_registerJITLoaderPerfImpl";
87getCodeLoadRecord(
const Symbol &
Sym, std::atomic<uint64_t> &CodeIndex) {
92 Record.Prefix.Id = PerfJITRecordType::JIT_CODE_LOAD;
100 Record.CodeIndex = CodeIndex++;
114static std::optional<PerfJITDebugInfoRecord>
121 <<
" at address " <<
Addr.getValue() <<
" with size "
125 SAddr,
Size, DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
132 Record.Prefix.Id = PerfJITRecordType::JIT_CODE_DEBUG_INFO;
134 for (
const auto &Entry : LInfo) {
135 auto Addr = Entry.first;
140 Record.Entries.push_back({
Addr, Entry.second.Line,
141 Entry.second.Discriminator,
142 Entry.second.FileName});
144 size_t EntriesBytes = (2
148 for (
const auto &Entry :
Record.Entries) {
151 EntriesBytes += Entry.Name.size() + 1;
153 Record.Prefix.TotalSize = EntriesBytes;
155 <<
"Total size: " <<
Record.Prefix.TotalSize <<
"\n"
156 <<
"Nr entries: " <<
Record.Entries.size() <<
"\n");
163 Record.Prefix.Id = PerfJITRecordType::JIT_CODE_UNWINDING_INFO;
164 Record.Prefix.TotalSize = 0;
165 auto Eh_frame =
G.findSectionByName(
".eh_frame");
170 if (!
G.getTargetTriple().isOSBinFormatELF()) {
171 LLVM_DEBUG(
dbgs() <<
"Not an ELF file, will not emit unwinding info\n");
175 auto EHFrameSize = SR.getSize();
176 auto Eh_frame_hdr =
G.findSectionByName(
".eh_frame_hdr");
179 auto Hdr = createX64EHFrameHeader(*Eh_frame,
G.getEndianness(),
true);
181 return Hdr.takeError();
182 Record.EHFrameHdr = std::move(*Hdr);
187 Record.EHFrameHdrAddr = 0;
189 Record.UnwindDataSize = EHFrameSize +
Record.EHFrameHdrSize;
194 Record.EHFrameHdrSize = SR.getSize();
195 Record.UnwindDataSize = EHFrameSize +
Record.EHFrameHdrSize;
207 <<
"Total size: " <<
Record.Prefix.TotalSize <<
"\n"
208 <<
"Unwind size: " <<
Record.UnwindDataSize <<
"\n"
209 <<
"EHFrame size: " << EHFrameSize <<
"\n"
210 <<
"EHFrameHdr size: " <<
Record.EHFrameHdrSize <<
"\n");
215 std::atomic<uint64_t> &CodeIndex,
217 std::unique_ptr<DWARFContext> DC;
223 EmitDebugInfo =
false;
225 DC = std::move(EDC->first);
226 DCBacking = std::move(EDC->second);
230 for (
auto Sym :
G.defined_symbols()) {
241 auto UWR = getUnwindingRecord(
G);
259 : EPC(EPC), RegisterPerfStartAddr(RegisterPerfStartAddr),
260 RegisterPerfEndAddr(RegisterPerfEndAddr),
261 RegisterPerfImplAddr(RegisterPerfImplAddr), CodeIndex(0),
274 EmitDebugInfo, EmitUnwindInfo);
275 G.allocActions().push_back(
278 RegisterPerfImplAddr, Batch)),
288 return make_error<StringError>(
289 "Perf support only available for ELF LinkGraphs!",
296 {{ES.intern(RegisterPerfStartSymbolName), &StartAddr},
297 {ES.intern(RegisterPerfEndSymbolName), &EndAddr},
298 {ES.intern(RegisterPerfImplSymbolName), &ImplAddr}}))
299 return std::move(Err);
300 return std::make_unique<PerfSupportPlugin>(EPC, StartAddr, EndAddr, ImplAddr,
301 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.
const orc::SymbolStringPtr & 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