[−][src]Function rustc_codegen_llvm::back::wasm::rewrite_imports
pub fn rewrite_imports(path: &Path, import_map: &FxHashMap<String, String>)
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
Rewrite the module imports are listed from in a wasm module given the field
name to module name mapping in import_map
.
LLVM 6 which we're using right now doesn't have the ability to configure the
module a wasm symbol is import from. Rather all imported symbols come from
the bland "env"
module unconditionally. Furthermore we'd also need
support in LLD for preserving these import modules, which it unfortunately
currently does not.
This function is intended as a hack for now where we manually rewrite the
wasm output by LLVM to have the correct import modules listed. The
#[link(wasm_import_module = "...")]
attribute in Rust translates to the
module that each symbol is imported from, so here we manually go through the
wasm file, decode it, rewrite imports, and then rewrite the wasm module.
Support for this was added to LLVM in https://github.com/llvm-mirror/llvm/commit/0f32e1365, although support still needs to be added, tracked at https://bugs.llvm.org/show_bug.cgi?id=37168