Set hidden visibility on naked functions in compiler-builtins
88b46460fa made builtin functions hidden,
but it doesn't apply to naked functions, which are generated through a
different code path.
This commit is contained in:
parent
f60a0f1bcc
commit
73d06be9f3
1 changed files with 14 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use rustc_abi::{BackendRepr, Float, Integer, Primitive, RegKind};
|
||||
use rustc_hir::attrs::{InstructionSetAttr, Linkage};
|
||||
use rustc_hir::def_id::LOCAL_CRATE;
|
||||
use rustc_middle::mir::mono::{MonoItemData, Visibility};
|
||||
use rustc_middle::mir::{InlineAsmOperand, START_BLOCK};
|
||||
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
|
||||
|
|
@ -128,6 +129,15 @@ fn prefix_and_suffix<'tcx>(
|
|||
let is_arm = tcx.sess.target.arch == Arch::Arm;
|
||||
let is_thumb = tcx.sess.unstable_target_features.contains(&sym::thumb_mode);
|
||||
|
||||
// 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. For naked asm we set the visibility here.
|
||||
let mut visibility = item_data.visibility;
|
||||
if item_data.linkage != Linkage::Internal && tcx.is_compiler_builtins(LOCAL_CRATE) {
|
||||
visibility = Visibility::Hidden;
|
||||
}
|
||||
|
||||
let attrs = tcx.codegen_instance_attrs(instance.def);
|
||||
let link_section = attrs.link_section.map(|symbol| symbol.as_str().to_string());
|
||||
|
||||
|
|
@ -217,7 +227,7 @@ fn prefix_and_suffix<'tcx>(
|
|||
writeln!(begin, ".pushsection {section},\"ax\", {progbits}").unwrap();
|
||||
writeln!(begin, ".balign {align_bytes}").unwrap();
|
||||
write_linkage(&mut begin).unwrap();
|
||||
match item_data.visibility {
|
||||
match visibility {
|
||||
Visibility::Default => {}
|
||||
Visibility::Protected => writeln!(begin, ".protected {asm_name}").unwrap(),
|
||||
Visibility::Hidden => writeln!(begin, ".hidden {asm_name}").unwrap(),
|
||||
|
|
@ -243,7 +253,7 @@ fn prefix_and_suffix<'tcx>(
|
|||
writeln!(begin, ".pushsection {},regular,pure_instructions", section).unwrap();
|
||||
writeln!(begin, ".balign {align_bytes}").unwrap();
|
||||
write_linkage(&mut begin).unwrap();
|
||||
match item_data.visibility {
|
||||
match visibility {
|
||||
Visibility::Default | Visibility::Protected => {}
|
||||
Visibility::Hidden => writeln!(begin, ".private_extern {asm_name}").unwrap(),
|
||||
}
|
||||
|
|
@ -280,7 +290,7 @@ fn prefix_and_suffix<'tcx>(
|
|||
writeln!(begin, ".section {section},\"\",@").unwrap();
|
||||
// wasm functions cannot be aligned, so skip
|
||||
write_linkage(&mut begin).unwrap();
|
||||
if let Visibility::Hidden = item_data.visibility {
|
||||
if let Visibility::Hidden = visibility {
|
||||
writeln!(begin, ".hidden {asm_name}").unwrap();
|
||||
}
|
||||
writeln!(begin, ".type {asm_name}, @function").unwrap();
|
||||
|
|
@ -313,7 +323,7 @@ fn prefix_and_suffix<'tcx>(
|
|||
writeln!(begin, ".align {}", align_bytes).unwrap();
|
||||
|
||||
write_linkage(&mut begin).unwrap();
|
||||
if let Visibility::Hidden = item_data.visibility {
|
||||
if let Visibility::Hidden = visibility {
|
||||
// FIXME apparently `.globl {asm_name}, hidden` is valid
|
||||
// but due to limitations with `.weak` (see above) we can't really use that in general yet
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue