Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

ARM64: Add more cfi data #8336

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Native/Runtime/arm64/CallDescrWorker.S
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//void RhCallDescrWorker(CallDescrData * pCallDescrData);
NESTED_ENTRY RhCallDescrWorker, _TEXT, NoHandler

PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, #-32
PROLOG_SAVE_REG_PAIR x19, x20, #16
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -32
PROLOG_SAVE_REG_PAIR x19, x20, 16

// Save the value of SP before we start pushing any arguments
mov x20, sp
Expand Down Expand Up @@ -133,8 +133,8 @@ LReturnDone:
// Restore the value of SP
mov sp, x20

EPILOG_RESTORE_REG_PAIR x19, x20, #16
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #32
EPILOG_RESTORE_REG_PAIR x19, x20, 16
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 32
EPILOG_RETURN

NESTED_END RhCallDescrWorker
72 changes: 47 additions & 25 deletions src/Native/Runtime/arm64/ExceptionHandling.S
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@
// TODO PROLOG_PUSH_MACHINE_FRAME
.else
PROLOG_STACK_ALLOC 0x50
.cfi_adjust_cfa_offset 0x50
stp x3, lr, [sp] // x3 is the SP and lr is the IP of the fault site
.endif
stp d8, d9, [sp, #0x10]
stp d10, d11, [sp, #0x20]
stp d12, d13, [sp, #0x30]
stp d14, d15, [sp, #0x40]
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, #-0x70
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -0x70
stp xzr, xzr, [sp, #0x10] // locations reserved for return value, not used for exception handling
PROLOG_SAVE_REG_PAIR x19, x20, #0x20
PROLOG_SAVE_REG_PAIR x21, x22, #0x30
PROLOG_SAVE_REG_PAIR x23, x24, #0x40
PROLOG_SAVE_REG_PAIR x25, x26, #0x50
PROLOG_SAVE_REG_PAIR x27, x28, #0x60
PROLOG_SAVE_REG_PAIR x19, x20, 0x20
PROLOG_SAVE_REG_PAIR x21, x22, 0x30
PROLOG_SAVE_REG_PAIR x23, x24, 0x40
PROLOG_SAVE_REG_PAIR x25, x26, 0x50
PROLOG_SAVE_REG_PAIR x27, x28, 0x60
// } end PAL_LIMITED_CONTEXT

PROLOG_STACK_ALLOC STACKSIZEOF_ExInfo
Expand All @@ -53,13 +54,14 @@
// sp in fp. If sp is saved in fp in prolog then it is not expected that fp can change in the body
// of method. However, this method needs to be able to change fp before calling funclet.
// This is required to access locals in funclet.
PROLOG_SAVE_REG_PAIR_NO_FP_INDEXED fp,lr, #-0x60
PROLOG_SAVE_REG_PAIR x19, x20, #0x10
PROLOG_SAVE_REG_PAIR x21, x22, #0x20
PROLOG_SAVE_REG_PAIR x23, x24, #0x30
PROLOG_SAVE_REG_PAIR x25, x26, #0x40
PROLOG_SAVE_REG_PAIR x27, x28, #0x50
PROLOG_SAVE_REG_PAIR_NO_FP_INDEXED fp,lr, -0x60
PROLOG_SAVE_REG_PAIR x19, x20, 0x10
PROLOG_SAVE_REG_PAIR x21, x22, 0x20
PROLOG_SAVE_REG_PAIR x23, x24, 0x30
PROLOG_SAVE_REG_PAIR x25, x26, 0x40
PROLOG_SAVE_REG_PAIR x27, x28, 0x50
mov fp, sp
.cfi_def_cfa_register fp

.if \extraStackSize != 0
PROLOG_STACK_ALLOC \extraStackSize
Expand All @@ -78,12 +80,12 @@
EPILOG_STACK_FREE \extraStackSize
.endif

EPILOG_RESTORE_REG_PAIR x19, x20, #0x10
EPILOG_RESTORE_REG_PAIR x21, x22, #0x20
EPILOG_RESTORE_REG_PAIR x23, x24, #0x30
EPILOG_RESTORE_REG_PAIR x25, x26, #0x40
EPILOG_RESTORE_REG_PAIR x27, x28, #0x50
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #0x60
EPILOG_RESTORE_REG_PAIR x19, x20, 0x10
EPILOG_RESTORE_REG_PAIR x21, x22, 0x20
EPILOG_RESTORE_REG_PAIR x23, x24, 0x30
EPILOG_RESTORE_REG_PAIR x25, x26, 0x40
EPILOG_RESTORE_REG_PAIR x27, x28, 0x50
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 0x60
.endm


Expand Down Expand Up @@ -199,6 +201,26 @@



#ifdef FEATURE_EMULATED_TLS
// All these exception handling functions have their own stack frame.
// To avoid creating more than one frame per function we encapsulate these ETLS helper in own functions

NESTED_ENTRY RhpGetThreadETLS1, _TEXT, NoHandler
GETTHREAD_ETLS_1
ret
NESTED_END RhpGetThreadETLS1, _TEXT

NESTED_ENTRY RhpGetThreadETLS2, _TEXT, NoHandler
GETTHREAD_ETLS_2
ret
NESTED_END RhpGetThreadETLS2, _TEXT

NESTED_ENTRY RhpGetThreadETLS5, _TEXT, NoHandler
GETTHREAD_ETLS_5
ret
NESTED_END RhpGetThreadETLS5, _TEXT
#endif

#define rsp_offsetof_ExInfo 0
#define rsp_offsetof_Context STACKSIZEOF_ExInfo

Expand All @@ -216,7 +238,7 @@

// x2 = GetThread()
#ifdef FEATURE_EMULATED_TLS
GETTHREAD_ETLS_2
bl RhpGetThreadETLS2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These exception handling methods are not performance critical at all. It would be fine to always call RhpGetThread directly from here, for both FEATURE_EMULATED_TLS and !FEATURE_EMULATED_TLS, without going through the multiple levels of macros and wrappers.

Note that callee saved registers are saved by ALLOC_THROW_FRAME. You can stash the arguments in one of them around the call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be separate change. The multiple levels of macros are not that bad yet.

#else
INLINE_GETTHREAD x2
#endif
Expand Down Expand Up @@ -264,7 +286,7 @@

// x2 = GetThread()
#ifdef FEATURE_EMULATED_TLS
GETTHREAD_ETLS_2
bl RhpGetThreadETLS2
#else
INLINE_GETTHREAD x2
#endif
Expand Down Expand Up @@ -358,7 +380,7 @@ NotHijacked:

// x2 = GetThread()
#ifdef FEATURE_EMULATED_TLS
GETTHREAD_ETLS_2
bl RhpGetThreadETLS2
#else
INLINE_GETTHREAD x2
#endif
Expand Down Expand Up @@ -421,7 +443,7 @@ NotHijacked:
// clear the DoNotTriggerGc flag, trashes x4-x6
//
#ifdef FEATURE_EMULATED_TLS
GETTHREAD_ETLS_5
bl RhpGetThreadETLS5
#else
INLINE_GETTHREAD x5
#endif
Expand Down Expand Up @@ -464,7 +486,7 @@ ClearSuccess_Catch:
// @TODO: add debug-only validation code for ExInfo pop

#ifdef FEATURE_EMULATED_TLS
GETTHREAD_ETLS_1
bl RhpGetThreadETLS1
#else
INLINE_GETTHREAD x1
#endif
Expand Down Expand Up @@ -538,7 +560,7 @@ NoAbort:
// clear the DoNotTriggerGc flag, trashes x2-x4
//
#ifdef FEATURE_EMULATED_TLS
GETTHREAD_ETLS_2
bl RhpGetThreadETLS2
#else
INLINE_GETTHREAD x2
#endif
Expand Down Expand Up @@ -580,7 +602,7 @@ ClearSuccess:
// set the DoNotTriggerGc flag, trashes x1-x3
//
#ifdef FEATURE_EMULATED_TLS
GETTHREAD_ETLS_2
bl RhpGetThreadETLS2
#else
INLINE_GETTHREAD x2
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/Native/Runtime/arm64/MiscStubs.S
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RhpCheckCctor__SlowPath:
NESTED_ENTRY RhpCheckCctor2__SlowPath, _TEXT, NoHandler

// Need to preserve x0, x1 and lr across helper call. fp is also pushed to keep the stack 16 byte aligned.
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, #-0x20
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -0x20
stp x0, x1, [sp, #0x10]

// Call a C++ helper to retrieve the address of the classlib callback. The caller's return address is
Expand All @@ -91,7 +91,7 @@ RhpCheckCctor__SlowPath:
// frames).
mov x12, x0
ldp x0, x1, [sp, #0x10]
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #0x20
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 0x20
// tail-call the class lib cctor check function. This function is required to return its first
// argument, so that x0 can be preserved.
br x12
Expand Down
18 changes: 9 additions & 9 deletions src/Native/Runtime/arm64/PInvoke.S
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TSF_DoNotTriggerGc_Bit = 4
NESTED_ENTRY RhpWaitForSuspend, _TEXT, NoHandler

// FP and LR registers
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, #-0xA0 // Push down stack pointer and store FP and LR
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -0xA0 // Push down stack pointer and store FP and LR

// Need to save argument registers x0-x7 and the return buffer register x8
// Also save x9 which may be used for saving indirect call target
Expand Down Expand Up @@ -63,7 +63,7 @@ TSF_DoNotTriggerGc_Bit = 4
ldp x8, x9, [sp, #0x50]

// Restore FP and LR registers, and free the allocated stack block
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #0xA0
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 0xA0
EPILOG_RETURN

NESTED_END RhpWaitForSuspend, _TEXT
Expand All @@ -81,7 +81,7 @@ TSF_DoNotTriggerGc_Bit = 4
NESTED_ENTRY RhpWaitForGCNoAbort, _TEXT, NoHandler

// FP and LR registers
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, #-0x40 // Push down stack pointer and store FP and LR
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -0x40 // Push down stack pointer and store FP and LR

// Save the integer return registers, as well as the floating return registers
stp x0, x1, [sp, #0x10]
Expand All @@ -99,7 +99,7 @@ Done:
ldp x0, x1, [sp, #0x10]
ldp d0, d1, [sp, #0x20]
ldp d2, d3, [sp, #0x30]
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #0x40
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 0x40
EPILOG_RETURN

NESTED_END RhpWaitForGCNoAbort
Expand All @@ -116,7 +116,7 @@ Done:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
NESTED_ENTRY RhpWaitForGC, _TEXT, NoHandler

PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, #-0x10
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -0x10

PREPARE_EXTERNAL_VAR_INDIRECT_W RhpTrapThreads, 10

Expand All @@ -127,13 +127,13 @@ NoWait:
ldr x10, [x9, #OFFSETOF__PInvokeTransitionFrame__m_Flags]
tbz x10, #PTFF_THREAD_ABORT_BIT, NoAbort

EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #0x10
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 0x10
mov w0, #STATUS_REDHAWK_THREAD_ABORT
mov x1, lr // hijack target address as exception PC
b RhpThrowHwEx

NoAbort:
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #0x10
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 0x10
EPILOG_RETURN

NESTED_END RhpWaitForGC, _TEXT
Expand All @@ -153,7 +153,7 @@ NoAbort:
NESTED_ENTRY RhpReversePInvokeAttachOrTrapThread, _TEXT, NoHandler

// FP and LR registers
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, #-0xA0 // Push down stack pointer and store FP and LR
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -0xA0 // Push down stack pointer and store FP and LR

// Need to save argument registers x0-x7 and the return buffer register x8 (twice for 16B alignment)
stp x0, x1, [sp, #0x10]
Expand Down Expand Up @@ -185,7 +185,7 @@ NoAbort:
ldr x8, [sp, #0x50]

// Restore FP and LR registers, and free the allocated stack block
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #0xA0
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, 0xA0
EPILOG_RETURN

NESTED_END RhpReversePInvokeTrapThread
Expand Down
4 changes: 2 additions & 2 deletions src/Native/Runtime/arm64/UniversalTransition.S
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
NESTED_ENTRY Rhp\FunctionName, _TEXT, NoHandler

// FP and LR registers
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, #-STACK_SIZE // ;; Push down stack pointer and store FP and LR
PROLOG_SAVE_REG_PAIR_INDEXED fp, lr, -STACK_SIZE // ;; Push down stack pointer and store FP and LR

// Floating point registers
stp d0, d1, [sp, #(FLOAT_ARG_OFFSET )]
Expand Down Expand Up @@ -141,7 +141,7 @@
ldr x8, [sp, #(ARGUMENT_REGISTERS_OFFSET + 0x40)]

// Restore FP and LR registers, and free the allocated stack block
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, #STACK_SIZE
EPILOG_RESTORE_REG_PAIR_INDEXED fp, lr, STACK_SIZE

// Tailcall to the target address.
// TODO EPILOG_NOP
Expand Down
Loading