]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_llvm/src/consts.rs
Rollup merge of #97436 - compiler-errors:macos-ping-2, r=Mark-Simulacrum
[rust.git] / compiler / rustc_codegen_llvm / src / consts.rs
1 use crate::base;
2 use crate::common::CodegenCx;
3 use crate::debuginfo;
4 use crate::llvm::{self, True};
5 use crate::llvm_util;
6 use crate::type_::Type;
7 use crate::type_of::LayoutLlvmExt;
8 use crate::value::Value;
9 use cstr::cstr;
10 use libc::c_uint;
11 use rustc_codegen_ssa::traits::*;
12 use rustc_hir::def_id::DefId;
13 use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
14 use rustc_middle::mir::interpret::{
15     read_target_uint, Allocation, ConstAllocation, ErrorHandled, GlobalAlloc, InitChunk, Pointer,
16     Scalar as InterpScalar,
17 };
18 use rustc_middle::mir::mono::MonoItem;
19 use rustc_middle::ty::layout::LayoutOf;
20 use rustc_middle::ty::{self, Instance, Ty};
21 use rustc_middle::{bug, span_bug};
22 use rustc_target::abi::{
23     AddressSpace, Align, HasDataLayout, Primitive, Scalar, Size, WrappingRange,
24 };
25 use std::ops::Range;
26 use tracing::debug;
27
28 pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<'_>) -> &'ll Value {
29     let alloc = alloc.inner();
30     let mut llvals = Vec::with_capacity(alloc.relocations().len() + 1);
31     let dl = cx.data_layout();
32     let pointer_size = dl.pointer_size.bytes() as usize;
33
34     // Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`,
35     // so `range` must be within the bounds of `alloc` and not contain or overlap a relocation.
36     fn append_chunks_of_init_and_uninit_bytes<'ll, 'a, 'b>(
37         llvals: &mut Vec<&'ll Value>,
38         cx: &'a CodegenCx<'ll, 'b>,
39         alloc: &'a Allocation,
40         range: Range<usize>,
41     ) {
42         let chunks = alloc
43             .init_mask()
44             .range_as_init_chunks(Size::from_bytes(range.start), Size::from_bytes(range.end));
45
46         let chunk_to_llval = move |chunk| match chunk {
47             InitChunk::Init(range) => {
48                 let range = (range.start.bytes() as usize)..(range.end.bytes() as usize);
49                 let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range);
50                 cx.const_bytes(bytes)
51             }
52             InitChunk::Uninit(range) => {
53                 let len = range.end.bytes() - range.start.bytes();
54                 cx.const_undef(cx.type_array(cx.type_i8(), len))
55             }
56         };
57
58         // Generating partially-uninit consts is limited to small numbers of chunks,
59         // to avoid the cost of generating large complex const expressions.
60         // For example, `[(u32, u8); 1024 * 1024]` contains uninit padding in each element,
61         // and would result in `{ [5 x i8] zeroinitializer, [3 x i8] undef, ...repeat 1M times... }`.
62         let max = if llvm_util::get_version() < (14, 0, 0) {
63             // Generating partially-uninit consts inhibits optimizations in LLVM < 14.
64             // See https://github.com/rust-lang/rust/issues/84565.
65             1
66         } else {
67             cx.sess().opts.debugging_opts.uninit_const_chunk_threshold
68         };
69         let allow_uninit_chunks = chunks.clone().take(max.saturating_add(1)).count() <= max;
70
71         if allow_uninit_chunks {
72             llvals.extend(chunks.map(chunk_to_llval));
73         } else {
74             // If this allocation contains any uninit bytes, codegen as if it was initialized
75             // (using some arbitrary value for uninit bytes).
76             let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range);
77             llvals.push(cx.const_bytes(bytes));
78         }
79     }
80
81     let mut next_offset = 0;
82     for &(offset, alloc_id) in alloc.relocations().iter() {
83         let offset = offset.bytes();
84         assert_eq!(offset as usize as u64, offset);
85         let offset = offset as usize;
86         if offset > next_offset {
87             // This `inspect` is okay since we have checked that it is not within a relocation, it
88             // is within the bounds of the allocation, and it doesn't affect interpreter execution
89             // (we inspect the result after interpreter execution).
90             append_chunks_of_init_and_uninit_bytes(&mut llvals, cx, alloc, next_offset..offset);
91         }
92         let ptr_offset = read_target_uint(
93             dl.endian,
94             // This `inspect` is okay since it is within the bounds of the allocation, it doesn't
95             // affect interpreter execution (we inspect the result after interpreter execution),
96             // and we properly interpret the relocation as a relocation pointer offset.
97             alloc.inspect_with_uninit_and_ptr_outside_interpreter(offset..(offset + pointer_size)),
98         )
99         .expect("const_alloc_to_llvm: could not read relocation pointer")
100             as u64;
101
102         let address_space = match cx.tcx.global_alloc(alloc_id) {
103             GlobalAlloc::Function(..) => cx.data_layout().instruction_address_space,
104             GlobalAlloc::Static(..) | GlobalAlloc::Memory(..) => AddressSpace::DATA,
105         };
106
107         llvals.push(cx.scalar_to_backend(
108             InterpScalar::from_pointer(
109                 Pointer::new(alloc_id, Size::from_bytes(ptr_offset)),
110                 &cx.tcx,
111             ),
112             Scalar::Initialized {
113                 value: Primitive::Pointer,
114                 valid_range: WrappingRange::full(dl.pointer_size),
115             },
116             cx.type_i8p_ext(address_space),
117         ));
118         next_offset = offset + pointer_size;
119     }
120     if alloc.len() >= next_offset {
121         let range = next_offset..alloc.len();
122         // This `inspect` is okay since we have check that it is after all relocations, it is
123         // within the bounds of the allocation, and it doesn't affect interpreter execution (we
124         // inspect the result after interpreter execution).
125         append_chunks_of_init_and_uninit_bytes(&mut llvals, cx, alloc, range);
126     }
127
128     cx.const_struct(&llvals, true)
129 }
130
131 pub fn codegen_static_initializer<'ll, 'tcx>(
132     cx: &CodegenCx<'ll, 'tcx>,
133     def_id: DefId,
134 ) -> Result<(&'ll Value, ConstAllocation<'tcx>), ErrorHandled> {
135     let alloc = cx.tcx.eval_static_initializer(def_id)?;
136     Ok((const_alloc_to_llvm(cx, alloc), alloc))
137 }
138
139 fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align: Align) {
140     // The target may require greater alignment for globals than the type does.
141     // Note: GCC and Clang also allow `__attribute__((aligned))` on variables,
142     // which can force it to be smaller.  Rust doesn't support this yet.
143     if let Some(min) = cx.sess().target.min_global_align {
144         match Align::from_bits(min) {
145             Ok(min) => align = align.max(min),
146             Err(err) => {
147                 cx.sess().err(&format!("invalid minimum global alignment: {}", err));
148             }
149         }
150     }
151     unsafe {
152         llvm::LLVMSetAlignment(gv, align.bytes() as u32);
153     }
154 }
155
156 fn check_and_apply_linkage<'ll, 'tcx>(
157     cx: &CodegenCx<'ll, 'tcx>,
158     attrs: &CodegenFnAttrs,
159     ty: Ty<'tcx>,
160     sym: &str,
161     span_def_id: DefId,
162 ) -> &'ll Value {
163     let llty = cx.layout_of(ty).llvm_type(cx);
164     if let Some(linkage) = attrs.linkage {
165         debug!("get_static: sym={} linkage={:?}", sym, linkage);
166
167         // If this is a static with a linkage specified, then we need to handle
168         // it a little specially. The typesystem prevents things like &T and
169         // extern "C" fn() from being non-null, so we can't just declare a
170         // static and call it a day. Some linkages (like weak) will make it such
171         // that the static actually has a null value.
172         let llty2 = if let ty::RawPtr(ref mt) = ty.kind() {
173             cx.layout_of(mt.ty).llvm_type(cx)
174         } else {
175             cx.sess().span_fatal(
176                 cx.tcx.def_span(span_def_id),
177                 "must have type `*const T` or `*mut T` due to `#[linkage]` attribute",
178             )
179         };
180         unsafe {
181             // Declare a symbol `foo` with the desired linkage.
182             let g1 = cx.declare_global(sym, llty2);
183             llvm::LLVMRustSetLinkage(g1, base::linkage_to_llvm(linkage));
184
185             // Declare an internal global `extern_with_linkage_foo` which
186             // is initialized with the address of `foo`.  If `foo` is
187             // discarded during linking (for example, if `foo` has weak
188             // linkage and there are no definitions), then
189             // `extern_with_linkage_foo` will instead be initialized to
190             // zero.
191             let mut real_name = "_rust_extern_with_linkage_".to_string();
192             real_name.push_str(sym);
193             let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
194                 cx.sess().span_fatal(
195                     cx.tcx.def_span(span_def_id),
196                     &format!("symbol `{}` is already defined", &sym),
197                 )
198             });
199             llvm::LLVMRustSetLinkage(g2, llvm::Linkage::InternalLinkage);
200             llvm::LLVMSetInitializer(g2, g1);
201             g2
202         }
203     } else {
204         // Generate an external declaration.
205         // FIXME(nagisa): investigate whether it can be changed into define_global
206         cx.declare_global(sym, llty)
207     }
208 }
209
210 pub fn ptrcast<'ll>(val: &'ll Value, ty: &'ll Type) -> &'ll Value {
211     unsafe { llvm::LLVMConstPointerCast(val, ty) }
212 }
213
214 impl<'ll> CodegenCx<'ll, '_> {
215     pub(crate) fn const_bitcast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value {
216         unsafe { llvm::LLVMConstBitCast(val, ty) }
217     }
218
219     pub(crate) fn static_addr_of_mut(
220         &self,
221         cv: &'ll Value,
222         align: Align,
223         kind: Option<&str>,
224     ) -> &'ll Value {
225         unsafe {
226             let gv = match kind {
227                 Some(kind) if !self.tcx.sess.fewer_names() => {
228                     let name = self.generate_local_symbol_name(kind);
229                     let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
230                         bug!("symbol `{}` is already defined", name);
231                     });
232                     llvm::LLVMRustSetLinkage(gv, llvm::Linkage::PrivateLinkage);
233                     gv
234                 }
235                 _ => self.define_private_global(self.val_ty(cv)),
236             };
237             llvm::LLVMSetInitializer(gv, cv);
238             set_global_alignment(self, gv, align);
239             llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
240             gv
241         }
242     }
243
244     pub(crate) fn get_static(&self, def_id: DefId) -> &'ll Value {
245         let instance = Instance::mono(self.tcx, def_id);
246         if let Some(&g) = self.instances.borrow().get(&instance) {
247             return g;
248         }
249
250         let defined_in_current_codegen_unit =
251             self.codegen_unit.items().contains_key(&MonoItem::Static(def_id));
252         assert!(
253             !defined_in_current_codegen_unit,
254             "consts::get_static() should always hit the cache for \
255                  statics defined in the same CGU, but did not for `{:?}`",
256             def_id
257         );
258
259         let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
260         let sym = self.tcx.symbol_name(instance).name;
261         let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
262
263         debug!("get_static: sym={} instance={:?} fn_attrs={:?}", sym, instance, fn_attrs);
264
265         let g = if def_id.is_local() && !self.tcx.is_foreign_item(def_id) {
266             let llty = self.layout_of(ty).llvm_type(self);
267             if let Some(g) = self.get_declared_value(sym) {
268                 if self.val_ty(g) != self.type_ptr_to(llty) {
269                     span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
270                 }
271             }
272
273             let g = self.declare_global(sym, llty);
274
275             if !self.tcx.is_reachable_non_generic(def_id) {
276                 unsafe {
277                     llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden);
278                 }
279             }
280
281             g
282         } else {
283             check_and_apply_linkage(self, fn_attrs, ty, sym, def_id)
284         };
285
286         // Thread-local statics in some other crate need to *always* be linked
287         // against in a thread-local fashion, so we need to be sure to apply the
288         // thread-local attribute locally if it was present remotely. If we
289         // don't do this then linker errors can be generated where the linker
290         // complains that one object files has a thread local version of the
291         // symbol and another one doesn't.
292         if fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
293             llvm::set_thread_local_mode(g, self.tls_model);
294         }
295
296         if !def_id.is_local() {
297             let needs_dll_storage_attr = self.use_dll_storage_attrs && !self.tcx.is_foreign_item(def_id) &&
298                 // ThinLTO can't handle this workaround in all cases, so we don't
299                 // emit the attrs. Instead we make them unnecessary by disallowing
300                 // dynamic linking when linker plugin based LTO is enabled.
301                 !self.tcx.sess.opts.cg.linker_plugin_lto.enabled();
302
303             // If this assertion triggers, there's something wrong with commandline
304             // argument validation.
305             debug_assert!(
306                 !(self.tcx.sess.opts.cg.linker_plugin_lto.enabled()
307                     && self.tcx.sess.target.is_like_windows
308                     && self.tcx.sess.opts.cg.prefer_dynamic)
309             );
310
311             if needs_dll_storage_attr {
312                 // This item is external but not foreign, i.e., it originates from an external Rust
313                 // crate. Since we don't know whether this crate will be linked dynamically or
314                 // statically in the final application, we always mark such symbols as 'dllimport'.
315                 // If final linkage happens to be static, we rely on compiler-emitted __imp_ stubs
316                 // to make things work.
317                 //
318                 // However, in some scenarios we defer emission of statics to downstream
319                 // crates, so there are cases where a static with an upstream DefId
320                 // is actually present in the current crate. We can find out via the
321                 // is_codegened_item query.
322                 if !self.tcx.is_codegened_item(def_id) {
323                     unsafe {
324                         llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);
325                     }
326                 }
327             }
328         }
329
330         if self.use_dll_storage_attrs && self.tcx.is_dllimport_foreign_item(def_id) {
331             // For foreign (native) libs we know the exact storage type to use.
332             unsafe {
333                 llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);
334             }
335         }
336
337         unsafe {
338             if self.should_assume_dso_local(g, true) {
339                 llvm::LLVMRustSetDSOLocal(g, true);
340             }
341         }
342
343         self.instances.borrow_mut().insert(instance, g);
344         g
345     }
346 }
347
348 impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
349     fn static_addr_of(&self, cv: &'ll Value, align: Align, kind: Option<&str>) -> &'ll Value {
350         if let Some(&gv) = self.const_globals.borrow().get(&cv) {
351             unsafe {
352                 // Upgrade the alignment in cases where the same constant is used with different
353                 // alignment requirements
354                 let llalign = align.bytes() as u32;
355                 if llalign > llvm::LLVMGetAlignment(gv) {
356                     llvm::LLVMSetAlignment(gv, llalign);
357                 }
358             }
359             return gv;
360         }
361         let gv = self.static_addr_of_mut(cv, align, kind);
362         unsafe {
363             llvm::LLVMSetGlobalConstant(gv, True);
364         }
365         self.const_globals.borrow_mut().insert(cv, gv);
366         gv
367     }
368
369     fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
370         unsafe {
371             let attrs = self.tcx.codegen_fn_attrs(def_id);
372
373             let Ok((v, alloc)) = codegen_static_initializer(self, def_id) else {
374                 // Error has already been reported
375                 return;
376             };
377             let alloc = alloc.inner();
378
379             let g = self.get_static(def_id);
380
381             // boolean SSA values are i1, but they have to be stored in i8 slots,
382             // otherwise some LLVM optimization passes don't work as expected
383             let mut val_llty = self.val_ty(v);
384             let v = if val_llty == self.type_i1() {
385                 val_llty = self.type_i8();
386                 llvm::LLVMConstZExt(v, val_llty)
387             } else {
388                 v
389             };
390
391             let instance = Instance::mono(self.tcx, def_id);
392             let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
393             let llty = self.layout_of(ty).llvm_type(self);
394             let g = if val_llty == llty {
395                 g
396             } else {
397                 // If we created the global with the wrong type,
398                 // correct the type.
399                 let name = llvm::get_value_name(g).to_vec();
400                 llvm::set_value_name(g, b"");
401
402                 let linkage = llvm::LLVMRustGetLinkage(g);
403                 let visibility = llvm::LLVMRustGetVisibility(g);
404
405                 let new_g = llvm::LLVMRustGetOrInsertGlobal(
406                     self.llmod,
407                     name.as_ptr().cast(),
408                     name.len(),
409                     val_llty,
410                 );
411
412                 llvm::LLVMRustSetLinkage(new_g, linkage);
413                 llvm::LLVMRustSetVisibility(new_g, visibility);
414
415                 // The old global has had its name removed but is returned by
416                 // get_static since it is in the instance cache. Provide an
417                 // alternative lookup that points to the new global so that
418                 // global_asm! can compute the correct mangled symbol name
419                 // for the global.
420                 self.renamed_statics.borrow_mut().insert(def_id, new_g);
421
422                 // To avoid breaking any invariants, we leave around the old
423                 // global for the moment; we'll replace all references to it
424                 // with the new global later. (See base::codegen_backend.)
425                 self.statics_to_rauw.borrow_mut().push((g, new_g));
426                 new_g
427             };
428             set_global_alignment(self, g, self.align_of(ty));
429             llvm::LLVMSetInitializer(g, v);
430
431             if self.should_assume_dso_local(g, true) {
432                 llvm::LLVMRustSetDSOLocal(g, true);
433             }
434
435             // As an optimization, all shared statics which do not have interior
436             // mutability are placed into read-only memory.
437             if !is_mutable && self.type_is_freeze(ty) {
438                 llvm::LLVMSetGlobalConstant(g, llvm::True);
439             }
440
441             debuginfo::build_global_var_di_node(self, def_id, g);
442
443             if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
444                 llvm::set_thread_local_mode(g, self.tls_model);
445
446                 // Do not allow LLVM to change the alignment of a TLS on macOS.
447                 //
448                 // By default a global's alignment can be freely increased.
449                 // This allows LLVM to generate more performant instructions
450                 // e.g., using load-aligned into a SIMD register.
451                 //
452                 // However, on macOS 10.10 or below, the dynamic linker does not
453                 // respect any alignment given on the TLS (radar 24221680).
454                 // This will violate the alignment assumption, and causing segfault at runtime.
455                 //
456                 // This bug is very easy to trigger. In `println!` and `panic!`,
457                 // the `LOCAL_STDOUT`/`LOCAL_STDERR` handles are stored in a TLS,
458                 // which the values would be `mem::replace`d on initialization.
459                 // The implementation of `mem::replace` will use SIMD
460                 // whenever the size is 32 bytes or higher. LLVM notices SIMD is used
461                 // and tries to align `LOCAL_STDOUT`/`LOCAL_STDERR` to a 32-byte boundary,
462                 // which macOS's dyld disregarded and causing crashes
463                 // (see issues #51794, #51758, #50867, #48866 and #44056).
464                 //
465                 // To workaround the bug, we trick LLVM into not increasing
466                 // the global's alignment by explicitly assigning a section to it
467                 // (equivalent to automatically generating a `#[link_section]` attribute).
468                 // See the comment in the `GlobalValue::canIncreaseAlignment()` function
469                 // of `lib/IR/Globals.cpp` for why this works.
470                 //
471                 // When the alignment is not increased, the optimized `mem::replace`
472                 // will use load-unaligned instructions instead, and thus avoiding the crash.
473                 //
474                 // We could remove this hack whenever we decide to drop macOS 10.10 support.
475                 if self.tcx.sess.target.is_like_osx {
476                     // The `inspect` method is okay here because we checked relocations, and
477                     // because we are doing this access to inspect the final interpreter state
478                     // (not as part of the interpreter execution).
479                     //
480                     // FIXME: This check requires that the (arbitrary) value of undefined bytes
481                     // happens to be zero. Instead, we should only check the value of defined bytes
482                     // and set all undefined bytes to zero if this allocation is headed for the
483                     // BSS.
484                     let all_bytes_are_zero = alloc.relocations().is_empty()
485                         && alloc
486                             .inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len())
487                             .iter()
488                             .all(|&byte| byte == 0);
489
490                     let sect_name = if all_bytes_are_zero {
491                         cstr!("__DATA,__thread_bss")
492                     } else {
493                         cstr!("__DATA,__thread_data")
494                     };
495                     llvm::LLVMSetSection(g, sect_name.as_ptr());
496                 }
497             }
498
499             // Wasm statics with custom link sections get special treatment as they
500             // go into custom sections of the wasm executable.
501             if self.tcx.sess.target.is_like_wasm {
502                 if let Some(section) = attrs.link_section {
503                     let section = llvm::LLVMMDStringInContext(
504                         self.llcx,
505                         section.as_str().as_ptr().cast(),
506                         section.as_str().len() as c_uint,
507                     );
508                     assert!(alloc.relocations().is_empty());
509
510                     // The `inspect` method is okay here because we checked relocations, and
511                     // because we are doing this access to inspect the final interpreter state (not
512                     // as part of the interpreter execution).
513                     let bytes =
514                         alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len());
515                     let alloc = llvm::LLVMMDStringInContext(
516                         self.llcx,
517                         bytes.as_ptr().cast(),
518                         bytes.len() as c_uint,
519                     );
520                     let data = [section, alloc];
521                     let meta = llvm::LLVMMDNodeInContext(self.llcx, data.as_ptr(), 2);
522                     llvm::LLVMAddNamedMetadataOperand(
523                         self.llmod,
524                         "wasm.custom_sections\0".as_ptr().cast(),
525                         meta,
526                     );
527                 }
528             } else {
529                 base::set_link_section(g, attrs);
530             }
531
532             if attrs.flags.contains(CodegenFnAttrFlags::USED) {
533                 // `USED` and `USED_LINKER` can't be used together.
534                 assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER));
535
536                 // The semantics of #[used] in Rust only require the symbol to make it into the
537                 // object file. It is explicitly allowed for the linker to strip the symbol if it
538                 // is dead. As such, use llvm.compiler.used instead of llvm.used.
539                 // Additionally, https://reviews.llvm.org/D97448 in LLVM 13 started emitting unique
540                 // sections with SHF_GNU_RETAIN flag for llvm.used symbols, which may trigger bugs
541                 // in some versions of the gold linker.
542                 self.add_compiler_used_global(g);
543             }
544             if attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) {
545                 // `USED` and `USED_LINKER` can't be used together.
546                 assert!(!attrs.flags.contains(CodegenFnAttrFlags::USED));
547
548                 self.add_used_global(g);
549             }
550         }
551     }
552
553     /// Add a global value to a list to be stored in the `llvm.used` variable, an array of i8*.
554     fn add_used_global(&self, global: &'ll Value) {
555         let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_i8p()) };
556         self.used_statics.borrow_mut().push(cast);
557     }
558
559     /// Add a global value to a list to be stored in the `llvm.compiler.used` variable,
560     /// an array of i8*.
561     fn add_compiler_used_global(&self, global: &'ll Value) {
562         let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_i8p()) };
563         self.compiler_used_statics.borrow_mut().push(cast);
564     }
565 }