Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit 5428edf

Browse files
authored
Update wasmonkey (#237)
We will eventually get rid of it, but meanwhile, this updates it to use the current versions of parity-wasm and goblin.
1 parent 5de7989 commit 5428edf

File tree

11 files changed

+57
-70
lines changed

11 files changed

+57
-70
lines changed

Cargo.lock

Lines changed: 8 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
[package]
22
name = "wasmonkey"
3-
version = "0.1.4"
4-
authors = ["Frank Denis <[email protected]>"]
3+
version = "0.1.7"
4+
authors = ["Lucet team <[email protected]>"]
55
description = "Patch a WASM object file to replace a set of exported functions with imported functions from another library"
6-
license = "ISC"
7-
homepage = "https://github.com/jedisct1/wasmonkey"
8-
repository = "https://github.com/jedisct1/wasmonkey"
6+
license = "Apache-2.0 WITH LLVM-exception"
7+
homepage = "https://github.com/fastly/lucet"
8+
repository = "https://github.com/fastly/lucet"
99
categories = ["wasm"]
10+
edition = "2018"
1011

1112
[dependencies]
12-
clap = "2.32"
13+
clap = "2.33"
1314
failure = "0.1"
14-
goblin = "0.0.21"
15-
lazy_static = "1.2"
16-
parity-wasm = "0.35"
15+
goblin = "0.0.22"
16+
lazy_static = "1.3"
17+
parity-wasm = "0.38"
1718
serde = "1.0"
1819
serde_derive = "1.0"
1920
serde_json = "1.0"
20-
siphasher = "0.2"
21+
siphasher = "0.3"
2122
xfailure = "0.1"

lucet-builtins/wasmonkey/src/bin/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::{PatcherConfig, WError};
12
use clap::{App, Arg};
23
use std::path::PathBuf;
3-
use {PatcherConfig, WError};
44

55
#[derive(Default, Clone, Debug)]
66
pub struct Config {

lucet-builtins/wasmonkey/src/bin/wasmonkey.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
extern crate clap;
2-
extern crate failure;
3-
extern crate wasmonkey;
4-
51
mod config;
62

7-
use config::*;
3+
use crate::config::*;
84
use wasmonkey::*;
95

106
fn main() -> Result<(), WError> {

lucet-builtins/wasmonkey/src/functions_ids.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use errors::*;
1+
use crate::errors::*;
22
use parity_wasm::elements::{
33
CodeSection, ElementSection, ExportSection, FuncBody, Instruction, Instructions, Internal,
44
Module,
@@ -12,8 +12,8 @@ fn shift_function_ids_in_code_section(
1212
for code_body in code_bodies.iter_mut() {
1313
let opcodes = code_body.code_mut().elements_mut();
1414
for opcode in opcodes.iter_mut() {
15-
if let Instruction::Call(ref mut function_id) = opcode {
16-
*function_id = *function_id + shift
15+
if let Instruction::Call(function_id) = *opcode {
16+
*opcode = Instruction::Call(function_id + shift)
1717
}
1818
}
1919
}
@@ -23,8 +23,8 @@ fn shift_function_ids_in_code_section(
2323
fn shift_function_ids_in_exports_section(export_section: &mut ExportSection, shift: u32) {
2424
for entry in export_section.entries_mut() {
2525
let internal = entry.internal_mut();
26-
if let Internal::Function(ref mut function_id) = internal {
27-
*function_id = *function_id + shift
26+
if let Internal::Function(function_id) = *internal {
27+
*internal = Internal::Function(function_id + shift)
2828
}
2929
}
3030
}
@@ -53,9 +53,9 @@ fn replace_function_id_in_code_section(code_section: &mut CodeSection, before: u
5353
for code_body in code_bodies.iter_mut() {
5454
let opcodes = code_body.code_mut().elements_mut();
5555
for opcode in opcodes.iter_mut() {
56-
match opcode {
57-
Instruction::Call(ref mut function_id) if *function_id == before => {
58-
*function_id = after
56+
match *opcode {
57+
Instruction::Call(function_id) if function_id == before => {
58+
*opcode = Instruction::Call(after)
5959
}
6060
_ => {}
6161
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use errors::*;
2-
use parity_wasm::elements::{FunctionNameSection, IndexMap};
1+
use crate::errors::*;
2+
use parity_wasm::elements::{FunctionNameSubsection, IndexMap};
33

44
pub fn prepend_function_name(
5-
function_names_section: &mut FunctionNameSection,
5+
function_names_subsection: &mut FunctionNameSubsection,
66
name: String,
77
) -> Result<(), WError> {
8-
let mut map_new = IndexMap::with_capacity(function_names_section.names().len() + 1 as usize);
9-
for (idx, name) in function_names_section.names() {
8+
let mut map_new = IndexMap::with_capacity(function_names_subsection.names().len() + 1 as usize);
9+
for (idx, name) in function_names_subsection.names() {
1010
map_new.insert(idx + 1, name.clone());
1111
}
1212
map_new.insert(0, name);
13-
*function_names_section.names_mut() = map_new;
13+
*function_names_subsection.names_mut() = map_new;
1414
Ok(())
1515
}

lucet-builtins/wasmonkey/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
extern crate clap;
21
#[macro_use]
32
extern crate failure;
4-
extern crate goblin;
3+
54
#[cfg_attr(test, macro_use)]
65
extern crate lazy_static;
7-
extern crate parity_wasm;
6+
87
#[macro_use]
98
extern crate serde_derive;
10-
extern crate serde_json;
9+
1110
#[cfg(test)]
1211
extern crate siphasher;
1312
#[macro_use]
@@ -24,5 +23,5 @@ mod symbols;
2423
#[cfg(test)]
2524
mod tests;
2625

27-
pub use errors::*;
28-
pub use patcher::*;
26+
pub use crate::errors::*;
27+
pub use crate::patcher::*;

lucet-builtins/wasmonkey/src/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use errors::*;
1+
use crate::errors::*;
22
use serde_json;
33
use std::collections::HashMap;
44
use std::fs::File;

lucet-builtins/wasmonkey/src/patcher.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use errors::*;
2-
use functions_ids::*;
3-
use functions_names::*;
4-
use map::*;
1+
use crate::errors::*;
2+
use crate::functions_ids::*;
3+
use crate::functions_names::*;
4+
use crate::map::*;
5+
use crate::sections::*;
6+
use crate::symbols::{self, ExtractedSymbols};
57
use parity_wasm;
68
use parity_wasm::elements::{
7-
self, External, ImportEntry, ImportSection, Internal, Module, NameSection, Section,
9+
self, External, ImportEntry, ImportSection, Internal, Module, Section,
810
};
9-
use sections::*;
1011
use std::collections::HashMap;
1112
use std::path::{Path, PathBuf};
12-
use symbols::{self, ExtractedSymbols};
1313

1414
pub const BUILTIN_PREFIX: &str = "builtin_";
1515

@@ -176,11 +176,11 @@ fn prepend_builtin_to_names_section(module: &mut Module, builtin: &Builtin) -> R
176176
let names_section = module
177177
.names_section_mut()
178178
.expect("Names section not present");
179-
let function_names_section = match names_section {
180-
NameSection::Function(function_names_section) => function_names_section,
179+
let function_names_subsection = match names_section.functions_mut() {
180+
Some(function_names_subsection) => function_names_subsection,
181181
_ => xbail!(WError::InternalError("Unexpected names section")),
182182
};
183-
prepend_function_name(function_names_section, import_name)?;
183+
prepend_function_name(function_names_subsection, import_name)?;
184184
Ok(())
185185
}
186186

lucet-builtins/wasmonkey/src/symbols.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use errors::*;
1+
use crate::errors::*;
2+
use crate::patcher::BUILTIN_PREFIX;
23
use goblin::elf::Elf;
34
use goblin::mach::{self, Mach, MachO};
45
use goblin::Object;
5-
use patcher::BUILTIN_PREFIX;
66
use std::fs::File;
77
use std::io::Read;
88
use std::path::Path;
@@ -36,7 +36,7 @@ impl ExtractedSymbols {
3636

3737
pub fn merge_additional(mut self, additional_names: &[String]) -> Self {
3838
let mut additional_symbols: Vec<_> = additional_names
39-
.into_iter()
39+
.iter()
4040
.map(|name| ExtractedSymbol {
4141
name: name.to_string(),
4242
})
@@ -47,7 +47,7 @@ impl ExtractedSymbols {
4747
}
4848
}
4949

50-
fn parse_elf(elf: &Elf) -> Result<ExtractedSymbols, WError> {
50+
fn parse_elf(elf: &Elf<'_>) -> Result<ExtractedSymbols, WError> {
5151
let mut symbols = vec![];
5252

5353
for symbol in elf
@@ -67,7 +67,7 @@ fn parse_elf(elf: &Elf) -> Result<ExtractedSymbols, WError> {
6767
Ok(symbols.into())
6868
}
6969

70-
fn parse_macho(macho: &MachO) -> Result<ExtractedSymbols, WError> {
70+
fn parse_macho(macho: &MachO<'_>) -> Result<ExtractedSymbols, WError> {
7171
let mut symbols = vec![];
7272

7373
// Start by finding the boundaries of the text section

0 commit comments

Comments
 (0)