You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to use wasi-sdk to compile a program that might use threads (or shared memories, etc.), the program will fail to link because the libc used has not been compiled with all of the right features (i.e., --shared-memory which relies on --features='atomics,bulk-memory'):
$ cat <<EOF > test.c#include <stdio.h>int main() { printf("..."); return 0;}EOF
$ /opt/wasi-sdk/wasi-sdk-16.0/bin/clang -O3 --target=wasm32-wasi \ --sysroot=/opt/wasi-sdk/wasi-sdk-16.0/share/wasi-sysroot \ -mthread-model posix -Xlinker --features='atomics,bulk-memory' -Xlinker --shared-memory \ test.c -o test.wasm -v... "/opt/wasi-sdk/wasi-sdk-16.0/bin/wasm-ld" -m wasm32 -L/opt/wasi-sdk/wasi-sdk-16.0/share/wasi-sysroot/lib/wasm32-wasi /opt/wasi-sdk/wasi-sdk-16.0/share/wasi-sysroot/lib/wasm32-wasi/crt1-command.o --features=atomics,bulk-memory --shared-memory /tmp/test-86de01.o -lc /opt/wasi-sdk/wasi-sdk-16.0/lib/clang/14.0.4/lib/wasi/libclang_rt.builtins-wasm32.a -o test.wasm/opt/wasi-sdk/wasi-sdk-16.0/bin/wasm-ld: /lib64/libtinfo.so.6: no version information available (required by /opt/wasi-sdk/wasi-sdk-16.0/bin/wasm-ld)wasm-ld: error: --shared-memory is disallowed by errno.o because it was not compiled with 'atomics' or 'bulk-memory' features.clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
There should be some way to package up the output of a make THREAD_MODEL=posix build in the released binaries and helpfully link in the right things when, e.g., -pthreads or -mthread-model=posix are used. Any thoughts on how to move forward on this?
I would suggest that, at least initially you just build a completely separate sysroot. e.g. wasi-sysroot-mt?
In he long run we could come up with some kind of scheme where clang you select the library subdirectory within the sysroot differently, just like it does for architecture. e.g. -L<sysroot>/lib/wasm32-wasi/ would become something like -L<sysroot>/lib/wasm32-wasi/mt/. That why we could have single sysroot (and indeed a single architecture within that sysroot) that contains both a the mutlithreaded and singlethreaded libraries.
But I think two different sysroots should for a the time being.
Here's what we discussed today: wasi-libc would get distributed with a new subdirectory mt containing a whole new sysroot, the output of make THREAD_MODEL=posix. Then, we would need to change clang to append mt to the sysroot path when it detects flags that require a reentrant build (e.g., -pthread). @sunfishcode, @sbc100, does that sound right? (And maybe it's just a restatement of what @sbc100 just said above?)
I think we discussed not a separate sysroot just a new directory inside the existing sysroot (e.g. lib/was32-unknown-unknown/mt)? This will require a clang patch.
The completely separate sysroot is what we could use to try this out without first landing the clang patch.
Oh, ok, then I was misunderstanding what was said. So the contents of mt would instead contain the threads-compatible versions of all of the lib artifacts (e.g., crt1.o, libc.a, libm.a, libwasi-emulated-*.a, etc.)?
Basically yes, although crt1.o tends to be handled separately ... it might be special handling. Take a look a the current clang driver code for now it picks the lib directly along with how it picks crt1.o.
I think we discussed not a separate sysroot just a new directory inside the existing sysroot (e.g. lib/was32-unknown-unknown/mt)?
It can also be treated as a 'feature' of the target, and maybe triple can become wasm32-unknown-unknown-mt or wasm32-unknown-mt. The upside of that, in my opinion, is that it better reflects that 'mt' and 'non-mt' object files are more or less incompatible (mixing them leads to link errors, in all or some cases).
That might be a bit tricky tough... what happens if you build with -triple=wasm32-unknown + -pthread .. should that fail because you didn't specify a triple that supports threading?
I guess when the triple gets expanded from what the user specified on the command line and the missing components are added we could inject the -mt suffiix if the -pthread flag is present.
I guess when the triple gets expanded from what the user specified on the command line and the missing components are added we could inject the -mt suffiix if the -pthread flag is present.
Probably, I'll look at the driver and see what would be easier.
One thing that may be worth pointing out here from a Rust-perspective is that Rust can probably only really support this if the string is a brand new target. Rust additionally has precompiled artifacts (the Rust standard library) and I don't think that infrastructurally it's really possible to change the Rust compiler and distribution infrastructure for just the wasm target to have two sysroots in the similar manner that's being proposed for C here.
Personally I have always hoped to avoid having a threaded and non-threaded target for all wasm targets but at the current point in time I think it's the best solution at least for Rust. I'm sure, though, that whatever naming scheme is used for a C target (if that's settled on) will want to be mirrored in Rust as well.
To add to what Alex said here, adding a new triple ends up having a lot of administrative overhead.
I'd like to second the above ideas of having threading-enabled artifacts to be available in the same sysroot, under the same target triple, and teaching the clang and rust drivers how to find them, so that we don't need a whole separate target.
On a tangential note, I expect I'll have a hard time remembering the name "mt" stands for; could we name the artifacts something with "thread" in the name?
To clarify, though, as far as I know that's not a viable strategy for Rust (using the same target with separate sysroots). Implementing that for Rust would involve a fair amount of change to the release process, building, etc, that's all wasm-specific and doesn't have any precedent. I would be quite skeptical that unless someone is already signed up to do the work that this would never get done because it's too different from what's already there. Put another way, if a new target isn't made I don't think that Rust will, in any near-to-mid timeframe, gain support for precompiled artifacts with multithreading.
Broadly speaking I do personally care about Rust having good multithreading support for wasm, but not to the point that I can justify refactoring Rust's own distribution mechanism to accomodate this use case. I very much agree that adding new targets is a very big hammer but that's what I mean by I don't see a better solution at this time. Rust has an intermediate solution, though, that C doesn't where it's easier, at least on the nightly Rust channel, to compile the standard library from source with atomics/threads enabled.
I guess I don't quite see why we shouldn't assume that "sysroot-is-target" when --sysroot is passed?
I'm saying these two things are orthogonal and in general one should preserve orthogonality in flag behaviours. If you assume "sysroot-is-target", this should be done regardless of whether --sysroot was passed explicitly or a default value was chosen for it. This general principle of programming makes it easier to compose lower-level tools into higher-level tools, as the behaviours are more predictable.
Take your example about sysroot builders, yes if they only focus on wasm32-wasi today it make seem "redundant" but if they extend their functionality or someone composes them with another tool, then it's not redundant and in fact it would be less messy.
Thats basically what your clang patch does today doesn't it?
I think you're confusing me with @paravoid , we are both Debian developers but I'm giving an alternative opinion here. I didn't write any patches for clang, but I do maintain rustc in Debian as well (where the question about include paths is moot).
Regarding the duplication if headers, assuming we stick with our decision to treat wasm32-wasi-pthreads as a separate target, how should we handle the header redundancy? Should we:
a. Ship the headers twice, once under each target subdirectory
b. Ship the headers once in wasm32-wasi and have clang search or headers under the specific target (wasm32-wasi-pthreads) first and fall back to wasm32-wasi?
(Any other options?)
I imagine there is some precedent for (a) ? e.g. /usr/include/x86_64-linux-gnu/ and /usr/include/i386-linux-gnu/ contains a lot of identical files?
The wasi-sdk headers appear to be about 9 MiB installed. That's not free, but if it's significantly simpler to duplicate the headers than to figure out some kind of sharing configuration, I propose that we just duplicate it.
Will #331 be shipped in the next version of wasi-sdk? I'm not too sure what the release process is but the original intent of this issue is that future versions of wasi-libc would have both targets. I think we can close this once that is figured out.
Yes the next version should have two different target triples in the sysroot I think... although there maybe a little more work to make that happen still.
I agree, but I'm concerned with solving the end problem: @sbc100 or @sunfishcode, what else needs to happen for the THREAD_MODEL=posix builds to be released in the next version of wasi-sdk? If it's just a wasi-sdk thing at this point, I'll open an issue there with whatever you suggest and we can close this one.
One other point, though: as I was writing up the proposal to add this new target to Rust, I began to wonder whether wasm32-wasi-pthread is in fact the right name for the target. I wonder if perhaps the Rust target might make more sense as wasm32-wasi-threads and then I foresee some confusion (use wasm32-wasi-threads for Rust, use wasm32-wasi-pthread for C, etc.). Can we quickly bikeshed the name of this target before we release anything?
I'd be fine with calling the clang triple wasm32-wasi-threads if you prefer .. internally withing clang/llvm I believe we do use threadmodel=posix, but I guess that is an implementation detail.
The current release process isn't very automated. I take the build artifacts from CI and manually upload them to the release. So to add more artifacts here, we just need to (a) make sure CI produces them, and (b) that whoever does the next release knows to upload those artifacts.
Ok, I think the "how" is resolved at this point so we can close this. @yamt has WebAssembly/wasi-sdk#274 open to add wasm32-wasi-threads support to wasi-sdk. With that in place, the right answer for "how to distribute THREAD_MODEL=posix builds will be to use some new-ish version of wasi-sdk and tell the compiler to target wasm32-wasi-threads — all of that can be documented in the wasi-sdk repository.
Activity
abrown commentedon Sep 15, 2022
cc: @mingqiusun, @penzn
[-]How to package [/-][+]How to distribute `THREAD_MODEL=posix` builds?[/+]sbc100 commentedon Sep 15, 2022
I would suggest that, at least initially you just build a completely separate sysroot. e.g.
wasi-sysroot-mt?In he long run we could come up with some kind of scheme where clang you select the library subdirectory within the sysroot differently, just like it does for architecture. e.g.
-L<sysroot>/lib/wasm32-wasi/would become something like-L<sysroot>/lib/wasm32-wasi/mt/. That why we could have single sysroot (and indeed a single architecture within that sysroot) that contains both a the mutlithreaded and singlethreaded libraries.But I think two different sysroots should for a the time being.
abrown commentedon Sep 19, 2022
Here's what we discussed today: wasi-libc would get distributed with a new subdirectory
mtcontaining a whole new sysroot, the output ofmake THREAD_MODEL=posix. Then, we would need to changeclangto appendmtto the sysroot path when it detects flags that require a reentrant build (e.g.,-pthread). @sunfishcode, @sbc100, does that sound right? (And maybe it's just a restatement of what @sbc100 just said above?)sbc100 commentedon Sep 19, 2022
I think we discussed not a separate sysroot just a new directory inside the existing sysroot (e.g.
lib/was32-unknown-unknown/mt)? This will require a clang patch.The completely separate sysroot is what we could use to try this out without first landing the clang patch.
abrown commentedon Sep 19, 2022
Oh, ok, then I was misunderstanding what was said. So the contents of
mtwould instead contain the threads-compatible versions of all of thelibartifacts (e.g.,crt1.o,libc.a,libm.a,libwasi-emulated-*.a, etc.)?sbc100 commentedon Sep 19, 2022
Basically yes, although crt1.o tends to be handled separately ... it might be special handling. Take a look a the current clang driver code for now it picks the lib directly along with how it picks crt1.o.
penzn commentedon Sep 23, 2022
It can also be treated as a 'feature' of the target, and maybe triple can become
wasm32-unknown-unknown-mtorwasm32-unknown-mt. The upside of that, in my opinion, is that it better reflects that 'mt' and 'non-mt' object files are more or less incompatible (mixing them leads to link errors, in all or some cases).sbc100 commentedon Sep 23, 2022
Sure, if you think we can shoehorn it into the tipple that would great!
sbc100 commentedon Sep 23, 2022
That might be a bit tricky tough... what happens if you build with
-triple=wasm32-unknown+-pthread.. should that fail because you didn't specify a triple that supports threading?sbc100 commentedon Sep 23, 2022
I guess when the triple gets expanded from what the user specified on the command line and the missing components are added we could inject the
-mtsuffiix if the-pthreadflag is present.penzn commentedon Sep 23, 2022
Probably, I'll look at the driver and see what would be easier.
alexcrichton commentedon Sep 27, 2022
One thing that may be worth pointing out here from a Rust-perspective is that Rust can probably only really support this if the string is a brand new target. Rust additionally has precompiled artifacts (the Rust standard library) and I don't think that infrastructurally it's really possible to change the Rust compiler and distribution infrastructure for just the wasm target to have two sysroots in the similar manner that's being proposed for C here.
Personally I have always hoped to avoid having a threaded and non-threaded target for all wasm targets but at the current point in time I think it's the best solution at least for Rust. I'm sure, though, that whatever naming scheme is used for a C target (if that's settled on) will want to be mirrored in Rust as well.
sunfishcode commentedon Sep 27, 2022
To add to what Alex said here, adding a new triple ends up having a lot of administrative overhead.
I'd like to second the above ideas of having threading-enabled artifacts to be available in the same sysroot, under the same target triple, and teaching the clang and rust drivers how to find them, so that we don't need a whole separate target.
On a tangential note, I expect I'll have a hard time remembering the name "mt" stands for; could we name the artifacts something with "thread" in the name?
alexcrichton commentedon Sep 27, 2022
To clarify, though, as far as I know that's not a viable strategy for Rust (using the same target with separate sysroots). Implementing that for Rust would involve a fair amount of change to the release process, building, etc, that's all wasm-specific and doesn't have any precedent. I would be quite skeptical that unless someone is already signed up to do the work that this would never get done because it's too different from what's already there. Put another way, if a new target isn't made I don't think that Rust will, in any near-to-mid timeframe, gain support for precompiled artifacts with multithreading.
Broadly speaking I do personally care about Rust having good multithreading support for wasm, but not to the point that I can justify refactoring Rust's own distribution mechanism to accomodate this use case. I very much agree that adding new targets is a very big hammer but that's what I mean by I don't see a better solution at this time. Rust has an intermediate solution, though, that C doesn't where it's easier, at least on the nightly Rust channel, to compile the standard library from source with atomics/threads enabled.
18 remaining items
sunfishcode commentedon Nov 22, 2022
I like the idea of just accepting this. It's advantageous for WASI to be able to "fit in" within existing cross-compilation filesystem layouts.
infinity0 commentedon Nov 22, 2022
I'm saying these two things are orthogonal and in general one should preserve orthogonality in flag behaviours. If you assume "sysroot-is-target", this should be done regardless of whether --sysroot was passed explicitly or a default value was chosen for it. This general principle of programming makes it easier to compose lower-level tools into higher-level tools, as the behaviours are more predictable.
Take your example about sysroot builders, yes if they only focus on wasm32-wasi today it make seem "redundant" but if they extend their functionality or someone composes them with another tool, then it's not redundant and in fact it would be less messy.
I think you're confusing me with @paravoid , we are both Debian developers but I'm giving an alternative opinion here. I didn't write any patches for clang, but I do maintain rustc in Debian as well (where the question about include paths is moot).
sbc100 commentedon Nov 22, 2022
Regarding the duplication if headers, assuming we stick with our decision to treat
wasm32-wasi-pthreadsas a separate target, how should we handle the header redundancy? Should we:a. Ship the headers twice, once under each target subdirectory
b. Ship the headers once in
wasm32-wasiand have clang search or headers under the specific target (wasm32-wasi-pthreads) first and fall back towasm32-wasi?(Any other options?)
I imagine there is some precedent for (a) ? e.g.
/usr/include/x86_64-linux-gnu/and/usr/include/i386-linux-gnu/contains a lot of identical files?sunfishcode commentedon Nov 22, 2022
The wasi-sdk headers appear to be about 9 MiB installed. That's not free, but if it's significantly simpler to duplicate the headers than to figure out some kind of sharing configuration, I propose that we just duplicate it.
sbc100 commentedon Dec 17, 2022
Can we close this now that #331 has landed?
abrown commentedon Dec 19, 2022
Will #331 be shipped in the next version of wasi-sdk? I'm not too sure what the release process is but the original intent of this issue is that future versions of wasi-libc would have both targets. I think we can close this once that is figured out.
sbc100 commentedon Dec 19, 2022
Yes the next version should have two different target triples in the sysroot I think... although there maybe a little more work to make that happen still.
sbc100 commentedon Dec 19, 2022
the question of how we should distribute is kind of answered though: under a different target triple.
abrown commentedon Dec 21, 2022
I agree, but I'm concerned with solving the end problem: @sbc100 or @sunfishcode, what else needs to happen for the
THREAD_MODEL=posixbuilds to be released in the next version of wasi-sdk? If it's just a wasi-sdk thing at this point, I'll open an issue there with whatever you suggest and we can close this one.One other point, though: as I was writing up the proposal to add this new target to Rust, I began to wonder whether
wasm32-wasi-pthreadis in fact the right name for the target. I wonder if perhaps the Rust target might make more sense aswasm32-wasi-threadsand then I foresee some confusion (usewasm32-wasi-threadsfor Rust, usewasm32-wasi-pthreadfor C, etc.). Can we quickly bikeshed the name of this target before we release anything?sbc100 commentedon Dec 21, 2022
I'd be fine with calling the clang triple
wasm32-wasi-threadsif you prefer .. internally withing clang/llvm I believe we do use threadmodel=posix, but I guess that is an implementation detail.sbc100 commentedon Dec 21, 2022
It interesting that using
pthreadin the singular form makes sense to me in the triple but notthreadin the singular.sbc100 commentedon Dec 21, 2022
(earlier comment deleted)
sunfishcode commentedon Dec 21, 2022
The current release process isn't very automated. I take the build artifacts from CI and manually upload them to the release. So to add more artifacts here, we just need to (a) make sure CI produces them, and (b) that whoever does the next release knows to upload those artifacts.
abrown commentedon Jan 19, 2023
Ok, I think the "how" is resolved at this point so we can close this. @yamt has WebAssembly/wasi-sdk#274 open to add
wasm32-wasi-threadssupport to wasi-sdk. With that in place, the right answer for "how to distributeTHREAD_MODEL=posixbuilds will be to use some new-ish version of wasi-sdk and tell the compiler to targetwasm32-wasi-threads— all of that can be documented in the wasi-sdk repository.