Skip to content

Commit 936b529

Browse files
committed
[BOLT] Disallow Instrumentation mode for pac-ret binaries
- add unittest to cover this check
1 parent 84ab947 commit 936b529

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,12 @@ Error RewriteInstance::run() {
700700
adjustCommandLineOptions();
701701
discoverFileObjects();
702702

703+
if (opts::Instrument && opts::AllowPacret) {
704+
BC->errs() << "BOLT-ERROR: Instrumenting binaries with pac-ret hardening "
705+
"is not supported.\n";
706+
exit(1);
707+
}
708+
703709
if (opts::Instrument && !BC->IsStaticExecutable)
704710
if (Error E = discoverRtFiniAddress())
705711
return E;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Instrumenting binaries with pac-ret hardening is not supported.
2+
# This test makes sure that BOLT will fail when ran with both the
3+
# --allow-experimental-pacret and --instrument flags.
4+
5+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
6+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
7+
8+
# RUN: not llvm-bolt %t.exe -o %t.bolt --allow-experimental-pacret --instrument 2>&1 | FileCheck %s
9+
10+
# CHECK: BOLT-ERROR: Instrumenting binaries with pac-ret hardening is not supported.
11+
12+
.text
13+
.globl foo
14+
.p2align 2
15+
.type foo,@function
16+
foo:
17+
.cfi_startproc
18+
hint #25
19+
.cfi_negate_ra_state
20+
sub sp, sp, #16
21+
stp x29, x30, [sp, #16] // 16-byte Folded Spill
22+
.cfi_def_cfa_offset 16
23+
str w0, [sp, #12]
24+
ldr w8, [sp, #12]
25+
add w0, w8, #1
26+
ldp x29, x30, [sp, #16] // 16-byte Folded Reload
27+
add sp, sp, #16
28+
hint #29
29+
.cfi_negate_ra_state
30+
ret
31+
.Lfunc_end1:
32+
.size foo, .Lfunc_end1-foo
33+
.cfi_endproc
34+
35+
.global _start
36+
.type _start, %function
37+
_start:
38+
b foo
39+
40+
.reloc 0, R_AARCH64_NONE

0 commit comments

Comments
 (0)