[PATCH] D130034: [BOLT] Add BinaryContext::IsStripped

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 23:11:31 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG986362d4a3fd: [BOLT] Add BinaryContext::IsStripped (authored by nhuhuan, committed by Amir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130034

Files:
  bolt/include/bolt/Core/BinaryContext.h
  bolt/lib/Rewrite/RewriteInstance.cpp
  bolt/test/X86/is-strip.s


Index: bolt/test/X86/is-strip.s
===================================================================
--- /dev/null
+++ bolt/test/X86/is-strip.s
@@ -0,0 +1,10 @@
+# This test checks whether a binary is stripped or not.
+
+# RUN: %clang++ %p/Inputs/linenumber.cpp -o %t -Wl,-q
+# 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
+
+# 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.
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1562,6 +1562,7 @@
                      TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
 
   bool HasTextRelocations = false;
+  bool HasSymbolTable = false;
   bool HasDebugInfo = false;
 
   // Process special sections.
@@ -1593,6 +1594,7 @@
   }
 
   HasTextRelocations = (bool)BC->getUniqueSectionByName(".rela.text");
+  HasSymbolTable = (bool)BC->getUniqueSectionByName(".symtab");
   LSDASection = BC->getUniqueSectionByName(".gcc_except_table");
   EHFrameSection = BC->getUniqueSectionByName(".eh_frame");
   GOTPLTSection = BC->getUniqueSectionByName(".got.plt");
@@ -1629,6 +1631,8 @@
   BC->HasRelocations =
       HasTextRelocations && (opts::RelocationMode != cl::BOU_FALSE);
 
+  BC->IsStripped = !HasSymbolTable;
+
   // Force non-relocation mode for heatmap generation
   if (opts::HeatmapMode)
     BC->HasRelocations = false;
@@ -1637,6 +1641,10 @@
     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)
Index: bolt/include/bolt/Core/BinaryContext.h
===================================================================
--- bolt/include/bolt/Core/BinaryContext.h
+++ bolt/include/bolt/Core/BinaryContext.h
@@ -585,6 +585,9 @@
   /// Indicates if relocations are available for usage.
   bool HasRelocations{false};
 
+  /// Indicates if the binary is stripped
+  bool IsStripped{false};
+
   /// Is the binary always loaded at a fixed address. Shared objects and
   /// position-independent executables (PIEs) are examples of binaries that
   /// will have HasFixedLoadAddress set to false.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130034.448520.patch
Type: text/x-patch
Size: 2800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220729/b24eacbd/attachment.bin>


More information about the llvm-commits mailing list