Skip to content

Add dynamic build for curl and update tests#188

Open
vidyalakshmir wants to merge 2 commits intomainfrom
curl-dynamic
Open

Add dynamic build for curl and update tests#188
vidyalakshmir wants to merge 2 commits intomainfrom
curl-dynamic

Conversation

@vidyalakshmir
Copy link
Copy Markdown
Contributor

@vidyalakshmir vidyalakshmir commented Apr 13, 2026

Closes #100
Enable dynamic WebAssembly builds (LIND_DYLINK=1) for curl`

Shared libraries that git depends on:

  • openssl (libssl.so and libcrypto.so)
  • zlib (libz.so)
  • libc

Summary

This PR updates the curl build pipeline to support cross-compiling as a WebAssembly Position Independent Executable (PIE). When LIND_DYLINK=1 is enabled, curl will be compiled to dynamically link its external dependencies (OpenSSL, zlib) at runtime via the lind-wasm environment, rather than statically linking them into the binary.

Technical Details

Building Autotools/Libtool projects for WebAssembly dynamic linking requires bypassing several traditional Linux/ELF assumptions. This PR implements the "Static Internal, Dynamic External" workaround.

1. Libtool / ELF Versioning Bypass

  • By default, passing --enable-shared to curl's configure script causes Libtool to generate ELF version scripts (.ver), which WebAssembly's linker (wasm-ld) completely rejects.
  • Fix: The script intentionally leaves --disable-shared --enable-static enabled for Libtool, but overrides the environment to force the compiler to use Position Independent Code (-fPIC). This causes curl's internal libraries (libcurl.la) to compile safely as .a archives containing PIC objects, which are then successfully linked into the final dynamic executable.

2. Linker Flag Splitting (LDFLAGS)

  • autoconf feature tests frequently fail if they encounter undefined symbols too early.
  • Fix: The script now uses two separate LDFLAGS arrays. LDFLAGS_CONFIGURE uses strict static linking rules so feature detection works cleanly. LDFLAGS_WASM (injected only during the make step) includes the necessary -Wl,-pie, --allow-undefined, and --unresolved-symbols=import-dynamic flags required to build the Wasm PIE.

3. CRT & Export Handling

  • Includes required Lind-specific CRT objects (set_stack_pointer.o, crt1_shared.o).
  • Modifies wasm-opt to support bulk memory and threads for dynamic environments.
  • Runs add-export-tool immediately after optimization to expose __wasm_apply_tls_relocs, __wasm_apply_global_relocs, and __stack_pointer to the runtime host.

Test Runner Updates

  • Runtime Preloading: Updated the test execution wrapper. When LIND_DYLINK=1, the test suite now runs lind_run with the necessary --preload env=... arguments. This resolves the unknown import errors by ensuring the Wasm runtime populates the env namespace with our shared dependencies before executing curl.cwasm.

How to Test

Test Static Path:

  • make curl
  • APP=curl make test

Test Dynamic Path:

  • LIND_DYLINK=1 make curl
  • LIND_DYLINK=1 APP=curl make test
    (This requires the updates from this PR which does dynamic compilation of libraries)

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.

curl - dynamic build

1 participant