Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

docs: add documentation and example of using stack maps for GC#11710

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
maxnatamo wants to merge3 commits intobytecodealliance:main
base:main
Choose a base branch
Loading
frommaxnatamo:docs/add-additional-stackmap-documentation

Conversation

@maxnatamo
Copy link
Contributor

  • Adds a documentation entry for how stack maps might be used to implement a garbage collector.
  • Adds an example project which shows off how a simple garbage collector might actually be implemented. Currently only supportsx64 andaarch64 (only tested onaarch64 macOS). The code might be slightly overdone, but it was also copied from a side-project.

This was originallydiscussed on Zulip.

@maxnatamomaxnatamo requested a review froma team as acode ownerSeptember 18, 2025 20:04
@maxnatamomaxnatamo requested review fromabrown and removed request fora teamSeptember 18, 2025 20:04
@github-actionsgithub-actionsbot added craneliftIssues related to the Cranelift code generator cranelift:docs labelsSep 18, 2025
@abrownabrown requested review fromfitzgen and removed request forabrownSeptember 19, 2025 18:10
@abrown
Copy link
Member

cc:@fitzgen, you probably have more context here?

@maxnatamo
Copy link
ContributorAuthor

maxnatamo commentedSep 19, 2025
edited
Loading

There seems to be an issue with getting the correct return addresses when walking the stack on x64 Linux.

From what I gather, it's because Rust and/or LLVM doesn't use frame pointers the same way on some targets. It can be fixed by forcing frame pointers using-Cforce-frame-pointers, but I hope there is a better solution.

@cfallin
Copy link
Member

There seems to be an issue with getting the correct return addresses when walking the stack on x64 Linux.

From what I gather, it's because Rust and/or LLVM doesn't use frame pointers the same way on some targets. It can be fixed by forcing frame pointers using-Cforce-frame-pointers, but I hope there is a better solution.

I gather you're building your own runtime, but to offer parallel wisdom from Wasmtime, we know that we can only trust any invariants about the code that we ourselves generate with Cranelift; so we record entry and exit FPs for an "activation" of Wasm (call into Wasm from host, call from Wasm back out to host) and only walk the FP chain in that range. In general, when interacting with code produced by other compilers you need to follow their ABI (which in general on Linux means no frame pointers required, and using DWARF to interpret stack frames and unwind them).

@maxnatamo
Copy link
ContributorAuthor

Is there an "easy" solution which won't pollute the example with stack walking code? Could something like theunwinder crate in Wasmtime function here? I'll admit, this is outside of what I know about stack frames, unwinding, etc.

@cfallin
Copy link
Member

No, Wasmtime's unwinder has nothing to do with native stack frames; it is specific to Wasmtime's metadata format.

You'll probably want to do similar to Wasmtime (and Cranelift'sclif-util test runner) and emit a trampoline that usesget_frame_pointer at both ends of your Cranelift frames (entry and exit), then delimit your walk by those -- this very reason is why we added that intrinsic.

@maxnatamo
Copy link
ContributorAuthor

I've tried implementing something similar to what Wasmtime does, but I'm a little in over my head with this. The new implementation walks frame entries which are pushed and popped from trampolines, but the stack pointer is way off. There might be a simple solution to this, but I might've stared at this code for too long.

@fitzgen
Copy link
Member

Hi@maxnatamo, I don't have time to help debug this example program. In general, I'd suggest simplifying as much as possible, doing nothing else but saving the FP/SP that bookend each activation, make sure that works in isolation, and then slowly add more from there, checking that things look right along the way.

In the meantime, adding the doc comment expansionshere that we talked about on Zulip might be the expeditious option.

@fitzgenfitzgen removed their request for reviewSeptember 23, 2025 16:41
@maxnatamo
Copy link
ContributorAuthor

I can split the documentation entry and example into two separate PRs, if that helps. Then if I can't get the example working, the documentation can still be merged in.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

cranelift:docscraneliftIssues related to the Cranelift code generator

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@maxnatamo@abrown@cfallin@fitzgen

[8]ページ先頭

©2009-2025 Movatter.jp