Go to the documentation of this file.
31 #include <system_error>
38 auto I = FunctionIds.find(
Addr);
39 if (
I != FunctionIds.end())
45 auto I = FunctionAddresses.find(
FuncId);
46 if (
I != FunctionAddresses.end())
66 return make_error<StringError>(
67 "File format not supported (only does ELF and Mach-O little endian "
77 Address = Section.getAddress();
78 return *NameOrErr ==
"xray_instr_map";
84 if (
I == Sections.end())
85 return make_error<StringError>(
86 "Failed to find XRay instrumentation map.",
89 if (
Error E =
I->getContents().moveInto(Contents))
95 if (
const auto *ELFObj = dyn_cast<object::ELF32LEObjectFile>(ObjFile))
96 return ELFObj->getELFFile().getRelativeRelocationType();
97 else if (
const auto *ELFObj =
98 dyn_cast<object::ELF32BEObjectFile>(ObjFile))
99 return ELFObj->getELFFile().getRelativeRelocationType();
100 else if (
const auto *ELFObj =
101 dyn_cast<object::ELF64LEObjectFile>(ObjFile))
102 return ELFObj->getELFFile().getRelativeRelocationType();
103 else if (
const auto *ELFObj =
104 dyn_cast<object::ELF64BEObjectFile>(ObjFile))
105 return ELFObj->getELFFile().getRelativeRelocationType();
118 if (Supports && Supports(Reloc.getType())) {
126 }
else if (Supports && Supports(Reloc.getType())) {
128 auto A = AddendOrErr ? *AddendOrErr : 0;
136 }
else if (Reloc.getType() == RelativeRelocation) {
138 Relocs.
insert({Reloc.getOffset(), *AddendOrErr});
147 size_t ELFSledEntrySize = Is32Bit ? 16 : 32;
149 if ((
C - Contents.
bytes_end()) % ELFSledEntrySize != 0)
150 return make_error<StringError>(
151 Twine(
"Instrumentation map entries not evenly divisible by size of "
152 "an XRay sled entry."),
159 if (R != Relocs.
end())
165 const int WordSize = Is32Bit ? 4 : 8;
168 for (;
C != Contents.
bytes_end();
C += ELFSledEntrySize) {
170 StringRef(
reinterpret_cast<const char *
>(
C), ELFSledEntrySize),
true,
173 auto &Entry = Sleds.back();
177 Entry.Address = RelocateOrElse(AddrOff, Extractor.
getU32(&OffsetPtr));
179 Entry.Address = RelocateOrElse(AddrOff, Extractor.
getU64(&OffsetPtr));
182 Entry.Function = RelocateOrElse(FuncOff, Extractor.
getU32(&OffsetPtr));
184 Entry.Function = RelocateOrElse(FuncOff, Extractor.
getU64(&OffsetPtr));
191 if (
Kind >=
sizeof(Kinds) /
sizeof(Kinds[0]))
194 Entry.Kind = Kinds[
Kind];
195 Entry.AlwaysInstrument = Extractor.
getU8(&OffsetPtr) != 0;
196 Entry.Version = Extractor.
getU8(&OffsetPtr);
197 if (Entry.Version >= 2) {
199 Entry.Function +=
C - Contents.
bytes_begin() + WordSize + Address;
206 CurFn = Entry.Function;
207 FunctionAddresses[
FuncId] = Entry.Function;
208 FunctionIds[Entry.Function] =
FuncId;
210 if (Entry.Function != CurFn) {
212 CurFn = Entry.Function;
213 FunctionAddresses[
FuncId] = Entry.Function;
214 FunctionIds[Entry.Function] =
FuncId;
230 return make_error<StringError>(
231 Twine(
"Failed memory-mapping file '") + Filename +
"'.", EC);
233 std::vector<YAMLXRaySledEntry> YAMLSleds;
237 return make_error<StringError>(
238 Twine(
"Failed loading YAML document from '") + Filename +
"'.",
241 Sleds.reserve(YAMLSleds.size());
242 for (
const auto &
Y : YAMLSleds) {
243 FunctionAddresses[
Y.FuncId] =
Y.Function;
244 FunctionIds[
Y.Function] =
Y.FuncId;
245 Sleds.push_back(
SledEntry{
Y.Address,
Y.Function,
Y.Kind,
Y.AlwaysInstrument,
261 if (!ObjectFileOrError) {
262 auto E = ObjectFileOrError.takeError();
283 if (
auto E =
loadYAML(*FdOrErr, FileSize, Filename, Map.Sleds,
284 Map.FunctionAddresses, Map.FunctionIds))
286 }
else if (
auto E =
loadObj(Filename, *ObjectFileOrError, Map.Sleds,
287 Map.FunctionAddresses, Map.FunctionIds)) {
This is an optimization pass for GlobalISel generic memory operations.
Optional< uint64_t > getFunctionAddr(int32_t FuncId) const
Returns the function address for a function id.
The InstrumentationMap represents the computed function id's and indicated function addresses from an...
uint64_t(*)(uint64_t Type, uint64_t Offset, uint64_t S, uint64_t LocData, int64_t Addend) RelocationResolver
static ErrorSuccess success()
Create a success value.
virtual Triple::ArchType getArch() const =0
FunctionKinds
Each entry here represents the kinds of supported instrumentation map entries.
Tagged union holding either a T or a Error.
Optional< int32_t > getFunctionId(uint64_t Addr) const
Returns an XRay computed function id, provided a function address.
void consumeError(Error Err)
Consume a Error without doing anything.
Expected< InstrumentationMap > loadInstrumentationMap(StringRef Filename)
Loads the instrumentation map from |Filename|.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
(vector float) vec_cmpeq(*A, *B) C
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
Expected< file_t > openNativeFileForRead(const Twine &Name, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
static void getAddend(uint64_t &, const Elf_Rel_Impl< ELFT, false > &)
std::vector< SledEntry > SledContainer
This is a value type class that represents a single section in the list of sections in the object fil...
bool(*)(uint64_t) SupportsRelocation
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from where P can be anything The alignment inference code cannot handle loads from globals in static non mode because it doesn t look through the extra dyld stub load If you try vec_align ll without relocation you ll see what I mean We should lower which eliminates a constant pool load For float z nounwind readonly
bool isArch32Bit() const
Test whether the architecture is 32-bit.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
static Error loadYAML(sys::fs::file_t Fd, size_t FileSize, StringRef Filename, InstrumentationMap::SledContainer &Sleds, InstrumentationMap::FunctionAddressMap &FunctionAddresses, InstrumentationMap::FunctionAddressReverseMap &FunctionIds)
iterator find(const_arg_type_t< KeyT > Val)
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
std::error_code closeFile(file_t &F)
Close the file object.
std::pair< SupportsRelocation, RelocationResolver > getRelocationResolver(const ObjectFile &Obj)
const unsigned char * bytes_begin() const
Triple makeTriple() const
Create a triple from the data in this object file.
StringRef - Represent a constant reference to a string, i.e.
This class is the base class for all object file types.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
std::error_code make_error_code(BitcodeError E)
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Lightweight error class with error context and mandatory checking.
Represents an XRay instrumentation sled entry from an object file.
static Error loadObj(StringRef Filename, object::OwningBinary< object::ObjectFile > &ObjFile, InstrumentationMap::SledContainer &Sleds, InstrumentationMap::FunctionAddressMap &FunctionAddresses, InstrumentationMap::FunctionAddressReverseMap &FunctionIds)
Error takeError()
Take ownership of the stored error.
This class represents a memory mapped file.
std::error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
section_iterator_range sections() const
This is a value type class that represents a single relocation in the list of relocations in the obje...
Expected< int64_t > getAddend() const
std::unordered_map< int32_t, uint64_t > FunctionAddressMap
std::unordered_map< uint64_t, int32_t > FunctionAddressReverseMap
uint64_t resolveRelocation(RelocationResolver Resolver, const RelocationRef &R, uint64_t S, uint64_t LocData)
const unsigned char * bytes_end() const