@@ -8,13 +8,11 @@ use rustc_middle::mir::mono::MonoItem;
8
8
use rustc_middle:: ty:: { self , Instance , Ty } ;
9
9
use rustc_middle:: ty:: layout:: LayoutOf ;
10
10
use rustc_middle:: mir:: interpret:: { self , ConstAllocation , ErrorHandled , Scalar as InterpScalar , read_target_uint} ;
11
- use rustc_span:: Span ;
12
11
use rustc_span:: def_id:: DefId ;
13
12
use rustc_target:: abi:: { self , Align , HasDataLayout , Primitive , Size , WrappingRange } ;
14
13
15
14
use crate :: base;
16
15
use crate :: context:: CodegenCx ;
17
- use crate :: errors:: LinkageConstOrMutType ;
18
16
use crate :: type_of:: LayoutGccExt ;
19
17
20
18
impl < ' gcc , ' tcx > CodegenCx < ' gcc , ' tcx > {
@@ -239,12 +237,12 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
239
237
}
240
238
241
239
Node :: ForeignItem ( & hir:: ForeignItem {
242
- span,
240
+ span : _ ,
243
241
kind : hir:: ForeignItemKind :: Static ( ..) ,
244
242
..
245
243
} ) => {
246
244
let fn_attrs = self . tcx . codegen_fn_attrs ( def_id) ;
247
- check_and_apply_linkage ( & self , & fn_attrs, ty, sym, span )
245
+ check_and_apply_linkage ( & self , & fn_attrs, ty, sym)
248
246
}
249
247
250
248
item => bug ! ( "get_static: expected static, found {:?}" , item) ,
@@ -257,8 +255,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
257
255
//debug!("get_static: sym={} item_attr={:?}", sym, self.tcx.item_attrs(def_id));
258
256
259
257
let attrs = self . tcx . codegen_fn_attrs ( def_id) ;
260
- let span = self . tcx . def_span ( def_id) ;
261
- let global = check_and_apply_linkage ( & self , & attrs, ty, sym, span) ;
258
+ let global = check_and_apply_linkage ( & self , & attrs, ty, sym) ;
262
259
263
260
let needs_dll_storage_attr = false ; // TODO(antoyo)
264
261
@@ -355,24 +352,12 @@ pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id
355
352
Ok ( ( const_alloc_to_gcc ( cx, alloc) , alloc) )
356
353
}
357
354
358
- fn check_and_apply_linkage < ' gcc , ' tcx > ( cx : & CodegenCx < ' gcc , ' tcx > , attrs : & CodegenFnAttrs , ty : Ty < ' tcx > , sym : & str , span : Span ) -> LValue < ' gcc > {
355
+ fn check_and_apply_linkage < ' gcc , ' tcx > ( cx : & CodegenCx < ' gcc , ' tcx > , attrs : & CodegenFnAttrs , ty : Ty < ' tcx > , sym : & str ) -> LValue < ' gcc > {
359
356
let is_tls = attrs. flags . contains ( CodegenFnAttrFlags :: THREAD_LOCAL ) ;
360
357
let llty = cx. layout_of ( ty) . gcc_type ( cx, true ) ;
361
- if let Some ( linkage) = attrs. linkage {
362
- // If this is a static with a linkage specified, then we need to handle
363
- // it a little specially. The typesystem prevents things like &T and
364
- // extern "C" fn() from being non-null, so we can't just declare a
365
- // static and call it a day. Some linkages (like weak) will make it such
366
- // that the static actually has a null value.
367
- let llty2 =
368
- if let ty:: RawPtr ( ref mt) = ty. kind ( ) {
369
- cx. layout_of ( mt. ty ) . gcc_type ( cx, true )
370
- }
371
- else {
372
- cx. sess ( ) . emit_fatal ( LinkageConstOrMutType { span : span } )
373
- } ;
358
+ if let Some ( linkage) = attrs. import_linkage {
374
359
// Declare a symbol `foo` with the desired linkage.
375
- let global1 = cx. declare_global_with_linkage ( & sym, llty2 , base:: global_linkage_to_gcc ( linkage) ) ;
360
+ let global1 = cx. declare_global_with_linkage ( & sym, cx . type_i8 ( ) , base:: global_linkage_to_gcc ( linkage) ) ;
376
361
377
362
// Declare an internal global `extern_with_linkage_foo` which
378
363
// is initialized with the address of `foo`. If `foo` is
0 commit comments