Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions compiler/rustc_target/src/spec/crt_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
//!
//! | Pre-link CRT objects | glibc | musl | bionic | mingw | wasi |
//! |----------------------|------------------------|------------------------|------------------|-------------------|--------------|
//! | dynamic-nopic-exe | crt1, crti, crtbegin | crt1, crti, crtbegin | crtbegin_dynamic | crt2, crtbegin | crt1 |
//! | dynamic-pic-exe | Scrt1, crti, crtbeginS | Scrt1, crti, crtbeginS | crtbegin_dynamic | crt2, crtbegin | crt1 |
//! | static-nopic-exe | crt1, crti, crtbeginT | crt1, crti, crtbegin | crtbegin_static | crt2, crtbegin | crt1 |
//! | static-pic-exe | rcrt1, crti, crtbeginS | rcrt1, crti, crtbeginS | crtbegin_dynamic | crt2, crtbegin | crt1 |
//! | dynamic-dylib | crti, crtbeginS | crti, crtbeginS | crtbegin_so | dllcrt2, crtbegin | - |
//! | static-dylib (gcc) | crti, crtbeginT | crti, crtbeginS | crtbegin_so | dllcrt2, crtbegin | - |
//! | static-dylib (clang) | crti, crtbeginT | N/A | crtbegin_static | dllcrt2, crtbegin | - |
//! | dynamic-nopic-exe | crt1, crti, crtbegin | crt1, crti, crtbegin | crtbegin_dynamic | crt2, crtbegin | crt1-command |
//! | dynamic-pic-exe | Scrt1, crti, crtbeginS | Scrt1, crti, crtbeginS | crtbegin_dynamic | crt2, crtbegin | crt1-command |
//! | static-nopic-exe | crt1, crti, crtbeginT | crt1, crti, crtbegin | crtbegin_static | crt2, crtbegin | crt1-command |
//! | static-pic-exe | rcrt1, crti, crtbeginS | rcrt1, crti, crtbeginS | crtbegin_dynamic | crt2, crtbegin | crt1-command |
//! | dynamic-dylib | crti, crtbeginS | crti, crtbeginS | crtbegin_so | dllcrt2, crtbegin | crt1-reactor |
//! | static-dylib (gcc) | crti, crtbeginT | crti, crtbeginS | crtbegin_so | dllcrt2, crtbegin | crt1-reactor |
//! | static-dylib (clang) | crti, crtbeginT | N/A | crtbegin_static | dllcrt2, crtbegin | ctr1-reactor |
//! | wasi-reactor-exe | N/A | N/A | N/A | N/A | crt1-reactor |
//!
//! | Post-link CRT objects | glibc | musl | bionic | mingw | wasi |
Expand Down Expand Up @@ -127,6 +127,8 @@ pub(super) fn pre_wasi_self_contained() -> CrtObjects {
(LinkOutputKind::StaticNoPicExe, &["crt1-command.o"]),
(LinkOutputKind::StaticPicExe, &["crt1-command.o"]),
(LinkOutputKind::WasiReactorExe, &["crt1-reactor.o"]),

@bjorn3 bjorn3 Aug 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we still need the separate flag to enable usage of crt1-reactor.o?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't recall the history here myself, but I suspect not, no.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cc #108097 That PR also changed from --no-entry to --entry _initialize, though not just on wasi, but all wasm targets.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd like to only handle WASI targets here, not all targets. That PR also never landed I believe? The goal of this change is to handle ABI details for the upcoming wasip3 target which is broken without linking these files.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like to only handle WASI targets here, not all targets.

I'm aware.

That PR also never landed I believe?

Indeed. I was looking at why it never landed. I think because it was also touching other targets.

Wouldn't this PR also need to copy the --no-entry -> --entry _initialize change from that PR, but just for wasi? And maybe copy the table doc table change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, I've updated the table. I don't believe the --no-entry change is necessary -- with this PR _initialize is still exported works as intended.

(LinkOutputKind::DynamicDylib, &["crt1-reactor.o"]),
(LinkOutputKind::StaticDylib, &["crt1-reactor.o"]),
])
}

Expand Down
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/external_deps/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ impl Rustc {
self
}

/// Specify `-C link-self-contained={y,n}`.
pub fn link_self_contained(&mut self, enabled: &str) -> &mut Self {
self.cmd.arg(format!("-Clink-self-contained={enabled}"));
self
}

pub fn split_dwarf_out_dir(&mut self, out_dir: Option<&str>) -> &mut Self {
if let Some(out_dir) = out_dir {
self.cmd.arg(format!("-Zsplit-dwarf-out-dir={out_dir}"));
Expand Down
5 changes: 4 additions & 1 deletion tests/run-make/wasm-export-all-symbols/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ fn test(args: &[&str]) {
rustc().input("foo.rs").target("wasm32-wasip1").args(args).run();
rustc().input("main.rs").target("wasm32-wasip1").args(args).run();

verify_exports(Path::new("foo.wasm"), &[("foo", Func), ("FOO", Global), ("memory", Memory)]);
verify_exports(
Path::new("foo.wasm"),
&[("foo", Func), ("FOO", Global), ("memory", Memory), ("_initialize", Func)],
);
verify_exports(
Path::new("main.wasm"),
&[
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/wasm-symbols-not-exported/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn verify_symbols(path: &Path) {
if e.kind != wasmparser::ExternalKind::Func {
continue;
}
if e.name == "foo" {
if e.name == "foo" || e.name == "_initialize" {
continue;
}
panic!("unexpected export {e:?}");
Expand Down
1 change: 1 addition & 0 deletions tests/run-make/wasm-unexpected-features/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn main() {
.linker_plugin_lto("on")
.link_arg("--import-memory")
.extern_("minicore", path("libminicore.rlib"))
.link_self_contained("n")
.run();
verify_features(Path::new("foo.wasm"));
}
Expand Down
Loading