-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Test linking and running no_std
binaries
#138904
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
Conversation
tests/ui/no_std/simple-runs.rs
Outdated
// Need to link libSystem on Apple platforms, otherwise the linker fails with: | ||
// > ld: dynamic executables or dylibs must link with libSystem.dylib | ||
// | ||
// With the new linker introduced in Xcode 15, the error is instead: | ||
// > Undefined symbols: "dyld_stub_binder", referenced from: <initial-undefines> | ||
// | ||
// This _can_ be worked around by raising the deployment target with | ||
// MACOSX_DEPLOYMENT_TARGET=13.0, though it's a bit hard to test that while | ||
// still allowing the test suite to support running with older Xcode versions. | ||
#[cfg_attr(target_vendor = "apple", link(name = "System"))] | ||
extern "C" {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could just always link libSystem
internally in rustc
, but I'm not sure that's a good idea, since as noted, it is possible to create a fully no_std
binary that doesn't link libSystem
, it just requires the user to do some work.
Maybe better would be to document the limitation somewhere (where?)? Note that libc
does the linking internally too (linking to libc.dylib
also links to libSystem.dylib
), so any code that does #![no_std]
but uses libc
works without this.
For completeness, there is https://github.com./rust-lang/rust/blob/master/tests/run-make/thumb-none-qemu/example/src/main.rs so it's not completely untested, but coverage on more platforms is good of course. |
|
||
//@ run-pass | ||
//@ compile-flags: -Cpanic=abort | ||
//@ ignore-wasm different `main` convention |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure if we need to add more to the ignores here? Is something like ignore-embedded
a thing, and would it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing run-pass
already omits platforms that can't run standalone executables, cc @jieyouxu for a better answer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See
rust/src/tools/compiletest/src/runtest.rs
Line 986 in 4fd8c04
let proc_res = match &*self.config.target { |
run-pass
intentionally does not try to be "smart" and omit platforms that can't run standalone executables. Generally tests will need //@ ignore-cross-compile
if they need to run the test binary (but that only runs on host).
Ah nice. Do you think I should try to merge this test with that? |
This comment has been minimized.
This comment has been minimized.
I don't think so, that test is very specifically for checking that the embedded ecosystem continues to work. It uses qemu to run on a simulated microcontroller. So instead additionally having this test for many more platforms in the ui tests seems independently useful. |
e74978d
to
f9770e7
Compare
|
||
// # Linux | ||
// | ||
// Linking `libc` is required by crt1.o, otherwise the linker fails with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be fun to have a _start
lib-less linux binary as well
To have a @bors try Maybe it's worth adding a second test that links nothing, like Nora's suggestion? I'm not sure that is possible on MacOS but it is probably more interesting on Linux. |
Test linking and running `no_std` binaries I looked around, but it seems that we do not have a test that tests a `#![no_std]` + `#![no_main]` binary. So now I've added one. Motivated by discussion in [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Provide.20.60__isPlatformVersionAtLeast.60.20in.20.60std.60.3F/with/507870028). r? `@tgross35` I haven't tested on Windows, so: try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 And only tested lightly on Linux, so: try-job: x86_64-linux try-job: test-various
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@tgross35 if you're using C |
@bors try |
Test linking and running `no_std` binaries I looked around, but it seems that we do not have a test that tests a `#![no_std]` + `#![no_main]` binary. So now I've added one. Motivated by discussion in [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Provide.20.60__isPlatformVersionAtLeast.60.20in.20.60std.60.3F/with/507870028). r? `@tgross35` I haven't tested on Windows, so: try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 And only tested lightly on Linux, so: try-job: x86_64-gnu try-job: test-various
☀️ Try build successful - checks-actions |
LGTM but may as well try a couple of the more exotic targets before putting this into the queue. r=me with a pass. @bors try |
Test linking and running `no_std` binaries I looked around, but it seems that we do not have a test that tests a `#![no_std]` + `#![no_main]` binary. So now I've added one. Motivated by discussion in [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Provide.20.60__isPlatformVersionAtLeast.60.20in.20.60std.60.3F/with/507870028). r? `@tgross35` try-job: arm-android try-job: armhf-gnu try-job: dist-ohos try-job: x86_64-mingw-1
💥 Test timed out |
@bors try |
Test linking and running `no_std` binaries I looked around, but it seems that we do not have a test that tests a `#![no_std]` + `#![no_main]` binary. So now I've added one. Motivated by discussion in [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Provide.20.60__isPlatformVersionAtLeast.60.20in.20.60std.60.3F/with/507870028). r? `@tgross35` try-job: arm-android try-job: armhf-gnu try-job: dist-ohos try-job: x86_64-mingw-1
☀️ Try build successful - checks-actions |
@bors r+ |
Test linking and running `no_std` binaries I looked around, but it seems that we do not have a test that tests a `#![no_std]` + `#![no_main]` binary. So now I've added one. Motivated by discussion in [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Provide.20.60__isPlatformVersionAtLeast.60.20in.20.60std.60.3F/with/507870028). r? `@tgross35` try-job: arm-android try-job: armhf-gnu try-job: dist-ohos try-job: x86_64-mingw-1
Rollup of 18 pull requests Successful merges: - rust-lang#137412 (Ensure `swap_nonoverlapping` is really always untyped) - rust-lang#138167 (Small code improvement in rustdoc hidden stripper) - rust-lang#138605 (Clean up librustdoc::html::render to be better encapsulated) - rust-lang#138682 (Allow drivers to supply a list of extra symbols to intern) - rust-lang#138904 (Test linking and running `no_std` binaries) - rust-lang#139423 (Suppress missing field error when autoderef bottoms out in infer) - rust-lang#139449 (match ergonomics: replace `peel_off_references` with a recursive call) - rust-lang#139507 (compiletest: Trim whitespace from environment variable names) - rust-lang#139530 (Remove some dead or leftover code related to rustc-intrinsic abi removal) - rust-lang#139560 (fix title of offset_of_enum feature) - rust-lang#139563 (emit a better error message for using the macro incorrectly) - rust-lang#139568 (Don't use empty trait names) - rust-lang#139580 (Temporarily leave the review rotation) - rust-lang#139589 (saethlin is back from vacation) - rust-lang#139592 (rustdoc: Enable Markdown extensions when looking for doctests) - rust-lang#139599 (Tracking issue template: fine-grained information on style update status) - rust-lang#139600 (Update `compiler-builtins` to 0.1.153) - rust-lang#139606 (Update compiletest to Edition 2024) r? `@ghost` `@rustbot` modify labels: rollup
Test linking and running `no_std` binaries I looked around, but it seems that we do not have a test that tests a `#![no_std]` + `#![no_main]` binary. So now I've added one. Motivated by discussion in [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Provide.20.60__isPlatformVersionAtLeast.60.20in.20.60std.60.3F/with/507870028). r? ``@tgross35`` try-job: arm-android try-job: armhf-gnu try-job: dist-ohos try-job: x86_64-mingw-1
Rollup of 17 pull requests Successful merges: - rust-lang#137412 (Ensure `swap_nonoverlapping` is really always untyped) - rust-lang#138167 (Small code improvement in rustdoc hidden stripper) - rust-lang#138605 (Clean up librustdoc::html::render to be better encapsulated) - rust-lang#138682 (Allow drivers to supply a list of extra symbols to intern) - rust-lang#138904 (Test linking and running `no_std` binaries) - rust-lang#139423 (Suppress missing field error when autoderef bottoms out in infer) - rust-lang#139449 (match ergonomics: replace `peel_off_references` with a recursive call) - rust-lang#139507 (compiletest: Trim whitespace from environment variable names) - rust-lang#139530 (Remove some dead or leftover code related to rustc-intrinsic abi removal) - rust-lang#139560 (fix title of offset_of_enum feature) - rust-lang#139563 (emit a better error message for using the macro incorrectly) - rust-lang#139568 (Don't use empty trait names) - rust-lang#139580 (Temporarily leave the review rotation) - rust-lang#139589 (saethlin is back from vacation) - rust-lang#139592 (rustdoc: Enable Markdown extensions when looking for doctests) - rust-lang#139599 (Tracking issue template: fine-grained information on style update status) - rust-lang#139600 (Update `compiler-builtins` to 0.1.153) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 12 pull requests Successful merges: - rust-lang#137447 (add `core::intrinsics::simd::{simd_extract_dyn, simd_insert_dyn}`) - rust-lang#138182 (rustc_target: update x86_win64 to match the documented calling convention for f128) - rust-lang#138682 (Allow drivers to supply a list of extra symbols to intern) - rust-lang#138904 (Test linking and running `no_std` binaries) - rust-lang#138998 (Don't suggest the use of `impl Trait` in closure parameter) - rust-lang#139447 (doc changes: debug assertions -> overflow checks) - rust-lang#139469 (Introduce a `//@ needs-crate-type` compiletest directive) - rust-lang#139564 (Deeply normalize obligations in `BestObligation` folder) - rust-lang#139574 (bootstrap: improve `channel` handling) - rust-lang#139600 (Update `compiler-builtins` to 0.1.153) - rust-lang#139641 (Allow parenthesis around inferred array lengths) - rust-lang#139654 (Improve `AssocItem::descr`.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#138904 - madsmtm:apple-test-no-std, r=tgross35 Test linking and running `no_std` binaries I looked around, but it seems that we do not have a test that tests a `#![no_std]` + `#![no_main]` binary. So now I've added one. Motivated by discussion in [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Provide.20.60__isPlatformVersionAtLeast.60.20in.20.60std.60.3F/with/507870028). r? ```@tgross35``` try-job: arm-android try-job: armhf-gnu try-job: dist-ohos try-job: x86_64-mingw-1
I looked around, but it seems that we do not have a test that tests a
#![no_std]
+#![no_main]
binary. So now I've added one. Motivated by discussion in this Zulip thread.r? @tgross35
try-job: arm-android
try-job: armhf-gnu
try-job: dist-ohos
try-job: x86_64-mingw-1