Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions bolt/docs/BinaryAnalysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ extern cl::opt<bool> StrictMode;
extern cl::opt<bool> UpdateDebugSections;
extern cl::opt<unsigned> Verbosity;

extern bool BinaryAnalysisMode;
extern bool HeatmapMode;
extern bool processAllFunctions();

static cl::opt<bool> CheckEncoding(
Expand Down Expand Up @@ -2760,13 +2762,19 @@ struct CFISnapshot {
}
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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
Loading