From 93fb15788ae42bd3deab70d7eba47fd784991b6f Mon Sep 17 00:00:00 2001 From: Serge Rogatch Date: Thu, 22 Dec 2016 18:48:36 +0000 Subject: [PATCH] [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 Subscribers: llvm-commits, iid_iunknown, aemerson Differential Revision: https://reviews.llvm.org/D27996 llvm-svn: 290354 --- compiler-rt/lib/xray/xray_AArch64.cc | 5 ++++- compiler-rt/test/xray/TestCases/Linux/patching-unpatching.cc | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/xray/xray_AArch64.cc b/compiler-rt/lib/xray/xray_AArch64.cc index 8f24610..12b4a6f 100644 --- a/compiler-rt/lib/xray/xray_AArch64.cc +++ b/compiler-rt/lib/xray/xray_AArch64.cc @@ -75,8 +75,8 @@ inline static bool patchSled(const bool Enable, const uint32_t FuncId, // B #32 uint32_t *FirstAddress = reinterpret_cast(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 +88,7 @@ inline static bool patchSled(const bool Enable, const uint32_t FuncId, *reinterpret_cast(CurAddress) = TracingHook; CurAddress += 2; *CurAddress = uint32_t(PatchOpcodes::PO_LdpX0X30SP_16); + CurAddress++; std::atomic_store_explicit( reinterpret_cast *>(FirstAddress), uint32_t(PatchOpcodes::PO_StpX0X30SP_m16e), std::memory_order_release); @@ -96,6 +97,8 @@ inline static bool patchSled(const bool Enable, const uint32_t FuncId, reinterpret_cast *>(FirstAddress), uint32_t(PatchOpcodes::PO_B32), std::memory_order_release); } + __clear_cache(reinterpret_cast(FirstAddress), + reinterpret_cast(CurAddress)); return true; } diff --git a/compiler-rt/test/xray/TestCases/Linux/patching-unpatching.cc b/compiler-rt/test/xray/TestCases/Linux/patching-unpatching.cc index e684e42..05478a4 100644 --- a/compiler-rt/test/xray/TestCases/Linux/patching-unpatching.cc +++ b/compiler-rt/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" -- 2.7.4