@@ -3,6 +3,7 @@ use crate::llvm;
3
3
use syntax_pos:: symbol:: Symbol ;
4
4
use rustc:: session:: Session ;
5
5
use rustc:: session:: config:: PrintRequest ;
6
+ use rustc_data_structures:: fx:: FxHashSet ;
6
7
use rustc_target:: spec:: { MergeFunctions , PanicStrategy } ;
7
8
use libc:: c_int;
8
9
use std:: ffi:: CString ;
@@ -51,43 +52,62 @@ unsafe fn configure_llvm(sess: &Session) {
51
52
52
53
llvm:: LLVMRustInstallFatalErrorHandler ( ) ;
53
54
55
+ fn llvm_arg_to_arg_name ( full_arg : & str ) -> & str {
56
+ full_arg. trim ( ) . split ( |c : char | {
57
+ c == '=' || c. is_whitespace ( )
58
+ } ) . next ( ) . unwrap_or ( "" )
59
+ }
60
+
61
+ let user_specified_args: FxHashSet < _ > = sess
62
+ . opts
63
+ . cg
64
+ . llvm_args
65
+ . iter ( )
66
+ . map ( |s| llvm_arg_to_arg_name ( s) )
67
+ . filter ( |s| s. len ( ) > 0 )
68
+ . collect ( ) ;
69
+
54
70
{
55
- let mut add = |arg : & str | {
56
- let s = CString :: new ( arg) . unwrap ( ) ;
57
- llvm_args. push ( s. as_ptr ( ) ) ;
58
- llvm_c_strs. push ( s) ;
71
+ // This adds the given argument to LLVM. Unless `force` is true
72
+ // user specified arguments are *not* overridden.
73
+ let mut add = |arg : & str , force : bool | {
74
+ if force || !user_specified_args. contains ( llvm_arg_to_arg_name ( arg) ) {
75
+ let s = CString :: new ( arg) . unwrap ( ) ;
76
+ llvm_args. push ( s. as_ptr ( ) ) ;
77
+ llvm_c_strs. push ( s) ;
78
+ }
59
79
} ;
60
- add ( "rustc" ) ; // fake program name
61
- if sess. time_llvm_passes ( ) { add ( "-time-passes" ) ; }
62
- if sess. print_llvm_passes ( ) { add ( "-debug-pass=Structure" ) ; }
80
+ add ( "rustc" , true ) ; // fake program name
81
+ if sess. time_llvm_passes ( ) { add ( "-time-passes" , false ) ; }
82
+ if sess. print_llvm_passes ( ) { add ( "-debug-pass=Structure" , false ) ; }
63
83
if sess. opts . debugging_opts . disable_instrumentation_preinliner {
64
- add ( "-disable-preinline" ) ;
84
+ add ( "-disable-preinline" , false ) ;
65
85
}
66
86
if sess. opts . debugging_opts . generate_arange_section {
67
- add ( "-generate-arange-section" ) ;
87
+ add ( "-generate-arange-section" , false ) ;
68
88
}
69
89
if get_major_version ( ) >= 8 {
70
90
match sess. opts . debugging_opts . merge_functions
71
91
. unwrap_or ( sess. target . target . options . merge_functions ) {
72
92
MergeFunctions :: Disabled |
73
93
MergeFunctions :: Trampolines => { }
74
94
MergeFunctions :: Aliases => {
75
- add ( "-mergefunc-use-aliases" ) ;
95
+ add ( "-mergefunc-use-aliases" , false ) ;
76
96
}
77
97
}
78
98
}
79
99
80
100
if sess. target . target . target_os == "emscripten" &&
81
101
sess. panic_strategy ( ) == PanicStrategy :: Unwind {
82
- add ( "-enable-emscripten-cxx-exceptions" ) ;
102
+ add ( "-enable-emscripten-cxx-exceptions" , false ) ;
83
103
}
84
104
85
105
// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
86
106
// during inlining. Unfortunately these may block other optimizations.
87
- add ( "-preserve-alignment-assumptions-during-inlining=false" ) ;
107
+ add ( "-preserve-alignment-assumptions-during-inlining=false" , false ) ;
88
108
89
109
for arg in & sess. opts . cg . llvm_args {
90
- add ( & ( * arg) ) ;
110
+ add ( & ( * arg) , true ) ;
91
111
}
92
112
}
93
113
0 commit comments