llvm-project/compiler-rt/lib/ubsan
Marcos Pividori 2b9c44e226 [sanitizer] Use interception to access to strong definitions in the executable.
In Windows, when sanitizers are implemented as a shared library (DLL), users can
redefine and export a new definition for weak functions, in the main executable,
for example:

extern "C" __declspec(dllexport)
void __sanitizer_cov_trace_pc_guard(u32* guard) {
  // Different implementation provided by the client.
}

However, other dlls, will continue using the default implementation imported
from the sanitizer dll. This is different in linux, where all the shared
libraries will consider the strong definition.

With the implementation in this diff, when the dll is initialized, it will check
if the main executable exports the definition for some weak function (for
example __sanitizer_cov_trace_pc_guard). If it finds that function, then it will
override the function in the dll with that pointer. So, all the dlls with
instrumentation that import __sanitizer_cov_trace_pc_guard__dll() from asan dll,
will be using the function provided by the main executable.

In other words, when the main executable exports a strong definition for a weak
function, we ensure all the dlls use that implementation instead of the default
weak implementation.

The behavior is similar to linux. Now, every user that want to override a weak
function, only has to define and export it. The same for Linux and Windows, and
it will work fine. So, there is no difference on the user's side.

All the sanitizers will include a file sanitizer_win_weak_interception.cc that
register sanitizer's weak functions to be intercepted in the binary section WEAK

When the sanitizer dll is initialized, it will execute weak_intercept_init()
which will consider all the CB registered in the section WEAK. So, for all the
weak functions registered, we will check if a strong definition is provided in
the main executable.

All the files sanitizer_win_weak_interception.cc are independent, so we do not
need to include a specific list of sanitizers.
Now, we include [asan|ubsan|sanitizer_coverage]_win_weak_interception.cc and
sanitizer_win_weak_interception.cc in asan dll, so when it is initialized, it
will consider all the weak functions from asan, ubsan and sanitizer coverage.

After this diff, sanitizer coverage is fixed for MD on Windows. In particular
libFuzzer can provide custom implementation for all sanitizer coverage's weak
functions, and they will be considered by asan dll.

Differential Revision: https://reviews.llvm.org/D29168

llvm-svn: 293958
2017-02-02 23:02:11 +00:00
..
CMakeLists.txt [sanitizer] Use interception to access to strong definitions in the executable. 2017-02-02 23:02:11 +00:00
ubsan.syms.extra
ubsan_checks.inc [UBSan] Remove "-fsanitize=" prefix from ubsan_checks.inc. NFC. 2015-12-08 23:29:36 +00:00
ubsan_diag.cc [sanitizer] Use architecture/slice information when symbolizing fat Mach-O files on Darwin 2017-01-06 21:45:05 +00:00
ubsan_diag.h [UBSan] Implement runtime suppressions (PR25066). 2015-12-18 19:56:42 +00:00
ubsan_flags.cc General definition for weak functions 2017-01-29 05:44:59 +00:00
ubsan_flags.h [UBSan] Embed UBSan into ASan runtime (compiler-rt part). 2015-04-01 22:42:36 +00:00
ubsan_flags.inc [UBSan] Add the ability to print more precise error kind in summary line. 2015-08-24 23:18:49 +00:00
ubsan_handlers.cc [ubsan] Minimize size of data for type_mismatch (Redo of D19668) 2017-01-06 14:40:28 +00:00
ubsan_handlers.h [ubsan] Minimize size of data for type_mismatch (Redo of D19668) 2017-01-06 14:40:28 +00:00
ubsan_handlers_cxx.cc UBSan: crash less often on corrupted Vtables. 2016-06-02 18:36:12 +00:00
ubsan_handlers_cxx.h [cfi] Cross-DSO CFI diagnostic mode (compiler-rt part) 2016-01-25 23:34:38 +00:00
ubsan_init.cc [ubsan] Initialize Android logging. 2016-08-15 18:35:40 +00:00
ubsan_init.h [UBSan] Embed UBSan into ASan runtime (compiler-rt part). 2015-04-01 22:42:36 +00:00
ubsan_init_standalone.cc [UBSan] Add missing header that defines SANITIZER_CAN_USE_PREINIT_ARRAY 2015-05-11 21:06:49 +00:00
ubsan_interface.inc [sanitizer] Add list of symbols exported in sanitizers' interface. 2017-01-31 20:23:21 +00:00
ubsan_platform.h [sanitizer] [SystemZ] Enable UBSan. 2016-04-15 22:25:04 +00:00
ubsan_type_hash.cc CFI: Get check-cfi passing on Windows. 2015-07-08 22:10:34 +00:00
ubsan_type_hash.h UBSan: crash less often on corrupted Vtables. 2016-06-02 18:36:12 +00:00
ubsan_type_hash_itanium.cc [ubsan] More 0 -> nullptr conversions (NFC) 2016-10-06 23:41:57 +00:00
ubsan_type_hash_win.cc UBSan: Simplify logic for locating the RTTI object. 2015-07-08 23:22:39 +00:00
ubsan_value.cc Fix bad regression from r263077 when building with MSVC. 2016-03-12 01:57:31 +00:00
ubsan_value.h [UBSan] Explicitly list all supported OS/arch pairs supported by UBSan. 2015-03-26 17:26:04 +00:00
ubsan_win_dll_thunk.cc [sanitizer] Intercept weak functions in dll_thunks. 2017-02-02 23:01:34 +00:00
ubsan_win_dynamic_runtime_thunk.cc [sanitizer] Add dynamic_runtime_thunk for different sanitizers. 2017-02-02 23:01:41 +00:00
ubsan_win_weak_interception.cc [sanitizer] Use interception to access to strong definitions in the executable. 2017-02-02 23:02:11 +00:00
weak_symbols.txt Enable weak hooks on darwin 2017-01-09 03:51:42 +00:00