diff options
author | Marcos Pividori <mpividori@google.com> | 2017-02-02 23:01:41 +0000 |
---|---|---|
committer | Marcos Pividori <mpividori@google.com> | 2017-02-02 23:01:41 +0000 |
commit | e1b9a6cf921f5c81b6253e6cf8531082b9857fae (patch) | |
tree | 2d3273d417ab8dcb4c81a7aa7b627d6b559b5a26 /lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc | |
parent | ca2b8ef1e0ae392ffcb5b7357ec9eed92deec865 (diff) |
[sanitizer] Add dynamic_runtime_thunk for different sanitizers.
In Windows, when the sanitizer is implemented as a shared library (DLL), we need
an auxiliary static library dynamic_runtime_thunk that will be linked to the
main executable and dlls.
In the sanitizer DLL, we are exposing weak functions with WIN_WEAK_EXPORT_DEF(),
which exports the default implementation with __dll suffix. For example: for
sanitizer coverage, the default implementation of __sanitizer_cov_trace_cmp is
exported as: __sanitizer_cov_trace_cmp__dll.
In the dynamic_runtime_thunk static library, we include weak aliases to the
imported implementation from the dll, using the macro WIN_WEAK_IMPORT_DEF().
By default, all users's programs that include calls to weak functions like
__sanitizer_cov_trace_cmp, will be redirected to the implementation in the dll,
when linking to dynamic_runtime_thunk.
After this diff, we are able to compile code with sanitizer coverage
instrumentation on Windows. When the instrumented object files are linked with
clang-rt_asan_dynamic_runtime_thunk-arch.lib all the weak symbols will be
resolved to the implementation imported from asan dll.
All the files sanitizer_dynamic_runtime_thunk.cc are independent, so we do not
need to include a specific list of sanitizers.
Now, we compile: [asan|ubsan|sanitizer_coverage]_win_dynamic_runtime_thunk.cc
and sanitizer_win_dynamic_runtime_thunk.cc to generate
asan_dynamic_runtime_thunk.lib, because we include asan, ubsan and sanitizer
coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29158
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293953 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc')
-rw-r--r-- | lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc b/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc new file mode 100644 index 000000000..c9b74a4c9 --- /dev/null +++ b/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc @@ -0,0 +1,21 @@ +//===-- ubsan_win_dynamic_runtime_thunk.cc --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines things that need to be present in the application modules +// to interact with Ubsan, when it is included in a dll. +// +//===----------------------------------------------------------------------===// +#ifdef SANITIZER_DYNAMIC_RUNTIME_THUNK +#define SANITIZER_IMPORT_INTERFACE 1 +#include "sanitizer_common/sanitizer_win_defs.h" +// Define weak alias for all weak functions imported from ubsan. +#define INTERFACE_FUNCTION(Name) +#define INTERFACE_WEAK_FUNCTION(Name) WIN_WEAK_IMPORT_DEF(Name) +#include "ubsan_interface.inc" +#endif // SANITIZER_DYNAMIC_RUNTIME_THUNK |