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
+ //
1
7
// FIXME:
2
8
// fat-lto UI test fail with:
3
9
// x86_64-pc-linux-gnu-gcc-13.1.0: fatal error: ‘-fuse-linker-plugin’, but liblto_plugin.so not found
10
16
// 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.
11
17
// => Maybe it's the symbol file?
12
18
// => 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.
13
38
//
14
39
// FIXME:
15
40
// I had to copy lto1, crtbegin.o from the system to /opt/…
20
45
// warning: using serial compilation of 26 LTRANS jobs
21
46
// lto-wrapper: note: see the '-flto' option documentation for more information
22
47
//
23
- // strace shows that we still have those warnings:
48
+ // strace shows that we indeed had those warnings:
24
49
// [pid 8775] write(2, "lto-wrapper: warning: using seri"..., 65) = 65
25
50
// [pid 8775] write(2, "lto-wrapper: note: see the '-flt"..., 77) = 77
26
51
//
@@ -30,7 +55,7 @@ use std::fs::{self, File};
30
55
use std:: path:: { Path , PathBuf } ;
31
56
use std:: sync:: atomic:: Ordering ;
32
57
33
- use gccjit:: OutputKind ;
58
+ use gccjit:: { OutputKind , OptimizationLevel } ;
34
59
use object:: read:: archive:: ArchiveFile ;
35
60
use rustc_codegen_ssa:: back:: lto:: { LtoModuleCodegen , SerializedModule } ;
36
61
use rustc_codegen_ssa:: back:: symbol_export;
@@ -280,7 +305,14 @@ fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &Handler, mod
280
305
// TODO: add the proper file extension here?
281
306
let path = tmp_path. path ( ) . to_path_buf ( ) . join ( & module. name ) ;
282
307
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) ;
284
316
let buffer = ModuleBuffer :: new ( PathBuf :: from ( path) ) ;
285
317
let llmod_id = CString :: new ( & module. name [ ..] ) . unwrap ( ) ;
286
318
serialized_modules. push ( ( SerializedModule :: Local ( buffer) , llmod_id) ) ;
0 commit comments