v8  7.9.317 (node 13.2.0)
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 (host)
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 // Operating system detection (target)
127 //
128 // V8_TARGET_OS_ANDROID
129 // V8_TARGET_OS_FUCHSIA
130 // V8_TARGET_OS_IOS
131 // V8_TARGET_OS_LINUX
132 // V8_TARGET_OS_MACOSX
133 // V8_TARGET_OS_WIN
134 //
135 // If not set explicitly, these fall back to corresponding V8_OS_ values.
136 
137 #ifdef V8_HAVE_TARGET_OS
138 
139 // The target OS is provided, just check that at least one known value is set.
140 # if !defined(V8_TARGET_OS_ANDROID)
141  && !defined(V8_TARGET_OS_FUCHSIA)
142  && !defined(V8_TARGET_OS_IOS)
143  && !defined(V8_TARGET_OS_LINUX)
144  && !defined(V8_TARGET_OS_MACOSX)
145  && !defined(V8_TARGET_OS_WIN)
146 # error No known target OS defined.
147 # endif
148 
149 #else // V8_HAVE_TARGET_OS
150 
151 # if defined(V8_TARGET_OS_ANDROID)
152  || defined(V8_TARGET_OS_FUCHSIA)
153  || defined(V8_TARGET_OS_IOS)
154  || defined(V8_TARGET_OS_LINUX)
155  || defined(V8_TARGET_OS_MACOSX)
156  || defined(V8_TARGET_OS_WIN)
157 # error A target OS is defined but V8_HAVE_TARGET_OS is unset.
158 # endif
159 
160 // Fall back to the detected host OS.
161 #ifdef V8_OS_ANDROID
162 # define V8_TARGET_OS_ANDROID
163 #endif
164 
165 #ifdef V8_OS_FUCHSIA
166 # define V8_TARGET_OS_FUCHSIA
167 #endif
168 
169 #ifdef V8_OS_IOS
170 # define V8_TARGET_OS_IOS
171 #endif
172 
173 #ifdef V8_OS_LINUX
174 # define V8_TARGET_OS_LINUX
175 #endif
176 
177 #ifdef V8_OS_MACOSX
178 # define V8_TARGET_OS_MACOSX
179 #endif
180 
181 #ifdef V8_OS_WIN
182 # define V8_TARGET_OS_WIN
183 #endif
184 
185 #endif // V8_HAVE_TARGET_OS
186 
187 // -----------------------------------------------------------------------------
188 // C library detection
189 //
190 // V8_LIBC_MSVCRT - MSVC libc
191 // V8_LIBC_BIONIC - Bionic libc
192 // V8_LIBC_BSD - BSD libc derivate
193 // V8_LIBC_GLIBC - GNU C library
194 // V8_LIBC_UCLIBC - uClibc
195 //
196 // Note that testing for libc must be done using #if not #ifdef. For example,
197 // to test for the GNU C library, use:
198 // #if V8_LIBC_GLIBC
199 // ...
200 // #endif
201 
202 #if defined (_MSC_VER)
203 # define V8_LIBC_MSVCRT 1
204 #elif defined(__BIONIC__)
205 # define V8_LIBC_BIONIC 1
206 # define V8_LIBC_BSD 1
207 #elif defined(__UCLIBC__)
208 // Must test for UCLIBC before GLIBC, as UCLIBC pretends to be GLIBC.
209 # define V8_LIBC_UCLIBC 1
210 #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__)
211 # define V8_LIBC_GLIBC 1
212 #else
213 # define V8_LIBC_BSD V8_OS_BSD
214 #endif
215 
216 
217 // -----------------------------------------------------------------------------
218 // Compiler detection
219 //
220 // V8_CC_GNU - GCC, or clang in gcc mode
221 // V8_CC_INTEL - Intel C++
222 // V8_CC_MINGW - Minimalist GNU for Windows
223 // V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32)
224 // V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64)
225 // V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode
226 //
227 // C++11 feature detection
228 //
229 // Compiler-specific feature detection
230 //
231 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline))
232 // supported
233 // V8_HAS_ATTRIBUTE_NONNULL - __attribute__((nonnull)) supported
234 // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported
235 // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported
236 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported
237 // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
238 // supported
239 // V8_HAS_BUILTIN_BSWAP16 - __builtin_bswap16() supported
240 // V8_HAS_BUILTIN_BSWAP32 - __builtin_bswap32() supported
241 // V8_HAS_BUILTIN_BSWAP64 - __builtin_bswap64() supported
242 // V8_HAS_BUILTIN_CLZ - __builtin_clz() supported
243 // V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported
244 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported
245 // V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported
246 // V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported
247 // V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported
248 // V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported
249 // V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported
250 // V8_HAS_COMPUTED_GOTO - computed goto/labels as values
251 // supported
252 // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported
253 // V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported
254 // V8_HAS___FORCEINLINE - __forceinline supported
255 //
256 // Note that testing for compilers and/or features must be done using #if
257 // not #ifdef. For example, to test for Intel C++ Compiler, use:
258 // #if V8_CC_INTEL
259 // ...
260 // #endif
261 
262 #if defined(__clang__)
263 
264 #if defined(__GNUC__) // Clang in gcc mode.
265 # define V8_CC_GNU 1
266 #endif
267 
268 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
269 # define V8_HAS_ATTRIBUTE_NONNULL (__has_attribute(nonnull))
270 # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
271 # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
272 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
273 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
274  (__has_attribute(warn_unused_result))
275 
276 # define V8_HAS_BUILTIN_ASSUME_ALIGNED (__has_builtin(__builtin_assume_aligned))
277 # define V8_HAS_BUILTIN_BSWAP16 (__has_builtin(__builtin_bswap16))
278 # define V8_HAS_BUILTIN_BSWAP32 (__has_builtin(__builtin_bswap32))
279 # define V8_HAS_BUILTIN_BSWAP64 (__has_builtin(__builtin_bswap64))
280 # define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz))
281 # define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz))
282 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
283 # define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address))
284 # define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount))
285 # define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow))
286 # define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow))
287 # define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow))
288 
289 // Clang has no __has_feature for computed gotos.
290 // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
291 # define V8_HAS_COMPUTED_GOTO 1
292 
293 # if __cplusplus >= 201402L
294 # define V8_CAN_HAVE_DCHECK_IN_CONSTEXPR 1
295 # endif
296 
297 #elif defined(__GNUC__)
298 
299 # define V8_CC_GNU 1
300 # if defined(__INTEL_COMPILER) // Intel C++ also masquerades as GCC 3.2.0
301 # define V8_CC_INTEL 1
302 # endif
303 # if defined(__MINGW32__)
304 # define V8_CC_MINGW32 1
305 # endif
306 # if defined(__MINGW64__)
307 # define V8_CC_MINGW64 1
308 # endif
309 # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
310 
311 // always_inline is available in gcc 4.0 but not very reliable until 4.4.
312 // Works around "sorry, unimplemented: inlining failed" build errors with
313 // older compilers.
314 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0))
315 # define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0))
316 # define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0))
317 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0))
318 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
319  (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0))
320 
321 # define V8_HAS_BUILTIN_ASSUME_ALIGNED (V8_GNUC_PREREQ(4, 7, 0))
322 # define V8_HAS_BUILTIN_CLZ (V8_GNUC_PREREQ(3, 4, 0))
323 # define V8_HAS_BUILTIN_CTZ (V8_GNUC_PREREQ(3, 4, 0))
324 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0))
325 # define V8_HAS_BUILTIN_FRAME_ADDRESS (V8_GNUC_PREREQ(2, 96, 0))
326 # define V8_HAS_BUILTIN_POPCOUNT (V8_GNUC_PREREQ(3, 4, 0))
327 
328 // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
329 #define V8_HAS_COMPUTED_GOTO (V8_GNUC_PREREQ(2, 0, 0))
330 
331 #endif
332 
333 #if defined(_MSC_VER)
334 # define V8_CC_MSVC 1
335 
336 # define V8_HAS_DECLSPEC_NOINLINE 1
337 # define V8_HAS_DECLSPEC_SELECTANY 1
338 
339 # define V8_HAS___FORCEINLINE 1
340 
341 #endif
342 
343 
344 // -----------------------------------------------------------------------------
345 // Helper macros
346 
347 // A macro used to make better inlining. Don't bother for debug builds.
348 // Use like:
349 // V8_INLINE int GetZero() { return 0; }
350 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
351 # define V8_INLINE inline __attribute__((always_inline))
352 #elif !defined(DEBUG) && V8_HAS___FORCEINLINE
353 # define V8_INLINE __forceinline
354 #else
355 # define V8_INLINE inline
356 #endif
357 
358 #if V8_HAS_BUILTIN_ASSUME_ALIGNED
359 # define V8_ASSUME_ALIGNED(ptr, alignment)
360  __builtin_assume_aligned((ptr), (alignment))
361 #else
362 # define V8_ASSUME_ALIGNED(ptr, alignment) (ptr)
363 #endif
364 
365 
366 // A macro to mark specific arguments as non-null.
367 // Use like:
368 // int add(int* x, int y, int* z) V8_NONNULL(1, 3) { return *x + y + *z; }
369 #if V8_HAS_ATTRIBUTE_NONNULL
370 # define V8_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
371 #else
372 # define V8_NONNULL(...) /* NOT SUPPORTED */
373 #endif
374 
375 
376 // A macro used to tell the compiler to never inline a particular function.
377 // Don't bother for debug builds.
378 // Use like:
379 // V8_NOINLINE int GetMinusOne() { return -1; }
380 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE
381 # define V8_NOINLINE __attribute__((noinline))
382 #elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE
383 # define V8_NOINLINE __declspec(noinline)
384 #else
385 # define V8_NOINLINE /* NOT SUPPORTED */
386 #endif
387 
388 
389 // A macro (V8_DEPRECATED) to mark classes or functions as deprecated.
390 #if defined(V8_DEPRECATION_WARNINGS)
391 # define V8_DEPRECATED(message) [[deprecated(message)]]
392 #else
393 # define V8_DEPRECATED(message)
394 #endif
395 
396 
397 // A macro (V8_DEPRECATE_SOON) to make it easier to see what will be deprecated.
398 #if defined(V8_IMMINENT_DEPRECATION_WARNINGS)
399 # define V8_DEPRECATE_SOON(message) [[deprecated(message)]]
400 #else
401 # define V8_DEPRECATE_SOON(message)
402 #endif
403 
404 
405 // A macro to provide the compiler with branch prediction information.
406 #if V8_HAS_BUILTIN_EXPECT
407 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
408 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1))
409 #else
410 # define V8_UNLIKELY(condition) (condition)
411 # define V8_LIKELY(condition) (condition)
412 #endif
413 
414 
415 // Annotate a function indicating the caller must examine the return value.
416 // Use like:
417 // int foo() V8_WARN_UNUSED_RESULT;
418 #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
419 #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
420 #else
421 #define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */
422 #endif
423 
424 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
425 #error Inconsistent build configuration: To build the V8 shared library set
426  BUILDING_V8_SHARED, to include its headers for linking against the V8
427  shared library set USING_V8_SHARED.
428 #endif
429 
430 #ifdef V8_OS_WIN
431 
432 // Setup for Windows DLL export/import. When building the V8 DLL the
433 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
434 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
435 // static library or building a program which uses the V8 static library neither
436 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
437 #ifdef BUILDING_V8_SHARED
438 # define V8_EXPORT __declspec(dllexport)
439 #elif USING_V8_SHARED
440 # define V8_EXPORT __declspec(dllimport)
441 #else
442 # define V8_EXPORT
443 #endif // BUILDING_V8_SHARED
444 
445 #else // V8_OS_WIN
446 
447 // Setup for Linux shared library export.
448 #if V8_HAS_ATTRIBUTE_VISIBILITY
449 # ifdef BUILDING_V8_SHARED
450 # define V8_EXPORT __attribute__ ((visibility("default")))
451 # else
452 # define V8_EXPORT
453 # endif
454 #else
455 # define V8_EXPORT
456 #endif
457 
458 #endif // V8_OS_WIN
459 
460 // clang-format on
461 
462 #endif // V8CONFIG_H_