]> git.proxmox.com Git - wasi-libc.git/log
wasi-libc.git
18 months agoBeginning porting Emscripten's emmalloc to wasi-libc.
Dan Gohman [Fri, 14 Oct 2022 23:01:00 +0000 (16:01 -0700)]
Beginning porting Emscripten's emmalloc to wasi-libc.

emmalloc.c is derived from Emscripten at this path here:

https://github.com/emscripten-core/emscripten/blob/main/system/lib/emmalloc.c

19 months agoAdd a check to command modules to ensure that they're only started once. (#329)
Dan Gohman [Fri, 14 Oct 2022 00:58:14 +0000 (17:58 -0700)]
Add a check to command modules to ensure that they're only started once. (#329)

* Add a check to command modules to ensure that they're only started once.

Wasm command modules should only be called once per instance, because
the programming model doesn't leave linear memory in a reusable state
when the program exits. As use cases arise for loading wasm modules in
environments that want to treat them like reactors, add a safety check
to ensure that command modules are used according to their
expectations.

19 months agothreads: enable pthread_join (#336)
Marcin Kolny [Mon, 10 Oct 2022 22:25:56 +0000 (23:25 +0100)]
threads: enable pthread_join (#336)

19 months agothreads: Enable __lock file for posix thread model (#337)
Marcin Kolny [Mon, 10 Oct 2022 22:19:25 +0000 (23:19 +0100)]
threads: Enable __lock file for posix thread model (#337)

19 months agoAvoid depending on `max_align_t` in <__struct_sockaddr.h>.
Dan Gohman [Mon, 10 Oct 2022 17:35:30 +0000 (10:35 -0700)]
Avoid depending on `max_align_t` in <__struct_sockaddr.h>.

`max_align_t` is not declared in C99 mode, so use an aligned attribute
and `__BIGGEST_ALIGNMENT__` instead.

Fixes WebAssembly/wasi-sdk#111.

19 months agoFix missing errno assignments.
Dan Gohman [Thu, 6 Oct 2022 18:48:54 +0000 (11:48 -0700)]
Fix missing errno assignments.

In PR #294 I removed a little too much code; we still need to assign to
`errno` in the code in question here.

19 months agoAdd braces to `if` statements whose bodies have multiple statements.
Dan Gohman [Thu, 6 Oct 2022 17:43:42 +0000 (10:43 -0700)]
Add braces to `if` statements whose bodies have multiple statements.

Add braces to `if` statements so that the whole intended body is covered
by the conditional.

19 months agothreads: implement `pthread_create` (#325)
Andrew Brown [Tue, 4 Oct 2022 14:21:18 +0000 (07:21 -0700)]
threads: implement `pthread_create` (#325)

* threads: implement `pthread_create`

As described in the [`wasi-threads`] proposal, this change implements
`pthread_create` using the new `wasi_thread_spawn(void *arg)` API. As
described there, `wasi-libc` exports the thread entry point with the
expected name, `wasi_thread_start`, and then unwraps the passed argument
`struct` to invoke the user function with the user argument `struct`.

[`wasi-threads`]: https://github.com/WebAssembly/wasi-threads/pull/5

Previously, the TID was only passed to the child thread entry point; the
parent thread was forced to wait until the child thread set the TID in
the pthread structure. With this change, the TID will be passed not only
to the child thread but also returned to the parent thread, so that
either side can make progress. The `i32.store` becomes an
`i32.atomic.store` to avoid concurrent writes.

19 months agoUse quotes instead of angle brackets.
Dan Gohman [Wed, 28 Sep 2022 21:32:52 +0000 (14:32 -0700)]
Use quotes instead of angle brackets.

19 months agoDon't run static constructors on arbitrary user exports.
Dan Gohman [Fri, 23 Sep 2022 18:46:59 +0000 (11:46 -0700)]
Don't run static constructors on arbitrary user exports.

Previously, "new-style commmands" considered every user-defined
export to be a potential command entrypoint, so wasi-libc and wasm-ld
cooperated to run the user's static constructors on each entrypoint.

This form of new-style command turned out not to be useful, and it
interferes with some use cases, so disable it.

This is done by making an explicit call to `__wasm_call_ctors`, which
tells wasm-ld that it shouldn't synthesize any calls to
`__wasm_call_ctors` on its own.

20 months agomake `__get_tp()` a static function (#327)
Marcin Kolny [Mon, 19 Sep 2022 20:53:39 +0000 (21:53 +0100)]
make `__get_tp()` a static function (#327)

I'm not sure if the function really has to be exported. If so, we should
probably move it to a separate compilation unit, otherwise it will be defined
multiple times (e.g. in `strerror.o` and `__lctrans.o`) causing linker errors.
However, I don't see a reason (at least for now) to export this function,
therefore making it static in this PR.

20 months agothreads: implement support for conditional variables (#323)
Marcin Kolny [Tue, 6 Sep 2022 21:21:06 +0000 (23:21 +0200)]
threads: implement support for conditional variables (#323)

The implementation is not as efficient as for native Linux platform due
to lack of FUTEX_REQUEUE-like system call in WASI.

For now we wake all the waiters which is inefficient; if that becomes
a bottleneck, I suggest we'll revisit the implementation.

20 months agoImplement support for pthread_rwlock (#321)
Marcin Kolny [Tue, 6 Sep 2022 17:14:07 +0000 (19:14 +0200)]
Implement support for pthread_rwlock (#321)

* threads: implement support for pthread_rwlockattr

* threads: implement support for pthread_rwlock

20 months agothreads: implement support for pthread_condattr (#320)
Marcin Kolny [Tue, 6 Sep 2022 17:13:21 +0000 (19:13 +0200)]
threads: implement support for pthread_condattr (#320)

21 months agothreads: implement support for unnamed semaphores (#316)
Andrew Brown [Mon, 22 Aug 2022 21:22:09 +0000 (14:22 -0700)]
threads: implement support for unnamed semaphores (#316)

[POSIX semaphores] come in two forms: named and unnamed. Roughly, named
semaphores use files to implement locking across processes; unnamed
semaphores use a shared memory region to implement locking across
threads in the same process. Since WASI currently has no process concept
(and it is relatively unclear how to map the WASI files as shared
memory), only the unnamed semaphores are supported by this changed. This
means that `sem_open`, `sem_close`, and `sem_unlink` will not available
to programs compiled with a threads-enabled `wasi-libc`.

[POSIX semaphores]: https://man7.org/linux/man-pages/man7/sem_overview.7.html

21 months agothreads: implement support for pthread mutexes (#315)
Andrew Brown [Mon, 22 Aug 2022 15:39:44 +0000 (08:39 -0700)]
threads: implement support for pthread mutexes (#315)

This change adds pthread's mutex support to the `THREAD_MODEL=posix`
build of wasi-libc. Some less-common features are unsupported and
documented here:
- mutex robust lists are disabled and their use will return a runtime
  error; currently WASI does not support the concept of multiple
  processes so maintaining robust mutexes across processes does not yet
  make sense in wasi-libc
- timed locks with priority inheritance (PI) are disabled and will act
  as any other mutex; this feature is related to task priorities which
  is not yet relevant in the WASI ecosystem (see [priority-inheritance
  futexes](https://man7.org/linux/man-pages/man2/futex.2.html))
- thread cancellation is ignored; this feature is difficult to support
  and @sunfishcode would likely want to discuss this before adding it at
  some later time.

21 months agoFix `make THREAD_MODEL=posix` (#311)
Andrew Brown [Tue, 9 Aug 2022 15:08:37 +0000 (08:08 -0700)]
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>
21 months agoSort lists of input files (#313)
Bernhard M. Wiedemann [Tue, 9 Aug 2022 04:54:37 +0000 (06:54 +0200)]
Sort lists of input files (#313)

For reproducible .a files in spite of non-deterministic
filesystem readdir order

Without this patch, find returned files in filesystem order
and llvm-ar used that order to create .a files.

21 months agoRemove duplicates from `defined-symbols.txt` (#314)
Andrew Brown [Mon, 1 Aug 2022 22:52:16 +0000 (15:52 -0700)]
Remove duplicates from `defined-symbols.txt` (#314)

In #311, it became apparent that duplicate symbol definitions were
becoming unwieldy. This change merges all duplicates using `uniq`.

22 months agoMove `weak` attribute to front (#310)
Andrew Brown [Tue, 26 Jul 2022 23:12:17 +0000 (16:12 -0700)]
Move `weak` attribute to front (#310)

This is a follow-up based on @sbc100's comments in #306.

22 months agoFix typo
Andrew Brown [Tue, 26 Jul 2022 22:57:48 +0000 (15:57 -0700)]
Fix typo

22 months agoUse MUSL's `weak*` feature in bottom half (#306)
Andrew Brown [Tue, 26 Jul 2022 21:15:12 +0000 (14:15 -0700)]
Use MUSL's `weak*` feature in bottom half (#306)

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.

22 months agoDelete several blocks of unused code. (#294)
Dan Gohman [Wed, 20 Jul 2022 22:46:06 +0000 (15:46 -0700)]
Delete several blocks of unused code. (#294)

* Delete several blocks of unused code.

Delete several pieces of code from libc-bottom-half/cloudlibc that aren't in
use on wasi-libc.

* Delete more of `_CLOCK_PROCESS_CPUTIME_ID` or `_CLOCK_THREAD_CPUTIME_ID`.

22 months agoUpdate README and add CI-tests for minimal supported LLVM-version (10) (#302)
msirringhaus [Wed, 13 Jul 2022 15:49:17 +0000 (17:49 +0200)]
Update README and add CI-tests for minimal supported LLVM-version (10) (#302)

Fixes: #301
22 months agoAdd a `getpagesize` function. (#300)
Dan Gohman [Mon, 11 Jul 2022 15:27:39 +0000 (08:27 -0700)]
Add a `getpagesize` function. (#300)

* Add a `getpagesize` function.

This adds a `getpagesize` function. This interface is deprecated in POSIX,
but it's sufficiently widely used and not problematic in practice.

* Use musl's `getpagesize`.

* Enable the `getpagesize` declaration in unistd.h.

23 months agoFix `gettimeofday` to correctly handle a null argument.
Dan Gohman [Wed, 25 May 2022 03:55:41 +0000 (20:55 -0700)]
Fix `gettimeofday` to correctly handle a null argument.

`gettimeofday` is defined to do nothing if passed NULL.

23 months agoRemove support for `__original_main`. (#295)
Dan Gohman [Wed, 1 Jun 2022 15:51:20 +0000 (08:51 -0700)]
Remove support for `__original_main`. (#295)

* Remove support for `__original_main`.

This was used in old LLVM versions. Recent LLVM versions all emit either
`__main_void` or `__main_argv_argc`, so we can use those directly.

* Update the CI to use LLVM 14.0.0.

2 years agoUpdate to musl 1.2.3.
Dan Gohman [Wed, 25 May 2022 02:31:23 +0000 (19:31 -0700)]
Update to musl 1.2.3.

* Update to musl 1.2.3.

See the WHATSNEW file for details.

2 years agoFix utimensat to avoid passing uninitialized values into WASI calls.
Dan Gohman [Tue, 24 May 2022 20:56:33 +0000 (13:56 -0700)]
Fix utimensat to avoid passing uninitialized values into WASI calls.

Previously, utimensat would leave the mtim and/or atim timestamps
uninitialized when the `MTIM_NOW` or `ATIM_NOW` were in use, because
that means the respective timestamps are not used.

However, clang now automatically adds `noundef` to the arguments in
functions like `__wasi_path_filestat_set_times`, and there are cases
where simplifycfg can see paths where the uninitialized values are
passed to those `noundef` arguments.

To fix this, change the utimens code to zero out the timestamps when
they aren't in use, to avoid passing uninitialized arguments.

2 years agoImplement BULK_MEMORY_THRESHOLD
Cheng Shao [Wed, 18 May 2022 19:19:27 +0000 (19:19 +0000)]
Implement BULK_MEMORY_THRESHOLD

2 years agoAdd TODO pointing to LLVM bug report
Cheng Shao [Sat, 11 Dec 2021 15:04:49 +0000 (15:04 +0000)]
Add TODO pointing to LLVM bug report

2 years agoOnly apply -mbulk-memory to specific files
Cheng Shao [Sat, 4 Dec 2021 05:52:11 +0000 (05:52 +0000)]
Only apply -mbulk-memory to specific files

2 years agoDon't use __builtin version of wmem*
Cheng Shao [Sat, 4 Dec 2021 04:27:20 +0000 (04:27 +0000)]
Don't use __builtin version of wmem*

2 years agoUse bulk memory opcodes when possible
Cheng Shao [Sat, 4 Dec 2021 03:56:45 +0000 (03:56 +0000)]
Use bulk memory opcodes when possible

2 years agoFix test artifacts
Cheng Shao [Sat, 4 Dec 2021 03:33:42 +0000 (03:33 +0000)]
Fix test artifacts

2 years ago-mbulk-memory go brrr
Cheng Shao [Sat, 4 Dec 2021 03:13:34 +0000 (03:13 +0000)]
-mbulk-memory go brrr

2 years agoFix `find_relpath` to handle large buffers correctly.
Dan Gohman [Tue, 10 May 2022 01:16:05 +0000 (18:16 -0700)]
Fix `find_relpath` to handle large buffers correctly.

As a follow-up to #247, fix `find_relpath` to handle large buffers
correctly.

Co-Authored-by: Yuta Saito <kateinoigakukun@gmail.com>
2 years agoExclude C++ headers from the generated include-all.c program.
Dan Gohman [Fri, 6 May 2022 01:04:14 +0000 (18:04 -0700)]
Exclude C++ headers from the generated include-all.c program.

The order that things happen in appears to have changed, and the
include-all.c script is now generated at a time when there can be
C++ headers in the sysroot, so adjust the script to exclude C++
headers.

2 years agoOverride Make's default for CC and AR.
Mike Hommey [Thu, 5 May 2022 05:06:22 +0000 (14:06 +0900)]
Override Make's default for CC and AR.

2 years agofeat: add support for accept and accept4
Harald Hoyer [Mon, 2 May 2022 10:21:42 +0000 (12:21 +0200)]
feat: add support for accept and accept4

Since the socket address of the accepted socket is unknown,
all bytes are set to zero and the length is truncated to the size
of the generic `struct sockaddr`.

Signed-off-by: Harald Hoyer <harald@profian.com>
2 years agoAdjust the Makefile for LLVM 15 as of 2022-04-20
Mike Hommey [Thu, 21 Apr 2022 02:52:43 +0000 (11:52 +0900)]
Adjust the Makefile for LLVM 15 as of 2022-04-20

2 years agobuild: update WASI and partially regenerate `api.h`
Roman Volosatovs [Mon, 4 Apr 2022 15:39:21 +0000 (17:39 +0200)]
build: update WASI and partially regenerate `api.h`

2 years agoAdd implementation file.
Dan Gohman [Mon, 28 Mar 2022 21:55:08 +0000 (14:55 -0700)]
Add implementation file.

2 years agoDefine DTTOIF and IFTODT.
Dan Gohman [Thu, 24 Mar 2022 00:17:34 +0000 (17:17 -0700)]
Define DTTOIF and IFTODT.

Fixes #268.

2 years agoAdjust the Makefile for LLVM 14
Mike Hommey [Fri, 8 Apr 2022 01:38:53 +0000 (10:38 +0900)]
Adjust the Makefile for LLVM 14

2 years ago`WASM_NM` -> `NM` to use standardized env var
John Ericson [Wed, 16 Mar 2022 18:20:29 +0000 (18:20 +0000)]
`WASM_NM` -> `NM` to use standardized env var

Progress towards #269

2 years ago`WASM_AR` -> `AR` to use standardized env var
John Ericson [Wed, 16 Mar 2022 18:20:29 +0000 (18:20 +0000)]
`WASM_AR` -> `AR` to use standardized env var

Progress towards #269

2 years ago`WASM_CFLAGS` -> `EXTRA_CFLAGS`
John Ericson [Wed, 16 Mar 2022 18:20:29 +0000 (18:20 +0000)]
`WASM_CFLAGS` -> `EXTRA_CFLAGS`

Progress towards #269

2 years ago`WASM_CC` -> `CC` to use standardized env var
John Ericson [Tue, 22 Mar 2022 22:33:41 +0000 (22:33 +0000)]
`WASM_CC` -> `CC` to use standardized env var

Progress towards #269

2 years agoPull out `{UN,}DEFINED_SYMBOLS` as make vars
John Ericson [Wed, 30 Mar 2022 02:07:02 +0000 (02:07 +0000)]
Pull out `{UN,}DEFINED_SYMBOLS` as make vars

If the Apple bug is in make and not bash, maybe this will help.

2 years agoDo more explicit env vars for CI
John Ericson [Mon, 21 Mar 2022 23:43:55 +0000 (23:43 +0000)]
Do more explicit env vars for CI

This gets ready for switching to the standard vars, which sadly were
already mis-initialized in this environment so we have to be extra
careful to override them.

2 years agoFix futimens error handling.
Dan Gohman [Mon, 28 Mar 2022 21:44:48 +0000 (14:44 -0700)]
Fix futimens error handling.

Fix a bug introduced in #242 noticed [here]: if `tv_usec` is out of
range, then properly return an error code.

[here]: https://github.com/WebAssembly/wasi-libc/commit/079adff840032c3455eb1cb34dc9ceaa0b2bfc0c#r69631767

2 years agoUpdate the comment at the top of wasi/api.h.
Dan Gohman [Thu, 24 Mar 2022 00:22:32 +0000 (17:22 -0700)]
Update the comment at the top of wasi/api.h.

2 years agoDisable the headerstest test.
Dan Gohman [Wed, 23 Mar 2022 22:52:44 +0000 (15:52 -0700)]
Disable the headerstest test.

2 years agoRemove the signal constants and proc_raise function.
Dan Gohman [Wed, 23 Mar 2022 22:07:36 +0000 (15:07 -0700)]
Remove the signal constants and proc_raise function.

The WASI signal constants and proc_raise function were removed in the
latest [ephemeral], which had been scheduled to be in the next snapshot,
however WASI itself is now transitioning away from the snapshot system.

WASI libc will also be transitioning to updated wit specs once they're
ready, however until that time, we can make the simple change of
removing these signal constants to avoid confusion.

Fixes #271.
Fixes #272.

[ephemeral]: https://github.com/WebAssembly/WASI/tree/main/phases/ephemeral/witx

2 years agoSimplify a header check by using the `SYSROOT_*` variables
John Ericson [Tue, 22 Mar 2022 03:55:01 +0000 (03:55 +0000)]
Simplify a header check by using the `SYSROOT_*` variables

2 years agoAdd `make clean` rule, don't have `include_dirs` nuke other things (#277)
John Ericson [Wed, 23 Mar 2022 00:25:54 +0000 (20:25 -0400)]
Add `make clean` rule, don't have `include_dirs` nuke other things (#277)

I think this separation of concerns is good, though I don't need it for
Nixpkgs.

2 years agoUse `-isystem` instead of `--sysroot` for the installed headers
John Ericson [Mon, 21 Mar 2022 23:16:23 +0000 (23:16 +0000)]
Use `-isystem` instead of `--sysroot` for the installed headers

This is less of a sledgehammer, and prepares the way for #270.

2 years agoEnable support for `utimes` and `futimesat`.
Dan Gohman [Fri, 2 Apr 2021 19:18:20 +0000 (12:18 -0700)]
Enable support for `utimes` and `futimesat`.

These can both be implemented in terms of `utimensat`.

2 years agomore graphical code
Gerd Stolpmann [Wed, 16 Jun 2021 08:55:12 +0000 (10:55 +0200)]
more graphical code

2 years agochdir: fixing a malloc'ed buffer that was not large enough
Gerd Stolpmann [Tue, 15 Jun 2021 19:03:22 +0000 (21:03 +0200)]
chdir: fixing a malloc'ed buffer that was not large enough
(mem corruption)

2 years agoAdjust the Makefile for LLVM 13
Mike Hommey [Wed, 22 Sep 2021 06:35:10 +0000 (15:35 +0900)]
Adjust the Makefile for LLVM 13

2 years agoAllow user to provide CC wrapper (#255)
Vitali Lovich [Wed, 22 Sep 2021 04:52:40 +0000 (21:52 -0700)]
Allow user to provide CC wrapper (#255)

If using a custom toolchain not on the path, explicitly invoking
ccache/sccache is required (also easier to debug that the right compiler
is being invoked). Fixes #253.

2 years agoBuild with -Wno-unknown-warning-option too.
Dan Gohman [Mon, 9 Aug 2021 23:52:35 +0000 (16:52 -0700)]
Build with -Wno-unknown-warning-option too.

To suppress the warning about older compilers warning about the flag to
suppress the warning that newer compilers are emitting.

2 years agoIgnore -Wunused-but-set-variable warnings.
Dan Gohman [Mon, 9 Aug 2021 23:43:57 +0000 (16:43 -0700)]
Ignore -Wunused-but-set-variable warnings.

This come up when compiling musl with newer clang releases and
appear to be harmless.

2 years agoAdd build flag to select malloc implementation
Ayke van Laethem [Tue, 13 Jul 2021 21:10:58 +0000 (23:10 +0200)]
Add build flag to select malloc implementation

Add a build flag MALLOC_IMPL that can be set to dlmalloc or none
(defaulting to dlmalloc) which controls the malloc implementation to
use. The dlmalloc option is the same as before, but selecting none
removes dlmalloc from the libc build.

This flag replaces the BUILD_DLMALLOC flag, which never worked and thus
can be removed without breaking any builds. By switching to MALLOC_IMPL,
there is a clear path towards a different heap implementation, such as
mimalloc.

3 years agoAlso add a way to read `environ` without triggering eager init.
Dan Gohman [Thu, 18 Mar 2021 16:48:01 +0000 (09:48 -0700)]
Also add a way to read `environ` without triggering eager init.

Add a `__wasilibc_get_environ` function which returns the value of
`environ` but without performing eager init.

3 years agoAdd a function to de-initialize the environment-variable state.
Dan Gohman [Thu, 11 Mar 2021 15:26:31 +0000 (07:26 -0800)]
Add a function to de-initialize the environment-variable state.

Add a `__wasilibc_deinit_environ` function which clears the current
environment variable state to the state where next time the environment
variable functions are called, they'll reinitialize the environment.

And add a `__wasilibc_maybe_reinitialize_environ_eagerly` function to
reinitialize the environment variable state if `environ` or `_environ`
are needed.

These functions are needed by wizer to be able to suspend and resume
a program and have it read new environment variables from the host
environment; see bytecodealliance/wizer#8 for background.

3 years agoImplement emulated support for `getpid`.
Dan Gohman [Fri, 2 Apr 2021 19:39:00 +0000 (12:39 -0700)]
Implement emulated support for `getpid`.

Add a simple `getpid` emulation function which just returns a fixed
value, for applications that just use it for logging.

3 years agoAdd some more comments.
Dan Gohman [Mon, 22 Mar 2021 20:30:18 +0000 (13:30 -0700)]
Add some more comments.

3 years agoInclude libwasi-emulated-*.a symbols in defined-symbols.txt.
Dan Gohman [Mon, 22 Mar 2021 20:17:38 +0000 (13:17 -0700)]
Include libwasi-emulated-*.a symbols in defined-symbols.txt.

3 years agoEmulate `clock`, `times`, and `getrusage` using the monotonic clock.
Dan Gohman [Mon, 22 Mar 2021 16:33:30 +0000 (09:33 -0700)]
Emulate `clock`, `times`, and `getrusage` using the monotonic clock.

Upcoming WASI snapshots omit the `PROCESS_CPUTIME` clock, since WASI has
no inherent concept of processes, and since implementations which don't
use a process for each instance don't have a way to implement it
efficiently.

However, `clock`, `times`, and `getrusage` are useful functions, so
provide optional emulated version of them, using the `MONOTONIC` clock.
This means these implementations will measure not just the program's
own CPU time, but also time spent suspended while other programs are
running.

Due to this difference in behavior, put these implementations behind
a flag. Users must pass `-D_WASI_EMULATED_PROCESS_CLOCK` and link with
`-lwasi-emulated-process-clocks` to enable them.

3 years agoUpdate to musl 1.2.2.
Dan Gohman [Thu, 18 Mar 2021 16:47:06 +0000 (09:47 -0700)]
Update to musl 1.2.2.

See the WHATSNEW file for details.

3 years agoUpdate README.md to include Arch Linux in section title
Zheng Luo [Sun, 28 Feb 2021 19:16:48 +0000 (19:16 +0000)]
Update README.md to include Arch Linux in section title

3 years agoUpdate README to include AUR repo
Zheng Luo [Sun, 28 Feb 2021 05:27:15 +0000 (00:27 -0500)]
Update README to include AUR repo

Just created an AUR repo at https://aur.archlinux.org/packages/wasi-libc-git/ . Add its link to README to help fellow Archlinux users

3 years agoUpdate to the next version of the `witx` crate (#234)
Alex Crichton [Tue, 23 Feb 2021 18:18:56 +0000 (12:18 -0600)]
Update to the next version of the `witx` crate (#234)

* Update to the next version of the `witx` crate

* Generate adapter functions instead of simply a header file to have a
  place where adapter code can go.
* Implement adapters in terms of the instructions that the `witx` crate
  tells us about.
* Update the interface of functions to what `witx` expects, notably
  string arguments are now only taken as `char*` and `strlen` happens in
  the adapter function.
* Update defined/predefined/undefined symbol lists for types that have
  been updated.

Some precise generated code has changed but the actual APIs should all
be the same except for the change to not take the length of the string
in the raw WASI call, since idiomatically C doesn't pass the length of
strings around.

Eventually it's expected that the shim functions, while sometimes not
necessary today, will implement more checks and more conversions as
necessary for new APIs.

* Actually update witx submodule

* Comment how to regenerate files

* Tweak name of actual function imports

Make it a bit clearer that they're the ones that we're importing and
calling.

* Update submodule to point to WebAssembly

3 years agoAT_FDCWD support.
Dan Gohman [Thu, 4 Feb 2021 17:29:21 +0000 (09:29 -0800)]
AT_FDCWD support.

AT_FDCWD is a special constant in POSIX that can be passed to *at
functions to indicate the current working directory. Since the
current working directory is emulated in wasi libc, add emulated
AT_FDCWD support as well.

Fixes #42.

3 years agoImplement the cimag/creal functions for all types consistently.
Dan Gohman [Fri, 5 Feb 2021 04:15:04 +0000 (20:15 -0800)]
Implement the cimag/creal functions for all types consistently.

3 years agoAdd -Wno-ignored-pragmas.
Dan Gohman [Fri, 5 Feb 2021 04:14:52 +0000 (20:14 -0800)]
Add -Wno-ignored-pragmas.

3 years agoDefine creal/cimag/etc. in a libc-friendly way.
Dan Gohman [Fri, 5 Feb 2021 04:06:13 +0000 (20:06 -0800)]
Define creal/cimag/etc. in a libc-friendly way.

3 years agoAdd -Wno-missing-braces.
Dan Gohman [Fri, 5 Feb 2021 03:38:59 +0000 (19:38 -0800)]
Add -Wno-missing-braces.

3 years agoAdd -Wno-ignored-attributes.
Dan Gohman [Fri, 5 Feb 2021 03:35:56 +0000 (19:35 -0800)]
Add -Wno-ignored-attributes.

3 years agoAdd -Wno-unused-function.
Dan Gohman [Fri, 5 Feb 2021 03:32:30 +0000 (19:32 -0800)]
Add -Wno-unused-function.

3 years agoAdd -Wno-unused-variable.
Dan Gohman [Fri, 5 Feb 2021 02:55:57 +0000 (18:55 -0800)]
Add -Wno-unused-variable.

3 years agoFix a warning.
Dan Gohman [Fri, 5 Feb 2021 02:16:12 +0000 (18:16 -0800)]
Fix a warning.

3 years agoAdd -Wno-sign-compare too.
Dan Gohman [Fri, 5 Feb 2021 02:08:41 +0000 (18:08 -0800)]
Add -Wno-sign-compare too.

3 years agoIgnore a few warnings which occur in third-party code.
Dan Gohman [Fri, 5 Feb 2021 01:59:31 +0000 (17:59 -0800)]
Ignore a few warnings which occur in third-party code.

3 years agoAdd -Wall -Wextra -Werror to the build.
Dan Gohman [Fri, 5 Feb 2021 00:27:52 +0000 (16:27 -0800)]
Add -Wall -Wextra -Werror to the build.

3 years agoRemove __wasilibc_unmodified_upstream markers from libc-bottom-half.
Dan Gohman [Fri, 5 Feb 2021 00:36:38 +0000 (16:36 -0800)]
Remove __wasilibc_unmodified_upstream markers from libc-bottom-half.

We've already started removing this; this just removes all remaining
ones under the libc-bottom-half directory.

These markers were originally intended to help track upstream changes,
however in practice they created a lot of clutter and weren't that
helpful. And now, upstream cloudlibc is no longer active.

3 years agoUse separate makefile var for CFLAGS (#226)
Albert Cervin [Thu, 10 Dec 2020 16:31:21 +0000 (17:31 +0100)]
Use separate makefile var for CFLAGS (#226)

CFLAGS now get initialized with the provided value for WASM_CFLAGS, or
its default.

This seems to be the intended use case of having `WASM_CFLAGS ?=` at the
top of the Makefile. Otherwise, if WASM_CFLAGS is set on the command
line, it overrides all CFLAGS and for example `--sysroot` is not added,
rendering the build invalid unless it is supplied on the make command
line.

3 years agowindows ci: try moving rustup stuff to non-bash shell (#225)
Pat Hickey [Mon, 30 Nov 2020 23:42:32 +0000 (15:42 -0800)]
windows ci: try moving rustup stuff to non-bash shell (#225)

3 years agoFix sinh's sign handling
Dan Gohman [Mon, 30 Nov 2020 21:25:28 +0000 (13:25 -0800)]
Fix sinh's sign handling

In the musl 1.2.1 update, I made a change to disable the new code in
sinh for handling directed rounding modes, but I only incompletely
disabled it. This led to `sinh(-inf)` computing `inf` instead of `-inf`,
detected in [wasi-libc-test]. This patch fixes it.

[wasi-libc-test]: https://github.com/CraneStation/wasi-libc-test/tree/master/libc-test

3 years agoUpdate to musl 1.2.1. (#222)
Dan Gohman [Mon, 30 Nov 2020 20:47:45 +0000 (12:47 -0800)]
Update to musl 1.2.1. (#222)

See the WHATSNEW file for details. WASI libc currently uses a separate
malloc, so the new mallocng is not currently used.

This includes a few new custom changes to disable code for handling
directed rounding modes. Wasm doesn't have directed rounding modes,
so disabling this code size saves code size, something the WASI libc
project cares about!

3 years agoAdd basic emulation of getcwd/chdir (#214)
Alex Crichton [Mon, 30 Nov 2020 20:40:41 +0000 (14:40 -0600)]
Add basic emulation of getcwd/chdir (#214)

* Add basic emulation of getcwd/chdir

This commit adds basic emulation of a current working directory to
wasi-libc. The `getcwd` and `chdir` symbols are now implemented and
available for use. The `getcwd` implementation is pretty simple in that
it just copies out of a new global, `__wasilibc_cwd`, which defaults to
`"/"`. The `chdir` implementation is much more involved and has more
ramification, however.

A new function, `make_absolute`, was added to the preopens object. Paths
stored in the preopen table are now always stored as absolute paths
instead of relative paths, and initial relative paths are interpreted as
being relative to `/`. Looking up a path to preopen now always turns it
into an absolute path, relative to the current working directory, and an
appropriate path is then returned.

The signature of `__wasilibc_find_relpath` has changed as well. It now
returns two path components, one for the absolute part and one for the
relative part. Additionally the relative part is always dynamically
allocated since it may no longer be a substring of the original input
path.

This has been tested lightly against the Rust standard library so far,
but I'm not a regular C developer so there's likely a few things to
improve!

* Amortize mallocs made in syscalls

* Avoid size bloat on programs that don't use `chdir`

* Add threading compat

* Collect `link`/`renameat` second path lookup

* Update comments about chdir.c in makefile

* Move definition of `__wasilibc_find_relpath_alloc` to header

* Expand comments

* Document the format of strings a bit more

* Fixup a few issues in path logic

* Fix GitHub Actions

3 years agoCI: use $GITHUB_PATH,ENV rather than add-path, set-env
Pat Hickey [Mon, 5 Oct 2020 20:33:32 +0000 (13:33 -0700)]
CI: use $GITHUB_PATH,ENV rather than add-path, set-env

In accordance with this advisory it's recommended we move to a
different scheme of setting env vars and updating PATH:

https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

3 years agoNew-style command support. (#203)
Dan Gohman [Sat, 3 Oct 2020 21:18:39 +0000 (14:18 -0700)]
New-style command support. (#203)

This adds a new crt1-command.c startup file, which uses
[new-style command support]. Instead of calling `__wasm_call_ctors`
and `__wasm_call_dtors` directly, this lets wasm-ld automatically call
them.

This preserves the existing crt1.c, so that the same wasi-libc build
can support old-style and new-style commands, for compatibility during
the transition.

[new-style command support]: https://reviews.llvm.org/D81689

Co-authored-by: Dan Gohman <sunfish@mozilla.com>
3 years agoactivate the use of __heap_base (#215)
vms [Thu, 24 Sep 2020 01:14:32 +0000 (04:14 +0300)]
activate the use of __heap_base (#215)

3 years agoRedefine the `access` bits to be compatible with other systems (#210)
Dan Gohman [Fri, 31 Jul 2020 20:44:58 +0000 (13:44 -0700)]
Redefine the `access` bits to be compatible with other systems (#210)

Normally bits like this would be considered implementation details, but
in this case, `X_OK`, `W_OK`, and `R_OK` line up with `S_IXOTH`,
`S_IWOTH`, and `S_IROTH` on other systems, and those bits do have
well-known values.

3 years agoComment a use of `__attribute__((visibility("protected")))`. (#204)
Dan Gohman [Sat, 13 Jun 2020 03:21:12 +0000 (20:21 -0700)]
Comment a use of `__attribute__((visibility("protected")))`. (#204)

This comments out a use of "protected" visibility, since
[WebAssembly doesn't support it].

[WebAssembly doesn't support it]: https://reviews.llvm.org/D81688

3 years agoRename `__prepare_for_exit` to `__wasm_call_dtors`. (#201)
Dan Gohman [Mon, 8 Jun 2020 22:21:18 +0000 (15:21 -0700)]
Rename `__prepare_for_exit` to `__wasm_call_dtors`. (#201)

This emphasizes the relationship with `__wasm_call_ctors`. Note however
that while `__wasm_call_ctors` is synthesized by the linker,
`__wasm_call_dtors` is still defined by libc.

Static constructors are registered statically, but static destructors
need to be registered dynamically so that they only run if their
corresponding static constructors have run, and so that they're
ordered with respect to interleaved `atexit` calls.