LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 35365 - ASAN on Windows dies on exception re-throw
Summary: ASAN on Windows dies on exception re-throw
Status: NEW
Alias: None
Product: compiler-rt
Classification: Unclassified
Component: asan (show other bugs)
Version: 5.0
Hardware: PC Windows XP
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-20 07:52 PST by Steinar H. Gunderson
Modified: 2018-06-11 18:23 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steinar H. Gunderson 2017-11-20 07:52:33 PST
Hi,

ASAN on Clang 5.0.0 on Windows seems not to handle exception rethrow properly; it dies with a NULL pointer exception. A simple example (that uses a separate helper function to do the rethrow, but it dies even without it, although in a different and less helpful way):

#include <iostream>
#include <stdexcept>

void func()
{
        throw std::runtime_error("hello, world");
}

void handle_rethrow()
{
        try {
                throw;
        } catch (std::exception &e) {
                std::cout << e.what() << std::endl;
        }
}

int main(void)
{
        try {
                func();
        } catch (...) {
                handle_rethrow();
        }
}

C:\Users\sgunders\source>cl /c /EHsc -fsanitize=address test.cpp

C:\Users\sgunders\source>"c:\Program Files\LLVM\bin\lld-link.exe" /out:test.exe test.obj "c:\Program Files\LLVM\lib\clang\5.0.0\lib\windows\clang_rt.asan_cxx-x86_64.lib" "c:\Program Files\LLVM\lib\clang\5.0.0\lib\windows\clang_rt.asan-x86_64.lib"

C:\Users\sgunders\source>.\test.exe
=================================================================
==33004==ERROR: AddressSanitizer: access-violation on unknown address 0x000000000000 (pc 0x7ff7413fb2d4 bp 0x002c886fd390 sp 0x002c886fad00 T0)
==33004==The signal is caused by a READ memory access.
==33004==Hint: address points to the zero page.
    #0 0x7ff7413fb2d3 in _asan_test_only_reported_buggy_pointer+0xc982a3 (C:\Users\sgunders\source\test.exe+0x140cbb2d3)
    #1 0x7ff74145258f in _asan_after_dynamic_init+0x243bf (C:\Users\sgunders\source\test.exe+0x140d1258f)
    #2 0x7ff741448327 in _asan_after_dynamic_init+0x1a157 (C:\Users\sgunders\source\test.exe+0x140d08327)
    #3 0x7ffe6600a162 in RtlCaptureContext+0x3c2 (C:\Windows\SYSTEM32\ntdll.dll+0x1800aa162)
    #4 0x7ff7413fb20a in _asan_test_only_reported_buggy_pointer+0xc981da (C:\Users\sgunders\source\test.exe+0x140cbb20a)
    #5 0x7ff7413fb3a2 in _asan_test_only_reported_buggy_pointer+0xc98372 (C:\Users\sgunders\source\test.exe+0x140cbb3a2)
    #6 0x7ff74145258f in _asan_after_dynamic_init+0x243bf (C:\Users\sgunders\source\test.exe+0x140d1258f)
    #7 0x7ff741448327 in _asan_after_dynamic_init+0x1a157 (C:\Users\sgunders\source\test.exe+0x140d08327)
    #8 0x7ffe6600a162 in RtlCaptureContext+0x3c2 (C:\Windows\SYSTEM32\ntdll.dll+0x1800aa162)
    #9 0x7ff7413fb36d in _asan_test_only_reported_buggy_pointer+0xc9833d (C:\Users\sgunders\source\test.exe+0x140cbb36d)
    #10 0x7ff74143c6c4 in _asan_after_dynamic_init+0xe4f4 (C:\Users\sgunders\source\test.exe+0x140cfc6c4)
    #11 0x7ffe636f8363 in BaseThreadInitThunk+0x13 (C:\Windows\System32\KERNEL32.DLL+0x180008363)
    #12 0x7ffe65fc7090 in RtlUserThreadStart+0x20 (C:\Windows\SYSTEM32\ntdll.dll+0x180067090)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: access-violation (C:\Users\sgunders\source\test.exe+0x140cbb2d3) in _asan_test_only_reported_buggy_pointer+0xc982a3
==33004==ABORTING

The same code works without fault with ASAN on Linux, and without ASAN on Windows.
Comment 1 Reid Kleckner 2017-11-20 13:10:32 PST
I was able to reproduce this, but I think this is just the beginning of the very large task of retrofitting ASan to support Windows EH.
Comment 2 Steinar H. Gunderson 2017-11-20 13:13:02 PST
It seems normal EH works fine, just not re-throw. Our code doesn't use exceptions a lot, though, so there might very well be lots of problems I've missed.