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 @@ -82,6 +82,10 @@ extern cl::opt ReorderFunctions; extern cl::opt TimeBuild; +cl::opt AllowStripped("allow-stripped", + cl::desc("allow processing of stripped binaries"), + cl::Hidden, cl::cat(BoltCategory)); + static cl::opt ForceToDataRelocations( "force-data-relocations", cl::desc("force relocations to data sections to always be processed"), @@ -1662,6 +1666,12 @@ BC->IsStripped = !HasSymbolTable; + if (BC->IsStripped && !opts::AllowStripped) { + errs() << "BOLT-ERROR: 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; @@ -1670,10 +1680,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 EHFrameOrError = BC->DwCtx->getEHFrame(); if (!EHFrameOrError) diff --git a/bolt/test/X86/broken_dynsym.test b/bolt/test/X86/broken_dynsym.test --- a/bolt/test/X86/broken_dynsym.test +++ b/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 diff --git a/bolt/test/X86/is-strip.s b/bolt/test/X86/is-strip.s --- a/bolt/test/X86/is-strip.s +++ b/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-ERROR: stripped binaries are not supported. +# CHECK-STRIP: BOLT-ERROR: stripped binaries are not supported.