Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error if link_ordinal used with unsupported link kind #100069

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
dpaoliello marked this conversation as resolved.
Show resolved Hide resolved
&& 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),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete

#[link(name = "foo")]
extern "C" {
#[link_ordinal(3)]
//~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib`
fn foo();
}

#[link(name = "bar", kind = "static")]
extern "C" {
#[link_ordinal(3)]
//~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib`
fn bar();
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/link-ordinal-unsupported-link-kind.rs:1:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information

error: `#[link_ordinal]` is only supported if link kind is `raw-dylib`
--> $DIR/link-ordinal-unsupported-link-kind.rs:6:5
|
LL | #[link_ordinal(3)]
| ^^^^^^^^^^^^^^^^^^

error: `#[link_ordinal]` is only supported if link kind is `raw-dylib`
--> $DIR/link-ordinal-unsupported-link-kind.rs:13:5
|
LL | #[link_ordinal(3)]
| ^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors; 1 warning emitted