diff options
author | Vladislav Khmelevsky <och95@yandex.ru> | 2022-03-10 21:38:55 +0300 |
---|---|---|
committer | Vladislav Khmelevsky <och95@yandex.ru> | 2022-03-15 22:12:17 +0300 |
commit | 8ab69baad51a3f50800cb2eea9985fe5f2702438 (patch) | |
tree | c1dee5c5286840a83b8f88f88fc4c7ff33bfe055 /bolt | |
parent | 78406ac8985bcefcf38d00c6fd112067cc773d96 (diff) |
[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
Diffstat (limited to 'bolt')
-rw-r--r-- | bolt/include/bolt/Utils/CommandLineOpts.h | 1 | ||||
-rw-r--r-- | bolt/lib/Core/BinaryEmitter.cpp | 6 | ||||
-rw-r--r-- | bolt/lib/Passes/Aligner.cpp | 8 | ||||
-rw-r--r-- | bolt/lib/Passes/LongJmp.cpp | 4 | ||||
-rw-r--r-- | bolt/lib/Utils/CommandLineOpts.cpp | 5 |
5 files changed, 15 insertions, 9 deletions
diff --git a/bolt/include/bolt/Utils/CommandLineOpts.h b/bolt/include/bolt/Utils/CommandLineOpts.h index f0ce7f52ac04..08321168f0e0 100644 --- a/bolt/include/bolt/Utils/CommandLineOpts.h +++ b/bolt/include/bolt/Utils/CommandLineOpts.h @@ -30,6 +30,7 @@ extern llvm::cl::OptionCategory BoltInstrCategory; extern llvm::cl::OptionCategory HeatmapCategory; extern llvm::cl::opt<unsigned> AlignText; +extern llvm::cl::opt<unsigned> AlignFunctions; extern llvm::cl::opt<bool> AggregateOnly; extern llvm::cl::opt<unsigned> BucketsPerLine; extern llvm::cl::opt<bool> DiffOnly; diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp index 4f9af59adc84..b672a801a360 100644 --- a/bolt/lib/Core/BinaryEmitter.cpp +++ b/bolt/lib/Core/BinaryEmitter.cpp @@ -291,6 +291,12 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) { BC.Ctx->addGenDwarfSection(Section); if (BC.HasRelocations) { + // Set section alignment to at least maximum possible object alignment. + // We need this to support LongJmp and other passes that calculates + // tentative layout. + if (Section->getAlignment() < opts::AlignFunctions) + Section->setAlignment(Align(opts::AlignFunctions)); + Streamer.emitCodeAlignment(BinaryFunction::MinAlign, &*BC.STI); uint16_t MaxAlignBytes = EmitColdPart ? Function.getMaxColdAlignmentBytes() : Function.getMaxAlignmentBytes(); diff --git a/bolt/lib/Passes/Aligner.cpp b/bolt/lib/Passes/Aligner.cpp index b1fd7fc3231a..cae0570a2922 100644 --- a/bolt/lib/Passes/Aligner.cpp +++ b/bolt/lib/Passes/Aligner.cpp @@ -23,6 +23,7 @@ extern cl::OptionCategory BoltOptCategory; extern cl::opt<bool> AlignBlocks; extern cl::opt<bool> PreserveBlocksAlignment; +extern cl::opt<unsigned> AlignFunctions; cl::opt<unsigned> AlignBlocksMinSize("align-blocks-min-size", @@ -44,13 +45,6 @@ AlignBlocksThreshold("align-blocks-threshold", cl::cat(BoltOptCategory)); cl::opt<unsigned> -AlignFunctions("align-functions", - cl::desc("align functions at a given value (relocation mode)"), - cl::init(64), - cl::ZeroOrMore, - cl::cat(BoltOptCategory)); - -cl::opt<unsigned> AlignFunctionsMaxBytes("align-functions-max-bytes", cl::desc("maximum number of bytes to use to align functions"), cl::init(32), diff --git a/bolt/lib/Passes/LongJmp.cpp b/bolt/lib/Passes/LongJmp.cpp index 9816e5d83197..d576bf185621 100644 --- a/bolt/lib/Passes/LongJmp.cpp +++ b/bolt/lib/Passes/LongJmp.cpp @@ -11,7 +11,6 @@ //===----------------------------------------------------------------------===// #include "bolt/Passes/LongJmp.h" -#include "llvm/Support/Alignment.h" #define DEBUG_TYPE "longjmp" @@ -19,7 +18,7 @@ using namespace llvm; namespace opts { extern cl::OptionCategory BoltOptCategory; - +extern cl::opt<unsigned> AlignFunctions; extern cl::opt<bool> UseOldText; extern cl::opt<bool> HotFunctionsAtEnd; @@ -295,6 +294,7 @@ void LongJmpPass::tentativeBBLayout(const BinaryFunction &Func) { uint64_t LongJmpPass::tentativeLayoutRelocColdPart( const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions, uint64_t DotAddress) { + DotAddress = alignTo(DotAddress, llvm::Align(opts::AlignFunctions)); for (BinaryFunction *Func : SortedFunctions) { if (!Func->isSplit()) continue; diff --git a/bolt/lib/Utils/CommandLineOpts.cpp b/bolt/lib/Utils/CommandLineOpts.cpp index e0567465644b..9ea20ac0c354 100644 --- a/bolt/lib/Utils/CommandLineOpts.cpp +++ b/bolt/lib/Utils/CommandLineOpts.cpp @@ -42,6 +42,11 @@ AlignText("align-text", cl::Hidden, cl::cat(BoltCategory)); +cl::opt<unsigned> AlignFunctions( + "align-functions", + cl::desc("align functions at a given value (relocation mode)"), + cl::init(64), cl::ZeroOrMore, cl::cat(BoltOptCategory)); + cl::opt<bool> AggregateOnly("aggregate-only", cl::desc("exit after writing aggregated data file"), |