]> git.proxmox.com Git - wasi-libc.git/commit
Fix `make THREAD_MODEL=posix` (#311)
authorAndrew Brown <andrew.brown@intel.com>
Tue, 9 Aug 2022 15:08:37 +0000 (08:08 -0700)
committerGitHub <noreply@github.com>
Tue, 9 Aug 2022 15:08:37 +0000 (08:08 -0700)
commitdcd28cf8f6db612d8f71f2f9ca6bb6b4e46451b8
treec670f6fb528bc6847828493c35b3ecc5c773b292
parent69031b63706df46e8e15ffeaaddeb3d1c5c0d462
Fix `make THREAD_MODEL=posix` (#311)

* Fixes for the THREAD_MODEL=posix build

* Fix expected symbols from previous commit

* Enable `lock` in `random.c` when threads are enabled

This uses the `_REENTRANT` definition to indicate when the `lock` should
be available.

* Disable `aio.h` when compiling for threads

In talking to @sunfishcode about `aio.h`, this functionality is not yet
a primary concern (it was already disabled in the default,
single-threaded mode). Additionally, this change adds expectation lines
for the new symbols/includes added and removed by `pthread.h`.

This change was reached by running:
```console
$ git diff --no-index expected/wasm32-wasi sysroot/share/wasm32-wasi > patch.diff
# replace "sysroot/share" with "expected" in `patch.diff`
$ git apply patch.diff --reject
# manually fix any rejections
```

* Specify the TLS model until LLVM 15 is released

The `-ftls-model` configuration can be removed once https://reviews.llvm.org/D130053 makes its way into an upstream release.

* Rename `__wasi_libc_pthread_self` to `__wasilibc_pthread_self`

The symbol is still undefined, though.

* Add different sets of expected output based on THREAD_MODEL

* Re-add trailing whitespace to `predefined-macros.txt`

@sbc100 wanted to retain the whitespace trailing after certain
predefined macro lines. This change restores that whitespace from
upstream and re-generates the POSIX version using the following command:

```console
$ git diff --no-index expected/wasm32-wasi/posix/predefined-macros.txt sysroot/share/wasm32-wasi/predefined-macros.txt | sed 's/sysroot\/share\/wasm32-wasi/expected\/wasm32-wasi\/posix/' | git apply
```

* Protect `preopens.c` against concurrent access

* Only build thread-capable wasi-libc on latest version of Clang

* Use `thrd_sleep` from MUSL instead of aliasing `nanosleep`

* Define `pthread_setcancelstate` in `THREAD_MODEL=posix` builds

There are other options here (e.g., always define the `pthread_*`
symbols with stubs) but until we discuss that this is an intermediate
working step.

* Define a Wasm global to store `pthread_self`

* Remove `g_needs_dynamic_alloc` global

* Document the state of pthread support

* review: de-duplicate symbols based on #314

* review: only define `__wasilibc_cwd_{un}lock` when needed

* review: add #ifdefs to `__pthread_setcancelstate`

* review: add additional #ifdefs to `pthread_self.c`

* review: put lock definition behind #ifdef _REENTRANT

* review: remove pthread_setcancelstate.c

* review: re-fix indentation

* review: alias __clock_nanosleep in bottom half

* review: remove extra line

Co-authored-by: Sam Clegg <sbc@chromium.org>
30 files changed:
.github/workflows/main.yml
Makefile
README.md
expected/wasm32-wasi/defined-symbols.txt [deleted file]
expected/wasm32-wasi/include-all.c [deleted file]
expected/wasm32-wasi/posix/defined-symbols.txt [new file with mode: 0644]
expected/wasm32-wasi/posix/include-all.c [new file with mode: 0644]
expected/wasm32-wasi/posix/predefined-macros.txt [new file with mode: 0644]
expected/wasm32-wasi/posix/undefined-symbols.txt [new file with mode: 0644]
expected/wasm32-wasi/predefined-macros.txt [deleted file]
expected/wasm32-wasi/single/defined-symbols.txt [new file with mode: 0644]
expected/wasm32-wasi/single/include-all.c [new file with mode: 0644]
expected/wasm32-wasi/single/predefined-macros.txt [new file with mode: 0644]
expected/wasm32-wasi/single/undefined-symbols.txt [new file with mode: 0644]
expected/wasm32-wasi/undefined-symbols.txt [deleted file]
libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c
libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c
libc-bottom-half/sources/chdir.c
libc-bottom-half/sources/getcwd.c
libc-bottom-half/sources/getentropy.c
libc-bottom-half/sources/preopens.c
libc-top-half/musl/arch/wasm32/atomic_arch.h
libc-top-half/musl/arch/wasm32/pthread_arch.h
libc-top-half/musl/include/pthread.h
libc-top-half/musl/src/conf/sysconf.c
libc-top-half/musl/src/internal/pthread_impl.h
libc-top-half/musl/src/prng/random.c
libc-top-half/musl/src/thread/pthread_self.c
libc-top-half/musl/src/thread/pthread_setcancelstate.c
libc-top-half/musl/src/thread/thrd_sleep.c