@@ -341,7 +341,7 @@ pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id
341
341
342
342
fn check_and_apply_linkage < ' gcc , ' tcx > ( cx : & CodegenCx < ' gcc , ' tcx > , attrs : & CodegenFnAttrs , ty : Ty < ' tcx > , sym : & str ) -> LValue < ' gcc > {
343
343
let is_tls = attrs. flags . contains ( CodegenFnAttrFlags :: THREAD_LOCAL ) ;
344
- let llty = cx. layout_of ( ty) . gcc_type ( cx) ;
344
+ let gcc_type = cx. layout_of ( ty) . gcc_type ( cx) ;
345
345
if let Some ( linkage) = attrs. import_linkage {
346
346
// Declare a symbol `foo` with the desired linkage.
347
347
let global1 = cx. declare_global_with_linkage ( & sym, cx. type_i8 ( ) , base:: global_linkage_to_gcc ( linkage) ) ;
@@ -354,9 +354,10 @@ fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &Codeg
354
354
// zero.
355
355
let mut real_name = "_rust_extern_with_linkage_" . to_string ( ) ;
356
356
real_name. push_str ( & sym) ;
357
- let global2 = cx. define_global ( & real_name, llty , is_tls, attrs. link_section ) ;
357
+ let global2 = cx. define_global ( & real_name, gcc_type , is_tls, attrs. link_section ) ;
358
358
// TODO(antoyo): set linkage.
359
- global2. global_set_initializer_rvalue ( global1. get_address ( None ) ) ;
359
+ let value = cx. const_ptrcast ( global1. get_address ( None ) , gcc_type) ;
360
+ global2. global_set_initializer_rvalue ( value) ;
360
361
// TODO(antoyo): use global_set_initializer() when it will work.
361
362
global2
362
363
}
@@ -370,6 +371,6 @@ fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &Codeg
370
371
// don't do this then linker errors can be generated where the linker
371
372
// complains that one object files has a thread local version of the
372
373
// symbol and another one doesn't.
373
- cx. declare_global ( & sym, llty , GlobalKind :: Imported , is_tls, attrs. link_section )
374
+ cx. declare_global ( & sym, gcc_type , GlobalKind :: Imported , is_tls, attrs. link_section )
374
375
}
375
376
}
0 commit comments