[PATCH] D142686: [BOLT] Reintroduce allow-stripped

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 26 21:17:03 PST 2023


Amir created this revision.
Amir added a reviewer: maksfb.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

Reject stripped binaries as a policy.

The core issue with stripped binaries is that we can't detect the presence
of split functions which require extra handling. Therefore BOLT can't ensure
functional correctness of produced binary if the input stripped binary contains
split functions. Supporting such cases is an interesting problem but it goes
against BOLT's intended goal of achieving peak program performance.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142686

Files:
  bolt/lib/Rewrite/RewriteInstance.cpp
  bolt/test/X86/broken_dynsym.test
  bolt/test/X86/is-strip.s


Index: bolt/test/X86/is-strip.s
===================================================================
--- bolt/test/X86/is-strip.s
+++ bolt/test/X86/is-strip.s
@@ -4,7 +4,8 @@
 # RUN: llvm-bolt %t -o %t.out 2>&1 | FileCheck %s -check-prefix=CHECK-NOSTRIP
 # RUN: cp %t %t.stripped
 # RUN: llvm-strip -s %t.stripped
-# RUN: llvm-bolt %t.stripped -o %t.out 2>&1 | FileCheck %s -check-prefix=CHECK-STRIP
+# RUN: not llvm-bolt %t.stripped -o %t.out 2>&1 | FileCheck %s -check-prefix=CHECK-STRIP
+# RUN: llvm-bolt %t.stripped -o %t.out -allow-stripped 2>&1 | FileCheck %s -check-prefix=CHECK-NOSTRIP
 
-# CHECK-NOSTRIP-NOT: BOLT-INFO: input binary is stripped. The support is limited and is considered experimental.
-# CHECK-STRIP: BOLT-INFO: input binary is stripped. The support is limited and is considered experimental.
+# CHECK-NOSTRIP-NOT: BOLT-INFO: stripped binaries are not supported.
+# CHECK-STRIP: BOLT-INFO: stripped binaries are not supported.
Index: bolt/test/X86/broken_dynsym.test
===================================================================
--- bolt/test/X86/broken_dynsym.test
+++ bolt/test/X86/broken_dynsym.test
@@ -3,6 +3,6 @@
 
 # RUN: yaml2obj %p/Inputs/broken_dynsym.yaml -o %t
 # RUN: llvm-strip -s %t
-# RUN: llvm-bolt %t -o %t.bolt | FileCheck %s
+# RUN: llvm-bolt %t -o %t.bolt -allow-stripped | FileCheck %s
 
 # CHECK-NOT: section index out of bounds 
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -82,6 +82,10 @@
 extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
 extern cl::opt<bool> TimeBuild;
 
+cl::opt<bool> AllowStripped("allow-stripped",
+                            cl::desc("allow processing of stripped binaries"),
+                            cl::Hidden, cl::cat(BoltCategory));
+
 static cl::opt<bool> ForceToDataRelocations(
     "force-data-relocations",
     cl::desc("force relocations to data sections to always be processed"),
@@ -1656,6 +1660,12 @@
 
   BC->IsStripped = !HasSymbolTable;
 
+  if (BC->IsStripped && !opts::AllowStripped) {
+    outs() << "BOLT-INFO: stripped binaries are not supported. If you know "
+              "what you're doing, use -allow-stripped to proceed.";
+    exit(1);
+  }
+
   // Force non-relocation mode for heatmap generation
   if (opts::HeatmapMode)
     BC->HasRelocations = false;
@@ -1664,10 +1674,6 @@
     outs() << "BOLT-INFO: enabling " << (opts::StrictMode ? "strict " : "")
            << "relocation mode\n";
 
-  if (BC->IsStripped)
-    outs() << "BOLT-INFO: input binary is stripped. The support is limited and "
-           << "is considered experimental.\n";
-
   // Read EH frame for function boundaries info.
   Expected<const DWARFDebugFrame *> EHFrameOrError = BC->DwCtx->getEHFrame();
   if (!EHFrameOrError)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142686.492641.patch
Type: text/x-patch
Size: 2890 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230127/4c85578b/attachment.bin>


More information about the llvm-commits mailing list