aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/XRay
diff options
context:
space:
mode:
authorIan Levesque <ianlevesque@fb.com>2020-05-19 01:38:14 -0400
committerIan Levesque <ianlevesque@fb.com>2020-05-28 18:41:11 -0400
commite62d67f770d279d0ef7e6f1175e0a88aaffd58b0 (patch)
tree8500622176c3fc967c11cd9eb378a7c4e648457f /llvm/lib/XRay
parent57f1c43cda8a05920997cd50147ed01a124b4239 (diff)
downloadllvm-e62d67f770d279d0ef7e6f1175e0a88aaffd58b0.zip
llvm-e62d67f770d279d0ef7e6f1175e0a88aaffd58b0.tar.gz
llvm-e62d67f770d279d0ef7e6f1175e0a88aaffd58b0.tar.bz2
[xray] Add llvm-xray extract support for 32 bit ARM
Summary: XRay works on 32-bit ARM but extract didn't support it. See also another previous attempt in D77858. Reviewers: MaskRay, dberris, johnislarry Subscribers: kristof.beyls, hiraditya, danielkiss, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D80185
Diffstat (limited to 'llvm/lib/XRay')
-rw-r--r--llvm/lib/XRay/InstrumentationMap.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/llvm/lib/XRay/InstrumentationMap.cpp b/llvm/lib/XRay/InstrumentationMap.cpp
index 9db9692..de0a9e6 100644
--- a/llvm/lib/XRay/InstrumentationMap.cpp
+++ b/llvm/lib/XRay/InstrumentationMap.cpp
@@ -61,6 +61,7 @@ loadObj(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile,
if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
!(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
ObjFile.getBinary()->getArch() == Triple::ppc64le ||
+ ObjFile.getBinary()->getArch() == Triple::arm ||
ObjFile.getBinary()->getArch() == Triple::aarch64))
return make_error<StringError>(
"File format not supported (only does ELF and Mach-O little endian "
@@ -115,7 +116,14 @@ loadObj(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile,
for (const object::SectionRef &Section : Sections) {
for (const object::RelocationRef &Reloc : Section.relocations()) {
- if (SupportsRelocation && SupportsRelocation(Reloc.getType())) {
+ if (ObjFile.getBinary()->getArch() == Triple::arm) {
+ if (SupportsRelocation && SupportsRelocation(Reloc.getType())) {
+ Expected<uint64_t> ValueOrErr = Reloc.getSymbol()->getValue();
+ if (!ValueOrErr)
+ return ValueOrErr.takeError();
+ Relocs.insert({Reloc.getOffset(), Resolver(Reloc, *ValueOrErr, 0)});
+ }
+ } else if (SupportsRelocation && SupportsRelocation(Reloc.getType())) {
auto AddendOrErr = object::ELFRelocationRef(Reloc).getAddend();
auto A = AddendOrErr ? *AddendOrErr : 0;
Expected<uint64_t> ValueOrErr = Reloc.getSymbol()->getValue();
@@ -133,12 +141,13 @@ loadObj(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile,
// Copy the instrumentation map data into the Sleds data structure.
auto C = Contents.bytes_begin();
- static constexpr size_t ELF64SledEntrySize = 32;
+ bool Is32Bit = ObjFile.getBinary()->makeTriple().isArch32Bit();
+ size_t ELFSledEntrySize = Is32Bit ? 16 : 32;
- if ((C - Contents.bytes_end()) % ELF64SledEntrySize != 0)
+ if ((C - Contents.bytes_end()) % ELFSledEntrySize != 0)
return make_error<StringError>(
Twine("Instrumentation map entries not evenly divisible by size of "
- "an XRay sled entry in ELF64."),
+ "an XRay sled entry."),
std::make_error_code(std::errc::executable_format_error));
auto RelocateOrElse = [&](uint64_t Offset, uint64_t Address) {
@@ -151,20 +160,26 @@ loadObj(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile,
return Address;
};
- const int WordSize = 8;
+ const int WordSize = Is32Bit ? 4 : 8;
int32_t FuncId = 1;
uint64_t CurFn = 0;
- for (; C != Contents.bytes_end(); C += ELF64SledEntrySize) {
+ for (; C != Contents.bytes_end(); C += ELFSledEntrySize) {
DataExtractor Extractor(
- StringRef(reinterpret_cast<const char *>(C), ELF64SledEntrySize), true,
+ StringRef(reinterpret_cast<const char *>(C), ELFSledEntrySize), true,
8);
Sleds.push_back({});
auto &Entry = Sleds.back();
uint64_t OffsetPtr = 0;
uint64_t AddrOff = OffsetPtr;
- Entry.Address = RelocateOrElse(AddrOff, Extractor.getU64(&OffsetPtr));
+ if (Is32Bit)
+ Entry.Address = RelocateOrElse(AddrOff, Extractor.getU32(&OffsetPtr));
+ else
+ Entry.Address = RelocateOrElse(AddrOff, Extractor.getU64(&OffsetPtr));
uint64_t FuncOff = OffsetPtr;
- Entry.Function = RelocateOrElse(FuncOff, Extractor.getU64(&OffsetPtr));
+ if (Is32Bit)
+ Entry.Function = RelocateOrElse(FuncOff, Extractor.getU32(&OffsetPtr));
+ else
+ Entry.Function = RelocateOrElse(FuncOff, Extractor.getU64(&OffsetPtr));
auto Kind = Extractor.getU8(&OffsetPtr);
static constexpr SledEntry::FunctionKinds Kinds[] = {
SledEntry::FunctionKinds::ENTRY, SledEntry::FunctionKinds::EXIT,