Commit Graph

115 Commits

Author SHA1 Message Date
Dan Gohman
7fcc4f29df
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.
2019-11-04 14:56:35 -08:00
Dan Gohman
eb7230cf94
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.
2019-11-04 13:17:03 -08:00
Dan Gohman
ec3ee5e985
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.
2019-10-28 11:08:12 -07:00
Dan Gohman
8048aeb500
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.
2019-10-28 10:35:45 -07:00
Dan Gohman
a8a5dbcf91
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.
2019-10-28 10:34:57 -07:00
Dan Gohman
afbf94c39e
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`.
2019-10-24 17:30:46 -07:00
Dan Gohman
1f11b91e7f
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.
2019-10-22 11:25:19 -07:00
Dan Gohman
289fdce22b
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
2019-10-22 08:00:48 -07:00
Dan Gohman
bdfbb54520
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.
2019-10-22 06:02:44 -07:00
vms
d253aa3de2 Make sbrk(0) deterministic (#115)
* fix the behavior of sbrk(0)

* review changes
2019-10-21 15:44:23 -07:00
Dan Gohman
b59b83cbc2
Miscellaneous cleanups (#113)
* Tidy up some #include names.

* Move non-cloudlibc sources out of the cloudlibc directory.
2019-10-18 13:53:13 -07:00
vms
c54004fcce fix the typo (#108)
* fix the typo
2019-10-14 14:52:10 -07:00
Dan Gohman
78b8651224
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.
2019-10-11 05:07:34 -07:00
Dan Gohman
472b213bb6 Don't define readdir64_r.
wasi-libc doesn't define readdir_r, so don't define readdir64_r as an
alias for it.
2019-10-07 08:59:55 -07:00
Dan Gohman
33e8b5189b 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.
2019-10-07 08:59:24 -07:00
Dan Gohman
1f40984219 Factor out the include-file exclude list into a variable.
This also starts categorizing these headers into groups and adding
comments explaining their purpose.
2019-10-07 08:59:24 -07:00
Dan Gohman
447ea829a9 Add a CODE_OF_CONDUCT.md file. (#101) 2019-10-03 14:15:49 +02:00
Dan Gohman
c9a573306f 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.
2019-09-07 07:22:18 -07:00
Sam Clegg
c35f0f5dd6 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
2019-08-29 20:39:11 -07:00
Dan Gohman
d498fc3ddf Fix a warning about a spurious redundant static keyword. 2019-08-29 10:27:41 -07:00
Dan Gohman
32cd170026 Update docs to say "libc" rather than "sysroot" where applicable. 2019-08-29 10:27:23 -07:00
Dan Gohman
b7ae2fe33b WASI libc's dirent does have t_type, so define _DIRENT_HAVE_D_TYPE.
Also update predefined-macros.txt.
2019-08-29 10:22:03 -07:00
Dan Gohman
bed0cb5d3a 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.
2019-08-29 10:22:03 -07:00
Dan Gohman
7d2354e7d1 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.
2019-08-29 07:03:29 -07:00
Till Schneidereit
255e6f7c0d
Add Azure Pipelines definition (#78) 2019-08-12 13:50:53 +02:00
Dan Gohman
d4db3fa212 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.
2019-08-07 17:53:41 -07:00
Sam Clegg
8df0d4cd6a Fix predefined macros check after recent clang change
This is an alternative to #75.
2019-07-16 07:12:28 -07:00
Dan Gohman
a413650013 Don't declare realpath or pseudo-terminal functions.
These functions are not currently defined, so suppress their declarations
in the headers.
2019-07-11 10:36:28 -07:00
Sam Clegg
94d34a13ad Update title in README.md 2019-06-24 10:27:17 -07:00
Sam Clegg
92eaf255a1 Ensure argv is null terminated.
This matches the behavior of populate __environ.

See #27
2019-05-30 08:15:23 -07:00
Dan Gohman
eee6ee7566 Don't declare popen and pclose. 2019-05-15 12:01:17 -07:00
Dan Gohman
84a2343ce4 Don't install <sys/xattr.h>, which isn't supported on WASI. 2019-05-15 12:01:17 -07:00
Dan Gohman
0a738e8fd6 Remove more declarations for symbols that aren't defined. 2019-05-15 12:01:17 -07:00
Dan Gohman
24f6fe1cc8 Don't declare lockfile and timezone functions.
These aren't defined, so don't declare them either.
2019-05-15 12:01:17 -07:00
Dan Gohman
6cddc9250b Implement truncate(2).
This adds a simple implementation of truncate in terms of open and
ftruncate.
2019-05-15 11:53:11 -07:00
Dan Gohman
7d5074ff66 Add complex builtins for creal and cimag too. 2019-05-15 11:52:56 -07:00
Dan Gohman
16450763eb 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.
2019-05-15 11:52:56 -07:00
Sam Clegg
1f7d798a3a
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.
2019-05-15 09:54:54 -07:00
Dan Gohman
5067fefb25 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.
2019-05-15 06:36:02 -07:00
Dan Gohman
256081f628 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.
2019-05-10 12:37:49 -07:00
Dan Gohman
861f0d2ec8 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.
2019-05-10 12:37:31 -07:00
Dan Gohman
a077330632 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.
2019-05-09 09:16:56 -07:00
Dan Gohman
e369ade425 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.
2019-05-09 09:16:38 -07:00
Dan Gohman
288738d194 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.
2019-05-09 09:15:30 -07:00
Dan Gohman
900b8032b4 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.
2019-05-09 09:15:30 -07:00
Dan Gohman
1dd59d8506 Use the compiler builtins for isless etc.
Building on a64f6544, use compiler builtins for isless, isgreater,
isunordered, and similar as well.
2019-05-09 09:15:30 -07:00
Dan Gohman
60cba39d11 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.
2019-05-09 09:11:43 -07:00
Dan Gohman
1db93d1169 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.
2019-05-09 09:10:57 -07:00
Dan Gohman
46ce01276f Don't declare dup in unistd.h.
Dup isn't defined in libc.a, so don't declare it.
2019-05-09 09:07:57 -07:00
Dan Gohman
e91e6dd766 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.
2019-05-09 09:07:38 -07:00