-
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
NativeAOT incorrect native code when assigning unmanaged function pointer to struct member #107396
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
Doesn't repro on win-x64 with Preview 6. So it's either recent regression or arm64 specific. |
Also doesn't repro on win-x64 RC2, so it's very likely arm64 specific. |
I can't repro on x64/macOS either. |
Yeah. there seems to be some confusion about which register holds the value. Here's the full disassembly of the constructor:
The interesting part is:
This is where we take the address of Nothing seems to touch x20 until we get to the compare call:
And at this point x22 should have the same value as x20 but it doesn't, |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
This works on .NET 8 (osx arm64), but breaks on .NET 9 (I tried Preview6 and later, and it all fails). |
@AndyAyersMS, PTAL if we need to fix this in .NET 9. |
I can repro on my volterra. Digging in. |
There is one other place the addresses get taken, but it's hidden. The JIT tries to set up ldr q16, [@RWD00]
str q16, [x19, #0x08]
ldp x22, x23, [x19, #0x08] However the function addresses are not properly captured in the vector constant
I am not sure if we support relocs in jit emitted data. If not, we'll need to block transforming these two separate stores into a single vector constant store. @EgorBo do you know? |
@rolfbjarne I have a fix. Would it be ok to add your example as a new test case? |
We can't represent relocations in data currently. Fixes dotnet#107396.
Yes, of course. |
We can't represent relocations in data currently. Fixes #107396.
FWIW, the JitInterface has provisions for relocs in JIT emitted data. For this method on arm64 I don't see RyuJIT calling |
I guess it should call it now with #107491 |
We can't represent relocations in data currently. Fixes #107396. Co-authored-by: Andy Ayers <[email protected]> Co-authored-by: Jeff Schwartz <[email protected]>
…#107491) We can't represent relocations in data currently. Fixes dotnet#107396.
…#107491) We can't represent relocations in data currently. Fixes dotnet#107396.
…#107491) We can't represent relocations in data currently. Fixes dotnet#107396.
Description
NativeAOT seems to generate incorrect native code when assigning unmanaged function pointer to struct member
Reproduction Steps
Compile & run:
csproj
Expected behavior
Actual behavior
$ dotnet publish /p:PublishAot=true && ./bin/Release/net9.0/osx-arm64/publish/repro Cblock.Allocate: 0x421280 vs 0x104e7c2c0 Not equal ❌ Cblock.Free: 0x421298 vs 0x104e7c2e0 Not equal ❌ Cblock.Allocate: 0x104e7c2c0 vs 0x104e7c2c0 Equal ✅ Cblock.Free: 0x104e7c2e0 vs 0x104e7c2e0 Equal ✅
Regression?
I'm not sure; this showed up in a new test failure, but unrelated things might have hidden it.
While creating a smaller test case, there were numerous times I'd change something seemingly unrelevant (such as remove a Console.WriteLine), and the problem would go away.
Known Workarounds
Assigning the function pointer to an intermediate variable seems to work.
Configuration
$ donut --info .NET SDK: Version: 9.0.100-rc.2.24420.1 Commit: e2b7b9d2b4 Workload version: 9.0.100-manifests.3edc8368 MSBuild version: 17.12.0-preview-24415-04+f422d8d7d Runtime Environment: OS Name: Mac OS X OS Version: 14.6 OS Platform: Darwin RID: osx-arm64 Base Path: /Users/rolf/work/maccore/net9.0/xamarin-macios/builds/downloads/dotnet-sdk-9.0.100-rc.2.24420.1/sdk/9.0.100-rc.2.24420.1/ .NET workloads installed: Configured to use loose manifests when installing new manifests. [macos] Installation Source: SDK 9.0.100-rc.2 Manifest Version: 14.5.9308-ci.dev-rolf-bump-main-in-net9-0-2024-09-04/9.0.100-rc.2 Manifest Path: /Users/rolf/work/maccore/net9.0/xamarin-macios/builds/downloads/dotnet-sdk-9.0.100-rc.2.24420.1/sdk-manifests/9.0.100-rc.2/microsoft.net.sdk.macos/WorkloadManifest.json Install Type: FileBased [ios] Installation Source: SDK 9.0.100-rc.2 Manifest Version: 17.5.9308-ci.dev-rolf-bump-main-in-net9-0-2024-09-04/9.0.100-rc.2 Manifest Path: /Users/rolf/work/maccore/net9.0/xamarin-macios/builds/downloads/dotnet-sdk-9.0.100-rc.2.24420.1/sdk-manifests/9.0.100-rc.2/microsoft.net.sdk.ios/WorkloadManifest.json Install Type: FileBased [maccatalyst] Installation Source: SDK 9.0.100-rc.2 Manifest Version: 17.5.9308-ci.dev-rolf-bump-main-in-net9-0-2024-09-04/9.0.100-rc.2 Manifest Path: /Users/rolf/work/maccore/net9.0/xamarin-macios/builds/downloads/dotnet-sdk-9.0.100-rc.2.24420.1/sdk-manifests/9.0.100-rc.2/microsoft.net.sdk.maccatalyst/WorkloadManifest.json Install Type: FileBased [tvos] Installation Source: SDK 9.0.100-rc.2 Manifest Version: 17.5.9308-ci.dev-rolf-bump-main-in-net9-0-2024-09-04/9.0.100-rc.2 Manifest Path: /Users/rolf/work/maccore/net9.0/xamarin-macios/builds/downloads/dotnet-sdk-9.0.100-rc.2.24420.1/sdk-manifests/9.0.100-rc.2/microsoft.net.sdk.tvos/WorkloadManifest.json Install Type: FileBased Host: Version: 9.0.0-rc.1.24414.5 Architecture: arm64 Commit: static .NET SDKs installed: 9.0.100-rc.2.24420.1 [/Users/rolf/work/maccore/net9.0/xamarin-macios/builds/downloads/dotnet-sdk-9.0.100-rc.2.24420.1/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 9.0.0-rc.1.24412.15 [/Users/rolf/work/maccore/net9.0/xamarin-macios/builds/downloads/dotnet-sdk-9.0.100-rc.2.24420.1/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 9.0.0-rc.1.24414.5 [/Users/rolf/work/maccore/net9.0/xamarin-macios/builds/downloads/dotnet-sdk-9.0.100-rc.2.24420.1/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: Not set global.json file: /Users/rolf/work/maccore/net9.0/xamarin-macios/global.json Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
Other information
No response
The text was updated successfully, but these errors were encountered: