Skip to content

Commit

Permalink
Use unsafe in the unsafe attribute examples.
Browse files Browse the repository at this point in the history
This will be required in 2024.
  • Loading branch information
ehuss committed Jul 25, 2024
1 parent 28005ff commit d062efb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/abi.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ object file, similar to the [`used` attribute](#the-used-attribute).
This attribute is unsafe as an unmangled symbol may collide with another symbol
with the same name (or with a well-known symbol), leading to undefined behavior.

```rust
#[unsafe(no_mangle)]
extern "C" fn foo() {}
```

## The `link_section` attribute

The *`link_section` attribute* specifies the section of the object file that a
Expand All @@ -80,8 +85,8 @@ of memory not expecting them, such as mutable data into read-only areas.

<!-- no_run: don't link. The format of the section name is platform-specific. -->
```rust,no_run
#[no_mangle]
#[link_section = ".example_section"]
#[unsafe(no_mangle)]
#[unsafe(link_section = ".example_section")]
pub static VAR1: u32 = 1;
```

Expand All @@ -96,7 +101,7 @@ symbol with the same name (or with a well-known symbol), leading to undefined
behavior.

```rust
#[export_name = "exported_symbol_name"]
#[unsafe(export_name = "exported_symbol_name")]
pub fn name_in_rust() { }
```

Expand Down

0 comments on commit d062efb

Please sign in to comment.