aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaschalis Mpeis <paschalis.mpeis@arm.com>2024-07-15 09:20:47 +0300
committerGitHub <noreply@github.com>2024-07-15 07:20:47 +0100
commit587308c3436b3fb757d3ba4343ccd4bd0c90f429 (patch)
tree783ff2006699a52160005b1cd0ebf8667c3536d2
parent37211d17f9f237e8a820ed81c1b5e92c22b45d5e (diff)
downloadllvm-587308c3436b3fb757d3ba4343ccd4bd0c90f429.zip
llvm-587308c3436b3fb757d3ba4343ccd4bd0c90f429.tar.gz
llvm-587308c3436b3fb757d3ba4343ccd4bd0c90f429.tar.bz2
[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 ```
-rw-r--r--bolt/include/bolt/Core/MCPlusBuilder.h8
-rw-r--r--bolt/lib/Target/X86/X86MCPlusBuilder.cpp6
-rw-r--r--bolt/test/AArch64/dummy-return.s28
3 files changed, 34 insertions, 8 deletions
diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h
index ab07f07..885d627 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -2041,9 +2041,13 @@ public:
return InstructionListType();
}
+ /// Returns a function body that contains only a return instruction. An
+ /// example usage is a workaround for the '__bolt_fini_trampoline' of
+ // Instrumentation.
virtual InstructionListType createDummyReturnFunction(MCContext *Ctx) const {
- llvm_unreachable("not implemented");
- return InstructionListType();
+ InstructionListType Insts(1);
+ createReturn(Insts[0]);
+ return Insts;
}
/// This method takes an indirect call instruction and splits it up into an
diff --git a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
index 37136f4..e46c425 100644
--- a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
+++ b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
@@ -3241,12 +3241,6 @@ public:
return Insts;
}
- InstructionListType createDummyReturnFunction(MCContext *Ctx) const override {
- InstructionListType Insts(1);
- createReturn(Insts[0]);
- return Insts;
- }
-
BlocksVectorTy indirectCallPromotion(
const MCInst &CallInst,
const std::vector<std::pair<MCSymbol *, uint64_t>> &Targets,
diff --git a/bolt/test/AArch64/dummy-return.s b/bolt/test/AArch64/dummy-return.s
new file mode 100644
index 0000000..a446343
--- /dev/null
+++ b/bolt/test/AArch64/dummy-return.s
@@ -0,0 +1,28 @@
+# REQUIRES: system-linux,target=aarch64{{.*}}
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -static
+# RUN: llvm-bolt -instrument -instrumentation-sleep-time=1 %t.exe \
+# RUN: -o %t.instr 2>&1 | FileCheck %s
+# RUN: llvm-objdump --disassemble-symbols=__bolt_fini_trampoline %t.instr -D \
+# RUN: | FileCheck %s -check-prefix=CHECK-ASM
+
+# CHECK: BOLT-INFO: output linked against instrumentation runtime library
+# CHECK-ASM: <__bolt_fini_trampoline>:
+# CHECK-ASM-NEXT: ret
+
+ .text
+ .align 4
+ .global _start
+ .type _start, %function
+_start:
+ bl foo
+ ret
+ .size _start, .-_start
+
+ .global foo
+ .type foo, %function
+foo:
+ mov w0, wzr
+ ret
+ .size foo, .-foo