Bug 96948 - _Unwind_GetIP() and _Unwind_GetIPInfo() empty in _Unwind_Backtrace() with SEH on mingw64
Summary: _Unwind_GetIP() and _Unwind_GetIPInfo() empty in _Unwind_Backtrace() with SEH...
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcc (show other bugs)
Version: 8.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2020-09-07 03:33 UTC by Kirill Müller
Modified: 2020-11-06 22:45 UTC (History)
1 user (show)

See Also:
Target: x86_64-MinGW-W64
Known to work:
Known to fail:
Last reconfirmed:

Reproducible example (318 bytes, text/x-csrc)
2020-09-07 03:33 UTC, Kirill Müller
Proposed patch (708 bytes, patch)
2020-09-07 03:34 UTC, Kirill Müller
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kirill Müller 2020-09-07 03:33:58 UTC
Created attachment 49187 [details]
Reproducible example

The attached program, modeled after `btest.c` in libbacktrace, produces the following output in mingw64 (SEH):

0/0[0] (403180)
0/0[0] (4015da)
0/0[0] (4011a0)
0/0[0] (401510)
0/0[0] (7ffb6e4d7bc0)
0/0[0] (7ffb6e90ce30)

The first two numbers are _Unwind_GetIP() and _Unwind_GetIPInfo(). The last number is _Unwind_GetRegionStart(), which appears to be correct. Note how the first address is different from the next three -- this seems to be located in libgcc and should be stripped.

Applying https://github.com/gcc-mirror/gcc/pull/48 gives the following:

4015ff/4015ff[0] (4015da)
4013c5/4013c5[0] (4011a0)
40152b/40152b[0] (401510)
7ffb6e4d7bd4/7ffb6e4d7bd4[0] (7ffb6e4d7bc0)
7ffb6e90ce51/7ffb6e90ce51[0] (7ffb6e90ce30)

Raw patch attached.

Tested on Windows in gcc 8.3.0 in the rtools40 toolchain, a custom msys2 environment: https://cran.r-project.org/bin/windows/Rtools/. The mingw32 (SJLJ) version is not affected.
Comment 1 Kirill Müller 2020-09-07 03:34:34 UTC
Created attachment 49188 [details]
Proposed patch
Comment 2 Kirill Müller 2020-09-07 03:36:51 UTC
$ gcc -v
Using built-in specs.
Target: x86_64-w64-mingw32
Configured with: ../gcc-8.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran --disable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Built by Jeroen for the R-project' --with-bugurl=https://github.com/r-windows --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 8.3.0 (Built by Jeroen for the R-project)
Comment 3 Richard Biener 2020-09-07 05:53:28 UTC
Patches should be sent to gcc-patches@gcc.gnu.org
Comment 4 Kirill Müller 2020-09-07 06:13:47 UTC
Comment 5 Kirill Müller 2020-09-09 02:57:16 UTC
Solved by https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553418.html.
Comment 6 Jeffrey A. Law 2020-11-06 22:45:39 UTC
Should be fixed on trunk now.