authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-24 19:43:56-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-24 19:43:56-04:00
logad438a95c528c4a2013e3e7fb99ea9a260143eb3
tree7d4daebb99dd0d1fbc9b324f0416b9bc86008f70
parentf8bd1cd3b11802d3566d287167d79d3cfc3ef41d
signaturelock-open Commit is signed but in an unrecognized format.

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.

3 files changed, 17 insertions(+), 4 deletions(-)

src/codegen.cpp+3-1
...@@ -8762,7 +8762,9 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa...@@ -8762,7 +8762,9 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
8762 }8762 }
87638763
8764 if (g->zig_target->is_native) {8764 if (g->zig_target->is_native) {
8765 args.append("-march=native");8765 if (target_supports_clang_march_native(g->zig_target)) {
8766 args.append("-march=native");
8767 }
8766 } else {8768 } else {
8767 args.append("-target");8769 args.append("-target");
8768 args.append(buf_ptr(&g->llvm_triple_str));8770 args.append(buf_ptr(&g->llvm_triple_str));
src/target.cpp+13-3
...@@ -1583,9 +1583,19 @@ bool target_os_requires_libc(Os os) {...@@ -1583,9 +1583,19 @@ bool target_os_requires_libc(Os os) {
1583}1583}
15841584
1585bool target_supports_fpic(const ZigTarget *target) {1585bool target_supports_fpic(const ZigTarget *target) {
1586 // This is not whether the target supports Position Independent Code, but whether the -fPIC1586 // This is not whether the target supports Position Independent Code, but whether the -fPIC
1587 // C compiler argument is valid.1587 // C compiler argument is valid.
1588 return target->os != OsWindows;1588 return target->os != OsWindows;
1589}
1590
1591bool target_supports_clang_march_native(const ZigTarget *target) {
1592 // Whether clang supports -march=native on this target.
1593 // Arguably it should always work, but in reality it gives:
1594 // error: the clang compiler does not support '-march=native'
1595 // If we move CPU detection logic into Zig itelf, we will not need this,
1596 // instead we will always pass target features and CPU configuration explicitly.
1597 return target->arch != ZigLLVM_aarch64 &&
1598 target->arch != ZigLLVM_aarch64_be;
1589}1599}
15901600
1591bool target_supports_stack_probing(const ZigTarget *target) {1601bool target_supports_stack_probing(const ZigTarget *target) {
src/target.hpp+1
...@@ -182,6 +182,7 @@ bool target_can_build_libc(const ZigTarget *target);...@@ -182,6 +182,7 @@ bool target_can_build_libc(const ZigTarget *target);
182const char *target_libc_generic_name(const ZigTarget *target);182const char *target_libc_generic_name(const ZigTarget *target);
183bool target_is_libc_lib_name(const ZigTarget *target, const char *name);183bool target_is_libc_lib_name(const ZigTarget *target, const char *name);
184bool target_supports_fpic(const ZigTarget *target);184bool target_supports_fpic(const ZigTarget *target);
185bool target_supports_clang_march_native(const ZigTarget *target);
185bool target_requires_pic(const ZigTarget *target, bool linking_libc);186bool target_requires_pic(const ZigTarget *target, bool linking_libc);
186bool target_requires_pie(const ZigTarget *target);187bool target_requires_pie(const ZigTarget *target);
187bool target_abi_is_gnu(ZigLLVM_EnvironmentType abi);188bool target_abi_is_gnu(ZigLLVM_EnvironmentType abi);