[PATCH] D27996: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the instruction cache after code modification

Serge Rogatch via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 20 11:57:34 PST 2016


rSerge created this revision.
rSerge added reviewers: dberris, rengolin.
rSerge added subscribers: iid_iunknown, llvm-commits.
Herald added a subscriber: aemerson.

This patch attempts to fix test patching-unpatching.cc . The new code flushes the instruction cache after modifying the program at runtime.


https://reviews.llvm.org/D27996

Files:
  lib/xray/xray_AArch64.cc
  test/xray/TestCases/Linux/patching-unpatching.cc


Index: test/xray/TestCases/Linux/patching-unpatching.cc
===================================================================
--- test/xray/TestCases/Linux/patching-unpatching.cc
+++ 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"
 
Index: lib/xray/xray_AArch64.cc
===================================================================
--- lib/xray/xray_AArch64.cc
+++ lib/xray/xray_AArch64.cc
@@ -61,8 +61,8 @@
   //   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);
@@ -74,14 +74,17 @@
     *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);
   } else {
     std::atomic_store_explicit(
         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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27996.82129.patch
Type: text/x-patch
Size: 1658 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161220/9c892bd5/attachment.bin>


More information about the llvm-commits mailing list