[compiler-rt] 5081468 - [xray] Avoid text relocations in trampolines for ARM/AArch64

Ian Levesque via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 21 20:21:36 PDT 2020


Author: Ian Levesque
Date: 2020-04-21T23:21:02-04:00
New Revision: 5081468a669236fded73b2ca9fad2a8b8e6b7bf9

URL: https://github.com/llvm/llvm-project/commit/5081468a669236fded73b2ca9fad2a8b8e6b7bf9
DIFF: https://github.com/llvm/llvm-project/commit/5081468a669236fded73b2ca9fad2a8b8e6b7bf9.diff

LOG: [xray] Avoid text relocations in trampolines for ARM/AArch64

Summary: Switch to pc-relative lookup of the xray handler function to avoid text relocations.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: kristof.beyls, danielkiss, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78595

Added: 
    

Modified: 
    compiler-rt/lib/xray/xray_trampoline_AArch64.S
    compiler-rt/lib/xray/xray_trampoline_arm.S

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/xray/xray_trampoline_AArch64.S b/compiler-rt/lib/xray/xray_trampoline_AArch64.S
index 8f8ab35ce2fb..9dc862bb55f6 100644
--- a/compiler-rt/lib/xray/xray_trampoline_AArch64.S
+++ b/compiler-rt/lib/xray/xray_trampoline_AArch64.S
@@ -27,10 +27,10 @@ __xray_FunctionEntry:
     STP Q2, Q3, [SP, #-32]!
     STP Q4, Q5, [SP, #-32]!
     STP Q6, Q7, [SP, #-32]!
-    /* Load the address of _ZN6__xray19XRayPatchedFunctionE into X1 */
-    LDR X1, =_ZN6__xray19XRayPatchedFunctionE
+    /* Load the page address of _ZN6__xray19XRayPatchedFunctionE into X1 */
+    ADRP X1, _ZN6__xray19XRayPatchedFunctionE
     /* Load the handler function pointer into X2 */
-    LDR X2, [X1]
+    LDR X2, [X1, #:lo12:_ZN6__xray19XRayPatchedFunctionE]
     /* Handler address is nullptr if handler is not set */
     CMP X2, #0
     BEQ FunctionEntry_restore
@@ -72,10 +72,10 @@ __xray_FunctionExit:
     STP X5, X6, [SP, #-16]!
     STP X7, X30, [SP, #-16]!
     STR Q0, [SP, #-16]!
-    /* Load the address of _ZN6__xray19XRayPatchedFunctionE into X1 */
-    LDR X1, =_ZN6__xray19XRayPatchedFunctionE
+    /* Load the page address of _ZN6__xray19XRayPatchedFunctionE into X1 */
+    ADRP X1, _ZN6__xray19XRayPatchedFunctionE
     /* Load the handler function pointer into X2 */
-    LDR X2, [X1]
+    LDR X2, [X1, #:lo12:_ZN6__xray19XRayPatchedFunctionE]
     /* Handler address is nullptr if handler is not set */
     CMP X2, #0
     BEQ FunctionExit_restore
@@ -117,10 +117,10 @@ __xray_FunctionTailExit:
     STP Q2, Q3, [SP, #-32]!
     STP Q4, Q5, [SP, #-32]!
     STP Q6, Q7, [SP, #-32]!
-    /* Load the address of _ZN6__xray19XRayPatchedFunctionE into X1 */
-    LDR X1, =_ZN6__xray19XRayPatchedFunctionE
+    /* Load the page address of _ZN6__xray19XRayPatchedFunctionE into X1 */
+    ADRP X1, _ZN6__xray19XRayPatchedFunctionE
     /* Load the handler function pointer into X2 */
-    LDR X2, [X1]
+    LDR X2, [X1, #:lo12:_ZN6__xray19XRayPatchedFunctionE]
     /* Handler address is nullptr if handler is not set */
     CMP X2, #0
     BEQ FunctionTailExit_restore

diff  --git a/compiler-rt/lib/xray/xray_trampoline_arm.S b/compiler-rt/lib/xray/xray_trampoline_arm.S
index 528bc6c72fdd..3ffc1e443761 100644
--- a/compiler-rt/lib/xray/xray_trampoline_arm.S
+++ b/compiler-rt/lib/xray/xray_trampoline_arm.S
@@ -21,9 +21,9 @@ __xray_FunctionEntry:
     PUSH {r1-r3,lr}
     @ Save floating-point parameters of the instrumented function
     VPUSH {d0-d7}
-    MOVW r1,#:lower16:_ZN6__xray19XRayPatchedFunctionE
-    MOVT r1,#:upper16:_ZN6__xray19XRayPatchedFunctionE
-    LDR r2, [r1]
+    MOVW r1, #:lower16:_ZN6__xray19XRayPatchedFunctionE - (. + 16)
+    MOVT r1, #:upper16:_ZN6__xray19XRayPatchedFunctionE - (. + 12)
+    LDR r2, [pc, r1]
     @ Handler address is nullptr if handler is not set
     CMP r2, #0
     BEQ FunctionEntry_restore
@@ -53,9 +53,9 @@ __xray_FunctionExit:
     @ Save the floating-point return value of the instrumented function
     VPUSH {d0}
     @ Load the handler address
-    MOVW r1,#:lower16:_ZN6__xray19XRayPatchedFunctionE
-    MOVT r1,#:upper16:_ZN6__xray19XRayPatchedFunctionE
-    LDR r2, [r1]
+    MOVW r1, #:lower16:_ZN6__xray19XRayPatchedFunctionE - (. + 16)
+    MOVT r1, #:upper16:_ZN6__xray19XRayPatchedFunctionE - (. + 12)
+    LDR r2, [pc, r1]
     @ Handler address is nullptr if handler is not set
     CMP r2, #0
     BEQ FunctionExit_restore
@@ -84,9 +84,9 @@ __xray_FunctionTailExit:
     PUSH {r1-r3,lr}
     @ Save floating-point parameters of the instrumented function
     VPUSH {d0-d7}
-    MOVW r1,#:lower16:_ZN6__xray19XRayPatchedFunctionE
-    MOVT r1,#:upper16:_ZN6__xray19XRayPatchedFunctionE
-    LDR r2, [r1]
+    MOVW r1, #:lower16:_ZN6__xray19XRayPatchedFunctionE - (. + 16)
+    MOVT r1, #:upper16:_ZN6__xray19XRayPatchedFunctionE - (. + 12)
+    LDR r2, [pc, r1]
     @ Handler address is nullptr if handler is not set
     CMP r2, #0
     BEQ FunctionTailExit_restore


        


More information about the llvm-commits mailing list