@@ -29,7 +29,21 @@ use crate::ptr;
29
29
use crate :: sync:: atomic:: { self , AtomicPtr , Ordering } ;
30
30
31
31
// We can use true weak linkage on ELF targets.
32
- #[ cfg( not( any( target_os = "macos" , target_os = "ios" ) ) ) ]
32
+ #[ cfg( all( not( any( target_os = "macos" , target_os = "ios" ) ) , not( bootstrap) ) ) ]
33
+ pub ( crate ) macro weak {
34
+ ( fn $name: ident( $( $t: ty) , * ) -> $ret: ty) => (
35
+ let ref $name: ExternWeak <unsafe extern "C" fn ( $( $t) , * ) -> $ret> = {
36
+ extern "C" {
37
+ #[ linkage = "extern_weak" ]
38
+ static $name: Option <unsafe extern "C" fn ( $( $t) , * ) -> $ret>;
39
+ }
40
+ #[ allow( unused_unsafe) ]
41
+ ExternWeak :: new ( unsafe { $name } )
42
+ } ;
43
+ )
44
+ }
45
+
46
+ #[ cfg( all( not( any( target_os = "macos" , target_os = "ios" ) ) , bootstrap) ) ]
33
47
pub( crate ) macro weak {
34
48
( fn $name: ident( $( $t: ty) , * ) -> $ret: ty) => (
35
49
let ref $name: ExternWeak <unsafe extern "C" fn ( $( $t) , * ) -> $ret> = {
@@ -47,18 +61,39 @@ pub(crate) macro weak {
47
61
#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
48
62
pub( crate ) use self :: dlsym as weak ;
49
63
64
+ #[ cfg( not( bootstrap) ) ]
65
+ pub( crate ) struct ExternWeak <F : Copy > {
66
+ weak_ptr: Option <F >,
67
+ }
68
+
69
+ #[ cfg( not( bootstrap) ) ]
70
+ impl<F : Copy > ExternWeak <F > {
71
+ #[ inline]
72
+ pub ( crate ) fn new ( weak_ptr : Option < F > ) -> Self {
73
+ ExternWeak { weak_ptr }
74
+ }
75
+
76
+ #[ inline]
77
+ pub ( crate ) fn get ( & self ) -> Option < F > {
78
+ self . weak_ptr
79
+ }
80
+ }
81
+
82
+ #[ cfg( bootstrap) ]
50
83
pub ( crate ) struct ExternWeak < F > {
51
84
weak_ptr : * const libc:: c_void ,
52
85
_marker : PhantomData < F > ,
53
86
}
54
87
88
+ #[ cfg( bootstrap) ]
55
89
impl < F > ExternWeak < F > {
56
90
#[ inline]
57
91
pub ( crate ) fn new ( weak_ptr : * const libc:: c_void ) -> Self {
58
92
ExternWeak { weak_ptr, _marker : PhantomData }
59
93
}
60
94
}
61
95
96
+ #[ cfg( bootstrap) ]
62
97
impl < F > ExternWeak < F > {
63
98
#[ inline]
64
99
pub ( crate ) fn get ( & self ) -> Option < F > {
0 commit comments