Skip to content

Commit 62a289d

Browse files
committed
[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
1 parent 0389462 commit 62a289d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

bolt/lib/Passes/LongJmp.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ using namespace llvm;
1818

1919
namespace opts {
2020
extern cl::OptionCategory BoltOptCategory;
21+
extern llvm::cl::opt<unsigned> AlignText;
2122
extern cl::opt<unsigned> AlignFunctions;
2223
extern cl::opt<bool> UseOldText;
2324
extern cl::opt<bool> HotFunctionsAtEnd;
@@ -342,7 +343,7 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
342343
tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress);
343344
ColdLayoutDone = true;
344345
if (opts::HotFunctionsAtEnd)
345-
DotAddress = alignTo(DotAddress, BC.PageAlign);
346+
DotAddress = alignTo(DotAddress, opts::AlignText);
346347
}
347348

348349
DotAddress = alignTo(DotAddress, BinaryFunction::MinAlign);
@@ -390,11 +391,11 @@ void LongJmpPass::tentativeLayout(
390391
// Initial padding
391392
if (opts::UseOldText && EstimatedTextSize <= BC.OldTextSectionSize) {
392393
DotAddress = BC.OldTextSectionAddress;
393-
uint64_t Pad = offsetToAlignment(DotAddress, llvm::Align(BC.PageAlign));
394+
uint64_t Pad = offsetToAlignment(DotAddress, llvm::Align(opts::AlignText));
394395
if (Pad + EstimatedTextSize <= BC.OldTextSectionSize)
395396
DotAddress += Pad;
396397
} else {
397-
DotAddress = alignTo(BC.LayoutStartAddress, BC.PageAlign);
398+
DotAddress = alignTo(BC.LayoutStartAddress, opts::AlignText);
398399
}
399400

400401
tentativeLayoutRelocMode(BC, SortedFunctions, DotAddress);

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,9 @@ void RewriteInstance::adjustCommandLineOptions() {
17431743
if (!opts::AlignText.getNumOccurrences())
17441744
opts::AlignText = BC->PageAlign;
17451745

1746+
if (opts::AlignText < opts::AlignFunctions)
1747+
opts::AlignText = (unsigned)opts::AlignFunctions;
1748+
17461749
if (BC->isX86() && opts::Lite.getNumOccurrences() == 0 && !opts::StrictMode &&
17471750
!opts::UseOldText)
17481751
opts::Lite = true;

0 commit comments

Comments
 (0)