* c-parser.c (c_parser_omp_requires): Call sorry_at on requires
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_platform.h
blob352b374e177069e4d4867e71f2284687acabdae8
1 //===-- sanitizer_platform.h ------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // Common platform macros.
9 //===----------------------------------------------------------------------===//
11 #ifndef SANITIZER_PLATFORM_H
12 #define SANITIZER_PLATFORM_H
14 #if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \
15 !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(_WIN32) && \
16 !defined(__Fuchsia__) && !defined(__rtems__) && \
17 !(defined(__sun__) && defined(__svr4__))
18 # error "This operating system is not supported"
19 #endif
21 #if defined(__linux__)
22 # define SANITIZER_LINUX 1
23 #else
24 # define SANITIZER_LINUX 0
25 #endif
27 #if defined(__FreeBSD__)
28 # define SANITIZER_FREEBSD 1
29 #else
30 # define SANITIZER_FREEBSD 0
31 #endif
33 #if defined(__NetBSD__)
34 # define SANITIZER_NETBSD 1
35 #else
36 # define SANITIZER_NETBSD 0
37 #endif
39 #if defined(__OpenBSD__)
40 # define SANITIZER_OPENBSD 1
41 #else
42 # define SANITIZER_OPENBSD 0
43 #endif
45 #if defined(__sun__) && defined(__svr4__)
46 # define SANITIZER_SOLARIS 1
47 #else
48 # define SANITIZER_SOLARIS 0
49 #endif
51 #if defined(__APPLE__)
52 # define SANITIZER_MAC 1
53 # include <TargetConditionals.h>
54 # if TARGET_OS_IPHONE
55 # define SANITIZER_IOS 1
56 # else
57 # define SANITIZER_IOS 0
58 # endif
59 # if TARGET_OS_SIMULATOR
60 # define SANITIZER_IOSSIM 1
61 # else
62 # define SANITIZER_IOSSIM 0
63 # endif
64 #else
65 # define SANITIZER_MAC 0
66 # define SANITIZER_IOS 0
67 # define SANITIZER_IOSSIM 0
68 #endif
70 #if defined(__APPLE__) && TARGET_OS_IPHONE && TARGET_OS_WATCH
71 # define SANITIZER_WATCHOS 1
72 #else
73 # define SANITIZER_WATCHOS 0
74 #endif
76 #if defined(__APPLE__) && TARGET_OS_IPHONE && TARGET_OS_TV
77 # define SANITIZER_TVOS 1
78 #else
79 # define SANITIZER_TVOS 0
80 #endif
82 #if defined(_WIN32)
83 # define SANITIZER_WINDOWS 1
84 #else
85 # define SANITIZER_WINDOWS 0
86 #endif
88 #if defined(_WIN64)
89 # define SANITIZER_WINDOWS64 1
90 #else
91 # define SANITIZER_WINDOWS64 0
92 #endif
94 #if defined(__ANDROID__)
95 # define SANITIZER_ANDROID 1
96 #else
97 # define SANITIZER_ANDROID 0
98 #endif
100 #if defined(__Fuchsia__)
101 # define SANITIZER_FUCHSIA 1
102 #else
103 # define SANITIZER_FUCHSIA 0
104 #endif
106 #if defined(__rtems__)
107 # define SANITIZER_RTEMS 1
108 #else
109 # define SANITIZER_RTEMS 0
110 #endif
112 #define SANITIZER_POSIX \
113 (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC || \
114 SANITIZER_NETBSD || SANITIZER_OPENBSD || SANITIZER_SOLARIS)
116 #if __LP64__ || defined(_WIN64)
117 # define SANITIZER_WORDSIZE 64
118 #else
119 # define SANITIZER_WORDSIZE 32
120 #endif
122 #if SANITIZER_WORDSIZE == 64
123 # define FIRST_32_SECOND_64(a, b) (b)
124 #else
125 # define FIRST_32_SECOND_64(a, b) (a)
126 #endif
128 #if defined(__x86_64__) && !defined(_LP64)
129 # define SANITIZER_X32 1
130 #else
131 # define SANITIZER_X32 0
132 #endif
134 #if defined(__mips__)
135 # define SANITIZER_MIPS 1
136 # if defined(__mips64)
137 # define SANITIZER_MIPS32 0
138 # define SANITIZER_MIPS64 1
139 # else
140 # define SANITIZER_MIPS32 1
141 # define SANITIZER_MIPS64 0
142 # endif
143 #else
144 # define SANITIZER_MIPS 0
145 # define SANITIZER_MIPS32 0
146 # define SANITIZER_MIPS64 0
147 #endif
149 #if defined(__s390__)
150 # define SANITIZER_S390 1
151 # if defined(__s390x__)
152 # define SANITIZER_S390_31 0
153 # define SANITIZER_S390_64 1
154 # else
155 # define SANITIZER_S390_31 1
156 # define SANITIZER_S390_64 0
157 # endif
158 #else
159 # define SANITIZER_S390 0
160 # define SANITIZER_S390_31 0
161 # define SANITIZER_S390_64 0
162 #endif
164 #if defined(__powerpc__)
165 # define SANITIZER_PPC 1
166 # if defined(__powerpc64__)
167 # define SANITIZER_PPC32 0
168 # define SANITIZER_PPC64 1
169 // 64-bit PPC has two ABIs (v1 and v2). The old powerpc64 target is
170 // big-endian, and uses v1 ABI (known for its function descriptors),
171 // while the new powerpc64le target is little-endian and uses v2.
172 // In theory, you could convince gcc to compile for their evil twins
173 // (eg. big-endian v2), but you won't find such combinations in the wild
174 // (it'd require bootstrapping a whole system, which would be quite painful
175 // - there's no target triple for that). LLVM doesn't support them either.
176 # if _CALL_ELF == 2
177 # define SANITIZER_PPC64V1 0
178 # define SANITIZER_PPC64V2 1
179 # else
180 # define SANITIZER_PPC64V1 1
181 # define SANITIZER_PPC64V2 0
182 # endif
183 # else
184 # define SANITIZER_PPC32 1
185 # define SANITIZER_PPC64 0
186 # define SANITIZER_PPC64V1 0
187 # define SANITIZER_PPC64V2 0
188 # endif
189 #else
190 # define SANITIZER_PPC 0
191 # define SANITIZER_PPC32 0
192 # define SANITIZER_PPC64 0
193 # define SANITIZER_PPC64V1 0
194 # define SANITIZER_PPC64V2 0
195 #endif
197 #if defined(__arm__)
198 # define SANITIZER_ARM 1
199 #else
200 # define SANITIZER_ARM 0
201 #endif
203 #if SANITIZER_SOLARIS && SANITIZER_WORDSIZE == 32
204 # define SANITIZER_SOLARIS32 1
205 #else
206 # define SANITIZER_SOLARIS32 0
207 #endif
209 #if defined(__myriad2__)
210 # define SANITIZER_MYRIAD2 1
211 #else
212 # define SANITIZER_MYRIAD2 0
213 #endif
215 // By default we allow to use SizeClassAllocator64 on 64-bit platform.
216 // But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64
217 // does not work well and we need to fallback to SizeClassAllocator32.
218 // For such platforms build this code with -DSANITIZER_CAN_USE_ALLOCATOR64=0 or
219 // change the definition of SANITIZER_CAN_USE_ALLOCATOR64 here.
220 #ifndef SANITIZER_CAN_USE_ALLOCATOR64
221 # if (SANITIZER_ANDROID && defined(__aarch64__)) || SANITIZER_FUCHSIA
222 # define SANITIZER_CAN_USE_ALLOCATOR64 1
223 # elif defined(__mips64) || defined(__aarch64__)
224 # define SANITIZER_CAN_USE_ALLOCATOR64 0
225 # else
226 # define SANITIZER_CAN_USE_ALLOCATOR64 (SANITIZER_WORDSIZE == 64)
227 # endif
228 #endif
230 // The range of addresses which can be returned my mmap.
231 // FIXME: this value should be different on different platforms. Larger values
232 // will still work but will consume more memory for TwoLevelByteMap.
233 #if defined(__mips__)
234 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40)
235 #elif defined(__aarch64__)
236 # if SANITIZER_MAC
237 // Darwin iOS/ARM64 has a 36-bit VMA, 64GiB VM
238 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 36)
239 # else
240 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 48)
241 # endif
242 #else
243 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
244 #endif
246 // The AArch64 linux port uses the canonical syscall set as mandated by
247 // the upstream linux community for all new ports. Other ports may still
248 // use legacy syscalls.
249 #ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
250 # if defined(__aarch64__) && SANITIZER_LINUX
251 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
252 # else
253 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0
254 # endif
255 #endif
257 // udi16 syscalls can only be used when the following conditions are
258 // met:
259 // * target is one of arm32, x86-32, sparc32, sh or m68k
260 // * libc version is libc5, glibc-2.0, glibc-2.1 or glibc-2.2 to 2.15
261 // built against > linux-2.2 kernel headers
262 // Since we don't want to include libc headers here, we check the
263 // target only.
264 #if defined(__arm__) || SANITIZER_X32 || defined(__sparc__)
265 #define SANITIZER_USES_UID16_SYSCALLS 1
266 #else
267 #define SANITIZER_USES_UID16_SYSCALLS 0
268 #endif
270 #if defined(__mips__)
271 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 10)
272 #else
273 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
274 #endif
276 // Assume obsolete RPC headers are available by default
277 #if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
278 # define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
279 # define HAVE_TIRPC_RPC_XDR_H 0
280 #endif
282 /// \macro MSC_PREREQ
283 /// \brief Is the compiler MSVC of at least the specified version?
284 /// The common \param version values to check for are:
285 /// * 1800: Microsoft Visual Studio 2013 / 12.0
286 /// * 1900: Microsoft Visual Studio 2015 / 14.0
287 #ifdef _MSC_VER
288 # define MSC_PREREQ(version) (_MSC_VER >= (version))
289 #else
290 # define MSC_PREREQ(version) 0
291 #endif
293 #if defined(__arm64__) && SANITIZER_IOS
294 # define SANITIZER_NON_UNIQUE_TYPEINFO 1
295 #else
296 # define SANITIZER_NON_UNIQUE_TYPEINFO 0
297 #endif
299 // On linux, some architectures had an ABI transition from 64-bit long double
300 // (ie. same as double) to 128-bit long double. On those, glibc symbols
301 // involving long doubles come in two versions, and we need to pass the
302 // correct one to dlvsym when intercepting them.
303 #if SANITIZER_LINUX && (SANITIZER_S390 || SANITIZER_PPC32 || SANITIZER_PPC64V1)
304 #define SANITIZER_NLDBL_VERSION "GLIBC_2.4"
305 #endif
307 #if SANITIZER_GO == 0
308 # define SANITIZER_GO 0
309 #endif
311 // On PowerPC and ARM Thumb, calling pthread_exit() causes LSan to detect leaks.
312 // pthread_exit() performs unwinding that leads to dlopen'ing libgcc_s.so.
313 // dlopen mallocs "libgcc_s.so" string which confuses LSan, it fails to realize
314 // that this allocation happens in dynamic linker and should be ignored.
315 #if SANITIZER_PPC || defined(__thumb__)
316 # define SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT 1
317 #else
318 # define SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT 0
319 #endif
321 #if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD || \
322 SANITIZER_OPENBSD || SANITIZER_SOLARIS
323 # define SANITIZER_MADVISE_DONTNEED MADV_FREE
324 #else
325 # define SANITIZER_MADVISE_DONTNEED MADV_DONTNEED
326 #endif
328 // Older gcc have issues aligning to a constexpr, and require an integer.
329 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56859 among others.
330 #if defined(__powerpc__) || defined(__powerpc64__)
331 # define SANITIZER_CACHE_LINE_SIZE 128
332 #else
333 # define SANITIZER_CACHE_LINE_SIZE 64
334 #endif
336 // Enable offline markup symbolizer for Fuchsia and RTEMS.
337 #if SANITIZER_FUCHSIA || SANITIZER_RTEMS
338 #define SANITIZER_SYMBOLIZER_MARKUP 1
339 #else
340 #define SANITIZER_SYMBOLIZER_MARKUP 0
341 #endif
343 #endif // SANITIZER_PLATFORM_H