summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerge Rogatch <srogatch@accesssoftek.com>2017-01-10 16:16:33 +0000
committerSerge Rogatch <srogatch@accesssoftek.com>2017-01-10 16:16:33 +0000
commit60d67c3850c0d7768976410a996368ab56a0f4bf (patch)
treee441477122e3d89204582890e50b7139b7048108
parent9235f229da3a6a3f0a8e12461704ee437d7a0b90 (diff)
downloadcompiler-rt-60d67c3850c0d7768976410a996368ab56a0f4bf.tar.gz
[XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the instruction cache after code modification
Summary: This patch attempts to fix test patching-unpatching.cc . The new code flushes the instruction cache after modifying the program at runtime. Reviewers: dberris, rengolin, pelikan, rovka Subscribers: rovka, llvm-commits, iid_iunknown, aemerson Differential Revision: https://reviews.llvm.org/D27996 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@291568 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/xray/xray_AArch64.cc8
-rw-r--r--test/xray/TestCases/Linux/patching-unpatching.cc1
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/xray/xray_AArch64.cc b/lib/xray/xray_AArch64.cc
index 8f24610da..0c1df22ec 100644
--- a/lib/xray/xray_AArch64.cc
+++ b/lib/xray/xray_AArch64.cc
@@ -19,6 +19,9 @@
#include <atomic>
#include <cassert>
+
+extern "C" void __clear_cache(void* start, void* end);
+
namespace __xray {
uint64_t cycleFrequency() XRAY_NEVER_INSTRUMENT {
@@ -75,8 +78,8 @@ inline static bool patchSled(const bool Enable, const uint32_t FuncId,
// B #32
uint32_t *FirstAddress = reinterpret_cast<uint32_t *>(Sled.Address);
+ uint32_t *CurAddress = FirstAddress + 1;
if (Enable) {
- uint32_t *CurAddress = FirstAddress + 1;
*CurAddress = uint32_t(PatchOpcodes::PO_LdrW0_12);
CurAddress++;
*CurAddress = uint32_t(PatchOpcodes::PO_LdrX16_12);
@@ -88,6 +91,7 @@ inline static bool patchSled(const bool Enable, const uint32_t FuncId,
*reinterpret_cast<void (**)()>(CurAddress) = TracingHook;
CurAddress += 2;
*CurAddress = uint32_t(PatchOpcodes::PO_LdpX0X30SP_16);
+ CurAddress++;
std::atomic_store_explicit(
reinterpret_cast<std::atomic<uint32_t> *>(FirstAddress),
uint32_t(PatchOpcodes::PO_StpX0X30SP_m16e), std::memory_order_release);
@@ -96,6 +100,8 @@ inline static bool patchSled(const bool Enable, const uint32_t FuncId,
reinterpret_cast<std::atomic<uint32_t> *>(FirstAddress),
uint32_t(PatchOpcodes::PO_B32), std::memory_order_release);
}
+ __clear_cache(reinterpret_cast<char*>(FirstAddress),
+ reinterpret_cast<char*>(CurAddress));
return true;
}
diff --git a/test/xray/TestCases/Linux/patching-unpatching.cc b/test/xray/TestCases/Linux/patching-unpatching.cc
index e684e427f..05478a488 100644
--- a/test/xray/TestCases/Linux/patching-unpatching.cc
+++ b/test/xray/TestCases/Linux/patching-unpatching.cc
@@ -3,7 +3,6 @@
//
// RUN: %clangxx_xray -fxray-instrument -std=c++11 %s -o %t
// RUN: XRAY_OPTIONS="patch_premain=false" %run %t 2>&1 | FileCheck %s
-// REQUIRES: stable-runtime
#include "xray/xray_interface.h"