Skip to content

Commit 8ab69ba

Browse files
committed
[BOLT] Set cold sections alignment explicitly
The cold text section alignment is set using the maximum alignment value passed to the emitCodeAlignment. In order to calculate tentetive layout right we will set the minimum alignment of such sections to the maximum possible function alignment explicitly. Differential Revision: https://reviews.llvm.org/D121392
1 parent 78406ac commit 8ab69ba

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern llvm::cl::OptionCategory BoltInstrCategory;
3030
extern llvm::cl::OptionCategory HeatmapCategory;
3131

3232
extern llvm::cl::opt<unsigned> AlignText;
33+
extern llvm::cl::opt<unsigned> AlignFunctions;
3334
extern llvm::cl::opt<bool> AggregateOnly;
3435
extern llvm::cl::opt<unsigned> BucketsPerLine;
3536
extern llvm::cl::opt<bool> DiffOnly;

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) {
291291
BC.Ctx->addGenDwarfSection(Section);
292292

293293
if (BC.HasRelocations) {
294+
// Set section alignment to at least maximum possible object alignment.
295+
// We need this to support LongJmp and other passes that calculates
296+
// tentative layout.
297+
if (Section->getAlignment() < opts::AlignFunctions)
298+
Section->setAlignment(Align(opts::AlignFunctions));
299+
294300
Streamer.emitCodeAlignment(BinaryFunction::MinAlign, &*BC.STI);
295301
uint16_t MaxAlignBytes = EmitColdPart ? Function.getMaxColdAlignmentBytes()
296302
: Function.getMaxAlignmentBytes();

bolt/lib/Passes/Aligner.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern cl::OptionCategory BoltOptCategory;
2323

2424
extern cl::opt<bool> AlignBlocks;
2525
extern cl::opt<bool> PreserveBlocksAlignment;
26+
extern cl::opt<unsigned> AlignFunctions;
2627

2728
cl::opt<unsigned>
2829
AlignBlocksMinSize("align-blocks-min-size",
@@ -43,13 +44,6 @@ AlignBlocksThreshold("align-blocks-threshold",
4344
cl::Hidden,
4445
cl::cat(BoltOptCategory));
4546

46-
cl::opt<unsigned>
47-
AlignFunctions("align-functions",
48-
cl::desc("align functions at a given value (relocation mode)"),
49-
cl::init(64),
50-
cl::ZeroOrMore,
51-
cl::cat(BoltOptCategory));
52-
5347
cl::opt<unsigned>
5448
AlignFunctionsMaxBytes("align-functions-max-bytes",
5549
cl::desc("maximum number of bytes to use to align functions"),

bolt/lib/Passes/LongJmp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "bolt/Passes/LongJmp.h"
14-
#include "llvm/Support/Alignment.h"
1514

1615
#define DEBUG_TYPE "longjmp"
1716

1817
using namespace llvm;
1918

2019
namespace opts {
2120
extern cl::OptionCategory BoltOptCategory;
22-
21+
extern cl::opt<unsigned> AlignFunctions;
2322
extern cl::opt<bool> UseOldText;
2423
extern cl::opt<bool> HotFunctionsAtEnd;
2524

@@ -295,6 +294,7 @@ void LongJmpPass::tentativeBBLayout(const BinaryFunction &Func) {
295294
uint64_t LongJmpPass::tentativeLayoutRelocColdPart(
296295
const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions,
297296
uint64_t DotAddress) {
297+
DotAddress = alignTo(DotAddress, llvm::Align(opts::AlignFunctions));
298298
for (BinaryFunction *Func : SortedFunctions) {
299299
if (!Func->isSplit())
300300
continue;

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ AlignText("align-text",
4242
cl::Hidden,
4343
cl::cat(BoltCategory));
4444

45+
cl::opt<unsigned> AlignFunctions(
46+
"align-functions",
47+
cl::desc("align functions at a given value (relocation mode)"),
48+
cl::init(64), cl::ZeroOrMore, cl::cat(BoltOptCategory));
49+
4550
cl::opt<bool>
4651
AggregateOnly("aggregate-only",
4752
cl::desc("exit after writing aggregated data file"),

0 commit comments

Comments
 (0)