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

4 years agopoint at WASI with tagged unions merged into master
Pat Hickey [Tue, 18 Feb 2020 20:36:35 +0000 (12:36 -0800)]
point at WASI with tagged unions merged into master

4 years agorebased wasi repo branch
Pat Hickey [Fri, 14 Feb 2020 01:12:43 +0000 (17:12 -0800)]
rebased wasi repo branch

4 years agomain: get more useful help by requiring subcommand
Pat Hickey [Fri, 14 Feb 2020 00:48:33 +0000 (16:48 -0800)]
main: get more useful help by requiring subcommand

fake required arguments are no good

4 years agominor change in union AST in wasi- tag is namedtype
Pat Hickey [Fri, 14 Feb 2020 00:48:17 +0000 (16:48 -0800)]
minor change in union AST in wasi- tag is namedtype

4 years agolibc: change to flattened event struct
Pat Hickey [Wed, 12 Feb 2020 17:55:32 +0000 (09:55 -0800)]
libc: change to flattened event struct

4 years agoupdate to WASI where snashot event_u flattened to struct
Pat Hickey [Wed, 12 Feb 2020 17:49:07 +0000 (09:49 -0800)]
update to WASI where snashot event_u flattened to struct

4 years agocloudlibc & libpreopen: changes for tagged unions
Pat Hickey [Thu, 6 Feb 2020 21:21:11 +0000 (13:21 -0800)]
cloudlibc & libpreopen: changes for tagged unions

we decided to abandon the upstream code guarded by
 #ifdef __wasilibc_unmodified_upstream // non-anonymous unions
because these changes are sprawling and those guards are of diminishing
importance

4 years agowasi/api.h: regenerated with tagged unions
Pat Hickey [Thu, 6 Feb 2020 21:20:57 +0000 (13:20 -0800)]
wasi/api.h: regenerated with tagged unions

4 years agoWASI: tagged unions PR wip
Pat Hickey [Thu, 6 Feb 2020 21:19:58 +0000 (13:19 -0800)]
WASI: tagged unions PR wip

4 years agowasi-headers: unions are tagged now
Pat Hickey [Thu, 6 Feb 2020 21:19:44 +0000 (13:19 -0800)]
wasi-headers: unions are tagged now

4 years agoDefine a_clz_32 for musl so that it doesn't use a software version. (#171)
Dan Gohman [Fri, 21 Feb 2020 19:41:05 +0000 (11:41 -0800)]
Define a_clz_32 for musl so that it doesn't use a software version. (#171)

