Skip to content

Commit 6bbd60f

Browse files
committed
Don't SHF_ALLOC the blockmap and LLVM bitcode sections.
It's not clear if it's correct to be SHF_ALLOCing these sections, so we err on the side of caution and don't. For more info, see: ykjit/yk#923
1 parent 0b60fc9 commit 6bbd60f

File tree

5 files changed

+5
-102
lines changed

5 files changed

+5
-102
lines changed

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ namespace llvm {
9999
extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold;
100100
}
101101

102-
extern bool YkAllocLLVMBCSection;
103-
104102
namespace {
105103

106104
/// These are manifest constants used by the bitcode writer. They do not need to
@@ -5185,45 +5183,15 @@ void llvm::embedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf,
51855183
ModuleData = ArrayRef<uint8_t>((const uint8_t *)Buf.getBufferStart(),
51865184
Buf.getBufferSize());
51875185
}
5188-
5189-
GlobalValue::LinkageTypes SymLinkage = GlobalValue::PrivateLinkage;
5190-
5191-
// For the YK JIT we prepend a header containing the size of the bitcode.
5192-
// This is required in order to load bitcode from memory.
5193-
std::vector<uint8_t> YkModuleData;
5194-
if (YkAllocLLVMBCSection) {
5195-
// Write length field.
5196-
uint64_t ModuleDataSize = ModuleData.size();
5197-
uint8_t *Bytes = reinterpret_cast<uint8_t *>(&ModuleDataSize);
5198-
for (size_t I = 0; I < sizeof(ModuleDataSize); I++)
5199-
YkModuleData.push_back(Bytes[I]);
5200-
5201-
// Append bitcode.
5202-
std::move(ModuleData.begin(), ModuleData.end(),
5203-
std::back_inserter(YkModuleData));
5204-
ModuleData = YkModuleData;
5205-
5206-
// Ensure the symbol is exported in the resulting binary.
5207-
SymLinkage = GlobalValue::ExternalLinkage;
5208-
}
5209-
52105186
llvm::Constant *ModuleConstant =
52115187
llvm::ConstantDataArray::get(M.getContext(), ModuleData);
52125188
llvm::GlobalVariable *GV = new llvm::GlobalVariable(
5213-
M, ModuleConstant->getType(), true, SymLinkage, ModuleConstant);
5189+
M, ModuleConstant->getType(), true, llvm::GlobalValue::PrivateLinkage,
5190+
ModuleConstant);
52145191
GV->setSection(getSectionNameForBitcode(T));
5215-
5216-
if (YkAllocLLVMBCSection) {
5217-
// For Yk there will only ever be one embedded (LTO'd) module. This gives
5218-
// us the freedom to align the section so that we can read our size header
5219-
// without issue.
5220-
GV->setAlignment(Align(sizeof(uint64_t)));
5221-
} else {
5222-
// Set alignment to 1 to prevent padding between two contributions from input
5223-
// sections after linking.
5224-
GV->setAlignment(Align(1));
5225-
}
5226-
5192+
// Set alignment to 1 to prevent padding between two contributions from input
5193+
// sections after linking.
5194+
GV->setAlignment(Align(1));
52275195
UsedArray.push_back(
52285196
ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
52295197
if (llvm::GlobalVariable *Old =

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ static cl::opt<bool>
138138
cl::desc("Embed final IR as bitcode after all "
139139
"optimisations and transformations have run."));
140140

141-
extern bool YkAllocLLVMBBAddrMapSection;
142141
extern bool YkExtendedLLVMBBAddrMapSection;
143142
extern bool YkStackMapOffsetFix;
144143
extern bool YkEmbedIR;
@@ -1403,18 +1402,6 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
14031402

14041403
OutStreamer->pushSection();
14051404
OutStreamer->switchSection(BBAddrMapSection);
1406-
1407-
if (YkAllocLLVMBBAddrMapSection) {
1408-
if (!YkEmittedFirstBBAddrMap) {
1409-
// Add the `ykllvm.bbaddrmaps.start` symbol.
1410-
emitYkBBAddrMapSymbol(MF.getContext(), *OutStreamer, true);
1411-
YkEmittedFirstBBAddrMap = true;
1412-
}
1413-
// We cache the last seen bbaddrmap section fragment so that we can insert
1414-
// the stop symbol when the asmprinter is finalising.
1415-
YkLastBBAddrMapSection = BBAddrMapSection;
1416-
}
1417-
14181405
OutStreamer->AddComment("version");
14191406
uint8_t BBAddrMapVersion = OutStreamer->getContext().getBBAddrMapVersion();
14201407
OutStreamer->emitInt8(BBAddrMapVersion);
@@ -2513,14 +2500,6 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
25132500
}
25142501

