From 7d25e4cc800934d891acadfdaa23ae5fb83e165e Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Wed, 31 Jan 2024 22:35:52 +0100 Subject: [PATCH] Fix *AVLocation to be global labels without the Thumb bit to prevent misoptimization --- src/coreclr/nativeaot/Runtime/EHHelpers.cpp | 4 ++-- src/coreclr/nativeaot/Runtime/arm/Interlocked.S | 8 ++++---- src/coreclr/nativeaot/Runtime/arm/StubDispatch.S | 2 +- .../nativeaot/Runtime/arm/WriteBarriers.S | 16 ++++++++-------- .../nativeaot/Runtime/unix/unixasmmacrosarm.inc | 5 +++++ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/EHHelpers.cpp b/src/coreclr/nativeaot/Runtime/EHHelpers.cpp index 242acc2f99e65..b4b8e86052eb7 100644 --- a/src/coreclr/nativeaot/Runtime/EHHelpers.cpp +++ b/src/coreclr/nativeaot/Runtime/EHHelpers.cpp @@ -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 @@ -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 diff --git a/src/coreclr/nativeaot/Runtime/arm/Interlocked.S b/src/coreclr/nativeaot/Runtime/arm/Interlocked.S index 67a079863d986..631731c7e3a32 100644 --- a/src/coreclr/nativeaot/Runtime/arm/Interlocked.S +++ b/src/coreclr/nativeaot/Runtime/arm/Interlocked.S @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/coreclr/nativeaot/Runtime/arm/StubDispatch.S b/src/coreclr/nativeaot/Runtime/arm/StubDispatch.S index 05cf4f919817d..9ff29b9989b7d 100644 --- a/src/coreclr/nativeaot/Runtime/arm/StubDispatch.S +++ b/src/coreclr/nativeaot/Runtime/arm/StubDispatch.S @@ -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 diff --git a/src/coreclr/nativeaot/Runtime/arm/WriteBarriers.S b/src/coreclr/nativeaot/Runtime/arm/WriteBarriers.S index 2d22c9bf1f18b..3f7a10a859255 100644 --- a/src/coreclr/nativeaot/Runtime/arm/WriteBarriers.S +++ b/src/coreclr/nativeaot/Runtime/arm/WriteBarriers.S @@ -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] @@ -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] @@ -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 @@ -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] @@ -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. diff --git a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm.inc b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm.inc index eaf96c70609ee..b50e485106d8a 100644 --- a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm.inc +++ b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm.inc @@ -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)