Support 32-bit build. (#44)

* Support 32-bit build.

Signatures/functions/imports/exports etc are defined as varuint32 in
the WebAssembly specification so use u32 rather than u64.

Decrease the static memory constants for 32-bit addressing mode so
that they fit within 32-bit memory constraints.

Conditionalize cmake compile of SignalHandlers.cpp so that -m32 is
passed when building 32-bit.

Add a no-op match for Reloc::X86CallPCRel4 during linking. This is
probably the wrong thing, but it allows the tests to pass. Using the
same logic from the Reloc::X86PCRel4 case did not work.
This commit is contained in:
Joel Martin
2019-01-24 15:40:25 -06:00
committed by Dan Gohman
parent 00a4e93bcd
commit fdcb2184a8
7 changed files with 162 additions and 100 deletions

View File

@@ -1,7 +1,11 @@
cmake_minimum_required(VERSION 3.0)
project(SignalHandlers CXX)
set(CMAKE_CXX_FLAGS "-std=c++11 -fno-exceptions -fno-rtti -fPIC")
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set(CMAKE_CXX_FLAGS "-std=c++11 -fno-exceptions -fno-rtti -fPIC")
else( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set(CMAKE_CXX_FLAGS "-m32 -std=c++11 -fno-exceptions -fno-rtti -fPIC")
endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
add_library(SignalHandlers STATIC SignalHandlers.cpp)

View File

@@ -27,7 +27,7 @@ use cranelift_wasm::{
use indexmap;
use std::borrow::ToOwned;
use std::boxed::Box;
use std::collections::{hash_map, HashMap};
use std::collections::HashMap;
use std::rc::Rc;
use std::string::{String, ToString};
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};
@@ -619,17 +619,7 @@ impl Instance {
let vmctx_globals = create_globals(&module);
let offsets = VMOffsets {
pointer_size: mem::size_of::<*const u8>() as u8,
num_signature_ids: vmshared_signatures.len() as u64,
num_imported_functions: imports.functions.len() as u64,
num_imported_tables: imports.tables.len() as u64,
num_imported_memories: imports.memories.len() as u64,
num_imported_globals: imports.globals.len() as u64,
num_defined_tables: tables.len() as u64,
num_defined_memories: memories.len() as u64,
num_defined_globals: vmctx_globals.len() as u64,
};
let offsets = VMOffsets::new(mem::size_of::<*const u8>() as u8, &module);
let mut contents_mmap = Mmap::with_at_least(
mem::size_of::<InstanceContents>()
@@ -710,7 +700,7 @@ impl Instance {
// Collect the exports for the global export map.
for (field, decl) in &module.exports {
use hash_map::Entry::*;
use std::collections::hash_map::Entry::*;
let cell: &RefCell<HashMap<std::string::String, core::option::Option<Export>>> =
contents.global_exports.borrow();
let map: &mut HashMap<std::string::String, core::option::Option<Export>> =

View File

@@ -29,6 +29,9 @@ impl SignatureRegistry {
match self.signature_hash.entry(sig.clone()) {
hash_map::Entry::Occupied(entry) => *entry.get(),
hash_map::Entry::Vacant(entry) => {
#[cfg(target_pointer_width = "32")]
let sig_id = VMSharedSignatureIndex::new(cast::u32(len));
#[cfg(target_pointer_width = "64")]
let sig_id = VMSharedSignatureIndex::new(cast::u32(len).unwrap());
entry.insert(sig_id);
sig_id

View File

@@ -409,7 +409,7 @@ mod test_vmshared_signature_index {
impl VMSharedSignatureIndex {
/// Create a new `VMSharedSignatureIndex`.
pub fn new(value: u32) -> Self {
Self(value)
VMSharedSignatureIndex(value)
}
}