Test linking and running no_std binaries
This commit is contained in:
parent
4510e86a41
commit
f9770e742a
1 changed files with 41 additions and 0 deletions
41
tests/ui/no_std/simple-runs.rs
Normal file
41
tests/ui/no_std/simple-runs.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
//! Check that `no_std` binaries can link and run without depending on `libstd`.
|
||||
|
||||
//@ run-pass
|
||||
//@ compile-flags: -Cpanic=abort
|
||||
//@ ignore-wasm different `main` convention
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::ffi::{c_char, c_int};
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
// # Linux
|
||||
//
|
||||
// Linking `libc` is required by crt1.o, otherwise the linker fails with:
|
||||
// > /usr/bin/ld: in function `_start': undefined reference to `__libc_start_main'
|
||||
//
|
||||
// # Apple
|
||||
//
|
||||
// Linking `libSystem` is required, 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(all(not(target_vendor = "apple"), unix), link(name = "c"))]
|
||||
#[cfg_attr(target_vendor = "apple", link(name = "System"))]
|
||||
extern "C" {}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic_handler(_info: &PanicInfo<'_>) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int {
|
||||
0
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue