Skip to content

Add build script to compile bash dynamically#93

Open
vidyalakshmir wants to merge 1 commit intomainfrom
dynloading/bash
Open

Add build script to compile bash dynamically#93
vidyalakshmir wants to merge 1 commit intomainfrom
dynloading/bash

Conversation

@vidyalakshmir
Copy link
Contributor

@vidyalakshmir vidyalakshmir commented Feb 25, 2026

Description

This PR introduces a dynamic (shared) WebAssembly build script for Bash.

Key Changes

  • Enabled Position Independent Code (PIC): Appended -fPIC to CFLAGS so all core objects and builtins are compiled for dynamic linking.
  • Updated WASM Linker Flags: Replaced static memory bounds with dynamic PIE flags (-Wl,-pie, -Wl,--import-table, -Wl,--export-dynamic, -Wl,--experimental-pic).
  • Restored libdl Support: Re-introduced -ldl in the final linker command to support loading shared objects at runtime.
  • Automated LindFS Installation: Added a final step that automatically copies the compiled bash binary (and .cwasm if available) directly into $LINDFS_ROOT/bin.

Integration with lind-wasm branch dylink_impl_integration

The latest dylink_impl_integration of lind-wasm is used. Steps followed are detailed below.

git checkout dylink_impl_integration
git pull
make
scripts/make_shared_glibc.sh
scripts/make_shared_libm.sh
cd src/lind-boot
cargo build --features disable_signals

Updated lind-wasm/scripts/append_tls_relocs_export.sh to use standard wasm2wat and wat2wasm commands instead of absolute paths.

Tested

Test script

Tested with a simple test script lind-wasm/lindfs/bash_tests/test.sh

#!/bin/bash
name="Bash"
if [[ -n "$name" ]]; then
  printf "Hello, %s!\n" "$name"
fi
for i in {1..3}; do
  printf "Count: %d\n" "$i"
done

Command to run the test

sudo /home/lind/lind-wasm/src/lind-boot/target/debug/lind-boot --preload env=/lib/libc.so --preload env=/lib/libm.so /bin/bash /bash_tests/test.sh

Test output

thread 'main' (48837) panicked at src/lind_wasmtime/execute.rs:726:33:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@vidyalakshmir
Copy link
Contributor Author

vidyalakshmir commented Feb 25, 2026

I am adding this PR to get started with compiling apps for dynamic loading. I have mentioned the steps followed to use the new 'dynamic loading' branch within lind-wasm. Also the steps to build bash dynamically was followed looking at the python build scripts from 'build_python' branch of lind-wasm-apps/.

I am hitting an issue when I run both bash and python which is built for dynamic loading. @qianxichen233

fi

BASE_SYSROOT="${BASE_SYSROOT:-$LIND_WASM_ROOT/build/sysroot}"
MERGED_SYSROOT="${APPS_MERGED:-$APPS_ROOT/build/sysroot_merged}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a static build thing. is libc not dynamic now?

fi

###############################################################################
# 10. Install to Lind Filesystem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to remove this since we'll have our own make install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants