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

AOT code ends up in non-executable memory by try_merge_data_and_text() #3825

Open
sasq64 opened this issue Sep 30, 2024 · 1 comment
Open

Comments

@sasq64
Copy link

sasq64 commented Sep 30, 2024

Subject of the issue

Running AOT code on MacOS; works fine without --xip, but with the flag I crash on access error when trying to call native code.

Test case

Your environment

  • MacOS Sonoma 14.2
  • WAMR 2.1.2

Steps to reproduce

Build a wasm-file and compile to aot with wamrc --target aarch64v8 --xip

Expected behavior

Should not crash

Actual behavior

Crashes with access error in non executable memory

Extra Info

Changing aot_loader.c:2163 from

sections = loader_mmap((uint32)total_size, false, NULL, 0);
to
sections = loader_mmap((uint32)total_size, true, NULL, 0);

fixes the issue for me.

@wenyongh
Copy link
Contributor

wenyongh commented Oct 8, 2024

Hi, try_merge_data_and_text is called only when the aot module is not in indirect mode (module->is_indirect_mode is false):

if (!module->is_indirect_mode && is_load_from_file_buf)
if (!try_merge_data_and_text(&buf, &buf_end, module,

But module->is_indirect_mode is set to true when the input is an XIP file:

read_uint16(p, p_end, e_type);
if (e_type == E_TYPE_XIP) {
*p_mode = true;
}

It is a little strange that it isn't set, could you help check whether create_sections and resolve_execute_mode are called?

BTW, in iwasm's main function, we mmap the AOT file previously for XIP mode before loading it, and aot text won't be mmapped again during loading:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/product-mini/platforms/posix/main.c#L891-L902

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

No branches or pull requests

2 participants