Skip to content

Commit 2a5f980

Browse files
committed
Trying more stuff
1 parent 78ee4f1 commit 2a5f980

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

src/back/lto.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ fn fat_lto(
272272
// We cannot load and merge GCC contexts in memory like cg_llvm is doing.
273273
// Instead, we combine the object files into a single object file.
274274
for module in in_memory {
275+
println!("Adding -flto for {}", module.name);
275276
let path = tmp_path.path().to_path_buf().join(&module.name);
276277
let path = path.to_str().expect("path");
277278
let context = &module.module_llvm.context;
@@ -280,6 +281,10 @@ fn fat_lto(
280281
context.set_optimization_level(to_gcc_opt_level(config.opt_level));
281282
context.add_command_line_option("-flto=auto");
282283
context.add_command_line_option("-flto-partition=one");
284+
context.add_driver_option("-flto=auto");
285+
context.add_driver_option("-flto-partition=one");
286+
context.add_command_line_option("-fno-fat-lto-objects");
287+
context.add_driver_option("-fno-fat-lto-objects");
283288
context.add_command_line_option("-fno-use-linker-plugin");
284289
context.add_driver_option("-fno-use-linker-plugin");
285290
context.compile_to_file(OutputKind::ObjectFile, path);
@@ -518,8 +523,9 @@ fn thin_lto(
518523
});*/
519524

520525
match module {
521-
SerializedModule::Local(_) => {
522-
//let path = module_buffer.0.to_str().expect("path");
526+
SerializedModule::Local(ref module) => {
527+
let path = module.0.to_str().expect("path");
528+
println!("??? Should we add -flto for: {:?}", path);
523529
//let my_path = PathBuf::from(path);
524530
//let exists = my_path.exists();
525531
/*module.module_llvm.should_combine_object_files = true;
@@ -653,6 +659,12 @@ pub unsafe fn optimize_thin_module(
653659
Some(thin_buffer) => Arc::clone(&thin_buffer.context),
654660
None => {
655661
let context = Context::default();
662+
context.add_command_line_option("-flto=auto");
663+
context.add_command_line_option("-flto-partition=one");
664+
context.add_driver_option("-flto=auto");
665+
context.add_driver_option("-flto-partition=one");
666+
context.add_command_line_option("-fno-fat-lto-objects");
667+
context.add_driver_option("-fno-fat-lto-objects");
656668
context.add_command_line_option("-fno-use-linker-plugin");
657669
context.add_driver_option("-fno-use-linker-plugin");
658670
let len = thin_module.shared.thin_buffers.len();

src/back/write.rs

+28-7
Original file line numberDiff line numberDiff line change
@@ -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.

src/base.rs

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ pub fn compile_codegen_unit(
100100
let cgu = tcx.codegen_unit(cgu_name);
101101
// Instantiate monomorphizations without filling out definitions yet...
102102
let context = new_context(tcx);
103+
println!("==== Module codegen: {}", cgu_name);
104+
context.add_driver_option("-fno-use-linker-plugin");
103105

104106
if tcx.sess.panic_strategy() == PanicStrategy::Unwind {
105107
context.add_command_line_option("-fexceptions");

src/lib.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl CodegenBackend for GccCodegenBackend {
196196
// Get the second TargetInfo with the correct CPU features by setting the arch.
197197
let context = Context::default();
198198
context.add_command_line_option("-fno-use-linker-plugin");
199-
context.add_driver_option("-fno-use-linker-plugin");
199+
//context.add_driver_option("-fno-use-linker-plugin");
200200
if target_cpu != "generic" {
201201
context.add_command_line_option(format!("-march={}", target_cpu));
202202
}
@@ -213,7 +213,7 @@ impl CodegenBackend for GccCodegenBackend {
213213
let temp_file = temp_dir.into_path().join("result.asm");
214214
let check_context = Context::default();
215215
context.add_command_line_option("-fno-use-linker-plugin");
216-
context.add_driver_option("-fno-use-linker-plugin");
216+
//context.add_driver_option("-fno-use-linker-plugin");
217217
check_context.set_print_errors_to_stderr(false);
218218
let _int128_ty = check_context.new_c_type(CType::UInt128t);
219219
// NOTE: we cannot just call compile() as this would require other files than libgccjit.so.
@@ -271,8 +271,12 @@ impl CodegenBackend for GccCodegenBackend {
271271

272272
fn new_context<'gcc, 'tcx>(tcx: TyCtxt<'tcx>) -> Context<'gcc> {
273273
let context = Context::default();
274+
context.add_command_line_option("-flto=auto");
275+
context.add_command_line_option("-flto-partition=one");
276+
context.add_driver_option("-flto=auto");
277+
context.add_driver_option("-flto-partition=one");
274278
context.add_command_line_option("-fno-use-linker-plugin");
275-
context.add_driver_option("-fno-use-linker-plugin");
279+
//context.add_driver_option("-fno-use-linker-plugin");
276280
if tcx.sess.target.arch == "x86" || tcx.sess.target.arch == "x86_64" {
277281
context.add_command_line_option("-masm=intel");
278282
}
@@ -306,6 +310,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
306310
should_combine_object_files: false,
307311
temp_dir: None,
308312
};
313+
mods.context.add_driver_option("-fno-use-linker-plugin");
309314

310315
unsafe {
311316
allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind);
@@ -468,7 +473,7 @@ pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
468473
// Float16).
469474
let context = Context::default();
470475
context.add_command_line_option("-fno-use-linker-plugin");
471-
context.add_driver_option("-fno-use-linker-plugin");
476+
//context.add_driver_option("-fno-use-linker-plugin");
472477
Arc::new(Mutex::new(IntoDynSyncSend(context.get_target_info())))
473478
};
474479
#[cfg(not(feature = "master"))]

0 commit comments

Comments
 (0)