Commit Graph

3 Commits

Author SHA1 Message Date
Joel Dice
3f745ab23d add stubs for dlopen, dlsym, etc. (#443)
* add stubs for dlopen, dlsym, etc.

This adds weak exports for the POSIX `dlopen`, `dlsym`, `dlclose`, and `dlerror`
functions, allowing code which uses those features to compile.  The
implementations are stubs which always fail since there is currently no official
standard for runtime dynamic linking.

Since the symbols are weak, they can be overriden with useful, runtime-specific
implementations, e.g. based on host functions or statically-generated tables
(see https://github.com/dicej/component-linking-demo for an example of the
latter).

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* move `dlopen` stubs out of libc and into libdl

Per review feedback, it's easier to simply replace libdl.so with a working
implementation at runtime than it is to override a handful of symbols in libc.

Note that I've both added libdl.so and replaced the empty libdl.a we were
previously creating with one that contains the stubs.  I'm thinking we might as
well be consistent about what symbols the .so and the .a contain.  Otherwise,
e.g. the CPython build gets confused when the dlfcn.h says `dlopen` etc. exist
but libdl.a is empty.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* customize dlfcn.h for WASI

For WASI, we use flag values which match MacOS rather than musl.  This gives
`RTLD_LOCAL` a non-zero value, avoiding ambiguity and allowing us to defer the
decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` should be the default when
neither is specified.

We also avoid declaring `dladdr`, `dlinfo`, and friends on WASI since they are
neither supported nor stubbed at this time.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* use musl's RTLD_* flags except for RTLD_LOCAL

This minimizes the divergence from upstream while still giving us the
flexibility to choose a default value later.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* use `NULL` instead of `0` for null pointers

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

---------

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
2024-06-25 12:13:34 +02:00
Dan Gohman
575e1579a4 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.
2020-02-26 10:23:05 -08:00
Dan Gohman
320054e84f WASI libc prototype implementation.
This incoporates pieces from musl-libc, cloudlibc, cloudabi, libpreopen,
and dlmalloc, as well as a significant amount of new code.
2019-03-27 07:59:55 -07:00