From 5593c63e12a8d85052f548218b2957dea314be18 Mon Sep 17 00:00:00 2001 From: emekoi Date: Fri, 26 Jul 2019 16:26:01 -0500 Subject: [PATCH 1/3] improved CMake file for MinGW --- CMakeLists.txt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d8cf0c507d..debfb9392c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -209,7 +209,7 @@ else() else() set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Wno-comment") if(MINGW) - set(ZIG_LLD_COMPILE_FLAGS "${ZIG_LLD_COMPILE_FLAGS} -D__STDC_FORMAT_MACROS -D__USE_MINGW_ANSI_STDIO -Wno-pedantic-ms-format") + set(ZIG_LLD_COMPILE_FLAGS "${ZIG_LLD_COMPILE_FLAGS} -D__STDC_FORMAT_MACROS -D__USE_MINGW_ANSI_STDIO") endif() endif() set_target_properties(embedded_lld_lib PROPERTIES @@ -511,19 +511,23 @@ set(OPTIMIZED_C_FLAGS "-std=c99 -O3") set(EXE_LDFLAGS " ") if(MSVC) - set(EXE_LDFLAGS "/STACK:16777216") + set(EXE_LDFLAGS "${EXE_LDFLAGS} /STACK:16777216") elseif(MINGW) set(EXE_LDFLAGS "${EXE_LDFLAGS} -Wl,--stack,16777216") endif() if(ZIG_STATIC) if(APPLE) - set(EXE_LDFLAGS "-static-libgcc -static-libstdc++") + set(EXE_LDFLAGS "${EXE_LDFLAGS} -static-libgcc -static-libstdc++") elseif(MINGW) - set(EXE_LDFLAGS "-static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -lz3 -lz -lgomp -Wl,--no-whole-archive") + set(EXE_LDFLAGS "${EXE_LDFLAGS} -static-libgcc -static-libstdc++ -Wl,-Bstatic, -lwinpthread -lz3 -lz -lgomp") else() - set(EXE_LDFLAGS "-static") + set(EXE_LDFLAGS "${EXE_LDFLAGS} -static") endif() +else() + if(MINGW) + set(EXE_LDFLAGS "${EXE_LDFLAGS} -lz3") + endif() endif() if(ZIG_TEST_COVERAGE) @@ -559,11 +563,6 @@ if(NOT MSVC) target_link_libraries(compiler LINK_PUBLIC ${LIBXML2}) endif() -if(MINGW) - find_library(Z3_LIBRARIES NAMES z3 z3.dll) - target_link_libraries(compiler LINK_PUBLIC ${Z3_LIBRARIES}) -endif() - if(ZIG_DIA_GUIDS_LIB) target_link_libraries(compiler LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB}) endif() From 10b10177025790ffa84304f282e8323ea2b10c37 Mon Sep 17 00:00:00 2001 From: emekoi Date: Sat, 27 Jul 2019 17:50:44 -0500 Subject: [PATCH 2/3] fixed backtraces when linking libc on mingw --- std/coff.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/std/coff.zig b/std/coff.zig index 9fdc368878..7c53f48f66 100644 --- a/std/coff.zig +++ b/std/coff.zig @@ -120,7 +120,15 @@ pub const Coff = struct { pub fn getPdbPath(self: *Coff, buffer: []u8) !usize { try self.loadSections(); - const header = (self.getSection(".rdata") orelse return error.MissingCoffSection).header; + const header = blk: { + if (self.getSection(".buildid")) |section| { + break :blk section.header; + } else if (self.getSection(".rdata")) |section| { + break :blk section.header; + } else { + return error.MissingCoffSection; + } + }; // The linker puts a chunk that contains the .pdb path right after the // debug_directory. From 357fb4f1436fca4b68ca5adf14ba85f3b21b5dcf Mon Sep 17 00:00:00 2001 From: emekoi Date: Sat, 27 Jul 2019 17:54:20 -0500 Subject: [PATCH 3/3] avoid passing -static to msvc when static linking --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index debfb9392c..998da172fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -521,7 +521,7 @@ if(ZIG_STATIC) set(EXE_LDFLAGS "${EXE_LDFLAGS} -static-libgcc -static-libstdc++") elseif(MINGW) set(EXE_LDFLAGS "${EXE_LDFLAGS} -static-libgcc -static-libstdc++ -Wl,-Bstatic, -lwinpthread -lz3 -lz -lgomp") - else() + elseif(NOT MSVC) set(EXE_LDFLAGS "${EXE_LDFLAGS} -static") endif() else()