@@ -6,7 +6,7 @@ use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, Mo
66use rustc_codegen_ssa:: { CompiledModule , ModuleCodegen } ;
77use rustc_errors:: DiagCtxtHandle ;
88use rustc_fs_util:: link_or_copy;
9- use rustc_session:: config:: OutputType ;
9+ use rustc_session:: config:: { Lto , OutputType } ;
1010use rustc_span:: fatal_error:: FatalError ;
1111use rustc_target:: spec:: SplitDebuginfo ;
1212
@@ -42,45 +42,74 @@ pub(crate) unsafe fn codegen(
4242 let bc_out = cgcx. output_filenames . temp_path ( OutputType :: Bitcode , module_name) ;
4343 let obj_out = cgcx. output_filenames . temp_path ( OutputType :: Object , module_name) ;
4444
45- if config. bitcode_needed ( ) && fat_lto {
46- let _timer = cgcx
47- . prof
48- . generic_activity_with_arg ( "GCC_module_codegen_make_bitcode" , & * module. name ) ;
49-
50- // TODO(antoyo)
51- /*if let Some(bitcode_filename) = bc_out.file_name() {
52- cgcx.prof.artifact_size(
53- "llvm_bitcode",
54- bitcode_filename.to_string_lossy(),
55- data.len() as u64,
56- );
57- }*/
58-
59- if config. emit_bc || config. emit_obj == EmitObj :: Bitcode {
45+ if config. bitcode_needed ( ) {
46+ if fat_lto {
6047 let _timer = cgcx
6148 . prof
62- . generic_activity_with_arg ( "GCC_module_codegen_emit_bitcode" , & * module. name ) ;
63- context. add_command_line_option ( "-flto=auto" ) ;
64- context. add_command_line_option ( "-flto-partition=one" ) ;
65- // TODO: remove since we don't want fat objects when it is for Bitcode only.
66- context. add_command_line_option ( "-ffat-lto-objects" ) ;
67- context
68- . compile_to_file ( OutputKind :: ObjectFile , bc_out. to_str ( ) . expect ( "path to str" ) ) ;
49+ . generic_activity_with_arg ( "GCC_module_codegen_make_bitcode" , & * module. name ) ;
50+
51+ // TODO(antoyo)
52+ /*if let Some(bitcode_filename) = bc_out.file_name() {
53+ cgcx.prof.artifact_size(
54+ "llvm_bitcode",
55+ bitcode_filename.to_string_lossy(),
56+ data.len() as u64,
57+ );
58+ }*/
59+
60+ if config. emit_bc || config. emit_obj == EmitObj :: Bitcode {
61+ let _timer = cgcx
62+ . prof
63+ . generic_activity_with_arg ( "GCC_module_codegen_emit_bitcode" , & * module. name ) ;
64+ context. add_command_line_option ( "-flto=auto" ) ;
65+ context. add_command_line_option ( "-flto-partition=one" ) ;
66+ // TODO: remove since we don't want fat objects when it is for Bitcode only.
67+ context. add_command_line_option ( "-ffat-lto-objects" ) ;
68+ context
69+ . compile_to_file ( OutputKind :: ObjectFile , bc_out. to_str ( ) . expect ( "path to str" ) ) ;
70+ }
71+
72+ if config. emit_obj == EmitObj :: ObjectCode ( BitcodeSection :: Full ) {
73+ let _timer = cgcx
74+ . prof
75+ . generic_activity_with_arg ( "GCC_module_codegen_embed_bitcode" , & * module. name ) ;
76+ // TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
77+ //embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
78+
79+ context. add_command_line_option ( "-flto=auto" ) ;
80+ context. add_command_line_option ( "-flto-partition=one" ) ;
81+ context. add_command_line_option ( "-ffat-lto-objects" ) ;
82+ // TODO(antoyo): Send -plugin/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/liblto_plugin.so to linker (this should be done when specifying the appropriate rustc cli argument).
83+ context
84+ . compile_to_file ( OutputKind :: ObjectFile , bc_out. to_str ( ) . expect ( "path to str" ) ) ;
85+ }
6986 }
87+ else {
88+ if config. emit_bc || config. emit_obj == EmitObj :: Bitcode {
89+ let _timer = cgcx
90+ . prof
91+ . generic_activity_with_arg ( "GCC_module_codegen_emit_bitcode" , & * module. name ) ;
92+ context
93+ . compile_to_file ( OutputKind :: ObjectFile , bc_out. to_str ( ) . expect ( "path to str" ) ) ;
94+ }
7095
71- if config. emit_obj == EmitObj :: ObjectCode ( BitcodeSection :: Full ) {
72- let _timer = cgcx
73- . prof
74- . generic_activity_with_arg ( "GCC_module_codegen_embed_bitcode" , & * module. name ) ;
75- // TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
76- //embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
77-
78- context. add_command_line_option ( "-flto=auto" ) ;
79- context. add_command_line_option ( "-flto-partition=one" ) ;
80- context. add_command_line_option ( "-ffat-lto-objects" ) ;
81- // TODO(antoyo): Send -plugin/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/liblto_plugin.so to linker (this should be done when specifying the appropriate rustc cli argument).
82- context
83- . compile_to_file ( OutputKind :: ObjectFile , bc_out. to_str ( ) . expect ( "path to str" ) ) ;
96+ if config. emit_obj == EmitObj :: ObjectCode ( BitcodeSection :: Full ) {
97+ // TODO: we might want to emit to emit an error here, saying to set the
98+ // environment variable EMBED_LTO_BITCODE.
99+ unreachable ! ( ) ;
100+ let _timer = cgcx
101+ . prof
102+ . generic_activity_with_arg ( "GCC_module_codegen_embed_bitcode" , & * module. name ) ;
103+ // TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
104+ //embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
105+
106+ context. add_command_line_option ( "-flto=auto" ) ;
107+ context. add_command_line_option ( "-flto-partition=one" ) ;
108+ context. add_command_line_option ( "-ffat-lto-objects" ) ;
109+ // TODO(antoyo): Send -plugin/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/liblto_plugin.so to linker (this should be done when specifying the appropriate rustc cli argument).
110+ context
111+ . compile_to_file ( OutputKind :: ObjectFile , bc_out. to_str ( ) . expect ( "path to str" ) ) ;
112+ }
84113 }
85114 }
86115
0 commit comments