-
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
Replace _malloc, _memcpy and friends with imported from env. #5755
Comments
Btw, I tried to use |
You can try replacing malloc on the C side, like shown here: https://github.com/kripken/emscripten/blob/incoming/tests/wrap_malloc.cpp . That might work in suppressing the dlmalloc ones. If that does not work, or is somehow tricky, you can try commenting out this line https://github.com/kripken/emscripten/blob/incoming/tools/system_libs.py#L447 to see if that will be effective. If so, perhaps we can add a linker flag |
Yep, that helps to replace dlmalloc one, but it is not precisely what I want. |
If you want just your compiled code, no system libraries or JS support code, then you can use the standalone wasm option, which basically means creating a dynamic library (side module) of your code. That wouldn't include malloc if you didn't statically link it in yourself. If that's what you're looking for, feedback on that path would be great. |
Sounds like what I need! |
We should make sure that mode works well with rust, when you can please let me know what issues you find. |
I managed to get a simple bare project building and I had a few issues. First, I encountered issue on Second issue is somekind simpler. On the steps After that I got wasm binaries. I published a repository with sources: https://github.com/pepyakin/rust-side-module-poc |
About the second issue: It looks like BINARYEN_ROOT isn't set up since if I can workaround this issue by providing |
I noticed the second issue yesterday too, yeah. #5763 should fix it. I didn't understand the first issue. Are you passing emcc a bunch of bitcode files, and that didn't work (with what error?), then you linked them using rust beforehand (and passed emcc just one file) and that did? |
Hmm, what's in that |
As far as I get it,
(you can download it here)
It seems that this file is an archive, here is
I guess It seems that there was similar issue. |
Hmm, the older issue was fixed it says. But I guess there is something else in that archive that we can't handle. Specifically,
Any idea what that |
Hm, according to this file it contains compressed LLVM bytecode. |
While considering archive, in case But in case It looks like it has something to do with
If I set it to However, then I encounter third issue:
This is no surprise for me, because rust's |
Yes, when building a library the behavior is to link in all the contents of .a files (since they were provided as inputs, and we don't have a main() function or other way to know which of them is actually needed; what is needed depends on linking at runtime). So I think rust should pick the files it needs and tell emcc to build those. However, maybe we should also ignore a "broken" file like that by default? On the other hand ignoring it silently might be worse. The third issue is code that fastcomp's backend can't legalize. We basically have code that legalizes anything clang will emit from C or C++, but arbitrary bitcode might not work. This is one motivation to use the wasm backend, although we could add it to fastcomp, but probably not worth it at this point. (I didn't know rust had i128 by default, btw, that's interesting.) |
I completely agree that it is not worth adding support for legalization of i128. Also, for Rust, there is core library without i128 exists. Furthermore, rust's i128 is still somekind a moving target, since it is still a nightly-only feature.
It seems to me that we are already ignoring some "broken" files when we are collecting symbols.
Hm, I'm not sure whether this is possible/feasible. Probably we need an advice from some rust wizards. |
Good point, that would be more consistent. Fix in #5777. |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
I'm working in a environment where
_malloc
/_free
and_memcpy
,_memmove
,_memset
are provided by customenv
module. This environment requires tiny WASM binaries.When I compile code with
emcc
, it emits it's own implementations of these functions. Even if I explicitly declare these function asextern
,emcc
will still fill them with default implementations. However, if I do provide these functions not asextern
, but as ordinary functions with bodies, thenemcc
will use my versions of these functions.So to get rid of these functions I just do some post-process stripping on the wasm binary with some home brewed tools (I'm wondering if this is safe enough?)
Is there a better way to compile wasm to a such kind of environment?
The text was updated successfully, but these errors were encountered: