Skip to content

Commit

Permalink
Merge pull request #110 from vext01/dont-alloc-sections
Browse files Browse the repository at this point in the history
Don't SHF_ALLOC the blockmap and LLVM bitcode sections.
  • Loading branch information
ptersilie authored Dec 11, 2023
2 parents 0b60fc9 + 6bbd60f commit 62c9338
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 102 deletions.
42 changes: 5 additions & 37 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ namespace llvm {
extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold;
}

extern bool YkAllocLLVMBCSection;

namespace {

/// These are manifest constants used by the bitcode writer. They do not need to
Expand Down Expand Up @@ -5185,45 +5183,15 @@ void llvm::embedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf,
ModuleData = ArrayRef<uint8_t>((const uint8_t *)Buf.getBufferStart(),
Buf.getBufferSize());
}

GlobalValue::LinkageTypes SymLinkage = GlobalValue::PrivateLinkage;

// For the YK JIT we prepend a header containing the size of the bitcode.
// This is required in order to load bitcode from memory.
std::vector<uint8_t> YkModuleData;
if (YkAllocLLVMBCSection) {
// Write length field.
uint64_t ModuleDataSize = ModuleData.size();
uint8_t *Bytes = reinterpret_cast<uint8_t *>(&ModuleDataSize);
for (size_t I = 0; I < sizeof(ModuleDataSize); I++)
YkModuleData.push_back(Bytes[I]);

// Append bitcode.
std::move(ModuleData.begin(), ModuleData.end(),
std::back_inserter(YkModuleData));
ModuleData = YkModuleData;

// Ensure the symbol is exported in the resulting binary.
SymLinkage = GlobalValue::ExternalLinkage;
}

llvm::Constant *ModuleConstant =
llvm::ConstantDataArray::get(M.getContext(), ModuleData);
llvm::GlobalVariable *GV = new llvm::GlobalVariable(
M, ModuleConstant->getType(), true, SymLinkage, ModuleConstant);
M, ModuleConstant->getType(), true, llvm::GlobalValue::PrivateLinkage,
ModuleConstant);
GV->setSection(getSectionNameForBitcode(T));

if (YkAllocLLVMBCSection) {
// For Yk there will only ever be one embedded (LTO'd) module. This gives
// us the freedom to align the section so that we can read our size header
// without issue.
GV->setAlignment(Align(sizeof(uint64_t)));
} else {
// Set alignment to 1 to prevent padding between two contributions from input
// sections after linking.
GV->setAlignment(Align(1));
}

// Set alignment to 1 to prevent padding between two contributions from input
// sections after linking.
GV->setAlignment(Align(1));
UsedArray.push_back(
ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
if (llvm::GlobalVariable *Old =
Expand Down
21 changes: 0 additions & 21 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ static cl::opt<bool>
cl::desc("Embed final IR as bitcode after all "
"optimisations and transformations have run."));

extern bool YkAllocLLVMBBAddrMapSection;
extern bool YkExtendedLLVMBBAddrMapSection;
extern bool YkStackMapOffsetFix;
extern bool YkEmbedIR;
Expand Down Expand Up @@ -1403,18 +1402,6 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {

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

if (YkAllocLLVMBBAddrMapSection) {
if (!YkEmittedFirstBBAddrMap) {
// Add the `ykllvm.bbaddrmaps.start` symbol.
emitYkBBAddrMapSymbol(MF.getContext(), *OutStreamer, true);
YkEmittedFirstBBAddrMap = true;
}
// We cache the last seen bbaddrmap section fragment so that we can insert
// the stop symbol when the asmprinter is finalising.
YkLastBBAddrMapSection = BBAddrMapSection;
}

OutStreamer->AddComment("version");
uint8_t BBAddrMapVersion = OutStreamer->getContext().getBBAddrMapVersion();
OutStreamer->emitInt8(BBAddrMapVersion);
Expand Down Expand Up @@ -2513,14 +2500,6 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
}

bool AsmPrinter::doFinalization(Module &M) {
if (YkAllocLLVMBBAddrMapSection && YkEmittedFirstBBAddrMap) {
// Add the `ykllvm.bbaddrmaps.stop` symbol.
OutStreamer->pushSection();
OutStreamer->switchSection(YkLastBBAddrMapSection);
emitYkBBAddrMapSymbol(OutContext, *OutStreamer, false);
OutStreamer->popSection();
}

// The `embed-bitcode` flag serialises the LLVM IR after only architecture
// agnostic optimisations have been run, but then proceeds to apply other
// optimisations and transformations afterwards. Sometimes this final version
Expand Down
8 changes: 0 additions & 8 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
using namespace llvm;
using namespace dwarf;

extern bool YkAllocLLVMBCSection;

static cl::opt<bool> JumpTableInFunctionSection(
"jumptable-in-function-section", cl::Hidden, cl::init(false),
cl::desc("Putting Jump Table in function section"));
Expand Down Expand Up @@ -810,12 +808,6 @@ static MCSection *selectExplicitSectionGlobal(
Retain, ForceUnique);

const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);

// The Yk JIT expects to load the IR from its address space. This tells the
// loader to load the section.
if (YkAllocLLVMBCSection && (SectionName == ".llvmbc"))
Flags |= llvm::ELF::SHF_ALLOC;

MCSectionELF *Section = Ctx.getELFSection(
SectionName, getELFSectionType(SectionName, Kind), Flags, EntrySize,
Group, IsComdat, UniqueID, LinkedToSym);
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/MC/MCObjectFileInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,6 @@ 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 @@ -1146,9 +1144,6 @@ 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
31 changes: 0 additions & 31 deletions llvm/lib/Support/Yk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,6 @@

using namespace llvm;

bool YkAllocLLVMBCSection;
namespace {
struct CreateYkAllocLLVMBCSectionParser {
static void *call() {
return new cl::opt<bool, true>(
"yk-alloc-llvmbc-section",
cl::desc("Make the `.llvmbc` section loadable"), cl::NotHidden,
cl::location(YkAllocLLVMBCSection));
}
};
} // namespace
static ManagedStatic<cl::opt<bool, true>, CreateYkAllocLLVMBCSectionParser>
YkAllocLLVMBCSectionParser;

bool YkAllocLLVMBBAddrMapSection;
namespace {
struct CreateYkAllocLLVMBBAddrMapSectionParser {
static void *call() {
return new cl::opt<bool, true>(
"yk-alloc-llvmbbaddrmap-section",
cl::desc("Make the `.llvmbbaddrmap` section loadable"), cl::NotHidden,
cl::location(YkAllocLLVMBBAddrMapSection));
}
};
} // namespace
static ManagedStatic<cl::opt<bool, true>,
CreateYkAllocLLVMBBAddrMapSectionParser>
YkAllocLLVMBBAddrMapSectionParser;

bool YkExtendedLLVMBBAddrMapSection;
namespace {
struct CreateYkExtendedLLVMBBAddrMapSectionParser {
Expand Down Expand Up @@ -126,8 +97,6 @@ struct CreateYkEmbedIRParser {
static ManagedStatic<cl::opt<bool, true>, CreateYkEmbedIRParser> YkEmbedIRParser;

void llvm::initYkOptions() {
*YkAllocLLVMBCSectionParser;
*YkAllocLLVMBBAddrMapSectionParser;
*YkExtendedLLVMBBAddrMapSectionParser;
*YkStackMapOffsetFixParser;
*YkStackMapAdditionalLocsParser;
Expand Down

0 comments on commit 62c9338

Please sign in to comment.