diff options
author | Kuba Mracek <mracek@apple.com> | 2016-11-23 02:07:04 +0000 |
---|---|---|
committer | Kuba Mracek <mracek@apple.com> | 2016-11-23 02:07:04 +0000 |
commit | 06995e866be7d9f20ccf1522ed1006b7f19eb146 (patch) | |
tree | 79572b7352392c6d7ccae462a3a052c6ca591d84 /llvm/lib/Target/ARM/ARMMCInstLower.cpp | |
parent | 6aefe00ccf7f0f9de4718f71e180916689d0b65e (diff) | |
download | bcm5719-llvm-06995e866be7d9f20ccf1522ed1006b7f19eb146.tar.gz bcm5719-llvm-06995e866be7d9f20ccf1522ed1006b7f19eb146.zip |
[xray] Add XRay support for Mach-O in CodeGen
Currently, XRay only supports emitting the XRay table (xray_instr_map) on ELF binaries. Let's add Mach-O support.
Differential Revision: https://reviews.llvm.org/D26983
llvm-svn: 287734
Diffstat (limited to 'llvm/lib/Target/ARM/ARMMCInstLower.cpp')
-rw-r--r-- | llvm/lib/Target/ARM/ARMMCInstLower.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/llvm/lib/Target/ARM/ARMMCInstLower.cpp b/llvm/lib/Target/ARM/ARMMCInstLower.cpp index 79f61652d61..dde91a7e04e 100644 --- a/llvm/lib/Target/ARM/ARMMCInstLower.cpp +++ b/llvm/lib/Target/ARM/ARMMCInstLower.cpp @@ -24,6 +24,7 @@ #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCSectionELF.h" +#include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCInstBuilder.h" #include "llvm/MC/MCStreamer.h" using namespace llvm; @@ -228,24 +229,33 @@ void ARMAsmPrinter::EmitXRayTable() { if (Sleds.empty()) return; + + MCSection *Section = nullptr; if (Subtarget->isTargetELF()) { - auto *Section = OutContext.getELFSection( - "xray_instr_map", ELF::SHT_PROGBITS, - ELF::SHF_ALLOC | ELF::SHF_GROUP | ELF::SHF_MERGE, 0, - CurrentFnSym->getName()); - auto PrevSection = OutStreamer->getCurrentSectionOnly(); - OutStreamer->SwitchSection(Section); - for (const auto &Sled : Sleds) { - OutStreamer->EmitSymbolValue(Sled.Sled, 4); - OutStreamer->EmitSymbolValue(CurrentFnSym, 4); - auto Kind = static_cast<uint8_t>(Sled.Kind); - OutStreamer->EmitBytes( - StringRef(reinterpret_cast<const char *>(&Kind), 1)); - OutStreamer->EmitBytes( - StringRef(reinterpret_cast<const char *>(&Sled.AlwaysInstrument), 1)); - OutStreamer->EmitZeros(6); - } - OutStreamer->SwitchSection(PrevSection); + Section = OutContext.getELFSection("xray_instr_map", ELF::SHT_PROGBITS, + ELF::SHF_ALLOC | ELF::SHF_GROUP | + ELF::SHF_MERGE, + 0, CurrentFnSym->getName()); + } else if (Subtarget->isTargetMachO()) { + Section = OutContext.getMachOSection("__DATA", "xray_instr_map", 0, + SectionKind::getReadOnlyWithRel()); + } else { + llvm_unreachable("Unsupported target"); } + + auto PrevSection = OutStreamer->getCurrentSectionOnly(); + OutStreamer->SwitchSection(Section); + for (const auto &Sled : Sleds) { + OutStreamer->EmitSymbolValue(Sled.Sled, 4); + OutStreamer->EmitSymbolValue(CurrentFnSym, 4); + auto Kind = static_cast<uint8_t>(Sled.Kind); + OutStreamer->EmitBytes( + StringRef(reinterpret_cast<const char *>(&Kind), 1)); + OutStreamer->EmitBytes( + StringRef(reinterpret_cast<const char *>(&Sled.AlwaysInstrument), 1)); + OutStreamer->EmitZeros(6); + } + OutStreamer->SwitchSection(PrevSection); + Sleds.clear(); } |