@@ -341,7 +341,7 @@ pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id
341341
342342fn check_and_apply_linkage < ' gcc , ' tcx > ( cx : & CodegenCx < ' gcc , ' tcx > , attrs : & CodegenFnAttrs , ty : Ty < ' tcx > , sym : & str ) -> LValue < ' gcc > {
343343 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) ;
345345 if let Some ( linkage) = attrs. import_linkage {
346346 // Declare a symbol `foo` with the desired linkage.
347347 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
354354 // zero.
355355 let mut real_name = "_rust_extern_with_linkage_" . to_string ( ) ;
356356 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 ) ;
358358 // 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) ;
360361 // TODO(antoyo): use global_set_initializer() when it will work.
361362 global2
362363 }
@@ -370,6 +371,6 @@ fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &Codeg
370371 // don't do this then linker errors can be generated where the linker
371372 // complains that one object files has a thread local version of the
372373 // 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 )
374375 }
375376}
0 commit comments