This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Create a __stack_limit variable
AbandonedPublic

Authored by sunfish on Nov 20 2019, 3:08 PM.

Details

Reviewers
sbc100
Summary

Create a stack_limit variable, similar to stack_pointer, to mark
the end of the stack. This will support stack overflow checks.

Diff Detail

Event Timeline

sunfish created this revision.Nov 20 2019, 3:08 PM

Does this need to be wasm global? Or can it just be regular data symbol like globalBase? i.e. do we want fast access to it without a load?

lld/wasm/Writer.cpp
221

Maybe avoid the extra local and just do this 4 lines above. You can also remove the now redundant log("mem: stack base = " + Twine(memoryPtr)); line?

Does this need to be wasm global? Or can it just be regular data symbol like globalBase? i.e. do we want fast access to it without a load?

I made it a global because I was thinking about multiple threads, where each thread has its own stack. But that's true, we could do a data symbol in the single-threaded case. I'll look into that.

I think if you want it to be visible as a C symbol, with an address etc, then it would need to be data symbol. It can be TLS for multi-threading I guess?

Sorry, I have somehow forgotten about this change when I created https://reviews.llvm.org/D135910.

I'm not sure if something like this also needed? Unlike the two variables I created this global is thread local which means it could be more useful in mutli-thread environments. In emscripten we currently inject a (TLS) wasm global to aid with stack checking: https://github.com/emscripten-core/emscripten/blob/af961ad5c4c278ec510f0b7f7d522a95ee5a90f8/system/lib/compiler-rt/stack_limits.S#L21-L24.. but I suppose having the linker so it could also make sense.

Do you think this change is still useful and/or better than https://reviews.llvm.org/D135910?

Herald added a project: Restricted Project. · View Herald TranscriptOct 13 2022, 2:57 PM
sunfish abandoned this revision.Oct 14 2022, 8:08 AM

Do you think this change is still useful and/or better than https://reviews.llvm.org/D135910?

I agree that D135910 is the better approach here.