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

New-style command support. #203

Merged
merged 1 commit into from
Oct 3, 2020
Merged

New-style command support. #203

merged 1 commit into from
Oct 3, 2020

Conversation

sunfishcode
Copy link
Member

This enables new-style command support. Instead of calling
__wasm_call_ctors and __wasm_call_dtors directly, this lets
wasm-ld automatically call them.

And, this comments out a use of "protected" visibility, since
WebAssembly doesn't support it.

sunfishcode added a commit to sunfishcode/WASI that referenced this pull request Jun 11, 2020
The core idea of new-style commands is that all function exports are
command entrypoints, and they expect to be called on a fresh instance
which lives only for the direction of the call.

This is a generalization of the existing `_start` convention, which
already has the expectation of a fresh instance  which lives only for
the direction of the call, and is one of the pieces need to enable
user-defined command entrypoints which don't take string arguments and
don't return an i32 status code.

To show how this works in practice, the following patches implement
this new behavior in wasm-ld and wasi-libc:
 - https://reviews.llvm.org/D81689
 - WebAssembly/wasi-libc#203
libc-top-half/musl/src/internal/stdio_impl.h Outdated Show resolved Hide resolved
libc-bottom-half/crt/crt1.c Outdated Show resolved Hide resolved
@sunfishcode
Copy link
Member Author

This currently depends on wasm-ld having https://reviews.llvm.org/D81689 in it. Since we're just now dropping support for LLVM 8.0, we'll need to think more about how to manage compatibility here.

@sbc100
Copy link
Member

sbc100 commented Aug 5, 2020

Should we tag/branch for each major llvm release that we support?

@sunfishcode
Copy link
Member Author

Branch/tag sounds difficult if these live a long time and we end up having to backport patches to all the branches.

I'm thinking about moving the crt1.c in this PR to crt1-command.c, and restoring the previous crt1.c, so that one libc can support both old and new styles -- the compiler driver would be able to pick which one it wants. I'll investigate this in more detail after https://reviews.llvm.org/D81689 lands.

This adds a new crt1-command.c startup file, which uses
[new-style command support]. Instead of calling `__wasm_call_ctors`
and `__wasm_call_dtors` directly, this lets wasm-ld automatically call
them.

This preserves the existing crt1.c, so that the same wasi-libc build
can support old-style and new-style commands, for compatibility during
the transition.

[new-style command support]: https://reviews.llvm.org/D81689
@sunfishcode
Copy link
Member Author

https://reviews.llvm.org/D81689 has now landed, and I've now made the change to preserve the existing crt1.c and move the new one into crt1-command.c so that one WASI libc build can support both modes, to avoid the need to depend on the LLVM version.

@sunfishcode sunfishcode merged commit 614d783 into master Oct 3, 2020
@sunfishcode sunfishcode deleted the new-style-commands branch October 3, 2020 21:18
@@ -276,6 +276,7 @@ _exit
_flushlbf
_initialize
_start
_start
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does _start appear twice now?

Copy link
Member Author

@sunfishcode sunfishcode Dec 29, 2020

Choose a reason for hiding this comment

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

It's defined in crt1.o and crt1-reactor.o. Programs will only use one or the other, but the script which generates defined-symbols.txt doesn't know that.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 9, 2021
This switches Rust's WASI target to use crt1-command.o instead of
crt1.o, which enables support for new-style commands. By default,
new-style commands work the same way as old-style commands, so nothing
immediately changes here, but this will be needed by later changes to
enable support for typed arguments.

See here for more information on new-style commands:
 - WebAssembly/wasi-libc#203
 - https://reviews.llvm.org/D81689
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 9, 2021
…chton

WASI: Switch to crt1-command.o to enable support for new-style commands

This switches Rust's WASI target to use crt1-command.o instead of
crt1.o, which enables support for new-style commands. By default,
new-style commands work the same way as old-style commands, so nothing
immediately changes here, but this will be needed by later changes to
enable support for typed arguments.

See here for more information on new-style commands:
 - WebAssembly/wasi-libc#203
 - https://reviews.llvm.org/D81689

r? `@alexcrichton`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 9, 2021
…chton

WASI: Switch to crt1-command.o to enable support for new-style commands

This switches Rust's WASI target to use crt1-command.o instead of
crt1.o, which enables support for new-style commands. By default,
new-style commands work the same way as old-style commands, so nothing
immediately changes here, but this will be needed by later changes to
enable support for typed arguments.

See here for more information on new-style commands:
 - WebAssembly/wasi-libc#203
 - https://reviews.llvm.org/D81689

r? ``@alexcrichton``
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 10, 2021
…chton

WASI: Switch to crt1-command.o to enable support for new-style commands

This switches Rust's WASI target to use crt1-command.o instead of
crt1.o, which enables support for new-style commands. By default,
new-style commands work the same way as old-style commands, so nothing
immediately changes here, but this will be needed by later changes to
enable support for typed arguments.

See here for more information on new-style commands:
 - WebAssembly/wasi-libc#203
 - https://reviews.llvm.org/D81689

r? ```@alexcrichton```
sunfishcode added a commit to sunfishcode/WASI that referenced this pull request Mar 17, 2022
The core idea of new-style commands is that all function exports are
command entrypoints, and they expect to be called on a fresh instance
which lives only for the direction of the call.

This is a generalization of the existing `_start` convention, which
already has the expectation of a fresh instance  which lives only for
the direction of the call, and is one of the pieces need to enable
user-defined command entrypoints which don't take string arguments and
don't return an i32 status code.

To show how this works in practice, the following patches implement
this new behavior in wasm-ld and wasi-libc:
 - https://reviews.llvm.org/D81689
 - WebAssembly/wasi-libc#203
sunfishcode added a commit to WebAssembly/WASI that referenced this pull request Mar 17, 2022
The core idea of new-style commands is that all function exports are
command entrypoints, and they expect to be called on a fresh instance
which lives only for the direction of the call.

This is a generalization of the existing `_start` convention, which
already has the expectation of a fresh instance  which lives only for
the direction of the call, and is one of the pieces need to enable
user-defined command entrypoints which don't take string arguments and
don't return an i32 status code.

To show how this works in practice, the following patches implement
this new behavior in wasm-ld and wasi-libc:
 - https://reviews.llvm.org/D81689
 - WebAssembly/wasi-libc#203
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants