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.
6666Additionally, the item will be publicly exported from the produced library or
6767object file, similar to the [ ` used ` attribute] ( #the-used-attribute ) .
6868
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+
6972## The ` link_section ` attribute
7073
7174The * ` link_section ` attribute* specifies the section of the object file that a
7275[ function] or [ static] 's content will be placed into. It uses the
7376[ _ MetaNameValueStr_ ] syntax to specify the section name.
7477
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+
7582<!-- no_run: don't link. The format of the section name is platform-specific. -->
7683``` rust,no_run
7784#[no_mangle]
@@ -85,6 +92,9 @@ The *`export_name` attribute* specifies the name of the symbol that will be
8592exported on a [ function] or [ static] . It uses the [ _ MetaNameValueStr_ ] syntax
8693to specify the symbol name.
8794
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+
8898``` rust
8999#[export_name = " exported_symbol_name" ]
90100pub fn name_in_rust () { }
Original file line number Diff line number Diff line change 44> ** <sup >Syntax</sup >** \
55> _ InnerAttribute_ :\
66>   ;  ; ` # ` ` ! ` ` [ ` _ Attr_ ` ] `
7+ >   ;  ; ` # ` ` ! ` ` [ ` ` unsafe ` ` ( ` _ Attr_ ` ) ` ` ] `
78>
89> _ OuterAttribute_ :\
910>   ;  ; ` # ` ` [ ` _ Attr_ ` ] `
11+ >   ;  ; ` # ` ` [ ` ` unsafe ` ` ( ` _ Attr_ ` ) ` ` ] `
12+ >   ;  ; ` # ` ` ! ` ` [ ` _ Attr_ ` ] `
13+ >   ;  ; ` # ` ` ! ` ` [ ` ` unsafe ` ` ( ` _ Attr_ ` ) ` ` ] `
1014>
1115> _ Attr_ :\
1216>   ;  ; [ _ SimplePath_ ] _ AttrInput_ <sup >?</sup >
@@ -29,6 +33,16 @@ Attributes other than macro attributes also allow the input to be an equals
2933sign (` = ` ) followed by an expression. See the [ meta item
3034syntax] ( #meta-item-attribute-syntax ) below for more details.
3135
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+
3246Attributes can be classified into the following kinds:
3347
3448* [ Built-in attributes]
You can’t perform that action at this time.
0 commit comments