@@ -435,7 +435,56 @@ macro_rules! intrinsics {
435
435
intrinsics!( $( $rest) * ) ;
436
436
) ;
437
437
438
- // This is the final catch-all rule. At this point we generate an
438
+ // This is the last rule for anything that has `strong_if`, which can be
439
+ // provided to opt out of the default weak linkage.
440
+ //
441
+ // This attribute takes a `cfg` predicate, e.g. `#![strong_if(target_arch = "mips")]`
442
+ (
443
+
444
+ #[ strong_if( $( $strong: tt) * ) ]
445
+ $( #[ $( $attr: tt) * ] ) *
446
+ pub $( unsafe $( @ $empty: tt) ?) ? extern $abi: tt fn $name: ident( $( $argname: ident: $ty: ty) ,* ) $( -> $ret: ty) ? {
447
+ $( $body: tt) *
448
+ }
449
+
450
+ $( $rest: tt) *
451
+ ) => (
452
+ intrinsics!(
453
+ @final
454
+ func:
455
+ $( #[ $( $attr) * ] ) *
456
+ pub $( unsafe $( $empty) ?) ? extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
457
+ $( $body) *
458
+ }
459
+ strong_if: ( $( $strong) * )
460
+ rest: $( $rest) *
461
+ ) ;
462
+ ) ;
463
+
464
+ // This is the final catch-all rule, used by everything that does not have
465
+ // `strong_if` (above). The rule just converts matched syntax into the
466
+ // struct-like syntax used by `@final`.
467
+ (
468
+ $( #[ $( $attr: tt) * ] ) *
469
+ pub $( unsafe $( @ $empty: tt) ?) ? extern $abi: tt fn $name: ident( $( $argname: ident: $ty: ty) ,* ) $( -> $ret: ty) ? {
470
+ $( $body: tt) *
471
+ }
472
+
473
+ $( $rest: tt) *
474
+ ) => (
475
+ intrinsics!(
476
+ @final
477
+ func:
478
+ $( #[ $( $attr) * ] ) *
479
+ pub $( unsafe $( $empty) ?) ? extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
480
+ $( $body) *
481
+ }
482
+ strong_if:
483
+ rest: $( $rest) *
484
+ ) ;
485
+ ) ;
486
+
487
+ // This is where everything gets instantiated. At this point we generate an
439
488
// intrinsic with a conditional `#[no_mangle]` directive to avoid
440
489
// interfering with duplicate symbols and whatnot during testing.
441
490
//
@@ -448,12 +497,15 @@ macro_rules! intrinsics {
448
497
// After the intrinsic is defined we just continue with the rest of the
449
498
// input we were given.
450
499
(
451
- $( #[ $( $attr: tt) * ] ) *
452
- pub $( unsafe $( @ $empty: tt) ?) ? extern $abi: tt fn $name: ident( $( $argname: ident: $ty: ty) ,* ) $( -> $ret: ty) ? {
453
- $( $body: tt) *
454
- }
500
+ @final
501
+ func:
502
+ $( #[ $( $attr: tt) * ] ) *
503
+ pub $( unsafe $( @ $empty: tt) ?) ? extern $abi: tt fn $name: ident( $( $argname: ident: $ty: ty) ,* ) $( -> $ret: ty) ? {
504
+ $( $body: tt) *
505
+ }
455
506
456
- $( $rest: tt) *
507
+ strong_if: $( ( $( $strong: tt) * ) ) ?
508
+ rest: $( $rest: tt) *
457
509
) => (
458
510
$( #[ $( $attr) * ] ) *
459
511
pub $( unsafe $( $empty) ?) ? extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
@@ -464,7 +516,10 @@ macro_rules! intrinsics {
464
516
mod $name {
465
517
$( #[ $( $attr) * ] ) *
466
518
#[ no_mangle]
467
- #[ cfg_attr( all( not( windows) , not( target_vendor = "apple" ) ) , linkage = "weak" ) ]
519
+ #[ cfg_attr(
520
+ not( any( windows, target_vendor = "apple" $( , $( $strong) * ) ?) ) ,
521
+ linkage = "weak"
522
+ ) ]
468
523
$( unsafe $( $empty) ?) ? extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
469
524
super :: $name( $( $argname) ,* )
470
525
}
0 commit comments