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

[WIP] Fixes for the THREAD_MODEL=posix build #303

Closed
wants to merge 1 commit into from
Closed

Conversation

sbc100
Copy link
Member

@sbc100 sbc100 commented Jul 18, 2022

No description provided.

@sbc100 sbc100 force-pushed the fix_pthread_build branch from f44f89c to 7af7dda Compare July 18, 2022 22:19
@sbc100
Copy link
Member Author

sbc100 commented Jul 18, 2022

Still need to deal with preopens.c

int r = __wasi_random_get(buffer, len);
pthread_setcancelstate(cs, 0);
Copy link
Member

Choose a reason for hiding this comment

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

I propose that we leave out considerations of cancellation out for now. Pthread cancellation is something of an anti-sweet-spot, being particularly difficult and expensive to implement, while being particularly rarely used.

One of the particular complexities is what to do if one thread tries to cancel another thread that's currently executing host code. That might require all host code to be pthread cancel-safe, which would be very difficult for many popular host implementations today.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds reasonable, at least for a first pass. How about we just avoid using pthread_setcancelstate et al in the bottom half and just stub them out (make them no-ops) when compiling top-half code.

#if _REENTRANT
int val;
__asm__(".globaltype g_needs_dynamic_alloc, i32\n"
"global.get __wasi_libc_pthread_self\n"
Copy link
Member

Choose a reason for hiding this comment

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

Where are g_needs_dynamic_alloc and __wasi_libc_pthread_self defined?

As a minor style nit, wasi-libc usually uses identifiers named __wasilibc_* rather than __wasi_libc_*.

@@ -5,6 +5,7 @@
#include <errno.h>
#include <threads.h>
#include <time.h>
#include <_/cdefs.h> // for __strong_reference
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding this include, let's just delete the thrd_sleep alias here. If we want thrd_sleep, it's better to use the musl definition, which correctly implements the C11 behavior.

if (path[0] == 0 || !strcmp(path, ".") || !strcmp(path, "./")) {
return make_absolute_buf;
}
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment about what this block of code does?

"local.set %0" : "=r" (val));
return val;
#else
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

Does __get_tp need to be defined in non-_REENTRANT mode? It seems better to get an undefined-symbol link error if we try to use it than to have it silently return NULL, especially with NULL being a valid address.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for all the comments. I will address all of them, this PR is certainly not ready to land. I just wanted to share what I had done so far.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, makes sense. I was just looking through it so that I could follow along, and happened to have comments along the way :-).

abrown added a commit to abrown/wasi-libc that referenced this pull request Jul 25, 2022
This change extracts the `weak*`-related parts of WebAssembly#303 as a separate PR.
Note that this is slightly strange in that it uses some top-half MUSL
headers in the bottom-half code, but discussion around this led me to
believe that the advantages of, e.g., `LOCK` made this worthwhile.
Beyond just changing uses of `weak` to `__weak__`, we also MUSL's `weak`
and `weak_alias` macros in a few more places.
abrown added a commit to abrown/wasi-libc that referenced this pull request Jul 25, 2022
These changes get past several small build errors in WebAssembly#303.
sunfishcode pushed a commit that referenced this pull request Jul 26, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This change extracts the `weak*`-related parts of #303 as a separate PR.
Note that this is slightly strange in that it uses some top-half MUSL
headers in the bottom-half code, but discussion around this led me to
believe that the advantages of, e.g., `LOCK` made this worthwhile.
Beyond just changing uses of `weak` to `__weak__`, we also MUSL's `weak`
and `weak_alias` macros in a few more places.
@sbc100
Copy link
Member Author

sbc100 commented Jul 27, 2022

Closing in favor of #311

@sbc100 sbc100 closed this Jul 27, 2022
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.

None yet

2 participants