Skip to content

Commit 297f7d9

Browse files
committed
use tcx.codegen_fn_attrs to get attribute info
1 parent 678dfa6 commit 297f7d9

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
109109
sym::rustc_allocator_zeroed => {
110110
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
111111
}
112-
sym::naked => {
113-
// this attribute is ignored during codegen, because a function marked as naked is
114-
// turned into a global asm block.
115-
}
112+
sym::naked => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
116113
sym::no_mangle => {
117114
if tcx.opt_item_name(did.to_def_id()).is_some() {
118115
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
172172
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
173173
debug!("fn_abi: {:?}", fn_abi);
174174

175-
if cx.tcx().has_attr(instance.def.def_id(), rustc_span::sym::naked) {
175+
if cx.tcx().codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
176176
let cached_llbbs = IndexVec::new();
177177

178178
let fx: FunctionCx<'_, '_, Bx> = FunctionCx {

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use rustc_middle::mir::InlineAsmOperand;
88
use rustc_middle::ty;
99
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
1010
use rustc_middle::ty::{Instance, TyCtxt};
11-
12-
use rustc_span::sym;
1311
use rustc_target::asm::InlineAsmArch;
1412

1513
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
@@ -133,12 +131,9 @@ fn prefix_and_suffix<'tcx>(
133131

134132
let asm_name = format!("{}{}", if mangle { "_" } else { "" }, tcx.symbol_name(instance).name);
135133

136-
let opt_section = tcx
137-
.get_attr(instance.def.def_id(), sym::link_section)
138-
.and_then(|attr| attr.value_str())
139-
.map(|attr| attr.as_str().to_string());
140-
141134
let attrs = tcx.codegen_fn_attrs(instance.def_id());
135+
let link_section = attrs.link_section.map(|symbol| symbol.as_str().to_string());
136+
142137
let (arch_prefix, arch_suffix) = if is_arm {
143138
(
144139
match attrs.instruction_set {
@@ -162,7 +157,7 @@ fn prefix_and_suffix<'tcx>(
162157
let mut end = String::new();
163158
match AsmBinaryFormat::from_target(&tcx.sess.target) {
164159
AsmBinaryFormat::Elf => {
165-
let section = opt_section.unwrap_or(format!(".text.{asm_name}"));
160+
let section = link_section.unwrap_or(format!(".text.{asm_name}"));
166161

167162
let progbits = match is_arm {
168163
true => "%progbits",
@@ -199,7 +194,7 @@ fn prefix_and_suffix<'tcx>(
199194
}
200195
}
201196
AsmBinaryFormat::Macho => {
202-
let section = opt_section.unwrap_or("__TEXT,__text".to_string());
197+
let section = link_section.unwrap_or("__TEXT,__text".to_string());
203198
writeln!(begin, ".pushsection {},regular,pure_instructions", section).unwrap();
204199
writeln!(begin, ".balign 4").unwrap();
205200
if let Some(linkage) = linkage_directive(item_data.linkage) {
@@ -220,7 +215,7 @@ fn prefix_and_suffix<'tcx>(
220215
}
221216
}
222217
AsmBinaryFormat::Coff => {
223-
let section = opt_section.unwrap_or(format!(".text.{asm_name}"));
218+
let section = link_section.unwrap_or(format!(".text.{asm_name}"));
224219
writeln!(begin, ".pushsection {},\"xr\"", section).unwrap();
225220
writeln!(begin, ".balign 4").unwrap();
226221
if let Some(linkage) = linkage_directive(item_data.linkage) {

0 commit comments

Comments
 (0)