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