diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -3906,6 +3906,21 @@ CodeSections.emplace_back(&Section); auto compareSections = [&](const BinarySection *A, const BinarySection *B) { + + // If both A and B have names starting with ".text.cold", then + // - if opts::HotFunctionsAtEnd is true, we want order + // ".text.cold.T", ".text.cold.T-1", ... ".text.cold.1", ".text.cold" + // - if opts::HotFunctionsAtEnd is false, we want order + // ".text.cold", ".text.cold.1", ... ".text.cold.T-1", ".text.cold.T" + if (A->getName().startswith(BC->getColdCodeSectionName()) && + B->getName().startswith(BC->getColdCodeSectionName())) + if (A->getName().size() != B->getName().size()) + return (opts::HotFunctionsAtEnd) + ? (A->getName().size() > B->getName().size()) + : (A->getName().size() < B->getName().size()); + return (opts::HotFunctionsAtEnd) ? (A->getName() > B->getName()) + : (A->getName() < B->getName()); + // Place movers before anything else. if (A->getName() == BC->getHotTextMoverSectionName()) return true; @@ -3921,6 +3936,9 @@ // Determine the order of sections. llvm::stable_sort(CodeSections, compareSections); + for (BinarySection *Section : CodeSections) { + outs() << "Shatian DDebug: " << Section->getName() << '\n'; + } return CodeSections; }