Skip to content

Commit b4c6991

Browse files
authored
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
2 parents 3990e5d + f9770e7 commit b4c6991

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/ui/no_std/simple-runs.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//! Check that `no_std` binaries can link and run without depending on `libstd`.
2+
3+
//@ run-pass
4+
//@ compile-flags: -Cpanic=abort
5+
//@ ignore-wasm different `main` convention
6+
7+
#![no_std]
8+
#![no_main]
9+
10+
use core::ffi::{c_char, c_int};
11+
use core::panic::PanicInfo;
12+
13+
// # Linux
14+
//
15+
// Linking `libc` is required by crt1.o, otherwise the linker fails with:
16+
// > /usr/bin/ld: in function `_start': undefined reference to `__libc_start_main'
17+
//
18+
// # Apple
19+
//
20+
// Linking `libSystem` is required, otherwise the linker fails with:
21+
// > ld: dynamic executables or dylibs must link with libSystem.dylib
22+
//
23+
// With the new linker introduced in Xcode 15, the error is instead:
24+
// > Undefined symbols: "dyld_stub_binder", referenced from: <initial-undefines>
25+
//
26+
// This _can_ be worked around by raising the deployment target with
27+
// MACOSX_DEPLOYMENT_TARGET=13.0, though it's a bit hard to test that while
28+
// still allowing the test suite to support running with older Xcode versions.
29+
#[cfg_attr(all(not(target_vendor = "apple"), unix), link(name = "c"))]
30+
#[cfg_attr(target_vendor = "apple", link(name = "System"))]
31+
extern "C" {}
32+
33+
#[panic_handler]
34+
fn panic_handler(_info: &PanicInfo<'_>) -> ! {
35+
loop {}
36+
}
37+
38+
#[no_mangle]
39+
extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int {
40+
0
41+
}

0 commit comments

Comments
 (0)