diff --git a/bolt/docs/BinaryAnalysis.md b/bolt/docs/BinaryAnalysis.md index 9f0f01898051..b13410cd9635 100644 --- a/bolt/docs/BinaryAnalysis.md +++ b/bolt/docs/BinaryAnalysis.md @@ -180,12 +180,6 @@ The following are current known cases of false negatives: [prototype branch]( https://github.com/llvm/llvm-project/compare/main...kbeyls:llvm-project:bolt-gadget-scanner-prototype). -BOLT cannot currently handle functions with `cfi_negate_ra_state` correctly, -i.e. any binaries built with `-mbranch-protection=pac-ret`. The scanner is meant -to be used on specifically such binaries, so this is a major limitation! Work is -going on in PR [#120064](https://github.com/llvm/llvm-project/pull/120064) to -fix this. - ## How to add your own binary analysis _TODO: this section needs to be written. Ideally, we should have a simple diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 4624abadc701..9773e21aa752 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -65,6 +65,8 @@ extern cl::opt StrictMode; extern cl::opt UpdateDebugSections; extern cl::opt Verbosity; +extern bool BinaryAnalysisMode; +extern bool HeatmapMode; extern bool processAllFunctions(); static cl::opt CheckEncoding( @@ -2760,13 +2762,19 @@ private: } case MCCFIInstruction::OpAdjustCfaOffset: case MCCFIInstruction::OpWindowSave: - case MCCFIInstruction::OpNegateRAState: case MCCFIInstruction::OpNegateRAStateWithPC: case MCCFIInstruction::OpLLVMDefAspaceCfa: case MCCFIInstruction::OpLabel: case MCCFIInstruction::OpValOffset: llvm_unreachable("unsupported CFI opcode"); break; + case MCCFIInstruction::OpNegateRAState: + if (!(opts::BinaryAnalysisMode || opts::HeatmapMode)) { + llvm_unreachable("BOLT-ERROR: binaries using pac-ret hardening (e.g. " + "as produced by '-mbranch-protection=pac-ret') are " + "currently not supported by BOLT."); + } + break; case MCCFIInstruction::OpRememberState: case MCCFIInstruction::OpRestoreState: case MCCFIInstruction::OpGnuArgsSize: @@ -2900,13 +2908,19 @@ struct CFISnapshotDiff : public CFISnapshot { return CFAReg == Instr.getRegister() && CFAOffset == Instr.getOffset(); case MCCFIInstruction::OpAdjustCfaOffset: case MCCFIInstruction::OpWindowSave: - case MCCFIInstruction::OpNegateRAState: case MCCFIInstruction::OpNegateRAStateWithPC: case MCCFIInstruction::OpLLVMDefAspaceCfa: case MCCFIInstruction::OpLabel: case MCCFIInstruction::OpValOffset: llvm_unreachable("unsupported CFI opcode"); return false; + case MCCFIInstruction::OpNegateRAState: + if (!(opts::BinaryAnalysisMode || opts::HeatmapMode)) { + llvm_unreachable("BOLT-ERROR: binaries using pac-ret hardening (e.g. " + "as produced by '-mbranch-protection=pac-ret') are " + "currently not supported by BOLT."); + } + break; case MCCFIInstruction::OpRememberState: case MCCFIInstruction::OpRestoreState: case MCCFIInstruction::OpGnuArgsSize: @@ -3051,13 +3065,19 @@ BinaryFunction::unwindCFIState(int32_t FromState, int32_t ToState, break; case MCCFIInstruction::OpAdjustCfaOffset: case MCCFIInstruction::OpWindowSave: - case MCCFIInstruction::OpNegateRAState: case MCCFIInstruction::OpNegateRAStateWithPC: case MCCFIInstruction::OpLLVMDefAspaceCfa: case MCCFIInstruction::OpLabel: case MCCFIInstruction::OpValOffset: llvm_unreachable("unsupported CFI opcode"); break; + case MCCFIInstruction::OpNegateRAState: + if (!(opts::BinaryAnalysisMode || opts::HeatmapMode)) { + llvm_unreachable("BOLT-ERROR: binaries using pac-ret hardening (e.g. " + "as produced by '-mbranch-protection=pac-ret') are " + "currently not supported by BOLT."); + } + break; case MCCFIInstruction::OpGnuArgsSize: // do not affect CFI state break;