[PATCH] D21612: [compiler-rt] [XRay] Basic initialization and flag definition for XRay runtime

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 15 00:40:46 PDT 2016


dberris added a comment.

I've added one flag, and the beginnings of having more flags to be supported going forward.

This is now ready for another look.


================
Comment at: lib/xray/xray_interface.cc:35-54
@@ +34,22 @@
+  // First thing we do is save the caller provided registers before doing any
+  // actual work.
+  uint64_t Rrdi, Rrax, Rrdx, Rrsi, Rrcx, Rr8, Rr9, Rrbp;
+  __asm__ __volatile__("mov %%rbp, %0" : "=m"(Rrbp));
+  __asm__ __volatile__("mov %%rdi, %0" : "=m"(Rrdi));
+  __asm__ __volatile__("mov %%rax, %0" : "=m"(Rrax));
+  __asm__ __volatile__("mov %%rdx, %0" : "=m"(Rrdx));
+  __asm__ __volatile__("mov %%rsi, %0" : "=m"(Rrsi));
+  __asm__ __volatile__("mov %%rcx, %0" : "=m"(Rrcx));
+  __asm__ __volatile__("mov %%r8, %0" : "=m"(Rr8));
+  __asm__ __volatile__("mov %%r9, %0" : "=m"(Rr9));
+
+  // FIXME: Handle async signal safety, and prevent recursive calls.
+  auto Fn = __xray::XRayPatchedFunction.load(std::memory_order_acquire);
+  if (Fn != nullptr) {
+    int32_t FunctionID;
+    __asm__("mov %%r10d, %0" : "=g"(FunctionID) : : "%r10");
+    (*Fn)(FunctionID, XRayEntryType::ENTRY);
+  }
+
+  // Then restore the registers before returning.
+  __asm__ __volatile__("mov %0,%%r9" : : "m"(Rr9) : "%r9");
----------------
I thought about this a little more, and I think it's going to be a bit harder to implement a few of the things being done here in pure assembler. I'm sure I can do it, but I'd rather do it in a separate change, after this one lands, if that's alright with you?


https://reviews.llvm.org/D21612





More information about the llvm-commits mailing list