diff options
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 29 |
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`", + ); + } } _ => {} |
