| author | |
| committer | |
| log | ad438a95c528c4a2013e3e7fb99ea9a260143eb3 |
| tree | 7d4daebb99dd0d1fbc9b324f0416b9bc86008f70 |
| parent | f8bd1cd3b11802d3566d287167d79d3cfc3ef41d |
| signature |
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 | } |
| 8763 | 8763 | ||
| 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 | } |
| 1584 | 1584 | ||
| 1585 | bool target_supports_fpic(const ZigTarget *target) { | 1585 | bool target_supports_fpic(const ZigTarget *target) { |
| 1586 | // This is not whether the target supports Position Independent Code, but whether the -fPIC | 1586 | // 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 | |||
| 1591 | bool 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 | } |
| 1590 | 1600 | ||
| 1591 | bool target_supports_stack_probing(const ZigTarget *target) { | 1601 | bool 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); |
| 182 | const char *target_libc_generic_name(const ZigTarget *target); | 182 | const char *target_libc_generic_name(const ZigTarget *target); |
| 183 | bool target_is_libc_lib_name(const ZigTarget *target, const char *name); | 183 | bool target_is_libc_lib_name(const ZigTarget *target, const char *name); |
| 184 | bool target_supports_fpic(const ZigTarget *target); | 184 | bool target_supports_fpic(const ZigTarget *target); |
| 185 | bool target_supports_clang_march_native(const ZigTarget *target); | ||
| 185 | bool target_requires_pic(const ZigTarget *target, bool linking_libc); | 186 | bool target_requires_pic(const ZigTarget *target, bool linking_libc); |
| 186 | bool target_requires_pie(const ZigTarget *target); | 187 | bool target_requires_pie(const ZigTarget *target); |
| 187 | bool target_abi_is_gnu(ZigLLVM_EnvironmentType abi); | 188 | bool target_abi_is_gnu(ZigLLVM_EnvironmentType abi); |