File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -66,12 +66,19 @@ item's name.
66
66
Additionally, the item will be publicly exported from the produced library or
67
67
object file, similar to the [ ` used ` attribute] ( #the-used-attribute ) .
68
68
69
+ This attribute is unsafe as an unmangled symbol may collide with another
70
+ symbol with the same name (or a well-known symbol), leading to undefined behavior.
71
+
69
72
## The ` link_section ` attribute
70
73
71
74
The * ` link_section ` attribute* specifies the section of the object file that a
72
75
[ function] or [ static] 's content will be placed into. It uses the
73
76
[ _ MetaNameValueStr_ ] syntax to specify the section name.
74
77
78
+ This attribute is unsafe as using ` link_section ` allows users to place data
79
+ and code into sections of memory not expecting them, such as mutable data
80
+ into read-only areas.
81
+
75
82
<!-- no_run: don't link. The format of the section name is platform-specific. -->
76
83
``` rust,no_run
77
84
#[no_mangle]
@@ -85,6 +92,9 @@ The *`export_name` attribute* specifies the name of the symbol that will be
85
92
exported on a [ function] or [ static] . It uses the [ _ MetaNameValueStr_ ] syntax
86
93
to specify the symbol name.
87
94
95
+ This attribute is unsafe as a symbol with a custom name may collide with another
96
+ symbol with the same name (or a well-known symbol), leading to undefined behavior.
97
+
88
98
``` rust
89
99
#[export_name = " exported_symbol_name" ]
90
100
pub fn name_in_rust () { }
Original file line number Diff line number Diff line change 4
4
> ** <sup >Syntax</sup >** \
5
5
> _ InnerAttribute_ :\
6
6
>   ;  ; ` # ` ` ! ` ` [ ` _ Attr_ ` ] `
7
+ >   ;  ; ` # ` ` ! ` ` [ ` ` unsafe ` ` ( ` _ Attr_ ` ) ` ` ] `
7
8
>
8
9
> _ OuterAttribute_ :\
9
10
>   ;  ; ` # ` ` [ ` _ Attr_ ` ] `
11
+ >   ;  ; ` # ` ` [ ` ` unsafe ` ` ( ` _ Attr_ ` ) ` ` ] `
12
+ >   ;  ; ` # ` ` ! ` ` [ ` _ Attr_ ` ] `
13
+ >   ;  ; ` # ` ` ! ` ` [ ` ` unsafe ` ` ( ` _ Attr_ ` ) ` ` ] `
10
14
>
11
15
> _ Attr_ :\
12
16
>   ;  ; [ _ SimplePath_ ] _ AttrInput_ <sup >?</sup >
@@ -29,6 +33,16 @@ Attributes other than macro attributes also allow the input to be an equals
29
33
sign (` = ` ) followed by an expression. See the [ meta item
30
34
syntax] ( #meta-item-attribute-syntax ) below for more details.
31
35
36
+ An attribute may be considered unsafe. Unsafe attributes must * satisfy* extra
37
+ safety conditions that cannot be checked by the compiler, and are specified
38
+ as the attribute wrapped in ` unsafe(...) ` , for instance, ` #[unsafe(no_mangle)] ` .
39
+
40
+ The following attributes are unsafe:
41
+
42
+ * [ ` export_name ` ]
43
+ * [ ` link_section ` ]
44
+ * [ ` no_mangle ` ]
45
+
32
46
Attributes can be classified into the following kinds:
33
47
34
48
* [ Built-in attributes]
You can’t perform that action at this time.
0 commit comments