Skip to content

[BUG][WASM] Since lld made --stack-first default, most of the WASM examples will put the stack into reserved space #2880

@Taywee

Description

@Taywee

For context, look at llvm#151015 and its PR, llvm#166998.

Without --stack-first, the stack is put after the data segment, so you can use --global-base=98304 to set up the WASM memory to be

  • 0x00000-0x18000: TIC-80 reserved
  • 0x18000: data segment starts (global_base)
  • data_end: stack starts
  • stack_end: heap starts

But now that --stack-first is the default, newer versions of lld's WASM linker will set up (with an 8K stack):

  • 0x00000-0x02000: stack range
  • 0x18000: data segment starts (global_base)
  • data_end: heap starts

There doesn't seem to be a good way to control this. The Rust template actually has a functional workaround (though it should also have --stack-first to be safe, I think it could misbehave otherwise, sticking the data segment in VRAM). With this one, you set stack first, and set your stack size to 96K + whatever you want your actual stack size to be. The zig template, nim template, and c template all look like they depend on --global-base and non-stack-first behavior. The d template does use --stack-first, but it looks like it gives it a default stack size of 1MiB, so I'm not sure how that one would have worked at all.

Ideally, this would be solved with something like --stack-base or --memory-base to allow the first 96K of memory to be reserved, but that option doesn't exist in lld yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions