]>
Commit | Line | Data |
---|---|---|
36093749 | 1 | //===-- sanitizer_coverage_win_sections.cc --------------------------------===// |
2 | // | |
3 | // This file is distributed under the University of Illinois Open Source | |
4 | // License. See LICENSE.TXT for details. | |
5 | // | |
6 | //===----------------------------------------------------------------------===// | |
7 | // | |
d2ef4bee | 8 | // This file defines delimiters for Sanitizer Coverage's section. It contains |
9 | // Windows specific tricks to coax the linker into giving us the start and stop | |
10 | // addresses of a section, as ELF linkers can do, to get the size of certain | |
11 | // arrays. According to https://msdn.microsoft.com/en-us/library/7977wcck.aspx | |
12 | // sections with the same name before "$" are sorted alphabetically by the | |
13 | // string that comes after "$" and merged into one section. We take advantage | |
14 | // of this by putting data we want the size of into the middle (M) of a section, | |
15 | // by using the letter "M" after "$". We get the start of this data (ie: | |
16 | // __start_section_name) by making the start variable come at the start of the | |
17 | // section (using the letter A after "$"). We do the same to get the end of the | |
18 | // data by using the letter "Z" after "$" to make the end variable come after | |
19 | // the data. Note that because of our technique the address of the start | |
20 | // variable is actually the address of data that comes before our middle | |
21 | // section. We also need to prevent the linker from adding any padding. Each | |
22 | // technique we use for this is explained in the comments below. | |
36093749 | 23 | //===----------------------------------------------------------------------===// |
24 | ||
25 | #include "sanitizer_platform.h" | |
26 | #if SANITIZER_WINDOWS | |
27 | #include <stdint.h> | |
36093749 | 28 | extern "C" { |
d2ef4bee | 29 | // The Guard array and counter array should both be merged into the .data |
30 | // section to reduce the number of PE sections However, because PCTable is | |
31 | // constant it should be merged with the .rdata section. | |
32 | #pragma section(".SCOV$GA", read, write) // NOLINT | |
33 | // Use align(1) to avoid adding any padding that will mess up clients trying to | |
34 | // determine the start and end of the array. | |
35 | __declspec(allocate(".SCOV$GA")) __declspec(align(1)) uint64_t | |
36 | __start___sancov_guards = 0; | |
37 | #pragma section(".SCOV$GZ", read, write) // NOLINT | |
38 | __declspec(allocate(".SCOV$GZ")) __declspec(align(1)) uint64_t | |
39 | __stop___sancov_guards = 0; | |
40 | ||
41 | #pragma section(".SCOV$CA", read, write) // NOLINT | |
42 | __declspec(allocate(".SCOV$CA")) __declspec(align(1)) uint64_t | |
43 | __start___sancov_cntrs = 0; | |
44 | #pragma section(".SCOV$CZ", read, write) // NOLINT | |
45 | __declspec(allocate(".SCOV$CZ")) __declspec(align(1)) uint64_t | |
46 | __stop___sancov_cntrs = 0; | |
47 | ||
48 | #pragma comment(linker, "/MERGE:.SCOV=.data") | |
49 | ||
50 | // Use uint64_t so there won't be any issues if the linker tries to word align | |
51 | // the pc array. | |
52 | #pragma section(".SCOVP$A", read) // NOLINT | |
53 | __declspec(allocate(".SCOVP$A")) __declspec(align(1)) uint64_t | |
54 | __start___sancov_pcs = 0; | |
55 | #pragma section(".SCOVP$Z", read) // NOLINT | |
56 | __declspec(allocate(".SCOVP$Z")) __declspec(align(1)) uint64_t | |
57 | __stop___sancov_pcs = 0; | |
58 | ||
59 | #pragma comment(linker, "/MERGE:.SCOVP=.rdata") | |
36093749 | 60 | } |
d2ef4bee | 61 | #endif // SANITIZER_WINDOWS |