@@ -22,6 +22,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
2222use rustc_data_structures:: small_c_str:: SmallCStr ;
2323use rustc_errors:: { DiagCtxtHandle , Level } ;
2424use rustc_fs_util:: { link_or_copy, path_to_c_string} ;
25+ use rustc_middle:: middle:: debuginfo:: CommandLineArgsForDebuginfo ;
2526use rustc_middle:: ty:: TyCtxt ;
2627use rustc_session:: Session ;
2728use rustc_session:: config:: {
@@ -31,7 +32,6 @@ use rustc_span::{BytePos, InnerSpan, Pos, SpanData, SyntaxContext, sym};
3132use rustc_target:: spec:: { CodeModel , FloatAbi , RelocModel , SanitizerSet , SplitDebuginfo , TlsModel } ;
3233use tracing:: { debug, trace} ;
3334
34- use crate :: back:: command_line_args:: quote_command_line_args;
3535use crate :: back:: lto:: ThinBuffer ;
3636use crate :: back:: owned_target_machine:: OwnedTargetMachine ;
3737use crate :: back:: profiling:: {
@@ -108,7 +108,11 @@ pub(crate) fn create_informational_target_machine(
108108 sess : & Session ,
109109 only_base_features : bool ,
110110) -> OwnedTargetMachine {
111- let config = TargetMachineFactoryConfig { split_dwarf_file : None , output_obj_file : None } ;
111+ let config = TargetMachineFactoryConfig {
112+ split_dwarf_file : None ,
113+ output_obj_file : None ,
114+ args_for_debuginfo : None ,
115+ } ;
112116 // Can't use query system here quite yet because this function is invoked before the query
113117 // system/tcx is set up.
114118 let features = llvm_util:: global_llvm_features ( sess, false , only_base_features) ;
@@ -133,7 +137,12 @@ pub(crate) fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTar
133137 mod_name,
134138 tcx. sess . invocation_temp . as_deref ( ) ,
135139 ) ) ;
136- let config = TargetMachineFactoryConfig { split_dwarf_file, output_obj_file } ;
140+
141+ let config = TargetMachineFactoryConfig {
142+ split_dwarf_file,
143+ output_obj_file,
144+ args_for_debuginfo : Some ( Arc :: clone ( tcx. args_for_debuginfo ( ) ) ) ,
145+ } ;
137146
138147 target_machine_factory (
139148 tcx. sess ,
@@ -253,19 +262,6 @@ pub(crate) fn target_machine_factory(
253262
254263 let use_emulated_tls = matches ! ( sess. tls_model( ) , TlsModel :: Emulated ) ;
255264
256- // Command-line information to be included in the target machine.
257- // This seems to only be used for embedding in PDB debuginfo files.
258- // FIXME(Zalathar): Maybe skip this for non-PDB targets?
259- let argv0 = std:: env:: current_exe ( )
260- . unwrap_or_default ( )
261- . into_os_string ( )
262- . into_string ( )
263- . unwrap_or_default ( ) ;
264- let command_line_args = quote_command_line_args ( & sess. expanded_args ) ;
265- // Self-profile counter for the number of bytes produced by command-line quoting.
266- // Values are summed, so the summary result is cumulative across all TM factories.
267- sess. prof . artifact_size ( "quoted_command_line_args" , "-" , command_line_args. len ( ) as u64 ) ;
268-
269265 let debuginfo_compression = sess. opts . debuginfo_compression . to_string ( ) ;
270266 match sess. opts . debuginfo_compression {
271267 rustc_session:: config:: DebugInfoCompression :: Zlib => {
@@ -304,6 +300,14 @@ pub(crate) fn target_machine_factory(
304300 let split_dwarf_file = path_to_cstring_helper ( config. split_dwarf_file ) ;
305301 let output_obj_file = path_to_cstring_helper ( config. output_obj_file ) ;
306302
303+ let ( argv0, quoted_args) = config
304+ . args_for_debuginfo
305+ . as_deref ( )
306+ . map ( |CommandLineArgsForDebuginfo { argv0, quoted_args } | {
307+ ( argv0. as_str ( ) , quoted_args. as_str ( ) )
308+ } )
309+ . unwrap_or_default ( ) ;
310+
307311 OwnedTargetMachine :: new (
308312 & triple,
309313 & cpu,
@@ -326,8 +330,8 @@ pub(crate) fn target_machine_factory(
326330 & output_obj_file,
327331 & debuginfo_compression,
328332 use_emulated_tls,
329- & argv0,
330- & command_line_args ,
333+ argv0,
334+ quoted_args ,
331335 use_wasm_eh,
332336 )
333337 } )
0 commit comments