Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions src/mono_item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use gccjit::Function;
#[cfg(feature = "master")]
use gccjit::{FnAttribute, LValue, ToRValue, VarAttribute};
use gccjit::{FnAttribute, GlobalKind, ToRValue, Type, VarAttribute};
use rustc_codegen_ssa::traits::PreDefineCodegenMethods;
use rustc_hir::attrs::Linkage;
use rustc_hir::def::DefKind;
Expand Down Expand Up @@ -34,19 +34,13 @@ impl<'gcc, 'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
let gcc_type = self.layout_of(ty).gcc_type(self);

let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
let global = self.define_global(global_name, gcc_type, is_tls, attrs.link_section);
#[cfg(feature = "master")]
global.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility)));
// FIXME(antoyo): set linkage.

let create_global = |this: &CodegenCx<'gcc, 'tcx>, name: &str, visibility: Visibility| {
let global = this.define_global(name, gcc_type, is_tls, attrs.link_section);
#[cfg(feature = "master")]
global.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility)));
// FIXME(antoyo): set linkage.
global
};
let global = create_global(self, global_name, visibility);

let attrs = self.tcx.codegen_instance_attrs(instance.def);
#[cfg(feature = "master")]
self.add_static_aliases(&attrs.foreign_item_symbol_aliases, global_name, &create_global);
self.add_static_aliases(gcc_type, global_name, attrs, &attrs.foreign_item_symbol_aliases);

self.instances.borrow_mut().insert(instance, global);
}
Expand Down Expand Up @@ -75,20 +69,31 @@ impl<'gcc, 'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {

impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
#[cfg(feature = "master")]
fn add_static_aliases<F>(
fn add_static_aliases(
&self,
aliases: &[(DefId, Linkage, Visibility)],
gcc_type: Type<'gcc>,
aliased: &str,
create_global: &F,
) where
F: Fn(&CodegenCx<'gcc, 'tcx>, &str, Visibility) -> LValue<'gcc>,
{
for &(alias, _linkage, visibility) in aliases {
attrs: &CodegenFnAttrs,
aliases: &[(DefId, Linkage, Visibility)],
) {
let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);

for &(alias, linkage, visibility) in aliases {
let instance = Instance::mono(self.tcx, alias);
let symbol_name = self.tcx.symbol_name(instance);

let alias = create_global(self, symbol_name.name, visibility);
let alias = self.declare_global(
symbol_name.name,
gcc_type,
GlobalKind::Imported,
is_tls,
attrs.link_section,
);
alias.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility)));
alias.add_attribute(VarAttribute::Alias(aliased));
if linkage == Linkage::WeakAny {
alias.add_attribute(VarAttribute::Weak);
}

// Add the alias name to the set of cached items, so there is no duplicate
// instance added to it during the normal `external static` codegen
Expand Down Expand Up @@ -153,6 +158,11 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {

attributes::from_fn_attrs(self, fn_decl, instance, Some(fn_abi));

#[cfg(feature = "master")]
if linkage == Linkage::WeakAny {
fn_decl.add_attribute(FnAttribute::Weak);
}

// 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
Expand Down
9 changes: 0 additions & 9 deletions tests/failing-ui-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,8 @@ tests/ui/attributes/fn-align-dyn.rs
tests/ui/linkage-attr/raw-dylib/elf/glibc-x86_64.rs
tests/ui/statics/const_generics.rs
tests/ui/thir-print/offset_of.rs
tests/ui/eii/default/call_impl.rs
tests/ui/asm/x86_64/global_asm_escape.rs
tests/ui/lto/all-crates.rs
tests/ui/eii/static/cross_crate_decl.rs
tests/ui/eii/static/cross_crate_def.rs
tests/ui/eii/static/same_address.rs
tests/ui/eii/static/simple.rs
tests/ui/eii/static/default.rs
tests/ui/eii/static/default_cross_crate.rs
tests/ui/eii/static/default_explicit.rs
tests/ui/eii/static/default_cross_crate_explicit.rs
tests/ui/explicit-tail-calls/tailcc-no-signature-restriction.rs
tests/ui/abi/rust-tail-cc.rs
tests/ui/abi/rust-preserve-none-cc.rs
Expand Down
Loading