This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments