diff --git a/bolt/include/bolt/Utils/CommandLineOpts.h b/bolt/include/bolt/Utils/CommandLineOpts.h --- a/bolt/include/bolt/Utils/CommandLineOpts.h +++ b/bolt/include/bolt/Utils/CommandLineOpts.h @@ -30,6 +30,7 @@ extern llvm::cl::OptionCategory HeatmapCategory; extern llvm::cl::opt AlignText; +extern llvm::cl::opt AlignFunctions; extern llvm::cl::opt AggregateOnly; extern llvm::cl::opt BucketsPerLine; extern llvm::cl::opt DiffOnly; diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp --- a/bolt/lib/Core/BinaryEmitter.cpp +++ b/bolt/lib/Core/BinaryEmitter.cpp @@ -291,6 +291,12 @@ BC.Ctx->addGenDwarfSection(Section); if (BC.HasRelocations) { + // Set section alignment to the maximum possible object alignment. + // We need this to support LongJmp and other passes that calculates + // tentative layout. + if (Section->getAlignment() == 1) + 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 --- a/bolt/lib/Passes/Aligner.cpp +++ b/bolt/lib/Passes/Aligner.cpp @@ -23,6 +23,7 @@ extern cl::opt AlignBlocks; extern cl::opt PreserveBlocksAlignment; +extern cl::opt AlignFunctions; cl::opt AlignBlocksMinSize("align-blocks-min-size", @@ -43,13 +44,6 @@ cl::Hidden, cl::cat(BoltOptCategory)); -cl::opt -AlignFunctions("align-functions", - cl::desc("align functions at a given value (relocation mode)"), - cl::init(64), - cl::ZeroOrMore, - cl::cat(BoltOptCategory)); - cl::opt AlignFunctionsMaxBytes("align-functions-max-bytes", cl::desc("maximum number of bytes to use to align functions"), diff --git a/bolt/lib/Passes/LongJmp.cpp b/bolt/lib/Passes/LongJmp.cpp --- 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 @@ namespace opts { extern cl::OptionCategory BoltOptCategory; - +extern cl::opt AlignFunctions; extern cl::opt UseOldText; extern cl::opt HotFunctionsAtEnd; @@ -295,6 +294,7 @@ uint64_t LongJmpPass::tentativeLayoutRelocColdPart( const BinaryContext &BC, std::vector &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 --- a/bolt/lib/Utils/CommandLineOpts.cpp +++ b/bolt/lib/Utils/CommandLineOpts.cpp @@ -42,6 +42,11 @@ cl::Hidden, cl::cat(BoltCategory)); +cl::opt AlignFunctions( + "align-functions", + cl::desc("align functions at a given value (relocation mode)"), + cl::init(64), cl::ZeroOrMore, cl::cat(BoltOptCategory)); + cl::opt AggregateOnly("aggregate-only", cl::desc("exit after writing aggregated data file"),