Skip to content

Commit 3fb8a1e

Browse files
committed
[BOLT] Review nits (NFC)
1 parent 543dde8 commit 3fb8a1e

File tree

7 files changed

+33
-47
lines changed

7 files changed

+33
-47
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ template <typename R> static bool emptyRange(const R &Range) {
179179
return Range.begin() == Range.end();
180180
}
181181

182+
static void checkFlagsForPacRet() {
183+
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode || opts::AllowPacret)) {
184+
llvm_unreachable(
185+
"BOLT-ERROR: support for binaries using pac-ret hardening (e.g. as "
186+
"produced by '-mbranch-protection=pac-ret') is experimental\n"
187+
"BOLT-ERROR: set --allow-experimental-pacret to allow processing");
188+
}
189+
}
190+
182191
/// Gets debug line information for the instruction located at the given
183192
/// address in the original binary. The SMLoc's pointer is used
184193
/// to point to this information, which is represented by a
@@ -2786,13 +2795,7 @@ struct CFISnapshot {
27862795
llvm_unreachable("unsupported CFI opcode");
27872796
break;
27882797
case MCCFIInstruction::OpNegateRAState:
2789-
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode ||
2790-
opts::AllowPacret)) {
2791-
llvm_unreachable(
2792-
"BOLT-ERROR: support for binaries using pac-ret hardening (e.g. as "
2793-
"produced by '-mbranch-protection=pac-ret') is experimental\n"
2794-
"BOLT-ERROR: set --allow-experimental-pacret to allow processing");
2795-
}
2798+
checkFlagsForPacRet();
27962799
break;
27972800
case MCCFIInstruction::OpRememberState:
27982801
case MCCFIInstruction::OpRestoreState:
@@ -2934,13 +2937,7 @@ struct CFISnapshotDiff : public CFISnapshot {
29342937
llvm_unreachable("unsupported CFI opcode");
29352938
return false;
29362939
case MCCFIInstruction::OpNegateRAState:
2937-
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode ||
2938-
opts::AllowPacret)) {
2939-
llvm_unreachable(
2940-
"BOLT-ERROR: support for binaries using pac-ret hardening (e.g. as "
2941-
"produced by '-mbranch-protection=pac-ret') is experimental\n"
2942-
"BOLT-ERROR: set --allow-experimental-pacret to allow processing");
2943-
}
2940+
checkFlagsForPacRet();
29442941
break;
29452942
case MCCFIInstruction::OpRememberState:
29462943
case MCCFIInstruction::OpRestoreState:
@@ -3093,13 +3090,7 @@ BinaryFunction::unwindCFIState(int32_t FromState, int32_t ToState,
30933090
llvm_unreachable("unsupported CFI opcode");
30943091
break;
30953092
case MCCFIInstruction::OpNegateRAState:
3096-
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode ||
3097-
opts::AllowPacret)) {
3098-
llvm_unreachable(
3099-
"BOLT-ERROR: support for binaries using pac-ret hardening (e.g. as "
3100-
"produced by '-mbranch-protection=pac-ret') is experimental\n"
3101-
"BOLT-ERROR: set --allow-experimental-pacret to allow processing");
3102-
}
3093+
checkFlagsForPacRet();
31033094
break;
31043095
case MCCFIInstruction::OpGnuArgsSize:
31053096
// do not affect CFI state

bolt/lib/Rewrite/BinaryPassManager.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,6 @@ static cl::opt<bool> ShortenInstructions("shorten-instructions",
275275
cl::desc("shorten instructions"),
276276
cl::init(true),
277277
cl::cat(BoltOptCategory));
278-
279-
cl::opt<bool> AllowPacret(
280-
"allow-experimental-pacret",
281-
cl::desc("Enable processing binaries with pac-ret (experimental)"),
282-
cl::cat(BoltOptCategory));
283278
} // namespace opts
284279

