-
I'm building a large third-party C codebase with Emscripten. Some functions don't work "as is" (e.g. they use Is there a way to do so without patching the code? E.g. there's a function I can manually patch the file and replace it with EM_JS function, but I'd be cleaner to provide my implementation in a separate file, to make future code sync easier. Only for this function, not others in the same file. Is it possible to replace this in-build or after-the-build? Some library management magic? Late symbol-replacement? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
I tried to do use Here's the error: ./emsdk/upstream/bin/llvm-strip --strip-symbol=fork run-command.o
./emsdk/upstream/bin/llvm-strip: error: only flags for section dumping, removal, and addition are supported |
Beta Was this translation helpful? Give feedback.
-
You can use the
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
extern pid_t __real_fork();
pid_t __wrap_fork() {
printf("wrap fork\n");
return 0;
}
int main() {
printf("fork(): %d\n", fork());
printf("real fork(): %d\n", __real_fork());
return 0;
} $ emcc -sEXIT_RUNTIME -sALLOW_UNIMPLEMENTED_SYSCALLS main.c -Wl,--wrap=fork -o main.js
$ node main.js
wrap fork
fork(): 0
real fork(): -1 This is supported in wasm-ld since commit llvm/llvm-project@a5ca34e. |
Beta Was this translation helpful? Give feedback.
You can use the
--wrap
linker option for this.main.c
:This is supported in wasm-ld since commit llvm/llvm-project@a5ca34e.