about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
diff options
context:
space:
mode:
author5225225 <5225225@mailbox.org>2022-05-16 18:04:54 +0100
committer5225225 <5225225@mailbox.org>2022-05-16 18:11:38 +0100
commita42a7a3eb90d67f9931e912b7e62f697c8467b3a (patch)
treeecde128a65587b66ca7c64154d6be0988d26e873 /compiler/rustc_lint/src
parentc52b9c10bfb5164015eb977ff498e0597ae63eb1 (diff)
downloadrust-a42a7a3eb90d67f9931e912b7e62f697c8467b3a.tar.gz
rust-a42a7a3eb90d67f9931e912b7e62f697c8467b3a.zip
Report unsafe for overriding link sections
Diffstat (limited to 'compiler/rustc_lint/src')
-rw-r--r--compiler/rustc_lint/src/builtin.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs
index a87083a082b..64d9d4aaf17 100644
--- a/compiler/rustc_lint/src/builtin.rs
+++ b/compiler/rustc_lint/src/builtin.rs
@@ -338,6 +338,17 @@ impl UnsafeCode {
                 .emit();
         })
     }
+
+    fn report_overridden_symbol_section(&self, cx: &EarlyContext<'_>, span: Span, msg: &str) {
+        self.report_unsafe(cx, span, |lint| {
+            lint.build(msg)
+                .note(
+                    "the program's behavior with overridden link sections on items is unpredictable \
+                    and Rust cannot provide guarantees when you manually override them",
+                )
+                .emit();
+        })
+    }
 }
 
 impl EarlyLintPass for UnsafeCode {
@@ -385,6 +396,7 @@ impl EarlyLintPass for UnsafeCode {
                         "declaration of a `no_mangle` function",
                     );
                 }
+
                 if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::export_name) {
                     self.report_overridden_symbol_name(
                         cx,
@@ -392,6 +404,14 @@ impl EarlyLintPass for UnsafeCode {
                         "declaration of a function with `export_name`",
                     );
                 }
+
+                if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::link_section) {
+                    self.report_overridden_symbol_section(
+                        cx,
+                        attr.span,
+                        "declaration of a function with `link_section`",
+                    );
+                }
             }
 
             ast::ItemKind::Static(..) => {
@@ -402,6 +422,7 @@ impl EarlyLintPass for UnsafeCode {
                         "declaration of a `no_mangle` static",
                     );
                 }
+
                 if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::export_name) {
                     self.report_overridden_symbol_name(
                         cx,
@@ -409,6 +430,14 @@ impl EarlyLintPass for UnsafeCode {
                         "declaration of a static with `export_name`",
                     );
                 }
+
+                if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::link_section) {
+                    self.report_overridden_symbol_section(
+                        cx,
+                        attr.span,
+                        "declaration of a static with `link_section`",
+                    );
+                }
             }
 
             _ => {}