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