Repository navigation
[NativeAOT] Read the byte-packed LSDA offsets without a misaligned load - #134051
Merged
MichalStrehovsky merged 2 commits intoSep 16, 2026
Merged
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
maximmenshikov
force-pushed
the
maximmenshikov/misaligned
branch
from
September 16, 2026 12:41
4e24216 to
cd863bb
Compare
jkotas
reviewed
Sep 16, 2026
jkotas
reviewed
Sep 16, 2026
A method's LSDA is byte-packed with no padding: a one-byte flags field followed by 32-bit offsets. UnixNativeCodeManager and RuntimeInstance read those offsets with *dac_cast<PTR_int32_t>(p), so the load lands on a 4-byte-aligned address only by chance. The cast also tells the compiler that the address is aligned, which the format does not promise. x64 and arm64 do not care. A RISC-V execution environment may support misaligned access in hardware, emulate it, or reject it, and the runtime cannot tell which, so it should not ask for it here. Build flags do not help: with -mstrict-align the compiler still emits a single lw, because the cast promised the alignment. Read the offsets through memcpy instead, in the decoder that already reads these blobs. NativePrimitiveDecoder gets a non-mutating PeekInt32 and PeekUInt32, and ReadInt32/ReadUInt32 use them rather than assembling the value out of byte loads by hand. That keeps every read native-endian, as it was before, and drops the signed overflow the old expressions had in the top byte. Nothing is lost where misaligned access is available: with clang 22.1.8 at -O2 the affected paths still compile to one ldrsw on arm64 and one movslq on x64. Signed-off-by: Maxim Menshikov <[email protected]>
maximmenshikov
force-pushed
the
maximmenshikov/misaligned
branch
from
September 16, 2026 13:24
cd863bb to
89a1ed8
Compare
maximmenshikov
marked this pull request as ready for review
September 16, 2026 13:28
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
jkotas
approved these changes
Sep 16, 2026
jtschuster
pushed a commit
to jtschuster/runtime
that referenced
this pull request
Sep 18, 2026
…ad (dotnet#134051) A method's LSDA is byte-packed with no padding: a one-byte flags field followed by 32-bit offsets. UnixNativeCodeManager and RuntimeInstance read those offsets with *dac_cast<PTR_int32_t>(p), so the load lands on a 4-byte-aligned address only by chance. The cast also tells the compiler that the address is aligned, which the format does not promise. x64 and arm64 do not care. A RISC-V execution environment may support misaligned access in hardware, emulate it, or reject it, and the runtime cannot tell which, so it should not ask for it here. Build flags do not help: with -mstrict-align the compiler still emits a single lw, because the cast promised the alignment. Read the offsets a byte at a time through NativePrimitiveDecoder, which already reads these blobs. It gets a non-mutating PeekInt32, and ReadInt32/ReadUInt32 now use it instead of repeating the byte assembly. Widening each byte before the shift also removes the signed overflow the old expressions had in the top byte. Nothing is lost where misaligned access is available: with clang 22.1.8 at -O2 the affected paths still compile to one ldrsw on arm64 and one movslq on x64. Signed-off-by: Maxim Menshikov <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A method's LSDA is byte-packed with no padding: a one-byte flags field followed by 32-bit offsets. UnixNativeCodeManager and RuntimeInstance read those offsets with *dac_cast<PTR_int32_t>(p), so the load lands on a 4-byte-aligned address only by chance. The cast also tells the compiler that the address is aligned, which the format does not promise.
x64 and arm64 do not care. A RISC-V execution environment may support misaligned access in hardware, emulate it, or reject it, and the runtime cannot tell which, so it should not ask for it here. Build flags do not help: with -mstrict-align the compiler still emits a single lw, because the cast promised the alignment.
Read the offsets a byte at a time through NativePrimitiveDecoder, which already reads these blobs. It gets a non-mutating PeekInt32, and ReadInt32/ReadUInt32 now use it instead of repeating the byte assembly. Widening each byte before the shift also removes the signed overflow the old expressions had in the top byte.
Nothing is lost where misaligned access is available: with clang 22.1.8 at -O2 the affected paths still compile to one ldrsw on arm64 and one movslq on x64.