Fix WASM templates after lld --stack-first default change#2906
Open
RayenChalouati wants to merge 1 commit intonesbox:mainfrom
Open
Fix WASM templates after lld --stack-first default change#2906RayenChalouati wants to merge 1 commit intonesbox:mainfrom
RayenChalouati wants to merge 1 commit intonesbox:mainfrom
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.
This updates the WASM templates to stop relying on --global-base=98304 with post-data stack placement, which no longer works reliably since newer versions of LLVM’s WebAssembly linker enable --stack-first by default.
TIC-80 reserves the first 96 KiB of memory (0x00000–0x18000) for internal systems. Previously, templates depended on the linker placing the stack after the data segment, allowing the data segment to start at --global-base=98304.
However, with --stack-first now enabled by default in lld, the stack is placed at the start of memory, which breaks this assumption and risks overlapping with TIC-80’s reserved memory.
Changes
The templates were updated to use the stack-reservation workaround instead:
Explicitly enable --stack-first
Increase stack size to 106496 bytes (96 KiB reserved + 8 KiB usable stack)
This effectively reserves the TIC-80 internal memory region while keeping a small usable stack.
Updated files
templates/rust/.cargo/config.toml
templates/nim/config.nims
templates/c/Makefile
templates/d/dub.json
templates/zig/build.zig
demos/wasm/build.zig
demos/bunny/wasmmark/build.zig
Short README notes were also added in each template to document the 96 KiB + 8 KiB stack layout.
Verification
Verification was static only:
Rust TOML parses correctly
dub.json parses correctly
git diff --check reports no issues
I was not able to run full builds because this environment does not have the required toolchains installed (cargo, rustc, zig, nim, ldc2, clang).
Remaining risk
For Zig templates, the oversized stack reservation pattern is now used, but --stack-first is not explicitly set and therefore still depends on Zig’s linker behavior.
References
llvm#151015
llvm#166998
WebAssembly linker documentation for LLVM