v8  5.5.372(node7.10.1)
V8 is Google's open source JavaScript engine
v8config.h
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8CONFIG_H_
6 #define V8CONFIG_H_
7 
8 // clang-format off
9 
10 // Platform headers for feature detection below.
11 #if defined(__ANDROID__)
12 # include <sys/cdefs.h>
13 #elif defined(__APPLE__)
14 # include <TargetConditionals.h>
15 #elif defined(__linux__)
16 # include <features.h>
17 #endif
18 
19 
20 // This macro allows to test for the version of the GNU C library (or
21 // a compatible C library that masquerades as glibc). It evaluates to
22 // 0 if libc is not GNU libc or compatible.
23 // Use like:
24 // #if V8_GLIBC_PREREQ(2, 3)
25 // ...
26 // #endif
27 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
28 # define V8_GLIBC_PREREQ(major, minor)
29  ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor)))
30 #else
31 # define V8_GLIBC_PREREQ(major, minor) 0
32 #endif
33 
34 
35 // This macro allows to test for the version of the GNU C++ compiler.
36 // Note that this also applies to compilers that masquerade as GCC,
37 // for example clang and the Intel C++ compiler for Linux.
38 // Use like:
39 // #if V8_GNUC_PREREQ(4, 3, 1)
40 // ...
41 // #endif
42 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
43 # define V8_GNUC_PREREQ(major, minor, patchlevel)
44  ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >=
45  ((major) * 10000 + (minor) * 100 + (patchlevel)))
46 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
47 # define V8_GNUC_PREREQ(major, minor, patchlevel)
48  ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >=
49  ((major) * 10000 + (minor) * 100 + (patchlevel)))
50 #else
51 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0
52 #endif
53 
54 
55 
56 // -----------------------------------------------------------------------------
57 // Operating system detection
58 //
59 // V8_OS_ANDROID - Android
60 // V8_OS_BSD - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD)
61 // V8_OS_CYGWIN - Cygwin
62 // V8_OS_DRAGONFLYBSD - DragonFlyBSD
63 // V8_OS_FREEBSD - FreeBSD
64 // V8_OS_LINUX - Linux
65 // V8_OS_MACOSX - Mac OS X
66 // V8_OS_NETBSD - NetBSD
67 // V8_OS_OPENBSD - OpenBSD
68 // V8_OS_POSIX - POSIX compatible (mostly everything except Windows)
69 // V8_OS_QNX - QNX Neutrino
70 // V8_OS_SOLARIS - Sun Solaris and OpenSolaris
71 // V8_OS_AIX - AIX
72 // V8_OS_WIN - Microsoft Windows
73 
74 #if defined(__ANDROID__)
75 # define V8_OS_ANDROID 1
76 # define V8_OS_LINUX 1
77 # define V8_OS_POSIX 1
78 #elif defined(__APPLE__)
79 # define V8_OS_BSD 1
80 # define V8_OS_MACOSX 1
81 # define V8_OS_POSIX 1
82 #elif defined(__CYGWIN__)
83 # define V8_OS_CYGWIN 1
84 # define V8_OS_POSIX 1
85 #elif defined(__linux__)
86 # define V8_OS_LINUX 1
87 # define V8_OS_POSIX 1
88 #elif defined(__sun)
89 # define V8_OS_POSIX 1
90 # define V8_OS_SOLARIS 1
91 #elif defined(_AIX)
92 #define V8_OS_POSIX 1
93 #define V8_OS_AIX 1
94 #elif defined(__FreeBSD__)
95 # define V8_OS_BSD 1
96 # define V8_OS_FREEBSD 1
97 # define V8_OS_POSIX 1
98 #elif defined(__DragonFly__)
99 # define V8_OS_BSD 1
100 # define V8_OS_DRAGONFLYBSD 1
101 # define V8_OS_POSIX 1
102 #elif defined(__NetBSD__)
103 # define V8_OS_BSD 1
104 # define V8_OS_NETBSD 1
105 # define V8_OS_POSIX 1
106 #elif defined(__OpenBSD__)
107 # define V8_OS_BSD 1
108 # define V8_OS_OPENBSD 1
109 # define V8_OS_POSIX 1
110 #elif defined(__QNXNTO__)
111 # define V8_OS_POSIX 1
112 # define V8_OS_QNX 1
113 #elif defined(_WIN32)
114 # define V8_OS_WIN 1
115 #endif
116 
117 
118 // -----------------------------------------------------------------------------
119 // C library detection
120 //
121 // V8_LIBC_MSVCRT - MSVC libc
122 // V8_LIBC_BIONIC - Bionic libc
123 // V8_LIBC_BSD - BSD libc derivate
124 // V8_LIBC_GLIBC - GNU C library
125 // V8_LIBC_UCLIBC - uClibc
126 //
127 // Note that testing for libc must be done using #if not #ifdef. For example,
128 // to test for the GNU C library, use:
129 // #if V8_LIBC_GLIBC
130 // ...
131 // #endif
132 
133 #if defined (_MSC_VER)
134 # define V8_LIBC_MSVCRT 1
135 #elif defined(__BIONIC__)
136 # define V8_LIBC_BIONIC 1
137 # define V8_LIBC_BSD 1
138 #elif defined(__UCLIBC__)
139 // Must test for UCLIBC before GLIBC, as UCLIBC pretends to be GLIBC.
140 # define V8_LIBC_UCLIBC 1
141 #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__)
142 # define V8_LIBC_GLIBC 1
143 #else
144 # define V8_LIBC_BSD V8_OS_BSD
145 #endif
146 
147 
148 // -----------------------------------------------------------------------------
149 // Compiler detection
150 //
151 // V8_CC_GNU - GCC, or clang in gcc mode
152 // V8_CC_INTEL - Intel C++
153 // V8_CC_MINGW - Minimalist GNU for Windows
154 // V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32)
155 // V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64)
156 // V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode
157 //
158 // C++11 feature detection
159 //
160 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported
161 // V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported
162 //
163 // Compiler-specific feature detection
164 //
165 // V8_HAS___ALIGNOF - __alignof(type) operator supported
166 // V8_HAS___ALIGNOF__ - __alignof__(type) operator supported
167 // V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported
168 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline))
169 // supported
170 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported
171 // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported
172 // V8_HAS_ATTRIBUTE_NORETURN - __attribute__((noreturn)) supported
173 // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported
174 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported
175 // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
176 // supported
177 // V8_HAS_BUILTIN_CLZ - __builtin_clz() supported
178 // V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported
179 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported
180 // V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported
181 // V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported
182 // V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported
183 // V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported
184 // V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported
185 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported
186 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported
187 // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported
188 // V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported
189 // V8_HAS_DECLSPEC_NORETURN - __declspec(noreturn) supported
190 // V8_HAS___FORCEINLINE - __forceinline supported
191 //
192 // Note that testing for compilers and/or features must be done using #if
193 // not #ifdef. For example, to test for Intel C++ Compiler, use:
194 // #if V8_CC_INTEL
195 // ...
196 // #endif
197 
198 #if defined(__clang__)
199 
200 #if defined(__GNUC__) // Clang in gcc mode.
201 # define V8_CC_GNU 1
202 #endif
203 
204 // Clang defines __alignof__ as alias for __alignof
205 # define V8_HAS___ALIGNOF 1
206 # define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF
207 
208 # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned))
209 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
210 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated))
211 # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
212 # define V8_HAS_ATTRIBUTE_NORETURN (__has_attribute(noreturn))
213 # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
214 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
215 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
216  (__has_attribute(warn_unused_result))
217 
218 # define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz))
219 # define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz))
220 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
221 # define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address))
222 # define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount))
223 # define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow))
224 # define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow))
225 # define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow))
226 
227 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas))
228 
229 #elif defined(__GNUC__)
230 
231 # define V8_CC_GNU 1
232 # if defined(__INTEL_COMPILER) // Intel C++ also masquerades as GCC 3.2.0
233 # define V8_CC_INTEL 1
234 # endif
235 # if defined(__MINGW32__)
236 # define V8_CC_MINGW32 1
237 # endif
238 # if defined(__MINGW64__)
239 # define V8_CC_MINGW64 1
240 # endif
241 # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
242 
243 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0))
244 
245 # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0))
246 // always_inline is available in gcc 4.0 but not very reliable until 4.4.
247 // Works around "sorry, unimplemented: inlining failed" build errors with
248 // older compilers.
249 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0))
250 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0))
251 # define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0))
252 # define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0))
253 # define V8_HAS_ATTRIBUTE_NORETURN (V8_GNUC_PREREQ(2, 5, 0))
254 # define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0))
255 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0))
256 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
257  (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0))
258 
259 # define V8_HAS_BUILTIN_CLZ (V8_GNUC_PREREQ(3, 4, 0))
260 # define V8_HAS_BUILTIN_CTZ (V8_GNUC_PREREQ(3, 4, 0))
261 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0))
262 # define V8_HAS_BUILTIN_FRAME_ADDRESS (V8_GNUC_PREREQ(2, 96, 0))
263 # define V8_HAS_BUILTIN_POPCOUNT (V8_GNUC_PREREQ(3, 4, 0))
264 
265 # if __cplusplus >= 201103L
266 # define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0))
267 # define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0))
268 # endif
269 #endif
270 
271 #if defined(_MSC_VER)
272 # define V8_CC_MSVC 1
273 # define V8_HAS___ALIGNOF 1
274 
275 # define V8_HAS_DECLSPEC_ALIGN 1
276 # define V8_HAS_DECLSPEC_DEPRECATED 1
277 # define V8_HAS_DECLSPEC_NOINLINE 1
278 # define V8_HAS_DECLSPEC_SELECTANY 1
279 # define V8_HAS_DECLSPEC_NORETURN 1
280 
281 # define V8_HAS___FORCEINLINE 1
282 
283 #endif
284 
285 
286 // -----------------------------------------------------------------------------
287 // Helper macros
288 
289 // A macro used to make better inlining. Don't bother for debug builds.
290 // Use like:
291 // V8_INLINE int GetZero() { return 0; }
292 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
293 # define V8_INLINE inline __attribute__((always_inline))
294 #elif !defined(DEBUG) && V8_HAS___FORCEINLINE
295 # define V8_INLINE __forceinline
296 #else
297 # define V8_INLINE inline
298 #endif
299 
300 
301 // A macro used to tell the compiler to never inline a particular function.
302 // Don't bother for debug builds.
303 // Use like:
304 // V8_NOINLINE int GetMinusOne() { return -1; }
305 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE
306 # define V8_NOINLINE __attribute__((noinline))
307 #elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE
308 # define V8_NOINLINE __declspec(noinline)
309 #else
310 # define V8_NOINLINE /* NOT SUPPORTED */
311 #endif
312 
313 
314 // A macro used to tell the compiler that a particular function never returns.
315 // Use like:
316 // V8_NORETURN void MyAbort() { abort(); }
317 #if V8_HAS_ATTRIBUTE_NORETURN
318 # define V8_NORETURN __attribute__((noreturn))
319 #elif HAS_DECLSPEC_NORETURN
320 # define V8_NORETURN __declspec(noreturn)
321 #else
322 # define V8_NORETURN /* NOT SUPPORTED */
323 #endif
324 
325 
326 // A macro (V8_DEPRECATED) to mark classes or functions as deprecated.
327 #if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE
328 #define V8_DEPRECATED(message, declarator)
329  declarator __attribute__((deprecated(message)))
330 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED
331 #define V8_DEPRECATED(message, declarator)
332  declarator __attribute__((deprecated))
333 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED
334 #define V8_DEPRECATED(message, declarator) __declspec(deprecated) declarator
335 #else
336 #define V8_DEPRECATED(message, declarator) declarator
337 #endif
338 
339 
340 // A macro (V8_DEPRECATE_SOON) to make it easier to see what will be deprecated.
341 #if defined(V8_IMMINENT_DEPRECATION_WARNINGS) &&
342  V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE
343 #define V8_DEPRECATE_SOON(message, declarator)
344  declarator __attribute__((deprecated(message)))
345 #elif defined(V8_IMMINENT_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED
346 #define V8_DEPRECATE_SOON(message, declarator)
347  declarator __attribute__((deprecated))
348 #elif defined(V8_IMMINENT_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED
349 #define V8_DEPRECATE_SOON(message, declarator) __declspec(deprecated) declarator
350 #else
351 #define V8_DEPRECATE_SOON(message, declarator) declarator
352 #endif
353 
354 
355 // A macro to provide the compiler with branch prediction information.
356 #if V8_HAS_BUILTIN_EXPECT
357 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
358 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1))
359 #else
360 # define V8_UNLIKELY(condition) (condition)
361 # define V8_LIKELY(condition) (condition)
362 #endif
363 
364 
365 // This macro allows to specify memory alignment for structs, classes, etc.
366 // Use like:
367 // class V8_ALIGNED(16) MyClass { ... };
368 // V8_ALIGNED(32) int array[42];
369 #if V8_HAS_CXX11_ALIGNAS
370 # define V8_ALIGNED(n) alignas(n)
371 #elif V8_HAS_ATTRIBUTE_ALIGNED
372 # define V8_ALIGNED(n) __attribute__((aligned(n)))
373 #elif V8_HAS_DECLSPEC_ALIGN
374 # define V8_ALIGNED(n) __declspec(align(n))
375 #else
376 # define V8_ALIGNED(n) /* NOT SUPPORTED */
377 #endif
378 
379 
380 // This macro is similar to V8_ALIGNED(), but takes a type instead of size
381 // in bytes. If the compiler does not supports using the alignment of the
382 // |type|, it will align according to the |alignment| instead. For example,
383 // Visual Studio C++ cannot combine __declspec(align) and __alignof. The
384 // |alignment| must be a literal that is used as a kind of worst-case fallback
385 // alignment.
386 // Use like:
387 // struct V8_ALIGNAS(AnotherClass, 16) NewClass { ... };
388 // V8_ALIGNAS(double, 8) int array[100];
389 #if V8_HAS_CXX11_ALIGNAS
390 # define V8_ALIGNAS(type, alignment) alignas(type)
391 #elif V8_HAS___ALIGNOF__ && V8_HAS_ATTRIBUTE_ALIGNED
392 # define V8_ALIGNAS(type, alignment) __attribute__((aligned(__alignof__(type))))
393 #else
394 # define V8_ALIGNAS(type, alignment) V8_ALIGNED(alignment)
395 #endif
396 
397 
398 // This macro returns alignment in bytes (an integer power of two) required for
399 // any instance of the given type, which is either complete type, an array type,
400 // or a reference type.
401 // Use like:
402 // size_t alignment = V8_ALIGNOF(double);
403 #if V8_HAS_CXX11_ALIGNOF
404 # define V8_ALIGNOF(type) alignof(type)
405 #elif V8_HAS___ALIGNOF
406 # define V8_ALIGNOF(type) __alignof(type)
407 #elif V8_HAS___ALIGNOF__
408 # define V8_ALIGNOF(type) __alignof__(type)
409 #else
410 // Note that alignment of a type within a struct can be less than the
411 // alignment of the type stand-alone (because of ancient ABIs), so this
412 // should only be used as a last resort.
413 namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; }
414 # define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type))
415 #endif
416 
417 // Annotate a function indicating the caller must examine the return value.
418 // Use like:
419 // int foo() WARN_UNUSED_RESULT;
420 #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
421 #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
422 #else
423 #define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */
424 #endif
425 
426 // clang-format on
427 
428 #endif // V8CONFIG_H_