]> git.proxmox.com Git - wasi-libc.git/log
wasi-libc.git
2 months agogive a reasonable default of BUILTINS_LIB (#442)
YAMAMOTO Takashi [Wed, 11 Oct 2023 22:42:24 +0000 (07:42 +0900)]
give a reasonable default of BUILTINS_LIB (#442)

2 months agoshlib: specify the sysroot to find the correct crt1 (#441)
YAMAMOTO Takashi [Tue, 10 Oct 2023 15:57:23 +0000 (00:57 +0900)]
shlib: specify the sysroot to find the correct crt1 (#441)

2 months agoremove `-nostdlib` from libc.so link command (#440)
Joel Dice [Sat, 7 Oct 2023 00:10:58 +0000 (18:10 -0600)]
remove `-nostdlib` from libc.so link command (#440)

Per https://reviews.llvm.org/D156205 (which we're planning to backport to LLVM
17 and pull into `wasi-sdk`), we want to link crt1-reactor.o into libc.so so it
exports `_initialize` instead of `__wasm_call_ctors`.

* add `-nodefaultlibs` to libc.so link command

This ensures that `-lc` is not passed to `wasm-ld`.

---------

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
2 months agoAdjust Makefile for LLVM trunk (18) as of 2023-10-03 (#438)
Mike Hommey [Tue, 3 Oct 2023 14:23:29 +0000 (23:23 +0900)]
Adjust Makefile for LLVM trunk (18) as of 2023-10-03 (#438)

https://github.com/llvm/llvm-project/commit/457f582ffe23e951380bc345c4c96ec053c09681
added __FLT128_* macros.

2 months agoadd shared library support (#429)
Joel Dice [Thu, 28 Sep 2023 13:11:09 +0000 (07:11 -0600)]
add shared library support (#429)

* add shared library support

This adds support for building WASI shared libraries per
https://github.com/WebAssembly/tool-conventions/blob/main/DynamicLinking.md.

For the time being, the goal is to allow "pseudo-dynamic" linking using the
Component Model per
https://github.com/WebAssembly/component-model/blob/main/design/mvp/examples/SharedEverythingDynamicLinking.md.
This requires all libraries to be available when the component is created, but
still allows runtime symbol resolution via `dlopen`/`dlsym` backed by a static
lookup table.  This is sufficient to support Python native extensions, for
example.  A complete demo using `wit-component` is available at
https://github.com/dicej/component-linking-demo.

This commit adds support for building `libc.so`, `libc++.so`, and `libc++abi.so`
alongside their static counterparts.

Notes:

- I had to refactor `errno` support a bit to avoid a spurious `_ZTH5errno` (AKA "thread-local initialization routine for errno") import in `libc++.so`.
- Long double print and scan are included by default in `libc.so` rather than in a separate library.
- `__main_argc_argv` is now a weak symbol since it's not relevant for reactors.
- `dlopen`/`dlsym` rely on a lookup table provided by the "dynamic" linker via `__wasm_set_libraries`.  Not all flags are supported yet, and unrecognized flags will result in an error.
- This requires https://reviews.llvm.org/D153293, which we will need to backport to LLVM 16 until 17 is released.  I'll open a `wasi-sdk` PR with that change and various Makefile tweaks to support shared libraries.
- `libc.so` is temporarily disabled for the `wasi-threads` build until someone can make `wasi_thread_start.s` position-independent.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
build `-fPIC` .o files separately from non-`-fPIC` ones

This allows us to build both libc.so and libc.a without incurring indirection
penalties in the latter.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
only build libc.so when explicitly requested

Shared library support in LLVM for non-Emscripten Wasm targets will be added in
version 17, which has not yet been released, so we should not attempt to build
libc.so by default (at least not yet).

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
remove dl.c

I'll open a separate PR for this later.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
update `check-symbols` files

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* generate separate .so files for emulated features

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* revert errno changes in favor of a smaller change

@yamt pointed out there's an easier way to address the `_ZTH5errno` issue I
described in an earlier commit: use `_Thread_local` for both C and C++.  This
gives us a simpler ABI and avoids needing to import a thread-local initializer
for `errno` in libc++.so.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* remove redundant `$(OBJDIR)/%.long-double.pic.o` rule in Makefile

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* consolidate libwasi-emulated-*.so into a single library

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* add comment explaining use of `--whole-archive`

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* Revert "remove redundant `$(OBJDIR)/%.long-double.pic.o` rule in Makefile"

This reverts commit dbe2cb10541dd27e4e0ed71d30ce304b9c9133d6.

* move `__main_void` from __main_void.c to crt1-command.c

This and `__main_argc_argv` are only relevant for commands (not reactors), so it
makes sense to scope them accordingly.  In addition, the latter was being
imported from libc.so, forcing applications to provide it even if it wasn't
relevant.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* Revert "consolidate libwasi-emulated-*.so into a single library"

This reverts commit c6518223a49f60e4bb254a3e77a411fdade18df2.

* build crt1-*.o with `-fPIC`

This ensures they can be used in a PIE or PIC context.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* ignore `__memory_base` when checking undefined symbols

Whether this symbol appears varies between LLVM versions.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* Revert "move `__main_void` from __main_void.c to crt1-command.c"

This reverts commit f3038354610b7eb18bfd39092a2ccc3b72842dc4.

* add explanatory comments to __main_void.c

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
* add `__wasilibc_unmodified_upstream` and comment to `__lctrans_cur`

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
---------

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
2 months agoFix typo in signal.c error messages (#437)
Ingvar Stepanyan [Wed, 27 Sep 2023 15:42:02 +0000 (16:42 +0100)]
Fix typo in signal.c error messages (#437)

https://github.com/WebAssembly/wasi-libc/commit/613e154eb20f137f297acc6f54f2ede40de17b0b fixed it in one function but not the other two :)

2 months agoUpdate thread id validation returned by `__wasi_thread_spawn` (#435)
Marcin Kolny [Mon, 18 Sep 2023 18:41:36 +0000 (20:41 +0200)]
Update thread id validation returned by `__wasi_thread_spawn` (#435)

According to the documentation: https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids, TID should be in the range <1, 0x1FFFFFFF>

3 months agobump version to 0.0~git20230821.ec4566b-2
Fabian Grünbichler [Tue, 28 May 2024 15:08:07 +0000 (17:08 +0200)]
bump version to 0.0~git20230821.ec4566b-2

Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
3 months agobump version to 0.0~git20230821.ec4566b-1
Fabian Grünbichler [Mon, 27 May 2024 12:52:42 +0000 (14:52 +0200)]
bump version to 0.0~git20230821.ec4566b-1

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
3 months agoswitch to LLVM 17
Fabian Grünbichler [Mon, 27 May 2024 12:52:01 +0000 (14:52 +0200)]
switch to LLVM 17

like rustc 1.73

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
3 months agoUpdate upstream source from tag 'upstream/0.0_git20230821.ec4566b'
Fabian Grünbichler [Mon, 27 May 2024 12:49:33 +0000 (14:49 +0200)]
Update upstream source from tag 'upstream/0.0_git20230821.ec4566b'

Update to upstream version '0.0~git20230821.ec4566b'
with Debian dir 419720976474c3cfbbaf2fd936969ed3e92d0c62

3 months agoNew upstream version 0.0~git20230821.ec4566b
Fabian Grünbichler [Mon, 27 May 2024 12:49:33 +0000 (14:49 +0200)]
New upstream version 0.0~git20230821.ec4566b

3 months agobump version to 0.0~git20230621.7018e24-2
Fabian Grünbichler [Mon, 27 May 2024 12:49:18 +0000 (14:49 +0200)]
bump version to 0.0~git20230621.7018e24-2

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
3 months agoNew upstream version 0.0~git20230821.ec4566b
Fabian Grünbichler [Mon, 27 May 2024 12:47:45 +0000 (14:47 +0200)]
New upstream version 0.0~git20230821.ec4566b

3 months agobump version to 0.0~git20230621.7018e24-1
Fabian Grünbichler [Fri, 17 May 2024 10:11:14 +0000 (12:11 +0200)]
bump version to 0.0~git20230621.7018e24-1

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
4 months agorebase patches
Fabian Grünbichler [Fri, 17 May 2024 10:10:15 +0000 (12:10 +0200)]
rebase patches

and drop the one that is no longer needed, since those macros/constants are no
longer defined anyway.

Gbp-Dch: Ignore

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
4 months agoNew upstream version 0.0~git20230621.7018e24
Fabian Grünbichler [Fri, 17 May 2024 10:04:56 +0000 (12:04 +0200)]
New upstream version 0.0~git20230621.7018e24

4 months agoUpdate upstream source from tag 'upstream/0.0_git20230621.7018e24'
Fabian Grünbichler [Fri, 17 May 2024 10:04:56 +0000 (12:04 +0200)]
Update upstream source from tag 'upstream/0.0_git20230621.7018e24'

Update to upstream version '0.0~git20230621.7018e24'
with Debian dir 9b0d9c96eba5ffa7f6fabe1830e7115cacf6a5cb

7 months agobump version to 0.0~git20230113.4362b18-3
Fabian Grünbichler [Thu, 25 Jan 2024 20:48:42 +0000 (21:48 +0100)]
bump version to 0.0~git20230113.4362b18-3

Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
7 months agoswitch to LLVM 16
Fabian Grünbichler [Thu, 25 Jan 2024 20:47:06 +0000 (21:47 +0100)]
switch to LLVM 16

the version currently used by rustc.

Closes: #1061217
Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
12 months agobump version to 0.0~git20230113.4362b18-2
Fabian Grünbichler [Wed, 13 Sep 2023 06:20:01 +0000 (08:20 +0200)]
bump version to 0.0~git20230113.4362b18-2

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
12 months agoRevert "build: enable stack protection"
Fabian Grünbichler [Wed, 13 Sep 2023 06:18:16 +0000 (08:18 +0200)]
Revert "build: enable stack protection"

This reverts commit 6ffd497d926c8e72ac97fb34ffefceb2a05b836c.

Seems like enabling stack protection causes WASM runtimes like wasmedge to
fail, so disable again for now.

12 months agobump version to 0.0~git20230113.4362b18-1
Fabian Grünbichler [Sun, 10 Sep 2023 17:23:51 +0000 (19:23 +0200)]
bump version to 0.0~git20230113.4362b18-1

Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
12 months agobump version to 0.0~git20230113.4362b18-1~exp1
Fabian Grünbichler [Fri, 8 Sep 2023 08:07:02 +0000 (10:07 +0200)]
bump version to 0.0~git20230113.4362b18-1~exp1

Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
12 months agopatches: add DEP-3 metadata
Fabian Grünbichler [Fri, 8 Sep 2023 08:05:58 +0000 (10:05 +0200)]
patches: add DEP-3 metadata

Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
12 months agocleanup lintian overrides
Fabian Grünbichler [Fri, 8 Sep 2023 07:55:56 +0000 (09:55 +0200)]
cleanup lintian overrides

Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
12 months agoupdate d/copyright
Fabian Grünbichler [Fri, 8 Sep 2023 07:55:37 +0000 (09:55 +0200)]
update d/copyright

these files are no longer contained in the upstream sources.

Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
12 months agod/control: update Standards-Version
Fabian Grünbichler [Fri, 8 Sep 2023 07:55:15 +0000 (09:55 +0200)]
d/control: update Standards-Version

Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
12 months agobuild: enable stack protection
Fabian Grünbichler [Fri, 8 Sep 2023 07:38:49 +0000 (09:38 +0200)]
build: enable stack protection

supported now, at least without the control flow part.

Signed-off-by: Fabian Grünbichler <debian@fabian.gruenbichler.email>
12 months agorebase patches
Fabian Grünbichler [Wed, 2 Aug 2023 10:23:41 +0000 (12:23 +0200)]
rebase patches

some dirs got moved/renamed.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
12 months agothreads: change `wasm32-wasi-pthread` to `wasm32-wasi-threads` (#381)
Andrew Brown [Fri, 13 Jan 2023 02:56:52 +0000 (18:56 -0800)]
threads: change `wasm32-wasi-pthread` to `wasm32-wasi-threads` (#381)

* Change `wasm32-wasi-pthread` to `wasm32-wasi-threads`

After some thought, I think that we should rename the `THREAD_MODEL=posix` build to avoid confusion. Why? Though in this project the use of this target does involve pthreads, it will not be so in other standard libraries or languages (see, e.g., https://github.com/rust-lang/compiler-team/issues/574). I think it would be preferable to emphasize the "threads" Wasm-level proposal and the "wasi-threads" proposal rather than the specific details of which threading API is being exposed.

* fix: rename the `expected` output directory as well

12 months agothreads: add `pthread_attr_setdetachstate` (#382)
Andrew Brown [Thu, 12 Jan 2023 03:47:44 +0000 (19:47 -0800)]
threads: add `pthread_attr_setdetachstate` (#382)

This API may not make a lot of sense in a WebAssembly world but it
seemed helpful to include it, even if it doesn't have much effect.

12 months agoRemove hacks for clang 8 (#384)
Mike Hommey [Thu, 12 Jan 2023 02:09:45 +0000 (11:09 +0900)]
Remove hacks for clang 8 (#384)

__FLOAT128__ has been defined since clang 9
__FLT16_* were defined until clang 9

12 months agoAdjust Makefile for LLVM trunk (16) as of 2023-01-05 (#379)
Mike Hommey [Tue, 10 Jan 2023 00:21:58 +0000 (09:21 +0900)]
Adjust Makefile for LLVM trunk (16) as of 2023-01-05 (#379)

https://github.com/llvm/llvm-project/commit/d227c3b68cf5c236902c9ff4fdf8b719c9a3dd26
added __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros.

12 months agoUse __BIGGEST_ALIGNMENT__ instead of max_align_t (#375)
YAMAMOTO Takashi [Mon, 9 Jan 2023 16:33:58 +0000 (01:33 +0900)]
Use __BIGGEST_ALIGNMENT__ instead of max_align_t (#375)

Also, remove no longer necessary __need_STDDEF_H_misc stuff.

References:
https://github.com/WebAssembly/wasi-libc/pull/335
https://github.com/WebAssembly/wasi-sdk/issues/111
https://github.com/llvm/llvm-project/blob/2e999b7dd1934a44d38c3a753460f1e5a217e9a5/clang/lib/Headers/stddef.h#L106-L113

12 months agoDon't use sbrk(0) to determine the initial heap size (#377)
Alex Crichton [Mon, 9 Jan 2023 16:33:05 +0000 (10:33 -0600)]
Don't use sbrk(0) to determine the initial heap size (#377)

* Don't use sbrk(0) to determine the initial heap size

This commit changes the `try_init_allocator` function as part of
dlmalloc to not use `sbrk(0)` to determine the initial heap size. The
purpose of this function is to use the extra memory at the end of linear
memory for the initial allocation heap before `memory.grow` is used to
allocate more memory. To learn the extent of this region the code
previously would use `sbrk(0)` to find the current size of linear
memory. This does not work, however, when other systems have called
`memory.grow` before this function is called. For example if another
allocator is used or if another component of a wasm binary grows memory
for its own purposes then that memory will be incorrectly claimed to be
owned by dlmalloc.

Instead this commit rounds up the `__heap_base` address to the nearest
page size, since that must be allocatable. Otherwise anything above this
rounded address is assumed to be used by something else, even if it's
addressable.

* Use `__heap_end` if defined

* Move mstate initialization earlier

12 months ago__init_tp: Initialize TID to non-zero value (#360)
YAMAMOTO Takashi [Fri, 6 Jan 2023 19:35:27 +0000 (04:35 +0900)]
__init_tp: Initialize TID to non-zero value (#360)

This fixes TID-based locking used within libc.

Also, initialize detach_state.

cf. https://github.com/WebAssembly/wasi-threads/pull/16

12 months agoImplement the critical part of wasi_thread_start in asm (#376)
YAMAMOTO Takashi [Fri, 6 Jan 2023 19:34:22 +0000 (04:34 +0900)]
Implement the critical part of wasi_thread_start in asm (#376)

* Implement the critical part of wasi_thread_start in asm

It's fragile to set up the critical part of C environment in C.

* Specify --target for asm files as well

* wasi_thread_start: Move __tls_base initialization to asm as well

12 months agoEnable pthread_equal function definition (#374)
Shengyun Zhou [Tue, 27 Dec 2022 10:34:03 +0000 (18:34 +0800)]
Enable pthread_equal function definition (#374)

12 months agoUse a separate OBJDIR for each TARGET_TRIPLE (#373)
YAMAMOTO Takashi [Mon, 26 Dec 2022 10:19:11 +0000 (19:19 +0900)]
Use a separate OBJDIR for each TARGET_TRIPLE (#373)

To make it easier to create a sysroot with both triples.

Eg.
```
make -j4 CC=/opt/wasi-sdk-16.0/bin/clang
make -j4 CC=/opt/wasi-sdk-16.0/bin/clang THREAD_MODEL=posix
```

12 months agowasi_thread_start: add a comment (#371)
YAMAMOTO Takashi [Fri, 23 Dec 2022 14:14:21 +0000 (23:14 +0900)]
wasi_thread_start: add a comment (#371)

12 months agoUse `ENOENT` rather than `ENOTCAPABLE` for missing preopens. (#370)
Dan Gohman [Wed, 21 Dec 2022 23:47:53 +0000 (15:47 -0800)]
Use `ENOENT` rather than `ENOTCAPABLE` for missing preopens. (#370)

When a user calls `open` with a path that does not have a corresponding
preopen, set errno to `ENOENT` rather than `ENOTCAPABLE`. This
conceptually represents an attempt to open a path which has not been
provided within the sandbox, so it's more accurately represented as
"not present" rather than "insufficient capabilities".

12 months agoDisable pthread_exit for now (#366)
YAMAMOTO Takashi [Wed, 21 Dec 2022 01:24:09 +0000 (10:24 +0900)]
Disable pthread_exit for now (#366)

The current wasi-threads has no thread-exit functionality.
Thus it isn't straightforward to implement pthread_exit
without leaking thread context. This commit simply disables
pthread_exit for now.

Also, instead of abusing `wasi_proc_exit` for thread exit,
make `wasi_thread_start` return.

Note: `wasi_proc_exit` is supposed to terminate all threads
in the "process", not only the calling thread.

Note: Depending on the conclusion of the discussion about
`wasi_thread_exit`, we might revisit this change later.

References:
https://github.com/WebAssembly/wasi-threads/issues/7
https://github.com/WebAssembly/wasi-threads/pull/17

12 months agothreads: Retrieve default stack size from __heap_base/__data_end (#350)
Marcin Kolny [Mon, 19 Dec 2022 12:18:19 +0000 (12:18 +0000)]
threads: Retrieve default stack size from __heap_base/__data_end (#350)

When compiling with `-z stack-size` flag, only the main thread's stack
size is set to the specified value and other threads use musl's default value.
That's inconsistent with LLD's `-Wl,-stack_size`.

I think we can make it similar to MUSL's behavior, where thread's stack
size can be set via `PT_GNU_STACK` program header (via `-Wl,-z,stack-size`
flag).

Configuring stack size through `pthread_attr_t` still work as expected and
overrides the defaults ([pthread_create.c](https://github.com/WebAssembly/wasi-libc/blob/be1ffd6a9eba1704085987482557c2a32724227f/libc-top-half/musl/src/thread/pthread_create.c#L362))
default settings.

12 months agoReduce over-allocation of stack (#365)
YAMAMOTO Takashi [Mon, 19 Dec 2022 12:16:54 +0000 (21:16 +0900)]
Reduce over-allocation of stack (#365)

* Disable stack guard
* Stop rounding up stack size to PAGE_SIZE

12 months agoAdd a separate install target for threaded libc (#331)
Petr Penzin [Wed, 14 Dec 2022 01:57:57 +0000 (17:57 -0800)]
Add a separate install target for threaded libc (#331)

Produce a different sysroot directory for threaded target. Restructure
`expected` directory to correspond to the target.

12 months ago__wait.c: fix a timeout (#361)
YAMAMOTO Takashi [Tue, 13 Dec 2022 20:07:33 +0000 (05:07 +0900)]
__wait.c: fix a timeout (#361)

Note: The typical symptom of this bug is a busy waiting on a lock.

Note: 0 means immediate timeout. a negative value means no timeout.

12 months agoEnable flockfile and friends (#362)
YAMAMOTO Takashi [Tue, 13 Dec 2022 17:56:45 +0000 (02:56 +0900)]
Enable flockfile and friends (#362)

12 months agothreads: enable access to `pthread_barrier_*` functions (#358)
Andrew Brown [Tue, 13 Dec 2022 17:19:32 +0000 (09:19 -0800)]
threads: enable access to `pthread_barrier_*` functions (#358)

In building some `libc-test` tests, I found these functions were not
compiled in. This change adds `pthread_barrier_init`,
`pthread_barrier_wait`, and `pthread_barrier_destroy` to the
`THREAD_MODEL=posix` build. As has been done with previous pthreads PRs,
this PR skips any inter-process locking by removing any calls to
`__vm_lock` and friends. If in the future WASI gains the "process"
concept, then these locations (and the pre-existing ones) will need to
be modified.

12 months agoEnable pthread_detach (#359)
YAMAMOTO Takashi [Fri, 9 Dec 2022 17:58:46 +0000 (02:58 +0900)]
Enable pthread_detach (#359)

12 months agothreads: enable access to `pthread_attr_get` functions (#357)
Andrew Brown [Thu, 8 Dec 2022 22:55:42 +0000 (14:55 -0800)]
threads: enable access to `pthread_attr_get` functions (#357)

The pthreads API exposes functions for querying the attributes of a
thread. This change allows these functions to be compiled in the
`THREAD_MODEL=posix` build. Some functions are skipped (and documented);
they can be added if/when needed. This change is motivated by a
`libc-test` test that uses these functions.

12 months agoDon't define `_POSIX_THREADS` unless threads are enabled. (#356)
Dan Gohman [Wed, 7 Dec 2022 21:54:19 +0000 (13:54 -0800)]
Don't define `_POSIX_THREADS` unless threads are enabled. (#356)

* Don't define `_POSIX_THREADS` unless threads are enabled.

Fixes #355.

* Remove `_POSIX_THREADS` from predefined-macros.txt.

12 months agowasi_thread_start: remove a useless cast (#354)
YAMAMOTO Takashi [Wed, 7 Dec 2022 17:31:41 +0000 (02:31 +0900)]
wasi_thread_start: remove a useless cast (#354)

12 months ago__wasi_thread_spawn: stop truncating the return value (#353)
YAMAMOTO Takashi [Wed, 7 Dec 2022 17:18:28 +0000 (02:18 +0900)]
__wasi_thread_spawn: stop truncating the return value (#353)

as __wasi_errno_t is uint16_t, with the current coding,
__pthread_create will never see negative return values from
wasi:thread_spawn.
eg. (int)(uint16_t)-1 == 65535.

12 months agoAdjust Makefile for LLVM trunk (16) as of 2022-11-08 (#344)
Mike Hommey [Wed, 7 Dec 2022 16:27:06 +0000 (01:27 +0900)]
Adjust Makefile for LLVM trunk (16) as of 2022-11-08 (#344)

https://github.com/llvm/llvm-project/commit/1e4e2433bcd1a0296ef1043c462252f0d087d90c
enabled sign-ext and mutable-globals by default, which adds
corresponding __wasm_-prefixed #defines.

https://github.com/llvm/llvm-project/commit/9e956995db1fc7e792e3dfb3a465a52626195557
changed the definition of __GNUC_VA_LIST to match that of GCC headers,
leaving it without a value.

12 months agobump version to 0.0~git20221206.8b7148f-1
Fabian Grünbichler [Sun, 3 Sep 2023 18:00:02 +0000 (20:00 +0200)]
bump version to 0.0~git20221206.8b7148f-1

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
12 months agoadd myself to Uploaders
Fabian Grünbichler [Sun, 3 Sep 2023 18:16:38 +0000 (20:16 +0200)]
add myself to Uploaders

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
12 months agodisable cf-protection as well
Fabian Grünbichler [Sun, 3 Sep 2023 18:09:21 +0000 (20:09 +0200)]
disable cf-protection as well

it's not supported yet, but is now enabled by default in Debian.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
12 months agoFix recursive mutex (#433)
YAMAMOTO Takashi [Mon, 21 Aug 2023 17:21:37 +0000 (02:21 +0900)]
Fix recursive mutex (#433)

the robust mutex logic in musl seems to assume that
the bit 29 of TIDs is always zero for some reasons.

from https://git.musl-libc.org/cgit/musl/commit/?id=099b89d3840c30d7dd962e18668c2e6d39f0c626
> note that the kernel ABI also reserves bit 29
> not to appear in any tid,

i'm not sure if the assumption is true or not, given that
FUTEX_TID_MASK is 0x3fffffff.

anyway, when using non-default type of mutex like recursive mutex,
it causes problems as we actually use TID 0x3fffffff for the main thread.

as we don't support robust mutex anyway, this commit simply
comments out the problematic condition.

fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2466

13 months agobump version to 0.0~git20221206.8b7148f-1~exp1
Fabian Grünbichler [Wed, 26 Jul 2023 21:09:19 +0000 (23:09 +0200)]
bump version to 0.0~git20221206.8b7148f-1~exp1

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
14 months agoAdd definitions for PF_INET, PF_INET6 and PF_UNSPEC (#426)
Marcin Kolny [Thu, 13 Jul 2023 16:18:08 +0000 (17:18 +0100)]
Add definitions for PF_INET, PF_INET6 and PF_UNSPEC (#426)

Given there are already AF_* definitions, and they are (now) essentially
synonyms, we add those definitions to enable compilation of code that
already use PF_* macros.

14 months agoAcquire the global lock before initializing malloc (#410)
Moritz Sichert [Tue, 11 Jul 2023 22:33:07 +0000 (00:33 +0200)]
Acquire the global lock before initializing malloc (#410)

In a multi-threaded execution we need to make sure that only exactly one
thread initializes malloc. The function try_init_allocator() can't
easily be made thread-safe, so just move the call to
try_init_allocator() inside the block that holds the lock.

14 months agodlmalloc: require __heap_end (#394)
YAMAMOTO Takashi [Tue, 11 Jul 2023 22:32:08 +0000 (07:32 +0900)]
dlmalloc: require __heap_end (#394)

This commit effectively drops the support of older wasm-ld. (LLVM <15.0.7).

We have two relevant use cases:

* `memory.grow` use outside of malloc
  (eg. used by polyfill preview1 binaries)

* `--init-memory` to somehow preallocate heap
  (eg. avoid dynamic allocations, especially on small environments)

While https://github.com/WebAssembly/wasi-libc/pull/377
fixed the former, it broke the latter if you are using
an older LLVM, which doesn't provide the `__heap_end` symbol,
to link your module.

As we couldn't come up with a solution which satisfies all parties,
this commit simply makes it require new enough LLVM which provides
`__heap_end`. After all, a link-time failure is more friendly to users
than failing later in a subtle way.

14 months agoUse -fno-strict-aliasing for emmalloc (#424)
Josh Stone [Fri, 23 Jun 2023 20:24:52 +0000 (13:24 -0700)]
Use -fno-strict-aliasing for emmalloc (#424)

14 months agoImprove `README.md` (#425)
Andrew Brown [Fri, 23 Jun 2023 20:24:08 +0000 (13:24 -0700)]
Improve `README.md` (#425)

This changes the front-page documentation to:
- use `wasi-libc` instead of "WASI Libc"
- explain how to build the pthreads-enabled `wasm32-wasi-threads` target

14 months agoFix a use-after-free bug for detached threads (#420)
YAMAMOTO Takashi [Wed, 21 Jun 2023 23:45:57 +0000 (08:45 +0900)]
Fix a use-after-free bug for detached threads (#420)

* Fix a use-after-free bug for detached threads

the issue was pointed out by @alexcrichton in
https://github.com/WebAssembly/wasi-libc/issues/405

* Rename map_base_lazy_free_queue as it only keeps a single item

Also, align the comment style with musl.

15 months agoAdjust Makefile for LLVM trunk (17) as of 2023-06-18 (#422)
Mike Hommey [Tue, 20 Jun 2023 17:47:19 +0000 (02:47 +0900)]
Adjust Makefile for LLVM trunk (17) as of 2023-06-18 (#422)

https://github.com/llvm/llvm-project/commit/7dd387d2971d7759cadfffeb2082439f6c7ddd49
added a bunch of __FPCLASS_* macros.

15 months agoFix races around pthread exit and join (#409)
YAMAMOTO Takashi [Wed, 7 Jun 2023 16:51:07 +0000 (01:51 +0900)]
Fix races around pthread exit and join (#409)

16 months agoConvert preopen initialization to be lazy. (#408)
Dan Gohman [Wed, 3 May 2023 19:44:21 +0000 (12:44 -0700)]
Convert preopen initialization to be lazy. (#408)

* Convert preopen initialization to be lazy.

Insteead of eagerly initializing the preopens in a static constructor,
perform preopen initialization the first time it's needed, or before a
close or a renumber which might disrupt the file descriptor space.

And, use a weak symbol with a stub function for use by `close` or
`fd_renumber`, we that they can trigger preopen initialization only
if it's actually needed.

This way, if a program doesn't contain any calls to any function that
needs preopens, it can avoid linking in the preopen initialization code.
And if it contains calls but doesn't execute them at runtime, it can
avoid executing the preopen intiailization code.

A downside here is that this may cause problems for users that call
`__wasi_fd_close` or `__wasi_fd_renumber` directly and close over
overwrite some preopens before libc has a chance to scan them. To
partially address this, this PR does add a declaration for
`__wasilibc_populate_preopens` to <wasi/libc.h> so that users can call
it manually if they need to.

* Fix calling `internal_register_preopened_fd` with the lock held.

Factor out the lock acquisition from the implementation of
`internal_register_preopened_fd` so that we can call it from
`__wasilibc_populate_preopens` with the lock held.

16 months agoUpdate README regarding the Arch Linux package (#412)
Jiri Pospisil [Thu, 27 Apr 2023 17:11:07 +0000 (19:11 +0200)]
Update README regarding the Arch Linux package (#412)

The Arch Linux package is now official and there are other WASI related
packages as well.

17 months agoFix debug build's `predefined-macros.txt` (#407)
Alex Crichton [Wed, 5 Apr 2023 19:13:39 +0000 (14:13 -0500)]
Fix debug build's `predefined-macros.txt` (#407)

This commit fixes the ability to build `wasi-libc` with `-g` options and
possibly without `-O2` options as well. I've found this useful when
debugging issues as historically that the build fails when `-g` is
passed or optimizations are removed due to the checks against these
expectation files. This commit adds more filters to the list of macros
to ensure that optimization/debug related ones are all removed from the
expectation lists.

17 months agoRefresh patches
Blair Noctis [Thu, 30 Mar 2023 18:51:53 +0000 (18:51 +0000)]
Refresh patches

17 months agoBump version to 0.0~git20221206.8b7148f
Blair Noctis [Thu, 30 Mar 2023 18:46:00 +0000 (18:46 +0000)]
Bump version to 0.0~git20221206.8b7148f

17 months agoUpdate upstream source from tag 'upstream/0.0_git20221206.8b7148f'
Blair Noctis [Thu, 30 Mar 2023 18:43:44 +0000 (18:43 +0000)]
Update upstream source from tag 'upstream/0.0_git20221206.8b7148f'

Update to upstream version '0.0~git20221206.8b7148f'
with Debian dir a4848b794e55026ddb78085598d8265d48ef88fd

17 months agoNew upstream version 0.0~git20221206.8b7148f
Blair Noctis [Thu, 30 Mar 2023 18:43:41 +0000 (18:43 +0000)]
New upstream version 0.0~git20221206.8b7148f

17 months agoFix a_store operation in atomic.h (#403)
Wenyong Huang [Fri, 24 Mar 2023 07:34:15 +0000 (15:34 +0800)]
Fix a_store operation in atomic.h (#403)

18 months agoUse __builtin_ctz and __builtin_clz in dlmalloc (#401)
Cheng Shao [Mon, 6 Mar 2023 16:37:38 +0000 (17:37 +0100)]
Use __builtin_ctz and __builtin_clz in dlmalloc (#401)

Co-authored-by: Ben Smith <binjimin@gmail.com>
18 months agoSort the object list passed to ar in the Makefile. (#399)
Pier Angelo Vendrame [Fri, 3 Mar 2023 17:29:24 +0000 (18:29 +0100)]
Sort the object list passed to ar in the Makefile. (#399)

This makes builds reproducible.

18 months agoAvoid using absolute pathnames in Makefile. NFC (#400)
Sam Clegg [Thu, 2 Mar 2023 01:14:42 +0000 (17:14 -0800)]
Avoid using absolute pathnames in Makefile. NFC (#400)

This makes the output of the build a lot more concise and easy to read.

The only real change here is to build each of the crt1 startup files
individually instead to trying to build them all in a single clang
invocation (that latter doesn't allow for -o to be specified which is
a pretty severe limitation, so its best avoided anyway).

It also reduces the size of the `ar` command line for libc itself from
78017 to 43609 (on my machine), which sadly is still tool long for win32
I believe.

18 months agothreads: enable `PTHREAD_{MUTEX,RWLOCK,COND}_INITIALIZER`. (#397)
Catherine [Fri, 24 Feb 2023 15:12:37 +0000 (15:12 +0000)]
threads: enable `PTHREAD_{MUTEX,RWLOCK,COND}_INITIALIZER`. (#397)

18 months agosetup_default_stack_size: set __default_stacksize unconditionally (#396)
YAMAMOTO Takashi [Wed, 22 Feb 2023 15:02:50 +0000 (00:02 +0900)]
setup_default_stack_size: set __default_stacksize unconditionally (#396)

If a user specifies a small stack size for the main,
maybe it's reasonable to use the same size for threads as well.

19 months agoFix MSG_TRUNC (#391)
YAMAMOTO Takashi [Sat, 4 Feb 2023 15:45:56 +0000 (00:45 +0900)]
Fix MSG_TRUNC (#391)

19 months agoAdd a check to reactor modules to ensure _initialize is only called once (#388)
Cheng Shao [Mon, 30 Jan 2023 12:30:02 +0000 (13:30 +0100)]
Add a check to reactor modules to ensure _initialize is only called once (#388)

Calling _initialize multiple times is undefined behavior, since the
ctors are not guaranteed to be idempotent. We should have this safety
check which is similar to #329.

19 months agothreads: implement support for spinlock (#324)
Marcin Kolny [Thu, 26 Jan 2023 17:42:48 +0000 (17:42 +0000)]
threads: implement support for spinlock (#324)

19 months agoRename thread_spawn import (#387)
YAMAMOTO Takashi [Wed, 25 Jan 2023 01:14:03 +0000 (10:14 +0900)]
Rename thread_spawn import (#387)

Following the wit-defined ABI:
https://github.com/WebAssembly/wasi-threads/pull/26

20 months agothreads: change `wasm32-wasi-pthread` to `wasm32-wasi-threads` (#381)
Andrew Brown [Fri, 13 Jan 2023 02:56:52 +0000 (18:56 -0800)]
threads: change `wasm32-wasi-pthread` to `wasm32-wasi-threads` (#381)

* Change `wasm32-wasi-pthread` to `wasm32-wasi-threads`

After some thought, I think that we should rename the `THREAD_MODEL=posix` build to avoid confusion. Why? Though in this project the use of this target does involve pthreads, it will not be so in other standard libraries or languages (see, e.g., https://github.com/rust-lang/compiler-team/issues/574). I think it would be preferable to emphasize the "threads" Wasm-level proposal and the "wasi-threads" proposal rather than the specific details of which threading API is being exposed.

* fix: rename the `expected` output directory as well

20 months agothreads: add `pthread_attr_setdetachstate` (#382)
Andrew Brown [Thu, 12 Jan 2023 03:47:44 +0000 (19:47 -0800)]
threads: add `pthread_attr_setdetachstate` (#382)

This API may not make a lot of sense in a WebAssembly world but it
seemed helpful to include it, even if it doesn't have much effect.

20 months agoRemove hacks for clang 8 (#384)
Mike Hommey [Thu, 12 Jan 2023 02:09:45 +0000 (11:09 +0900)]
Remove hacks for clang 8 (#384)

__FLOAT128__ has been defined since clang 9
__FLT16_* were defined until clang 9

20 months agoAdjust Makefile for LLVM trunk (16) as of 2023-01-05 (#379)
Mike Hommey [Tue, 10 Jan 2023 00:21:58 +0000 (09:21 +0900)]
Adjust Makefile for LLVM trunk (16) as of 2023-01-05 (#379)

https://github.com/llvm/llvm-project/commit/d227c3b68cf5c236902c9ff4fdf8b719c9a3dd26
added __GCC_HAVE_SYNC_COMPARE_AND_SWAP macros.

20 months agoUse __BIGGEST_ALIGNMENT__ instead of max_align_t (#375)
YAMAMOTO Takashi [Mon, 9 Jan 2023 16:33:58 +0000 (01:33 +0900)]
Use __BIGGEST_ALIGNMENT__ instead of max_align_t (#375)

Also, remove no longer necessary __need_STDDEF_H_misc stuff.

References:
https://github.com/WebAssembly/wasi-libc/pull/335
https://github.com/WebAssembly/wasi-sdk/issues/111
https://github.com/llvm/llvm-project/blob/2e999b7dd1934a44d38c3a753460f1e5a217e9a5/clang/lib/Headers/stddef.h#L106-L113

20 months agoDon't use sbrk(0) to determine the initial heap size (#377)
Alex Crichton [Mon, 9 Jan 2023 16:33:05 +0000 (10:33 -0600)]
Don't use sbrk(0) to determine the initial heap size (#377)

* Don't use sbrk(0) to determine the initial heap size

This commit changes the `try_init_allocator` function as part of
dlmalloc to not use `sbrk(0)` to determine the initial heap size. The
purpose of this function is to use the extra memory at the end of linear
memory for the initial allocation heap before `memory.grow` is used to
allocate more memory. To learn the extent of this region the code
previously would use `sbrk(0)` to find the current size of linear
memory. This does not work, however, when other systems have called
`memory.grow` before this function is called. For example if another
allocator is used or if another component of a wasm binary grows memory
for its own purposes then that memory will be incorrectly claimed to be
owned by dlmalloc.

Instead this commit rounds up the `__heap_base` address to the nearest
page size, since that must be allocatable. Otherwise anything above this
rounded address is assumed to be used by something else, even if it's
addressable.

* Use `__heap_end` if defined

* Move mstate initialization earlier

20 months ago__init_tp: Initialize TID to non-zero value (#360)
YAMAMOTO Takashi [Fri, 6 Jan 2023 19:35:27 +0000 (04:35 +0900)]
__init_tp: Initialize TID to non-zero value (#360)

This fixes TID-based locking used within libc.

Also, initialize detach_state.

cf. https://github.com/WebAssembly/wasi-threads/pull/16

20 months agoImplement the critical part of wasi_thread_start in asm (#376)
YAMAMOTO Takashi [Fri, 6 Jan 2023 19:34:22 +0000 (04:34 +0900)]
Implement the critical part of wasi_thread_start in asm (#376)

* Implement the critical part of wasi_thread_start in asm

It's fragile to set up the critical part of C environment in C.

* Specify --target for asm files as well

* wasi_thread_start: Move __tls_base initialization to asm as well

20 months agoEnable pthread_equal function definition (#374)
Shengyun Zhou [Tue, 27 Dec 2022 10:34:03 +0000 (18:34 +0800)]
Enable pthread_equal function definition (#374)

20 months agoUse a separate OBJDIR for each TARGET_TRIPLE (#373)
YAMAMOTO Takashi [Mon, 26 Dec 2022 10:19:11 +0000 (19:19 +0900)]
Use a separate OBJDIR for each TARGET_TRIPLE (#373)

To make it easier to create a sysroot with both triples.

Eg.
```
make -j4 CC=/opt/wasi-sdk-16.0/bin/clang
make -j4 CC=/opt/wasi-sdk-16.0/bin/clang THREAD_MODEL=posix
```

20 months agowasi_thread_start: add a comment (#371)
YAMAMOTO Takashi [Fri, 23 Dec 2022 14:14:21 +0000 (23:14 +0900)]
wasi_thread_start: add a comment (#371)

20 months agoUse `ENOENT` rather than `ENOTCAPABLE` for missing preopens. (#370)
Dan Gohman [Wed, 21 Dec 2022 23:47:53 +0000 (15:47 -0800)]
Use `ENOENT` rather than `ENOTCAPABLE` for missing preopens. (#370)

When a user calls `open` with a path that does not have a corresponding
preopen, set errno to `ENOENT` rather than `ENOTCAPABLE`. This
conceptually represents an attempt to open a path which has not been
provided within the sandbox, so it's more accurately represented as
"not present" rather than "insufficient capabilities".

21 months agoDisable pthread_exit for now (#366)
YAMAMOTO Takashi [Wed, 21 Dec 2022 01:24:09 +0000 (10:24 +0900)]
Disable pthread_exit for now (#366)

The current wasi-threads has no thread-exit functionality.
Thus it isn't straightforward to implement pthread_exit
without leaking thread context. This commit simply disables
pthread_exit for now.

Also, instead of abusing `wasi_proc_exit` for thread exit,
make `wasi_thread_start` return.

Note: `wasi_proc_exit` is supposed to terminate all threads
in the "process", not only the calling thread.

Note: Depending on the conclusion of the discussion about
`wasi_thread_exit`, we might revisit this change later.

References:
https://github.com/WebAssembly/wasi-threads/issues/7
https://github.com/WebAssembly/wasi-threads/pull/17

21 months agothreads: Retrieve default stack size from __heap_base/__data_end (#350)
Marcin Kolny [Mon, 19 Dec 2022 12:18:19 +0000 (12:18 +0000)]
threads: Retrieve default stack size from __heap_base/__data_end (#350)

When compiling with `-z stack-size` flag, only the main thread's stack
size is set to the specified value and other threads use musl's default value.
That's inconsistent with LLD's `-Wl,-stack_size`.

I think we can make it similar to MUSL's behavior, where thread's stack
size can be set via `PT_GNU_STACK` program header (via `-Wl,-z,stack-size`
flag).

Configuring stack size through `pthread_attr_t` still work as expected and
overrides the defaults ([pthread_create.c](https://github.com/WebAssembly/wasi-libc/blob/be1ffd6a9eba1704085987482557c2a32724227f/libc-top-half/musl/src/thread/pthread_create.c#L362))
default settings.

21 months agoReduce over-allocation of stack (#365)
YAMAMOTO Takashi [Mon, 19 Dec 2022 12:16:54 +0000 (21:16 +0900)]
Reduce over-allocation of stack (#365)

* Disable stack guard
* Stop rounding up stack size to PAGE_SIZE