Skip to content

Commit 986362d

Browse files
nhuhuanaaupov
authored andcommitted
[BOLT] Add BinaryContext::IsStripped
Determine stripped status of a binary based on .symtab Test Plan: ``` ninja check-bolt ``` Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D130034
1 parent dc2557f commit 986362d

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ class BinaryContext {
585585
/// Indicates if relocations are available for usage.
586586
bool HasRelocations{false};
587587

588+
/// Indicates if the binary is stripped
589+
bool IsStripped{false};
590+
588591
/// Is the binary always loaded at a fixed address. Shared objects and
589592
/// position-independent executables (PIEs) are examples of binaries that
590593
/// will have HasFixedLoadAddress set to false.

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ Error RewriteInstance::readSpecialSections() {
15621562
TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
15631563

15641564
bool HasTextRelocations = false;
1565+
bool HasSymbolTable = false;
15651566
bool HasDebugInfo = false;
15661567

15671568
// Process special sections.
@@ -1593,6 +1594,7 @@ Error RewriteInstance::readSpecialSections() {
15931594
}
15941595

15951596
HasTextRelocations = (bool)BC->getUniqueSectionByName(".rela.text");
1597+
HasSymbolTable = (bool)BC->getUniqueSectionByName(".symtab");
15961598
LSDASection = BC->getUniqueSectionByName(".gcc_except_table");
15971599
EHFrameSection = BC->getUniqueSectionByName(".eh_frame");
15981600
GOTPLTSection = BC->getUniqueSectionByName(".got.plt");
@@ -1629,6 +1631,8 @@ Error RewriteInstance::readSpecialSections() {
16291631
BC->HasRelocations =
16301632
HasTextRelocations && (opts::RelocationMode != cl::BOU_FALSE);
16311633

1634+
BC->IsStripped = !HasSymbolTable;
1635+
16321636
// Force non-relocation mode for heatmap generation
16331637
if (opts::HeatmapMode)
16341638
BC->HasRelocations = false;
@@ -1637,6 +1641,10 @@ Error RewriteInstance::readSpecialSections() {
16371641
outs() << "BOLT-INFO: enabling " << (opts::StrictMode ? "strict " : "")
16381642
<< "relocation mode\n";
16391643

1644+
if (BC->IsStripped)
1645+
outs() << "BOLT-INFO: input binary is stripped. The support is limited and "
1646+
<< "is considered experimental.\n";
1647+
16401648
// Read EH frame for function boundaries info.
16411649
Expected<const DWARFDebugFrame *> EHFrameOrError = BC->DwCtx->getEHFrame();
16421650
if (!EHFrameOrError)

bolt/test/X86/is-strip.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This test checks whether a binary is stripped or not.
2+
3+
# RUN: %clang++ %p/Inputs/linenumber.cpp -o %t -Wl,-q
4+
# RUN: llvm-bolt %t -o %t.out 2>&1 | FileCheck %s -check-prefix=CHECK-NOSTRIP
5+
# RUN: cp %t %t.stripped
6+
# RUN: llvm-strip -s %t.stripped
7+
# RUN: llvm-bolt %t.stripped -o %t.out 2>&1 | FileCheck %s -check-prefix=CHECK-STRIP
8+
9+
# CHECK-NOSTRIP-NOT: BOLT-INFO: input binary is stripped. The support is limited and is considered experimental.
10+
# CHECK-STRIP: BOLT-INFO: input binary is stripped. The support is limited and is considered experimental.

0 commit comments

Comments
 (0)