From: Vladislav Khmelevsky Date: Tue, 15 Mar 2022 19:17:51 +0000 (+0300) Subject: [BOLT] LongJmp: Fix hot text section alignment X-Git-Tag: upstream/15.0.7~13462 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=62a289d85c9fc8d7c0141e63477474c03a17e1b4;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/bolt/lib/Passes/LongJmp.cpp b/bolt/lib/Passes/LongJmp.cpp index d576bf1..fbbe054 100644 --- a/bolt/lib/Passes/LongJmp.cpp +++ b/bolt/lib/Passes/LongJmp.cpp @@ -18,6 +18,7 @@ using namespace llvm; namespace opts { extern cl::OptionCategory BoltOptCategory; +extern llvm::cl::opt AlignText; extern cl::opt AlignFunctions; extern cl::opt UseOldText; extern cl::opt HotFunctionsAtEnd; @@ -342,7 +343,7 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode( tentativeLayoutRelocColdPart(BC, SortedFunctions, DotAddress); ColdLayoutDone = true; if (opts::HotFunctionsAtEnd) - DotAddress = alignTo(DotAddress, BC.PageAlign); + DotAddress = alignTo(DotAddress, opts::AlignText); } DotAddress = alignTo(DotAddress, BinaryFunction::MinAlign); @@ -390,11 +391,11 @@ void LongJmpPass::tentativeLayout( // Initial padding if (opts::UseOldText && EstimatedTextSize <= BC.OldTextSectionSize) { DotAddress = BC.OldTextSectionAddress; - uint64_t Pad = offsetToAlignment(DotAddress, llvm::Align(BC.PageAlign)); + uint64_t Pad = offsetToAlignment(DotAddress, llvm::Align(opts::AlignText)); if (Pad + EstimatedTextSize <= BC.OldTextSectionSize) DotAddress += Pad; } else { - DotAddress = alignTo(BC.LayoutStartAddress, BC.PageAlign); + DotAddress = alignTo(BC.LayoutStartAddress, opts::AlignText); } tentativeLayoutRelocMode(BC, SortedFunctions, DotAddress); diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index b814862..8c8c55b 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -1743,6 +1743,9 @@ void RewriteInstance::adjustCommandLineOptions() { if (!opts::AlignText.getNumOccurrences()) opts::AlignText = BC->PageAlign; + if (opts::AlignText < opts::AlignFunctions) + opts::AlignText = (unsigned)opts::AlignFunctions; + if (BC->isX86() && opts::Lite.getNumOccurrences() == 0 && !opts::StrictMode && !opts::UseOldText) opts::Lite = true;