about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-21 15:29:44 +0100
committerGitHub <noreply@github.com>2019-12-21 15:29:44 +0100
commit6e3b1d63b6445cb55d75b1c360e99752e7c1fb94 (patch)
tree70bf2dfe7adb3d84ccfc3ec5eb45deac01e873d2
parentc0bf3afc96246ddefd3bcecc77c62bed1f00f14e (diff)
parent1ca145c3b5b7bc8907ff6f176df2b5687a8ea85f (diff)
downloadrust-6e3b1d63b6445cb55d75b1c360e99752e7c1fb94.tar.gz
rust-6e3b1d63b6445cb55d75b1c360e99752e7c1fb94.zip
Rollup merge of #67393 - michaelwoerister:llvm-args-override, r=varkor
Enable opting out of specific default LLVM arguments.

`rustc` by default adds a few arguments to LLVM (like `-mergefunc-use-aliases` for example). With this PR `rustc` will only emit these arguments if the same argument has not already been specified by the user via `-Cllvm-args`. This enables opting out of these defaults.

The PR also removes a PGO specific `-Z` flag the effect of which can also be easily achieved by `-Cllvm-args`.

Fixes https://github.com/rust-lang/rust/issues/64310.
-rw-r--r--src/librustc_codegen_llvm/llvm_util.rs48
-rw-r--r--src/librustc_session/options.rs2
2 files changed, 33 insertions, 17 deletions
diff --git a/src/librustc_codegen_llvm/llvm_util.rs b/src/librustc_codegen_llvm/llvm_util.rs
index 40739387b00..3145b0df63b 100644
--- a/src/librustc_codegen_llvm/llvm_util.rs
+++ b/src/librustc_codegen_llvm/llvm_util.rs
@@ -3,6 +3,7 @@ use crate::llvm;
 use syntax_pos::symbol::Symbol;
 use rustc::session::Session;
 use rustc::session::config::PrintRequest;
+use rustc_data_structures::fx::FxHashSet;
 use rustc_target::spec::{MergeFunctions, PanicStrategy};
 use libc::c_int;
 use std::ffi::CString;
@@ -51,20 +52,37 @@ unsafe fn configure_llvm(sess: &Session) {
 
     llvm::LLVMRustInstallFatalErrorHandler();
 
+    fn llvm_arg_to_arg_name(full_arg: &str) -> &str {
+        full_arg.trim().split(|c: char| {
+            c == '=' || c.is_whitespace()
+        }).next().unwrap_or("")
+    }
+
+    let user_specified_args: FxHashSet<_> = sess
+        .opts
+        .cg
+        .llvm_args
+        .iter()
+        .map(|s| llvm_arg_to_arg_name(s))
+        .filter(|s| s.len() > 0)
+        .collect();
+
     {
-        let mut add = |arg: &str| {
-            let s = CString::new(arg).unwrap();
-            llvm_args.push(s.as_ptr());
-            llvm_c_strs.push(s);
+        // This adds the given argument to LLVM. Unless `force` is true
+        // user specified arguments are *not* overridden.
+        let mut add = |arg: &str, force: bool| {
+            if force || !user_specified_args.contains(llvm_arg_to_arg_name(arg)) {
+                let s = CString::new(arg).unwrap();
+                llvm_args.push(s.as_ptr());
+                llvm_c_strs.push(s);
+            }
         };
-        add("rustc"); // fake program name
-        if sess.time_llvm_passes() { add("-time-passes"); }
-        if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
-        if sess.opts.debugging_opts.disable_instrumentation_preinliner {
-            add("-disable-preinline");
-        }
+        add("rustc", true); // fake program name
+        if sess.time_llvm_passes() { add("-time-passes", false); }
+        if sess.print_llvm_passes() { add("-debug-pass=Structure", false); }
+
         if sess.opts.debugging_opts.generate_arange_section {
-            add("-generate-arange-section");
+            add("-generate-arange-section", false);
         }
         if get_major_version() >= 8 {
             match sess.opts.debugging_opts.merge_functions
@@ -72,22 +90,22 @@ unsafe fn configure_llvm(sess: &Session) {
                 MergeFunctions::Disabled |
                 MergeFunctions::Trampolines => {}
                 MergeFunctions::Aliases => {
-                    add("-mergefunc-use-aliases");
+                    add("-mergefunc-use-aliases", false);
                 }
             }
         }
 
         if sess.target.target.target_os == "emscripten" &&
             sess.panic_strategy() == PanicStrategy::Unwind {
-            add("-enable-emscripten-cxx-exceptions");
+            add("-enable-emscripten-cxx-exceptions", false);
         }
 
         // HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
         // during inlining. Unfortunately these may block other optimizations.
-        add("-preserve-alignment-assumptions-during-inlining=false");
+        add("-preserve-alignment-assumptions-during-inlining=false", false);
 
         for arg in &sess.opts.cg.llvm_args {
-            add(&(*arg));
+            add(&(*arg), true);
         }
     }
 
diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs
index 9ddc9c0d602..2f2d03fc596 100644
--- a/src/librustc_session/options.rs
+++ b/src/librustc_session/options.rs
@@ -866,8 +866,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
         "extra arguments to prepend to the linker invocation (space separated)"),
     profile: bool = (false, parse_bool, [TRACKED],
                      "insert profiling code"),
-    disable_instrumentation_preinliner: bool = (false, parse_bool, [TRACKED],
-        "Disable the instrumentation pre-inliner, useful for profiling / PGO."),
     relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
         "choose which RELRO level to use"),
     nll_facts: bool = (false, parse_bool, [UNTRACKED],