Re: How to use AddressSanitizer with Wine?
Bernhard Übelacker <[email protected]> Sun, 27 Apr 2025 00:36:01 +0200
| Newsgroups | gmane.comp.emulators.wine.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello Alex, Am 26.04.25 um 23:18 schrieb Alex Henrie: > Dear oenologists, > > I would like to use GCC's AddressSanitizer [1] to investigate a memory > corruption bug in Wine. There must be a way to do it because I see > multiple references to "ASan" in the Wine commit log in commits from > this year.[2] I found some instructions on the WineHQ wiki,[3] but I > get a myriad of linker errors when I try to follow them. > > What Linux distributions can successfully compile Wine with libasan? > Are there special steps not mentioned in the wiki? Does > AddressSanitizer work with MinGW, or only with non-PE builds? > > I'd love to get AddressSanitizer working myself, but even if I can't, > thanks to Bernhard and Nikolay for using it to fix a lot of bugs > already. > > -Alex > > [1] https://github.com/google/sanitizers/wiki/AddressSanitizer > [2] https://gitlab.winehq.org/wine/wine/-/commits/master?search=ASan > [3] https://gitlab.winehq.org/wine/wine/-/wikis/Building-Wine#memory--address-checkers Thanks for asking, I fear I should have provide this information long time ago. I fear GCC is not able to achieve this on PE side currently. The wiki references may be just for the Unix side of things. A few months ago I felt brave and tried to get some changes into llvm-project about function interception, and that went better than I had hoped. So I found Martin Storsjö's llvm-mingw, and building wine with it works well. As a side project I tried to build wine with ASan(PE-side) enabled, and this worked (with currently plenty of hacks) also quite well. For enabling ASan(PE) I collected some "notes to myself", which I hope are enough accurate to enable someone else to reproduce the results. Currently I try to push my current state for each wine release, like in [7]. In [8][9] is the output when running the conformance test suite from such an ASan(PE) enabled tree. Thanks to Nikolay some of the issues could be fixed immediately. Unfortunately I have one patch with LLVM still in progress, therefore a self-built LLVM would be needed, to build wine. But this is just needed for HEAP_REALLOC_IN_PLACE_ONLY re-allocations, and running with "windows_hook_rtl_allocators=0" should not be affected by this, and that way building wine from the plain nightly llvm-mingw package should work. This notes might be better placed in the wiki, but I currently don't know how is the best way to enter it there. Please let me know any issues or uncertainties in my description. Kind regards, Bernhard [4] https://bugs.winehq.org/show_bug.cgi?id=50993 [5] https://bugs.winehq.org/show_bug.cgi?id=52386 [6] https://gitlab.winehq.org/bernhardu/wine/-/blob/asan-pe_2025-04-05_wine-10.6/README-ASan.md?ref_type=heads [7] https://gitlab.winehq.org/bernhardu/wine/-/tree/asan-pe_2025-04-05_wine-10.6?ref_type=heads [8] https://gitlab.winehq.org/bernhardu/wine/-/tree/asan-pe_2025-04-05_wine-10.6/asan_reports_x86_64?ref_type=heads [9] https://gitlab.winehq.org/bernhardu/wine/-/tree/asan-pe_2025-04-05_wine-10.6/asan_reports_x86?ref_type=heads