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.
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.
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`.
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.
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.
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.
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.
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.
Dan Gohman [Fri, 3 May 2019 20:55:41 +0000 (13:55 -0700)]
Use builtin functions rather than portable libm implementations.
For functions like sqrt, fabs, and others, use the builtin functions,
which provide single-instruction implementations, rather than using
musl's portable implementations.
Sam Clegg [Wed, 15 May 2019 16:54:54 +0000 (09:54 -0700)]
Don't create dummy libs for libc++/libc++abi (#68)
My understanding is that these dummy libs represent libraries who's
contents, under musl, live in libc itself rather than being split out
into separate libs.
libc++/libc++abi are not provided my musl so doesn't make sense to
pretend that we provide them.
This replaces our custom `unlink` wrapper with an upstream one. We still
end up replacing the entire body with local changes, but this makes it
easier to see what those changes are.
The other change here is a fix to ignore repeated '/'s in paths.
Dan Gohman [Wed, 8 May 2019 16:13:47 +0000 (09:13 -0700)]
Move the SEEK_* macros into their own header and use it from fcntl.h.
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.
Dan Gohman [Tue, 7 May 2019 16:24:10 +0000 (09:24 -0700)]
Ensure that `environ` is always initialized.
Initialize `environ` even if there are no environment variables, so that
it alwasy points to a NULL-terminated array even if that array just
contains the NULL. This fixes src/functional/env.c.
Sam Clegg [Thu, 2 May 2019 18:26:44 +0000 (11:26 -0700)]
Makefile: Don't mix phony targets with directory names
Remove build rules for $(SYSROOT) and $(SYSROOT_INC). The latter
becomes `include_dirs`. The former is not needed, instead just add
startup_files to the finish rule.
Dan Gohman [Mon, 29 Apr 2019 19:53:18 +0000 (12:53 -0700)]
Optimize lseek in the `tell` case.
`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.
Dan Gohman [Thu, 25 Apr 2019 22:30:07 +0000 (15:30 -0700)]
Disable unused fields in FILE and __libc.
Some of these fields are only needed for threads, some are not needed at
all. Removing them helps prevent code from accidentally using them, such
as when we merge in new musl versions.
Dan Gohman [Sat, 20 Apr 2019 00:22:28 +0000 (17:22 -0700)]
Implement FD_SET, FD_CLR, etc.
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.
Dan Gohman [Mon, 15 Apr 2019 13:11:29 +0000 (06:11 -0700)]
Update to musl 1.1.22.
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.
Dan Gohman [Mon, 15 Apr 2019 12:00:57 +0000 (05:00 -0700)]
Add a basics implementation of <inttypes.h>.
Musl's generic definitions for PRIxPTR and several others in
<inttypes.h> are incorrect for wasm, so introduce a new <inttypes.h>
and <__header_inttypes.h> in the basics module using compiler-provided
definitions.
Dan Gohman [Fri, 5 Apr 2019 23:10:38 +0000 (16:10 -0700)]
Define _ALL_SOURCE when generating predefined-macros.txt.
And clean up various stale declarations and macros that this turned up.
In particular:
- Don't install pthread.h or aio.h in THREAD_MODEL=single mode.
- Don't define mkstemp and friends, since WASI currently has no support for
temporary directories.
Dan Gohman [Wed, 3 Apr 2019 03:31:53 +0000 (20:31 -0700)]
Fix uselocale to support non-default locales.
Musl's locales implementation depends on pthreads. Since WASI libc
doesn't yet have pthreads, it currently has alternate code for
supporting locales. Previously, this code just assumed that it only had
to support the default locale, however libc++ uses uselocale with
non-default locals, so add support for that.
With this, the C++ <iostream>-style hello world now works, with
-fno-exceptions.
Dan Gohman [Wed, 3 Apr 2019 03:29:38 +0000 (20:29 -0700)]
Filter out __FLT16_* macros from predefined-macros.txt.
Whether these are defined or not depends on the version of clang in use,
and they're not that important at this time, so for now just ignore them
for the purposes of this testing output.