]> git.proxmox.com Git - wasi-libc.git/log
wasi-libc.git
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.

23 months 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.

23 months 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.

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

23 months 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

23 months 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

23 months 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*

23 months 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

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

23 months 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.

2 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.

2 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.

3 years agoAvoid calling `poll_oneoff` with zero subscriptions. (#162)
Dan Gohman [Tue, 2 Jun 2020 02:00:30 +0000 (19:00 -0700)]
Avoid calling `poll_oneoff` with zero subscriptions. (#162)

* Avoid calling `poll_oneoff` with zero subscriptions.

With https://github.com/WebAssembly/WASI/pull/193 merged, WASI is moving
to make `poll_oneoff` with no arguments an error. Even though that's in
ephemeral and not yet in a snapshot, we can start to anticipate it in
libc:
 - Remove the `pause` function, since WASI has no signals and thus no
   way to ever wake it up short of having the host terminate it.
 - Make `poll` and `pselect` return `ENOTSUP` in the case of having no
   events to wait for.

* Remove `pause` from the defined-symbols.txt list.

* Fix __wasilibc_unmodified_upstream markers.

* Check for zero subscriptions, rather than zero events.

Make `poll` and `pselect` return `ENOTSUP` when asked to poll on zero
subscriptions, rather than when the systerm returns zero events.

While here, drop the `__wasilibc_unmodified_upstream` markers, which
were already pretty noisy here, and would be significantly worse with
this change.

* Add comments about the subtle relationship between nfds and nsubscriptions.

* Rewrite the comment.

* Fix code quotes.

3 years agoMerge the basics component into libc-bottom-half. (#199)
Dan Gohman [Mon, 1 Jun 2020 23:44:05 +0000 (16:44 -0700)]
Merge the basics component into libc-bottom-half. (#199)

We no longer have a need to maintain basics as a separate component.
Folding it into libc-bottom-half eliminates a fair amount of redundancy.

3 years agoRewrite the preopen functionality. (#173)
Dan Gohman [Mon, 1 Jun 2020 21:32:24 +0000 (14:32 -0700)]
Rewrite the preopen functionality. (#173)

* Rewrite the preopen functionality.

Rewrite the preopen functionality to be simpler, better organized,
and better integrated into WASI libc. Preopen support has diverged so
much from libpreopen that it no longer makes sense to track libpreopen
as an explicit upstream. And add more documentation.

* Fix missing #include.

* Fix a compilation error.

3 years agoReplace old <signal.h> support with emulated <signal.h> support. (#183)
Dan Gohman [Fri, 29 May 2020 20:07:52 +0000 (13:07 -0700)]
Replace old <signal.h> support with emulated <signal.h> support. (#183)

wasm doesn't support signals, so provide an emulation layer, enabled
with -D_WASI_EMULATED_SIGNAL and -lwasi-emulated-signal.

3 years agoReactor support. (#74)
Dan Gohman [Fri, 29 May 2020 16:09:58 +0000 (09:09 -0700)]
Reactor support. (#74)

* Add support for the Reactor model.

* Mark _activate and _start as wasm exports.

* Rename _activate to _initialize.

* Don't define `_fini`.

* Rename reactor-crt1.c to crt1-reactor.c.

3 years agoMake mmap() possible to use in a conformant way. (#197)
whitequark [Tue, 26 May 2020 19:49:13 +0000 (19:49 +0000)]
Make mmap() possible to use in a conformant way. (#197)

3 years agoMake munmap() actually work. (#198)
whitequark [Tue, 26 May 2020 19:14:52 +0000 (19:14 +0000)]
Make munmap() actually work. (#198)

Before this commit, he header of a mapped area, `struct map`, was
defined as follows:

    struct map {
        int prot;
        int flags;
        off_t offset;
        size_t length;
        char body[];
    };

Because the size and alignment of an `off_t` is 8 bytes, the entire
structure was padded to 24 bytes. However, the offset of `body` into
`struct map` was only 20 bytes. Therefore the code in mmap() and
munmap() did not agree on the offset from header to body.

This commit changes mmap() to skip the entire header, which is what
munmap() expects and what the size calculation uses.

4 years agoCI: use llvm 10.0.0 release (#194)
Pat Hickey [Mon, 6 Apr 2020 23:53:56 +0000 (16:53 -0700)]
CI: use llvm 10.0.0 release (#194)

* CI: use llvm 10.0.0 release

* ci: download mac over https, add -L flag to curl

* llvm 10 is shipping for ubuntu 18.04, which is reasonable

* llvm releases are now served from github! :tada:

* oops

* one of these days ill get it right

* love too program in yml

* missed the other spot to convert to 18.04

* mac ci: fix clang_dir

4 years agodebug
Pat Hickey [Fri, 3 Apr 2020 21:01:25 +0000 (14:01 -0700)]
debug

4 years agogithub ci: download llvm over https, add -L flag to curl
Pat Hickey [Fri, 3 Apr 2020 20:58:57 +0000 (13:58 -0700)]
github ci: download llvm over https, add -L flag to curl

L means follow redirects

4 years agoAdded utime.h (#188)
Olaf Tomalka [Fri, 3 Apr 2020 22:39:43 +0000 (00:39 +0200)]
Added utime.h (#188)

* Added utime.h

* Changes after code review

* Auto-generated expected files instead of manually editing
* Fix libpreopoen stat and utime not following symlinks correctly

4 years agoregenerate api.h
Pat Hickey [Thu, 2 Apr 2020 22:46:19 +0000 (15:46 -0700)]
regenerate api.h

4 years agogen-headers: make handle output consistient with prior
Pat Hickey [Thu, 2 Apr 2020 21:45:52 +0000 (14:45 -0700)]
gen-headers: make handle output consistient with prior

4 years agowasi submodule: point to latest (witx 0.8.5 release)
Pat Hickey [Thu, 2 Apr 2020 21:45:33 +0000 (14:45 -0700)]
wasi submodule: point to latest (witx 0.8.5 release)

4 years agoUpdate libc-top-half/musl/README
Pat Hickey [Wed, 1 Apr 2020 18:25:43 +0000 (11:25 -0700)]
Update libc-top-half/musl/README

Co-Authored-By: Gabor Greif <ggreif@gmail.com>
4 years agoUpdate URL
Gabor Greif [Wed, 1 Apr 2020 10:13:17 +0000 (12:13 +0200)]
Update URL

4 years agoFix references to musl version
Gabor Greif [Wed, 1 Apr 2020 10:03:06 +0000 (12:03 +0200)]
Fix references to musl version

4 years agoMakefile refactoring; NFC (#186)
Dan Gohman [Fri, 20 Mar 2020 22:45:37 +0000 (15:45 -0700)]
Makefile refactoring; NFC (#186)

* Use ?= for variables intended to be overridable.

* Use `override` consistently for variables not meant to be overridden.

* Omit miscellaneous comments from the build output.

* Tidy up some comments.

* Use `addprefix` to factor out a common prefix.

* Add a comment.

* Reorganize.

* Adjust indentation.

* Simplify the logic for the `check` rule.

* Remove the `override` keywords.

They theoretically protect what the Makefile considers to be
implementation details from being overridden on the command-line,
but in practice this isn't super important, and they add a lot of
clutter.

* Put source file names on their own lines.

4 years agoLazy-initialize the environment variables. (#184)
Dan Gohman [Thu, 19 Mar 2020 16:32:41 +0000 (09:32 -0700)]
Lazy-initialize the environment variables. (#184)

* Lazy-initialize the environment variables.

This is the first in a series of PRs to make it easier to use WASI libc
in Wasm modules that don't have a `main` function. By initializing the
environment on demand, we avoid depending on having `__wasm_call_ctors`
run.

This uses weak symbols strategically to ensure that if `environ` is
used, it is initialized eagerly, but if only `getenv` and friends
are used, the environment is initialized lazily.

Eventually, I expect we'll have a convention for wasm modules without
main functions which will allow the `__wasm_call_ctors` function to be
called automatically, but this helps in simple cases for now.

Fixes #180.

* Add comments explaining the libc-environ-compat.h header usage.

4 years agoFix -std=gnu17 when generating predefined_macros.txt (#187)
Sam Clegg [Wed, 18 Mar 2020 11:26:57 +0000 (07:26 -0400)]
Fix -std=gnu17 when generating predefined_macros.txt (#187)

* Fix -std=gnu11 when generating predefined_macros.txt

The default recently changed in upstream clang:
https://reviews.llvm.org/D75383

We want to be immune to such things when generating this list so that
we can build wasi-libc with any recent clang version.

* 17

4 years agoMention libcxx and libcxxabi too.
Dan Gohman [Tue, 17 Mar 2020 23:21:10 +0000 (16:21 -0700)]
Mention libcxx and libcxxabi too.

4 years agoUpdate WASI Libc's README.md.
Dan Gohman [Tue, 10 Mar 2020 23:35:50 +0000 (16:35 -0700)]
Update WASI Libc's README.md.

Update the description, point users to wasi-sdk as a simpler place to
get started using this library, and remove old text about being a
"reference" implementation.

4 years agoMulti-license wasi-libc under Apache and MIT licenses. (#174)
Dan Gohman [Sat, 29 Feb 2020 09:52:28 +0000 (01:52 -0800)]
Multi-license wasi-libc under Apache and MIT licenses. (#174)

Multi-license wasi-libc under the Apache-2.0 WITH LLVM-exception,
Apache-2.0, and MIT licenses.

4 years agoAdd support for `__main_argc_argv`.
Dan Gohman [Fri, 20 Dec 2019 23:14:02 +0000 (15:14 -0800)]
Add support for `__main_argc_argv`.

This adds support for the `__main_argc_argv` change, while preserving
compatibility with `__original_main`. This is needed by the LTO build
because the `__original_main` hack works in LLVM codegen, which is after
LTO. The `__main_argc_argv` change is implemented in clang, which makes
it properly visible to LTO.

4 years agoUpdate to musl 1.2.0.
Dan Gohman [Wed, 26 Feb 2020 16:56:59 +0000 (08:56 -0800)]
Update to musl 1.2.0.

See the WHATSNEW file for details. The biggest change in musl is the
switch to 64-bit time_t for 32-bit targets, however WASI libc was already
using 64-bit time_t. The main change affecting WASI is an update to
Unicode 12.1.0.

4 years agoUpdate to musl 1.1.24.
Dan Gohman [Mon, 14 Oct 2019 16:00:02 +0000 (09:00 -0700)]
Update to musl 1.1.24.

See the WHATSNEW file for details; this doesn't have any major changes
for wasi-libc; in particular, the new catgets and GLOB_TILDE features
are disabled.