-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 llvm-svn: 293953
- Loading branch information
Marcos Pividori
committed
Feb 2, 2017
1 parent
f5d2654
commit b88e87d
Showing
7 changed files
with
117 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
compiler-rt/lib/sanitizer_common/sanitizer_coverage_win_dynamic_runtime_thunk.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- sanitizer_coverage_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 Sanitizer Coverage, when it is included in a dll. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifdef SANITIZER_DYNAMIC_RUNTIME_THUNK | ||
#define SANITIZER_IMPORT_INTERFACE 1 | ||
#include "sanitizer_win_defs.h" | ||
// Define weak alias for all weak functions imported from sanitizer coverage. | ||
#define INTERFACE_FUNCTION(Name) | ||
#define INTERFACE_WEAK_FUNCTION(Name) WIN_WEAK_IMPORT_DEF(Name) | ||
#include "sanitizer_coverage_interface.inc" | ||
#endif // SANITIZER_DYNAMIC_RUNTIME_THUNK |
21 changes: 21 additions & 0 deletions
21
compiler-rt/lib/sanitizer_common/sanitizer_win_dynamic_runtime_thunk.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- santizer_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 Sanitizer Common, when it is included in a dll. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifdef SANITIZER_DYNAMIC_RUNTIME_THUNK | ||
#define SANITIZER_IMPORT_INTERFACE 1 | ||
#include "sanitizer_win_defs.h" | ||
// Define weak alias for all weak functions imported from sanitizer common. | ||
#define INTERFACE_FUNCTION(Name) | ||
#define INTERFACE_WEAK_FUNCTION(Name) WIN_WEAK_IMPORT_DEF(Name) | ||
#include "sanitizer_common_interface.inc" | ||
#endif // SANITIZER_DYNAMIC_RUNTIME_THUNK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |