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

Error occurs when calling native function with local variable in AOT mode? #3345

Closed
kamylee opened this issue Apr 23, 2024 · 8 comments
Closed
Labels
aot runtime platform core/shared/platform

Comments

@kamylee
Copy link

kamylee commented Apr 23, 2024

When I call a native function and pass a local variable, it runs fine in wasm mode. But when I compile it into an AOT file, it crashes when executing wasm_runtime_load. If I use a global variable, it runs fine. Do I need to set something when compiling into an AOT file?

image

@TianlongLiang
Copy link
Contributor

Do you have a minimal reproducible example? Maybe I can give it a try to see where went wrong

@kamylee
Copy link
Author

kamylee commented Apr 24, 2024

generate wasm:
/E/WorkSpace/DownLoads/wasi-sdk-21.0.m-mingw/wasi-sdk-21.0+m/bin/clang -O3 -nostdlib \ -z stack-size=32768 -Wl,--initial-memory=65536 \ -o test.wasm test.c \ -Wl,--export=main -Wl,--export=__main_argc_argv -Wl,--export=test1 \ -Wl,--export=__heap_base -Wl,--export=__data_end \ -Wl,--no-entry -Wl,--strip-all -Wl,--allow-undefined

generate aot:
wamrc -o test.aot test.wasm

code in test.c:
`void test1()
{
char *buf;

buf = malloc(1024);
if (!buf) {
    printf("malloc buf failed\n");
    return;
}

//call native function
foo2("hello 123", buf, 1024);
printf("%s\n",buf );

free(buf);

}`
it'll call native function foo2 in iwasm.exe.
enter command like this: iwasm --heap-size=16384 -f test1 test.wasm
it's run ok.
iwasm --heap-size=16384 -f test1 test.aot
it's error.

image
Release.zip
all test file is in Release.zip.

@TianlongLiang
Copy link
Contributor

From you snapshot, I think maybe it's a platform specific question on windows, I tested it on ubuntu 20.04, it seems no error appears with foo2 implemented as following:

static void
foo2_wrapper(wasm_exec_env_t exec_env, char *name, char *result, int resultlen)
{
    strncpy(result, name, resultlen);
}

static NativeSymbol native_symbols[] = {
    REG_NATIVE_FUNC(foo2, "($*~)")
};

I will try it on Windows to see where went wrong

@kamylee
Copy link
Author

kamylee commented Apr 25, 2024

I also tried it in Ubuntu 22.04 and it ran okay with local variables. it seems to be a specific error on the Windows platform. thank you! wait for your conclusion!

@TianlongLiang
Copy link
Contributor

Hi, could you please tell me whether you compiled the iwasm and wamrc with the latest commit? I didn't see similar error on Windows

@kamylee
Copy link
Author

kamylee commented Apr 28, 2024

the commit date is 2024/3/26 17:55:53
image

@TianlongLiang
Copy link
Contributor

Can you try with the latest commit and recompile both the iwasm and wamrc to see whether the error is still?

@wenyongh wenyongh added aot runtime platform core/shared/platform labels Apr 28, 2024
@kamylee
Copy link
Author

kamylee commented Apr 28, 2024

thank you very much,It's running ok after the update. :)

@kamylee kamylee closed this as completed Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aot runtime platform core/shared/platform
Projects
None yet
Development

No branches or pull requests

3 participants