Skip to content

Commit ea0bb71

Browse files
committed
Fix files not used for LTO
1 parent b5eee91 commit ea0bb71

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/back/lto.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// TODO: do not embed the bitcode in the final binary.
2+
// It doesn't look like we try to generate fat objects for the final binary.
3+
// Check if the way we combine the object files make it keep the LTO sections on the final link.
4+
// FIXME: Maybe that's because the combined object files contain the IR (true) and the final link
5+
// does not remove it?
6+
//
17
// FIXME:
28
// fat-lto UI test fail with:
39
// x86_64-pc-linux-gnu-gcc-13.1.0: fatal error: ‘-fuse-linker-plugin’, but liblto_plugin.so not found
@@ -10,6 +16,25 @@
1016
// FIXME: if any of object files in incremental link cannot be used for link-time optimization, the linker plugin issues a warning and uses nolto-rel.
1117
// => Maybe it's the symbol file?
1218
// => There's a least the rust_alloc file.
19+
// => There are also these files:
20+
//
21+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.0
22+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.1
23+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.10
24+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.11
25+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.12
26+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.13
27+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.14
28+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.15
29+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.2
30+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.4
31+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.5
32+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.6
33+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.7
34+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.8
35+
// Non claimed: /tmp/.tmpgTaub4/uncbv.f5023a46-cgu.9
36+
//
37+
// TODO: make sure the CGUs of the current project ^ are compiled with LTO.
1338
//
1439
// FIXME:
1540
// I had to copy lto1, crtbegin.o from the system to /opt/…
@@ -20,7 +45,7 @@
2045
// warning: using serial compilation of 26 LTRANS jobs
2146
// lto-wrapper: note: see the '-flto' option documentation for more information
2247
//
23-
// strace shows that we still have those warnings:
48+
// strace shows that we indeed had those warnings:
2449
// [pid 8775] write(2, "lto-wrapper: warning: using seri"..., 65) = 65
2550
// [pid 8775] write(2, "lto-wrapper: note: see the '-flt"..., 77) = 77
2651
//
@@ -30,7 +55,7 @@ use std::fs::{self, File};
3055
use std::path::{Path, PathBuf};
3156
use std::sync::atomic::Ordering;
3257

33-
use gccjit::OutputKind;
58+
use gccjit::{OutputKind, OptimizationLevel};
3459
use object::read::archive::ArchiveFile;
3560
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule};
3661
use rustc_codegen_ssa::back::symbol_export;
@@ -280,7 +305,14 @@ fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &Handler, mod
280305
// TODO: add the proper file extension here?
281306
let path = tmp_path.path().to_path_buf().join(&module.name);
282307
let path = path.to_str().expect("path");
283-
module.module_llvm.context.compile_to_file(OutputKind::ObjectFile, path);
308+
let context = &module.module_llvm.context;
309+
// TODO: do we need the optimization level here?
310+
context.set_optimization_level(OptimizationLevel::Aggressive);
311+
context.add_command_line_option("-flto=auto");
312+
context.add_driver_option("-flto=auto");
313+
context.add_command_line_option("-flto-partition=one");
314+
context.add_driver_option("-flto-partition=one");
315+
context.compile_to_file(OutputKind::ObjectFile, path);
284316
let buffer = ModuleBuffer::new(PathBuf::from(path));
285317
let llmod_id = CString::new(&module.name[..]).unwrap();
286318
serialized_modules.push((SerializedModule::Local(buffer), llmod_id));

src/back/write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
4646
let _timer = cgcx
4747
.prof
4848
.generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name);
49+
// TODO: deduplicate add_command_line_option and add_driver_option.
4950
context.add_command_line_option("-flto=auto");
5051
context.add_driver_option("-flto=auto");
5152
context.add_command_line_option("-flto-partition=one");

src/base.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, supports_128bit_i
153153
context.set_keep_intermediates(true);
154154
}
155155

156+
if env::var("CG_GCCJIT_VERBOSE").as_deref() == Ok("1") {
157+
context.add_driver_option("-v");
158+
}
159+
156160
// NOTE: The codegen generates unrechable blocks.
157161
context.set_allow_unreachable_blocks(true);
158162

0 commit comments

Comments
 (0)