diff --git a/src/codegen.cpp b/src/codegen.cpp index 1c21a4a527..ba189baf89 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 1cab9253a0..9af42b7d9d 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 f4c638f196..e6b152be53 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);