[compiler-rt] r230344 - [ASan/Win] Add support for sanitizer allocator hooks, __asan_default_options and __asan_on_error

Dmitry Vyukov dvyukov at google.com
Wed Feb 25 02:50:44 PST 2015


On Tue, Feb 24, 2015 at 10:21 PM, Alexey Samsonov <vonosmas at gmail.com> wrote:
>
> On Tue, Feb 24, 2015 at 9:07 AM, Timur Iskhodzhanov <timurrrr at google.com>
> wrote:
>>
>> Author: timurrrr
>> Date: Tue Feb 24 11:07:22 2015
>> New Revision: 230344
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=230344&view=rev
>> Log:
>> [ASan/Win] Add support for sanitizer allocator hooks,
>> __asan_default_options and __asan_on_error
>>
>> Added:
>>     compiler-rt/trunk/test/asan/TestCases/Windows/default_options.cc
>>     compiler-rt/trunk/test/asan/TestCases/Windows/free_hook_realloc.cc
>>     compiler-rt/trunk/test/asan/TestCases/Windows/on_error_callback.cc
>> Modified:
>>     compiler-rt/trunk/lib/asan/asan_win.cc
>>     compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
>>     compiler-rt/trunk/test/asan/TestCases/default_options.cc
>>     compiler-rt/trunk/test/asan/TestCases/free_hook_realloc.cc
>>     compiler-rt/trunk/test/asan/TestCases/on_error_callback.cc
>>
>> Modified: compiler-rt/trunk/lib/asan/asan_win.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=230344&r1=230343&r2=230344&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/asan/asan_win.cc (original)
>> +++ compiler-rt/trunk/lib/asan/asan_win.cc Tue Feb 24 11:07:22 2015
>> @@ -27,13 +27,26 @@
>>  #include "sanitizer_common/sanitizer_mutex.h"
>>
>>  extern "C" {
>> -  SANITIZER_INTERFACE_ATTRIBUTE
>> -  int __asan_should_detect_stack_use_after_return() {
>> -    __asan_init();
>> -    return __asan_option_detect_stack_use_after_return;
>> -  }
>> +SANITIZER_INTERFACE_ATTRIBUTE
>> +int __asan_should_detect_stack_use_after_return() {
>> +  __asan_init();
>> +  return __asan_option_detect_stack_use_after_return;
>>  }
>>
>> +// We don't have a direct equivalent of weak symbols when using MSVC, but
>> we can
>> +// use the /alternatename directive to tell the linker to default a
>> specific
>> +// symbol to a specific value, which works nicely for allocator hooks and
>> +// __asan_default_options().
>> +void __sanitizer_default_malloc_hook(void *ptr, uptr size) { }
>> +void __sanitizer_default_free_hook(void *ptr) { }
>> +const char* __asan_default_default_options() { return ""; }
>> +void __asan_default_on_error() {}
>> +#pragma comment(linker,
>> "/alternatename:___sanitizer_malloc_hook=___sanitizer_default_malloc_hook")
>> // NOLINT
>> +#pragma comment(linker,
>> "/alternatename:___sanitizer_free_hook=___sanitizer_default_free_hook")
>> // NOLINT
>> +#pragma comment(linker,
>> "/alternatename:___asan_default_options=___asan_default_default_options")
>> // NOLINT
>> +#pragma comment(linker,
>> "/alternatename:___asan_on_error=___asan_default_on_error")
>> // NOLINT
>> +}  // extern "C"
>> +
>>  namespace __asan {
>>
>>  // ---------------------- TSD ---------------- {{{1
>>
>> Modified: compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc?rev=230344&r1=230343&r2=230344&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc (original)
>> +++ compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc Tue Feb 24 11:07:22
>> 2015
>> @@ -304,7 +304,6 @@ INTERFACE_FUNCTION(__sanitizer_cov_modul
>>  INTERFACE_FUNCTION(__sanitizer_cov_trace_basic_block)
>>  INTERFACE_FUNCTION(__sanitizer_cov_trace_func_enter)
>>  INTERFACE_FUNCTION(__sanitizer_cov_with_check)
>> -INTERFACE_FUNCTION(__sanitizer_free_hook)
>>  INTERFACE_FUNCTION(__sanitizer_get_allocated_size)
>>  INTERFACE_FUNCTION(__sanitizer_get_coverage_guards)
>>  INTERFACE_FUNCTION(__sanitizer_get_current_allocated_bytes)
>> @@ -314,7 +313,6 @@ INTERFACE_FUNCTION(__sanitizer_get_heap_
>>  INTERFACE_FUNCTION(__sanitizer_get_ownership)
>>  INTERFACE_FUNCTION(__sanitizer_get_total_unique_coverage)
>>  INTERFACE_FUNCTION(__sanitizer_get_unmapped_bytes)
>> -INTERFACE_FUNCTION(__sanitizer_malloc_hook)
>>  INTERFACE_FUNCTION(__sanitizer_maybe_open_cov_file)
>>  INTERFACE_FUNCTION(__sanitizer_print_stack_trace)
>>  INTERFACE_FUNCTION(__sanitizer_ptr_cmp)
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=230344&r1=230343&r2=230344&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
>> (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Tue
>> Feb 24 11:07:22 2015
>> @@ -32,7 +32,7 @@
>>  # define SANITIZER_WEAK_ATTRIBUTE  __attribute__((weak))
>>  #endif
>>
>> -#if SANITIZER_LINUX && !defined(SANITIZER_GO)
>> +#if (SANITIZER_LINUX && !defined(SANITIZER_GO)) || SANITIZER_WINDOWS
>
>
> +Dmitry
>
> This doesn't look right to me. Shouldn't it be
> #if (SANITIZER_LINUX || SANITIZER_WINDOWS) && !defined(SANITIZER_GO)
> ?

Yes, tsan on windows does not support weak hooks.
Timur, please change it to what Alexey says.
Alexey, thanks for noticing this.



More information about the llvm-commits mailing list