[BOLT] LongJmp: Fix hot text section alignment

The BinaryEmitter uses opts::AlignText value to align the hot text
section. Also check that the opts::AlignText is at least
equal opts::AlignFunctions for the same reason, as described in D121392.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

Differential Revision: https://reviews.llvm.org/D121728
This commit is contained in:
Vladislav Khmelevsky 2022-03-15 22:17:51 +03:00
parent 0389462587
commit 62a289d85c
2 changed files with 7 additions and 3 deletions

View File

@ -18,6 +18,7 @@ using namespace llvm;
namespace opts {
extern cl::OptionCategory BoltOptCategory;
extern llvm::cl::opt<unsigned> AlignText;
extern cl::opt<unsigned> AlignFunctions;
extern cl::opt<bool> UseOldText;
extern cl::opt<bool> HotFunctionsAtEnd;
@ -342,7 +343,7 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
ColdLayoutDone = true;
if (opts::HotFunctionsAtEnd)
DotAddress = alignTo(DotAddress, BC.PageAlign);
DotAddress = alignTo(DotAddress, opts::AlignText);
}
DotAddress = alignTo(DotAddress, BinaryFunction::MinAlign);
@ -390,11 +391,11 @@ void LongJmpPass::tentativeLayout(
// Initial padding
if (opts::UseOldText && EstimatedTextSize <= BC.OldTextSectionSize) {
DotAddress = BC.OldTextSectionAddress;
uint64_t Pad = offsetToAlignment(DotAddress, llvm::Align(BC.PageAlign));
uint64_t Pad = offsetToAlignment(DotAddress, llvm::Align(opts::AlignText));
if (Pad + EstimatedTextSize <= BC.OldTextSectionSize)
DotAddress += Pad;
} else {
DotAddress = alignTo(BC.LayoutStartAddress, BC.PageAlign);
DotAddress = alignTo(BC.LayoutStartAddress, opts::AlignText);
}
tentativeLayoutRelocMode(BC, SortedFunctions, DotAddress);

View File

@ -1743,6 +1743,9 @@ void RewriteInstance::adjustCommandLineOptions() {
if (!opts::AlignText.getNumOccurrences())
opts::AlignText = BC->PageAlign;
if (opts::AlignText < opts::AlignFunctions)
opts::AlignText = (unsigned)opts::AlignFunctions;
if (BC->isX86() && opts::Lite.getNumOccurrences() == 0 && !opts::StrictMode &&
!opts::UseOldText)
opts::Lite = true;