Add support for parsing #[link_ordinal] attribute.
This commit is contained in:
parent
e70ffed9cd
commit
3462b58f21
2 changed files with 44 additions and 0 deletions
|
@ -2669,6 +2669,11 @@ pub struct CodegenFnAttrs {
|
|||
/// probably isn't set when this is set, this is for foreign items while
|
||||
/// `#[export_name]` is for Rust-defined functions.
|
||||
pub link_name: Option<Symbol>,
|
||||
/// The `#[link_ordinal = "..."]` attribute, indicating an ordinal an
|
||||
/// imported function has in the dynamic library. Note that this must not
|
||||
/// be set when `link_name` is set. This is for foreign items with the
|
||||
/// "raw-dylib" kind.
|
||||
pub link_ordinal: Option<usize>,
|
||||
/// The `#[target_feature(enable = "...")]` attribute and the enabled
|
||||
/// features (only enabled features are supported right now).
|
||||
pub target_features: Vec<Symbol>,
|
||||
|
@ -2728,6 +2733,7 @@ impl CodegenFnAttrs {
|
|||
optimize: OptimizeAttr::None,
|
||||
export_name: None,
|
||||
link_name: None,
|
||||
link_ordinal: None,
|
||||
target_features: vec![],
|
||||
linkage: None,
|
||||
link_section: None,
|
||||
|
|
|
@ -2641,6 +2641,35 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
|
|||
}
|
||||
} else if attr.check_name(sym::link_name) {
|
||||
codegen_fn_attrs.link_name = attr.value_str();
|
||||
} else if attr.check_name(sym::link_ordinal) {
|
||||
use syntax::ast::{Lit, LitIntType, LitKind};
|
||||
let meta_item_list = attr.meta_item_list();
|
||||
let sole_meta_lit = if let Some(meta_item_list) = &meta_item_list {
|
||||
if meta_item_list.len() == 1 {
|
||||
meta_item_list.get(0).and_then(|item| item.literal())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(Lit { node: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) =
|
||||
sole_meta_lit
|
||||
{
|
||||
if *ordinal <= std::usize::MAX as u128 {
|
||||
codegen_fn_attrs.link_ordinal = Some(*ordinal as usize);
|
||||
} else {
|
||||
let msg = format!(
|
||||
"too large ordinal value in link_ordinal \
|
||||
value: `{}`",
|
||||
&ordinal
|
||||
);
|
||||
tcx.sess.span_err(attr.span, &msg);
|
||||
}
|
||||
} else {
|
||||
let msg = "illegal ordinal format in link_ordinal";
|
||||
tcx.sess.span_err(attr.span, &msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2742,6 +2771,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
|
|||
codegen_fn_attrs.export_name = Some(name);
|
||||
codegen_fn_attrs.link_name = Some(name);
|
||||
}
|
||||
if codegen_fn_attrs.link_name.is_some() && codegen_fn_attrs.link_ordinal.is_some() {
|
||||
if let Some(span) = inline_span {
|
||||
tcx.sess.span_err(
|
||||
span,
|
||||
"cannot use `#[link_name]` with \
|
||||
`#[link_ordinal]`",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Internal symbols to the standard library all have no_mangle semantics in
|
||||
// that they have defined symbol names present in the function name. This
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue