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

Issue about errno when using WASI #241

Closed
lhespress opened this issue Jun 30, 2022 · 8 comments
Closed

Issue about errno when using WASI #241

lhespress opened this issue Jun 30, 2022 · 8 comments

Comments

@lhespress
Copy link

I am testing the WASI by thread example, and find an issue about errno, my steps are following:

wasi-sdk-14.0/bin/clang -O3 -mbulk-memory -matomics -ftls-model=local-exec -pthread -z stack-size=8192 -Wl,--initial-memory=65536 -Wl,--shared-memory -Wl,--no-entry -Wl,--allow-undefined -Wl,--strip-all -Wl,--export=main -o thread.wasm thread.c

The result is relocation R_WASM_MEMORY_ADDR_TLS_SLEB cannot be used against errno in non-TLS section: .bss.

My thread code is following:

#include <stdio.h>
#include <errno.h>

int main(void)
{
    errno = 21;
    printf("thread exit %d\n", errno);

    return 0;
}
@sbc100
Copy link
Member

sbc100 commented Jun 30, 2022

This is most likely because non of the wasi-sdk core libraries such as libc and libc++ and compiler-rt are compiled with threading support.

In order to experiment with threading you would need to rebuild the whole SDK with -pthread in the cflags.

Also, you don't need -mbulk-memory -matomics since those should be implied by -pthread. I'm pretty sure the same is true for -ftls-model=local-exec. Just -pthread should be sufficient.

@lhespress
Copy link
Author

lhespress commented Jun 30, 2022

@sbc100 when i remove -mbulk-memory -matomics -ftls-model=local-exec, it shows the error only -ftls-model=local-exec is supported for now on non-Emscripten OSes: variable errno, so it should include -ftls-model=local-exec and have the same error as i first opened.

@sbc100
Copy link
Member

sbc100 commented Jun 30, 2022

Ok, so -ftls-model=local-exec is needed for now that, but the other two should are not.

@sbc100
Copy link
Member

sbc100 commented Jun 30, 2022

I guess this is really a duplicate of WebAssembly/WASI#296 and can probably be closes as such?

@sunfishcode
Copy link
Member

Yes, this is being pursued in https://reviews.llvm.org/D130053 and WebAssembly/wasi-libc#307.

@vapier
Copy link

vapier commented Aug 30, 2024

In order to experiment with threading you would need to rebuild the whole SDK with -pthread in the cflags.

this still seems to be the case with wasi-sdk-24. if that flag is required for correct behavior when using the new wasi threads target, shouldn't it be implied automatically?

@yamt
Copy link
Contributor

yamt commented Sep 2, 2024

In order to experiment with threading you would need to rebuild the whole SDK with -pthread in the cflags.

this still seems to be the case with wasi-sdk-24. if that flag is required for correct behavior when using the new wasi threads target, shouldn't it be implied automatically?

you don't need to "rebuild the whole SDK" as the recent wasi-sdk ships wasi-threads build of the libraries.

@vapier
Copy link

vapier commented Sep 2, 2024

sorry, meant to emphasize the consistent usage of the flag, not rebuilding the sdk. if you use the threads target but not the pthreads flag, things will link, but you end up with multiple errno storage as described in this report. so if the pthreads flag is required, why isn't it implied when using the threads target?

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

5 participants