Skip to content

Commit 5a3cce7

Browse files
committed
Use regular Rust static-PIE for Rust storage example
1 parent 119aaae commit 5a3cce7

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

guest/rust_storage/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33
pushd storage_program
44
./build.sh
55
popd
6-
storage_binary=./storage_program/target/x86_64-unknown-linux-musl/release/demo
6+
storage_binary=./storage_program/target/release/demo
77
objcopy -w --extract-symbol --strip-symbol=!remote* --strip-symbol=* $storage_binary storage.syms
88
gcc-12 -static -O2 symbol_offset.c -o symbol_offset
99
./symbol_offset storage.syms 0x44000000
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env bash
22
set -e
3-
RUSTFLAGS="-Zexport-executable-symbols" cargo build --target x86_64-unknown-linux-musl --release
3+
RUSTFLAGS="-Ctarget-feature=+crt-static -Zexport-executable-symbols" cargo build --release
4+
#RUSTFLAGS="-Zexport-executable-symbols" cargo build --target x86_64-unknown-linux-musl --release

guest/rust_storage/storage_program/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
use std::process::ExitCode;
2+
use std::sync::{LazyLock, Mutex};
3+
static ARRAY: LazyLock<Mutex<Vec<i32>>> = LazyLock::new(|| Mutex::new(vec![]));
24

35
#[no_mangle]
46
extern "C" fn remote_function(arg: fn(i32) -> i32, value: i32) -> i32 {
7+
// Locked reference to avoid data race issues
8+
ARRAY.lock().unwrap().push(value);
9+
//println!("In remote_function with vec: {:?}", *ARRAY.lock().unwrap());
510
return arg(value);
611
}
712

src/storage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ int main(int argc, char** argv)
170170
tinykvm::Machine vm{master_vm, options};
171171
assert(vm.is_remote_connected());
172172

173-
/* Call 'do_calculation' with 21 as argument */
173+
/* Measure call overhead */
174174
auto do_it = callback_address.find("do_nothing");
175175
if (do_it == callback_address.end()) {
176176
fprintf(stderr, "Error: no do_nothing() in guest\n");
@@ -187,6 +187,7 @@ int main(int argc, char** argv)
187187
}) / 100.0;
188188
printf("Call overhead: %.2fus\n", call_overhead * 1e6);
189189

190+
/* Call 'do_calculation' with 21 as argument */
190191
printf("Calling do_calculation() @ 0x%lX\n", calc_it->second);
191192
for (int i = 0; i < 10; i++)
192193
vm.timed_vmcall(calc_it->second, 5.0f, 21);

0 commit comments

Comments
 (0)