From ad438a95c528c4a2013e3e7fb99ea9a260143eb3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 24 Oct 2019 19:43:56 -0400 Subject: [PATCH] avoid passing -march=native when not supported Clang does not support -march=native for all targets. Arguably it should always work, but in reality it gives: error: the clang compiler does not support '-march=native' If we move CPU detection logic into Zig itelf, we will not need this, instead we will always pass target features and CPU configuration explicitly. For now, we simply avoid passing the flag when it is known to not be supported. --- src/codegen.cpp | 4 +++- src/target.cpp | 16 +++++++++++++--- src/target.hpp | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 1c21a4a5271501cce353fa63ed1ffb455eb1acd4..ba189baf896d66608fc0c67204095079ee3bb3eb 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8762,7 +8762,9 @@ void add_cc_args(CodeGen *g, ZigList &args, const char *out_dep_pa } if (g->zig_target->is_native) { - args.append("-march=native"); + if (target_supports_clang_march_native(g->zig_target)) { + args.append("-march=native"); + } } else { args.append("-target"); args.append(buf_ptr(&g->llvm_triple_str)); diff --git a/src/target.cpp b/src/target.cpp index 1cab9253a07ae7810fe885e96472914cd773fa98..9af42b7d9d82c9ed8376f1a473141b45309a8a80 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -1583,9 +1583,19 @@ bool target_os_requires_libc(Os os) { } bool target_supports_fpic(const ZigTarget *target) { - // This is not whether the target supports Position Independent Code, but whether the -fPIC - // C compiler argument is valid. - return target->os != OsWindows; + // This is not whether the target supports Position Independent Code, but whether the -fPIC + // C compiler argument is valid. + return target->os != OsWindows; +} + +bool target_supports_clang_march_native(const ZigTarget *target) { + // Whether clang supports -march=native on this target. + // Arguably it should always work, but in reality it gives: + // error: the clang compiler does not support '-march=native' + // If we move CPU detection logic into Zig itelf, we will not need this, + // instead we will always pass target features and CPU configuration explicitly. + return target->arch != ZigLLVM_aarch64 && + target->arch != ZigLLVM_aarch64_be; } bool target_supports_stack_probing(const ZigTarget *target) { diff --git a/src/target.hpp b/src/target.hpp index f4c638f19650657b0e2b0a277e8defacc430150c..e6b152be53ace68e46962177f9cc42f639dfeb2e 100644 --- a/src/target.hpp +++ b/src/target.hpp @@ -182,6 +182,7 @@ bool target_can_build_libc(const ZigTarget *target); const char *target_libc_generic_name(const ZigTarget *target); bool target_is_libc_lib_name(const ZigTarget *target, const char *name); bool target_supports_fpic(const ZigTarget *target); +bool target_supports_clang_march_native(const ZigTarget *target); bool target_requires_pic(const ZigTarget *target, bool linking_libc); bool target_requires_pie(const ZigTarget *target); bool target_abi_is_gnu(ZigLLVM_EnvironmentType abi); -- 2.54.0