about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-08-10 07:21:34 +0200
committerGitHub <noreply@github.com>2022-08-10 07:21:34 +0200
commit6b5ec41936930d3140a888903bf2ab928c068b09 (patch)
tree20c83ef69e0fffe5ea58b8a4888032232c18e58e /compiler
parente10f924e278f3b792bd8e9c2eb4c5012c1746a7c (diff)
parentfda5144ceb2be07501febbbccc10172b4ea737cd (diff)
downloadrust-6b5ec41936930d3140a888903bf2ab928c068b09.tar.gz
rust-6b5ec41936930d3140a888903bf2ab928c068b09.zip
Rollup merge of #100069 - dpaoliello:linkordinal, r=michaelwoerister
Add error if link_ordinal used with unsupported link kind

The `link_ordinal` attribute only has an affect if the `raw-dylib` link kind is used, so add an error if it is used with any other link kind.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_metadata/src/native_libs.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs
index 9f6079ecba4..c5e39507d7e 100644
--- a/compiler/rustc_metadata/src/native_libs.rs
+++ b/compiler/rustc_metadata/src/native_libs.rs
@@ -328,7 +328,31 @@ impl<'tcx> Collector<'tcx> {
                         .map(|child_item| self.build_dll_import(abi, child_item))
                         .collect()
                 }
-                _ => Vec::new(),
+                _ => {
+                    for child_item in foreign_mod_items {
+                        if self.tcx.def_kind(child_item.id.def_id).has_codegen_attrs()
+                            && self
+                                .tcx
+                                .codegen_fn_attrs(child_item.id.def_id)
+                                .link_ordinal
+                                .is_some()
+                        {
+                            let link_ordinal_attr = self
+                                .tcx
+                                .hir()
+                                .attrs(self.tcx.hir().local_def_id_to_hir_id(child_item.id.def_id))
+                                .iter()
+                                .find(|a| a.has_name(sym::link_ordinal))
+                                .unwrap();
+                            sess.span_err(
+                                link_ordinal_attr.span,
+                                "`#[link_ordinal]` is only supported if link kind is `raw-dylib`",
+                            );
+                        }
+                    }
+
+                    Vec::new()
+                }
             };
             self.libs.push(NativeLib {
                 name: name.map(|(name, _)| name),