File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -1087,8 +1087,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1087
1087
"failed to evaluate static in required link_section: {def_id:?}\n {err:?}"
1088
1088
)
1089
1089
} ) ;
1090
- let val = this. read_immediate ( & const_val) ?;
1091
- array. push ( val) ;
1090
+ match const_val. layout . ty . kind ( ) {
1091
+ ty:: FnPtr ( ..) => {
1092
+ array. push ( this. read_immediate ( & const_val) ?) ;
1093
+ }
1094
+ ty:: Array ( elem_ty, _) if matches ! ( elem_ty. kind( ) , ty:: FnPtr ( ..) ) => {
1095
+ let mut elems = this. project_array_fields ( & const_val) ?;
1096
+ while let Some ( ( _idx, elem) ) = elems. next ( this) ? {
1097
+ array. push ( this. read_immediate ( & elem) ?) ;
1098
+ }
1099
+ }
1100
+ _ =>
1101
+ throw_unsup_format ! (
1102
+ "only function pointers and arrays of function pointers are supported in well-known linker sections"
1103
+ ) ,
1104
+ }
1092
1105
}
1093
1106
interp_ok ( ( ) )
1094
1107
} ) ?;
Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ use std::sync::atomic::{AtomicUsize, Ordering};
2
2
3
3
static COUNT : AtomicUsize = AtomicUsize :: new ( 0 ) ;
4
4
5
- unsafe extern "C" fn ctor ( ) {
6
- COUNT . fetch_add ( 1 , Ordering :: Relaxed ) ;
5
+ unsafe extern "C" fn ctor < const N : usize > ( ) {
6
+ COUNT . fetch_add ( N , Ordering :: Relaxed ) ;
7
7
}
8
8
9
9
#[ rustfmt:: skip]
10
10
macro_rules! ctor {
11
- ( $ident: ident = $ctor: ident ) => {
11
+ ( $ident: ident: $ty : ty = $ctor: expr ) => {
12
12
#[ cfg_attr(
13
13
all( any(
14
14
target_os = "linux" ,
@@ -33,14 +33,13 @@ macro_rules! ctor {
33
33
link_section = "__DATA,__mod_init_func"
34
34
) ]
35
35
#[ used]
36
- static $ident: unsafe extern "C" fn ( ) = $ctor;
36
+ static $ident: $ty = $ctor;
37
37
} ;
38
38
}
39
39
40
- ctor ! { CTOR1 = ctor }
41
- ctor ! { CTOR2 = ctor }
42
- ctor ! { CTOR3 = ctor }
40
+ ctor ! { CTOR1 : unsafe extern "C" fn ( ) = ctor:: <1 > }
41
+ ctor ! { CTOR2 : [ unsafe extern "C" fn ( ) ; 2 ] = [ ctor:: <2 >, ctor:: <3 >] }
43
42
44
43
fn main ( ) {
45
- assert_eq ! ( COUNT . load( Ordering :: Relaxed ) , 3 , "ctors did not run" ) ;
44
+ assert_eq ! ( COUNT . load( Ordering :: Relaxed ) , 6 , "ctors did not run" ) ;
46
45
}
You can’t perform that action at this time.
0 commit comments