From b6be99c9e15c0d4a70cf1e92f5437c6b2e1d466c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 19 Feb 2020 20:58:06 -0600 Subject: [PATCH] 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! --- crates/environ/src/compilation.rs | 8 -------- crates/environ/src/cranelift.rs | 15 ++------------- crates/environ/src/func_environ.rs | 24 ------------------------ crates/jit/src/link.rs | 4 ---- crates/obj/src/function.rs | 28 ---------------------------- 5 files changed, 2 insertions(+), 77 deletions(-) diff --git a/crates/environ/src/compilation.rs b/crates/environ/src/compilation.rs index 2335565272..0a896316e1 100644 --- a/crates/environ/src/compilation.rs +++ b/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), } diff --git a/crates/environ/src/cranelift.rs b/crates/environ/src/cranelift.rs index d0d7d47d5c..3021929e8d 100644 --- a/crates/environ/src/cranelift.rs +++ b/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 { diff --git a/crates/environ/src/func_environ.rs b/crates/environ/src/func_environ.rs index f8d2ba5ec6..febf0e38a9 100644 --- a/crates/environ/src/func_environ.rs +++ b/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); diff --git a/crates/jit/src/link.rs b/crates/jit/src/link.rs index ac8c7c97e9..d64261d94d 100644 --- a/crates/jit/src/link.rs +++ b/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 { diff --git a/crates/obj/src/function.rs b/crates/obj/src/function.rs index da0bfc3f26..511756dfb1 100644 --- a/crates/obj/src/function.rs +++ b/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 }