alexcrichton opened PR #8363 from alexcrichton:fix-val-alignment-in-c-api
to bytecodealliance:main
:
This commit fixes an issue where
wasmtime_val_raw_t
had an incorrect alignment. In RustValRaw
contains au128
which has an alignment of 16 but in C the representation had a smaller alignment meaning that the alignment of the two structures was different. This was seen to cause alignment faults when structure were passed from C++ to Rust, for example.This then additionally changes the representation of
wasmtime_val_union
in Rust to use au128
instead of[u8; 16]
to ensure that the same 16-byte-alignedwasmtime_v128
type in C can represent both payloads inwasmtime_val_union
andwasmtime_val_raw_t
.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested fitzgen for a review on PR #8363.
alexcrichton requested wasmtime-core-reviewers for a review on PR #8363.
github-actions[bot] commented on PR #8363:
Subscribe to Label Action
cc @peterhuene
<details>
This issue or pull request has been labeled: "wasmtime:c-api"Thus the following users have been cc'd because of the following labels:
- peterhuene: wasmtime:c-api
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
fitzgen submitted PR review.
alexcrichton updated PR #8363.
alexcrichton has enabled auto merge for PR #8363.
alexcrichton updated PR #8363.
alexcrichton updated PR #8363.
alexcrichton updated PR #8363.
alexcrichton edited PR #8363:
This commit fixes an issue where
wasmtime_val_raw_t
had an incorrect
alignment. In RustValRaw
contains au128
which has an alignment of
16 but in C the representation had a smaller alignment meaning that the
alignment of the two structures was different. This was seen to cause
alignment faults when structure were passed from C++ to Rust, for
example.This commit changes the Rust representation of
ValRaw
'sv128
field
to do the same as C which is to use[u8; 16]
. This avoids the need to
raise the alignment in C which appears to be nontrivial. Cranelift is
appropriately adjusted to understand that loads/stores fromValRaw
are
no longer aligned. Technically this only applies to thev128
field but
it's not too bad to apply it to the other fields as well.
alexcrichton commented on PR #8363:
I ended up going the reverse direction here instead, lowering the alignment in Rust instead of raising the alignment in the C API. I don't know how to portably raise the alignment in C so I'd rather tweak the Rust side of things.
alexcrichton updated PR #8363.
alexcrichton merged PR #8363.
Last updated: Dec 23 2024 at 13:07 UTC