Export all fns with extern indicator
This commit is contained in:
parent
f62903b74a
commit
6b7cacb2c9
@ -90,10 +90,11 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
|
||||
let def_id = tcx.hir().local_def_id(hir_id);
|
||||
let generics = tcx.generics_of(def_id);
|
||||
if !generics.requires_monomorphization(tcx)
|
||||
&& (!Instance::mono(tcx, def_id.to_def_id())
|
||||
.def
|
||||
.generates_cgu_internal_copy(tcx)
|
||||
|| tcx.inline_exportable(def_id.to_def_id()))
|
||||
// Functions marked with #[inline] are codegened with "internal"
|
||||
// linkage and are not exported unless marked with an extern
|
||||
// inidicator
|
||||
&& (!Instance::mono(tcx, def_id.to_def_id()).def.generates_cgu_internal_copy(tcx)
|
||||
|| tcx.codegen_fn_attrs(def_id.to_def_id()).contains_extern_indicator())
|
||||
{
|
||||
Some(def_id)
|
||||
} else {
|
||||
|
@ -92,10 +92,10 @@ impl<'tcx> MonoItem<'tcx> {
|
||||
MonoItem::Fn(ref instance) => {
|
||||
let entry_def_id = tcx.entry_fn(LOCAL_CRATE).map(|(id, _)| id);
|
||||
// If this function isn't inlined or otherwise has explicit
|
||||
// linkage, then we'll be creating a globally shared version.
|
||||
// linkage or an extern indicator, then we'll be creating a
|
||||
// globally shared version.
|
||||
if self.explicit_linkage(tcx).is_some()
|
||||
|| !instance.def.generates_cgu_internal_copy(tcx)
|
||||
|| tcx.inline_exportable(instance.def_id())
|
||||
|| Some(instance.def_id()) == entry_def_id.map(LocalDefId::to_def_id)
|
||||
{
|
||||
return InstantiationMode::GloballyShared { may_conflict: false };
|
||||
@ -103,8 +103,12 @@ impl<'tcx> MonoItem<'tcx> {
|
||||
|
||||
// At this point we don't have explicit linkage and we're an
|
||||
// inlined function. If we're inlining into all CGUs then we'll
|
||||
// be creating a local copy per CGU
|
||||
if generate_cgu_internal_copies {
|
||||
// be creating a local copy per CGU. We need to watch out here
|
||||
// for an extern indicator as we don't want to optimise away
|
||||
// inlined functions that should be exported.
|
||||
if generate_cgu_internal_copies
|
||||
&& !tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator()
|
||||
{
|
||||
return InstantiationMode::LocalCopy;
|
||||
}
|
||||
|
||||
|
@ -697,10 +697,6 @@ rustc_queries! {
|
||||
storage(ArenaCacheSelector<'tcx>)
|
||||
cache_on_disk_if { true }
|
||||
}
|
||||
|
||||
query inline_exportable(def_id: DefId) -> bool {
|
||||
desc { |tcx| "computing whether `{}` should be explicitly exported", tcx.def_path_str(def_id) }
|
||||
}
|
||||
}
|
||||
|
||||
Other {
|
||||
|
@ -40,7 +40,6 @@ use rustc_middle::ty::util::Discr;
|
||||
use rustc_middle::ty::util::IntTypeExt;
|
||||
use rustc_middle::ty::{self, AdtKind, Const, ToPolyTraitRef, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{ReprOptions, ToPredicate, WithConstness};
|
||||
use rustc_session::config::CrateType;
|
||||
use rustc_session::lint;
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
@ -80,7 +79,6 @@ pub fn provide(providers: &mut Providers<'_>) {
|
||||
static_mutability,
|
||||
generator_kind,
|
||||
codegen_fn_attrs,
|
||||
inline_exportable,
|
||||
collect_mod_item_types,
|
||||
..*providers
|
||||
};
|
||||
@ -2601,16 +2599,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
|
||||
codegen_fn_attrs
|
||||
}
|
||||
|
||||
fn inline_exportable(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
// Functions marked with #[inline] are only ever codegened
|
||||
// with "internal" linkage and are never exported unless we're
|
||||
// building a `staticlib` or `cdylib` and they are marked
|
||||
// `#[no_mangle]`.
|
||||
tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_MANGLE)
|
||||
&& (tcx.sess.crate_types().contains(&CrateType::Cdylib)
|
||||
|| tcx.sess.crate_types().contains(&CrateType::Staticlib))
|
||||
}
|
||||
|
||||
/// Checks if the provided DefId is a method in a trait impl for a trait which has track_caller
|
||||
/// applied to the method prototype.
|
||||
fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
|
23
src/test/codegen/cdylib-external-inline-fns.rs
Normal file
23
src/test/codegen/cdylib-external-inline-fns.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// compile-flags: -C no-prepopulate-passes
|
||||
|
||||
#![crate_type = "cdylib"]
|
||||
|
||||
// CHECK: define void @a()
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub extern "C" fn a() {}
|
||||
|
||||
// CHECK: define void @b()
|
||||
#[export_name = "b"]
|
||||
#[inline]
|
||||
pub extern "C" fn b() {}
|
||||
|
||||
// CHECK: define void @c()
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
extern "C" fn c() {}
|
||||
|
||||
// CHECK: define void @d()
|
||||
#[export_name = "d"]
|
||||
#[inline]
|
||||
extern "C" fn d() {}
|
@ -1,13 +0,0 @@
|
||||
// compile-flags: -C no-prepopulate-passes
|
||||
|
||||
#![crate_type = "cdylib"]
|
||||
|
||||
// CHECK: define void @a()
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub extern "C" fn a() {
|
||||
// side effect to keep `a` around
|
||||
unsafe {
|
||||
core::ptr::read_volatile(&42);
|
||||
}
|
||||
}
|
@ -18,4 +18,9 @@ mod private {
|
||||
// CHECK: void @bar()
|
||||
#[export_name = "bar"]
|
||||
extern fn bar() {}
|
||||
|
||||
// CHECK: void @baz()
|
||||
#[export_name = "baz"]
|
||||
#[inline]
|
||||
extern fn baz() {}
|
||||
}
|
||||
|
@ -53,3 +53,13 @@ fn x() {
|
||||
core::ptr::read_volatile(&42);
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK: define void @i()
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
fn i() {}
|
||||
|
||||
// CHECK: define void @j()
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub fn j() {}
|
||||
|
23
src/test/codegen/staticlib-external-inline-fns.rs
Normal file
23
src/test/codegen/staticlib-external-inline-fns.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// compile-flags: -C no-prepopulate-passes
|
||||
|
||||
#![crate_type = "staticlib"]
|
||||
|
||||
// CHECK: define void @a()
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub extern "C" fn a() {}
|
||||
|
||||
// CHECK: define void @b()
|
||||
#[export_name = "b"]
|
||||
#[inline]
|
||||
pub extern "C" fn b() {}
|
||||
|
||||
// CHECK: define void @c()
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
extern "C" fn c() {}
|
||||
|
||||
// CHECK: define void @d()
|
||||
#[export_name = "d"]
|
||||
#[inline]
|
||||
extern "C" fn d() {}
|
@ -1,13 +0,0 @@
|
||||
// compile-flags: -C no-prepopulate-passes
|
||||
|
||||
#![crate_type = "staticlib"]
|
||||
|
||||
// CHECK: define void @a()
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub extern "C" fn a() {
|
||||
// side effect to keep `a` around
|
||||
unsafe {
|
||||
core::ptr::read_volatile(&42);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user