-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reloc failures with NativeAOT on Apple Silicon #67232
Comments
Ah, so those messages are still generated by the object writer in ILC. For example here: https://github.com/dotnet/llvm-project/blob/f1120a92d05f1c57e75af7d16504012570ef3409/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp#L102-L103. Looks like we need to decide what kind of relocation to generate when we're generating it. |
@MichalStrehovsky, thanks for the pointers. The managed part of objwriter API currently does not support
but this one remains:
it is |
Really nice progress! What is the reloc it's complaining about? Is it You'll know if the reloc got messed up if it ends up pointing at garbage after linking. |
Those were indeed all Pushed a commit to treat it as clang task, however, continues to fail (still complaining about Running % "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" \
-demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib \
-dynamic -arch arm64 -platform_version macos 12.0.0 12.1 \
-syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
-o bin/release/net7.0/osx-arm64/native/naot1 \
-L/usr/local/lib obj/release/net7.0/osx-arm64/native/naot1.o \
/Users/am11/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/7.0.0-dev/sdk/libbootstrapper.a \
/Users/am11/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/7.0.0-dev/sdk/libRuntime.WorkstationGC.a \
/Users/am11/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/7.0.0-dev/framework/libSystem.Native.a \
/Users/am11/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/7.0.0-dev/framework/libSystem.Globalization.Native.a \
/Users/am11/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/7.0.0-dev/framework/libSystem.IO.Compression.Native.a \
/Users/am11/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/7.0.0-dev/framework/libSystem.Net.Security.Native.a \
/Users/am11/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/7.0.0-dev/framework/libSystem.Security.Cryptography.Native.Apple.a \
-rpath @executable_path -lc++ -ldl -lm -lz -licucore \
-framework CoreFoundation -framework Foundation -framework Security -framework GSS \
-lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/lib/darwin/libclang_rt.osx.a \
-v
@(#)PROGRAM:ld PROJECT:ld64-711
BUILD 21:57:24 Nov 17 2021
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
/usr/local/lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
Framework search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/
ld: malformed __LD,__compact_unwind section, bad length file 'obj/release/net7.0/osx-arm64/native/naot1.o' |
Digging in Apple's source code, the error seems to be: the size of __compact_unwind section is not divisible by the size of the unwind entry. That's odd because we don't generate the Apple weird thing, we generate DWARF CFI. However, looking at LLVM source code, I think this is kicking in: And LLVM does generate something on our behalf. Probably broken from the sound of it. I would dig around that - can we still make do without a __compact_unwind section? If it's not present in the executable, maybe ld would still do the right thing and convert it from CFI to the compact unwind scheme for us. Maybe the right thing would be to start generating compact unwinding because Apple tends to unceremoniously cut off things they don't like anymore after a couple years of supporting both the thing they stopped liking and the new shiny thing. Unwinding codes are currently generated in RyuJIT. |
Thanks, and nice detective work finding those links! (I was only searching across org:dotnet 😅) Disabling compact unwind (dotnet/llvm-project@090a465) revealed some missing symbols errors. Those error messages were generous enough to point me to the missing Looks like we are getting there. Next error is:
Apparently, reloc 15 is assigned to |
Can you try updating this: runtime/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs Lines 94 to 100 in 59bb459
and make it so that it returns This will make the compiler avoid generating 32bit relative relocations in favor of full pointers. It will make the executables a bit bigger. We would want to try find a way to do 32bit relative relocs eventually, but let's first find out if that's really the problem. |
Having SupportsRelativePointers to return false had no effect, getting the ditto ld error. :( |
Ah, there's an extra code path that is not active for Wasm or CppCodegen (for which |
Thanks, this workaround worked for
I'll try to find out what is causing type 15 failure (to avoid workarounds). |
Yeah, that sounds like a better plan. This workaround is starting to get out of hand (I think now it's relocs generated by RyuJIT). I was able to make quick progress on issues like this in the past by reducing the problem into a ZeroSharp no-runtime size (https://github.com/MichalStrehovsky/zerosharp) repro case. The object files generated out of that are just a couple kilobytes in size and it's easier to trace through the problematic code within the compiler with that. But it's not mandatory to go in that direction, just a possible avenue if too many things are happening in a full Hello World. |
Pushed a commit to objwriter (dotnet/llvm-project@7280b55) which fixes type 15 error. After that % lldb bin/release/net7.0/osx-arm64/publish/naot1
Added Microsoft public symbol server
Added symbol directory path: /usr/local/share/dotnet/shared/Microsoft.NETCore.App/6.0.2
Added symbol directory path: /usr/local/share/dotnet/packs/Microsoft.NETCore.App.Host.osx-arm64/6.0.2/runtimes/osx-arm64/native
(lldb) target create "../naot1/bin/release/net7.0/osx-arm64/publish/naot1"
Current executable set to '/Users/am11/projects/naot1/bin/release/net7.0/osx-arm64/publish/naot1' (arm64).
(lldb) r
Process 38291 launched: '/Users/am11/projects/naot1/bin/release/net7.0/osx-arm64/publish/naot1' (arm64)
Process 38291 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x100460988)
frame #0: 0x0000000100460988 naot1`tls_CurrentThread
naot1`tls_CurrentThread:
-> 0x100460988 <+0>: ldp x16, x17, [x9, #-0xd0]
0x10046098c <+4>: udf #0x1
0x100460990 <+8>: udf #0x102
0x100460994 <+12>: udf #0x0
Target 0: (naot1) stopped.
(lldb) bt all
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x100460988)
* frame #0: 0x0000000100460988 naot1`tls_CurrentThread
frame #1: 0x00000001001a6db0 naot1`InitializeModules + 80
frame #2: 0x0000000100006438 naot1`main [inlined] InitializeRuntime() at main.cpp:169:5 [opt]
frame #3: 0x00000001000063ac naot1`main(argc=1, argv=0x000000016fdff798) at main.cpp:201:19 [opt]
frame #4: 0x0000000100c350f4 dyld`start + 520
thread #2
frame #0: 0x00000001a96f1eac libsystem_kernel.dylib`mach_absolute_time + 108
frame #1: 0x00000001a96f3838 libsystem_kernel.dylib`__commpage_gettimeofday_internal + 44
frame #2: 0x00000001a95f9534 libsystem_c.dylib`gettimeofday + 52
frame #3: 0x000000010004fcb4 naot1`::QueryPerformanceCounter(lpPerformanceCount=0x000000016fe86f68) at PalRedhawkUnix.cpp:1090:9 [opt]
frame #4: 0x0000000100012090 naot1`EnsureYieldProcessorNormalizedInitialized() [inlined] PalQueryPerformanceCounter(arg1=0x000000016fe86f68) at PalRedhawkFunctions.h:131:12 [opt]
frame #5: 0x0000000100012088 naot1`EnsureYieldProcessorNormalizedInitialized() at yieldprocessornormalized.cpp:76:9 [opt]
frame #6: 0x0000000100012024 naot1`EnsureYieldProcessorNormalizedInitialized() at yieldprocessornormalized.cpp:118:9 [opt]
frame #7: 0x000000010000801c naot1`FinalizerStart(pContext=0x0000600003000090) at FinalizerHelpers.cpp:54:5 [opt]
frame #8: 0x00000001a972d240 libsystem_pthread.dylib`_pthread_start + 148 |
Great progress! If I'm looking at the right thing, |
Yup, that was it: am11@5106fc9 (based on ELF sequence vs. MachO) It has moved the needle a bit; next up is (lldb) r
Process 89591 launched: '/Users/am11/projects/naot1/bin/release/net7.0/osx-arm64/publish/naot1' (arm64)
This version of LLDB has no plugin for the mipsassem language. Inspection of frame variables will be limited.
Process 89591 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x1a9734530)
frame #0: 0x000000010005c750 naot1`RhpNewArray at AllocFast.S:213
210 ldr x12, [x3, #OFFSETOF__Thread__m_alloc_context__alloc_ptr]
211
212 // Update the alloc pointer to account for the allocation.
-> 213 str x2, [x3, #OFFSETOF__Thread__m_alloc_context__alloc_ptr]
214
215 // Set the new objects MethodTable pointer and element count.
216 str x0, [x12, #OFFSETOF__Object__m_pEEType]
Target 0: (naot1) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x1a9734530)
* frame #0: 0x000000010005c750 naot1`RhpNewArray at AllocFast.S:213
frame #1: 0x00000001001a7114 naot1`S_P_CoreLib_Internal_Runtime_CompilerHelpers_StartupCodeHelpers__CreateTypeManagers + 100
frame #2: 0x00000001001a6db0 naot1`InitializeModules + 80
frame #3: 0x0000000100006458 naot1`main [inlined] InitializeRuntime() at main.cpp:169:5 [opt]
frame #4: 0x00000001000063cc naot1`main(argc=1, argv=0x000000016fdff7a0) at main.cpp:201:19 [opt]
frame #5: 0x0000000100c350f4 dyld`start + 520
(lldb) register read
General Purpose Registers:
x0 = 0x0000000100f04290
x1 = 0x0000000000000001
x2 = 0xd53bd071f9400430
x3 = 0x00000001a9734530 libdyld.dylib`tlv_get_addr
x4 = 0x000000000000000a
x5 = 0x0000000000000000
x6 = 0x0000000000000002
x7 = 0x0000000000000000
x8 = 0x00000000ffffffff
x9 = 0x0000000000000000
x10 = 0x0000000000000070
x11 = 0x0000000000000001
x12 = 0xd53bd071f9400410
x13 = 0x0000000001dfb800
x14 = 0x0000000001c00000
x15 = 0x0000000000000044
x16 = 0x0000000000000000
x17 = 0x0000000100f04290
x18 = 0x0000000000000000
x19 = 0x0000000000000001
x20 = 0x0000000100460968 naot1`__Module
x21 = 0x0000000100000000 naot1`_mh_execute_header
x22 = 0x00000001003773a0 naot1`c_classlibFunctions
x23 = 0x000000000000000a
x24 = 0x0000000000000000
x25 = 0x0000000000000000
x26 = 0x0000000000000000
x27 = 0x0000000000000000
x28 = 0x0000000000000000
fp = 0x000000016fdff570
lr = 0x000000010005c738 naot1`RhpNewArray + 56
sp = 0x000000016fdff560
pc = 0x000000010005c750 naot1`RhpNewArray + 80
cpsr = 0x80001000
# a weird "error: warning: warning:" from printer
(lldb) p OFFSETOF__Thread__m_alloc_context__alloc_ptr
error: warning: warning: got name from symbols: OFFSETOF__Thread__m_alloc_context__alloc_ptr
error: <user expression 8>:1:1: reference to 'OFFSETOF__Thread__m_alloc_context__alloc_ptr' is ambiguous
OFFSETOF__Thread__m_alloc_context__alloc_ptr
^
note: candidate found by name lookup is 'OFFSETOF__Thread__m_alloc_context__alloc_ptr'
note: candidate found by name lookup is 'OFFSETOF__Thread__m_alloc_context__alloc_ptr'
# but this suggests offset is zero
(lldb) image lookup -n OFFSETOF__Thread__m_alloc_context__alloc_ptr
1 match found in /Users/am11/projects/naot1/bin/release/net7.0/osx-arm64/publish/naot1:
Address: 0x0000000000000000 (0x0000000000000000)
Summary: 0x0000000000000000 |
That looks related to the TLS access. We're here: runtime/src/coreclr/nativeaot/Runtime/arm64/AllocFast.S Lines 193 to 213 in 9b2e2a8
My suspicion is that runtime/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc Lines 215 to 217 in 9b2e2a8
I would put a breakpoint here: runtime/src/coreclr/nativeaot/Runtime/threadstore.inl Lines 6 to 10 in 9b2e2a8
and see what value the variable has (and how the compiler got to it in assembly). Then compare with what INLINE_GETTHREAD came up with. (Make sure you're looking at the same thread, we already have the finalizer thread running at this point in startup). |
Ah, right, had to move x0 to the target register and also pop stack before endm for Now we are in the managed main and getting to the code emitted via objwriter: (lldb) target create "../naot1/bin/release/net7.0/osx-arm64/native/naot1"
Current executable set to '/Users/am11/projects/naot1/bin/release/net7.0/osx-arm64/native/naot1' (arm64).
(lldb) r
Process 86586 launched: '/Users/am11/projects/naot1/bin/release/net7.0/osx-arm64/native/naot1' (arm64)
Process 86586 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x00000001001fa8a4 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 52
naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create:
-> 0x1001fa8a4 <+52>: ldr x1, [x0]
0x1001fa8a8 <+56>: ldr x1, [x1, #0x1e8]
0x1001fa8ac <+60>: blr x1
0x1001fa8b0 <+64>: bl 0x1001a3b10 ; S_P_CoreLib_Internal_IntrinsicSupport_EqualityComparerHelpers__GetComparer
Target 0: (naot1) stopped.
(lldb) bt all
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
* frame #0: 0x00000001001fa8a4 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 52
frame #1: 0x0000000100190dd4 naot1`S_P_CoreLib_System_Collections_Generic_NonRandomizedStringEqualityComparer___cctor + 36
frame #2: 0x000000010019722c naot1`S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__EnsureClassConstructorRun + 204
frame #3: 0x00000001001970e4 naot1`S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__CheckStaticClassConstructionReturnGCStaticBase + 20
frame #4: 0x0000000100190d48 naot1`S_P_CoreLib_System_Collections_Generic_NonRandomizedStringEqualityComparer__GetStringComparer + 24
frame #5: 0x000000010020cc80 naot1`S_P_CoreLib_System_Collections_Generic_Dictionary_2<System___Canon__System___Canon>___ctor_2 + 128
frame #6: 0x00000001000e2a04 naot1`S_P_CoreLib_System_AppContext__SetData + 84
frame #7: 0x00000001002125a0 naot1`Internal_CompilerGenerated__Module___SetAppContextSwitches + 32
frame #8: 0x0000000100212734 naot1`__managed__Main + 228
frame #9: 0x0000000100006454 naot1`main(argc=1, argv=0x000000016fdff798) at main.cpp:205:18 [opt]
frame #10: 0x0000000100c350f4 dyld`start + 520
thread #2
frame #0: 0x00000001a96f1eac libsystem_kernel.dylib`mach_absolute_time + 108
frame #1: 0x00000001a96f3838 libsystem_kernel.dylib`__commpage_gettimeofday_internal + 44
frame #2: 0x00000001a95f9534 libsystem_c.dylib`gettimeofday + 52
frame #3: 0x000000010004fcc4 naot1`::QueryPerformanceCounter(lpPerformanceCount=0x000000016fe86f68) at PalRedhawkUnix.cpp:1090:9 [opt]
frame #4: 0x00000001000120a0 naot1`EnsureYieldProcessorNormalizedInitialized() [inlined] PalQueryPerformanceCounter(arg1=0x000000016fe86f68) at PalRedhawkFunctions.h:131:12 [opt]
frame #5: 0x0000000100012098 naot1`EnsureYieldProcessorNormalizedInitialized() at yieldprocessornormalized.cpp:76:9 [opt]
frame #6: 0x0000000100012034 naot1`EnsureYieldProcessorNormalizedInitialized() at yieldprocessornormalized.cpp:118:9 [opt]
frame #7: 0x000000010000802c naot1`FinalizerStart(pContext=0x0000600003000090) at FinalizerHelpers.cpp:54:5 [opt]
frame #8: 0x00000001a972d240 libsystem_pthread.dylib`_pthread_start + 148
(lldb) register read
General Purpose Registers:
x0 = 0x0000000000000000
x1 = 0x0000000100373628 (void *)0x0000000100469238: __writableDataString
x2 = 0x00000001003eeaf0 __TypeThreadStaticIndexS_P_CoreLib_System_Threading_ManagedThreadId
x3 = 0x0000000000000018
x4 = 0x0000000000000000
x5 = 0x0000000101800000
x6 = 0x0000000000000007
x7 = 0x0000000000000000
x8 = 0x0000000100ec11f0
x9 = 0x0000600000004090
x10 = 0x00000001a9734530 libdyld.dylib`tlv_get_addr
x11 = 0x0000000000000001
x12 = 0x000000010045f1e8 g_ephemeral_high
x13 = 0x0000000101807fd0
x14 = 0x0000000101806608
x15 = 0x0000000101806620
x16 = 0x0000000000000000
x17 = 0x0000000100f04290
x18 = 0x0000000000000000
x19 = 0x000000010041bf70 vtable for S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<String>
x20 = 0x00000001198061d8
x21 = 0x00000001198061e0
x22 = 0x0000000101806440
x23 = 0x0000000119804820
x24 = 0x0000000000000000
x25 = 0x0000000000000000
x26 = 0x0000000000000000
x27 = 0x0000000000000000
x28 = 0x0000000000000000
fp = 0x000000016fdff420
lr = 0x00000001001fa8a4 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 52
sp = 0x000000016fdff420
pc = 0x00000001001fa8a4 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 52
cpsr = 0x60001000 |
This doesn't ring any bell - can you paste the full disassembly of the faulting method? It's not clear where we are. I'm guessing that this is an attempt to do a virtual call to access the Line 30 in 07e87bc
...but the Lines 34 to 37 in 07e87bc
Validate that the parameter to the method is correct (it should be a Might be easier to debug through this with optimizations off (drop the |
With debug, here is the full disassembly at IP/PC ( (lldb) r
Process 88778 launched: '/Users/am11/projects/naot1/bin/Debug/net7.0/osx-arm64/publish/naot1' (arm64)
Process 88778 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x00000001002f0bb8 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 168
naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create:
-> 0x1002f0bb8 <+168>: ldr wzr, [x0]
0x1002f0bbc <+172>: blr x1
0x1002f0bc0 <+176>: str x0, [x29, #0x48]
0x1002f0bc4 <+180>: ldr x0, [x29, #0x48]
Target 0: (naot1) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
* frame #0: 0x00000001002f0bb8 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 168
frame #1: 0x00000001002f0c74 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__get_Default + 68
frame #2: 0x000000010023dec4 naot1`S_P_CoreLib_System_Collections_Generic_NonRandomizedStringEqualityComparer___cctor + 36
frame #3: 0x0000000100247ba0 naot1`S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__EnsureClassConstructorRun + 384
frame #4: 0x0000000100247988 naot1`S_P_CoreLib_System_Runtime_CompilerServices_ClassConstructorRunner__CheckStaticClassConstructionReturnGCStaticBase + 24
frame #5: 0x000000010023de28 naot1`S_P_CoreLib_System_Collections_Generic_NonRandomizedStringEqualityComparer__GetStringComparer + 40
frame #6: 0x000000010030e32c naot1`S_P_CoreLib_System_Collections_Generic_Dictionary_2<System___Canon__System___Canon>___ctor_2 + 268
frame #7: 0x000000010030e1dc naot1`S_P_CoreLib_System_Collections_Generic_Dictionary_2<System___Canon__System___Canon>___ctor + 28
frame #8: 0x0000000100123414 naot1`S_P_CoreLib_System_AppContext__SetData + 116
frame #9: 0x0000000100317a9c naot1`Internal_CompilerGenerated__Module___SetAppContextSwitches + 28
frame #10: 0x0000000100317bbc naot1`__managed__Main + 60
frame #11: 0x000000010000df64 naot1`main(argc=1, argv=0x000000016fdff7a0) at main.cpp:205:18 [opt]
frame #12: 0x0000000100f190f4 dyld`start + 520
(lldb) disassemble -a 0x1002f0bb8
naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create:
0x1002f0b10 <+0>: stp x29, x30, [sp, #-0x90]!
0x1002f0b14 <+4>: mov x29, sp
0x1002f0b18 <+8>: add x9, x29, #0x28 ; =0x28
0x1002f0b1c <+12>: movi.16b v16, #0x0
0x1002f0b20 <+16>: stp q16, q16, [x9]
0x1002f0b24 <+20>: stp q16, q16, [x9, #0x20]
0x1002f0b28 <+24>: stp xzr, xzr, [x9, #0x40]
0x1002f0b2c <+28>: str xzr, [x9, #0x50]
0x1002f0b30 <+32>: str x0, [x29, #0x88]
0x1002f0b34 <+36>: str x0, [x29, #0x80]
0x1002f0b38 <+40>: ldr x0, [x29, #0x80]
0x1002f0b3c <+44>: bl 0x10000b380 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_GCStaticBase_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>
0x1002f0b40 <+48>: add x0, x0, #0x8 ; =0x8
0x1002f0b44 <+52>: str x0, [x29, #0x78]
0x1002f0b48 <+56>: ldr x0, [x29, #0x80]
0x1002f0b4c <+60>: bl 0x10000bd54 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_TypeHandle_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>
0x1002f0b50 <+64>: bl 0x1002f0af0 ; S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__get_SupportsGenericIEquatableInterfaces
0x1002f0b54 <+68>: str w0, [x29, #0x74]
0x1002f0b58 <+72>: ldr x0, [x29, #0x78]
0x1002f0b5c <+76>: str x0, [x29, #0x68]
0x1002f0b60 <+80>: ldr w0, [x29, #0x74]
0x1002f0b64 <+84>: cbnz w0, 0x1002f0b88 ; <+120>
0x1002f0b68 <+88>: nop
0x1002f0b6c <+92>: nop
0x1002f0b70 <+96>: nop
0x1002f0b74 <+100>: nop
0x1002f0b78 <+104>: nop
0x1002f0b7c <+108>: ldr x0, [x29, #0x68]
0x1002f0b80 <+112>: str x0, [x29, #0x28]
0x1002f0b84 <+116>: b 0x1002f0b84 ; <+116>
0x1002f0b88 <+120>: ldr x0, [x29, #0x80]
0x1002f0b8c <+124>: bl 0x10000bd60 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_TypeHandle_T_System___Canon
0x1002f0b90 <+128>: bl 0x100261960 ; S_P_CoreLib_Internal_Runtime_CompilerHelpers_LdTokenHelpers__GetRuntimeTypeHandle
0x1002f0b94 <+132>: str x0, [x29, #0x60]
0x1002f0b98 <+136>: ldr x0, [x29, #0x60]
0x1002f0b9c <+140>: bl 0x100140890 ; S_P_CoreLib_System_Type__GetTypeFromHandle
0x1002f0ba0 <+144>: str x0, [x29, #0x58]
0x1002f0ba4 <+148>: adrp x0, -747
0x1002f0ba8 <+152>: add x0, x0, #0x4a8 ; =0x4a8
0x1002f0bac <+156>: str x0, [x29, #0x50]
0x1002f0bb0 <+160>: ldr x0, [x29, #0x58]
0x1002f0bb4 <+164>: ldr x1, [x29, #0x50]
-> 0x1002f0bb8 <+168>: ldr wzr, [x0]
0x1002f0bbc <+172>: blr x1
0x1002f0bc0 <+176>: str x0, [x29, #0x48]
0x1002f0bc4 <+180>: ldr x0, [x29, #0x48]
0x1002f0bc8 <+184>: bl 0x1002596d0 ; S_P_CoreLib_Internal_IntrinsicSupport_EqualityComparerHelpers__GetComparer
0x1002f0bcc <+188>: str x0, [x29, #0x40]
0x1002f0bd0 <+192>: ldr x0, [x29, #0x80]
0x1002f0bd4 <+196>: bl 0x10000c954 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_MethodDictionary_S_P_CoreLib_System_Runtime_CompilerServices_Unsafe__As<S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>>
0x1002f0bd8 <+200>: str x0, [x29, #0x20]
0x1002f0bdc <+204>: ldr x0, [x29, #0x20]
0x1002f0be0 <+208>: ldr x1, [x29, #0x40]
0x1002f0be4 <+212>: bl 0x100370490 ; S_P_CoreLib_System_Runtime_CompilerServices_Unsafe__As<System___Canon>
0x1002f0be8 <+216>: str x0, [x29, #0x38]
0x1002f0bec <+220>: ldr x0, [x29, #0x80]
0x1002f0bf0 <+224>: bl 0x10000c948 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_MethodDictionary_S_P_CoreLib_System_Threading_Interlocked__CompareExchange_3<S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>>
0x1002f0bf4 <+228>: str x0, [x29, #0x18]
0x1002f0bf8 <+232>: ldr x0, [x29, #0x18]
0x1002f0bfc <+236>: ldr x1, [x29, #0x68]
0x1002f0c00 <+240>: ldr x2, [x29, #0x38]
0x1002f0c04 <+244>: mov x3, xzr
0x1002f0c08 <+248>: bl 0x10036f770 ; S_P_CoreLib_System_Threading_Interlocked__CompareExchange_3<System___Canon>
0x1002f0c0c <+252>: str x0, [x29, #0x30]
0x1002f0c10 <+256>: nop
0x1002f0c14 <+260>: ldr x0, [x29, #0x80]
0x1002f0c18 <+264>: bl 0x10000b380 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_GCStaticBase_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>
0x1002f0c1c <+268>: ldr x0, [x0, #0x8]
0x1002f0c20 <+272>: ldp x29, x30, [sp], #0x90
0x1002f0c24 <+276>: ret
0x1002f0c28 <+280>: udf #0x0
0x1002f0c2c <+284>: udf #0x0
(lldb) register read
General Purpose Registers:
x0 = 0x0000000000000000
x1 = 0x00000001000054a8 naot1`__VirtualCall_S_P_CoreLib_System_Type__get_TypeHandle
x2 = 0x000000000000000a
x3 = 0x0000000102006668
x4 = 0x0000000000000020
x5 = 0x0000000000000003
x6 = 0x0000000000000007
x7 = 0x0000000000000000
x8 = 0x00000001011a11f0
x9 = 0x000000016fdff218
x10 = 0x00000001a9734530 libdyld.dylib`tlv_get_addr
x11 = 0x0000000000000001
x12 = 0x00000001005fe7a8 g_ephemeral_high
x13 = 0x0000000102007fd0
x14 = 0x0000000102006638
x15 = 0x0000000102006650
x16 = 0x0000000000000000
x17 = 0x0000000101204290
x18 = 0x0000000000000000
x19 = 0x000000016fdff7a0
x20 = 0x0000000000000001
x21 = 0x0000000100000000 naot1`_mh_execute_header
x22 = 0x0000000000000000
x23 = 0x0000000000000000
x24 = 0x0000000000000000
x25 = 0x0000000000000000
x26 = 0x0000000000000000
x27 = 0x0000000000000000
x28 = 0x0000000000000000
fp = 0x000000016fdff290
lr = 0x00000001002f0ba0 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 144
sp = 0x000000016fdff290
pc = 0x00000001002f0bb8 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 168
cpsr = 0x20001000
BTW, runtime's build.sh also produced |
I'm still looking at the disassembly, but while I'm doing that - the compiler produces DWARF debug information so you should be getting line numbers and local variables. It's supposed to debug like C++. Make sure ILC is invoked with the |
Yup, |
Can you dump what's in x0 at the spot where we call If x0 is already bogus at that point, check x0 before the call to
Just to double check - do you get line debugging and local variables as well? |
(lldb) r
Process 89722 launched: '/Users/am11/projects/naot1/bin/Debug/net7.0/osx-arm64/publish/naot1' (arm64)
Process 89722 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x00000001002f0bb8 naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 168
naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create:
-> 0x1002f0bb8 <+168>: ldr wzr, [x0]
0x1002f0bbc <+172>: blr x1
0x1002f0bc0 <+176>: str x0, [x29, #0x48]
0x1002f0bc4 <+180>: ldr x0, [x29, #0x48]
Target 0: (naot1) stopped.
(lldb) disassemble -a 0x1002f0bb8
naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create:
0x1002f0b10 <+0>: stp x29, x30, [sp, #-0x90]!
0x1002f0b14 <+4>: mov x29, sp
0x1002f0b18 <+8>: add x9, x29, #0x28 ; =0x28
0x1002f0b1c <+12>: movi.16b v16, #0x0
0x1002f0b20 <+16>: stp q16, q16, [x9]
0x1002f0b24 <+20>: stp q16, q16, [x9, #0x20]
0x1002f0b28 <+24>: stp xzr, xzr, [x9, #0x40]
0x1002f0b2c <+28>: str xzr, [x9, #0x50]
0x1002f0b30 <+32>: str x0, [x29, #0x88]
0x1002f0b34 <+36>: str x0, [x29, #0x80]
0x1002f0b38 <+40>: ldr x0, [x29, #0x80]
0x1002f0b3c <+44>: bl 0x10000b380 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_GCStaticBase_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>
0x1002f0b40 <+48>: add x0, x0, #0x8 ; =0x8
0x1002f0b44 <+52>: str x0, [x29, #0x78]
0x1002f0b48 <+56>: ldr x0, [x29, #0x80]
0x1002f0b4c <+60>: bl 0x10000bd54 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_TypeHandle_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>
0x1002f0b50 <+64>: bl 0x1002f0af0 ; S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__get_SupportsGenericIEquatableInterfaces
0x1002f0b54 <+68>: str w0, [x29, #0x74]
0x1002f0b58 <+72>: ldr x0, [x29, #0x78]
0x1002f0b5c <+76>: str x0, [x29, #0x68]
0x1002f0b60 <+80>: ldr w0, [x29, #0x74]
0x1002f0b64 <+84>: cbnz w0, 0x1002f0b88 ; <+120>
0x1002f0b68 <+88>: nop
0x1002f0b6c <+92>: nop
0x1002f0b70 <+96>: nop
0x1002f0b74 <+100>: nop
0x1002f0b78 <+104>: nop
0x1002f0b7c <+108>: ldr x0, [x29, #0x68]
0x1002f0b80 <+112>: str x0, [x29, #0x28]
0x1002f0b84 <+116>: b 0x1002f0b84 ; <+116>
0x1002f0b88 <+120>: ldr x0, [x29, #0x80]
0x1002f0b8c <+124>: bl 0x10000bd60 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_TypeHandle_T_System___Canon
0x1002f0b90 <+128>: bl 0x100261960 ; S_P_CoreLib_Internal_Runtime_CompilerHelpers_LdTokenHelpers__GetRuntimeTypeHandle
0x1002f0b94 <+132>: str x0, [x29, #0x60]
0x1002f0b98 <+136>: ldr x0, [x29, #0x60]
0x1002f0b9c <+140>: bl 0x100140890 ; S_P_CoreLib_System_Type__GetTypeFromHandle
0x1002f0ba0 <+144>: str x0, [x29, #0x58]
0x1002f0ba4 <+148>: adrp x0, -747
0x1002f0ba8 <+152>: add x0, x0, #0x4a8 ; =0x4a8
0x1002f0bac <+156>: str x0, [x29, #0x50]
0x1002f0bb0 <+160>: ldr x0, [x29, #0x58]
0x1002f0bb4 <+164>: ldr x1, [x29, #0x50]
-> 0x1002f0bb8 <+168>: ldr wzr, [x0]
0x1002f0bbc <+172>: blr x1
0x1002f0bc0 <+176>: str x0, [x29, #0x48]
0x1002f0bc4 <+180>: ldr x0, [x29, #0x48]
0x1002f0bc8 <+184>: bl 0x1002596d0 ; S_P_CoreLib_Internal_IntrinsicSupport_EqualityComparerHelpers__GetComparer
0x1002f0bcc <+188>: str x0, [x29, #0x40]
0x1002f0bd0 <+192>: ldr x0, [x29, #0x80]
0x1002f0bd4 <+196>: bl 0x10000c954 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_MethodDictionary_S_P_CoreLib_System_Runtime_CompilerServices_Unsafe__As<S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>>
0x1002f0bd8 <+200>: str x0, [x29, #0x20]
0x1002f0bdc <+204>: ldr x0, [x29, #0x20]
0x1002f0be0 <+208>: ldr x1, [x29, #0x40]
0x1002f0be4 <+212>: bl 0x100370490 ; S_P_CoreLib_System_Runtime_CompilerServices_Unsafe__As<System___Canon>
0x1002f0be8 <+216>: str x0, [x29, #0x38]
0x1002f0bec <+220>: ldr x0, [x29, #0x80]
0x1002f0bf0 <+224>: bl 0x10000c948 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_MethodDictionary_S_P_CoreLib_System_Threading_Interlocked__CompareExchange_3<S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>>
0x1002f0bf4 <+228>: str x0, [x29, #0x18]
0x1002f0bf8 <+232>: ldr x0, [x29, #0x18]
0x1002f0bfc <+236>: ldr x1, [x29, #0x68]
0x1002f0c00 <+240>: ldr x2, [x29, #0x38]
0x1002f0c04 <+244>: mov x3, xzr
0x1002f0c08 <+248>: bl 0x10036f770 ; S_P_CoreLib_System_Threading_Interlocked__CompareExchange_3<System___Canon>
0x1002f0c0c <+252>: str x0, [x29, #0x30]
0x1002f0c10 <+256>: nop
0x1002f0c14 <+260>: ldr x0, [x29, #0x80]
0x1002f0c18 <+264>: bl 0x10000b380 ; __GenericLookupFromType_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>_GCStaticBase_S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<T_System___Canon>
0x1002f0c1c <+268>: ldr x0, [x0, #0x8]
0x1002f0c20 <+272>: ldp x29, x30, [sp], #0x90
0x1002f0c24 <+276>: ret
0x1002f0c28 <+280>: udf #0x0
0x1002f0c2c <+284>: udf #0x0
(lldb) b -a 0x1002f0b9c
Breakpoint 1: where = naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 140, address = 0x00000001002f0b9c
(lldb) r
There is a running process, kill it and restart?: [Y/n] Y
Process 89722 exited with status = 9 (0x00000009)
Process 89732 launched: '/Users/am11/projects/naot1/bin/Debug/net7.0/osx-arm64/publish/naot1' (arm64)
Process 89732 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x00000001002f0b9c naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create + 140
naot1`S_P_CoreLib_System_Collections_Generic_EqualityComparer_1<System___Canon>__Create:
-> 0x1002f0b9c <+140>: bl 0x100140890 ; S_P_CoreLib_System_Type__GetTypeFromHandle
0x1002f0ba0 <+144>: str x0, [x29, #0x58]
0x1002f0ba4 <+148>: adrp x0, -747
0x1002f0ba8 <+152>: add x0, x0, #0x4a8 ; =0x4a8
Target 0: (naot1) stopped.
(lldb) register read x0
x0 = 0x00000001005a0620 vtable for String
(lldb) image lookup -va 0x00000001005a0620
Address: naot1[0x00000001005a0620] (naot1.__DATA.__data + 297760)
Summary: vtable for String
Module: file = "/Users/am11/projects/naot1/bin/Debug/net7.0/osx-arm64/publish/naot1", arch = "arm64"
Symbol: id = {0x00008410}, range = [0x00000001005a0620-0x00000001005a0698), name="vtable for String", mangled="_ZTV6String" |
Or fix the JIT to produce frames that are compatible with compact unwinding. |
That's also an option. I started reading the design document and there are some limits on what the instruction encoding allows in terms of offsets... Overall I think there are multiple viable ways to fix it but it's relatively easy to get it working in some way now that I know what is happening. |
You would need to map the memory with MAP_JIT flag (see MEM_RESERVE_EXECUTABLE in CLR code). Writes to both the data section and the thunk section have to be protected by the |
Reflection tests are failing because
|
I pushed changes to my branch that get the PInvoke smoke test passing. The MAP_JIT protection was the easy part. Apparently TLS access was trashing some registers in |
Apparently we still have to, I checked. Not sure what's different from regular CoreCLR though. |
The remaining failures seem to have some memory trashing going on. There may be something suspicious going on in |
aaaaaargh:
Spot the mistake. |
Somewhere along the way I broke the
...and the section has no relocations: I am running out of ideas on what could have possibly caused that. |
I did a rebuild and I could not reproduce it anymore... |
With the current state of things the smoke tests sometimes pass on my machine. Other times it fails here:
UPD: Updated |
I'll probably try to clean up my branch and submit a PR soon. |
That's GC interruption. You need to disable it in lldb with |
this assertion is failing: * thread #87, stop reason = hit program assert
frame #4: 0x00000001000818bc UnitTests`WKS::gc_heap::background_promote_callback(ppObject=0x000000017018eb90, sc=0x0000000170fc6a00, flags=1) at gc.cpp:35589:5
35586 UNREFERENCED_PARAMETER(sc);
35587 //in order to save space on the array, mark the object,
35588 //knowing that it will be visited later
-> 35589 assert (settings.concurrent);
35590
35591 THREAD_NUMBER_FROM_CONTEXT;
35592 #ifndef MULTIPLE_HEAPS
Target 0: (UnitTests) stopped. |
Yep, that matches what I get. Not every time though. |
We should probably fix GC_PAGE_SIZE definition ( runtime/src/coreclr/gc/gcpriv.h Line 6226 in 31bdc77
UPD: Updating |
I finally managed to get the assert under lldb. The interesting thing is that two thread try to do GC at the same time:
|
You may be seeing #75298 |
|
Confirmed, with #75298 I no longer see the crash. |
.NET 8 installer for SDK dotnet8 publish -c release --use-current-runtime -p:'PublishAot=true;StripSymbols=true' |
BTW, I haven't found any unusual warning if we delete this suppression:
Is it still relevant for osx-x64? |
Yes, it is. There are warnings about conversation of DWARF to compact unwinding. |
We can exclude TargetArchitecture=arm64 |
I am trying to enable NativeAOT on OSX arm64. With this patch main...am11:feature/nativeaot/osx-arm64 (tested with both
@GOTPAGE
and@PAGE
assembler directives), it builds the nupkg. Consuming that package results in the following errors during theilc
step:somewhere after the objwriter has succeeded:
runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ObjectWriter.cs
Line 1183 in 071e772
clang
command is executed. While the ilc task does not fail, MSBuild fails on the clang step:With objdump, that
__LD,__compact_unwind
section looks like:The text was updated successfully, but these errors were encountered: