From 153eeb4a5e68c6054a220667646b14f3785a942e Mon Sep 17 00:00:00 2001 From: Huan Nguyen Date: Wed, 28 Sep 2022 19:25:52 +0200 Subject: [PATCH] [BOLT] Disable -lite when split function is present In lite mode, BOLT only transforms a subset of functions, leave the remaining functions intact. For NoPIC, it is fine. BOLT can scan relocations and fix-up all refs that point to any function body in the subset. For no-split function PIC, it is fine. Since jump tables are intra- procedural transfer, BOLT can find both the jump table base and the target within same function. Thus, BOLT can update and/or move jump tables. However, it is wrong to process a subset of functions in split function PIC. This is because BOLT does not know if functions in the subset are isolated, i.e., cannot be accessed by functions out of the subset, especially via split jump table. For example, BOLT only process three functions A, B and C. Suppose that A is reached via jump table from A.cold, which is not processed. When A is moved (due to optimization), the jump table in A.cold is invalid. We cannot fix-up this jump table since it is only recognized in A.cold, which BOLT does not process. Solution: Disable lite mode if split function is present. Future improvement: In lite mode, if split function is found, BOLT processes both functions in the subset and all of their sibling fragments. Test Plan: ``` ninja check-bolt ``` Reviewed By: Amir, maksfb Differential Revision: https://reviews.llvm.org/D131283 --- bolt/lib/Rewrite/RewriteInstance.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index 434bea0d843d..9d658214942a 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -1429,10 +1429,17 @@ void RewriteInstance::adjustFunctionBoundaries() { Function.hasRestoredNameRegex(".*\\.cold(\\.[0-9]+)?"); if (FragName) { static bool PrintedWarning = false; - if (BC->HasRelocations && !PrintedWarning) { - errs() << "BOLT-WARNING: split function detected on input : " - << *FragName << ". The support is limited in relocation mode.\n"; + if (!PrintedWarning) { PrintedWarning = true; + errs() << "BOLT-WARNING: split function detected on input : " + << *FragName; + if (BC->HasRelocations) + errs() << ". The support is limited in relocation mode"; + if (opts::Lite) { + opts::Lite = false; + errs() << "\nBOLT-WARNING: disabling lite mode (-lite) when split " + << "functions are present\n"; + } } Function.IsFragment = true; }