-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overriding libc FS-related calls in Emscripten (for custom user's FS goodness) #23302
Comments
How does this work on non-emscripten platforms? Do they all currently use Emscripten does not current support wasm-ld does support the
However that would require adding a while bunch of linker flags which might be desirable. If the objcopy solution is something you would consider I think there has been some work on llvm/llvm-project#50623 so that its possible that could be an option in the future. Another option is to add internal aliases for the "real" versions of these symbol. Musl already does it itself for a lot of symbols. e.g:
|
I have two working variants:
So I wonder if any of these two are also applicable for Emscripten/libc? (for (2) probably llvm/llvm-project#50623 should be implemented first. I also had problems that some object files somehow re-export optind/optarg etc which conflict with multiple definitions with libc, so I had to prefix these in libc too)
Wow, this is very interesting! Should it also work for static linkage with regular musl libc? I also wonder is it possible to "hide" certain symbols, especially data-related symbols like optind, from libc during static linkage (without having to make a copy with renamed symbols)? |
How about adding alias for all of the original libc symbols you want to wrap. Adding those aliases to the emscripten version of musl seems like a reasonable request. Then method (2) would work fine with emscripten and without needing two different builds of libc. |
Not that I know of. |
This method seems less invasive and also avoids needing two different builds of libc. |
Do you mean adding the I'll also try And I still wonder if doing sth like this would work with Emscripten/libc (variant (1)) - as I don't fully understand the state of dynamic linking / dlsym support and especially of linkage to libc: #define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <dlfcn.h>
#include <sys/stat.h>
int open(const char *path, int flags, mode_t mode)
{
typedef int (*orig_func_type)(const char *pathname, int flags, mode_t mode);
fprintf(stderr, "log_file_access_preload: open(\"%s\", %d)\n", path, flags);
orig_func_type orig_func = (orig_func_type)dlsym(RTLD_NEXT, "open");
return orig_func(path, flags, mode);
} |
I wonder what would happen if I use |
(1) and (2) should work today. (3) requires form work on the llvm side which I believe has started but who knows when it will be ready. |
(1) seems fairly easy since you can just apply to to whatever symbols you need to wrap, and you can easily more symbols if you discover you need more. I don't believe any of these methods work for non-function symbols like |
I previously used See here: https://github.com/curiousdannii/emglken/blob/v0.6/src/getc.c (I no longer use it because I'm now completely avoiding the libc stdio API and effectively added my own syscalls instead.) |
I've implemented a read-only, virtual FS - for supporting "data package-like" ZIP-archives with musl libc by copying libc.a (for further linkage), prefixing FS-related symbols with
orig_
usingobjcopy
(e.g.open ->
orig_open) and then I'm defining
open(...)(and other related FS functions) in my own code (which calls
orig_open` under the hood when the accessed path does not match the virtual FS one).Is it feasible to reuse my custom
open(...)
code with Emscripten/libc somehow?For now, LLVM does not have support for renaming WASM symbols:
Does Emscripten support using
dlsym(RTLD_NEXT, "open");
specifically for libc?Or maybe is there another way to share my implementation code between regular musl libc and Emscripten/libc (and hook/override the Emscripten/libc default FS-related functions)?
(in this way I can come up with my own portable impl of "data packages", so that the data packages can be used with both Emscripten and not Emscripten, and so that multiple compression formats of data packages can be supported and experimenting with no ahead-of-time decompression)
Thanks!
Basically looking for a portable (so should work outside Emscripten context as well), minimalistic (hopefully header-only), non-intrusive libc-level virtual FS support - my take was overriding some FS posix/libc/c functions sufficient for my application, a more complete virtual FS support is a more complex (and still leaky) feat... Some related attempts:
The text was updated successfully, but these errors were encountered: