ianlancetaylor / libbacktrace

A C library that may be linked into a C/C++ program to produce symbolic backtraces
Other
944 stars 220 forks source link

No backtrace with Mingw64 and clang++ #103

Closed ArnaudValensi closed 1 month ago

ArnaudValensi commented 1 year ago

When compiling with clang++ with mingw64, I don't have the right backtrace:

*** Segmentation Fault ***

0x561e4a67 ???
        ???:0
0x561edbc1 ???
        ???:0
0x9cf07ff7 ???
        ???:0
0x9e93241e ???
        ???:0
0x9e8e14a3 ???
        ???:0
0x9e930f4d ???
        ???:0
0x561e4a81 ???
        ???:0

However, it works with g++, but only with the -no-pie option, so I suspect that libbacktrace doesn't handle ASLR in this case. Unfortunately clang seems to enable pie by default with no way to disable it.

I have the following with g++ and -no-pie:

*** Segmentation Fault ***

0x4000498a _Z15sigsegv_handleri
        src/test.cpp:58
0x4000da41 _gnu_exception_handler
        C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt_handler.c:213
0x9cf07ff7 ???
        ???:0
0x9e93241e ???
        ???:0
0x9e8e14a3 ???
        ???:0
0x9e930f4d ???
        ???:0
0x400049ad _Z12function_twov
        src/test.cpp:64
0x400049c4 _Z12function_onev
        src/test.cpp:68
0x40004a83 main
        src/test.cpp:87
0x400012ed __tmainCRTStartup
        C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:272
0x40001405 mainCRTStartup
        C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:193
0x9dc87613 ???
        ???:0
0x9e8e26a0 ???
        ???:0
0xffffffff ???
        ???:0

Is it normal that the symbols are not demangled?

Here my versions:

$ clang++.exe --version
clang version 15.0.5
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/msys64/mingw64/bin
$ g++.exe --version
g++.exe (Rev7, Built by MSYS2 project) 12.2.0
ianlancetaylor commented 1 year ago

I don't know how to implement this on Windows. Happy to look at a patch, though.

ArnaudValensi commented 1 year ago

Is symbol resolution with ASLR already implemented for some platforms?

ianlancetaylor commented 1 year ago

Yes, on ELF. It's the base_address values passed to backtrace_dwarf_add.

ianlancetaylor commented 1 month ago

Windows ASLR support has been committed, so this should work now.