Skip to content

Commit f5247e1

Browse files
committed
[BOLT] Review nits (NFC)
1 parent 936b529 commit f5247e1

File tree

7 files changed

+34
-47
lines changed

7 files changed

+34
-47
lines changed

bolt/lib/Core/BinaryFunction.cpp

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

187+
static void checkFlagsForPacRet() {
188+
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode || opts::AllowPacret)) {
189+
llvm_unreachable(
190+
"BOLT-ERROR: support for binaries using pac-ret hardening (e.g. as "
191+
"produced by '-mbranch-protection=pac-ret') is experimental\n"
192+
"BOLT-ERROR: set --allow-experimental-pacret to allow processing");
193+
}
194+
}
195+
187196
/// Gets debug line information for the instruction located at the given
188197
/// address in the original binary. The SMLoc's pointer is used
189198
/// to point to this information, which is represented by a
@@ -2770,13 +2779,7 @@ struct CFISnapshot {
27702779
llvm_unreachable("unsupported CFI opcode");
27712780
break;
27722781
case MCCFIInstruction::OpNegateRAState:
2773-
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode ||
2774-
opts::AllowPacret)) {
2775-
llvm_unreachable(
2776-
"BOLT-ERROR: support for binaries using pac-ret hardening (e.g. as "
2777-
"produced by '-mbranch-protection=pac-ret') is experimental\n"
2778-
"BOLT-ERROR: set --allow-experimental-pacret to allow processing");
2779-
}
2782+
checkFlagsForPacRet();
27802783
break;
27812784
case MCCFIInstruction::OpRememberState:
27822785
case MCCFIInstruction::OpRestoreState:
@@ -2918,13 +2921,7 @@ struct CFISnapshotDiff : public CFISnapshot {
29182921
llvm_unreachable("unsupported CFI opcode");
29192922
return false;
29202923
case MCCFIInstruction::OpNegateRAState:
2921-
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode ||
2922-
opts::AllowPacret)) {
2923-
llvm_unreachable(
2924-
"BOLT-ERROR: support for binaries using pac-ret hardening (e.g. as "
2925-
"produced by '-mbranch-protection=pac-ret') is experimental\n"
2926-
"BOLT-ERROR: set --allow-experimental-pacret to allow processing");
2927-
}
2924+
checkFlagsForPacRet();
29282925
break;
29292926
case MCCFIInstruction::OpRememberState:
29302927
case MCCFIInstruction::OpRestoreState:
@@ -3077,13 +3074,7 @@ BinaryFunction::unwindCFIState(int32_t FromState, int32_t ToState,
30773074
llvm_unreachable("unsupported CFI opcode");
30783075
break;
30793076
case MCCFIInstruction::OpNegateRAState:
3080-
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode ||
3081-
opts::AllowPacret)) {
3082-
llvm_unreachable(
3083-
"BOLT-ERROR: support for binaries using pac-ret hardening (e.g. as "
3084-
"produced by '-mbranch-protection=pac-ret') is experimental\n"
3085-
"BOLT-ERROR: set --allow-experimental-pacret to allow processing");
3086-
}
3077+
checkFlagsForPacRet();
30873078
break;
30883079
case MCCFIInstruction::OpGnuArgsSize:
30893080
// 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ cl::opt<unsigned>
219219
cl::init(0), cl::ZeroOrMore, cl::cat(BoltCategory),
220220
cl::sub(cl::SubCommand::getAll()));
221221

222+
cl::opt<bool> AllowPacret(
223+
"allow-experimental-pacret",
224+
cl::desc("Enable processing binaries with pac-ret (experimental)"),
225+
cl::init(false),
226+
cl::cat(BoltOptCategory));
227+
222228
bool processAllFunctions() {
223229
if (opts::AggregateOnly)
224230
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)