Skip to content
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

Fix ems allocator unaligned memory access on riscv64 #2140

Merged
merged 5 commits into from
Apr 26, 2023

Conversation

wenyongh
Copy link
Contributor

Add padding bytes to ensure the left/right/parent fields in struct hmu_tree_node
are 8-byte aligned on the target which doesn't support unaligned memory access.

/* each hmu node is 4-byte aligned and not 8-byte aligned,
add 4 bytes padding to make below left/right/parent fields
8-byte aligned, so that we can directly access them */
uint32 __padding;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

Cannot find where you set this variable but generally very good change for the project as currently ubsan wamr build fails with unaligned access

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that before this change, ubsan reports unaligned access issue, and after this PR, the issue isn't reported again? Maybe I should apply the change for all the targets, including x86-64.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi

Now it reports unaligned access but unfortunately I didn't try to fix padding for x86-64 now, and I hope something like that could help

@wenyongh wenyongh merged commit 5c497e5 into bytecodealliance:main Apr 26, 2023
@wenyongh wenyongh deleted the fix_ems_unaligned_access branch May 5, 2023 08:33
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…e#2140)

Make `hmu_tree_node` struct packed and add 4 padding bytes before `kfc_tree_root_buf`
field in `gc_heap_struct` struct to ensure the `left/right/parent` fields in `hmu_tree_node`
are 8-byte aligned on the 64-bit target which doesn't support unaligned memory access.

Fix the issue reported in bytecodealliance#2136.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants