Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6c22d4

Browse files
authored
[BOLT][BTI] Disallow instrumenting BTI binaries (#174936)
Until instrumentation support is added, the feature should be disabled for BTI binaries. An error message is added to explain the situation. Meanwhile, users can choose sampling-based profiling methods. Added a TODO comment explaining missing steps.
1 parent c63d295 commit d6c22d4

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

bolt/lib/Passes/Instrumentation.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,22 @@ void Instrumentation::instrumentFunction(BinaryFunction &Function,
606606
}
607607

608608
Error Instrumentation::runOnFunctions(BinaryContext &BC) {
609+
if (BC.usesBTI())
610+
return createFatalBOLTError(
611+
"BOLT-ERROR: instrumenting binaries using BTI is not supported.\n");
612+
/* BTI TODO:
613+
Instrumentation functions add indirect branches into the .text.injected
614+
section, see:
615+
- __bolt_instr_ind_call_handler
616+
- __bolt_instr_ind_tail_call_handler
617+
- __bolt_instr_ind_tailcall_handler_func
618+
- __bolt_start_trampoline
619+
- __bolt_fini_trampoline
620+
We cannot add BTIs to their targets when they are created, because the
621+
instrumentation snippets get added later to these targets, and the added BTI
622+
instruction will not be the first (rendering it useless).
623+
*/
624+
609625
const unsigned Flags = BinarySection::getFlags(/*IsReadOnly=*/false,
610626
/*IsText=*/false,
611627
/*IsAllocatable=*/true);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copy of instrumentation-ind-call.c, but checking that BOLT refuses the
2+
// instrumentation because of BTI.
3+
// TODO: once instrumentation support for BTI is added, update this to check the
4+
// same as instrumentation-ind-call.c
5+
6+
#include <stdio.h>
7+
8+
typedef int (*func_ptr)(int, int);
9+
10+
int add(int a, int b) { return a + b; }
11+
12+
int main() {
13+
func_ptr fun;
14+
fun = add;
15+
int sum = fun(10, 20); // indirect call to 'add'
16+
printf("The sum is: %d\n", sum);
17+
return 0;
18+
}
19+
/*
20+
REQUIRES: system-linux,bolt-runtime
21+
22+
RUN: %clang %cflags %s -o %t.exe -Wl,-q -no-pie -fpie \
23+
RUN: -mbranch-protection=standard -Wl,-z,force-bti
24+
25+
RUN: not llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \
26+
RUN: -o %t.instrumented 2>&1 | FileCheck %s
27+
28+
CHECK: binary is using BTI
29+
CHECK: FATAL BOLT-ERROR: instrumenting binaries using BTI is not supported
30+
*/

0 commit comments

Comments
 (0)