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

5 years agoDon't declare popen and pclose.
Dan Gohman [Tue, 14 May 2019 18:43:37 +0000 (11:43 -0700)]
Don't declare popen and pclose.

5 years agoDon't install <sys/xattr.h>, which isn't supported on WASI.
Dan Gohman [Tue, 14 May 2019 15:58:02 +0000 (08:58 -0700)]
Don't install <sys/xattr.h>, which isn't supported on WASI.

5 years agoRemove more declarations for symbols that aren't defined.
Dan Gohman [Tue, 14 May 2019 15:36:35 +0000 (08:36 -0700)]
Remove more declarations for symbols that aren't defined.

5 years agoDon't declare lockfile and timezone functions.
Dan Gohman [Tue, 7 May 2019 16:27:05 +0000 (09:27 -0700)]
Don't declare lockfile and timezone functions.

These aren't defined, so don't declare them either.

5 years agoImplement truncate(2).
Dan Gohman [Tue, 14 May 2019 18:49:22 +0000 (11:49 -0700)]
Implement truncate(2).

This adds a simple implementation of truncate in terms of open and
ftruncate.

5 years agoAdd complex builtins for creal and cimag too.
Dan Gohman [Tue, 14 May 2019 16:53:05 +0000 (09:53 -0700)]
Add complex builtins for creal and cimag too.

5 years agoUse builtin functions rather than portable libm implementations.
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.

5 years agoDon't create dummy libs for libc++/libc++abi (#68)
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.

5 years agoImplement more functions, remove more unimplemented headers.
Dan Gohman [Tue, 14 May 2019 18:54:41 +0000 (11:54 -0700)]
Implement more functions, remove more unimplemented headers.

Enable more musl sources for things tested in libc-test, and remove more
headers that aren't implemented on WASI.

5 years agoMove the mode_t macros into their own header.
Dan Gohman [Thu, 9 May 2019 17:31:09 +0000 (10:31 -0700)]
Move the mode_t macros into their own header.

This allows them to be defined by <fcntl.h> as well, as specified by
POSIX.

This fixes a part of src/api/fcntl.c.

5 years agoDefine O_TTY_INIT.
Dan Gohman [Thu, 9 May 2019 17:32:40 +0000 (10:32 -0700)]
Define O_TTY_INIT.

Define it to 0, as several popular operating systems ignore this flag.

This fixes a part of src/api/fcntl.c.

5 years agoUpdate to libpreopen 8835639f27fc42d32096d59d294a0bbb857dc368.
Dan Gohman [Tue, 7 May 2019 23:54:48 +0000 (16:54 -0700)]
Update to libpreopen 8835639f27fc42d32096d59d294a0bbb857dc368.

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.

5 years agoFix fmemopen and friends to use the correct SEEK_* values.
Dan Gohman [Wed, 8 May 2019 22:14:06 +0000 (15:14 -0700)]
Fix fmemopen and friends to use the correct SEEK_* values.

WASI's values for SEEK_CUR, SEEK_SET, and SEEK_END differ from musl's
values, so fix musl code that bakes in knowledge of these values.

This fixes src/functional/memstream.c.

5 years agoUse the compiler's real/imag operators instead of union type punning.
Dan Gohman [Mon, 29 Apr 2019 12:59:36 +0000 (05:59 -0700)]
Use the compiler's real/imag operators instead of union type punning.

This removes the last use of union type punning from WASI libc's
public header files.

5 years agoRemove __fpclassify and __signbit definitions.
Dan Gohman [Mon, 29 Apr 2019 12:10:37 +0000 (05:10 -0700)]
Remove __fpclassify and __signbit definitions.

With fpclassify and signbit now implemented as compiler builtins in a64f6544,
these out-of-line helper functions are no longer needed.

5 years agoUse the compiler builtins for isless etc.
Dan Gohman [Mon, 29 Apr 2019 12:10:37 +0000 (05:10 -0700)]
Use the compiler builtins for isless etc.

Building on a64f6544, use compiler builtins for isless, isgreater,
isunordered, and similar as well.

5 years agoMove the SEEK_* macros into their own header and use it from fcntl.h.
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.

This fixes one issue with src/api/fcntl.c.

5 years agoSwitch from the cloudlibc inet_pton etc. to the musl versions.
Dan Gohman [Wed, 8 May 2019 18:58:46 +0000 (11:58 -0700)]
Switch from the cloudlibc inet_pton etc. to the musl versions.

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.

5 years agoDon't declare dup in unistd.h.
Dan Gohman [Thu, 9 May 2019 06:05:14 +0000 (23:05 -0700)]
Don't declare dup in unistd.h.

