[PATCH] D121392: [BOLT] Set cold sections alignment explicitly

Vladislav Khmelevsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 11 12:26:20 PST 2022


yota9 updated this revision to Diff 414731.
yota9 added a comment.

nit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121392/new/

https://reviews.llvm.org/D121392

Files:
  bolt/include/bolt/Utils/CommandLineOpts.h
  bolt/lib/Core/BinaryEmitter.cpp
  bolt/lib/Passes/Aligner.cpp
  bolt/lib/Passes/LongJmp.cpp
  bolt/lib/Utils/CommandLineOpts.cpp


Index: bolt/lib/Utils/CommandLineOpts.cpp
===================================================================
--- bolt/lib/Utils/CommandLineOpts.cpp
+++ bolt/lib/Utils/CommandLineOpts.cpp
@@ -42,6 +42,11 @@
   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"),
Index: bolt/lib/Passes/LongJmp.cpp
===================================================================
--- bolt/lib/Passes/LongJmp.cpp
+++ 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<unsigned> AlignFunctions;
 extern cl::opt<bool> UseOldText;
 extern cl::opt<bool> HotFunctionsAtEnd;
 
@@ -295,6 +294,7 @@
 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;
Index: bolt/lib/Passes/Aligner.cpp
===================================================================
--- bolt/lib/Passes/Aligner.cpp
+++ bolt/lib/Passes/Aligner.cpp
@@ -23,6 +23,7 @@
 
 extern cl::opt<bool> AlignBlocks;
 extern cl::opt<bool> PreserveBlocksAlignment;
+extern cl::opt<unsigned> AlignFunctions;
 
 cl::opt<unsigned>
 AlignBlocksMinSize("align-blocks-min-size",
@@ -43,13 +44,6 @@
   cl::Hidden,
   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"),
Index: bolt/lib/Core/BinaryEmitter.cpp
===================================================================
--- bolt/lib/Core/BinaryEmitter.cpp
+++ bolt/lib/Core/BinaryEmitter.cpp
@@ -291,6 +291,12 @@
   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();
Index: bolt/include/bolt/Utils/CommandLineOpts.h
===================================================================
--- bolt/include/bolt/Utils/CommandLineOpts.h
+++ bolt/include/bolt/Utils/CommandLineOpts.h
@@ -30,6 +30,7 @@
 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121392.414731.patch
Type: text/x-patch
Size: 3530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220311/1de97adb/attachment.bin>


More information about the llvm-commits mailing list