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.
This commit is contained in:
Andrew Kelley 2019-10-24 19:43:56 -04:00
parent f8bd1cd3b1
commit ad438a95c5
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
3 changed files with 17 additions and 4 deletions

View File

@ -8762,7 +8762,9 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &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));

View File

@ -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) {

View File

@ -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);