Dup isn't defined in libc.a, so don't declare it.

5 years agoRe-enable '%s' in strftime.
Dan Gohman [Thu, 9 May 2019 05:29:34 +0000 (22:29 -0700)]
Re-enable '%s' in strftime.

This was commented out earlier when timezone handling was more in flux,
but it's ok to minimally support this now.

This fixes src/functional/strftime.c in libc-test.

5 years agoRename __wasilibc_rmfileat to __wasilibc_unlinkat.
Dan Gohman [Sat, 4 May 2019 06:36:00 +0000 (23:36 -0700)]
Rename __wasilibc_rmfileat to __wasilibc_unlinkat.

The POSIX terminology is that directories are "removed" while files
are "unlinked".

5 years agoAdd __restrict qualifiers to the fstatat declaration.
Dan Gohman [Sat, 4 May 2019 22:22:16 +0000 (15:22 -0700)]
Add __restrict qualifiers to the fstatat declaration.

This makes it consistent with its definition.

5 years agoEnsure that `environ` is always initialized.
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.

5 years agoFix the return value of the first call to uselocale.
Dan Gohman [Tue, 7 May 2019 16:22:40 +0000 (09:22 -0700)]
Fix the return value of the first call to uselocale.

The first call to uselocale should return LC_GLOBAL_LOCALE. This fixes
src/regression/uselocale-0.c in libc-test.

5 years agoMove abort.c out of libc-bottom-half and into basics.
Dan Gohman [Fri, 3 May 2019 21:23:30 +0000 (14:23 -0700)]
Move abort.c out of libc-bottom-half and into basics.

5 years agoDocument that WASM_NM and WASM_AR may also be required
Frank Denis [Mon, 6 May 2019 11:13:44 +0000 (13:13 +0200)]
Document that WASM_NM and WASM_AR may also be required

Also make it explicit that we currently need clang 8+

Fixes #44

5 years agouse ENOMEM instead of EINVAL, set EINVAL if length == 0
vms [Sun, 5 May 2019 20:53:18 +0000 (00:53 +0400)]
use ENOMEM instead of EINVAL, set EINVAL if length == 0

5 years agomove to __builtin_add_overflow
vms [Sun, 5 May 2019 16:59:48 +0000 (20:59 +0400)]
move to __builtin_add_overflow

5 years agocode deduplication
vms [Sun, 5 May 2019 08:17:37 +0000 (12:17 +0400)]
code deduplication

5 years agofix comment to correspond existing coding style
vms [Sat, 4 May 2019 17:48:05 +0000 (20:48 +0300)]
fix comment to correspond existing coding style

5 years agofix mmap overflow and some other stuff
vms [Sat, 4 May 2019 17:37:27 +0000 (20:37 +0300)]
fix mmap overflow and some other stuff

5 years agoMakefile: Don't mix phony targets with directory names
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.

5 years agodelete a space in predefined-macros.txt
vms [Thu, 2 May 2019 14:35:00 +0000 (17:35 +0300)]
delete a space in predefined-macros.txt

5 years agoreplace some macros with its builtins analogs
vms [Thu, 2 May 2019 14:19:05 +0000 (17:19 +0300)]
replace some macros with its builtins analogs

5 years agorename printf_no_Lf to __small_printf
vms [Wed, 1 May 2019 08:16:57 +0000 (11:16 +0300)]
rename printf_no_Lf to __small_printf

5 years agoDefine TIME_UTC to be 1.
Dan Gohman [Mon, 29 Apr 2019 17:23:44 +0000 (10:23 -0700)]
Define TIME_UTC to be 1.

TIME_UTC is the only time base defined by the relevant standards. This
change doesn't preclude adding other time bases in the future.

5 years agoDefine CLOCKS_PER_SEC to have type clock_t.
Dan Gohman [Mon, 29 Apr 2019 17:14:12 +0000 (10:14 -0700)]
Define CLOCKS_PER_SEC to have type clock_t.

The C standard requires CLOCKS_PER_SEC to have type clock_t.

5 years agoOptimize lseek in the `tell` case.
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.

5 years agoSay "wasm32-wasi" rather than "wasm32-unknown-wasi".
Dan Gohman [Mon, 29 Apr 2019 00:05:24 +0000 (17:05 -0700)]
Say "wasm32-wasi" rather than "wasm32-unknown-wasi".

5 years agoDeclare getentropy in <sys/random.h>
Dan Gohman [Tue, 30 Apr 2019 22:05:10 +0000 (15:05 -0700)]
Declare getentropy in <sys/random.h>

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.

5 years agoDisable unused fields in FILE and __libc.
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.

