rust/compiler/rustc_codegen_gcc/src/mono_item.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
3.0 KiB
Rust
Raw Normal View History

2022-07-24 16:33:38 -05:00
#[cfg(feature="master")]
use gccjit::{VarAttribute, FnAttribute};
2020-05-10 09:54:30 -05:00
use rustc_codegen_ssa::traits::PreDefineMethods;
2022-07-24 16:33:38 -05:00
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
2020-05-10 09:54:30 -05:00
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::mono::{Linkage, Visibility};
2023-02-21 20:18:40 -06:00
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
2021-09-28 08:18:27 -05:00
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
2020-05-10 09:54:30 -05:00
use crate::attributes;
2020-05-10 09:54:30 -05:00
use crate::base;
use crate::context::CodegenCx;
use crate::type_of::LayoutGccExt;
impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
2022-07-24 16:33:38 -05:00
#[cfg_attr(not(feature="master"), allow(unused_variables))]
fn predefine_static(&self, def_id: DefId, _linkage: Linkage, visibility: Visibility, symbol_name: &str) {
2020-05-10 09:54:30 -05:00
let attrs = self.tcx.codegen_fn_attrs(def_id);
let instance = Instance::mono(self.tcx, def_id);
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
let gcc_type = self.layout_of(ty).gcc_type(self);
2020-05-10 09:54:30 -05:00
let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
let global = self.define_global(symbol_name, gcc_type, is_tls, attrs.link_section);
2022-07-24 16:33:38 -05:00
#[cfg(feature="master")]
global.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility)));
2020-05-10 09:54:30 -05:00
2022-07-24 16:33:38 -05:00
// TODO(antoyo): set linkage.
2020-05-10 09:54:30 -05:00
self.instances.borrow_mut().insert(instance, global);
}
2022-07-24 16:33:38 -05:00
#[cfg_attr(not(feature="master"), allow(unused_variables))]
fn predefine_fn(&self, instance: Instance<'tcx>, linkage: Linkage, visibility: Visibility, symbol_name: &str) {
assert!(!instance.substs.needs_infer());
2020-05-10 09:54:30 -05:00
2021-09-28 08:18:27 -05:00
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
2020-05-10 09:54:30 -05:00
self.linkage.set(base::linkage_to_gcc(linkage));
2023-01-08 10:42:00 -06:00
let decl = self.declare_fn(symbol_name, &fn_abi);
2020-05-10 09:54:30 -05:00
//let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
attributes::from_fn_attrs(self, decl, instance);
2022-07-24 16:33:38 -05:00
// If we're compiling the compiler-builtins crate, e.g., the equivalent of
// compiler-rt, then we want to implicitly compile everything with hidden
// visibility as we're going to link this object all over the place but
// don't want the symbols to get exported.
if linkage != Linkage::Internal
&& linkage != Linkage::Private
&& self.tcx.is_compiler_builtins(LOCAL_CRATE)
{
#[cfg(feature="master")]
decl.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
}
else {
#[cfg(feature="master")]
decl.add_attribute(FnAttribute::Visibility(base::visibility_to_gcc(visibility)));
}
2021-08-15 07:28:46 -05:00
// TODO(antoyo): call set_link_section() to allow initializing argc/argv.
// TODO(antoyo): set unique comdat.
// TODO(antoyo): use inline attribute from there in linkage.set() above.
2022-10-19 08:23:23 -05:00
self.functions.borrow_mut().insert(symbol_name.to_string(), decl);
self.function_instances.borrow_mut().insert(instance, unsafe { std::mem::transmute(decl) });
2020-05-10 09:54:30 -05:00
}
}