@@ -116,6 +116,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
116116 AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
117117 AttributeKind :: Align { align, .. } => codegen_fn_attrs. alignment = Some ( * align) ,
118118 AttributeKind :: LinkName { name, .. } => codegen_fn_attrs. link_name = Some ( * name) ,
119+ AttributeKind :: LinkOrdinal { ordinal, span } => {
120+ codegen_fn_attrs. link_ordinal = Some ( * ordinal) ;
121+ link_ordinal_span = Some ( * span) ;
122+ }
119123 AttributeKind :: LinkSection { name, .. } => {
120124 codegen_fn_attrs. link_section = Some ( * name)
121125 }
@@ -248,12 +252,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
248252 }
249253 }
250254 }
251- sym:: link_ordinal => {
252- link_ordinal_span = Some ( attr. span ( ) ) ;
253- if let ordinal @ Some ( _) = check_link_ordinal ( tcx, attr) {
254- codegen_fn_attrs. link_ordinal = ordinal;
255- }
256- }
257255 sym:: no_sanitize => {
258256 no_sanitize_span = Some ( attr. span ( ) ) ;
259257 if let Some ( list) = attr. meta_item_list ( ) {
@@ -566,45 +564,6 @@ fn inherited_align<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Align> {
566564 tcx. codegen_fn_attrs ( opt_trait_item ( tcx, def_id) ?) . alignment
567565}
568566
569- fn check_link_ordinal ( tcx : TyCtxt < ' _ > , attr : & hir:: Attribute ) -> Option < u16 > {
570- use rustc_ast:: { LitIntType , LitKind , MetaItemLit } ;
571- let meta_item_list = attr. meta_item_list ( ) ?;
572- let [ sole_meta_list] = & meta_item_list[ ..] else {
573- tcx. dcx ( ) . emit_err ( errors:: InvalidLinkOrdinalNargs { span : attr. span ( ) } ) ;
574- return None ;
575- } ;
576- if let Some ( MetaItemLit { kind : LitKind :: Int ( ordinal, LitIntType :: Unsuffixed ) , .. } ) =
577- sole_meta_list. lit ( )
578- {
579- // According to the table at
580- // https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-header, the
581- // ordinal must fit into 16 bits. Similarly, the Ordinal field in COFFShortExport (defined
582- // in llvm/include/llvm/Object/COFFImportFile.h), which we use to communicate import
583- // information to LLVM for `#[link(kind = "raw-dylib"_])`, is also defined to be uint16_t.
584- //
585- // FIXME: should we allow an ordinal of 0? The MSVC toolchain has inconsistent support for
586- // this: both LINK.EXE and LIB.EXE signal errors and abort when given a .DEF file that
587- // specifies a zero ordinal. However, llvm-dlltool is perfectly happy to generate an import
588- // library for such a .DEF file, and MSVC's LINK.EXE is also perfectly happy to consume an
589- // import library produced by LLVM with an ordinal of 0, and it generates an .EXE. (I
590- // don't know yet if the resulting EXE runs, as I haven't yet built the necessary DLL --
591- // see earlier comment about LINK.EXE failing.)
592- if * ordinal <= u16:: MAX as u128 {
593- Some ( ordinal. get ( ) as u16 )
594- } else {
595- let msg = format ! ( "ordinal value in `link_ordinal` is too large: `{ordinal}`" ) ;
596- tcx. dcx ( )
597- . struct_span_err ( attr. span ( ) , msg)
598- . with_note ( "the value may not exceed `u16::MAX`" )
599- . emit ( ) ;
600- None
601- }
602- } else {
603- tcx. dcx ( ) . emit_err ( errors:: InvalidLinkOrdinalFormat { span : attr. span ( ) } ) ;
604- None
605- }
606- }
607-
608567fn check_link_name_xor_ordinal (
609568 tcx : TyCtxt < ' _ > ,
610569 codegen_fn_attrs : & CodegenFnAttrs ,
0 commit comments