diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h --- a/bolt/include/bolt/Core/BinaryContext.h +++ b/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. diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -1557,6 +1557,7 @@ TimerGroupName, TimerGroupDesc, opts::TimeRewrite); bool HasTextRelocations = false; + bool HasSymbolTable = false; bool HasDebugInfo = false; // Process special sections. @@ -1588,6 +1589,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"); @@ -1624,6 +1626,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; @@ -1632,6 +1636,9 @@ outs() << "BOLT-INFO: enabling " << (opts::StrictMode ? "strict " : "") << "relocation mode\n"; + if (BC->IsStripped) + outs() << "BOLT-INFO: target binary is stripped!\n"; + // Read EH frame for function boundaries info. Expected EHFrameOrError = BC->DwCtx->getEHFrame(); if (!EHFrameOrError) diff --git a/bolt/test/X86/Inputs/gcd.cpp b/bolt/test/X86/Inputs/gcd.cpp new file mode 100644 --- /dev/null +++ b/bolt/test/X86/Inputs/gcd.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +int main() { + int X, Y, Result; + cout << "Enter two numbers: "; + cin >> X >> Y; + + // swapping variables n1 and n2 if n2 is greater than n1. + if (Y > X) { + int Temp = Y; + Y = X; + X = Temp; + } + + for (int I = 1; I <= Y; ++I) { + if (X % I == 0 && Y % I == 0) { + Result = I; + } + } + + cout << "Greatest common divisor = " << Result << "\n"; + + return 0; +} diff --git a/bolt/test/X86/is-strip.s b/bolt/test/X86/is-strip.s new file mode 100644 --- /dev/null +++ b/bolt/test/X86/is-strip.s @@ -0,0 +1,13 @@ +# This reproduces a bug with jump table identification where jump table has +# entries pointing to code in function and its cold fragment. + +# REQUIRES: system-linux + +# RUN: %clang++ %p/Inputs/gcd.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: target binary is stripped! +# CHECK-STRIP: BOLT-INFO: target binary is stripped!