[PATCH] D40894: [XRay][compiler-rt+llvm] Update XRay trampoline CFI and register stashing semantics

Dean Michael Berris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 10 20:38:05 PST 2017


dberris updated this revision to Diff 126306.
dberris added a comment.

Actually back out the CFI-specific changes.


https://reviews.llvm.org/D40894

Files:
  compiler-rt/lib/xray/xray_trampoline_x86_64.S
  llvm/include/llvm/IR/Intrinsics.td


Index: llvm/include/llvm/IR/Intrinsics.td
===================================================================
--- llvm/include/llvm/IR/Intrinsics.td
+++ llvm/include/llvm/IR/Intrinsics.td
@@ -880,7 +880,7 @@
 // Custom event logging for x-ray.
 // Takes a pointer to a string and the length of the string.
 def int_xray_customevent : Intrinsic<[], [llvm_ptr_ty, llvm_i32_ty],
-                                     [NoCapture<0>, ReadOnly<0>, IntrWriteMem]>;
+                                     [NoCapture<0>, ReadOnly<0>, IntrWriteMem, IntrHasSideEffects]>;
 //===----------------------------------------------------------------------===//
 
 //===------ Memory intrinsics with element-wise atomicity guarantees ------===//
Index: compiler-rt/lib/xray/xray_trampoline_x86_64.S
===================================================================
--- compiler-rt/lib/xray/xray_trampoline_x86_64.S
+++ compiler-rt/lib/xray/xray_trampoline_x86_64.S
@@ -100,7 +100,7 @@
 	testq	%rax, %rax
 	je	.Ltmp0
 
-	// The patched function prolog puts its xray_instr_map index into %r10d.
+	// The patched function prologue puts its xray_instr_map index into %r10d.
 	movl	%r10d, %edi
 	xor	%esi,%esi
 	ALIGNED_CALL_RAX
@@ -219,6 +219,14 @@
 	CFI_STARTPROC
 	SAVE_REGISTERS
 
+	// Because calls to __xray_CustomEvent can occur in the middle of a function
+	// which may already be using scratch registers, we preserve more information
+	// in this trampoline than when we are handling entry/exit events.
+	subq $16, %rsp
+	CFI_ADJUST_CFA_OFFSET(16)
+	movq %r10, 8(%rsp)
+	movq %r11, 0(%rsp)
+
 	// We take two arguments to this trampoline, which should be in rdi	and rsi
 	// already. We also make sure that we stash %rax because we use that register
 	// to call the logging handler.
@@ -229,6 +237,11 @@
 	ALIGNED_CALL_RAX
 
 .LcustomEventCleanup:
+
+	movq 8(%rsp), %r10
+	movq 0(%rsp), %r11
+	addq $16, %rsp
+	CFI_ADJUST_CFA_OFFSET(-16)
 	RESTORE_REGISTERS
 	retq
 	ASM_SIZE(__xray_CustomEvent)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40894.126306.patch
Type: text/x-patch
Size: 1984 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171211/1ed6a4ad/attachment.bin>


More information about the llvm-commits mailing list