-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Test linking and running no_std
binaries
#138904
base: master
Are you sure you want to change the base?
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?
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
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
I haven't tested on Windows, so:
try-run: dist-x86_64-msvc
And only tested lightly on Linux, so:
try-run: dist-x86_64-linux