Bug 148623

Summary: Implement bmalloc::isASanEnabled for generic Unix
Product: WebKit Reporter: Michael Catanzaro <mcatanzaro>
Component: Web Template FrameworkAssignee: Michael Catanzaro <mcatanzaro>
Status: RESOLVED FIXED    
Severity: Enhancement CC: ap, ggaren, mcatanzaro
Priority: P2    
Version: Other   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch
none
Patch ggaren: review+

Description Michael Catanzaro 2015-08-30 16:30:09 PDT
If you only care about Clang (not sure), bmalloc::isASanEnabled could be as simple as:

static bool isASanEnabled()
{
#if defined(__has_feature) && __has_feature(address_sanitizer)
    return true;
#else
    return false;
#endif
}

Unless there is some reason I don't understand for the runtime check.

GCC supports asan but not __has_feature. This runtime check works:

    void *handle = dlopen(nullptr, RTLD_NOW);
    if (!handle)
        return false;
    bool result = !!dlsym(handle, "__asan_poison_memory_region");
    dlclose(handle);
    return result;

I expect that would work fine on Darwin too.
Comment 1 Michael Catanzaro 2015-08-30 16:34:34 PDT
Created attachment 260254 [details]
Patch
Comment 2 Michael Catanzaro 2015-08-30 16:43:54 PDT
Created attachment 260255 [details]
Patch
Comment 3 Alexey Proskuryakov 2015-08-30 17:43:05 PDT
The runtime check is needed because we need to disable bmalloc whenever ASan is enabled in the process - even if bmalloc itself is compiled without ASan.
Comment 4 Michael Catanzaro 2015-08-31 09:28:56 PDT
OK, that makes sense.
Comment 5 Michael Catanzaro 2015-08-31 09:31:30 PDT
Created attachment 260289 [details]
Patch
Comment 6 Geoffrey Garen 2015-08-31 13:16:47 PDT
Comment on attachment 260289 [details]
Patch

r=me
Comment 7 Michael Catanzaro 2015-08-31 13:41:41 PDT
Committed r189181: <http://trac.webkit.org/changeset/189181>