Skip to content

Commit c1f8a82

Browse files
author
Marcos Pividori
committedFeb 2, 2017
[sancov] Define delimiters for sanitizer coverage's binary section on Windows.
On Windows, the symbols "___stop___sancov_guards" and "___start___sancov_guards" are not defined automatically. So, we need to take a different approach. We define 3 sections: ".SCOV$A", ".SCOV$M" and ".SCOV$Z". Section ".SCOV$A" will only hold a variable ___start___sancov_guard. Section ".SCOV$M" will hold the main data. Section ".SCOV$Z" will only hold a variable ___stop___sancov_guards. When linking, they will be merged sorted by the characters after the $, so we can use the pointers of the variables ___[start|stop]___sancov_guard to know the actual range of addresses of that section. ___[start|stop]___sancov_guard should be defined only once per module. On Windows, we have 2 different cases: + When considering a shared runtime: All the modules, main executable and dlls, are linked to an auxiliary static library dynamic_runtime_thunk.lib. Because of that, we include the delimiters in `SancovDynamicRuntimeThunk`. + When considering a static runtime: The main executable in linked to the static runtime library. All the dlls are linked to an auxiliary static library dll_thunk. Because of that, we include the delimiter to both `SancovDllThunk` and `SANITIZER_LIBCDEP_SOURCES` (which is included in the static runtime lib). Differential Revision: https://reviews.llvm.org/D28435 llvm-svn: 293959
1 parent 2b9c44e commit c1f8a82

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎compiler-rt/lib/sanitizer_common/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ set(SANITIZER_LIBCDEP_SOURCES
5656
sanitizer_coverage_libcdep.cc
5757
sanitizer_coverage_libcdep_new.cc
5858
sanitizer_coverage_mapping_libcdep.cc
59+
sanitizer_coverage_win_sections.cc
5960
sanitizer_linux_libcdep.cc
6061
sanitizer_posix_libcdep.cc
6162
sanitizer_stacktrace_libcdep.cc
@@ -211,6 +212,7 @@ if(MSVC)
211212
${SANITIZER_COMMON_SUPPORTED_OS}
212213
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
213214
SOURCES sanitizer_coverage_win_dll_thunk.cc
215+
sanitizer_coverage_win_sections.cc
214216
CFLAGS ${SANITIZER_CFLAGS} -DSANITIZER_DLL_THUNK
215217
DEFS ${SANITIZER_COMMON_DEFINITIONS})
216218

@@ -230,6 +232,7 @@ if(MSVC)
230232
${SANITIZER_COMMON_SUPPORTED_OS}
231233
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
232234
SOURCES sanitizer_coverage_win_dynamic_runtime_thunk.cc
235+
sanitizer_coverage_win_sections.cc
233236
CFLAGS ${SANITIZER_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
234237
DEFS ${SANITIZER_COMMON_DEFINITIONS})
235238
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- sanitizer_coverage_win_sections.cc --------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This file defines delimiters for Sanitizer Coverage's section.
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "sanitizer_platform.h"
14+
#if SANITIZER_WINDOWS
15+
#include <stdint.h>
16+
#pragma section(".SCOV$A", read, write) // NOLINT
17+
#pragma section(".SCOV$Z", read, write) // NOLINT
18+
extern "C" {
19+
__declspec(allocate(".SCOV$A")) uint32_t __start___sancov_guards = 0;
20+
__declspec(allocate(".SCOV$Z")) uint32_t __stop___sancov_guards = 0;
21+
}
22+
#endif // SANITIZER_WINDOWS

0 commit comments

Comments
 (0)
Please sign in to comment.