diff --git a/src/base.rs b/src/base.rs index 91efcf18bf4..61da38f4b0d 100644 --- a/src/base.rs +++ b/src/base.rs @@ -19,7 +19,7 @@ use rustc_session::config::DebugInfo; use rustc_span::Symbol; -use crate::LockedTargetInfo; +use crate::{LockedTargetInfo, gcc_util}; use crate::GccContext; use crate::builder::Builder; use crate::context::CodegenCx; @@ -101,8 +101,6 @@ fn module_codegen(tcx: TyCtxt<'_>, (cgu_name, target_info): (Symbol, LockedTarge // TODO(antoyo): only set on x86 platforms. context.add_command_line_option("-masm=intel"); - // TODO(antoyo): set the correct -march flag. - if !disabled_features.contains("avx") { // NOTE: we always enable AVX because the equivalent of llvm.x86.sse2.cmp.pd in GCC for // SSE2 is multiple builtins, so we use the AVX __builtin_ia32_cmppd instead. @@ -127,6 +125,11 @@ fn module_codegen(tcx: TyCtxt<'_>, (cgu_name, target_info): (Symbol, LockedTarge context.add_command_line_option("-fno-pie"); } + let target_cpu = gcc_util::target_cpu(tcx.sess); + if target_cpu != "generic" { + context.add_command_line_option(&format!("-march={}", target_cpu)); + } + if tcx.sess.opts.unstable_opts.function_sections.unwrap_or(tcx.sess.target.function_sections) { context.add_command_line_option("-ffunction-sections"); context.add_command_line_option("-fdata-sections"); diff --git a/src/gcc_util.rs b/src/gcc_util.rs index 09a0af5d00d..91a815c0771 100644 --- a/src/gcc_util.rs +++ b/src/gcc_util.rs @@ -198,3 +198,18 @@ pub fn check_tied_features(sess: &Session, features: &FxHashMap<&str, bool>) -> } None } + +fn handle_native(name: &str) -> &str { + if name != "native" { + return name; + } + + unimplemented!(); +} + +pub fn target_cpu(sess: &Session) -> &str { + match sess.opts.cg.target_cpu { + Some(ref name) => handle_native(name), + None => handle_native(sess.target.cpu.as_ref()), + } +} diff --git a/src/lib.rs b/src/lib.rs index eedac315c60..df33e6cbd61 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,6 +107,7 @@ use tempfile::TempDir; use crate::back::lto::ModuleBuffer; +use crate::gcc_util::target_cpu; fluent_messages! { "../messages.ftl" } @@ -366,21 +367,6 @@ fn to_gcc_opt_level(optlevel: Option) -> OptimizationLevel { } } -fn handle_native(name: &str) -> &str { - if name != "native" { - return name; - } - - unimplemented!(); -} - -pub fn target_cpu(sess: &Session) -> &str { - match sess.opts.cg.target_cpu { - Some(ref name) => handle_native(name), - None => handle_native(sess.target.cpu.as_ref()), - } -} - pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &LockedTargetInfo) -> Vec { supported_target_features(sess) .iter()