[PATCH] D130071: [BOLT] Adapted policy checks for stripped binaries

Huan Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 21:10:30 PDT 2022


nhuhuan updated this revision to Diff 448507.
nhuhuan added a comment.

Clarify that it will not affect the correctness in processing nonstripped
binaries.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130071

Files:
  bolt/lib/Core/BinaryContext.cpp
  bolt/lib/Core/BinaryFunction.cpp


Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -1602,10 +1602,10 @@
     if (!getSecondaryEntryPointSymbol(Label))
       continue;
 
-    // In non-relocation mode there's potentially an external undetectable
-    // reference to the entry point and hence we cannot move this entry
-    // point. Optimizing without moving could be difficult.
-    if (!BC.HasRelocations)
+    // Stripped binaries mostly don't have .rela.text section
+    // Without .rela.text, BOLT cannot reliably move code
+    // Relaxing for stripped binaries only, not affect nonstripped binaries
+    if (!BC.IsStripped && !BC.HasRelocations)
       setSimple(false);
 
     const uint32_t Offset = KV.first;
Index: bolt/lib/Core/BinaryContext.cpp
===================================================================
--- bolt/lib/Core/BinaryContext.cpp
+++ bolt/lib/Core/BinaryContext.cpp
@@ -1119,14 +1119,19 @@
 
 bool BinaryContext::registerFragment(BinaryFunction &TargetFunction,
                                      BinaryFunction &Function) const {
-  if (!isPotentialFragmentByName(TargetFunction, Function))
+  // Only use symbol name matching for non-stripped binaries
+  if (!IsStripped && !isPotentialFragmentByName(TargetFunction, Function))
     return false;
   assert(TargetFunction.isFragment() && "TargetFunction must be a fragment");
   if (TargetFunction.isParentFragment(&Function))
     return true;
   TargetFunction.addParentFragment(Function);
   Function.addFragment(TargetFunction);
-  if (!HasRelocations) {
+
+  // Stripped binaries mostly don't have .rela.text section
+  // Without .rela.text, BOLT cannot reliably move code
+  // Relaxing for stripped binaries only, not affect nonstripped binaries
+  if (!IsStripped && !HasRelocations) {
     TargetFunction.setSimple(false);
     Function.setSimple(false);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130071.448507.patch
Type: text/x-patch
Size: 1961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220729/5a799bc3/attachment.bin>


More information about the llvm-commits mailing list