Skip to content

tests: check wasm compiler_builtins object architecture#156230

Open
Vastargazing wants to merge 1 commit into
rust-lang:mainfrom
Vastargazing:tests/wasm-compiler-builtins-object-arch
Open

tests: check wasm compiler_builtins object architecture#156230
Vastargazing wants to merge 1 commit into
rust-lang:mainfrom
Vastargazing:tests/wasm-compiler-builtins-object-arch

Conversation

@Vastargazing
Copy link
Copy Markdown
Contributor

@Vastargazing Vastargazing commented May 6, 2026

See #132802

This adds a run-make test for the wasm sysroot regression fixed in #137457

The test checks that the .o members in the prebuilt
libcompiler_builtins rlib for wasm32-wasip1 are wasm objects rather than
host ELF objects. Before that fix, bootstrap could use the host C compiler for
compiler-rt fallbacks on wasm targets and end up embedding host objects into
the wasm sysroot.

I used wasm32-wasip1 because that's the wasm target covered by the existing
tests/run-make CI setup, and the test asserts that it actually saw .o
members in the archive.

Closes: #132802

r? @tgross35

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 6, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 6, 2026

tgross35 is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@Vastargazing Vastargazing force-pushed the tests/wasm-compiler-builtins-object-arch branch from 211904e to b25f8a1 Compare May 6, 2026 11:17
Copy link
Copy Markdown
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Thank you for picking this up!

View changes since this review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a doc comment explaining what this does, and linking back to the issue

Comment on lines +22 to +24
if !name.ends_with(".o") {
continue;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is only skipping rmeta right? Flip this around to name.ends_with(".rmeta") so we find if there's something weird.

Comment on lines +39 to +40
C objects were expected on this configuration; \
test may be running without compiler-builtins-c enabled"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this comment isn't exactly accurate, there should be object files in the archive regardless of whether or not the C implementations are used.

Comment on lines +26 to +32
assert!(
obj_data.starts_with(b"\0asm"),
"object file `{name}` in compiler_builtins rlib is not a wasm binary \
(first bytes: {:02x?}); C compiler-rt fallbacks were built with the wrong \
toolchain — see rust-lang/rust#132802",
&obj_data[..4.min(obj_data.len())]
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reading into an object::File then checking .architecture() would probably be better here

@@ -0,0 +1,43 @@
//@ only-wasm32-wasip1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can this be changed to only-wasm? It might not be in CI but anyone running locally for the other targets should get it covered

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 18, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Vastargazing Vastargazing force-pushed the tests/wasm-compiler-builtins-object-arch branch from b25f8a1 to 962838f Compare May 21, 2026 04:42
@Vastargazing
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I've just force-pushed the fixes to the branch.

Addresssed everything we discussed: added the module-level docs with links, and broadened the directive to only-wasm to cover other targets. I also flipped the filter to skip only .rmeta so unexpected files will actually trigger a failure now.

For the wasm check, i dropped the raw magic bytes and went with object::File::parse + matching on Wasm32/Wasm64. Also cleaned up the misleading assert message about compiler-builtins-c and dropped the trailing eprintln!.

Let me know what you think!

@rust-log-analyzer

This comment has been minimized.

Add a run-make test that checks the `.o` members in the prebuilt
`libcompiler_builtins` archive for `wasm32-wasip1` are wasm objects.

This guards against building wasm compiler-rt fallbacks with the host C
toolchain.
@Vastargazing Vastargazing force-pushed the tests/wasm-compiler-builtins-object-arch branch from 962838f to 50ad258 Compare May 21, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Official binaries for wasm32-unknown-unknown (and potentially other WASM platforms?) contain code for the wrong architecture

4 participants