Skip to content

Commit 68471f1

Browse files
committed
Remove output_filenames field from GlobalAsmConfig
1 parent fa706d4 commit 68471f1

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

src/driver/aot.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,25 @@ fn module_codegen(
384384

385385
let global_asm_object_file =
386386
profiler.generic_activity_with_arg("compile assembly", &*cgu_name).run(|| {
387-
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, global_asm)
387+
if global_asm.is_empty() {
388+
return Ok::<_, String>(None);
389+
}
390+
391+
let global_asm_object_file =
392+
output_filenames.temp_path_ext_for_cgu("asm.o", &*cgu_name);
393+
crate::global_asm::compile_global_asm(
394+
&global_asm_config,
395+
global_asm,
396+
&global_asm_object_file,
397+
)?;
398+
399+
Ok(Some(global_asm_object_file))
388400
})?;
389401

390402
let codegen_result =
391403
profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| {
392404
emit_cgu(
393-
&global_asm_config.output_filenames,
405+
&output_filenames,
394406
&profiler,
395407
cgu_name,
396408
module,
@@ -449,7 +461,7 @@ pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box<OngoingCodegen> {
449461
}
450462
});
451463

452-
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx));
464+
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx.sess));
453465

454466
let (todo_cgus, done_cgus) =
455467
cgus.iter().enumerate().partition::<Vec<_>, _>(|&(i, _)| match cgu_reuse[i] {

src/global_asm.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
//! standalone executable.
33
44
use std::io::Write;
5-
use std::path::PathBuf;
5+
use std::path::{Path, PathBuf};
66
use std::process::{Command, Stdio};
7-
use std::sync::Arc;
87

98
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
109
use rustc_codegen_ssa::traits::{AsmCodegenMethods, GlobalAsmOperandRef};
1110
use rustc_middle::ty::TyCtxt;
1211
use rustc_middle::ty::layout::{
1312
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers,
1413
};
15-
use rustc_session::config::OutputFilenames;
14+
use rustc_session::Session;
1615
use rustc_target::asm::InlineAsmArch;
1716

1817
use crate::prelude::*;
@@ -163,32 +162,28 @@ fn codegen_global_asm_inner<'tcx>(
163162
pub(crate) struct GlobalAsmConfig {
164163
assembler: PathBuf,
165164
target: String,
166-
pub(crate) output_filenames: Arc<OutputFilenames>,
167165
}
168166

169167
impl GlobalAsmConfig {
170-
pub(crate) fn new(tcx: TyCtxt<'_>) -> Self {
168+
pub(crate) fn new(sess: &Session) -> Self {
171169
GlobalAsmConfig {
172-
assembler: crate::toolchain::get_toolchain_binary(tcx.sess, "as"),
173-
target: match &tcx.sess.opts.target_triple {
170+
assembler: crate::toolchain::get_toolchain_binary(sess, "as"),
171+
target: match &sess.opts.target_triple {
174172
rustc_target::spec::TargetTuple::TargetTuple(triple) => triple.clone(),
175173
rustc_target::spec::TargetTuple::TargetJson { path_for_rustdoc, .. } => {
176174
path_for_rustdoc.to_str().unwrap().to_owned()
177175
}
178176
},
179-
output_filenames: tcx.output_filenames(()).clone(),
180177
}
181178
}
182179
}
183180

184181
pub(crate) fn compile_global_asm(
185182
config: &GlobalAsmConfig,
186-
cgu_name: &str,
187183
global_asm: String,
188-
) -> Result<Option<PathBuf>, String> {
189-
if global_asm.is_empty() {
190-
return Ok(None);
191-
}
184+
global_asm_object_file: &Path,
185+
) -> Result<(), String> {
186+
assert!(!global_asm.is_empty());
192187

193188
// Remove all LLVM style comments
194189
let mut global_asm = global_asm
@@ -198,8 +193,6 @@ pub(crate) fn compile_global_asm(
198193
.join("\n");
199194
global_asm.push('\n');
200195

201-
let global_asm_object_file = config.output_filenames.temp_path_ext_for_cgu("asm.o", cgu_name);
202-
203196
// Assemble `global_asm`
204197
if option_env!("CG_CLIF_FORCE_GNU_AS").is_some() {
205198
let mut child = Command::new(&config.assembler)
@@ -266,5 +259,5 @@ pub(crate) fn compile_global_asm(
266259
}
267260
}
268261

269-
Ok(Some(global_asm_object_file))
262+
Ok(())
270263
}

0 commit comments

Comments
 (0)