285280
namespace llvm {

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,12 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
283283

284284
bool isPSignOnLR(const MCInst &Inst) const override {
285285
ErrorOr<MCPhysReg> SignReg = getSignedReg(Inst);
286-
if (SignReg && *SignReg != getNoRegister() && *SignReg == AArch64::LR)
287-
return true;
288-
289-
return false;
286+
return SignReg && *SignReg != getNoRegister() && *SignReg == AArch64::LR;
290287
}
291288

292289
bool isPAuthOnLR(const MCInst &Inst) const override {
293290
ErrorOr<MCPhysReg> AutReg = getAuthenticatedReg(Inst);
294-
if (AutReg && *AutReg != getNoRegister() && *AutReg == AArch64::LR)
295-
return true;
296-
return false;
291+
return AutReg && *AutReg != getNoRegister() && *AutReg == AArch64::LR;
297292
}
298293

299294
bool isPAuthAndRet(const MCInst &Inst) const override {

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ cl::opt<unsigned>
228228
cl::init(0), cl::ZeroOrMore, cl::cat(BoltCategory),
229229
cl::sub(cl::SubCommand::getAll()));
230230

231+
cl::opt<bool> AllowPacret(
232+
"allow-experimental-pacret",
233+
cl::desc("Enable processing binaries with pac-ret (experimental)"),
234+
cl::init(false), cl::cat(BoltOptCategory));
235+
231236
bool processAllFunctions() {
232237
if (opts::AggregateOnly)
233238
return false;

bolt/test/AArch64/negate-ra-state-incorrect.s

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
22
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
33
# RUN: llvm-bolt %t.exe -o %t.exe.bolt | FileCheck %s
4+
45
# check that the output is listing foo as incorrect
56
# CHECK: BOLT-INFO: inconsistent RAStates in function foo
67

@@ -9,10 +10,10 @@
910
# RUN: not grep "<foo>:" %t.exe.dump
1011

1112

12-
# Why is this test incorrect?
13-
# There is an extra .cfi_negate_ra_state in line ...
14-
# Because of this, we will get to the autiasp (hint #29)
15-
# in a (seemingly) unsigned state. That is incorrect.
13+
# How is this test incorrect?
14+
# There is an extra .cfi_negate_ra_state in foo.
15+
# Because of this, we will get to the autiasp (hint #29)
16+
# in a (seemingly) unsigned state. That is incorrect.
1617
.text
1718
.globl foo
1819
.p2align 2

bolt/test/AArch64/negate-ra-state.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
33

44
# RUN: llvm-objdump %t.exe -d > %t.exe.dump
5-
# RUN: llvm-objdump --dwarf=frames %t.exe -D > %t.exe.dump-dwarf
5+
# RUN: llvm-objdump --dwarf=frames %t.exe > %t.exe.dump-dwarf
66
# RUN: match-dwarf %t.exe.dump %t.exe.dump-dwarf foo > %t.match-dwarf.txt
77

88
# RUN: llvm-bolt %t.exe -o %t.exe.bolt

bolt/test/match_dwarf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ def print(self):
3939

4040
def parse_negate_offsets(self):
4141
"""
42-
Create a list of locations/offsets of the negate_ra_state
43-
CFIs in the dwarf entry.
44-
To find offsets for each, we match the DW_CFA_advance_loc entries,
45-
and sum up their values.
42+
Create a list of locations/offsets of the negate_ra_state CFIs in the
43+
dwarf entry. To find offsets for each, we match the DW_CFA_advance_loc
44+
entries, and sum up their values.
4645
"""
4746
negate_offsets = []
4847
loc = 0
@@ -65,10 +64,10 @@ def __eq__(self, other):
6564

6665
def extract_function_addresses(objdump):
6766
"""
68-
Parse and return address-to-name dictionary from objdump file
67+
Parse and return address-to-name dictionary from objdump file.
6968
Function names in the objdump look like this:
7069
000123abc <foo>:
71-
We want to create a dict from the addr (000123abc), to the name (foo).
70+
We create a dict from the addr (000123abc), to the name (foo).
7271
"""
7372
addr_name_dict = dict()
7473
re_function = re.compile(r"^([0-9a-fA-F]+)\s<(.*)>:$")
@@ -91,10 +90,10 @@ def match_dwarf_to_name(dwarfdump, addr_name_dict):
9190
The matched lines look like this:
9291
000123 000456 000789 FDE cie=000000 pc=0123abc...0456def
9392
We do not have the function name for this, only the PC range it applies to.
94-
We need to find the pc=0123abc (the start address), and find the matching name from
93+
We match the pc=0123abc (the start address), and find the matching name from
9594
the addr_name_dict.
96-
The result NameDwarfPair will hold the lines this header applied to, and instead of
97-
the header with the addresses, it will just have the function name.
95+
The resultint NameDwarfPair will hold the lines this header applied to, and
96+
instead of the header with the addresses, it will just have the function name.
9897
"""
9998
re_address_line = re.compile(r".*pc=([0-9a-fA-F]+)\.\.\.([0-9a-fA-F]+)")
10099
with open(dwarfdump, "r") as dw:

0 commit comments

Comments
 (0)