Skip to content

Handling misaligned memory accesses #4833

@tage64

Description

@tage64

I have a risc-v processor that doesn't support misaligned memory accesses. I ahead-of-time compile a wasm program with Wamrc but when I run it I get a trap for a misaligned load. I know that WebAssembly allows unaligned memory accesses so this isn't surprising but I wonder if it is possible to adjust load/stores to check for alignment when generating the LLVM-IR during compilation?

In core/iwasm/common/wasm_runtime_common.h there are several macros for doing unaligned stores/loads : STORE_I64, STORE_U32, LOAD_I64, LOAD_I16, ... I imagine something similar to these: Whenever the Wasm code wants to make a load or store, Wamrc emits instructions similar to these macros.

Is this possible today, or would it be hard to implement?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions