From 1c7f21852f0969855af7a2a752715ca0f537a8ea Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 9 Jul 2019 23:34:16 -0400 Subject: ship with mingw-w64 v6.0.0 See #514 --- src/target.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/target.cpp') diff --git a/src/target.cpp b/src/target.cpp index 5cbf8c4de1..eb6f33a8fe 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -1504,18 +1504,28 @@ struct AvailableLibC { static const AvailableLibC libcs_available[] = { {ZigLLVM_aarch64_be, OsLinux, ZigLLVM_GNU}, {ZigLLVM_aarch64_be, OsLinux, ZigLLVM_Musl}, + {ZigLLVM_aarch64_be, OsWindows, ZigLLVM_GNU}, + {ZigLLVM_aarch64_be, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_aarch64, OsLinux, ZigLLVM_GNU}, {ZigLLVM_aarch64, OsLinux, ZigLLVM_MuslEABI}, + {ZigLLVM_aarch64, OsWindows, ZigLLVM_GNU}, + {ZigLLVM_aarch64, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_armeb, OsLinux, ZigLLVM_GNUEABI}, {ZigLLVM_armeb, OsLinux, ZigLLVM_GNUEABIHF}, {ZigLLVM_armeb, OsLinux, ZigLLVM_MuslEABI}, {ZigLLVM_armeb, OsLinux, ZigLLVM_MuslEABIHF}, + {ZigLLVM_armeb, OsWindows, ZigLLVM_GNU}, + {ZigLLVM_armeb, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_arm, OsLinux, ZigLLVM_GNUEABI}, {ZigLLVM_arm, OsLinux, ZigLLVM_GNUEABIHF}, {ZigLLVM_arm, OsLinux, ZigLLVM_MuslEABI}, {ZigLLVM_arm, OsLinux, ZigLLVM_MuslEABIHF}, + {ZigLLVM_arm, OsWindows, ZigLLVM_GNU}, + {ZigLLVM_arm, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_x86, OsLinux, ZigLLVM_GNU}, {ZigLLVM_x86, OsLinux, ZigLLVM_Musl}, + {ZigLLVM_x86, OsWindows, ZigLLVM_MSVC}, + {ZigLLVM_x86, OsWindows, ZigLLVM_GNU}, {ZigLLVM_mips64el, OsLinux, ZigLLVM_GNUABI64}, {ZigLLVM_mips64el, OsLinux, ZigLLVM_GNUABIN32}, {ZigLLVM_mips64el, OsLinux, ZigLLVM_Musl}, @@ -1543,6 +1553,8 @@ static const AvailableLibC libcs_available[] = { {ZigLLVM_x86_64, OsLinux, ZigLLVM_GNU}, {ZigLLVM_x86_64, OsLinux, ZigLLVM_GNUX32}, {ZigLLVM_x86_64, OsLinux, ZigLLVM_Musl}, + {ZigLLVM_x86_64, OsWindows, ZigLLVM_MSVC}, + {ZigLLVM_x86_64, OsWindows, ZigLLVM_GNU}, }; bool target_can_build_libc(const ZigTarget *target) { @@ -1558,6 +1570,9 @@ bool target_can_build_libc(const ZigTarget *target) { } const char *target_libc_generic_name(const ZigTarget *target) { + if (target->os == OsWindows) { + return "mingw"; + } switch (target->abi) { case ZigLLVM_GNU: case ZigLLVM_GNUABIN32: -- cgit v1.2.3 From b4bbfe8c05760ee8ef94f7e23a8928e3cf8f6343 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 11 Jul 2019 12:56:51 -0400 Subject: the msvc target abi will have to be solved a different way --- src/target.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/target.cpp') diff --git a/src/target.cpp b/src/target.cpp index eb6f33a8fe..270bb057df 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -1459,8 +1459,8 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { case OsKFreeBSD: case OsNetBSD: case OsHurd: - return ZigLLVM_GNU; case OsWindows: + return ZigLLVM_GNU; case OsUefi: return ZigLLVM_MSVC; case OsLinux: @@ -1505,26 +1505,21 @@ static const AvailableLibC libcs_available[] = { {ZigLLVM_aarch64_be, OsLinux, ZigLLVM_GNU}, {ZigLLVM_aarch64_be, OsLinux, ZigLLVM_Musl}, {ZigLLVM_aarch64_be, OsWindows, ZigLLVM_GNU}, - {ZigLLVM_aarch64_be, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_aarch64, OsLinux, ZigLLVM_GNU}, {ZigLLVM_aarch64, OsLinux, ZigLLVM_MuslEABI}, {ZigLLVM_aarch64, OsWindows, ZigLLVM_GNU}, - {ZigLLVM_aarch64, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_armeb, OsLinux, ZigLLVM_GNUEABI}, {ZigLLVM_armeb, OsLinux, ZigLLVM_GNUEABIHF}, {ZigLLVM_armeb, OsLinux, ZigLLVM_MuslEABI}, {ZigLLVM_armeb, OsLinux, ZigLLVM_MuslEABIHF}, {ZigLLVM_armeb, OsWindows, ZigLLVM_GNU}, - {ZigLLVM_armeb, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_arm, OsLinux, ZigLLVM_GNUEABI}, {ZigLLVM_arm, OsLinux, ZigLLVM_GNUEABIHF}, {ZigLLVM_arm, OsLinux, ZigLLVM_MuslEABI}, {ZigLLVM_arm, OsLinux, ZigLLVM_MuslEABIHF}, {ZigLLVM_arm, OsWindows, ZigLLVM_GNU}, - {ZigLLVM_arm, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_x86, OsLinux, ZigLLVM_GNU}, {ZigLLVM_x86, OsLinux, ZigLLVM_Musl}, - {ZigLLVM_x86, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_x86, OsWindows, ZigLLVM_GNU}, {ZigLLVM_mips64el, OsLinux, ZigLLVM_GNUABI64}, {ZigLLVM_mips64el, OsLinux, ZigLLVM_GNUABIN32}, @@ -1553,7 +1548,6 @@ static const AvailableLibC libcs_available[] = { {ZigLLVM_x86_64, OsLinux, ZigLLVM_GNU}, {ZigLLVM_x86_64, OsLinux, ZigLLVM_GNUX32}, {ZigLLVM_x86_64, OsLinux, ZigLLVM_Musl}, - {ZigLLVM_x86_64, OsWindows, ZigLLVM_MSVC}, {ZigLLVM_x86_64, OsWindows, ZigLLVM_GNU}, }; -- cgit v1.2.3 From d9c4c96bf2755fba09cdf6c7f56b97b66b5255eb Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 11 Jul 2019 23:48:13 -0400 Subject: add -Wno-pragma-pack when targeting windows-gnu windows.h has files such as pshpack1.h which do #pragma packing, triggering a clang warning. So for this target, this warning is disabled. this commit also improves the error message printed when no libc can be used, printing the "zig triple" rather than the "llvm triple". --- src/all_types.hpp | 2 +- src/codegen.cpp | 24 +++++++++++++++--------- src/main.cpp | 2 +- src/target.cpp | 11 ++++++++++- src/target.hpp | 3 ++- 5 files changed, 29 insertions(+), 13 deletions(-) (limited to 'src/target.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index b49ed9820b..3cdaf36cd9 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1804,7 +1804,7 @@ struct CodeGen { ZigType *err_tag_type; ZigType *test_fn_type; - Buf triple_str; + Buf llvm_triple_str; Buf global_asm; Buf output_file_path; Buf o_file_output_path; diff --git a/src/codegen.cpp b/src/codegen.cpp index f9933aaf28..891e8ace92 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -199,7 +199,7 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget g->link_libs_list.append(g->libc_link_lib); } - get_target_triple(&g->triple_str, g->zig_target); + target_triple_llvm(&g->llvm_triple_str, g->zig_target); g->pointer_size_bytes = target_arch_pointer_bit_width(g->zig_target->arch) / 8; if (!target_has_debug_info(g->zig_target)) { @@ -8103,7 +8103,7 @@ static void init(CodeGen *g) { assert(g->root_out_name); g->module = LLVMModuleCreateWithName(buf_ptr(g->root_out_name)); - LLVMSetTarget(g->module, buf_ptr(&g->triple_str)); + LLVMSetTarget(g->module, buf_ptr(&g->llvm_triple_str)); if (target_object_format(g->zig_target) == ZigLLVM_COFF) { ZigLLVMAddModuleCodeViewFlag(g->module); @@ -8113,13 +8113,13 @@ static void init(CodeGen *g) { LLVMTargetRef target_ref; char *err_msg = nullptr; - if (LLVMGetTargetFromTriple(buf_ptr(&g->triple_str), &target_ref, &err_msg)) { + if (LLVMGetTargetFromTriple(buf_ptr(&g->llvm_triple_str), &target_ref, &err_msg)) { fprintf(stderr, "Zig is expecting LLVM to understand this target: '%s'\n" "However LLVM responded with: \"%s\"\n" "Zig is unable to continue. This is a bug in Zig:\n" "https://github.com/ziglang/zig/issues/438\n" - , buf_ptr(&g->triple_str), err_msg); + , buf_ptr(&g->llvm_triple_str), err_msg); exit(1); } @@ -8153,7 +8153,7 @@ static void init(CodeGen *g) { target_specific_features = ""; } - g->target_machine = ZigLLVMCreateTargetMachine(target_ref, buf_ptr(&g->triple_str), + g->target_machine = ZigLLVMCreateTargetMachine(target_ref, buf_ptr(&g->llvm_triple_str), target_specific_cpu_args, target_specific_features, opt_level, reloc_mode, LLVMCodeModelDefault, g->function_sections); @@ -8333,12 +8333,12 @@ static void detect_libc(CodeGen *g) { !target_os_is_darwin(g->zig_target->os)) { Buf triple_buf = BUF_INIT; - get_target_triple(&triple_buf, g->zig_target); + target_triple_zig(&triple_buf, g->zig_target); fprintf(stderr, "Zig is unable to provide a libc for the chosen target '%s'.\n" "The target is non-native, so Zig also cannot use the native libc installation.\n" - "Choose a target which has a libc available, or provide a libc installation text file.\n" - "See `zig libc --help` for more details.\n", buf_ptr(&triple_buf)); + "Choose a target which has a libc available (see `zig targets`), or\n" + "provide a libc installation text file (see `zig libc --help`).\n", buf_ptr(&triple_buf)); exit(1); } } @@ -8397,12 +8397,18 @@ void add_cc_args(CodeGen *g, ZigList &args, const char *out_dep_pa args.append("-march=native"); } else { args.append("-target"); - args.append(buf_ptr(&g->triple_str)); + args.append(buf_ptr(&g->llvm_triple_str)); } if (g->zig_target->os == OsFreestanding) { args.append("-ffreestanding"); } + // windows.h has files such as pshpack1.h which do #pragma packing, triggering a clang warning. + // So for this target, we disable this warning. + if (g->zig_target->os == OsWindows && target_abi_is_gnu(g->zig_target->abi)) { + args.append("-Wno-pragma-pack"); + } + if (!g->strip_debug_symbols) { args.append("-g"); } diff --git a/src/main.cpp b/src/main.cpp index 9329229a7b..f132dce176 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -982,7 +982,7 @@ int main(int argc, char **argv) { if (target_requires_pic(&target, have_libc) && want_pic == WantPICDisabled) { Buf triple_buf = BUF_INIT; - get_target_triple(&triple_buf, &target); + target_triple_zig(&triple_buf, &target); fprintf(stderr, "`--disable-pic` is incompatible with target '%s'\n", buf_ptr(&triple_buf)); return print_error_usage(arg0); } diff --git a/src/target.cpp b/src/target.cpp index 270bb057df..a0f842a5ac 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -753,7 +753,16 @@ void init_all_targets(void) { LLVMInitializeAllAsmParsers(); } -void get_target_triple(Buf *triple, const ZigTarget *target) { +void target_triple_zig(Buf *triple, const ZigTarget *target) { + buf_resize(triple, 0); + buf_appendf(triple, "%s%s-%s-%s", + ZigLLVMGetArchTypeName(target->arch), + ZigLLVMGetSubArchTypeName(target->sub_arch), + ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)), + ZigLLVMGetEnvironmentTypeName(target->abi)); +} + +void target_triple_llvm(Buf *triple, const ZigTarget *target) { buf_resize(triple, 0); buf_appendf(triple, "%s%s-%s-%s-%s", ZigLLVMGetArchTypeName(target->arch), diff --git a/src/target.hpp b/src/target.hpp index 99e38f1c62..e7e102a8ce 100644 --- a/src/target.hpp +++ b/src/target.hpp @@ -148,7 +148,8 @@ const char *target_oformat_name(ZigLLVM_ObjectFormatType oformat); ZigLLVM_ObjectFormatType target_object_format(const ZigTarget *target); void get_native_target(ZigTarget *target); -void get_target_triple(Buf *triple, const ZigTarget *target); +void target_triple_llvm(Buf *triple, const ZigTarget *target); +void target_triple_zig(Buf *triple, const ZigTarget *target); void init_all_targets(void); -- cgit v1.2.3 From 7b8ba871a9d14a26972caabc37aee1fb1f15006e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 12 Jul 2019 14:44:34 -0400 Subject: mingw libc: solve the segfault having to do with destructors * fixed --verbose-cc printing an extra "zig" before the rest of the command line * windows-gnu targets use libfoo.a, foo.o extensions to match mingw conventions. --- libc/mingw/include/config.h | 2 +- src/codegen.cpp | 10 +++++----- src/link.cpp | 20 +++++++++++--------- src/target.cpp | 15 ++++++++++++--- 4 files changed, 29 insertions(+), 18 deletions(-) (limited to 'src/target.cpp') diff --git a/libc/mingw/include/config.h b/libc/mingw/include/config.h index 45931b832a..2c96636426 100644 --- a/libc/mingw/include/config.h +++ b/libc/mingw/include/config.h @@ -2,7 +2,7 @@ /* config.h.in. Generated from configure.ac by autoheader. */ /* Whether the linker provides __CTOR_LIST__ */ -/* #undef HAVE_CTOR_LIST */ +#define HAVE_CTOR_LIST 1 /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 diff --git a/src/codegen.cpp b/src/codegen.cpp index 891e8ace92..94e2a98b2f 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8741,10 +8741,10 @@ static void gen_root_source(CodeGen *g) { } -static void print_zig_cc_cmd(const char *zig_exe, ZigList *args) { - fprintf(stderr, "%s", zig_exe); +static void print_zig_cc_cmd(ZigList *args) { for (size_t arg_i = 0; arg_i < args->length; arg_i += 1) { - fprintf(stderr, " %s", args->at(arg_i)); + const char *space_str = (arg_i == 0) ? "" : " "; + fprintf(stderr, "%s%s", space_str, args->at(arg_i)); } fprintf(stderr, "\n"); } @@ -8882,12 +8882,12 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { } if (g->verbose_cc) { - print_zig_cc_cmd("zig", &args); + print_zig_cc_cmd(&args); } os_spawn_process(args, &term); if (term.how != TerminationIdClean || term.code != 0) { fprintf(stderr, "\nThe following command failed:\n"); - print_zig_cc_cmd(buf_ptr(self_exe_path), &args); + print_zig_cc_cmd(&args); exit(1); } diff --git a/src/link.cpp b/src/link.cpp index 8cc6f629fc..bfceef74ea 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -646,6 +646,8 @@ static const char *build_libunwind(CodeGen *parent) { } static void mingw_add_cc_args(CodeGen *parent, CFile *c_file) { + c_file->args.append("-DHAVE_CONFIG_H"); + c_file->args.append("-I"); c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "include", buf_ptr(parent->zig_lib_dir)))); @@ -1158,7 +1160,7 @@ static void add_mingwex_os_dep(CodeGen *parent, CodeGen *child_gen, const char * static const char *get_libc_crt_file(CodeGen *parent, const char *file) { if (parent->libc == nullptr && parent->zig_target->os == OsWindows) { - if (strcmp(file, "crt2.obj") == 0) { + if (strcmp(file, "crt2.o") == 0) { CFile *c_file = allocate(1); c_file->source_path = buf_ptr(buf_sprintf( "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtexe.c", buf_ptr(parent->zig_lib_dir))); @@ -1170,7 +1172,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) { //c_file->args.append("-D_UNICODE"); //c_file->args.append("-DWPRFLAG=1"); return build_libc_object(parent, "crt2", c_file); - } else if (strcmp(file, "dllcrt2.obj") == 0) { + } else if (strcmp(file, "dllcrt2.o") == 0) { CFile *c_file = allocate(1); c_file->source_path = buf_ptr(buf_sprintf( "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtdll.c", buf_ptr(parent->zig_lib_dir))); @@ -1916,10 +1918,10 @@ static const char *get_libc_static_file(ZigLibCInstallation *lib, const char *fi return buf_ptr(out_buf); } -static void print_zig_cc_cmd(const char *zig_exe, ZigList *args) { - fprintf(stderr, "%s", zig_exe); +static void print_zig_cc_cmd(ZigList *args) { for (size_t arg_i = 0; arg_i < args->length; arg_i += 1) { - fprintf(stderr, " %s", args->at(arg_i)); + const char *space_str = (arg_i == 0) ? "" : " "; + fprintf(stderr, "%s%s", space_str, args->at(arg_i)); } fprintf(stderr, "\n"); } @@ -2017,13 +2019,13 @@ static const char *get_def_lib(CodeGen *parent, const char *name, const char *de args.append(buf_ptr(def_final_path)); if (parent->verbose_cc) { - print_zig_cc_cmd("zig", &args); + print_zig_cc_cmd(&args); } Termination term; os_spawn_process(args, &term); if (term.how != TerminationIdClean || term.code != 0) { fprintf(stderr, "\nThe following command failed:\n"); - print_zig_cc_cmd(buf_ptr(self_exe_path), &args); + print_zig_cc_cmd(&args); exit(1); } @@ -2070,9 +2072,9 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) { if (g->libc == nullptr) { if (is_dll) { - lj->args.append(get_libc_crt_file(g, "dllcrt2.obj")); + lj->args.append(get_libc_crt_file(g, "dllcrt2.o")); } else { - lj->args.append(get_libc_crt_file(g, "crt2.obj")); + lj->args.append(get_libc_crt_file(g, "crt2.o")); } lj->args.append(get_libc_crt_file(g, "mingw32.lib")); diff --git a/src/target.cpp b/src/target.cpp index a0f842a5ac..56c9a72c8f 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -993,7 +993,9 @@ bool target_allows_addr_zero(const ZigTarget *target) { } const char *target_o_file_ext(const ZigTarget *target) { - if (target->abi == ZigLLVM_MSVC || target->os == OsWindows || target->os == OsUefi) { + if (target->abi == ZigLLVM_MSVC || + (target->os == OsWindows && !target_abi_is_gnu(target->abi)) || + target->os == OsUefi) { return ".obj"; } else { return ".o"; @@ -1021,7 +1023,10 @@ const char *target_exe_file_ext(const ZigTarget *target) { } const char *target_lib_file_prefix(const ZigTarget *target) { - if (target->os == OsWindows || target->os == OsUefi || target_is_wasm(target)) { + if ((target->os == OsWindows && !target_abi_is_gnu(target->abi)) || + target->os == OsUefi || + target_is_wasm(target)) + { return ""; } else { return "lib"; @@ -1036,7 +1041,11 @@ const char *target_lib_file_ext(const ZigTarget *target, bool is_static, } if (target->os == OsWindows || target->os == OsUefi) { if (is_static) { - return ".lib"; + if (target->os == OsWindows && target_abi_is_gnu(target->abi)) { + return ".a"; + } else { + return ".lib"; + } } else { return ".dll"; } -- cgit v1.2.3