Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #102
Summary
This PR updates the GNU grep build pipeline to support cross-compiling as a WebAssembly Position Independent Executable (PIE). When LIND_DYLINK=1 is enabled, grep will be compiled to dynamically link its external dependencies (specifically the standard C library) at runtime via the lind-wasm environment.
Shared libraries that grep depends on:
Technical Details
Like other Autotools-based projects, building grep for WebAssembly dynamic linking requires specific compiler flag workarounds to prevent ELF compatibility errors.
LDFLAGS)Autoconf feature tests fail if they encounter undefined symbols (like PIE imports) during the configure phase.
Fix: The script uses two
LDFLAGSarrays.LDFLAGS_CONFIGUREuses 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 flagsrequired to build the Wasm PIE.Modifies the underlying configure steps to force static archive generation (
--disable-shared --enable-static) while explicitly injecting-fPICinto theCFLAGS. This bypasses legacy ELF linking errors while guaranteeing that the compiled objects are properly configured for dynamic execution.Statically Linked (gnulib): Compiled internally as a static archive with
-fPIC. This keeps grep's internal polyfills self-contained and completely bypasses Libtool's incompatibility with generating Wasm shared libraries.Dynamically Linked (libc): Standard C library functions are left unresolved using
--unresolved-symbols=import-dynamicrequiring the host environment to maplibc.sointo the WebAssembly env namespace at runtime.Injects required Lind-specific CRT objects (set_stack_pointer.o, crt1_shared.o).
Runs add-export-tool immediately after Wasm optimization to expose __wasm_apply_tls_relocs, __wasm_apply_global_relocs, and __stack_pointer to the runtime host.
Changes to grep test script
No changes are required for grep's
run_tests.sh. The latestlind_runscript (after the dynamic loading branch merge) handles dynamic standard libraries by automatically preloadinglibc.cwasmandlibm.cwasm. Since grep has no external dependencies beyond libc, it requires no explicit --preload flags.How to Test
Static build
Dynamic build
The dynamic build test succeeds with 4/5 tests being successful.
The one test which fails is due to a missing symbol from libc, which is currently handled in this issue.