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.
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.
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.
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`.
* 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.
* 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.
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.
utime.h, sysmacros.h, and libintl.h are all currently unsupported.
Removing them helps programs that autodetect features based on the
existence of headers.
* 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`.
* 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.
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.
POSIX requires fcntl.h to define the SEEK_* macros, so this satisfies
that requirement. Also, this allows <stdio.h> to avoid including as much
unnecessary content.
This fixes one issue with src/api/fcntl.c.
These functions aren't specific to the underlying system call interface,
so they don't need to be in the "bottom half".
This also fixes src/functional/inet_pton.c and
src/regression/inet_pton-empty-last-field.c in musl's libc-test.
`lseek(x, 0, SEEK_CUR)` has no effect other than to return the current
file offset. The patch here uses a macro with `__builtin_constant_p` to
recognize this case and rewrite it to a library call that uses `fd_tell`
rather than `fd_seek`, so that programs that don't need actual seeking
don't end up importing `fd_seek`.
This is also the first usage of `__wasi_fd_tell` in WASI libc, so this
adds it to undefined-symbols.txt.
Some systems, such as Darwin, only declare getentropy in <sys/random.h>,
so declare it there on WASI too for compatibility.
Also, give getentropy the underscore-prefix/weak-symbol treatment, as
it's not a standard-reserved identifier.
Previously, FD_SET and friends were missing their actual definitions.
This provides definitions, entirely within the system headers in a
way that doesn't need instantiated out-of-line definitions.
Most of the changes are in threads, TLS, dynamic linking, and other
features wasi doesn't yet use, but there are some bug fixes in code
wasi does use.
atanl.c - local changes no longer needed as they've now landed upstream.
include/alltypes.h.in - Upstream now makes FILE a complete type in
pre-C11 mode. For WASI, this level of pre-C11 strictness isn't as
important, and having multiple incompatible definitions of _IO_FILE
that are kept separate only by clever use of translation unit
boundaries can confuse some tools, so stick with the incomplete type.