@@ -124,6 +124,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
124124 AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
125125 AttributeKind :: Align { align, .. } => codegen_fn_attrs. alignment = Some ( * align) ,
126126 AttributeKind :: LinkName { name, .. } => codegen_fn_attrs. link_name = Some ( * name) ,
127+ AttributeKind :: LinkOrdinal { ordinal, span } => {
128+ codegen_fn_attrs. link_ordinal = Some ( * ordinal) ;
129+ link_ordinal_span = Some ( * span) ;
130+ }
127131 AttributeKind :: NoMangle ( attr_span) => {
128132 if tcx. opt_item_name ( did. to_def_id ( ) ) . is_some ( ) {
129133 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NO_MANGLE ;
@@ -263,12 +267,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
263267 }
264268 }
265269 }
266- sym:: link_ordinal => {
267- link_ordinal_span = Some ( attr. span ( ) ) ;
268- if let ordinal @ Some ( _) = check_link_ordinal ( tcx, attr) {
269- codegen_fn_attrs. link_ordinal = ordinal;
270- }
271- }
272270 sym:: no_sanitize => {
273271 no_sanitize_span = Some ( attr. span ( ) ) ;
274272 if let Some ( list) = attr. meta_item_list ( ) {
@@ -569,45 +567,6 @@ fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
569567 false
570568}
571569
572- fn check_link_ordinal ( tcx : TyCtxt < ' _ > , attr : & hir:: Attribute ) -> Option < u16 > {
573- use rustc_ast:: { LitIntType , LitKind , MetaItemLit } ;
574- let meta_item_list = attr. meta_item_list ( ) ?;
575- let [ sole_meta_list] = & meta_item_list[ ..] else {
576- tcx. dcx ( ) . emit_err ( errors:: InvalidLinkOrdinalNargs { span : attr. span ( ) } ) ;
577- return None ;
578- } ;
579- if let Some ( MetaItemLit { kind : LitKind :: Int ( ordinal, LitIntType :: Unsuffixed ) , .. } ) =
580- sole_meta_list. lit ( )
581- {
582- // According to the table at
583- // https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header, the
584- // ordinal must fit into 16 bits. Similarly, the Ordinal field in COFFShortExport (defined
585- // in llvm/include/llvm/Object/COFFImportFile.h), which we use to communicate import
586- // information to LLVM for `#[link(kind = "raw-dylib"_])`, is also defined to be uint16_t.
587- //
588- // FIXME: should we allow an ordinal of 0? The MSVC toolchain has inconsistent support for
589- // this: both LINK.EXE and LIB.EXE signal errors and abort when given a .DEF file that
590- // specifies a zero ordinal. However, llvm-dlltool is perfectly happy to generate an import
591- // library for such a .DEF file, and MSVC's LINK.EXE is also perfectly happy to consume an
592- // import library produced by LLVM with an ordinal of 0, and it generates an .EXE. (I
593- // don't know yet if the resulting EXE runs, as I haven't yet built the necessary DLL --
594- // see earlier comment about LINK.EXE failing.)
595- if * ordinal <= u16:: MAX as u128 {
596- Some ( ordinal. get ( ) as u16 )
597- } else {
598- let msg = format ! ( "ordinal value in `link_ordinal` is too large: `{ordinal}`" ) ;
599- tcx. dcx ( )
600- . struct_span_err ( attr. span ( ) , msg)
601- . with_note ( "the value may not exceed `u16::MAX`" )
602- . emit ( ) ;
603- None
604- }
605- } else {
606- tcx. dcx ( ) . emit_err ( errors:: InvalidLinkOrdinalFormat { span : attr. span ( ) } ) ;
607- None
608- }
609- }
610-
611570fn check_link_name_xor_ordinal (
612571 tcx : TyCtxt < ' _ > ,
613572 codegen_fn_attrs : & CodegenFnAttrs ,
0 commit comments