@@ -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 :: LinkSection { name, .. } => {
128132 codegen_fn_attrs. link_section = Some ( * name)
129133 }
@@ -256,12 +260,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
256260 }
257261 }
258262 }
259- sym:: link_ordinal => {
260- link_ordinal_span = Some ( attr. span ( ) ) ;
261- if let ordinal @ Some ( _) = check_link_ordinal ( tcx, attr) {
262- codegen_fn_attrs. link_ordinal = ordinal;
263- }
264- }
265263 sym:: no_sanitize => {
266264 no_sanitize_span = Some ( attr. span ( ) ) ;
267265 if let Some ( list) = attr. meta_item_list ( ) {
@@ -574,45 +572,6 @@ fn inherited_align<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Align> {
574572 tcx. codegen_fn_attrs ( opt_trait_item ( tcx, def_id) ?) . alignment
575573}
576574
577- fn check_link_ordinal ( tcx : TyCtxt < ' _ > , attr : & hir:: Attribute ) -> Option < u16 > {
578- use rustc_ast:: { LitIntType , LitKind , MetaItemLit } ;
579- let meta_item_list = attr. meta_item_list ( ) ?;
580- let [ sole_meta_list] = & meta_item_list[ ..] else {
581- tcx. dcx ( ) . emit_err ( errors:: InvalidLinkOrdinalNargs { span : attr. span ( ) } ) ;
582- return None ;
583- } ;
584- if let Some ( MetaItemLit { kind : LitKind :: Int ( ordinal, LitIntType :: Unsuffixed ) , .. } ) =
585- sole_meta_list. lit ( )
586- {
587- // According to the table at
588- // https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header, the
589- // ordinal must fit into 16 bits. Similarly, the Ordinal field in COFFShortExport (defined
590- // in llvm/include/llvm/Object/COFFImportFile.h), which we use to communicate import
591- // information to LLVM for `#[link(kind = "raw-dylib"_])`, is also defined to be uint16_t.
592- //
593- // FIXME: should we allow an ordinal of 0? The MSVC toolchain has inconsistent support for
594- // this: both LINK.EXE and LIB.EXE signal errors and abort when given a .DEF file that
595- // specifies a zero ordinal. However, llvm-dlltool is perfectly happy to generate an import
596- // library for such a .DEF file, and MSVC's LINK.EXE is also perfectly happy to consume an
597- // import library produced by LLVM with an ordinal of 0, and it generates an .EXE. (I
598- // don't know yet if the resulting EXE runs, as I haven't yet built the necessary DLL --
599- // see earlier comment about LINK.EXE failing.)
600- if * ordinal <= u16:: MAX as u128 {
601- Some ( ordinal. get ( ) as u16 )
602- } else {
603- let msg = format ! ( "ordinal value in `link_ordinal` is too large: `{ordinal}`" ) ;
604- tcx. dcx ( )
605- . struct_span_err ( attr. span ( ) , msg)
606- . with_note ( "the value may not exceed `u16::MAX`" )
607- . emit ( ) ;
608- None
609- }
610- } else {
611- tcx. dcx ( ) . emit_err ( errors:: InvalidLinkOrdinalFormat { span : attr. span ( ) } ) ;
612- None
613- }
614- }
615-
616575fn check_link_name_xor_ordinal (
617576 tcx : TyCtxt < ' _ > ,
618577 codegen_fn_attrs : & CodegenFnAttrs ,
0 commit comments