Skip to content

Commit badec30

Browse files
feat: move linker to separate crate
Signed-off-by: Florian Hartung <florian.hartung@dlr.de>
1 parent 25844d4 commit badec30

File tree

9 files changed

+46
-13
lines changed

9 files changed

+46
-13
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ members = [
44
"crates/benchmark",
55
"crates/checked",
66
"crates/compare-testsuite-rs",
7+
"crates/linker",
78
"crates/log_wrapper",
89
]
910
resolver = "2"
1011

1112
[workspace.dependencies]
1213
checked = { path = "crates/checked" }
14+
linker = { path = "crates/linker" }
1315
wasm-interpreter = { path = "." }
1416

1517
env_logger = "0.10.1"
@@ -44,7 +46,7 @@ libm = "=0.2.8"
4446
log_wrapper.path = "crates/log_wrapper"
4547

4648
[dev-dependencies]
47-
checked.workspace = true
49+
checked = { workspace = true, features = ["linker"] }
4850

4951
bumpalo = "3.17.0"
5052
env_logger = { workspace = true }

crates/checked/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ rust-version = "1.87.0" # Keep this in sync with the requirements!
66

77
[dependencies]
88
wasm-interpreter.workspace = true
9+
linker = { workspace = true, optional = true }
910

1011
[features]
11-
# TODO: interop, linker
12+
# linker
13+
# TODO: interop

crates/checked/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,20 @@ use core::sync::atomic::{AtomicU64, Ordering};
3333
use alloc::vec::Vec;
3434

3535
mod interop;
36-
mod linker;
3736
mod store;
3837
mod stored_types;
3938
mod value;
4039

4140
pub use interop::*;
42-
pub use linker::*;
4341
pub use store::*;
4442
pub use stored_types::*;
4543
pub use value::*;
4644

45+
#[cfg(feature = "linker")]
46+
mod linker;
47+
#[cfg(feature = "linker")]
48+
pub use linker::*;
49+
4750
/// A unique identifier for a specific [`Store`]
4851
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
4952
pub struct StoreId(u64);

crates/checked/src/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99

1010
#[derive(Default)]
1111
pub struct Linker {
12-
inner: wasm::linker::Linker,
12+
inner: linker::Linker,
1313

1414
/// This is for the checked API which makes sure that all objects used
1515
/// originate from the same [`Store`].

crates/linker/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "linker"
3+
version = "0.2.0"
4+
edition = "2024"
5+
rust-version = "1.87.0" # Keep this in sync with the requirements!
6+
7+
[dependencies]
8+
wasm-interpreter.workspace = true

crates/linker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# A Name Resolution Based Linker
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1+
//! A Name Resolution Based Linker
2+
3+
#![no_std]
4+
#![deny(
5+
clippy::missing_safety_doc,
6+
clippy::undocumented_unsafe_blocks,
7+
unsafe_op_in_unsafe_fn
8+
)]
9+
10+
extern crate alloc;
11+
112
use alloc::{
213
borrow::ToOwned,
314
collections::btree_map::{BTreeMap, Entry},
415
string::String,
516
vec::Vec,
617
};
718

8-
use crate::{
9-
addrs::ModuleAddr, store::InstantiationOutcome, ExternVal, RuntimeError, Store, ValidationInfo,
19+
use wasm::{
20+
ExternVal, RuntimeError, Store, ValidationInfo, addrs::ModuleAddr, config::Config,
21+
store::InstantiationOutcome,
1022
};
1123

12-
use super::config::Config;
13-
1424
/// A linker used to link a module's imports against extern values previously
1525
/// defined in this [`Linker`] context.
1626
///
@@ -98,12 +108,12 @@ impl Linker {
98108
) -> Result<(), RuntimeError> {
99109
// SAFETY: The caller ensures that the given module address is valid in
100110
// the given store.
101-
let module = unsafe { store.modules.get(module) };
102-
for export in &module.exports {
111+
let module_exports = unsafe { store.instance_exports_unchecked(module) };
112+
for export in module_exports {
103113
// SAFETY: The module and thus also its exported extern values come
104114
// from the same store used now. Therefore, the extern values must
105115
// be valid in this store.
106-
unsafe { self.define_unchecked(module_name.clone(), export.0.clone(), *export.1)? };
116+
unsafe { self.define_unchecked(module_name.clone(), export.0, export.1)? };
107117
}
108118

109119
Ok(())

src/execution/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub mod const_interpreter_loop;
1414
pub mod error;
1515
pub mod interop;
1616
mod interpreter_loop;
17-
pub mod linker;
1817
pub(crate) mod little_endian;
1918
pub mod resumable;
2019
pub mod store;

0 commit comments

Comments
 (0)