@@ -272,35 +272,39 @@ binary link:
272
272
273
273
Passing ` rlib ` s directly into your foreign linker is currently unsupported.
274
274
275
- ### Prohibited linkage and foreign unwinding
276
-
277
- r[ link.foreign-code.prohibited]
278
-
279
- Undfined behavior may be caused by foreign code unwinding into a Rust crate
280
- with these characteristics:
281
-
282
- * The foreign unwind enters Rust via a function or function pointer declared
283
- with an ABI that permits unwinding, that is, ` "Rust" ` (the default ABI) or
284
- any ` -unwind ` ABI
285
- * The Rust crate containing the ` -unwind ` ABI declaration was compiled with
286
- ` panic=unwind `
287
- * The final binary is linked with [ the ` panic=abort ` runtime] [ panic-runtime ]
288
-
289
- > ** Note** : To protect against this undefined behavior, ` rustc ` does not permit
290
- > linking the ` panic=abort ` runtime against any crate that was compiled with
291
- > ` panic=unwind ` if that crate also contains a call to a foreign function or
292
- > function pointer declared with an ` -unwind ` ABI. Note that this prohibition
293
- > applies even when linking a static or dynamic library that only includes Rust
294
- > code, since the resulting library may be subsequently linked against another
295
- > library that may unwind. However, use of the ` Rust ` (default) ABI does not
296
- > cause a link-error, since that ABI is not expected to be used as an
297
- > entrypoint into a static or shared library.
298
-
299
- > ** Note** : the restriction can only be violated when mixing code with different
300
- > ` -C panic ` flags. This is not possible in normal use of cargo, so most users
301
- > need not be concerned about this.
302
-
303
- r[ link.foreign-code.prohibited.lint.ffi_unwind_calls]
275
+ > [ !NOTE]
276
+ > Rust code compiled or linked with a different instance of the Rust runtime counts as a
277
+ > "foreign code" for the purpose of this section.
278
+
279
+ ### Prohibited linkage and unwinding
280
+
281
+ r[ link.unwinding]
282
+ If you are * not* using ` rustc ` to link Rust files, you must take care to ensure that unwinding is
283
+ handled consistently across the entire binary. This includes using ` dlopen ` or similar facilities
284
+ where linking is done by the system runtime without ` rustc ` being involved.
285
+
286
+ r[ link.unwinding.potential]
287
+ A Rust binary or ` staticlib ` is called * potentially unwinding* if any of the following conditions
288
+ is met:
289
+ - The binary or ` staticlib ` is linked with [ the ` panic=unwind ` runtime] [ panic-runtime ] .
290
+ - The binary or ` staticlib ` contains a crate built with ` -Cpanic=unwind ` that makes a call
291
+ to a function using a ` -unwind ` ABI.
292
+ - The binary or ` staticlib ` makes a ` "Rust" ` ABI call to code running in a separately built
293
+ ` staticlib ` (i.e., a separate instance of the Rust runtime), and that other ` staticlib ` is
294
+ potentially unwinding.
295
+
296
+ > [ !NOTE]
297
+ > This definition captures whether a ` "Rust" ` ABI call inside a Rust binary or ` staticlib ` can ever
298
+ > unwind.
299
+
300
+ r[ link.unwinding.prohibited]
301
+ If a Rust binary or ` staticlib ` is potentially unwinding, then all its crates must be built with ` -Cpanic=unwind ` .
302
+
303
+ > [ !NOTE]
304
+ > This restriction can only be violated when mixing code with different ` -C panic ` flags
305
+ > while also using a non-` rustc ` linker. Most users to not have to be concerned about this.
306
+
307
+ r[ link.unwinding.prohibited.lint.ffi_unwind_calls]
304
308
To guarantee that a library will be sound (and linkable with ` rustc ` )
305
309
regardless of the panic mode used at link-time, the [ ` ffi_unwind_calls ` lint]
306
310
may be used. The lint flags any calls to ` -unwind ` foreign functions or
0 commit comments