Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Jan 17, 2022
1 parent b8c8e05 commit 1e5dec6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,4 @@ path = "examples/features.rs"
required-features = ["cranelift"]

[patch.crates-io]
object = { git = "https://github.com/Amanieu/object", branch = "wasmer" }
object = { git = "https://github.com/gimli-rs/object" }
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,13 @@ compilers_engines :=
ifeq ($(ENABLE_CRANELIFT), 1)
compilers_engines += cranelift-universal

ifneq (, $(filter 1, $(IS_DARWIN) $(IS_LINUX)))
ifneq (, $(filter 1, $(IS_WINDOWS) $(IS_DARWIN) $(IS_LINUX)))
ifeq ($(IS_AMD64), 1)
ifneq ($(LIBC), musl)
compilers_engines += cranelift-dylib
endif
else ifeq ($(IS_AARCH64), 1)
# The object crate doesn't support yet Darwin + Aarch64 relocations
ifneq ($(IS_DARWIN), 1)
ifneq ($(LIBC), musl)
compilers_engines += cranelift-dylib
endif
endif
Expand All @@ -230,7 +229,7 @@ endif
##

ifeq ($(ENABLE_LLVM), 1)
ifneq (, $(filter 1, $(IS_DARWIN) $(IS_LINUX)))
ifneq (, $(filter 1, $(IS_WINDOWS) $(IS_DARWIN) $(IS_LINUX)))
ifeq ($(IS_AMD64), 1)
compilers_engines += llvm-universal
compilers_engines += llvm-dylib
Expand All @@ -246,7 +245,7 @@ endif
##

ifeq ($(ENABLE_SINGLEPASS), 1)
ifneq (, $(filter 1, $(IS_DARWIN) $(IS_LINUX)))
ifneq (, $(filter 1, $(IS_WINDOWS) $(IS_DARWIN) $(IS_LINUX)))
ifeq ($(IS_AMD64), 1)
compilers_engines += singlepass-universal
endif
Expand Down
24 changes: 15 additions & 9 deletions lib/engine-dylib/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ impl DylibArtifact {
data: &[u8],
tunables: &dyn Tunables,
) -> Result<Self, CompileError> {
use object::{write::CoffExportStyle, BinaryFormat};

let mut engine_inner = engine.inner_mut();
let target = engine.target();
let compiler = engine_inner.compiler()?;
Expand Down Expand Up @@ -241,6 +243,9 @@ impl DylibArtifact {
let mut obj =
get_object_for_target(&target_triple).map_err(to_compile_error)?;
emit_trampolines(&mut obj, engine.target());
if obj.format() == BinaryFormat::Coff {
obj.add_coff_exports(CoffExportStyle::Msvc);
}
let file = tempfile::Builder::new()
.prefix("wasmer_dylib_")
.suffix(".o")
Expand Down Expand Up @@ -285,6 +290,9 @@ impl DylibArtifact {
.map_err(to_compile_error)?;
emit_compilation(&mut obj, compilation, &symbol_registry, &target_triple)
.map_err(to_compile_error)?;
if obj.format() == BinaryFormat::Coff {
obj.add_coff_exports(CoffExportStyle::Msvc);
}
let file = tempfile::Builder::new()
.prefix("wasmer_dylib_")
.suffix(".o")
Expand Down Expand Up @@ -481,6 +489,13 @@ impl DylibArtifact {
dylib_path: PathBuf,
lib: Library,
) -> Result<Self, CompileError> {
unsafe {
let trampolines_symbol: LibrarySymbol<usize> = lib
.get(WASMER_TRAMPOLINES_SYMBOL)
.expect("missing WASMER_TRAMPOLINES symbol");
fill_trampoline_table(trampolines_symbol.into_raw().into_raw() as *mut usize);
}

let mut finished_functions: PrimaryMap<LocalFunctionIndex, FunctionBodyPtr> =
PrimaryMap::new();
for (function_local_index, _function_len) in metadata.function_body_lengths.iter() {
Expand Down Expand Up @@ -665,15 +680,6 @@ impl DylibArtifact {

let metadata = ModuleMetadata::deserialize(metadata_slice)?;

let trampolines_symbol: LibrarySymbol<usize> =
lib.get(WASMER_TRAMPOLINES_SYMBOL).map_err(|e| {
DeserializeError::CorruptedBinary(format!(
"The provided object file doesn't seem to be generated by Wasmer: {}",
e
))
})?;
fill_trampoline_table(trampolines_symbol.into_raw().into_raw() as *mut usize);

let mut engine_inner = engine.inner_mut();

Self::from_parts(&mut engine_inner, metadata, shared_path, lib)
Expand Down

0 comments on commit 1e5dec6

Please sign in to comment.