Clarify OS-specific entry points (#516)

Closes #515 
Closes #514
This commit is contained in:
Philipp Oppermann
2019-01-03 17:27:21 +01:00
committed by GitHub
parent 0554c5c5fb
commit 5a90015dc7

View File

@@ -316,16 +316,22 @@ use core::panic::PanicInfo;
fn panic(_info: &PanicInfo) -> ! { fn panic(_info: &PanicInfo) -> ! {
loop {} loop {}
} }
```
// On Linux: The entry point definition depends on the target operating system. For Linux it looks like this:
```rust
#[no_mangle] // don't mangle the name of this function #[no_mangle] // don't mangle the name of this function
pub extern "C" fn _start() -> ! { pub extern "C" fn _start() -> ! {
// this function is the entry point, since the linker looks for a function // this function is the entry point, since the linker looks for a function
// named `_start` by default // named `_start` by default
loop {} loop {}
} }
```
// On Windows: For Windows like this:
```rust
#[no_mangle] #[no_mangle]
pub extern "C" fn mainCRTStartup() -> ! { pub extern "C" fn mainCRTStartup() -> ! {
main(); main();
@@ -335,16 +341,18 @@ pub extern "C" fn mainCRTStartup() -> ! {
pub extern "C" fn main() -> ! { pub extern "C" fn main() -> ! {
loop {} loop {}
} }
```
// On macOS: And for macOS like this:
```rust
#[no_mangle] #[no_mangle]
pub extern "C" fn main() -> ! { pub extern "C" fn main() -> ! {
loop {} loop {}
} }
``` ```
`Cargo.toml`: The `Cargo.toml` is independent of the operating system and looks like this:
```toml ```toml
[package] [package]
@@ -361,7 +369,7 @@ panic = "abort" # disable stack unwinding on panic
panic = "abort" # disable stack unwinding on panic panic = "abort" # disable stack unwinding on panic
``` ```
It can be compiled with: The binary can be compiled with:
```bash ```bash
# Linux # Linux