Skip to content

Commit d694f29

Browse files
authored
Merge pull request #2958 from emekoi/mingw-cmake
fix backtraces on mingw
2 parents c47b753 + 357fb4f commit d694f29

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

CMakeLists.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ else()
209209
else()
210210
set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Wno-comment")
211211
if(MINGW)
212-
set(ZIG_LLD_COMPILE_FLAGS "${ZIG_LLD_COMPILE_FLAGS} -D__STDC_FORMAT_MACROS -D__USE_MINGW_ANSI_STDIO -Wno-pedantic-ms-format")
212+
set(ZIG_LLD_COMPILE_FLAGS "${ZIG_LLD_COMPILE_FLAGS} -D__STDC_FORMAT_MACROS -D__USE_MINGW_ANSI_STDIO")
213213
endif()
214214
endif()
215215
set_target_properties(embedded_lld_lib PROPERTIES
@@ -511,19 +511,23 @@ set(OPTIMIZED_C_FLAGS "-std=c99 -O3")
511511

512512
set(EXE_LDFLAGS " ")
513513
if(MSVC)
514-
set(EXE_LDFLAGS "/STACK:16777216")
514+
set(EXE_LDFLAGS "${EXE_LDFLAGS} /STACK:16777216")
515515
elseif(MINGW)
516516
set(EXE_LDFLAGS "${EXE_LDFLAGS} -Wl,--stack,16777216")
517517
endif()
518518

519519
if(ZIG_STATIC)
520520
if(APPLE)
521-
set(EXE_LDFLAGS "-static-libgcc -static-libstdc++")
521+
set(EXE_LDFLAGS "${EXE_LDFLAGS} -static-libgcc -static-libstdc++")
522522
elseif(MINGW)
523-
set(EXE_LDFLAGS "-static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -lz3 -lz -lgomp -Wl,--no-whole-archive")
524-
else()
525-
set(EXE_LDFLAGS "-static")
523+
set(EXE_LDFLAGS "${EXE_LDFLAGS} -static-libgcc -static-libstdc++ -Wl,-Bstatic, -lwinpthread -lz3 -lz -lgomp")
524+
elseif(NOT MSVC)
525+
set(EXE_LDFLAGS "${EXE_LDFLAGS} -static")
526526
endif()
527+
else()
528+
if(MINGW)
529+
set(EXE_LDFLAGS "${EXE_LDFLAGS} -lz3")
530+
endif()
527531
endif()
528532

529533
if(ZIG_TEST_COVERAGE)
@@ -559,11 +563,6 @@ if(NOT MSVC)
559563
target_link_libraries(compiler LINK_PUBLIC ${LIBXML2})
560564
endif()
561565

562-
if(MINGW)
563-
find_library(Z3_LIBRARIES NAMES z3 z3.dll)
564-
target_link_libraries(compiler LINK_PUBLIC ${Z3_LIBRARIES})
565-
endif()
566-
567566
if(ZIG_DIA_GUIDS_LIB)
568567
target_link_libraries(compiler LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB})
569568
endif()

std/coff.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,15 @@ pub const Coff = struct {
120120

121121
pub fn getPdbPath(self: *Coff, buffer: []u8) !usize {
122122
try self.loadSections();
123-
const header = (self.getSection(".rdata") orelse return error.MissingCoffSection).header;
123+
const header = blk: {
124+
if (self.getSection(".buildid")) |section| {
125+
break :blk section.header;
126+
} else if (self.getSection(".rdata")) |section| {
127+
break :blk section.header;
128+
} else {
129+
return error.MissingCoffSection;
130+
}
131+
};
124132

125133
// The linker puts a chunk that contains the .pdb path right after the
126134
// debug_directory.

0 commit comments

Comments
 (0)