25152502
bool AsmPrinter::doFinalization(Module &M) {
2516-
if (YkAllocLLVMBBAddrMapSection && YkEmittedFirstBBAddrMap) {
2517-
// Add the `ykllvm.bbaddrmaps.stop` symbol.
2518-
OutStreamer->pushSection();
2519-
OutStreamer->switchSection(YkLastBBAddrMapSection);
2520-
emitYkBBAddrMapSymbol(OutContext, *OutStreamer, false);
2521-
OutStreamer->popSection();
2522-
}
2523-
25242503
// The `embed-bitcode` flag serialises the LLVM IR after only architecture
25252504
// agnostic optimisations have been run, but then proceeds to apply other
25262505
// optimisations and transformations afterwards. Sometimes this final version

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@
7171
using namespace llvm;
7272
using namespace dwarf;
7373

74-
extern bool YkAllocLLVMBCSection;
75-
7674
static cl::opt<bool> JumpTableInFunctionSection(
7775
"jumptable-in-function-section", cl::Hidden, cl::init(false),
7876
cl::desc("Putting Jump Table in function section"));
@@ -810,12 +808,6 @@ static MCSection *selectExplicitSectionGlobal(
810808
Retain, ForceUnique);
811809

812810
const MCSymbolELF *LinkedToSym = getLinkedToSymbol(GO, TM);
813-
814-
// The Yk JIT expects to load the IR from its address space. This tells the
815-
// loader to load the section.
816-
if (YkAllocLLVMBCSection && (SectionName == ".llvmbc"))
817-
Flags |= llvm::ELF::SHF_ALLOC;
818-
819811
MCSectionELF *Section = Ctx.getELFSection(
820812
SectionName, getELFSectionType(SectionName, Kind), Flags, EntrySize,
821813
Group, IsComdat, UniqueID, LinkedToSym);

llvm/lib/MC/MCObjectFileInfo.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,6 @@ MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
11311131
cast<MCSymbolELF>(TextSec.getBeginSymbol()));
11321132
}
11331133

1134-
extern bool YkAllocLLVMBBAddrMapSection;
1135-
11361134
MCSection *
11371135
MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
11381136
if (Ctx->getObjectFileType() != MCContext::IsELF)
@@ -1146,9 +1144,6 @@ MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {
11461144
Flags |= ELF::SHF_GROUP;
11471145
}
11481146

1149-
if (YkAllocLLVMBBAddrMapSection)
1150-
Flags |= ELF::SHF_ALLOC;
1151-
11521147
// Use the text section's begin symbol and unique ID to create a separate
11531148
// .llvm_bb_addr_map section associated with every unique text section.
11541149
return Ctx->getELFSection(".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP,

llvm/lib/Support/Yk.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,6 @@
44

55
using namespace llvm;
66

7-
bool YkAllocLLVMBCSection;
8-
namespace {
9-
struct CreateYkAllocLLVMBCSectionParser {
10-
static void *call() {
11-
return new cl::opt<bool, true>(
12-
"yk-alloc-llvmbc-section",
13-
cl::desc("Make the `.llvmbc` section loadable"), cl::NotHidden,
14-
cl::location(YkAllocLLVMBCSection));
15-
}
16-
};
17-
} // namespace
18-
static ManagedStatic<cl::opt<bool, true>, CreateYkAllocLLVMBCSectionParser>
19-
YkAllocLLVMBCSectionParser;
20-
21-
bool YkAllocLLVMBBAddrMapSection;
22-
namespace {
23-
struct CreateYkAllocLLVMBBAddrMapSectionParser {
24-
static void *call() {
25-
return new cl::opt<bool, true>(
26-
"yk-alloc-llvmbbaddrmap-section",
27-
cl::desc("Make the `.llvmbbaddrmap` section loadable"), cl::NotHidden,
28-
cl::location(YkAllocLLVMBBAddrMapSection));
29-
}
30-
};
31-
} // namespace
32-
static ManagedStatic<cl::opt<bool, true>,
33-
CreateYkAllocLLVMBBAddrMapSectionParser>
34-
YkAllocLLVMBBAddrMapSectionParser;
35-
367
bool YkExtendedLLVMBBAddrMapSection;
378
namespace {
389
struct CreateYkExtendedLLVMBBAddrMapSectionParser {
@@ -126,8 +97,6 @@ struct CreateYkEmbedIRParser {
12697
static ManagedStatic<cl::opt<bool, true>, CreateYkEmbedIRParser> YkEmbedIRParser;
12798

12899
void llvm::initYkOptions() {
129-
*YkAllocLLVMBCSectionParser;
130-
*YkAllocLLVMBBAddrMapSectionParser;
131100
*YkExtendedLLVMBBAddrMapSectionParser;
132101
*YkStackMapOffsetFixParser;
133102
*YkStackMapAdditionalLocsParser;

0 commit comments

Comments
 (0)