Skip to content

Commit 587308c

Browse files
[BOLT][AArch64] Provide createDummyReturnFunction (#96626)
AArch64 needs this function when instrumenting statically-linked binaries. Sample commands: ```bash clang -Wl,-q test.c -static -o out llvm-bolt -instrument -instrumentation-sleep-time=5 out -o out.instr ```
1 parent 37211d1 commit 587308c

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,9 +2041,13 @@ class MCPlusBuilder {
20412041
return InstructionListType();
20422042
}
20432043

2044+
/// Returns a function body that contains only a return instruction. An
2045+
/// example usage is a workaround for the '__bolt_fini_trampoline' of
2046+
// Instrumentation.
20442047
virtual InstructionListType createDummyReturnFunction(MCContext *Ctx) const {
2045-
llvm_unreachable("not implemented");
2046-
return InstructionListType();
2048+
InstructionListType Insts(1);
2049+
createReturn(Insts[0]);
2050+
return Insts;
20472051
}
20482052

20492053
/// This method takes an indirect call instruction and splits it up into an

bolt/lib/Target/X86/X86MCPlusBuilder.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,12 +3241,6 @@ class X86MCPlusBuilder : public MCPlusBuilder {
32413241
return Insts;
32423242
}
32433243

3244-
InstructionListType createDummyReturnFunction(MCContext *Ctx) const override {
3245-
InstructionListType Insts(1);
3246-
createReturn(Insts[0]);
3247-
return Insts;
3248-
}
3249-
32503244
BlocksVectorTy indirectCallPromotion(
32513245
const MCInst &CallInst,
32523246
const std::vector<std::pair<MCSymbol *, uint64_t>> &Targets,

bolt/test/AArch64/dummy-return.s

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# REQUIRES: system-linux,target=aarch64{{.*}}
2+
3+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
4+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -static
5+
# RUN: llvm-bolt -instrument -instrumentation-sleep-time=1 %t.exe \
6+
# RUN: -o %t.instr 2>&1 | FileCheck %s
7+
# RUN: llvm-objdump --disassemble-symbols=__bolt_fini_trampoline %t.instr -D \
8+
# RUN: | FileCheck %s -check-prefix=CHECK-ASM
9+
10+
# CHECK: BOLT-INFO: output linked against instrumentation runtime library
11+
# CHECK-ASM: <__bolt_fini_trampoline>:
12+
# CHECK-ASM-NEXT: ret
13+
14+
.text
15+
.align 4
16+
.global _start
17+
.type _start, %function
18+
_start:
19+
bl foo
20+
ret
21+
.size _start, .-_start
22+
23+
.global foo
24+
.type foo, %function
25+
foo:
26+
mov w0, wzr
27+
ret
28+
.size foo, .-foo

0 commit comments

Comments
 (0)