55#include "unixasmmacros.inc"
66#include "asmconstants.h"
77
8+ // On Apple platforms we emit the whole patched region as single function
9+ // with .alt_entry labels for individual write barrier helpers. This ensures
10+ // the linker doesn't relocate or split the code and treats it as single
11+ // atom. We also need to be careful to produce the correct unwinding
12+ // information.
13+
14+ // -----------------------------------------------------------------------------
15+ // The following Macros help in WRITE_BARRIER Implementations
16+ // WRITE_BARRIER_ENTRY
17+ //
18+ // Declare the start of a write barrier function. Use similarly to NESTED_ENTRY. This is the only legal way
19+ // to declare a write barrier function.
20+ //
21+ .macro WRITE_BARRIER_ENTRY name
22+ #if defined(__APPLE__)
23+ .text
24+ .p2align 4
25+ .alt_entry C_FUNC(\name)
26+ .private_ extern C_FUNC(\name)
27+ C_FUNC(\name):
28+ #else
29+ LEAF_ENTRY \name , _TEXT
30+ #endif
31+ .endm
32+
33+ // WRITE_BARRIER_END
34+ //
35+ // The partner to WRITE_BARRIER_ENTRY , used like NESTED_END.
36+ //
37+ .macro WRITE_BARRIER_END name
38+ #if defined(__APPLE__)
39+ .alt_entry C_FUNC(\name\()_End)
40+ .private_ extern C_FUNC(\name\()_End)
41+ C_FUNC(\name\()_End):
42+ // make sure this symbol gets its own address
43+ nop
44+ #else
45+ LEAF_END_MARKED \name , _TEXT
46+ #endif
47+ .endm
48+
849// Mark start of the code region th at we patch at runtime
50+ #if defined(__APPLE__)
51+ . global C_FUNC(JIT_PatchedCodeStart)
52+ C_FUNC(JIT_PatchedCodeStart):
53+ .cfi_startproc
54+ ret
55+ #else
956LEAF_ENTRY JIT_PatchedCodeStart , _TEXT
1057 ret
1158LEAF_END JIT_PatchedCodeStart , _TEXT
59+ #endif
1260
1361
1462// There is an even more optimized version of these helpers possible which takes
@@ -24,7 +72,7 @@ LEAF_END JIT_PatchedCodeStart, _TEXT
2472// it needs to have it's card updated
2573//
2674// void JIT_CheckedWriteBarrier(Object ** dst , Object * src)
27- LEAF_ENTRY_PATCHABLE JIT_CheckedWriteBarrier, _TEXT
75+ WRITE_BARRIER_ENTRY JIT_CheckedWriteBarrier
2876
2977 // When WRITE_BARRIER_CHECK is defined _NotInHeap will write the reference
3078 // but if it isn't then it will just return.
@@ -45,7 +93,7 @@ LEAF_ENTRY_PATCHABLE JIT_CheckedWriteBarrier, _TEXT
4593 // See comment above about possible AV
4694 mov [ rdi ], rsi
4795 ret
48- LEAF_END_MARKED JIT_CheckedWriteBarrier, _TEXT
96+ WRITE_BARRIER_END JIT_CheckedWriteBarrier
4997
5098
5199// This is used by the mechanism to hold either the JIT_WriteBarrier_PreGrow
@@ -54,7 +102,7 @@ LEAF_END_MARKED JIT_CheckedWriteBarrier, _TEXT
54102// larger of the two functions (JIT_WriteBarrier_PostGrow) to ensure we have created
55103// enough space to copy th at code in .
56104.balign 16
57- LEAF_ENTRY_PATCHABLE JIT_WriteBarrier, _TEXT
105+ WRITE_BARRIER_ENTRY JIT_WriteBarrier
58106#ifdef _DEBUG
59107 // In debug builds , this just contains jump to the debug version of the write barrier by default
60108 jmp C_FUNC(JIT_WriteBarrier_Debug)
@@ -237,9 +285,17 @@ LEAF_ENTRY_PATCHABLE JIT_WriteBarrier, _TEXT
237285 // make sure this is bigger than any of the others
238286 .balign 16
239287 nop
240- LEAF_END_MARKED JIT_WriteBarrier, _TEXT
288+ WRITE_BARRIER_END JIT_WriteBarrier
241289
242290// Mark start of the code region th at we patch at runtime
243- LEAF_ENTRY_PATCHABLE JIT_PatchedCodeLast , _TEXT
291+ #if defined(__APPLE__)
292+ .private_ extern C_FUNC(JIT_PatchedCodeLast)
293+ .alt_entry C_FUNC(JIT_PatchedCodeLast)
294+ C_FUNC(JIT_PatchedCodeLast):
295+ .cfi_endproc
296+ ret
297+ #else
298+ LEAF_ENTRY JIT_PatchedCodeLast , _TEXT
244299 ret
245300LEAF_END JIT_PatchedCodeLast , _TEXT
301+ #endif
0 commit comments