Open kekekeks opened 1 year ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak See info in area-owners.md if you want to be subscribed.
Author: | kekekeks |
---|---|
Assignees: | - |
Labels: | `arch-arm32`, `area-CodeGen-coreclr`, `untriaged` |
Milestone: | - |
Unsafe.CopyBlockUnaligned doesn't seem to respect memory alignment restrictions either when used with Unsafe.SizeOf<T>
@BruceForstall PTAL.
I'm not 100% sure I know how we detect "this platform doesn't support unaligned reads" so it can be a bug in that logic that detects it?
Another issue is what we assume in R2R? Do we throw R2R unconditionally if current platform doesn't support them or R2R itself assumes unaligned reads are not allowed on given platform?
The Linux distros that we test on have the alignment fixups enabled by default. There are likely number of other issues that would popup with alignment fixups disabled.
Does your distro have the alignment fixups explicitly disabled? Can you enable them?
Or have you encountered this issue when accessing device memory (similar to https://github.com/dotnet/runtime/issues/66082)?
.NET 6.0: Only ReadUnaligned generates invalid code
I'm confused, I see the exact same stores/loads from the pointer (in r0
) in all your examples, only there are some extra unnecessary copies between stack slots that we are now getting rid of in .NET 7.
I do believe that the JIT always assumes that unaligned integer loads/stores are supported by the target, so unaligned loads/stores are only treated specially for floats.
@jkotas the issue was reported on 32-bit Raspbian / Raspberry Pi Zero 2. The memory was allocated via Marshal.AllocHGlobal. Replacing ReadUnaligned
with manual byte copy loop fixed the issue.
@jakobbotsch we do read double
, float
and float
-based System.Numerics
structures via ReadUnaligned
Description
It seems that ReadUnaligned and WriteUnaligned no longer support unaligned pointer access on ARM architecture.
Reproduction Steps
https://godbolt.org/z/nGh9vP6KK
.NET 6.0: Only ReadUnaligned generates invalid code
.NET 7.0: Both WriteUnaligned and ReadUnaligned generate direct pointer access
Expected behavior
Generated code properly handles misaligned pointers
Actual behavior
Unhandled fault: alignment exception
Regression?
No response
Known Workarounds
Buffer.MemoryCopy
Configuration
Raspberry Pi 3, Debian 11 32 bit
Other information
No response