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

feat: Wasm Linux support wasm32-wali #4244

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

arjunr2
Copy link

@arjunr2 arjunr2 commented Jan 16, 2025

Description

Retargetting support to main (from #3778) for wasm32-wali according to MCP rust-lang/compiler-team#797

Sources

WALI documentation: https://github.com/arjunr2/WALI

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot
Copy link
Collaborator

rustbot commented Jan 16, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @tgross35 (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

// * Architecture-specific features
// * Dynamic linking (until Wasm gains support)
// Currently only supports the 'musl' environment
fn test_wasm32_linux(target: &str) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is most of this copied from test_linux? If so, it would just make more sense to configure wali using that same function instead of duplicating.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of it is configured using test_linux, I can use the same function. Although if it's currently only Tier-3, we could maybe hold-off on libc-test support until a later point in time. I feel like the latter makes more sense to me at the moment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay to add testing and think it's probably a good idea if more API is planned, but that is up to you as the target maintainer. Reasonably small changes in test_linux are just preferable over having the same config in two places.

Comment on lines +4 to +5
#![feature(c_variadic)]
#![feature(concat_idents)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for experimentation, correct? Will need to be removed before merge.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not be necessary if we remove the syscall shims.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as in #3778, why is there a b64 module when the arch is wasm32?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please make sure the unneeded comments are cleaned up once this is ready.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in #3778, please drop the syscall shims

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syscall shims are rather integral to portability of many applications. What is the best direction forward to get that into the ecosystem?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part I am missing is, why doesn't wali just add a varidic syscall(long, ...) symbol that we could bind to? If portability is important then this seems relevant beyond Rust's libc, and it would be better to just not have the number->signature mapping responsibility in this repo.

If that doesn't work then I can help rework the macro to not rely on unstable features, and we could probably start by mapping a subset like e.g. whatever std will need.

In any case I think it's easiest to just drop this portion for now, get the rest merged, and then revisit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wali-libc does provide musl's variadic syscall that can be bound too. The problem I encountered though is that most invocations of syscall used by many libraries don't adhere to the exact type signature for some arguments (using i32 instead of i64 for instance). This would not be type-checked by Rust

This causes a unique issue for variadic argument parsing in C. It has not been an issue for hardware ISAs in musl till date since they just pass arguments to registers. However, for Wasm as a virtual ISA target, variadic calls (as per clang compiler today) are supported through arguments packed into a memory buffer -- passing incorrect types will lead to wrong offset parsing.

It is currently unclear what it handle this problem in the compiler, or if it even needs to be done. The easiest reliable fix is to type-cast all arguments accordingly in Rust, which is what the shim provides.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, I'm on board for dropping the shim for the first merge, and we can start by increasing support as you suggested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting; do varidic functions aside from syscall work cross-language, or is that one special? Rust's ... should work with the exact same ABI as C's ... and if not, it is a bug. Shimming to work around an ABI mismatch isn't a great solution.

You should open an issue in rust-lang/rust to investigate further, but if Rust's varidics aren't compatible with C's varidics then that just needs to be fixed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a Rust variadics issue since this also happens when invoking syscall from C. It's an LLVM compiler issue in marshalling variadic arguments and should be fixable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants