Skip to content

Commit e74978d

Browse files
committed
Test linking and running no_std binaries
1 parent 4510e86 commit e74978d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/ui/no_std/simple-runs.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
// Need to link libSystem on Apple platforms, otherwise the linker fails with:
14+
// > ld: dynamic executables or dylibs must link with libSystem.dylib
15+
//
16+
// With the new linker introduced in Xcode 15, the error is instead:
17+
// > Undefined symbols: "dyld_stub_binder", referenced from: <initial-undefines>
18+
//
19+
// This _can_ be worked around by raising the deployment target with
20+
// MACOSX_DEPLOYMENT_TARGET=13.0, though it's a bit hard to test that while
21+
// still allowing the test suite to support running with older Xcode versions.
22+
#[cfg_attr(target_vendor = "apple", link(name = "System"))]
23+
extern "C" {}
24+
25+
#[panic_handler]
26+
fn panic_handler(_info: &PanicInfo<'_>) -> ! {
27+
loop {}
28+
}
29+
30+
#[no_mangle]
31+
extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int {
32+
0
33+
}

0 commit comments

Comments
 (0)