From c8482da779a9cd5fa34c094639942ab4eb515cc1 Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Mon, 6 Feb 2023 18:06:54 -0800 Subject: [PATCH] [BOLT] Reintroduce allow-stripped 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. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D142686 --- bolt/lib/Rewrite/RewriteInstance.cpp | 14 ++++++++++---- bolt/test/X86/broken_dynsym.test | 2 +- bolt/test/X86/is-strip.s | 7 ++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index b7d9593..aad0f83 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -82,6 +82,10 @@ extern cl::list ReorderData; 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 @@ Error RewriteInstance::readSpecialSections() { 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 @@ Error RewriteInstance::readSpecialSections() { 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 index c715be8..9e7ed40 100644 --- 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 index aaffb00..9d10845 100644 --- 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. -- 2.7.4