Skip to content

Commit

Permalink
Fix *AVLocation to be global labels without the Thumb bit to prevent …
Browse files Browse the repository at this point in the history
…misoptimization
  • Loading branch information
filipnavara committed Jan 31, 2024
1 parent f6efcd6 commit 7d25e4c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Runtime/EHHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ static bool InWriteBarrierHelper(uintptr_t faultingIP)
ASSERT(*(uint8_t*)writeBarrierAVLocations[i] != 0xE9); // jmp XXXXXXXX
#endif

if (PCODEToPINSTR(writeBarrierAVLocations[i]) == faultingIP)
if (writeBarrierAVLocations[i] == faultingIP)
return true;
}
#endif // USE_PORTABLE_HELPERS
Expand Down Expand Up @@ -377,7 +377,7 @@ static bool InInterfaceDispatchHelper(uintptr_t faultingIP)
ASSERT(*(uint8_t*)interfaceDispatchAVLocations[i] != 0xE9); // jmp XXXXXXXX
#endif

if (PCODEToPINSTR(interfaceDispatchAVLocations[i]) == faultingIP)
if (interfaceDispatchAVLocations[i] == faultingIP)
return true;
}
#endif // USE_PORTABLE_HELPERS
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/nativeaot/Runtime/arm/Interlocked.S
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// r2 = comparand
LEAF_ENTRY RhpLockCmpXchg8, _TEXT
dmb
ALTERNATE_ENTRY RhpLockCmpXchg8AVLocation
GLOBAL_LABEL RhpLockCmpXchg8AVLocation
LOCAL_LABEL(CmpXchg8Retry):
ldrexb r3, [r0]
cmp r2, r3
Expand All @@ -38,7 +38,7 @@ LEAF_END RhpLockCmpXchg8, _TEXT
LEAF_ENTRY RhpLockCmpXchg16, _TEXT
uxth r2, r2
dmb
ALTERNATE_ENTRY RhpLockCmpXchg16AVLocation
GLOBAL_LABEL RhpLockCmpXchg16AVLocation
LOCAL_LABEL(CmpXchg16Retry):
ldrexh r3, [r0]
cmp r2, r3
Expand All @@ -60,7 +60,7 @@ LEAF_END RhpLockCmpXchg16, _TEXT
// r2 = comparand
LEAF_ENTRY RhpLockCmpXchg32, _TEXT
dmb
ALTERNATE_ENTRY RhpLockCmpXchg32AVLocation
GLOBAL_LABEL RhpLockCmpXchg32AVLocation
LOCAL_LABEL(CmpXchg32Retry):
ldrex r3, [r0]
cmp r2, r3
Expand All @@ -81,7 +81,7 @@ LEAF_END RhpLockCmpXchg32, _TEXT
// {r2,r3} = value
// sp[0+8] = comparand
LEAF_ENTRY RhpLockCmpXchg64, _TEXT
ALTERNATE_ENTRY RhpLockCmpXchg64AVLocation
GLOBAL_LABEL RhpLockCmpXchg64AVLocation
ldr r12, [r0] // dummy read for null check
PROLOG_PUSH "{r4-r6,lr}"
dmb
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/arm/StubDispatch.S
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ NESTED_ENTRY RhpInterfaceDispatch\entries, _TEXT, NoHandler
ldr r2, [r12, #OFFSETOF__InterfaceDispatchCell__m_pCache]

// Load the MethodTable from the object instance in r0.
ALTERNATE_ENTRY RhpInterfaceDispatchAVLocation\entries
GLOBAL_LABEL RhpInterfaceDispatchAVLocation\entries
ldr r1, [r0]

CurrentOffset = OFFSETOF__InterfaceDispatchCache__m_rgEntries
Expand Down
16 changes: 8 additions & 8 deletions src/coreclr/nativeaot/Runtime/arm/WriteBarriers.S
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ ALTERNATE_ENTRY RhpAssignRef

// Write the reference into the location. Note that we rely on the fact that no GC can occur between here
// and the card table update we may perform below.
ALTERNATE_ENTRY "RhpAssignRefAvLocation"\EXPORT_REG_NAME // WriteBarrierFunctionAvLocation
GLOBAL_LABEL "RhpAssignRefAvLocation"\EXPORT_REG_NAME // WriteBarrierFunctionAvLocation
.ifc \REFREG, r1
ALTERNATE_ENTRY RhpAssignRefAVLocation
GLOBAL_LABEL RhpAssignRefAVLocation
.endif
str \REFREG, [r0]

Expand Down Expand Up @@ -234,9 +234,9 @@ ALTERNATE_ENTRY RhpCheckedAssignRef
dmb
// Write the reference into the location. Note that we rely on the fact that no GC can occur between here
// and the card table update we may perform below.
ALTERNATE_ENTRY "RhpCheckedAssignRefAvLocation"\EXPORT_REG_NAME // WriteBarrierFunctionAvLocation
GLOBAL_LABEL "RhpCheckedAssignRefAvLocation"\EXPORT_REG_NAME // WriteBarrierFunctionAvLocation
.ifc \REFREG, r1
ALTERNATE_ENTRY RhpCheckedAssignRefAVLocation
GLOBAL_LABEL RhpCheckedAssignRefAVLocation
.endif
str \REFREG, [r0]

Expand All @@ -261,7 +261,7 @@ LEAF_ENTRY RhpCheckedLockCmpXchg, _TEXT
// barrier must occur before the object reference update, so we have to do it unconditionally even
// though the update may fail below.
dmb
ALTERNATE_ENTRY RhpCheckedLockCmpXchgAVLocation
GLOBAL_LABEL RhpCheckedLockCmpXchgAVLocation
LOCAL_LABEL(RhpCheckedLockCmpXchgRetry):
ldrex r3, [r0]
cmp r2, r3
Expand All @@ -286,7 +286,7 @@ LEAF_ENTRY RhpCheckedXchg, _TEXT
// To implement our chosen memory model for ARM we insert a memory barrier at GC write barriers. This
// barrier must occur before the object reference update.
dmb
ALTERNATE_ENTRY RhpCheckedXchgAVLocation
GLOBAL_LABEL RhpCheckedXchgAVLocation
LOCAL_LABEL(RhpCheckedXchgRetry):
ldrex r2, [r0]
strex r3, r1, [r0]
Expand Down Expand Up @@ -320,9 +320,9 @@ LEAF_ENTRY RhpByRefAssignRef, _TEXT
// See comment in RhpAssignRef
dmb

ALTERNATE_ENTRY RhpByRefAssignRefAVLocation1
GLOBAL_LABEL RhpByRefAssignRefAVLocation1
ldr r2, [r1]
ALTERNATE_ENTRY RhpByRefAssignRefAVLocation2
GLOBAL_LABEL RhpByRefAssignRefAVLocation2
str r2, [r0]

// Check whether the writes were even into the heap. If not there's no card update required.
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ C_FUNC(\Name):
C_FUNC(\Name):
.endm

.macro GLOBAL_LABEL Name
.global C_FUNC(\Name)
C_FUNC(\Name):
.endm

.macro LEAF_ENTRY Name, Section
.thumb_func
.global C_FUNC(\Name)
Expand Down

0 comments on commit 7d25e4c

Please sign in to comment.