Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/contribute/toolchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ options.
- `lind_syscall/lind_syscall.c`
- `lind_syscall/addr_translation.c`
- `csu/wasm32/wasi_thread_start.s`
- `csu/wasm32/set_stack_pointer.s`

3. Generate sysroot

Expand Down
2 changes: 1 addition & 1 deletion scripts/lind_compile
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ do_dynamic_compile() {
fi

run_cmd "${CLANG_BIN}" "${default_clang_flags[@]}" "${mandatory_clang_flags[@]}"\
"${EXTRA_CLANG_ARGS[@]}" "${SRC}" "$SYSROOT/lib/wasm32-wasi/set_stack_pointer.o" "$SYSROOT/lib/wasm32-wasi/crt1_shared.o" "$SYSROOT/lib/wasm32-wasi/lind_utils.o" -o "${OUT_WASM}"
"${EXTRA_CLANG_ARGS[@]}" "${SRC}" "$SYSROOT/lib/wasm32-wasi/crt1_shared.o" "$SYSROOT/lib/wasm32-wasi/lind_utils.o" -o "${OUT_WASM}"

run_cmd $REPO_ROOT/tools/add-export-tool/add-export-tool "${OUT_WASM}" "${OUT_WASM}" __wasm_apply_tls_relocs func __wasm_apply_tls_relocs optional
run_cmd $REPO_ROOT/tools/add-export-tool/add-export-tool "${OUT_WASM}" "${OUT_WASM}" __wasm_apply_global_relocs func __wasm_apply_global_relocs optional
Expand Down
5 changes: 0 additions & 5 deletions scripts/make_glibc_and_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ $CC --target=wasm32-wasi-threads -matomics \
-o $BUILD/csu/wasi_thread_start.o \
-c $GLIBC/csu/wasm32/wasi_thread_start.s

$CC --target=wasm32-wasi-threads -matomics \
-o $BUILD/csu/set_stack_pointer.o \
-c $GLIBC/csu/wasm32/set_stack_pointer.s

# Generate sysroot
# First, remove the existing sysroot directory to start cleanly
rm -rf "$SYSROOT"
Expand All @@ -185,7 +181,6 @@ rm -rf "$SYSROOT"
# Create the sysroot directory structure
mkdir -p "$SYSROOT/include/wasm32-wasi" "$SYSROOT/lib/wasm32-wasi"
cp "$BUILD/lind_utils.o" "$SYSROOT/lib/wasm32-wasi/"
cp "$BUILD/csu/set_stack_pointer.o" "$SYSROOT/lib/wasm32-wasi/"

"$SCRIPT_DIR/make_archive.sh"
cd $SCRIPT_DIR
Expand Down
1 change: 0 additions & 1 deletion scripts/object_lists/libc_objects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ lind_syscall.o
addr_translation.o
lind_debug.o
csu/wasi_thread_start.o
csu/set_stack_pointer.o
csu/__init_tls.o
csu/init-first.o
csu/libc-start.o
Expand Down
1 change: 0 additions & 1 deletion scripts/object_lists/libc_objects_shared.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ lind_syscall.os
addr_translation.os
lind_debug.os
csu/wasi_thread_start.os
csu/set_stack_pointer.os
csu/libc-start.os
csu/sysdep.os
csu/version.os
Expand Down
23 changes: 0 additions & 23 deletions src/glibc/csu/wasm32/set_stack_pointer.s

This file was deleted.

3 changes: 0 additions & 3 deletions src/glibc/nptl/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ late_init (void)
the user code (*PD->start_routine). */


void set_stack_pointer(int stack_addr);
void *__dummy_reference2 = set_stack_pointer;

static int _Noreturn start_thread (void *arg);

static int create_thread (struct pthread *pd, const struct pthread_attr *attr,
Expand Down
5 changes: 2 additions & 3 deletions src/wasmtime/crates/lind-multi-process/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,10 +1139,9 @@ impl<
// we might also want to perserve the offset of current stack pointer to stack bottom
// not very sure if this is required, but just keep everything the same from parent seems to be good
let offset = parent_stack_high_usr as u32 - stack_pointer;
let stack_pointer_setter = instance
.get_typed_func::<i32, ()>(&mut store, "set_stack_pointer")
instance
.set_stack_pointer(&mut store, (stack_addr - offset) as i32)
.unwrap();
let _ = stack_pointer_setter.call(&mut store, (stack_addr - offset) as i32);
// TODO: set up __stack_low and __stack_high
// TODO: should share the imported wasm global

Expand Down
20 changes: 20 additions & 0 deletions src/wasmtime/crates/wasmtime/src/runtime/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,26 @@ impl Instance {
return Err(());
}

/// Updates the exported `__stack_pointer` global for this instance.
/// Returns `Err(())` if `__stack_pointer` is not exported, is not a global,
/// or cannot be updated.
pub fn set_stack_pointer(&self, mut store: impl AsContextMut, sp: i32) -> Result<(), ()> {
Comment thread
Yaxuan-w marked this conversation as resolved.
if let Some(sp_extern) = self.get_export(store.as_context_mut(), "__stack_pointer") {
match sp_extern {
Extern::Global(sp_global) => {
match sp_global.set(store.as_context_mut(), Val::I32(sp)) {
Ok(()) => return Ok(()),
Err(_) => return Err(()),
}
}
_ => {
return Err(());
}
}
}
Err(())
}

pub fn get_stack_low(&self, mut store: impl AsContextMut) -> Result<i32, ()> {
if let Some(sp_extern) = self.get_export(store.as_context_mut(), "__stack_low") {
match sp_extern {
Expand Down