From fd9604952d80d62bc3db57fff07c047bb6773903 Mon Sep 17 00:00:00 2001 From: Vladislav Khmelevsky Date: Tue, 7 Jun 2022 18:40:04 +0300 Subject: [PATCH] [BOLT] Set valid index for functions with profiles Some of the passes that calculates tentative layout like LongJmp and Golang are expecting that only functions with valid index will be located in hot text section. But currently functions with valid profiles and not set index are breaking this logic, to fix this we can move the hasValidProfile() condition from AssignSections pass to ReorderFunctions. Vladislav Khmelevsky, Advanced Software Technology Lab, Huawei Differential Revision: https://reviews.llvm.org/D127223 --- bolt/lib/Passes/BinaryPasses.cpp | 3 +-- bolt/lib/Passes/ReorderFunctions.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp index b2b4ce50596b..ad32293830bd 100644 --- a/bolt/lib/Passes/BinaryPasses.cpp +++ b/bolt/lib/Passes/BinaryPasses.cpp @@ -1211,8 +1211,7 @@ void AssignSections::runOnFunctions(BinaryContext &BC) { continue; } - if (!UseColdSection || Function.hasValidIndex() || - Function.hasValidProfile()) + if (!UseColdSection || Function.hasValidIndex()) Function.setCodeSectionName(BC.getMainCodeSectionName()); else Function.setCodeSectionName(BC.getColdCodeSectionName()); diff --git a/bolt/lib/Passes/ReorderFunctions.cpp b/bolt/lib/Passes/ReorderFunctions.cpp index b6eb147514f0..6b7f80960fae 100644 --- a/bolt/lib/Passes/ReorderFunctions.cpp +++ b/bolt/lib/Passes/ReorderFunctions.cpp @@ -128,6 +128,13 @@ void ReorderFunctions::reorder(std::vector &&Clusters, } } + // Assign valid index for functions with valid profile. + for (auto &It : BFs) { + BinaryFunction &BF = It.second; + if (!BF.hasValidIndex() && BF.hasValidProfile()) + BF.setIndex(Index++); + } + if (opts::ReorderFunctions == RT_NONE) return;