@@ -68,15 +68,13 @@ pub enum OptLevel {
68
68
SizeMin , // -Oz
69
69
}
70
70
71
+ /// This is what the `LtoCli` values get mapped to after resolving defaults and
72
+ /// and taking other command line options into account.
71
73
#[ derive( Clone , Copy , PartialEq , Hash , Debug ) ]
72
74
pub enum Lto {
73
75
/// Don't do any LTO whatsoever
74
76
No ,
75
77
76
- /// Do a full crate graph LTO. The flavor is determined by the compiler
77
- /// (currently the default is "fat").
78
- Yes ,
79
-
80
78
/// Do a full crate graph LTO with ThinLTO
81
79
Thin ,
82
80
@@ -88,6 +86,23 @@ pub enum Lto {
88
86
Fat ,
89
87
}
90
88
89
+ /// The different settings that the `-C lto` flag can have.
90
+ #[ derive( Clone , Copy , PartialEq , Hash , Debug ) ]
91
+ pub enum LtoCli {
92
+ /// `-C lto=no`
93
+ No ,
94
+ /// `-C lto=yes`
95
+ Yes ,
96
+ /// `-C lto`
97
+ NoParam ,
98
+ /// `-C lto=thin`
99
+ Thin ,
100
+ /// `-C lto=fat`
101
+ Fat ,
102
+ /// No `-C lto` flag passed
103
+ Unspecified ,
104
+ }
105
+
91
106
#[ derive( Clone , PartialEq , Hash ) ]
92
107
pub enum CrossLangLto {
93
108
LinkerPlugin ( PathBuf ) ,
@@ -801,15 +816,16 @@ macro_rules! options {
801
816
pub const parse_unpretty: Option <& ' static str > =
802
817
Some ( "`string` or `string=string`" ) ;
803
818
pub const parse_lto: Option <& ' static str > =
804
- Some ( "one of `thin`, `fat`, or omitted" ) ;
819
+ Some ( "either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \
820
+ `fat`, or omitted") ;
805
821
pub const parse_cross_lang_lto: Option <& ' static str > =
806
822
Some ( "either a boolean (`yes`, `no`, `on`, `off`, etc), \
807
823
or the path to the linker plugin") ;
808
824
}
809
825
810
826
#[ allow( dead_code) ]
811
827
mod $mod_set {
812
- use super :: { $struct_name, Passes , Sanitizer , Lto , CrossLangLto } ;
828
+ use super :: { $struct_name, Passes , Sanitizer , LtoCli , CrossLangLto } ;
813
829
use rustc_target:: spec:: { LinkerFlavor , PanicStrategy , RelroLevel } ;
814
830
use std:: path:: PathBuf ;
815
831
@@ -1002,11 +1018,23 @@ macro_rules! options {
1002
1018
}
1003
1019
}
1004
1020
1005
- fn parse_lto( slot: & mut Lto , v: Option <& str >) -> bool {
1021
+ fn parse_lto( slot: & mut LtoCli , v: Option <& str >) -> bool {
1022
+ if v. is_some( ) {
1023
+ let mut bool_arg = None ;
1024
+ if parse_opt_bool( & mut bool_arg, v) {
1025
+ * slot = if bool_arg. unwrap( ) {
1026
+ LtoCli :: Yes
1027
+ } else {
1028
+ LtoCli :: No
1029
+ } ;
1030
+ return true
1031
+ }
1032
+ }
1033
+
1006
1034
* slot = match v {
1007
- None => Lto :: Yes ,
1008
- Some ( "thin" ) => Lto :: Thin ,
1009
- Some ( "fat" ) => Lto :: Fat ,
1035
+ None => LtoCli :: NoParam ,
1036
+ Some ( "thin" ) => LtoCli :: Thin ,
1037
+ Some ( "fat" ) => LtoCli :: Fat ,
1010
1038
Some ( _) => return false ,
1011
1039
} ;
1012
1040
true
@@ -1047,7 +1075,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
1047
1075
"extra arguments to append to the linker invocation (space separated)" ) ,
1048
1076
link_dead_code: bool = ( false , parse_bool, [ UNTRACKED ] ,
1049
1077
"don't let linker strip dead code (turning it on can be used for code coverage)" ) ,
1050
- lto: Lto = ( Lto :: No , parse_lto, [ TRACKED ] ,
1078
+ lto: LtoCli = ( LtoCli :: Unspecified , parse_lto, [ TRACKED ] ,
1051
1079
"perform LLVM link-time optimizations" ) ,
1052
1080
target_cpu: Option <String > = ( None , parse_opt_string, [ TRACKED ] ,
1053
1081
"select target processor (rustc --print target-cpus for details)" ) ,
@@ -2384,8 +2412,8 @@ mod dep_tracking {
2384
2412
use std:: hash:: Hash ;
2385
2413
use std:: path:: PathBuf ;
2386
2414
use std:: collections:: hash_map:: DefaultHasher ;
2387
- use super :: { CrateType , DebugInfo , ErrorOutputType , Lto , OptLevel , OutputTypes ,
2388
- Passes , Sanitizer , CrossLangLto } ;
2415
+ use super :: { CrateType , DebugInfo , ErrorOutputType , OptLevel , OutputTypes ,
2416
+ Passes , Sanitizer , LtoCli , CrossLangLto } ;
2389
2417
use syntax:: feature_gate:: UnstableFeatures ;
2390
2418
use rustc_target:: spec:: { PanicStrategy , RelroLevel , TargetTriple } ;
2391
2419
use syntax:: edition:: Edition ;
@@ -2440,7 +2468,7 @@ mod dep_tracking {
2440
2468
impl_dep_tracking_hash_via_hash ! ( RelroLevel ) ;
2441
2469
impl_dep_tracking_hash_via_hash ! ( Passes ) ;
2442
2470
impl_dep_tracking_hash_via_hash ! ( OptLevel ) ;
2443
- impl_dep_tracking_hash_via_hash ! ( Lto ) ;
2471
+ impl_dep_tracking_hash_via_hash ! ( LtoCli ) ;
2444
2472
impl_dep_tracking_hash_via_hash ! ( DebugInfo ) ;
2445
2473
impl_dep_tracking_hash_via_hash ! ( UnstableFeatures ) ;
2446
2474
impl_dep_tracking_hash_via_hash ! ( OutputTypes ) ;
@@ -2514,7 +2542,7 @@ mod tests {
2514
2542
use lint;
2515
2543
use middle:: cstore;
2516
2544
use session:: config:: { build_configuration, build_session_options_and_crate_config} ;
2517
- use session:: config:: { Lto , CrossLangLto } ;
2545
+ use session:: config:: { LtoCli , CrossLangLto } ;
2518
2546
use session:: build_session;
2519
2547
use std:: collections:: { BTreeMap , BTreeSet } ;
2520
2548
use std:: iter:: FromIterator ;
@@ -2948,7 +2976,7 @@ mod tests {
2948
2976
2949
2977
// Make sure changing a [TRACKED] option changes the hash
2950
2978
opts = reference. clone ( ) ;
2951
- opts. cg . lto = Lto :: Fat ;
2979
+ opts. cg . lto = LtoCli :: Fat ;
2952
2980
assert ! ( reference. dep_tracking_hash( ) != opts. dep_tracking_hash( ) ) ;
2953
2981
2954
2982
opts = reference. clone ( ) ;
0 commit comments