Skip to content

Commit ea09b7d

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35663 - CryZe:no-stdlib, r=Manishearth
Improve `No stdlib` and related Documentation This renames all lang item function names to the ones used in `libstd` and `libpanic_unwind`. It also explains the `eh_unwind_resume` lang item in the `libcore` documentation, where it was missing. A third function is also needed on certain compilation targets, so this was also added to the `No stdlib` documentation.
2 parents a9e3cff + e586d21 commit ea09b7d

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/doc/book/lang-items.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ fn main(argc: isize, argv: *const *const u8) -> isize {
5757
0
5858
}
5959
60-
#[lang = "eh_personality"] extern fn eh_personality() {}
61-
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
60+
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
61+
#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { loop {} }
6262
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
6363
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
6464
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
@@ -73,8 +73,8 @@ Other features provided by lang items include:
7373
`==`, `<`, dereferencing (`*`) and `+` (etc.) operators are all
7474
marked with lang items; those specific four are `eq`, `ord`,
7575
`deref`, and `add` respectively.
76-
- stack unwinding and general failure; the `eh_personality`, `fail`
77-
and `fail_bounds_checks` lang items.
76+
- stack unwinding and general failure; the `eh_personality`,
77+
`eh_unwind_resume`, `fail` and `fail_bounds_checks` lang items.
7878
- the traits in `std::marker` used to indicate types of
7979
various kinds; lang items `send`, `sync` and `copy`.
8080
- the marker types and variance indicators found in

src/doc/book/no-stdlib.md

+25-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
5555
// provided by libstd.
5656
#[lang = "eh_personality"]
5757
#[no_mangle]
58-
pub extern fn eh_personality() {
58+
pub extern fn rust_eh_personality() {
59+
}
60+
61+
// This function may be needed based on the compilation target.
62+
#[lang = "eh_unwind_resume"]
63+
#[no_mangle]
64+
pub extern fn rust_eh_unwind_resume() {
5965
}
6066
6167
#[lang = "panic_fmt"]
@@ -87,12 +93,18 @@ pub extern fn main(_argc: i32, _argv: *const *const u8) -> i32 {
8793
0
8894
}
8995
90-
// These functions and traits are used by the compiler, but not
96+
// These functions are used by the compiler, but not
9197
// for a bare-bones hello world. These are normally
9298
// provided by libstd.
9399
#[lang = "eh_personality"]
94100
#[no_mangle]
95-
pub extern fn eh_personality() {
101+
pub extern fn rust_eh_personality() {
102+
}
103+
104+
// This function may be needed based on the compilation target.
105+
#[lang = "eh_unwind_resume"]
106+
#[no_mangle]
107+
pub extern fn rust_eh_unwind_resume() {
96108
}
97109
98110
#[lang = "panic_fmt"]
@@ -104,23 +116,28 @@ pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
104116
}
105117
```
106118

107-
## More about the langauge items
119+
## More about the language items
108120

109121
The compiler currently makes a few assumptions about symbols which are
110122
available in the executable to call. Normally these functions are provided by
111123
the standard library, but without it you must define your own. These symbols
112124
are called "language items", and they each have an internal name, and then a
113125
signature that an implementation must conform to.
114126

115-
The first of these two functions, `eh_personality`, is used by the failure
127+
The first of these functions, `rust_eh_personality`, is used by the failure
116128
mechanisms of the compiler. This is often mapped to GCC's personality function
117129
(see the [libstd implementation][unwind] for more information), but crates
118130
which do not trigger a panic can be assured that this function is never
119-
called. Both the language item and the symbol name are `eh_personality`.
120-
131+
called. The language item's name is `eh_personality`.
132+
121133
[unwind]: https://github.com/rust-lang/rust/blob/master/src/libpanic_unwind/gcc.rs
122134

123-
The second function, `panic_fmt`, is also used by the failure mechanisms of the
135+
The second function, `rust_begin_panic`, is also used by the failure mechanisms of the
124136
compiler. When a panic happens, this controls the message that's displayed on
125137
the screen. While the language item's name is `panic_fmt`, the symbol name is
126138
`rust_begin_panic`.
139+
140+
A third function, `rust_eh_unwind_resume`, is also needed if the `custom_unwind_resume`
141+
flag is set in the options of the compilation target. It allows customizing the
142+
process of resuming unwind at the end of the landing pads. The language item's name
143+
is `eh_unwind_resume`.

src/libcore/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
//! line. It is up to consumers of this core library to define this panic
4343
//! function; it is only required to never return. This requires a `lang`
4444
//! attribute named `panic_fmt`.
45+
//!
46+
//! * `rust_eh_personality` - is used by the failure mechanisms of the
47+
//! compiler. This is often mapped to GCC's personality function, but crates
48+
//! which do not trigger a panic can be assured that this function is never
49+
//! called. The `lang` attribute is called `eh_personality`.
4550
4651
// Since libcore defines many fundamental lang items, all tests live in a
4752
// separate crate, libcoretest, to avoid bizarre issues.

0 commit comments

Comments
 (0)