Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm targets should append lld --stack-first #4496

Closed
fengb opened this issue Feb 18, 2020 · 3 comments · Fixed by #5501
Closed

Wasm targets should append lld --stack-first #4496

fengb opened this issue Feb 18, 2020 · 3 comments · Fixed by #5501
Labels
accepted This proposal is planned. arch-wasm 32-bit and 64-bit WebAssembly contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@fengb
Copy link
Contributor

fengb commented Feb 18, 2020

By default, LLVM adopts this memory model:

|   Globals   |   <-- Stack   |   Heap -->  |++

This means when the stack runs out of space, it will start trampling over global memory before causing a stack overflow.

Appending --stack-first will flip where the stack and the globals are located, so stack overflow will error out immediately instead of corrupting globals.

Rust has made a similar decision: rustwasm/team#81 (comment)

@andrewrk andrewrk added arch-wasm 32-bit and 64-bit WebAssembly proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. labels Feb 18, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Feb 18, 2020
@andrewrk andrewrk added accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels Feb 18, 2020
@zigazeljko
Copy link
Contributor

So the only change is adding lj->args.append("--stack-first"); to construct_linker_job_wasm?

If so, I can prepare a pull request.

@fengb
Copy link
Contributor Author

fengb commented Jun 1, 2020

Yep that should be it.

@ryuukk
Copy link
Contributor

ryuukk commented Dec 7, 2021

thanks, you saved me after 2 days of headache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. arch-wasm 32-bit and 64-bit WebAssembly contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants