]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
dts: Update our device tree sources file fomr Linux 4.13
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sanitizer_platform.h
1 //===-- sanitizer_platform.h ------------------------------------*- C++ -*-===//
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 // Common platform macros.
11 //===----------------------------------------------------------------------===//
12
13 #ifndef SANITIZER_PLATFORM_H
14 #define SANITIZER_PLATFORM_H
15
16 #if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \
17   !defined(__APPLE__) && !defined(_WIN32)
18 # error "This operating system is not supported"
19 #endif
20
21 #if defined(__linux__)
22 # define SANITIZER_LINUX   1
23 #else
24 # define SANITIZER_LINUX   0
25 #endif
26
27 #if defined(__FreeBSD__)
28 # define SANITIZER_FREEBSD 1
29 #else
30 # define SANITIZER_FREEBSD 0
31 #endif
32
33 #if defined(__NetBSD__)
34 # define SANITIZER_NETBSD 1
35 #else
36 # define SANITIZER_NETBSD 0
37 #endif
38
39 #if defined(__APPLE__)
40 # define SANITIZER_MAC     1
41 # include <TargetConditionals.h>
42 # if TARGET_OS_IPHONE
43 #  define SANITIZER_IOS    1
44 # else
45 #  define SANITIZER_IOS    0
46 # endif
47 # if TARGET_IPHONE_SIMULATOR
48 #  define SANITIZER_IOSSIM 1
49 # else
50 #  define SANITIZER_IOSSIM 0
51 # endif
52 #else
53 # define SANITIZER_MAC     0
54 # define SANITIZER_IOS     0
55 # define SANITIZER_IOSSIM  0
56 #endif
57
58 #if defined(__APPLE__) && TARGET_OS_IPHONE && TARGET_OS_WATCH
59 # define SANITIZER_WATCHOS 1
60 #else
61 # define SANITIZER_WATCHOS 0
62 #endif
63
64 #if defined(__APPLE__) && TARGET_OS_IPHONE && TARGET_OS_TV
65 # define SANITIZER_TVOS 1
66 #else
67 # define SANITIZER_TVOS 0
68 #endif
69
70 #if defined(_WIN32)
71 # define SANITIZER_WINDOWS 1
72 #else
73 # define SANITIZER_WINDOWS 0
74 #endif
75
76 #if defined(_WIN64)
77 # define SANITIZER_WINDOWS64 1
78 #else
79 # define SANITIZER_WINDOWS64 0
80 #endif
81
82 #if defined(__ANDROID__)
83 # define SANITIZER_ANDROID 1
84 #else
85 # define SANITIZER_ANDROID 0
86 #endif
87
88 #define SANITIZER_POSIX \
89   (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC || SANITIZER_NETBSD)
90
91 #if __LP64__ || defined(_WIN64)
92 #  define SANITIZER_WORDSIZE 64
93 #else
94 #  define SANITIZER_WORDSIZE 32
95 #endif
96
97 #if SANITIZER_WORDSIZE == 64
98 # define FIRST_32_SECOND_64(a, b) (b)
99 #else
100 # define FIRST_32_SECOND_64(a, b) (a)
101 #endif
102
103 #if defined(__x86_64__) && !defined(_LP64)
104 # define SANITIZER_X32 1
105 #else
106 # define SANITIZER_X32 0
107 #endif
108
109 #if defined(__mips__)
110 # define SANITIZER_MIPS 1
111 # if defined(__mips64)
112 #  define SANITIZER_MIPS32 0
113 #  define SANITIZER_MIPS64 1
114 # else
115 #  define SANITIZER_MIPS32 1
116 #  define SANITIZER_MIPS64 0
117 # endif
118 #else
119 # define SANITIZER_MIPS 0
120 # define SANITIZER_MIPS32 0
121 # define SANITIZER_MIPS64 0
122 #endif
123
124 #if defined(__s390__)
125 # define SANITIZER_S390 1
126 # if defined(__s390x__)
127 #  define SANITIZER_S390_31 0
128 #  define SANITIZER_S390_64 1
129 # else
130 #  define SANITIZER_S390_31 1
131 #  define SANITIZER_S390_64 0
132 # endif
133 #else
134 # define SANITIZER_S390 0
135 # define SANITIZER_S390_31 0
136 # define SANITIZER_S390_64 0
137 #endif
138
139 #if defined(__powerpc__)
140 # define SANITIZER_PPC 1
141 # if defined(__powerpc64__)
142 #  define SANITIZER_PPC32 0
143 #  define SANITIZER_PPC64 1
144 // 64-bit PPC has two ABIs (v1 and v2).  The old powerpc64 target is
145 // big-endian, and uses v1 ABI (known for its function descriptors),
146 // while the new powerpc64le target is little-endian and uses v2.
147 // In theory, you could convince gcc to compile for their evil twins
148 // (eg. big-endian v2), but you won't find such combinations in the wild
149 // (it'd require bootstrapping a whole system, which would be quite painful
150 // - there's no target triple for that).  LLVM doesn't support them either.
151 #  if _CALL_ELF == 2
152 #   define SANITIZER_PPC64V1 0
153 #   define SANITIZER_PPC64V2 1
154 #  else
155 #   define SANITIZER_PPC64V1 1
156 #   define SANITIZER_PPC64V2 0
157 #  endif
158 # else
159 #  define SANITIZER_PPC32 1
160 #  define SANITIZER_PPC64 0
161 #  define SANITIZER_PPC64V1 0
162 #  define SANITIZER_PPC64V2 0
163 # endif
164 #else
165 # define SANITIZER_PPC 0
166 # define SANITIZER_PPC32 0
167 # define SANITIZER_PPC64 0
168 # define SANITIZER_PPC64V1 0
169 # define SANITIZER_PPC64V2 0
170 #endif
171
172 #if defined(__arm__)
173 # define SANITIZER_ARM 1
174 #else
175 # define SANITIZER_ARM 0
176 #endif
177
178 // By default we allow to use SizeClassAllocator64 on 64-bit platform.
179 // But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64
180 // does not work well and we need to fallback to SizeClassAllocator32.
181 // For such platforms build this code with -DSANITIZER_CAN_USE_ALLOCATOR64=0 or
182 // change the definition of SANITIZER_CAN_USE_ALLOCATOR64 here.
183 #ifndef SANITIZER_CAN_USE_ALLOCATOR64
184 # if SANITIZER_ANDROID && defined(__aarch64__)
185 #  define SANITIZER_CAN_USE_ALLOCATOR64 1
186 # elif defined(__mips64) || defined(__aarch64__)
187 #  define SANITIZER_CAN_USE_ALLOCATOR64 0
188 # else
189 #  define SANITIZER_CAN_USE_ALLOCATOR64 (SANITIZER_WORDSIZE == 64)
190 # endif
191 #endif
192
193 // The range of addresses which can be returned my mmap.
194 // FIXME: this value should be different on different platforms.  Larger values
195 // will still work but will consume more memory for TwoLevelByteMap.
196 #if defined(__mips__)
197 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40)
198 #elif defined(__aarch64__)
199 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 48)
200 #else
201 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
202 #endif
203
204 // The AArch64 linux port uses the canonical syscall set as mandated by
205 // the upstream linux community for all new ports. Other ports may still
206 // use legacy syscalls.
207 #ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
208 # if defined(__aarch64__) && SANITIZER_LINUX
209 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
210 # else
211 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0
212 # endif
213 #endif
214
215 // udi16 syscalls can only be used when the following conditions are
216 // met:
217 // * target is one of arm32, x86-32, sparc32, sh or m68k
218 // * libc version is libc5, glibc-2.0, glibc-2.1 or glibc-2.2 to 2.15
219 //   built against > linux-2.2 kernel headers
220 // Since we don't want to include libc headers here, we check the
221 // target only.
222 #if defined(__arm__) || SANITIZER_X32 || defined(__sparc__)
223 #define SANITIZER_USES_UID16_SYSCALLS 1
224 #else
225 #define SANITIZER_USES_UID16_SYSCALLS 0
226 #endif
227
228 #if defined(__mips__)
229 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 10)
230 #else
231 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
232 #endif
233
234 // Assume obsolete RPC headers are available by default
235 #if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
236 # define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
237 # define HAVE_TIRPC_RPC_XDR_H 0
238 #endif
239
240 /// \macro MSC_PREREQ
241 /// \brief Is the compiler MSVC of at least the specified version?
242 /// The common \param version values to check for are:
243 ///  * 1800: Microsoft Visual Studio 2013 / 12.0
244 ///  * 1900: Microsoft Visual Studio 2015 / 14.0
245 #ifdef _MSC_VER
246 # define MSC_PREREQ(version) (_MSC_VER >= (version))
247 #else
248 # define MSC_PREREQ(version) 0
249 #endif
250
251 #if defined(__arm64__) && SANITIZER_IOS
252 # define SANITIZER_NON_UNIQUE_TYPEINFO 1
253 #else
254 # define SANITIZER_NON_UNIQUE_TYPEINFO 0
255 #endif
256
257 // On linux, some architectures had an ABI transition from 64-bit long double
258 // (ie. same as double) to 128-bit long double.  On those, glibc symbols
259 // involving long doubles come in two versions, and we need to pass the
260 // correct one to dlvsym when intercepting them.
261 #if SANITIZER_LINUX && (SANITIZER_S390 || SANITIZER_PPC32 || SANITIZER_PPC64V1)
262 #define SANITIZER_NLDBL_VERSION "GLIBC_2.4"
263 #endif
264
265 #if SANITIZER_GO == 0
266 # define SANITIZER_GO 0
267 #endif
268
269 // On PowerPC and ARM Thumb, calling pthread_exit() causes LSan to detect leaks.
270 // pthread_exit() performs unwinding that leads to dlopen'ing libgcc_s.so.
271 // dlopen mallocs "libgcc_s.so" string which confuses LSan, it fails to realize
272 // that this allocation happens in dynamic linker and should be ignored.
273 #if SANITIZER_PPC || defined(__thumb__)
274 # define SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT 1
275 #else
276 # define SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT 0
277 #endif
278
279
280 #endif // SANITIZER_PLATFORM_H