5 years agoAdd vfwprintf.c to the printscan list.
Dan Gohman [Mon, 22 Apr 2019 13:23:56 +0000 (06:23 -0700)]
Add vfwprintf.c to the printscan list.

This causes the build to produce no-long-double and no-floating-point
versions of this file, following what is done for vfprintf.c.

5 years agoImplement FD_SET, FD_CLR, etc.
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.

5 years agoRemove capsicum.h; WASI libc doesn't support that API, even internally.
Dan Gohman [Mon, 22 Apr 2019 23:22:27 +0000 (16:22 -0700)]
Remove capsicum.h; WASI libc doesn't support that API, even internally.

5 years agoMake calloc set ENOMEM when failing due to overflow.
Dan Gohman [Mon, 22 Apr 2019 18:36:54 +0000 (11:36 -0700)]
Make calloc set ENOMEM when failing due to overflow.

This fixes a bug in upstream dlmalloc, where it doesn't set errno to
ENOMEM in overflow or footprint overrun cases.

5 years agoMake the strerror message for ESUCCESS (0) be "Success".
Dan Gohman [Tue, 23 Apr 2019 19:53:29 +0000 (12:53 -0700)]
Make the strerror message for ESUCCESS (0) be "Success".

Previously it was "No error information", which was indistinguishable
from an unrecognized errno value.

5 years agoImplement reallocarray.
Dan Gohman [Mon, 22 Apr 2019 19:46:36 +0000 (12:46 -0700)]
Implement reallocarray.

reallocarray is non-standard but present in GLIBC and BSDs.

5 years agoUpdate README.md
Dimitrii Nemkov [Tue, 23 Apr 2019 06:04:01 +0000 (11:04 +0500)]
Update README.md

5 years agoAdd missing asctime symbol
Jakub Konka [Tue, 23 Apr 2019 12:09:24 +0000 (14:09 +0200)]
Add missing asctime symbol

5 years agoFix floatscan no long double usage (#21)
vms [Mon, 22 Apr 2019 21:37:03 +0000 (00:37 +0300)]
Fix floatscan no long double usage (#21)

* fix long double using in floatscan

* define separate macroses for copysignl, fmodl, and scalbnl instead of #ifndef

5 years agoRemove the Linux-specific <sys/signalfd.h> header.
Dan Gohman [Sat, 20 Apr 2019 00:19:07 +0000 (17:19 -0700)]
Remove the Linux-specific <sys/signalfd.h> header.

5 years agoDeclare getrusage.
Dan Gohman [Sat, 20 Apr 2019 00:19:55 +0000 (17:19 -0700)]
Declare getrusage.

It's defined publicly in libc, so publicly declare it too.

5 years agoFormat changes to musl code to fit musl's style.
Dan Gohman [Mon, 15 Apr 2019 17:51:44 +0000 (10:51 -0700)]
Format changes to musl code to fit musl's style.

The whitespace diffs are converting from spaces to tabs.

5 years agoFixes #20
Jakub Konka [Sun, 21 Apr 2019 19:24:20 +0000 (21:24 +0200)]
Fixes #20

Adds missing localtime.c source file to Makefile and to expected
defined symbols list.

5 years agogitignore build
Pat Hickey [Fri, 19 Apr 2019 18:15:48 +0000 (11:15 -0700)]
gitignore build

5 years agobuild: use LC_ALL=C for sorting
Pat Hickey [Fri, 19 Apr 2019 00:17:35 +0000 (17:17 -0700)]
build: use LC_ALL=C for sorting

LC_COLLATE doesn't seem to work with all `sort`s

5 years agoUpdate to cloudlibc 8835639f27fc42d32096d59d294a0bbb857dc368.
Dan Gohman [Mon, 15 Apr 2019 13:12:13 +0000 (06:12 -0700)]
Update to cloudlibc 8835639f27fc42d32096d59d294a0bbb857dc368.

There's no functional change here; the only change is the patch I
submitted upstream, so we can remove some local changes.

5 years agoUpdate to musl 1.1.22.
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.

5 years agoRename README to README.md.
Dan Gohman [Fri, 12 Apr 2019 16:25:29 +0000 (09:25 -0700)]
Rename README to README.md.

5 years agoRemove socket.c, which was a stub that always failed with ENOSYS.
Dan Gohman [Fri, 12 Apr 2019 16:20:20 +0000 (09:20 -0700)]
Remove socket.c, which was a stub that always failed with ENOSYS.

5 years agoUse the same indentation style as surrounding code.
Dan Gohman [Fri, 12 Apr 2019 15:53:41 +0000 (08:53 -0700)]
Use the same indentation style as surrounding code.