| author | |
| committer | |
| log | e60072635eca3f3c983d92819aa67c0decc7d4a6 |
| tree | be8950a91fecf0e879e8cc797d6a1c32a1c03781 |
| parent | 8a8da49b5212030d603000d699a8ca9ed92e24cd |
| signature |
4 files changed, 130 insertions(+), 0 deletions(-)
lib/libc/include/wasm-wasi-musl/dlfcn.h created+56| ... | ... | @@ -0,0 +1,56 @@ |
| 1 | #ifndef	_DLFCN_H | |
| 2 | #define	_DLFCN_H | |
| 3 | ||
| 4 | #ifdef __cplusplus | |
| 5 | extern "C" { | |
| 6 | #endif | |
| 7 | ||
| 8 | #include <features.h> | |
| 9 | ||
| 10 | #define RTLD_LAZY 1 | |
| 11 | #define RTLD_NOW 2 | |
| 12 | #define RTLD_NOLOAD 4 | |
| 13 | #define RTLD_NODELETE 4096 | |
| 14 | #define RTLD_GLOBAL 256 | |
| 15 | #ifdef __wasilibc_unmodified_upstream | |
| 16 | #define RTLD_LOCAL 0 | |
| 17 | #else | |
| 18 | /* For WASI, we give `RTLD_LOCAL` a non-zero value, avoiding ambiguity and | |
| 19 | * allowing us to defer the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` | |
| 20 | * should be the default when neither is specified. | |
| 21 | */ | |
| 22 | #define RTLD_LOCAL 8 | |
| 23 | #endif | |
| 24 | ||
| 25 | #define RTLD_NEXT ((void *)-1) | |
| 26 | #define RTLD_DEFAULT ((void *)0) | |
| 27 | ||
| 28 | #ifdef __wasilibc_unmodified_upstream | |
| 29 | #define RTLD_DI_LINKMAP 2 | |
| 30 | #endif | |
| 31 | ||
| 32 | int dlclose(void *); | |
| 33 | char *dlerror(void); | |
| 34 | void *dlopen(const char *, int); | |
| 35 | void *dlsym(void *__restrict, const char *__restrict); | |
| 36 | ||
| 37 | #if defined(__wasilibc_unmodified_upstream) && (defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) | |
| 38 | typedef struct { | |
| 39 | 	const char *dli_fname; | |
| 40 | 	void *dli_fbase; | |
| 41 | 	const char *dli_sname; | |
| 42 | 	void *dli_saddr; | |
| 43 | } Dl_info; | |
| 44 | int dladdr(const void *, Dl_info *); | |
| 45 | int dlinfo(void *, int, void *); | |
| 46 | #endif | |
| 47 | ||
| 48 | #if _REDIR_TIME64 | |
| 49 | __REDIR(dlsym, __dlsym_time64); | |
| 50 | #endif | |
| 51 | ||
| 52 | #ifdef __cplusplus | |
| 53 | } | |
| 54 | #endif | |
| 55 | ||
| 56 | #endif |
lib/libc/wasi/libc-top-half/musl/src/misc/dl.c created+45| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | /* This file is used to build libdl.so with stub versions of `dlopen`, `dlsym`, | |
| 2 | * etc. The intention is that this stubbed libdl.so can be used to build | |
| 3 | * libraries and applications which use `dlopen` without committing to a | |
| 4 | * specific runtime implementation. Later, it can be replaced with a real, | |
| 5 | * working libdl.so (e.g. at runtime or component composition time). | |
| 6 | * | |
| 7 | * For example, the `wasm-tools component link` subcommand can be used to create | |
| 8 | * a component that bundles any `dlopen`-able libraries in such a way that their | |
| 9 | * function exports can be resolved symbolically at runtime using an | |
| 10 | * implementation of libdl.so designed for that purpose. In other cases, a | |
| 11 | * runtime might provide Emscripten-style dynamic linking via URLs or else a | |
| 12 | * more traditional, filesystem-based implementation. Finally, even this | |
| 13 | * stubbed version of libdl.so can be used at runtime in cases where dynamic | |
| 14 | * library resolution cannot or should not be supported (and the application can | |
| 15 | * handle this situation gracefully). */ | |
| 16 | ||
| 17 | #include <stddef.h> | |
| 18 | #include <dlfcn.h> | |
| 19 | ||
| 20 | static const char *error = NULL; | |
| 21 | ||
| 22 | weak int dlclose(void *library) | |
| 23 | { | |
| 24 | 	error = "dlclose not implemented"; | |
| 25 | 	return -1; | |
| 26 | } | |
| 27 | ||
| 28 | weak char *dlerror(void) | |
| 29 | { | |
| 30 | 	const char *var = error; | |
| 31 | 	error = NULL; | |
| 32 | 	return (char*) var; | |
| 33 | } | |
| 34 | ||
| 35 | weak void *dlopen(const char *name, int flags) | |
| 36 | { | |
| 37 | 	error = "dlopen not implemented"; | |
| 38 | 	return NULL; | |
| 39 | } | |
| 40 | ||
| 41 | weak void *dlsym(void *library, const char *name) | |
| 42 | { | |
| 43 | 	error = "dlsym not implemented"; | |
| 44 | 	return NULL; | |
| 45 | } |
src/Compilation.zig+1| ... | ... | @@ -806,6 +806,7 @@ pub const MiscTask = enum { |
| 806 | 806 | @"wasi crt1-reactor.o", |
| 807 | 807 | @"wasi crt1-command.o", |
| 808 | 808 | @"wasi libc.a", |
| 809 | @"wasi libdl.a", | |
| 809 | 810 | @"libwasi-emulated-process-clocks.a", |
| 810 | 811 | @"libwasi-emulated-getpid.a", |
| 811 | 812 | @"libwasi-emulated-mman.a", |
src/wasi_libc.zig+28| ... | ... | @@ -10,6 +10,7 @@ pub const CrtFile = enum { |
| 10 | 10 | crt1_reactor_o, |
| 11 | 11 | crt1_command_o, |
| 12 | 12 | libc_a, |
| 13 | libdl_a, | |
| 13 | 14 | libwasi_emulated_process_clocks_a, |
| 14 | 15 | libwasi_emulated_getpid_a, |
| 15 | 16 | libwasi_emulated_mman_a, |
| ... | ... | @@ -17,6 +18,9 @@ pub const CrtFile = enum { |
| 17 | 18 | }; |
| 18 | 19 | |
| 19 | 20 | pub fn getEmulatedLibCrtFile(lib_name: []const u8) ?CrtFile { |
| 21 | if (mem.eql(u8, lib_name, "dl")) { | |
| 22 | return .libdl_a; | |
| 23 | } | |
| 20 | 24 | if (mem.eql(u8, lib_name, "wasi-emulated-process-clocks")) { |
| 21 | 25 | return .libwasi_emulated_process_clocks_a; |
| 22 | 26 | } |
| ... | ... | @@ -34,6 +38,7 @@ pub fn getEmulatedLibCrtFile(lib_name: []const u8) ?CrtFile { |
| 34 | 38 | |
| 35 | 39 | pub fn emulatedLibCRFileLibName(crt_file: CrtFile) []const u8 { |
| 36 | 40 | return switch (crt_file) { |
| 41 | .libdl_a => "libdl.a", | |
| 37 | 42 | .libwasi_emulated_process_clocks_a => "libwasi-emulated-process-clocks.a", |
| 38 | 43 | .libwasi_emulated_getpid_a => "libwasi-emulated-getpid.a", |
| 39 | 44 | .libwasi_emulated_mman_a => "libwasi-emulated-mman.a", |
| ... | ... | @@ -154,6 +159,25 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 154 | 159 | |
| 155 | 160 | try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items, .{}); |
| 156 | 161 | }, |
| 162 | ||
| 163 | .libdl_a => { | |
| 164 | var args = std.ArrayList([]const u8).init(arena); | |
| 165 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | |
| 166 | try addLibcBottomHalfIncludes(comp, arena, &args); | |
| 167 | ||
| 168 | var emu_dl_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | |
| 169 | for (emulated_dl_src_files) |file_path| { | |
| 170 | try emu_dl_sources.append(.{ | |
| 171 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | |
| 172 | "libc", try sanitize(arena, file_path), | |
| 173 | }), | |
| 174 | .extra_flags = args.items, | |
| 175 | .owner = undefined, | |
| 176 | }); | |
| 177 | } | |
| 178 | try comp.build_crt_file("dl", .Lib, .@"wasi libdl.a", prog_node, emu_dl_sources.items, .{}); | |
| 179 | }, | |
| 180 | ||
| 157 | 181 | .libwasi_emulated_process_clocks_a => { |
| 158 | 182 | var args = std.ArrayList([]const u8).init(arena); |
| 159 | 183 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| ... | ... | @@ -1173,6 +1197,10 @@ const libc_top_half_src_files = [_][]const u8{ |
| 1173 | 1197 | const crt1_command_src_file = "wasi/libc-bottom-half/crt/crt1-command.c"; |
| 1174 | 1198 | const crt1_reactor_src_file = "wasi/libc-bottom-half/crt/crt1-reactor.c"; |
| 1175 | 1199 | |
| 1200 | const emulated_dl_src_files = &[_][]const u8{ | |
| 1201 | "wasi/libc-top-half/musl/src/misc/dl.c", | |
| 1202 | }; | |
| 1203 | ||
| 1176 | 1204 | const emulated_process_clocks_src_files = &[_][]const u8{ |
| 1177 | 1205 | "wasi/libc-bottom-half/clocks/clock.c", |
| 1178 | 1206 | "wasi/libc-bottom-half/clocks/getrusage.c", |