@@ -65,13 +65,18 @@ pub(crate) unsafe fn codegen(
6565 "GCC_module_codegen_emit_bitcode" ,
6666 & * module. name ,
6767 ) ;
68+ println ! ( "Adding -flto for {}" , bc_out. to_str( ) . unwrap( ) ) ;
6869 context. add_command_line_option ( "-flto=auto" ) ;
6970 context. add_command_line_option ( "-flto-partition=one" ) ;
71+ context. add_driver_option ( "-flto=auto" ) ;
72+ context. add_driver_option ( "-flto-partition=one" ) ;
73+ context. add_command_line_option ( "-fno-fat-lto-objects" ) ;
74+ context. add_driver_option ( "-fno-fat-lto-objects" ) ;
7075 // FIXME FIXME FIXME: it seems that uncommenting "ADD_ARG ("-fno-use-linker-plugin")" in libgccjit
7176 // make the test fail (undefined symbol main).
7277 // TODO: Perhaps we're not sending this flag somewhere?
7378 context. add_command_line_option ( "-fno-use-linker-plugin" ) ;
74- context. add_driver_option ( "-fno-use-linker-plugin" ) ;
79+ // context.add_driver_option("-fno-use-linker-plugin");
7580 // TODO(antoyo): remove since we don't want fat objects when it is for Bitcode only.
7681 context. add_command_line_option ( "-ffat-lto-objects" ) ;
7782 context. compile_to_file (
@@ -88,10 +93,15 @@ pub(crate) unsafe fn codegen(
8893 // TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
8994 //embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
9095
96+ println ! ( "Adding -flto for {}" , bc_out. to_str( ) . unwrap( ) ) ;
9197 context. add_command_line_option ( "-flto=auto" ) ;
9298 context. add_command_line_option ( "-flto-partition=one" ) ;
99+ context. add_driver_option ( "-flto=auto" ) ;
100+ context. add_driver_option ( "-flto-partition=one" ) ;
101+ context. add_command_line_option ( "-fno-fat-lto-objects" ) ;
102+ context. add_driver_option ( "-fno-fat-lto-objects" ) ;
93103 context. add_command_line_option ( "-fno-use-linker-plugin" ) ;
94- context. add_driver_option ( "-fno-use-linker-plugin" ) ;
104+ // context.add_driver_option("-fno-use-linker-plugin");
95105 context. add_command_line_option ( "-ffat-lto-objects" ) ;
96106 // 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).
97107 context. compile_to_file (
@@ -179,15 +189,20 @@ pub(crate) unsafe fn codegen(
179189 if fat_lto {
180190 context. add_command_line_option ( "-flto=auto" ) ;
181191 context. add_command_line_option ( "-flto-partition=one" ) ;
192+ context. add_driver_option ( "-flto=auto" ) ;
193+ context. add_driver_option ( "-flto-partition=one" ) ;
194+ context. add_command_line_option ( "-fno-fat-lto-objects" ) ;
195+ context. add_driver_option ( "-fno-fat-lto-objects" ) ;
182196 //context.add_command_line_option("-ffat-lto-objects");
183197 context. add_command_line_option ( "-fno-use-linker-plugin" ) ;
184- context. add_driver_option ( "-fno-use-linker-plugin" ) ;
198+ // context.add_driver_option("-fno-use-linker-plugin");
185199
186- // FIXME FIXME FIXME :
200+ // FIXME:
187201 // /usr/bin/ld: warning: incremental linking of LTO and non-LTO objects; using -flinker-output=nolto-rel which will bypass whole program optimization
188- // ====> So I'm probably missing -flto somewhere.
202+ // => So I'm probably missing -flto somewhere.
203+ // ====> That was caused because I didn't build the sysroot with LTO.
189204
190- println ! ( "**** Adding -flto to {:?}" , obj_out. to_str( ) . expect( "path to str" ) ) ;
205+ println ! ( "Adding -flto to {:?}" , obj_out. to_str( ) . expect( "path to str" ) ) ;
191206
192207 // FIXME: the problem is probably that the code is only in GIMPLE IR while
193208 // we would want to get the optimized asm done from LTO.
@@ -221,8 +236,14 @@ pub(crate) unsafe fn codegen(
221236 println ! ( "****************************************************************************************************" ) ;
222237
223238 let context = Context :: default ( ) ;
239+ context. add_command_line_option ( "-flto=auto" ) ;
240+ context. add_command_line_option ( "-flto-partition=one" ) ;
241+ context. add_driver_option ( "-flto=auto" ) ;
242+ context. add_driver_option ( "-flto-partition=one" ) ;
243+ context. add_command_line_option ( "-fno-fat-lto-objects" ) ;
244+ context. add_driver_option ( "-fno-fat-lto-objects" ) ;
224245 context. add_command_line_option ( "-fno-use-linker-plugin" ) ;
225- context. add_driver_option ( "-fno-use-linker-plugin" ) ;
246+ // context.add_driver_option("-fno-use-linker-plugin");
226247 if cgcx. target_arch == "x86" || cgcx. target_arch == "x86_64" {
227248 // NOTE: it seems we need to use add_driver_option instead of
228249 // add_command_line_option here because we use the LTO frontend via gcc.
0 commit comments