Browse Source

Remove memory-related cases from `RelocationTarget` (#949)

This commit shrinks the `RelocationTarget` enumeration to remove
intrinsic-related relocations since they are no longer used. Instead
these function calls are done indirectly via a table in the `VMContext`.
This means that all of this is essentially dead code!
pull/955/head
Alex Crichton 5 years ago
committed by GitHub
parent
commit
b6be99c9e1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      crates/environ/src/compilation.rs
  2. 15
      crates/environ/src/cranelift.rs
  3. 24
      crates/environ/src/func_environ.rs
  4. 4
      crates/jit/src/link.rs
  5. 28
      crates/obj/src/function.rs

8
crates/environ/src/compilation.rs

@ -247,14 +247,6 @@ pub enum RelocationTarget {
UserFunc(FuncIndex),
/// A compiler-generated libcall.
LibCall(ir::LibCall),
/// Function for growing a locally-defined 32-bit memory by the specified amount of pages.
Memory32Grow,
/// Function for growing an imported 32-bit memory by the specified amount of pages.
ImportedMemory32Grow,
/// Function for query current size of a locally-defined 32-bit linear memory.
Memory32Size,
/// Function for query current size of an imported 32-bit linear memory.
ImportedMemory32Size,
/// Jump table index.
JumpTable(FuncIndex, ir::JumpTable),
}

15
crates/environ/src/cranelift.rs

@ -6,10 +6,7 @@ use crate::compilation::{
Compilation, CompileError, CompiledFunction, CompiledFunctionUnwindInfo, Relocation,
RelocationTarget, TrapInformation,
};
use crate::func_environ::{
get_func_name, get_imported_memory32_grow_name, get_imported_memory32_size_name,
get_memory32_grow_name, get_memory32_size_name, FuncEnvironment,
};
use crate::func_environ::{get_func_name, FuncEnvironment};
use crate::module::Module;
use crate::module_environ::FunctionBodyData;
use crate::CacheConfig;
@ -46,15 +43,7 @@ impl binemit::RelocSink for RelocSink {
name: &ExternalName,
addend: binemit::Addend,
) {
let reloc_target = if *name == get_memory32_grow_name() {
RelocationTarget::Memory32Grow
} else if *name == get_imported_memory32_grow_name() {
RelocationTarget::ImportedMemory32Grow
} else if *name == get_memory32_size_name() {
RelocationTarget::Memory32Size
} else if *name == get_imported_memory32_size_name() {
RelocationTarget::ImportedMemory32Size
} else if let ExternalName::User { namespace, index } = *name {
let reloc_target = if let ExternalName::User { namespace, index } = *name {
debug_assert_eq!(namespace, 0);
RelocationTarget::UserFunc(FuncIndex::from_u32(index))
} else if let ExternalName::LibCall(libcall) = *name {

24
crates/environ/src/func_environ.rs

@ -22,30 +22,6 @@ pub fn get_func_name(func_index: FuncIndex) -> ir::ExternalName {
ir::ExternalName::user(0, func_index.as_u32())
}
/// Compute an `ir::ExternalName` for the `memory.grow` libcall for
/// 32-bit locally-defined memories.
pub fn get_memory32_grow_name() -> ir::ExternalName {
ir::ExternalName::user(1, 0)
}
/// Compute an `ir::ExternalName` for the `memory.grow` libcall for
/// 32-bit imported memories.
pub fn get_imported_memory32_grow_name() -> ir::ExternalName {
ir::ExternalName::user(1, 1)
}
/// Compute an `ir::ExternalName` for the `memory.size` libcall for
/// 32-bit locally-defined memories.
pub fn get_memory32_size_name() -> ir::ExternalName {
ir::ExternalName::user(1, 2)
}
/// Compute an `ir::ExternalName` for the `memory.size` libcall for
/// 32-bit imported memories.
pub fn get_imported_memory32_size_name() -> ir::ExternalName {
ir::ExternalName::user(1, 3)
}
/// An index type for builtin functions.
pub struct BuiltinFunctionIndex(u32);

4
crates/jit/src/link.rs

@ -29,10 +29,6 @@ pub fn link_module(
}
None => panic!("direct call to import"),
},
RelocationTarget::Memory32Grow => wasmtime_memory32_grow as usize,
RelocationTarget::Memory32Size => wasmtime_memory32_size as usize,
RelocationTarget::ImportedMemory32Grow => wasmtime_imported_memory32_grow as usize,
RelocationTarget::ImportedMemory32Size => wasmtime_imported_memory32_size as usize,
RelocationTarget::LibCall(libcall) => {
use cranelift_codegen::ir::LibCall::*;
match libcall {

28
crates/obj/src/function.rs

@ -5,16 +5,6 @@ use wasmtime_environ::settings;
use wasmtime_environ::settings::Configurable;
use wasmtime_environ::{Compilation, Module, RelocationTarget, Relocations};
fn get_reloc_target_special_import_name(target: RelocationTarget) -> Option<&'static str> {
Some(match target {
RelocationTarget::Memory32Grow => &"wasmtime_memory32_grow",
RelocationTarget::ImportedMemory32Grow => &"wasmtime_memory32_grow",
RelocationTarget::Memory32Size => &"wasmtime_memory32_size",
RelocationTarget::ImportedMemory32Size => &"wasmtime_imported_memory32_size",
_ => return None,
})
}
/// Defines module functions
pub fn declare_functions(
obj: &mut Artifact,
@ -25,14 +15,6 @@ pub fn declare_functions(
let string_name = format!("_wasm_function_{}", i);
obj.declare(string_name, Decl::function_import())?;
}
for (_, function_relocs) in relocations.iter() {
for r in function_relocs {
let special_import_name = get_reloc_target_special_import_name(r.reloc_target);
if let Some(special_import_name) = special_import_name {
obj.declare(special_import_name, Decl::function_import())?;
}
}
}
for (i, _function_relocs) in relocations.iter().rev() {
let func_index = module.func_index(i);
let string_name = format!("_wasm_function_{}", func_index.index());
@ -81,16 +63,6 @@ pub fn emit_functions(
at: r.offset as u64,
})?;
}
RelocationTarget::Memory32Grow
| RelocationTarget::ImportedMemory32Grow
| RelocationTarget::Memory32Size
| RelocationTarget::ImportedMemory32Size => {
obj.link(Link {
from: &string_name,
to: get_reloc_target_special_import_name(r.reloc_target).expect("name"),
at: r.offset as u64,
})?;
}
RelocationTarget::JumpTable(_, _) => {
// ignore relocations for jump tables
}

Loading…
Cancel
Save