summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/PatchableFunction.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2020-01-03 00:35:47 -0800
committerFangrui Song <maskray@google.com>2020-01-10 09:55:51 -0800
commit4d1e23e3b3cd7c72a8b24dc5acb7e13c58a8de37 (patch)
treedc5bd17c830b737ce47c0d8887049a24b33eb7d5 /llvm/lib/CodeGen/PatchableFunction.cpp
parentfd8ded99fe6e9fcae2c98ccad25d6562c5fa8a14 (diff)
downloadbcm5719-llvm-4d1e23e3b3cd7c72a8b24dc5acb7e13c58a8de37.tar.gz
bcm5719-llvm-4d1e23e3b3cd7c72a8b24dc5acb7e13c58a8de37.zip
[AArch64] Add function attribute "patchable-function-entry" to add NOPs at function entry
The Linux kernel uses -fpatchable-function-entry to implement DYNAMIC_FTRACE_WITH_REGS for arm64 and parisc. GCC 8 implemented -fpatchable-function-entry, which can be seen as a generalized form of -mnop-mcount. The N,M form (function entry points before the Mth NOP) is currently only used by parisc. This patch adds N,0 support to AArch64 codegen. N is represented as the function attribute "patchable-function-entry". We will use a different function attribute for M, if we decide to implement it. The patch reuses the existing patchable-function pass, and TargetOpcode::PATCHABLE_FUNCTION_ENTER which is currently used by XRay. When the integrated assembler is used, __patchable_function_entries will be created for each text section with the SHF_LINK_ORDER flag to prevent --gc-sections (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93197) and COMDAT (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93195) issues. Retrospectively, __patchable_function_entries should use a PC-relative relocation type to avoid the SHF_WRITE flag and dynamic relocations. "patchable-function-entry"'s interaction with Branch Target Identification is still unclear (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92424 for GCC discussions). Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D72215
Diffstat (limited to 'llvm/lib/CodeGen/PatchableFunction.cpp')
-rw-r--r--llvm/lib/CodeGen/PatchableFunction.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/PatchableFunction.cpp b/llvm/lib/CodeGen/PatchableFunction.cpp
index f499241d43c..1d6069c5055 100644
--- a/llvm/lib/CodeGen/PatchableFunction.cpp
+++ b/llvm/lib/CodeGen/PatchableFunction.cpp
@@ -55,6 +55,15 @@ static bool doesNotGeneratecode(const MachineInstr &MI) {
}
bool PatchableFunction::runOnMachineFunction(MachineFunction &MF) {
+ if (MF.getFunction().hasFnAttribute("patchable-function-entry")) {
+ MachineBasicBlock &FirstMBB = *MF.begin();
+ MachineInstr &FirstMI = *FirstMBB.begin();
+ const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
+ BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
+ TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER));
+ return true;
+ }
+
if (!MF.getFunction().hasFnAttribute("patchable-function"))
return false;
OpenPOWER on IntegriCloud