Skip to content

Commit 46c15ab

Browse files
committed
Mark all labels inside JIT_PatchedCode region as .alt_entry on Apple platforms
1 parent 07a9eeb commit 46c15ab

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

src/coreclr/pal/inc/unixasmmacrosamd64.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ C_FUNC(\Name):
5252
.cfi_endproc
5353
.endm
5454

55+
// Special version of the LEAF_ENTRY macro that should be used inside
56+
// patchable code region to prevent the linker from relocating the code.
57+
// On most Unix platforms this is identical to LEAF_ENTRY. However, on
58+
// Apple platforms it produces the function entry points at .alt_entry
59+
// symbols that create external labels but keep the whole patched region
60+
// as single atom for the linker.
61+
.macro LEAF_ENTRY_PATCHABLE Name, Section
62+
#if defined(__APPLE__)
63+
.text
64+
.p2align 4
65+
.alt_entry C_FUNC(\Name)
66+
.private_extern C_FUNC(\Name)
67+
C_FUNC(\Name):
68+
.cfi_startproc
69+
#else
70+
LEAF_ENTRY \Name, \Section
71+
#endif
72+
.endm
73+
5574
.macro LEAF_END_MARKED Name, Section
5675
#if defined(__APPLE__)
5776
.alt_entry C_FUNC(\Name\()_End)

src/coreclr/pal/inc/unixasmmacrosarm64.inc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ C_FUNC(\Name):
6363
.cfi_endproc
6464
.endm
6565

66+
// Special version of the LEAF_ENTRY macro that should be used inside
67+
// patchable code region to prevent the linker from relocating the code.
68+
// On most Unix platforms this is identical to LEAF_ENTRY. However, on
69+
// Apple platforms it produces the function entry points at .alt_entry
70+
// symbols that create external labels but keep the whole patched region
71+
// as single atom for the linker.
72+
.macro LEAF_ENTRY_PATCHABLE Name, Section
73+
#if defined(__APPLE__)
74+
.text
75+
.p2align 2
76+
.alt_entry C_FUNC(\Name)
77+
.private_extern C_FUNC(\Name)
78+
C_FUNC(\Name):
79+
.cfi_startproc
80+
#else
81+
LEAF_ENTRY \Name, \Section
82+
#endif
83+
.endm
84+
6685
.macro LEAF_END_MARKED Name, Section
6786
#if defined(__APPLE__)
6887
.alt_entry C_FUNC(\Name\()_End)

src/coreclr/vm/amd64/patchedcode.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LEAF_END JIT_PatchedCodeStart, _TEXT
2424
// it needs to have it's card updated
2525
//
2626
// void JIT_CheckedWriteBarrier(Object** dst, Object* src)
27-
LEAF_ENTRY JIT_CheckedWriteBarrier, _TEXT
27+
LEAF_ENTRY_PATCHABLE JIT_CheckedWriteBarrier, _TEXT
2828

2929
// When WRITE_BARRIER_CHECK is defined _NotInHeap will write the reference
3030
// but if it isn't then it will just return.
@@ -54,7 +54,7 @@ LEAF_END_MARKED JIT_CheckedWriteBarrier, _TEXT
5454
// larger of the two functions (JIT_WriteBarrier_PostGrow) to ensure we have created
5555
// enough space to copy that code in.
5656
.balign 16
57-
LEAF_ENTRY JIT_WriteBarrier, _TEXT
57+
LEAF_ENTRY_PATCHABLE JIT_WriteBarrier, _TEXT
5858
#ifdef _DEBUG
5959
// In debug builds, this just contains jump to the debug version of the write barrier by default
6060
jmp C_FUNC(JIT_WriteBarrier_Debug)
@@ -240,6 +240,6 @@ LEAF_ENTRY JIT_WriteBarrier, _TEXT
240240
LEAF_END_MARKED JIT_WriteBarrier, _TEXT
241241

242242
// Mark start of the code region that we patch at runtime
243-
LEAF_ENTRY JIT_PatchedCodeLast, _TEXT
243+
LEAF_ENTRY_PATCHABLE JIT_PatchedCodeLast, _TEXT
244244
ret
245245
LEAF_END JIT_PatchedCodeLast, _TEXT

src/coreclr/vm/arm64/patchedcode.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// to declare a write barrier function.
1414
//
1515
.macro WRITE_BARRIER_ENTRY name
16-
LEAF_ENTRY \name, _TEXT
16+
LEAF_ENTRY_PATCHABLE \name, _TEXT
1717
.endm
1818

1919
// WRITE_BARRIER_END
@@ -145,7 +145,7 @@ WRITE_BARRIER_END JIT_WriteBarrier_Table
145145

146146
// ------------------------------------------------------------------
147147
// End of the writeable code region
148-
LEAF_ENTRY JIT_PatchedCodeLast, _TEXT
148+
LEAF_ENTRY_PATCHABLE JIT_PatchedCodeLast, _TEXT
149149
ret lr
150150
LEAF_END JIT_PatchedCodeLast, _TEXT
151151

0 commit comments

Comments
 (0)