v8  7.8.279 (node 12.19.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_FUCHSIA - Fuchsia
65 // V8_OS_LINUX - Linux
66 // V8_OS_MACOSX - Mac OS X
67 // V8_OS_IOS - iOS
68 // V8_OS_NETBSD - NetBSD
69 // V8_OS_OPENBSD - OpenBSD
70 // V8_OS_POSIX - POSIX compatible (mostly everything except Windows)
71 // V8_OS_QNX - QNX Neutrino
72 // V8_OS_SOLARIS - Sun Solaris and OpenSolaris
73 // V8_OS_AIX - AIX
74 // V8_OS_WIN - Microsoft Windows
75 
76 #if defined(__ANDROID__)
77 # define V8_OS_ANDROID 1
78 # define V8_OS_LINUX 1
79 # define V8_OS_POSIX 1
80 #elif defined(__APPLE__)
81 # define V8_OS_BSD 1
82 # define V8_OS_MACOSX 1
83 # define V8_OS_POSIX 1
84 # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
85 # define V8_OS_IOS 1
86 # endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
87 #elif defined(__CYGWIN__)
88 # define V8_OS_CYGWIN 1
89 # define V8_OS_POSIX 1
90 #elif defined(__linux__)
91 # define V8_OS_LINUX 1
92 # define V8_OS_POSIX 1
93 #elif defined(__sun)
94 # define V8_OS_POSIX 1
95 # define V8_OS_SOLARIS 1
96 #elif defined(_AIX)
97 #define V8_OS_POSIX 1
98 #define V8_OS_AIX 1
99 #elif defined(__FreeBSD__)
100 # define V8_OS_BSD 1
101 # define V8_OS_FREEBSD 1
102 # define V8_OS_POSIX 1
103 #elif defined(__Fuchsia__)
104 # define V8_OS_FUCHSIA 1
105 # define V8_OS_POSIX 1
106 #elif defined(__DragonFly__)
107 # define V8_OS_BSD 1
108 # define V8_OS_DRAGONFLYBSD 1
109 # define V8_OS_POSIX 1
110 #elif defined(__NetBSD__)
111 # define V8_OS_BSD 1
112 # define V8_OS_NETBSD 1
113 # define V8_OS_POSIX 1
114 #elif defined(__OpenBSD__)
115 # define V8_OS_BSD 1
116 # define V8_OS_OPENBSD 1
117 # define V8_OS_POSIX 1
118 #elif defined(__QNXNTO__)
119 # define V8_OS_POSIX 1
120 # define V8_OS_QNX 1
121 #elif defined(_WIN32)
122 # define V8_OS_WIN 1
123 #endif
124 
125 
126 // -----------------------------------------------------------------------------
127 // C library detection
128 //
129 // V8_LIBC_MSVCRT - MSVC libc
130 // V8_LIBC_BIONIC - Bionic libc
131 // V8_LIBC_BSD - BSD libc derivate
132 // V8_LIBC_GLIBC - GNU C library
133 // V8_LIBC_UCLIBC - uClibc
134 //
135 // Note that testing for libc must be done using #if not #ifdef. For example,
136 // to test for the GNU C library, use:
137 // #if V8_LIBC_GLIBC
138 // ...
139 // #endif
140 
141 #if defined (_MSC_VER)
142 # define V8_LIBC_MSVCRT 1
143 #elif defined(__BIONIC__)
144 # define V8_LIBC_BIONIC 1
145 # define V8_LIBC_BSD 1
146 #elif defined(__UCLIBC__)
147 // Must test for UCLIBC before GLIBC, as UCLIBC pretends to be GLIBC.
148 # define V8_LIBC_UCLIBC 1
149 #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__)
150 # define V8_LIBC_GLIBC 1
151 #else
152 # define V8_LIBC_BSD V8_OS_BSD
153 #endif
154 
155 
156 // -----------------------------------------------------------------------------
157 // Compiler detection
158 //
159 // V8_CC_GNU - GCC, or clang in gcc mode
160 // V8_CC_INTEL - Intel C++
161 // V8_CC_MINGW - Minimalist GNU for Windows
162 // V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32)
163 // V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64)
164 // V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode
165 //
166 // C++11 feature detection
167 //
168 // Compiler-specific feature detection
169 //
170 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline))
171 // supported
172 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported
173 // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported
174 // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported
175 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported
176 // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
177 // supported
178 // V8_HAS_BUILTIN_BSWAP16 - __builtin_bswap16() supported
179 // V8_HAS_BUILTIN_BSWAP32 - __builtin_bswap32() supported
180 // V8_HAS_BUILTIN_BSWAP64 - __builtin_bswap64() supported
181 // V8_HAS_BUILTIN_CLZ - __builtin_clz() supported
182 // V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported
183 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported
184 // V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported
185 // V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported
186 // V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported
187 // V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported
188 // V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported
189 // V8_HAS_COMPUTED_GOTO - computed goto/labels as values
190 // supported
191 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported
192 // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported
193 // V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported
194 // V8_HAS_DECLSPEC_NORETURN - __declspec(noreturn) supported
195 // V8_HAS___FORCEINLINE - __forceinline supported
196 //
197 // Note that testing for compilers and/or features must be done using #if
198 // not #ifdef. For example, to test for Intel C++ Compiler, use:
199 // #if V8_CC_INTEL
200 // ...
201 // #endif
202 
203 #if defined(__clang__)
204 
205 #if defined(__GNUC__) // Clang in gcc mode.
206 # define V8_CC_GNU 1
207 #endif
208 
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_DEPRECATED_MESSAGE
212  (__has_extension(attribute_deprecated_with_message))
213 # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
214 # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
215 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
216 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
217  (__has_attribute(warn_unused_result))
218 
219 # define V8_HAS_BUILTIN_ASSUME_ALIGNED (__has_builtin(__builtin_assume_aligned))
220 # define V8_HAS_BUILTIN_BSWAP16 (__has_builtin(__builtin_bswap16))
221 # define V8_HAS_BUILTIN_BSWAP32 (__has_builtin(__builtin_bswap32))
222 # define V8_HAS_BUILTIN_BSWAP64 (__has_builtin(__builtin_bswap64))
223 # define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz))
224 # define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz))
225 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
226 # define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address))
227 # define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount))
228 # define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow))
229 # define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow))
230 # define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow))
231 
232 // Clang has no __has_feature for computed gotos.
233 // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
234 # define V8_HAS_COMPUTED_GOTO 1
235 
236 # if __cplusplus >= 201402L
237 # define V8_CAN_HAVE_DCHECK_IN_CONSTEXPR 1
238 # endif
239 
240 #elif defined(__GNUC__)
241 
242 # define V8_CC_GNU 1
243 # if defined(__INTEL_COMPILER) // Intel C++ also masquerades as GCC 3.2.0
244 # define V8_CC_INTEL 1
245 # endif
246 # if defined(__MINGW32__)
247 # define V8_CC_MINGW32 1
248 # endif
249 # if defined(__MINGW64__)
250 # define V8_CC_MINGW64 1
251 # endif
252 # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
253 
254 // always_inline is available in gcc 4.0 but not very reliable until 4.4.
255 // Works around "sorry, unimplemented: inlining failed" build errors with
256 // older compilers.
257 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0))
258 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0))
259 # define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0))
260 # define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0))
261 # define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0))
262 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0))
263 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
264  (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0))
265 
266 # define V8_HAS_BUILTIN_ASSUME_ALIGNED (V8_GNUC_PREREQ(4, 7, 0))
267 # define V8_HAS_BUILTIN_CLZ (V8_GNUC_PREREQ(3, 4, 0))
268 # define V8_HAS_BUILTIN_CTZ (V8_GNUC_PREREQ(3, 4, 0))
269 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0))
270 # define V8_HAS_BUILTIN_FRAME_ADDRESS (V8_GNUC_PREREQ(2, 96, 0))
271 # define V8_HAS_BUILTIN_POPCOUNT (V8_GNUC_PREREQ(3, 4, 0))
272 
273 // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
274 #define V8_HAS_COMPUTED_GOTO (V8_GNUC_PREREQ(2, 0, 0))
275 
276 #endif
277 
278 #if defined(_MSC_VER)
279 # define V8_CC_MSVC 1
280 
281 # define V8_HAS_DECLSPEC_DEPRECATED 1
282 # define V8_HAS_DECLSPEC_NOINLINE 1
283 # define V8_HAS_DECLSPEC_SELECTANY 1
284 # define V8_HAS_DECLSPEC_NORETURN 1
285 
286 # define V8_HAS___FORCEINLINE 1
287 
288 #endif
289 
290 
291 // -----------------------------------------------------------------------------
292 // Helper macros
293 
294 // A macro used to make better inlining. Don't bother for debug builds.
295 // Use like:
296 // V8_INLINE int GetZero() { return 0; }
297 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
298 # define V8_INLINE inline __attribute__((always_inline))
299 #elif !defined(DEBUG) && V8_HAS___FORCEINLINE
300 # define V8_INLINE __forceinline
301 #else
302 # define V8_INLINE inline
303 #endif
304 
305 #if V8_HAS_BUILTIN_ASSUME_ALIGNED
306 # define V8_ASSUME_ALIGNED(ptr, alignment)
307  __builtin_assume_aligned((ptr), (alignment))
308 #else
309 # define V8_ASSUME_ALIGNED(ptr) (ptr)
310 #endif
311 
312 // A macro used to tell the compiler to never inline a particular function.
313 // Don't bother for debug builds.
314 // Use like:
315 // V8_NOINLINE int GetMinusOne() { return -1; }
316 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE
317 # define V8_NOINLINE __attribute__((noinline))
318 #elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE
319 # define V8_NOINLINE __declspec(noinline)
320 #else
321 # define V8_NOINLINE /* NOT SUPPORTED */
322 #endif
323 
324 
325 // A macro (V8_DEPRECATED) to mark classes or functions as deprecated.
326 #if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE
327 #define V8_DEPRECATED(message, declarator)
328  declarator __attribute__((deprecated(message)))
329 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED
330 #define V8_DEPRECATED(message, declarator)
331  declarator __attribute__((deprecated))
332 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED
333 #define V8_DEPRECATED(message, declarator) __declspec(deprecated) declarator
334 #else
335 #define V8_DEPRECATED(message, declarator) declarator
336 #endif
337 
338 
339 // A macro (V8_DEPRECATE_SOON) to make it easier to see what will be deprecated.
340 #if defined(V8_IMMINENT_DEPRECATION_WARNINGS) &&
341  V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE
342 #define V8_DEPRECATE_SOON(message, declarator)
343  declarator __attribute__((deprecated(message)))
344 #elif defined(V8_IMMINENT_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED
345 #define V8_DEPRECATE_SOON(message, declarator)
346  declarator __attribute__((deprecated))
347 #elif defined(V8_IMMINENT_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED
348 #define V8_DEPRECATE_SOON(message, declarator) __declspec(deprecated) declarator
349 #else
350 #define V8_DEPRECATE_SOON(message, declarator) declarator
351 #endif
352 
353 
354 // A macro to provide the compiler with branch prediction information.
355 #if V8_HAS_BUILTIN_EXPECT
356 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
357 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1))
358 #else
359 # define V8_UNLIKELY(condition) (condition)
360 # define V8_LIKELY(condition) (condition)
361 #endif
362 
363 
364 // Annotate a function indicating the caller must examine the return value.
365 // Use like:
366 // int foo() V8_WARN_UNUSED_RESULT;
367 #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
368 #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
369 #else
370 #define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */
371 #endif
372 
373 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
374 #error Inconsistent build configuration: To build the V8 shared library set
375  BUILDING_V8_SHARED, to include its headers for linking against the V8
376  shared library set USING_V8_SHARED.
377 #endif
378 
379 #ifdef V8_OS_WIN
380 
381 // Setup for Windows DLL export/import. When building the V8 DLL the
382 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
383 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
384 // static library or building a program which uses the V8 static library neither
385 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
386 #ifdef BUILDING_V8_SHARED
387 # define V8_EXPORT __declspec(dllexport)
388 #elif USING_V8_SHARED
389 # define V8_EXPORT __declspec(dllimport)
390 #else
391 # define V8_EXPORT
392 #endif // BUILDING_V8_SHARED
393 
394 #else // V8_OS_WIN
395 
396 // Setup for Linux shared library export.
397 #if V8_HAS_ATTRIBUTE_VISIBILITY
398 # ifdef BUILDING_V8_SHARED
399 # define V8_EXPORT __attribute__ ((visibility("default")))
400 # else
401 # define V8_EXPORT
402 # endif
403 #else
404 # define V8_EXPORT
405 #endif
406 
407 #endif // V8_OS_WIN
408 
409 // clang-format on
410 
411 #endif // V8CONFIG_H_