Skip to content

Commit df5de03

Browse files
committed
Don't build command-line args for an "informational" target machine
1 parent ec38671 commit df5de03

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ pub(crate) fn create_informational_target_machine(
112112
// Can't use query system here quite yet because this function is invoked before the query
113113
// system/tcx is set up.
114114
let features = llvm_util::global_llvm_features(sess, false, only_base_features);
115-
target_machine_factory(sess, config::OptLevel::No, &features)(config)
116-
.unwrap_or_else(|err| llvm_err(sess.dcx(), err))
115+
target_machine_factory(sess, config::OptLevel::No, &features, TargetMachineRole::Informational)(
116+
config,
117+
)
118+
.unwrap_or_else(|err| llvm_err(sess.dcx(), err))
117119
}
118120

119121
pub(crate) fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTargetMachine {
@@ -139,6 +141,7 @@ pub(crate) fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTar
139141
tcx.sess,
140142
tcx.backend_optimization_level(()),
141143
tcx.global_backend_features(()),
144+
TargetMachineRole::Codegen,
142145
)(config)
143146
.unwrap_or_else(|err| llvm_err(tcx.dcx(), err))
144147
}
@@ -199,10 +202,17 @@ fn to_llvm_float_abi(float_abi: Option<FloatAbi>) -> llvm::FloatAbi {
199202
}
200203
}
201204

205+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
206+
pub(crate) enum TargetMachineRole {
207+
Informational,
208+
Codegen,
209+
}
210+
202211
pub(crate) fn target_machine_factory(
203212
sess: &Session,
204213
optlvl: config::OptLevel,
205214
target_features: &[String],
215+
tm_role: TargetMachineRole,
206216
) -> TargetMachineFactoryFn<LlvmCodegenBackend> {
207217
let reloc_model = to_llvm_relocation_model(sess.relocation_model());
208218

@@ -253,12 +263,21 @@ pub(crate) fn target_machine_factory(
253263
// Command-line information to be included in the target machine.
254264
// This seems to only be used for embedding in PDB debuginfo files.
255265
// FIXME(Zalathar): Maybe skip this for non-PDB targets?
256-
let argv0 = std::env::current_exe()
257-
.unwrap_or_default()
258-
.into_os_string()
259-
.into_string()
260-
.unwrap_or_default();
261-
let command_line_args = quote_command_line_args(&sess.expanded_args);
266+
let (argv0, command_line_args);
267+
match tm_role {
268+
TargetMachineRole::Informational => {
269+
argv0 = String::new();
270+
command_line_args = String::new()
271+
}
272+
TargetMachineRole::Codegen => {
273+
argv0 = std::env::current_exe()
274+
.unwrap_or_default()
275+
.into_os_string()
276+
.into_string()
277+
.unwrap_or_default();
278+
command_line_args = quote_command_line_args(&sess.expanded_args);
279+
}
280+
}
262281

263282
let debuginfo_compression = sess.opts.debuginfo_compression.to_string();
264283
match sess.opts.debuginfo_compression {

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ use rustc_session::Session;
4646
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4747
use rustc_span::Symbol;
4848

49+
use crate::back::write::TargetMachineRole;
50+
4951
mod abi;
5052
mod allocator;
5153
mod asm;
@@ -125,7 +127,12 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
125127
optlvl: OptLevel,
126128
target_features: &[String],
127129
) -> TargetMachineFactoryFn<Self> {
128-
back::write::target_machine_factory(sess, optlvl, target_features)
130+
back::write::target_machine_factory(
131+
sess,
132+
optlvl,
133+
target_features,
134+
TargetMachineRole::Codegen,
135+
)
129136
}
130137

131138
fn spawn_named_thread<F, T>(

0 commit comments

Comments
 (0)