Skip to content

Commit

Permalink
Merge rust-lang#47
Browse files Browse the repository at this point in the history
47: Make it so we can read the `.llvm_bb_addr_map` section from memory at runtime r=ltratt a=vext01



Co-authored-by: Edd Barrett <vext01@gmail.com>
  • Loading branch information
bors[bot] and vext01 committed Sep 29, 2022
2 parents 1cb9a4a + 3c763c9 commit bd1d951
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ static cl::opt<bool>
cl::desc("Embed final IR as bitcode after all "
"optimisations and transformations have run."));

extern bool YkAllocLLVMBBAddrMapSection;

const char DWARFGroupName[] = "dwarf";
const char DWARFGroupDescription[] = "DWARF Emission";
const char DbgTimerName[] = "emit";
Expand Down Expand Up @@ -1324,6 +1326,20 @@ static unsigned getBBAddrMapMetadata(const MachineBasicBlock &MBB) {
(const_cast<MachineBasicBlock &>(MBB).canFallThrough() << 3);
}

void emitYkBBAddrMapSymbol(const MachineFunction &MF, MCStreamer &OutStreamer,
bool Start) {
std::string SymName("ykllvm.bbaddrmap.");
SymName.append(MF.getName().str());
if (Start)
SymName.append(".start");
else
SymName.append(".end");

MCSymbol *Sym = MF.getContext().getOrCreateSymbol(SymName);
OutStreamer.emitSymbolAttribute(Sym, llvm::MCSA_Global);
OutStreamer.emitLabel(Sym);
}

void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
MCSection *BBAddrMapSection =
getObjFileLowering().getBBAddrMapSection(*MF.getSection());
Expand All @@ -1333,6 +1349,11 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {

OutStreamer->pushSection();
OutStreamer->switchSection(BBAddrMapSection);

// Add the `ykllvm.bbaddrmap.<func>.start` symbol.
if (YkAllocLLVMBBAddrMapSection)
emitYkBBAddrMapSymbol(MF, *OutStreamer, true);

OutStreamer->AddComment("version");
OutStreamer->emitInt8(OutStreamer->getContext().getBBAddrMapVersion());
OutStreamer->AddComment("feature");
Expand Down Expand Up @@ -1421,6 +1442,11 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
OutStreamer->emitULEB128IntValue(I);
}
}

// Add the `ykllvm.bbaddrmap.<func>.end` symbol.
if (YkAllocLLVMBBAddrMapSection)
emitYkBBAddrMapSymbol(MF, *OutStreamer, false);

OutStreamer->popSection();
}

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/MC/MCObjectFileInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,8 @@ MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
cast<MCSymbolELF>(TextSec.getBeginSymbol()));
}

extern bool YkAllocLLVMBBAddrMapSection;

MCSection *
MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
if (Ctx->getObjectFileType() != MCContext::IsELF)
Expand All @@ -1133,6 +1135,9 @@ MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
Flags |= ELF::SHF_GROUP;
}

if (YkAllocLLVMBBAddrMapSection)
Flags |= ELF::SHF_ALLOC;

// Use the text section's begin symbol and unique ID to create a separate
// .llvm_bb_addr_map section associated with every unique text section.
return Ctx->getELFSection(".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP,
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Support/Yk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ bool YkAllocLLVMBCSection;
static cl::opt<bool, true> YkAllocLLVMBCSectionParser(
"yk-alloc-llvmbc-section", cl::desc("Make the `.llvmbc` section loadable"),
cl::NotHidden, cl::location(YkAllocLLVMBCSection));

bool YkAllocLLVMBBAddrMapSection;
static cl::opt<bool, true> YkAllocLLVMBBAddrMapSectionParser(
"yk-alloc-llvmbbaddrmap-section",
cl::desc("Make the `.llvmbbaddrmap` section loadable"), cl::NotHidden,
cl::location(YkAllocLLVMBBAddrMapSection));

0 comments on commit bd1d951

Please sign in to comment.