@@ -25,11 +25,12 @@ macro_rules! public_test_dep {
25
25
/// platforms need and elsewhere in this library it just looks like normal Rust
26
26
/// code.
27
27
///
28
- /// When the weak-intrinsics feature is enabled, all intrinsics functions are
29
- /// marked with #[linkage = "weak"] so that they can be replaced by another
30
- /// implementation at link time. This is particularly useful for mixed Rust/C++
31
- /// binaries that want to use the C++ intrinsics, otherwise linking against the
32
- /// Rust stdlib will replace those from the compiler-rt library.
28
+ /// All intrinsics functions are marked with #[linkage = "weak"] when
29
+ /// `not(windows) and not(target_vendor = "apple")`.
30
+ /// `weak` linkage attribute is used so that these functions can be replaced
31
+ /// by another implementation at link time. This is particularly useful for mixed
32
+ /// Rust/C++ binaries that want to use the C++ intrinsics, otherwise linking against
33
+ /// the Rust stdlib will replace those from the compiler-rt library.
33
34
///
34
35
/// This macro is structured to be invoked with a bunch of functions that looks
35
36
/// like:
@@ -53,10 +54,6 @@ macro_rules! public_test_dep {
53
54
///
54
55
/// A quick overview of attributes supported right now are:
55
56
///
56
- /// * `weak` - indicates that the function should always be given weak linkage.
57
- /// This attribute must come before other attributes, as the other attributes
58
- /// will generate the final output function and need to have `weak` modify
59
- /// them.
60
57
/// * `maybe_use_optimized_c_shim` - indicates that the Rust implementation is
61
58
/// ignored if an optimized C version was compiled.
62
59
/// * `aapcs_on_arm` - forces the ABI of the function to be `"aapcs"` on ARM and
@@ -128,67 +125,6 @@ macro_rules! intrinsics {
128
125
intrinsics!( $( $rest) * ) ;
129
126
) ;
130
127
131
- // Explicit weak linkage gets dropped when weak-intrinsics is on since it
132
- // will be added unconditionally to all intrinsics and would conflict
133
- // otherwise.
134
- (
135
- #[ weak]
136
- $( #[ $( $attr: tt) * ] ) *
137
- pub extern $abi: tt fn $name: ident( $( $argname: ident: $ty: ty) ,* ) $( -> $ret: ty) ? {
138
- $( $body: tt) *
139
- }
140
-
141
- $( $rest: tt) *
142
- ) => (
143
- #[ cfg( feature = "weak-intrinsics" ) ]
144
- intrinsics! {
145
- $( #[ $( $attr) * ] ) *
146
- pub extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
147
- $( $body) *
148
- }
149
- }
150
-
151
- #[ cfg( not( feature = "weak-intrinsics" ) ) ]
152
- intrinsics! {
153
- $( #[ $( $attr) * ] ) *
154
- #[ linkage = "weak" ]
155
- pub extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
156
- $( $body) *
157
- }
158
- }
159
-
160
- intrinsics!( $( $rest) * ) ;
161
- ) ;
162
- // Same as above but for unsafe.
163
- (
164
- #[ weak]
165
- $( #[ $( $attr: tt) * ] ) *
166
- pub unsafe extern $abi: tt fn $name: ident( $( $argname: ident: $ty: ty) ,* ) $( -> $ret: ty) ? {
167
- $( $body: tt) *
168
- }
169
-
170
- $( $rest: tt) *
171
- ) => (
172
- #[ cfg( feature = "weak-intrinsics" ) ]
173
- intrinsics! {
174
- $( #[ $( $attr) * ] ) *
175
- pub unsafe extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
176
- $( $body) *
177
- }
178
- }
179
-
180
- #[ cfg( not( feature = "weak-intrinsics" ) ) ]
181
- intrinsics! {
182
- $( #[ $( $attr) * ] ) *
183
- #[ linkage = "weak" ]
184
- pub unsafe extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
185
- $( $body) *
186
- }
187
- }
188
-
189
- intrinsics!( $( $rest) * ) ;
190
- ) ;
191
-
192
128
// Right now there's a bunch of architecture-optimized intrinsics in the
193
129
// stock compiler-rt implementation. Not all of these have been ported over
194
130
// to Rust yet so when the `c` feature of this crate is enabled we fall back
@@ -211,7 +147,6 @@ macro_rules! intrinsics {
211
147
$( $rest: tt) *
212
148
) => (
213
149
#[ cfg( $name = "optimized-c" ) ]
214
- #[ cfg_attr( feature = "weak-intrinsics" , linkage = "weak" ) ]
215
150
pub $( unsafe $( $empty) ? ) ? extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
216
151
extern $abi {
217
152
fn $name( $( $argname: $ty) ,* ) $( -> $ret) ?;
@@ -311,16 +246,15 @@ macro_rules! intrinsics {
311
246
) => (
312
247
#[ cfg( all( any( windows, target_os = "uefi" ) , target_arch = "x86_64" ) ) ]
313
248
$( #[ $( $attr) * ] ) *
314
- #[ cfg_attr( feature = "weak-intrinsics" , linkage = "weak" ) ]
315
249
pub extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
316
250
$( $body) *
317
251
}
318
252
319
- #[ cfg( all( any( windows, target_os = "uefi" ) , target_arch = "x86_64" ) ) ]
320
- pub mod $name {
321
- #[ cfg_attr ( not ( feature = "mangled-names" ) , no_mangle) ]
322
- #[ cfg_attr( feature = "weak-intrinsics" , linkage = "weak" ) ]
323
- pub extern $abi fn $name( $( $argname: $ty) ,* )
253
+ #[ cfg( all( any( windows, target_os = "uefi" ) , target_arch = "x86_64" , not ( feature = "mangled-names" ) ) ) ]
254
+ mod $name {
255
+ #[ no_mangle]
256
+ #[ cfg_attr( all ( not ( windows ) , not ( target_vendor = "apple" ) ) , linkage = "weak" ) ]
257
+ extern $abi fn $name( $( $argname: $ty) ,* )
324
258
-> $crate:: macros:: win64_128bit_abi_hack:: U64x2
325
259
{
326
260
let e: $( $ret) ? = super :: $name( $( $argname) ,* ) ;
@@ -357,20 +291,20 @@ macro_rules! intrinsics {
357
291
$( $body) *
358
292
}
359
293
360
- #[ cfg( target_arch = "arm" ) ]
361
- pub mod $name {
362
- #[ cfg_attr ( not ( feature = "mangled-names" ) , no_mangle) ]
363
- #[ cfg_attr( feature = "weak-intrinsics" , linkage = "weak" ) ]
364
- pub extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
294
+ #[ cfg( all ( target_arch = "arm" , not ( feature = "mangled-names" ) ) ) ]
295
+ mod $name {
296
+ #[ no_mangle]
297
+ #[ cfg_attr( all ( not ( windows ) , not ( target_vendor = "apple" ) ) , linkage = "weak" ) ]
298
+ extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
365
299
super :: $name( $( $argname) ,* )
366
300
}
367
301
}
368
302
369
- #[ cfg( target_arch = "arm" ) ]
370
- pub mod $alias {
371
- #[ cfg_attr ( not ( feature = "mangled-names" ) , no_mangle) ]
372
- #[ cfg_attr( any ( all( not( windows) , not( target_vendor="apple" ) ) , feature = "weak-intrinsics" ) , linkage = "weak" ) ]
373
- pub extern "aapcs" fn $alias( $( $argname: $ty) ,* ) $( -> $ret) ? {
303
+ #[ cfg( all ( target_arch = "arm" , not ( feature = "mangled-names" ) ) ) ]
304
+ mod $alias {
305
+ #[ no_mangle]
306
+ #[ cfg_attr( all( not( windows) , not( target_vendor="apple" ) ) , linkage = "weak" ) ]
307
+ extern "aapcs" fn $alias( $( $argname: $ty) ,* ) $( -> $ret) ? {
374
308
super :: $name( $( $argname) ,* )
375
309
}
376
310
}
@@ -401,12 +335,12 @@ macro_rules! intrinsics {
401
335
$( $body) *
402
336
}
403
337
404
- #[ cfg( feature = "mem" ) ]
405
- pub mod $name {
338
+ #[ cfg( all ( feature = "mem" , not ( feature = "mangled-names" ) ) ) ]
339
+ mod $name {
406
340
$( #[ $( $attr) * ] ) *
407
- #[ cfg_attr ( not ( feature = "mangled-names" ) , no_mangle) ]
408
- #[ cfg_attr( feature = "weak-intrinsics" , linkage = "weak" ) ]
409
- pub unsafe extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
341
+ #[ no_mangle]
342
+ #[ cfg_attr( all ( not ( windows ) , not ( target_vendor = "apple" ) ) , linkage = "weak" ) ]
343
+ unsafe extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
410
344
super :: $name( $( $argname) ,* )
411
345
}
412
346
}
@@ -425,11 +359,12 @@ macro_rules! intrinsics {
425
359
426
360
$( $rest: tt) *
427
361
) => (
362
+ // `#[naked]` definitions are referenced by other places, so we can't use `cfg` like the others
428
363
pub mod $name {
429
364
#[ naked]
430
365
$( #[ $( $attr) * ] ) *
431
366
#[ cfg_attr( not( feature = "mangled-names" ) , no_mangle) ]
432
- #[ cfg_attr( feature = "weak-intrinsics" , linkage = "weak" ) ]
367
+ #[ cfg_attr( all ( not ( windows ) , not ( target_vendor = "apple" ) ) , linkage = "weak" ) ]
433
368
pub unsafe extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
434
369
$( $body) *
435
370
}
@@ -492,11 +427,12 @@ macro_rules! intrinsics {
492
427
$( $body) *
493
428
}
494
429
495
- pub mod $name {
430
+ #[ cfg( not( feature = "mangled-names" ) ) ]
431
+ mod $name {
496
432
$( #[ $( $attr) * ] ) *
497
- #[ cfg_attr ( not ( feature = "mangled-names" ) , no_mangle) ]
498
- #[ cfg_attr( feature = "weak-intrinsics" , linkage = "weak" ) ]
499
- pub extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
433
+ #[ no_mangle]
434
+ #[ cfg_attr( all ( not ( windows ) , not ( target_vendor = "apple" ) ) , linkage = "weak" ) ]
435
+ extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
500
436
super :: $name( $( $argname) ,* )
501
437
}
502
438
}
@@ -518,11 +454,12 @@ macro_rules! intrinsics {
518
454
$( $body) *
519
455
}
520
456
521
- pub mod $name {
457
+ #[ cfg( not( feature = "mangled-names" ) ) ]
458
+ mod $name {
522
459
$( #[ $( $attr) * ] ) *
523
- #[ cfg_attr ( not ( feature = "mangled-names" ) , no_mangle) ]
524
- #[ cfg_attr( feature = "weak-intrinsics" , linkage = "weak" ) ]
525
- pub unsafe extern $abi fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
460
+ #[ no_mangle]
461
+ #[ cfg_attr( all ( not ( windows ) , not ( target_vendor = "apple" ) ) , linkage = "weak" ) ]
462
+ unsafe fn $name( $( $argname: $ty) ,* ) $( -> $ret) ? {
526
463
super :: $name( $( $argname) ,* )
527
464
}
528
465
}
0 commit comments