Skip to content

Commit 9d9ede5

Browse files
jkotasfilipnavara
andauthored
Standardize on using code location for interior asm code references (#97853)
* Standardize on using code location for interior asm code references * Update src/coreclr/nativeaot/Runtime/arm/ExceptionHandling.S Co-authored-by: Filip Navara <[email protected]> * Fix Windows Arm64 --------- Co-authored-by: Filip Navara <[email protected]>
1 parent 4cff20f commit 9d9ede5

19 files changed

+52
-169
lines changed

src/coreclr/nativeaot/Runtime/StackFrameIterator.cpp

+10-28
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,28 @@
3737
#if !defined(USE_PORTABLE_HELPERS) // @TODO: these are (currently) only implemented in assembly helpers
3838

3939
#if defined(FEATURE_DYNAMIC_CODE)
40-
EXTERN_C void * RhpUniversalTransition();
41-
GPTR_IMPL_INIT(PTR_VOID, g_RhpUniversalTransitionAddr, (void**)&RhpUniversalTransition);
42-
43-
EXTERN_C PTR_VOID PointerToReturnFromUniversalTransition;
44-
GVAL_IMPL_INIT(PTR_VOID, g_ReturnFromUniversalTransitionAddr, PointerToReturnFromUniversalTransition);
45-
46-
EXTERN_C PTR_VOID PointerToReturnFromUniversalTransition_DebugStepTailCall;
47-
GVAL_IMPL_INIT(PTR_VOID, g_ReturnFromUniversalTransition_DebugStepTailCallAddr, PointerToReturnFromUniversalTransition_DebugStepTailCall);
40+
EXTERN_C CODE_LOCATION ReturnFromUniversalTransition;
41+
EXTERN_C CODE_LOCATION ReturnFromUniversalTransition_DebugStepTailCall;
4842
#endif
4943

5044
#ifdef TARGET_X86
51-
EXTERN_C void * PointerToRhpCallFunclet2;
52-
GVAL_IMPL_INIT(PTR_VOID, g_RhpCallFunclet2Addr, PointerToRhpCallFunclet2);
45+
EXTERN_C CODE_LOCATION RhpCallFunclet2;
5346
#endif
54-
EXTERN_C void * PointerToRhpCallCatchFunclet2;
55-
GVAL_IMPL_INIT(PTR_VOID, g_RhpCallCatchFunclet2Addr, PointerToRhpCallCatchFunclet2);
56-
EXTERN_C void * PointerToRhpCallFinallyFunclet2;
57-
GVAL_IMPL_INIT(PTR_VOID, g_RhpCallFinallyFunclet2Addr, PointerToRhpCallFinallyFunclet2);
58-
EXTERN_C void * PointerToRhpCallFilterFunclet2;
59-
GVAL_IMPL_INIT(PTR_VOID, g_RhpCallFilterFunclet2Addr, PointerToRhpCallFilterFunclet2);
60-
EXTERN_C void * PointerToRhpThrowEx2;
61-
GVAL_IMPL_INIT(PTR_VOID, g_RhpThrowEx2Addr, PointerToRhpThrowEx2);
62-
EXTERN_C void * PointerToRhpThrowHwEx2;
63-
GVAL_IMPL_INIT(PTR_VOID, g_RhpThrowHwEx2Addr, PointerToRhpThrowHwEx2);
64-
EXTERN_C void * PointerToRhpRethrow2;
65-
GVAL_IMPL_INIT(PTR_VOID, g_RhpRethrow2Addr, PointerToRhpRethrow2);
47+
EXTERN_C CODE_LOCATION RhpCallCatchFunclet2;
48+
EXTERN_C CODE_LOCATION RhpCallFinallyFunclet2;
49+
EXTERN_C CODE_LOCATION RhpCallFilterFunclet2;
50+
EXTERN_C CODE_LOCATION RhpThrowEx2;
51+
EXTERN_C CODE_LOCATION RhpThrowHwEx2;
52+
EXTERN_C CODE_LOCATION RhpRethrow2;
6653
#endif // !defined(USE_PORTABLE_HELPERS)
6754

6855
// Addresses of functions in the DAC won't match their runtime counterparts so we
6956
// assign them to globals. However it is more performant in the runtime to compare
7057
// against immediates than to fetch the global. This macro hides the difference.
71-
//
72-
// We use a special code path for the return address from thunks as
73-
// having the return address public confuses today DIA stackwalker. Before we can
74-
// ingest the updated DIA, we're instead exposing a global void * variable
75-
// holding the return address.
7658
#ifdef DACCESS_COMPILE
7759
#define EQUALS_RETURN_ADDRESS(x, func_name) ((x) == g_ ## func_name ## Addr)
7860
#else
79-
#define EQUALS_RETURN_ADDRESS(x, func_name) (((x)) == (PointerTo ## func_name))
61+
#define EQUALS_RETURN_ADDRESS(x, func_name) ((x) == &func_name)
8062
#endif
8163

8264
#ifdef DACCESS_COMPILE

src/coreclr/nativeaot/Runtime/amd64/AsmMacros.inc

-18
Original file line numberDiff line numberDiff line change
@@ -214,24 +214,6 @@ Name label proc
214214
PUBLIC Name
215215
endm
216216

217-
EXPORT_POINTER_TO_ADDRESS macro Name
218-
219-
local AddressToExport
220-
221-
AddressToExport label proc
222-
223-
.const
224-
225-
align 8
226-
227-
Name dq offset AddressToExport
228-
229-
public Name
230-
231-
.code
232-
233-
endm
234-
235217
_tls_array equ 58h ;; offsetof(TEB, ThreadLocalStoragePointer)
236218

237219
;;

src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S

+6-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ NESTED_ENTRY RhpThrowHwEx, _TEXT, NoHandler
7070
// rsi contains the address of the ExInfo
7171
call EXTERNAL_C_FUNC(RhThrowHwEx)
7272

73-
EXPORT_POINTER_TO_ADDRESS PointerToRhpThrowHwEx2
73+
ALTERNATE_ENTRY RhpThrowHwEx2
7474

7575
// no return
7676
int 3
@@ -151,7 +151,7 @@ NESTED_ENTRY RhpThrowEx, _TEXT, NoHandler
151151
// rsi contains the address of the ExInfo
152152
call EXTERNAL_C_FUNC(RhThrowEx)
153153

154-
EXPORT_POINTER_TO_ADDRESS PointerToRhpThrowEx2
154+
ALTERNATE_ENTRY RhpThrowEx2
155155

156156
// no return
157157
int 3
@@ -222,7 +222,7 @@ NESTED_ENTRY RhpRethrow, _TEXT, NoHandler
222222
// rsi contains the address of the new ExInfo
223223
call EXTERNAL_C_FUNC(RhRethrow)
224224

225-
EXPORT_POINTER_TO_ADDRESS PointerToRhpRethrow2
225+
ALTERNATE_ENTRY RhpRethrow2
226226

227227
// no return
228228
int 3
@@ -334,7 +334,7 @@ NESTED_ENTRY RhpCallCatchFunclet, _TEXT, NoHandler
334334
mov rsi, [rsp + locArg0] // rsi <- exception object
335335
call qword ptr [rsp + locArg1] // call handler funclet
336336

337-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallCatchFunclet2
337+
ALTERNATE_ENTRY RhpCallCatchFunclet2
338338

339339
mov rdx, [rsp + locArg2] // rdx <- dispatch context
340340

@@ -473,7 +473,7 @@ NESTED_ENTRY RhpCallFinallyFunclet, _TEXT, NoHandler
473473
mov rdi, [rsi + OFFSETOF__REGDISPLAY__SP] // rdi <- establisher frame
474474
call qword ptr [rsp + locArg0] // handler funclet address
475475

476-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallFinallyFunclet2
476+
ALTERNATE_ENTRY RhpCallFinallyFunclet2
477477

478478
mov rsi, [rsp + locArg1] // rsi <- regdisplay
479479

@@ -523,7 +523,7 @@ NESTED_ENTRY RhpCallFilterFunclet, _TEXT, NoHandler
523523
mov rdi, [rdx + OFFSETOF__REGDISPLAY__SP] // rdi <- establisher frame
524524
call rax
525525

526-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallFilterFunclet2
526+
ALTERNATE_ENTRY RhpCallFilterFunclet2
527527

528528
// RAX contains the result of the filter execution
529529

src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.asm

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ NESTED_ENTRY RhpThrowHwEx, _TEXT
9292
;; rdx contains the address of the ExInfo
9393
call RhThrowHwEx
9494

95-
EXPORT_POINTER_TO_ADDRESS PointerToRhpThrowHwEx2
95+
ALTERNATE_ENTRY RhpThrowHwEx2
9696

9797
;; no return
9898
int 3
@@ -184,7 +184,7 @@ NESTED_ENTRY RhpThrowEx, _TEXT
184184
;; rdx contains the address of the ExInfo
185185
call RhThrowEx
186186

187-
EXPORT_POINTER_TO_ADDRESS PointerToRhpThrowEx2
187+
ALTERNATE_ENTRY RhpThrowEx2
188188

189189
;; no return
190190
int 3
@@ -269,7 +269,7 @@ NESTED_ENTRY RhpRethrow, _TEXT
269269
;; rdx contains the address of the new ExInfo
270270
call RhRethrow
271271

272-
EXPORT_POINTER_TO_ADDRESS PointerToRhpRethrow2
272+
ALTERNATE_ENTRY RhpRethrow2
273273

274274
;; no return
275275
int 3
@@ -428,7 +428,7 @@ endif
428428
mov rdx, [rsp + rsp_offsetof_arguments + 0h] ;; rdx <- exception object
429429
call qword ptr [rsp + rsp_offsetof_arguments + 8h] ;; call handler funclet
430430

431-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallCatchFunclet2
431+
ALTERNATE_ENTRY RhpCallCatchFunclet2
432432

433433
mov r8, [rsp + rsp_offsetof_arguments + 10h] ;; r8 <- dispatch context
434434

@@ -601,7 +601,7 @@ endif
601601
mov rcx, [rdx + OFFSETOF__REGDISPLAY__SP] ;; rcx <- establisher frame
602602
call qword ptr [rsp + rsp_offsetof_arguments + 0h] ;; handler funclet address
603603

604-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallFinallyFunclet2
604+
ALTERNATE_ENTRY RhpCallFinallyFunclet2
605605

606606
mov rdx, [rsp + rsp_offsetof_arguments + 8h] ;; rdx <- regdisplay
607607

@@ -666,7 +666,7 @@ NESTED_ENTRY RhpCallFilterFunclet, _TEXT
666666
mov rcx, [r8 + OFFSETOF__REGDISPLAY__SP] ;; rcx <- establisher frame
667667
call rax
668668

669-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallFilterFunclet2
669+
ALTERNATE_ENTRY RhpCallFilterFunclet2
670670

671671
;; RAX contains the result of the filter execution
672672

src/coreclr/nativeaot/Runtime/amd64/UniversalTransition.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ NESTED_ENTRY Rhp\FunctionName, _TEXT, NoHandler
124124
lea rdi, [rsp + DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK]
125125
call r10
126126

127-
EXPORT_POINTER_TO_ADDRESS PointerToReturnFrom\FunctionName
127+
ALTERNATE_ENTRY ReturnFrom\FunctionName
128128

129129
// restore fp argument registers
130130
movdqa xmm0, [rsp + DISTANCE_FROM_CHILDSP_TO_FP_REGS + 0x00]

src/coreclr/nativeaot/Runtime/amd64/UniversalTransition.asm

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ endif ; TRASH_SAVED_ARGUMENT_REGISTERS
126126
lea rcx, [rsp + DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK]
127127
call r10
128128

129-
EXPORT_POINTER_TO_ADDRESS PointerToReturnFrom&FunctionName
129+
ALTERNATE_ENTRY ReturnFrom&FunctionName
130130

131131
; We cannot make the label public as that tricks DIA stackwalker into thinking
132132
; it's the beginning of a method. For this reason we export the address

src/coreclr/nativeaot/Runtime/arm/ExceptionHandling.S

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ NESTED_ENTRY RhpThrowHwEx, _TEXT, NoHandler
7171
// r1 contains the address of the ExInfo
7272
bl C_FUNC(RhThrowHwEx)
7373

74-
EXPORT_POINTER_TO_ADDRESS PointerToRhpThrowHwEx2
74+
GLOBAL_LABEL RhpThrowHwEx2
7575

7676
// no return
7777
EMIT_BREAKPOINT
@@ -176,7 +176,7 @@ LOCAL_LABEL(NotHiJacked):
176176
// r1 contains the address of the new ExInfo
177177
bl C_FUNC(RhThrowEx)
178178

179-
EXPORT_POINTER_TO_ADDRESS PointerToRhpThrowEx2
179+
GLOBAL_LABEL RhpThrowEx2
180180

181181
// no return
182182
EMIT_BREAKPOINT
@@ -237,7 +237,7 @@ NESTED_ENTRY RhpRethrow, _TEXT, NoHandler
237237
// r1 contains the address of the new ExInfo
238238
blx C_FUNC(RhRethrow)
239239

240-
EXPORT_POINTER_TO_ADDRESS PointerToRhpRethrow2
240+
GLOBAL_LABEL RhpRethrow2
241241

242242
// no return
243243
EMIT_BREAKPOINT
@@ -320,7 +320,7 @@ LOCAL_LABEL(ClearSuccess_Catch):
320320
// r0 <- exception object
321321
blx r3 // call handler funclet
322322

323-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallCatchFunclet2
323+
GLOBAL_LABEL RhpCallCatchFunclet2
324324

325325
str r0, [sp, #rsp_offset_r0] // Save the result
326326

@@ -421,7 +421,7 @@ LOCAL_LABEL(ClearSuccess):
421421

422422
blx r2 // handler funclet address
423423

424-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallFinallyFunclet2
424+
GLOBAL_LABEL RhpCallFinallyFunclet2
425425

426426
ldr r1, [sp, #rsp_offset_r1] // reload REGDISPLAY pointer
427427

@@ -497,7 +497,7 @@ NESTED_ENTRY RhpCallFilterFunclet, _TEXT, NoHandler
497497
// r1 = establisher frame
498498
blx r12
499499

500-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallFilterFunclet2
500+
GLOBAL_LABEL RhpCallFilterFunclet2
501501

502502
// R0 contains the result of the filter execution
503503

src/coreclr/nativeaot/Runtime/arm/UniversalTransition.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ NESTED_ENTRY Rhp\FunctionName, _TEXT, NoHandler
123123
add r0, sp, #DISTANCE_FROM_CHILDSP_TO_RETURN_BLOCK // First parameter to target function is a pointer to the return block
124124
blx r12
125125

126-
EXPORT_POINTER_TO_ADDRESS PointerToReturnFrom\FunctionName
126+
GLOBAL_LABEL ReturnFrom\FunctionName
127127

128128
// We cannot make the label public as that tricks DIA stackwalker into thinking
129129
// it's the beginning of a method. For this reason we export an auxiliary variable

src/coreclr/nativeaot/Runtime/arm64/AsmMacros.h

-19
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,6 @@ MovInstr SETS "movk"
173173
ldr w$RegNum, [x$RegNum, $Name]
174174
MEND
175175

176-
177-
;; -----------------------------------------------------------------------------
178-
;;
179-
;; Macro to export a pointer to an address inside a stub as a 64-bit variable
180-
;;
181-
MACRO
182-
EXPORT_POINTER_TO_ADDRESS $Name
183-
LCLS CodeLbl
184-
CodeLbl SETS "$Name":CC:"Lbl"
185-
$CodeLbl
186-
AREA | .rdata | , ALIGN = 8, DATA, READONLY
187-
$Name
188-
DCQ $CodeLbl
189-
EXPORT $Name
190-
TEXTAREA
191-
ROUT
192-
193-
MEND
194-
195176
;; -----------------------------------------------------------------------------
196177
;;
197178
;; Macro for indicating an alternate entry point into a function.

src/coreclr/nativeaot/Runtime/arm64/ExceptionHandling.S

+6-6
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
// x1: ExInfo*
246246
bl C_FUNC(RhThrowHwEx)
247247

248-
EXPORT_POINTER_TO_ADDRESS PointerToRhpThrowHwEx2
248+
ALTERNATE_ENTRY RhpThrowHwEx2
249249

250250
// no return
251251
EMIT_BREAKPOINT
@@ -332,7 +332,7 @@ LOCAL_LABEL(NotHijacked):
332332
// x1: ExInfo*
333333
bl C_FUNC(RhThrowEx)
334334

335-
EXPORT_POINTER_TO_ADDRESS PointerToRhpThrowEx2
335+
ALTERNATE_ENTRY RhpThrowEx2
336336

337337
// no return
338338
EMIT_BREAKPOINT
@@ -377,7 +377,7 @@ LOCAL_LABEL(NotHijacked):
377377
// x1 contains the address of the new ExInfo
378378
bl C_FUNC(RhRethrow)
379379

380-
EXPORT_POINTER_TO_ADDRESS PointerToRhpRethrow2
380+
ALTERNATE_ENTRY RhpRethrow2
381381

382382
// no return
383383
EMIT_BREAKPOINT
@@ -452,7 +452,7 @@ LOCAL_LABEL(ClearSuccess_Catch):
452452
// x0 still contains the exception object
453453
blr x1
454454

455-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallCatchFunclet2
455+
ALTERNATE_ENTRY RhpCallCatchFunclet2
456456

457457
// x0 contains resume IP
458458

@@ -586,7 +586,7 @@ LOCAL_LABEL(ClearSuccess):
586586
//
587587
blr x0
588588

589-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallFinallyFunclet2
589+
ALTERNATE_ENTRY RhpCallFinallyFunclet2
590590

591591
ldr x1, [sp, #rsp_offset_x1] // reload REGDISPLAY pointer
592592

@@ -650,7 +650,7 @@ LOCAL_LABEL(SetSuccess):
650650
// x0 still contains the exception object
651651
blr x1
652652

653-
EXPORT_POINTER_TO_ADDRESS PointerToRhpCallFilterFunclet2
653+
ALTERNATE_ENTRY RhpCallFilterFunclet2
654654

655655
ldp d8, d9, [sp, #0x00]
656656
ldp d10, d11, [sp, #0x10]

0 commit comments

Comments
 (0)