Skip to content

Commit

Permalink
Remove the custom probestack trampoline in compiler-cranelift
Browse files Browse the repository at this point in the history
This is now handled by the generic trampoline code in the engine.
  • Loading branch information
Amanieu committed Mar 14, 2022
1 parent af3d948 commit 657bbae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 63 deletions.
38 changes: 1 addition & 37 deletions lib/compiler-cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use gimli::write::{Address, EhFrame, FrameTable};
use loupe::MemoryUsage;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use std::sync::Arc;
use target_lexicon::{Architecture, OperatingSystem};
use wasmer_compiler::CompileError;
use wasmer_compiler::{CallingConvention, ModuleTranslationState, Target};
use wasmer_compiler::{
Expand All @@ -30,13 +29,8 @@ use wasmer_compiler::{
FunctionBodyData, MiddlewareBinaryReader, ModuleMiddleware, ModuleMiddlewareChain,
SectionIndex,
};
use wasmer_compiler::{
CustomSection, CustomSectionProtection, Relocation, RelocationKind, RelocationTarget,
SectionBody,
};
use wasmer_types::entity::{EntityRef, PrimaryMap};
use wasmer_types::{FunctionIndex, LocalFunctionIndex, SignatureIndex};
use wasmer_vm::libcalls::LibCall;

/// A compiler that compiles a WebAssembly module with Cranelift, translating the Wasm to Cranelift IR,
/// optimizing it and then translating to assembly.
Expand Down Expand Up @@ -109,35 +103,6 @@ impl Compiler for CraneliftCompiler {

let mut custom_sections = PrimaryMap::new();

let probestack_trampoline_relocation_target = if target.triple().operating_system
== OperatingSystem::Linux
&& target.triple().architecture == Architecture::X86_64
{
let probestack_trampoline = CustomSection {
protection: CustomSectionProtection::ReadExecute,
// We create a jump to an absolute 64bits address
// with an indrect jump immediatly followed but the absolute address
// JMP [IP+0] FF 25 00 00 00 00
// 64bits ADDR 00 00 00 00 00 00 00 00 preset to 0 until the relocation takes place
bytes: SectionBody::new_with_vec(vec![
0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
]),
relocations: vec![Relocation {
kind: RelocationKind::Abs8,
reloc_target: RelocationTarget::LibCall(LibCall::Probestack),
// 6 is the size of the jmp instruction. The relocated address must follow
offset: 6,
addend: 0,
}],
};
custom_sections.push(probestack_trampoline);

Some(SectionIndex::new(custom_sections.len() - 1))
} else {
None
};

let (functions, fdes): (Vec<CompiledFunction>, Vec<_>) = function_body_inputs
.iter()
.collect::<Vec<(LocalFunctionIndex, &FunctionBodyData<'_>)>>()
Expand Down Expand Up @@ -174,8 +139,7 @@ impl Compiler for CraneliftCompiler {
)?;

let mut code_buf: Vec<u8> = Vec::new();
let mut reloc_sink =
RelocSink::new(&module, func_index, probestack_trampoline_relocation_target);
let mut reloc_sink = RelocSink::new(&module, func_index);
let mut trap_sink = TrapSink::new();
let mut stackmap_sink = binemit::NullStackMapSink {};
context
Expand Down
28 changes: 2 additions & 26 deletions lib/compiler-cranelift/src/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
use crate::translator::{irlibcall_to_libcall, irreloc_to_relocationkind};
use cranelift_codegen::binemit;
use cranelift_codegen::ir::LibCall;
use cranelift_codegen::ir::{self, ExternalName};
use cranelift_entity::EntityRef as CraneliftEntityRef;
use wasmer_compiler::{JumpTable, Relocation, RelocationTarget, TrapInformation};
use wasmer_compiler::{RelocationKind, SectionIndex};
use wasmer_types::entity::EntityRef;
use wasmer_types::{FunctionIndex, LocalFunctionIndex, ModuleInfo};
use wasmer_vm::TrapCode;
Expand All @@ -20,9 +18,6 @@ pub(crate) struct RelocSink<'a> {

/// Relocations recorded for the function.
pub func_relocs: Vec<Relocation>,

/// The section where the probestack trampoline call is located
pub probestack_trampoline_relocation_target: Option<SectionIndex>,
}

impl<'a> binemit::RelocSink for RelocSink<'a> {
Expand All @@ -42,21 +37,7 @@ impl<'a> binemit::RelocSink for RelocSink<'a> {
.expect("The provided function should be local"),
)
} else if let ExternalName::LibCall(libcall) = *name {
match (libcall, self.probestack_trampoline_relocation_target) {
(LibCall::Probestack, Some(probestack_trampoline_relocation_target)) => {
self.func_relocs.push(Relocation {
kind: RelocationKind::X86CallPCRel4,
reloc_target: RelocationTarget::CustomSection(
probestack_trampoline_relocation_target,
),
offset: offset,
addend: addend,
});
// Skip the default path
return;
}
_ => RelocationTarget::LibCall(irlibcall_to_libcall(libcall)),
}
RelocationTarget::LibCall(irlibcall_to_libcall(libcall))
} else {
panic!("unrecognized external name")
};
Expand Down Expand Up @@ -93,19 +74,14 @@ impl<'a> binemit::RelocSink for RelocSink<'a> {

impl<'a> RelocSink<'a> {
/// Return a new `RelocSink` instance.
pub fn new(
module: &'a ModuleInfo,
func_index: FunctionIndex,
probestack_trampoline_relocation_target: Option<SectionIndex>,
) -> Self {
pub fn new(module: &'a ModuleInfo, func_index: FunctionIndex) -> Self {
let local_func_index = module
.local_func_index(func_index)
.expect("The provided function should be local");
Self {
module,
local_func_index,
func_relocs: Vec::new(),
probestack_trampoline_relocation_target,
}
}
}
Expand Down

0 comments on commit 657bbae

Please sign in to comment.