4 years agoWASI libc supports environment variables; update the README. (#172)
Dan Gohman [Fri, 21 Feb 2020 19:40:41 +0000 (11:40 -0800)]
WASI libc supports environment variables; update the README. (#172)

4 years agoRemove unused cloudlibc headers. (#170)
Dan Gohman [Fri, 21 Feb 2020 19:40:23 +0000 (11:40 -0800)]
Remove unused cloudlibc headers. (#170)

4 years agofix macos filename, use https
Pat Hickey [Wed, 19 Feb 2020 23:24:14 +0000 (15:24 -0800)]
fix macos filename, use https

4 years agoCI: upgrade to llvm 9.0.0
Pat Hickey [Wed, 19 Feb 2020 22:15:48 +0000 (14:15 -0800)]
CI: upgrade to llvm 9.0.0

4 years agoremove no-self-update workaround for windows azure
Pat Hickey [Wed, 19 Feb 2020 22:09:50 +0000 (14:09 -0800)]
remove no-self-update workaround for windows azure

4 years agodeprecate azure pipelines CI, build libc on GH Actions
Pat Hickey [Wed, 19 Feb 2020 01:46:29 +0000 (17:46 -0800)]
deprecate azure pipelines CI, build libc on GH Actions

4 years agoDon't call `free` on paths which are about to call `_Exit`. (#161)
Dan Gohman [Fri, 14 Feb 2020 22:02:59 +0000 (14:02 -0800)]
Don't call `free` on paths which are about to call `_Exit`. (#161)

This is a minor code-size optimization.

4 years agogen-headers: Generate assertions of layout from witx (#149)
Pat Hickey [Fri, 7 Feb 2020 21:21:18 +0000 (13:21 -0800)]
gen-headers: Generate assertions of layout from witx (#149)

* use pch/layout branch for witx; generate assertions of layout

* address review comments, add asserts for handle

* change wasm32 support comment to a preprocessor error

* expose `to_c_header` in wasi-headers crate for use in external test harness

* main.rs: inputs and output arguments are optional

so that generate-libc command works

* regen header

4 years agoCorrect minor typo in c_headers.rs (#166)
Daniel Bevenius [Fri, 7 Feb 2020 13:18:10 +0000 (14:18 +0100)]
Correct minor typo in c_headers.rs (#166)

The header api.h was update using the following command:
$ cd tools/wasi-headers
$ cargo run -- WASI/phases/snapshot/witx/typenames.witx \
  WASI/phases/snapshot/witx/wasi_snapshot_preview1.witx \
  --output ../../libc-bottom-half/headers/public/wasi/api.h

4 years agoConvert more wasi-libc code to `//`-style comments. (#153)
Dan Gohman [Fri, 17 Jan 2020 00:00:37 +0000 (16:00 -0800)]
Convert more wasi-libc code to `//`-style comments. (#153)

This is purely a style change, in accordance with #116.

4 years agoImprovements to wasi-headers tool (#160)
Pat Hickey [Tue, 14 Jan 2020 22:24:12 +0000 (14:24 -0800)]
Improvements to wasi-headers tool (#160)

* wasi-headers: update WASI submodule, handle changes to witx ast

* wasi-headers: restructure lib and exe to be more flexible

just factor out some of the hard-coded stuff

4 years agoFix environment variable init to exit successfully. (#159)
Dan Gohman [Tue, 14 Jan 2020 17:56:58 +0000 (09:56 -0800)]
Fix environment variable init to exit successfully. (#159)

This fixes https://github.com/bytecodealliance/wasmtime/issues/783.

4 years agoMove math source files. (#151)
Dan Gohman [Fri, 20 Dec 2019 23:43:31 +0000 (15:43 -0800)]
Move math source files. (#151)

This is split out from the LTO change. It's needed by the LTO build so
that we can easily build these files in non-LTO mode, since they satisfy
calls emitted by LLVM codegen after LTO.

4 years agoAvoid using cast expressions in WASI API constants. (#148)
Dan Gohman [Mon, 16 Dec 2019 21:29:06 +0000 (13:29 -0800)]
Avoid using cast expressions in WASI API constants. (#148)

Cast expressions aren't valid to use in some preprocessor constants, so
change the constants to use `UINT32_C` etc. instead of casts.

Fixes #146.

4 years agoUpdate signal macros after upgrade to snapshot1 (#144)
Sam Clegg [Tue, 3 Dec 2019 17:23:40 +0000 (11:23 -0600)]
Update signal macros after upgrade to snapshot1 (#144)

This should probably have been part of #140 but we don't actually
support signals so this doesn't get much testing I imagine.

The old names like `__WASI_SIGBUS` no longer exist and the new names
look like `__WASI_SIGNAL_BUS`.

4 years agogithub actions: pin checkout action to v1 (#145)
Sam Clegg [Tue, 3 Dec 2019 17:15:26 +0000 (11:15 -0600)]
github actions: pin checkout action to v1 (#145)

master now contains a new v2 beta version of this action that no longer
supports "submodules".   We can update to v2 later once it stabilizes.

4 years agoUse constructor functions for optional init routines. (#142)
Dan Gohman [Mon, 25 Nov 2019 22:04:45 +0000 (14:04 -0800)]
Use constructor functions for optional init routines. (#142)

* Use constructor functions for optional init routines.

Instead of using weak symbols, use constructor function attributes for the
environment and preopen initialization routines. This is simpler, uses
less code, and is more LTO-friendly.

* Change the constructor priorities to start at 50.

We don't currently have specific plans for other levels in the reserved
range (0-100), so leave room for both lower and higher priorities.

4 years agoc header generation updated for reorganized witx ast (#139)
Pat Hickey [Fri, 22 Nov 2019 18:06:12 +0000 (13:06 -0500)]
c header generation updated for reorganized witx ast (#139)

4 years agoCorrect the version of #136 on master (#141)
Dan Gohman [Fri, 22 Nov 2019 04:55:26 +0000 (20:55 -0800)]
Correct the version of #136 on master (#141)

* Add the WASI repo as a submodule.

Also, add the witx filenames to the generated output, and just have
`cargo run` auto-generate the api.h header, rather than using clap.

* Switch witx to a path dependency.

* Add a test.

* Add a test that the generated file is in sync with the generator.

* Enable CI testing with Github Actions.

* Fix the name of the wasi-headers directory.

* Enable submodules.

* Add a diff mechanism to help explain failures.

* Sort the inputs for display.

* More debugging.

* More debugging.

* Add a .gitattributes file forcing text files to be eol=lf.

Most editors these days can deal with eof=lf files, even on Windows, and
this avoids trouble with headers and other generated files differing in
line endings.

4 years agoWasi snapshot preview1 (#140)
Dan Gohman [Fri, 22 Nov 2019 04:06:00 +0000 (20:06 -0800)]
Wasi snapshot preview1 (#140)

* Make __wasi_linkcount_t a uint64_t (#134)

Refs: https://github.com/WebAssembly/WASI/pull/127

* Generate the WASI interface from witx.

This replaces the hand-maintained <wasi/core.h> header with a
<wasi/api.h> generated from witx.

Most of the churn here is caused by upstream WASI renamings; hopefully
in the future ABI updates will be less noisy.

4 years agoIgnore rights in libpreopen. (#129)
Dan Gohman [Thu, 21 Nov 2019 23:49:51 +0000 (15:49 -0800)]
Ignore rights in libpreopen. (#129)

Don't ignore paths which don't have the required rights. This means
that if the lookup finds a path that doesn't have the required
rights, it'll just proceed to the actual operation which will fail
with `ENOTCAPABLE`.

Intuitively, use cases which would depend on having multiple
overlapping matching paths for a given lookup and intelligently
picking the one with the required rights seems like they should
be uncommon.

This is simpler overall, and requires less code.

4 years agoMake the `__original_main` definition weak, fixing -flto. (#138)
Dan Gohman [Wed, 20 Nov 2019 19:35:47 +0000 (11:35 -0800)]
Make the `__original_main` definition weak, fixing -flto. (#138)

4 years agoOptimize `fmin`, `fmax`, etc. (#120)
Dan Gohman [Wed, 20 Nov 2019 19:13:45 +0000 (11:13 -0800)]
Optimize `fmin`, `fmax`, etc. (#120)

Use wasm's builtin min and max operators to implement libc `fmin`,
`fmax, `fminf`, and `fmaxf`, by handling the NaN cases explicitly.

Credit to https://github.com/emscripten-core/emscripten/pull/9689
for spotting this opportunity!

4 years agoDon't pre-check capabilities in `openat`. (#130)
Dan Gohman [Sun, 10 Nov 2019 14:39:00 +0000 (06:39 -0800)]
Don't pre-check capabilities in `openat`. (#130)

Rely on the WASI implementation to check capabilities flags, rather
than also checking them in the userspace `openat` implementation.

This code is admittedly getting fairly dense with `#ifdef`s, so it
may soon make sense to move this file out of the `cloudlibc`
directory and removing the upstream change markers.

4 years agoUse consistent style for wasi-libc C source files. (#131)
Dan Gohman [Fri, 8 Nov 2019 19:59:57 +0000 (11:59 -0800)]
Use consistent style for wasi-libc C source files. (#131)

For now, this means using `//`-style comments in .c source files (though
not public header files), and spaces rather than tabs. No strong opinion
here; this is just what the majority of the current code is using.

This also synchronizes basics/crt/crt1.c with libc-bottom-half's
version, though this is just a cleanup as the former isn't currently used
by the main wasi-libc build.

4 years agoFix unintended recursion in __wasilibc_register_preopened_fd. (#133)
Dan Gohman [Fri, 8 Nov 2019 19:44:18 +0000 (11:44 -0800)]
Fix unintended recursion in __wasilibc_register_preopened_fd. (#133)

4 years agoAvoid a `strdup` call in `__wasilibc_populate_libpreopen`. (#128)
Dan Gohman [Fri, 8 Nov 2019 19:31:44 +0000 (11:31 -0800)]
Avoid a `strdup` call in `__wasilibc_populate_libpreopen`. (#128)

* Avoid a `strdup` call in `__wasilibc_populate_libpreopen`.

Optimize `__wasilibc_populate_libpreopen` to avoid calling `strdup` in
the common case where it's called from `__wasilibc_populate_libpreopen`.

* Convert an if into a ?:.

4 years agoDon't link in libpreopen initialization code when it isn't needed. (#127)
Dan Gohman [Fri, 8 Nov 2019 19:08:22 +0000 (11:08 -0800)]
Don't link in libpreopen initialization code when it isn't needed. (#127)

* Avoid linking in `populate_libpreopen` when it isn't needed.

* Merge adjacent `if`s using `&&`.

4 years agoTemporarily disable the use of `__heap_base`. (#132)
Dan Gohman [Thu, 7 Nov 2019 21:09:31 +0000 (13:09 -0800)]
Temporarily disable the use of `__heap_base`. (#132)

This temporarily disables the feature in
a214f1c0b167608ab4ec3e63f8144c3430af9372, since it hits LLVM bug
43613, which is fixed on LLVM master and awaiting a backport to
the 9.0 branch.

https://bugs.llvm.org/show_bug.cgi?id=43613

4 years agoUse __heap_base by dlmalloc (#114)
vms [Tue, 5 Nov 2019 20:52:51 +0000 (23:52 +0300)]
Use __heap_base by dlmalloc (#114)

* add explicit allocator initialization

* move init to a better place

* fix warnings

* add __wasilibc_try_init_allocator

* move initialization to dlmalloc()

* fix typos

* fix identations

* follow style guide

* review changes

4 years agoAvoid varargs conventions when calling open (#126)
Dan Gohman [Tue, 5 Nov 2019 00:37:45 +0000 (16:37 -0800)]
Avoid varargs conventions when calling open (#126)

* Add an entrypoint for calling open that bypasses the varargs.

* Add an entrypoint for calling openat that bypasses the varargs.

4 years agoRevamp and simplify the libpreopen code. (#110)
Dan Gohman [Mon, 4 Nov 2019 22:56:35 +0000 (14:56 -0800)]
Revamp and simplify the libpreopen code. (#110)

wasi-libc's copy of libpreopen has evolved so many local changes that
it's no longer worth keeping the upstream code structure and marking
changes with __wasilibc_unmodified_upstream.

This PR merges the source files into a single file, removes all
__wasilibc_unmodified_upstream code, eliminates the ability to
allocate multiple preopen lists, eliminates the need for
__wasilibc_init_preopen, eliminates the non-standard eaccess, and
makes several other cleanups. It also enables NDEBUG so that internal
assertions are disabled in release builds.

4 years agoRemove more unsupported headers. (#123)
Dan Gohman [Mon, 4 Nov 2019 21:17:03 +0000 (13:17 -0800)]
Remove more unsupported headers. (#123)

utime.h, sysmacros.h, and libintl.h are all currently unsupported.
Removing them helps programs that autodetect features based on the
existence of headers.

4 years agoAvoid using user identifiers in function declarations. (#124)
Dan Gohman [Mon, 28 Oct 2019 18:08:12 +0000 (11:08 -0700)]
Avoid using user identifiers in function declarations. (#124)

MultiSource/Benchmarks/McCat in llvm-test-suite has a macro named
`n`, so rename function parameters to avoid colliding.

4 years agoDon't build bind_textdomain_codeset.c (#122)
Dan Gohman [Mon, 28 Oct 2019 17:35:45 +0000 (10:35 -0700)]
Don't build bind_textdomain_codeset.c (#122)

`bind_textdomain_codeset` without the rest of libintl.h isn't useful
without the rest of gettext.

4 years agoEnsure `__environ` is initialized even when it's empty. (#125)
Dan Gohman [Mon, 28 Oct 2019 17:34:57 +0000 (10:34 -0700)]
Ensure `__environ` is initialized even when it's empty. (#125)

POSIX requires `environ` to be a pointer to a NULL-terminated array of
pointers, so it itself can't be NULL.

This fixes a regression in src/functional/env.c in wasi-libc-test.

4 years agoCall `populate_args` only if we actually need command-line arguments (#112)
Dan Gohman [Fri, 25 Oct 2019 00:30:46 +0000 (17:30 -0700)]
Call `populate_args` only if we actually need command-line arguments (#112)

* Link `populate_args` only if we actually need command-line arguments.

This avoids linking in the argv/argc initialization code,
and the __wasi_args_sizes_get and __wasi_args_get imports, in
programs that don't use command-line arguments. The way this works is,
if the user writes `int main(int argc, char *argv[])`, the argument
initialization code is loaded, and if they write `int main(void)`,
it's not loaded.

This promotes the `__original_main` mechanism into an effective contract
between the compiler and libc, which wasn't its original purpose,
however it seems to fit this purpose quite well.

* Document that `__original_main` may be the user's zero-arg `main`.

4 years agoFix corner cases and style in the argv/argc code. (#118)
Dan Gohman [Tue, 22 Oct 2019 18:25:19 +0000 (11:25 -0700)]
Fix corner cases and style in the argv/argc code. (#118)

This fixes some potential memory leaks in pathological situations, and
updates the code to use `//`-style comments.

4 years agoWorkaround a bug causing Windows CI failures. (#119)
Dan Gohman [Tue, 22 Oct 2019 15:00:48 +0000 (08:00 -0700)]
Workaround a bug causing Windows CI failures. (#119)

This works around [this bug], which manifests as

```
error: could not remove 'setup' file: 'C:\Users\VssAdministrator\.cargo\bin/rustup-init.exe'
info: caused by: Access is denied. (os error 5)
```

as suggested by [this comment].

[this bug]: https://github.com/microsoft/azure-pipelines-image-generation/issues/1224
[this comment]: https://github.com/CraneStation/wasi-libc/pull/118#issuecomment-544978683

4 years agoCall `populate_environ` only if we actually need environment variables. (#109)
Dan Gohman [Tue, 22 Oct 2019 13:02:44 +0000 (06:02 -0700)]
Call `populate_environ` only if we actually need environment variables. (#109)

* Link `populate_environ` only if we actually need environment variables.

This avoids linking in the environment variable initialization code,
and the __wasi_environ_sizes_get and __wasi_environ_get imports, in
programs that don't use environment variables.

This also removes the "___environ" (three underscores) alias symbol,
which is only in musl for backwards compatibility.

* Switch to //-style comments.

* If malloc fails, don't leave `__environ` pointing to an uninitialized buffer.

* Fix a memory leak if one malloc succeeds and the other fails.

* Use calloc to handle multiplication overflow.

This also handles the NULL terminator.

* Don't initialize __environ until everything has succeeded.

* Avoid leaking in case __wasi_environ_get fails.

* Handle overflow in the add too.

* Add #include <stdlib.h> for malloc etc.

* If the environment is empty, don't allocate any memory.

4 years agoMake sbrk(0) deterministic (#115)
vms [Mon, 21 Oct 2019 22:44:23 +0000 (01:44 +0300)]
Make sbrk(0) deterministic (#115)

* fix the behavior of sbrk(0)

* review changes

4 years agoMiscellaneous cleanups (#113)
Dan Gohman [Fri, 18 Oct 2019 20:53:13 +0000 (13:53 -0700)]
Miscellaneous cleanups (#113)

* Tidy up some #include names.

* Move non-cloudlibc sources out of the cloudlibc directory.

4 years agofix the typo (#108)
vms [Mon, 14 Oct 2019 21:52:10 +0000 (00:52 +0300)]
fix the typo (#108)

* fix the typo

4 years agoRemove -fno-builtin. (#104)
Dan Gohman [Fri, 11 Oct 2019 12:07:34 +0000 (05:07 -0700)]
Remove -fno-builtin. (#104)

* Remove -fno-builtin.

-fno-builtin suppresses optimizations such as turning calls to `sqrt`
or `fabs` into `f64.sqrt` or `f64.abs` instructions inline. Libc code
itself benefits from these optimizations.

I originally added this flag because historically it was needed when
building libc to avoid the compiler pattern-matching the body of memcpy
into a memcpy call, however clang no longer requires this.

* Expand the comment about why we use USE_DL_PREFIX in dlmalloc.

4 years agoDon't define readdir64_r.
Dan Gohman [Fri, 4 Oct 2019 20:15:38 +0000 (13:15 -0700)]
Don't define readdir64_r.

wasi-libc doesn't define readdir_r, so don't define readdir64_r as an
alias for it.

4 years agoOmit musl's stdarg.h and stddef.h from the sysroot.
Dan Gohman [Mon, 29 Apr 2019 12:52:26 +0000 (05:52 -0700)]
Omit musl's stdarg.h and stddef.h from the sysroot.

We already use the compiler's versions of these; this just moves from
having libc #include_next them to having libc just omit them entirely,
which is simpler.

This removes the special code to define musl's include guard, however
I originally added that when I was still working out how WASI's stddef.h
would interact with other code. I believe it's no longer important.

4 years agoFactor out the include-file exclude list into a variable.
Dan Gohman [Mon, 29 Apr 2019 12:50:54 +0000 (05:50 -0700)]
Factor out the include-file exclude list into a variable.

This also starts categorizing these headers into groups and adding
comments explaining their purpose.

4 years agoAdd a CODE_OF_CONDUCT.md file. (#101)
Dan Gohman [Thu, 3 Oct 2019 12:15:49 +0000 (05:15 -0700)]
Add a CODE_OF_CONDUCT.md file. (#101)

4 years agoSet the MALLOC_ALIGNMENT to 16.
Dan Gohman [Fri, 19 Jul 2019 22:06:57 +0000 (15:06 -0700)]
Set the MALLOC_ALIGNMENT to 16.

This isn't strictly required, as wasm SIMD loads and stores work on
unaligned memory. However, it may provide better performance. That said,
this isn't currently studied by any benchmarking.

4 years agoWhen checking undefined symbol list, ignore certain llvm buildins
Sam Clegg [Fri, 30 Aug 2019 01:05:38 +0000 (18:05 -0700)]
When checking undefined symbol list, ignore certain llvm buildins

These can vary between llvm version.  For example a recent upstream
change recently added __multi3 to the list:
https://reviews.llvm.org/D65143

Fixes #98

4 years agoFix a warning about a spurious redundant static keyword.
Dan Gohman [Thu, 29 Aug 2019 14:01:59 +0000 (07:01 -0700)]
Fix a warning about a spurious redundant static keyword.

4 years agoUpdate docs to say "libc" rather than "sysroot" where applicable.
Dan Gohman [Tue, 4 Jun 2019 03:45:29 +0000 (20:45 -0700)]
Update docs to say "libc" rather than "sysroot" where applicable.

4 years agoWASI libc's dirent does have t_type, so define _DIRENT_HAVE_D_TYPE.
Dan Gohman [Thu, 29 Aug 2019 16:40:40 +0000 (09:40 -0700)]
WASI libc's dirent does have t_type, so define _DIRENT_HAVE_D_TYPE.

Also update predefined-macros.txt.

4 years agoFix _DIRENT_HAVE_D_* macros.
Dan Gohman [Thu, 29 Aug 2019 13:58:56 +0000 (06:58 -0700)]
Fix _DIRENT_HAVE_D_* macros.

Don't define _DIRENT_HAVE_D_RECLEN or _DIRENT_HAVE_D_OFF, as WASI libc's
dirent doesn't have d_reclen or d_off.

4 years agoDisable the lseek optimization in C++.
Dan Gohman [Wed, 10 Jul 2019 00:21:38 +0000 (17:21 -0700)]
Disable the lseek optimization in C++.

The lseek optimization turns lseek calls into __wasilibc_tell calls when
possible, using macros and __builtin_constant_p. However, this isn't
safe in C++ code in the presence of namespaces and `using` declarations,
to just disable it in C++ for now.

4 years agoAdd Azure Pipelines definition (#78)
Till Schneidereit [Mon, 12 Aug 2019 11:50:53 +0000 (13:50 +0200)]
Add Azure Pipelines definition (#78)

4 years agoUpdate to musl 1.1.23.
Dan Gohman [Fri, 19 Jul 2019 19:40:16 +0000 (12:40 -0700)]
Update to musl 1.1.23.

See the WHATSNEW file for details; among other things, this contains new
math library implementation for log/exp/pow.

4 years agoFix predefined macros check after recent clang change
Sam Clegg [Fri, 12 Jul 2019 09:21:15 +0000 (02:21 -0700)]
Fix predefined macros check after recent clang change

This is an alternative to #75.

4 years agoDon't declare `realpath` or pseudo-terminal functions.
Dan Gohman [Thu, 11 Jul 2019 16:32:39 +0000 (09:32 -0700)]
Don't declare `realpath` or pseudo-terminal functions.

These functions are not currently defined, so suppress their declarations
in the headers.

4 years agoUpdate title in README.md
Sam Clegg [Mon, 24 Jun 2019 17:21:36 +0000 (10:21 -0700)]
Update title in README.md

4 years agoEnsure argv is null terminated.
Sam Clegg [Wed, 29 May 2019 23:27:58 +0000 (16:27 -0700)]
Ensure argv is null terminated.

This matches the behavior of populate __environ.

See #27