From e381a42de9c0f0c5439a926b0ac99026a0373f49 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 20 Feb 2020 17:02:29 -0500 Subject: [PATCH] quick fix: add -mcpu=baseline support to zig0 When the build.zig logic to build libzigstage2 was converted to a cmake command, it neglected to use baseline CPU features rather than compiling with native features. This adds a hard coded flag `-mcpu=baseline` which can be used to detect the native target, but mark it as non-native so that it does not get the CPU features specific to the host used to compile libzigstage2. Full `-mcpu` support is happening in the upcoming pull request #4509, and so this "quick fix" will be cleaned up in that branch, before it is merged to master. closes #4506 --- CMakeLists.txt | 1 + src/main.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab4607d23..a3d6a7fb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -616,6 +616,7 @@ endif() set(BUILD_LIBSTAGE2_ARGS "build-lib" "src-self-hosted/stage2.zig" + -mcpu=baseline --name zigstage2 --override-lib-dir "${CMAKE_SOURCE_DIR}/lib" --cache on diff --git a/src/main.cpp b/src/main.cpp index d7f5e5b7b..5046c92dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -450,6 +450,7 @@ static int main0(int argc, char **argv) { const char *cpu = nullptr; const char *features = nullptr; CodeModel code_model = CodeModelDefault; + bool baseline_cpu = false; ZigList llvm_argv = {0}; llvm_argv.append("zig (LLVM option parsing)"); @@ -716,6 +717,8 @@ static int main0(int argc, char **argv) { emit_llvm_ir = true; } else if (strcmp(arg, "-fno-emit-llvm-ir") == 0) { emit_llvm_ir = false; + } else if (strcmp(arg, "-mcpu=baseline") == 0) { + baseline_cpu = true; } else if (i + 1 >= argc) { fprintf(stderr, "Expected another argument after %s\n", arg); return print_error_usage(arg0); @@ -977,6 +980,9 @@ static int main0(int argc, char **argv) { fprintf(stderr, "-target-glibc provided but no -target parameter\n"); return print_error_usage(arg0); } + if (baseline_cpu) { + target.is_native = false; + } } else { if ((err = target_parse_triple(&target, target_string))) { if (err == ErrorUnknownArchitecture && target.arch != ZigLLVM_UnknownArch) {