You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/abi.md
+49-9Lines changed: 49 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,23 +65,62 @@ r[abi.no_mangle]
65
65
## The `no_mangle` attribute
66
66
67
67
r[abi.no_mangle.intro]
68
-
The*`no_mangle` attribute* may be used on any [item] to disable standard symbol name mangling.The symbol for the item will be the identifier of the item's name.
68
+
The*`no_mangle` attribute* may be used on functions and statics to disable standard symbol name mangling.The symbol for the item will be the identifier of the item's name.
69
69
70
-
r[abi.no_mangle.publicly-exported]
71
-
Additionally, the item will be publicly exported from the produced library or object file, similar to the [`used` attribute](#the-used-attribute).
70
+
> [!EXAMPLE]
71
+
> ```rust
72
+
> #[unsafe(no_mangle)]
73
+
> extern "C" fn foo() {}
74
+
> ```
72
75
73
-
r[abi.no_mangle.unsafe]
74
-
Thisattribute is unsafeas an unmangled symbol may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior.
76
+
r[abi.no_mangle.syntax]
77
+
The `no_mangle` attribute uses the [MetaWord] syntax and thus does not take any inputs.
<!--TODO: should this clarify that external block items are already unmangled?, and thus the attribute does nothing?Currently it is "phased out" warning.-->
95
+
96
+
r[abi.no_mangle.closures]
97
+
`no_mangle` may not be used with a [closure].
98
+
99
+
r[abi.no_mangle.generics]
100
+
`no_mangle` may not be used on an item with generic parameters.
101
+
102
+
r[abi.no_mangle.duplicates]
103
+
Only the first instance of `no_mangle` on an item is honored.Subsequent `no_mangle` attributes are ignored.
104
+
105
+
> [!NOTE]
106
+
> `rustc` currently warns on subsequent duplicate `no_mangle` attributes.
107
+
108
+
r[abi.no_mangle.export_name]
109
+
If `no_mangle` is used with [`export_name`][abi.export_name], then the `export_name` is used instead.
110
+
111
+
r[abi.no_mangle.unsafe]
112
+
The `no_mangle` attribute must be marked with [`unsafe`][attributes.safety] because an unmangled symbol may collide with another symbol with the same name (or with a well-known symbol), leading to undefined behavior.
80
113
81
114
r[abi.no_mangle.edition2024]
82
115
> [!EDITION-2024]
83
116
> Before the 2024 edition it is allowed to use the `no_mangle` attribute without the `unsafe` qualification.
84
117
118
+
r[abi.no_mangle.publicly-exported]
119
+
In addition to disabling name mangling, the item will be publicly exported from the produced library or object file, similar to the [`used` attribute](#the-used-attribute).
120
+
121
+
r[abi.no_mangle.ascii-only]
122
+
`no_mangle` may only be used on items with a name that only contains ASCII characters.
0 commit comments