Skip to content

Commit 41cbadf

Browse files
committed
Update note about eh_personality
1 parent de8d617 commit 41cbadf

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/custom-target.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ You can pretty much copy that output into your file. Start with a few modificati
5151
- Remove `"is-builtin": true`
5252
- Fill `llvm-target` with [the triple that LLVM expects][llvm-target-triple]
5353
- Decide on a panicking strategy. A bare metal implementation will likely use
54-
`"panic-strategy": "abort"`. If you decide not to `abort` on panicking, even if you [tell Cargo
55-
to][aborting-on-panic], you must define an [eh_personality] function.
54+
`"panic-strategy": "abort"`. If you decide not to `abort` on panicking, unless you [tell Cargo
55+
to][eh_personality], you must define an [eh_personality] function.
5656
- Configure atomics. Pick the first option that describes your target:
5757
- I have a single-core processor, no threads, no interrupts, or any way for multiple things to be
5858
happening in parallel: if you are **sure** that is the case, such as WASM (for now), you may set
@@ -166,6 +166,7 @@ exclude `std` when compiling for bare-metal. To do so, specify the crated you'd
166166
### language item required, but not found: `eh_personality`
167167

168168
Either add `"panic-strategy": "abort"` to your target file, or define an [eh_personality] function.
169+
Alternatively, [tell Cargo to ignore it][eh_personality].
169170

170171
### undefined reference to `__sync_val_compare_and_swap_#`
171172

src/smallest-no-std.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,24 @@ $ cat .cargo/config
108108

109109
## eh_personality
110110

111-
If your [target][custom-target] does not contain `"panic-strategy": "abort"`, which most targets for
112-
full operating systems don't, then you must add an `eh_personality` function, which requires a
113-
nightly compiler. [Here is Rust's documentation about it][more-about-lang-items], and [here is some
114-
discussion about it][til-why-eh-personality]. A simple implementation that does not do anything
115-
special when unwinding is as follows:
111+
If your configuration does not unconditionally abort on panic, which most targets for full operating
112+
systems don't (or if your [custom target][custom-target] does not contain
113+
`"panic-strategy": "abort"`), then you must tell Cargo to do so or add an `eh_personality` function,
114+
which requires a nightly compiler. [Here is Rust's documentation about it][more-about-lang-items],
115+
and [here is some discussion about it][til-why-eh-personality].
116+
117+
In your Cargo.toml, add:
118+
119+
``` toml
120+
[profile.dev]
121+
panic = "abort"
122+
123+
[profile.release]
124+
panic = "abort"
125+
```
126+
127+
Alternatively, declare the `eh_personality` function. A simple implementation that does not do
128+
anything special when unwinding is as follows:
116129

117130
``` rust
118131
#![feature(lang_items)]
@@ -121,6 +134,9 @@ special when unwinding is as follows:
121134
extern "C" fn eh_personality() {}
122135
```
123136

137+
You will receive the error `language item required, but not found: 'eh_personality'` if not
138+
included.
139+
124140
[custom-target]: ./custom-target.md
125141
[more-about-lang-items]:
126142
https://doc.rust-lang.org/unstable-book/language-features/lang-items.html#more-about-the-language-items

0 commit comments

Comments
 (0)