v8  9.0.257(node16.0.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 #ifdef V8_GN_HEADER
9 #if __cplusplus >= 201703L && !__has_include("v8-gn.h")
10 #error Missing v8-gn.h. The configuration for v8 is missing from the include path
11  . Add it with -I<path> to the command line
12 #endif
13 #include "v8-gn.h" // NOLINT(build/include_directory)
14 #endif
15 
16 // clang-format off
17 
18 // Platform headers for feature detection below.
19 #if defined(__ANDROID__)
20 # include <sys/cdefs.h>
21 #elif defined(__APPLE__)
22 # include <TargetConditionals.h>
23 #elif defined(__linux__)
24 # include <features.h>
25 #endif
26 
27 
28 // This macro allows to test for the version of the GNU C library (or
29 // a compatible C library that masquerades as glibc). It evaluates to
30 // 0 if libc is not GNU libc or compatible.
31 // Use like:
32 // #if V8_GLIBC_PREREQ(2, 3)
33 // ...
34 // #endif
35 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
36 # define V8_GLIBC_PREREQ(major, minor)
37  ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor)))
38 #else
39 # define V8_GLIBC_PREREQ(major, minor) 0
40 #endif
41 
42 
43 // This macro allows to test for the version of the GNU C++ compiler.
44 // Note that this also applies to compilers that masquerade as GCC,
45 // for example clang and the Intel C++ compiler for Linux.
46 // Use like:
47 // #if V8_GNUC_PREREQ(4, 3, 1)
48 // ...
49 // #endif
50 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
51 # define V8_GNUC_PREREQ(major, minor, patchlevel)
52  ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >=
53  ((major) * 10000 + (minor) * 100 + (patchlevel)))
54 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
55 # define V8_GNUC_PREREQ(major, minor, patchlevel)
56  ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >=
57  ((major) * 10000 + (minor) * 100 + (patchlevel)))
58 #else
59 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0
60 #endif
61 
62 
63 
64 // -----------------------------------------------------------------------------
65 // Operating system detection (host)
66 //
67 // V8_OS_ANDROID - Android
68 // V8_OS_BSD - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD)
69 // V8_OS_CYGWIN - Cygwin
70 // V8_OS_DRAGONFLYBSD - DragonFlyBSD
71 // V8_OS_FREEBSD - FreeBSD
72 // V8_OS_FUCHSIA - Fuchsia
73 // V8_OS_LINUX - Linux
74 // V8_OS_MACOSX - Mac OS X
75 // V8_OS_IOS - iOS
76 // V8_OS_NETBSD - NetBSD
77 // V8_OS_OPENBSD - OpenBSD
78 // V8_OS_POSIX - POSIX compatible (mostly everything except Windows)
79 // V8_OS_QNX - QNX Neutrino
80 // V8_OS_SOLARIS - Sun Solaris and OpenSolaris
81 // V8_OS_STARBOARD - Starboard (platform abstraction for Cobalt)
82 // V8_OS_AIX - AIX
83 // V8_OS_WIN - Microsoft Windows
84 
85 #if defined(__ANDROID__)
86 # define V8_OS_ANDROID 1
87 # define V8_OS_LINUX 1
88 # define V8_OS_POSIX 1
89 #elif defined(__APPLE__)
90 # define V8_OS_BSD 1
91 # define V8_OS_MACOSX 1
92 # define V8_OS_POSIX 1
93 # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
94 # define V8_OS_IOS 1
95 # endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
96 #elif defined(__CYGWIN__)
97 # define V8_OS_CYGWIN 1
98 # define V8_OS_POSIX 1
99 #elif defined(__linux__)
100 # define V8_OS_LINUX 1
101 # define V8_OS_POSIX 1
102 #elif defined(__sun)
103 # define V8_OS_POSIX 1
104 # define V8_OS_SOLARIS 1
105 #elif defined(STARBOARD)
106 # define V8_OS_STARBOARD 1
107 #elif defined(_AIX)
108 #define V8_OS_POSIX 1
109 #define V8_OS_AIX 1
110 #elif defined(__FreeBSD__)
111 # define V8_OS_BSD 1
112 # define V8_OS_FREEBSD 1
113 # define V8_OS_POSIX 1
114 #elif defined(__Fuchsia__)
115 # define V8_OS_FUCHSIA 1
116 # define V8_OS_POSIX 1
117 #elif defined(__DragonFly__)
118 # define V8_OS_BSD 1
119 # define V8_OS_DRAGONFLYBSD 1
120 # define V8_OS_POSIX 1
121 #elif defined(__NetBSD__)
122 # define V8_OS_BSD 1
123 # define V8_OS_NETBSD 1
124 # define V8_OS_POSIX 1
125 #elif defined(__OpenBSD__)
126 # define V8_OS_BSD 1
127 # define V8_OS_OPENBSD 1
128 # define V8_OS_POSIX 1
129 #elif defined(__QNXNTO__)
130 # define V8_OS_POSIX 1
131 # define V8_OS_QNX 1
132 #elif defined(_WIN32)
133 # define V8_OS_WIN 1
134 #endif
135 
136 // -----------------------------------------------------------------------------
137 // Operating system detection (target)
138 //
139 // V8_TARGET_OS_ANDROID
140 // V8_TARGET_OS_FUCHSIA
141 // V8_TARGET_OS_IOS
142 // V8_TARGET_OS_LINUX
143 // V8_TARGET_OS_MACOSX
144 // V8_TARGET_OS_WIN
145 //
146 // If not set explicitly, these fall back to corresponding V8_OS_ values.
147 
148 #ifdef V8_HAVE_TARGET_OS
149 
150 // The target OS is provided, just check that at least one known value is set.
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 No known target OS defined.
158 # endif
159 
160 #else // V8_HAVE_TARGET_OS
161 
162 # if defined(V8_TARGET_OS_ANDROID)
163  || defined(V8_TARGET_OS_FUCHSIA)
164  || defined(V8_TARGET_OS_IOS)
165  || defined(V8_TARGET_OS_LINUX)
166  || defined(V8_TARGET_OS_MACOSX)
167  || defined(V8_TARGET_OS_WIN)
168 # error A target OS is defined but V8_HAVE_TARGET_OS is unset.
169 # endif
170 
171 // Fall back to the detected host OS.
172 #ifdef V8_OS_ANDROID
173 # define V8_TARGET_OS_ANDROID
174 #endif
175 
176 #ifdef V8_OS_FUCHSIA
177 # define V8_TARGET_OS_FUCHSIA
178 #endif
179 
180 #ifdef V8_OS_IOS
181 # define V8_TARGET_OS_IOS
182 #endif
183 
184 #ifdef V8_OS_LINUX
185 # define V8_TARGET_OS_LINUX
186 #endif
187 
188 #ifdef V8_OS_MACOSX
189 # define V8_TARGET_OS_MACOSX
190 #endif
191 
192 #ifdef V8_OS_WIN
193 # define V8_TARGET_OS_WIN
194 #endif
195 
196 #endif // V8_HAVE_TARGET_OS
197 
198 // -----------------------------------------------------------------------------
199 // C library detection
200 //
201 // V8_LIBC_MSVCRT - MSVC libc
202 // V8_LIBC_BIONIC - Bionic libc
203 // V8_LIBC_BSD - BSD libc derivate
204 // V8_LIBC_GLIBC - GNU C library
205 // V8_LIBC_UCLIBC - uClibc
206 //
207 // Note that testing for libc must be done using #if not #ifdef. For example,
208 // to test for the GNU C library, use:
209 // #if V8_LIBC_GLIBC
210 // ...
211 // #endif
212 
213 #if defined (_MSC_VER)
214 # define V8_LIBC_MSVCRT 1
215 #elif defined(__BIONIC__)
216 # define V8_LIBC_BIONIC 1
217 # define V8_LIBC_BSD 1
218 #elif defined(__UCLIBC__)
219 // Must test for UCLIBC before GLIBC, as UCLIBC pretends to be GLIBC.
220 # define V8_LIBC_UCLIBC 1
221 #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__)
222 # define V8_LIBC_GLIBC 1
223 #else
224 # define V8_LIBC_BSD V8_OS_BSD
225 #endif
226 
227 
228 // -----------------------------------------------------------------------------
229 // Compiler detection
230 //
231 // V8_CC_GNU - GCC, or clang in gcc mode
232 // V8_CC_INTEL - Intel C++
233 // V8_CC_MINGW - Minimalist GNU for Windows
234 // V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32)
235 // V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64)
236 // V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode
237 //
238 // C++11 feature detection
239 //
240 // Compiler-specific feature detection
241 //
242 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline))
243 // supported
244 // V8_HAS_ATTRIBUTE_NONNULL - __attribute__((nonnull)) supported
245 // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported
246 // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported
247 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported
248 // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
249 // supported
250 // V8_HAS_CPP_ATTRIBUTE_NODISCARD - [[nodiscard]] supported
251 // V8_HAS_BUILTIN_BSWAP16 - __builtin_bswap16() supported
252 // V8_HAS_BUILTIN_BSWAP32 - __builtin_bswap32() supported
253 // V8_HAS_BUILTIN_BSWAP64 - __builtin_bswap64() supported
254 // V8_HAS_BUILTIN_CLZ - __builtin_clz() supported
255 // V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported
256 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported
257 // V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported
258 // V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported
259 // V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported
260 // V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported
261 // V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported
262 // V8_HAS_COMPUTED_GOTO - computed goto/labels as values
263 // supported
264 // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported
265 // V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported
266 // V8_HAS___FORCEINLINE - __forceinline supported
267 //
268 // Note that testing for compilers and/or features must be done using #if
269 // not #ifdef. For example, to test for Intel C++ Compiler, use:
270 // #if V8_CC_INTEL
271 // ...
272 // #endif
273 
274 #if defined(__has_cpp_attribute)
275 #define V8_HAS_CPP_ATTRIBUTE(FEATURE) __has_cpp_attribute(FEATURE)
276 #else
277 #define V8_HAS_CPP_ATTRIBUTE(FEATURE) 0
278 #endif
279 
280 #if defined(__clang__)
281 
282 #if defined(__GNUC__) // Clang in gcc mode.
283 # define V8_CC_GNU 1
284 #endif
285 
286 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
287 # define V8_HAS_ATTRIBUTE_NONNULL (__has_attribute(nonnull))
288 # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
289 # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
290 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
291 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
292  (__has_attribute(warn_unused_result))
293 
294 # define V8_HAS_CPP_ATTRIBUTE_NODISCARD (V8_HAS_CPP_ATTRIBUTE(nodiscard))
295 
296 # define V8_HAS_BUILTIN_ASSUME_ALIGNED (__has_builtin(__builtin_assume_aligned))
297 # define V8_HAS_BUILTIN_BSWAP16 (__has_builtin(__builtin_bswap16))
298 # define V8_HAS_BUILTIN_BSWAP32 (__has_builtin(__builtin_bswap32))
299 # define V8_HAS_BUILTIN_BSWAP64 (__has_builtin(__builtin_bswap64))
300 # define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz))
301 # define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz))
302 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
303 # define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address))
304 # define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount))
305 # define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow))
306 # define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow))
307 # define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow))
308 
309 // Clang has no __has_feature for computed gotos.
310 // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
311 # define V8_HAS_COMPUTED_GOTO 1
312 
313 // Whether constexpr has full C++14 semantics, in particular that non-constexpr
314 // code is allowed as long as it's not executed for any constexpr instantiation.
315 # define V8_HAS_CXX14_CONSTEXPR 1
316 
317 #elif defined(__GNUC__)
318 
319 # define V8_CC_GNU 1
320 # if defined(__INTEL_COMPILER) // Intel C++ also masquerades as GCC 3.2.0
321 # define V8_CC_INTEL 1
322 # endif
323 # if defined(__MINGW32__)
324 # define V8_CC_MINGW32 1
325 # endif
326 # if defined(__MINGW64__)
327 # define V8_CC_MINGW64 1
328 # endif
329 # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
330 
331 // always_inline is available in gcc 4.0 but not very reliable until 4.4.
332 // Works around "sorry, unimplemented: inlining failed" build errors with
333 // older compilers.
334 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE 1
335 # define V8_HAS_ATTRIBUTE_NOINLINE 1
336 # define V8_HAS_ATTRIBUTE_UNUSED 1
337 # define V8_HAS_ATTRIBUTE_VISIBILITY 1
338 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT (!V8_CC_INTEL)
339 # define V8_HAS_CPP_ATTRIBUTE_NODISCARD (V8_HAS_CPP_ATTRIBUTE(nodiscard))
340 
341 # define V8_HAS_BUILTIN_ASSUME_ALIGNED 1
342 # define V8_HAS_BUILTIN_CLZ 1
343 # define V8_HAS_BUILTIN_CTZ 1
344 # define V8_HAS_BUILTIN_EXPECT 1
345 # define V8_HAS_BUILTIN_FRAME_ADDRESS 1
346 # define V8_HAS_BUILTIN_POPCOUNT 1
347 
348 // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
349 #define V8_HAS_COMPUTED_GOTO 1
350 
351 // Whether constexpr has full C++14 semantics, in particular that non-constexpr
352 // code is allowed as long as it's not executed for any constexpr instantiation.
353 // GCC only supports this since version 6.
354 # define V8_HAS_CXX14_CONSTEXPR (V8_GNUC_PREREQ(6, 0, 0))
355 
356 #endif
357 
358 #if defined(_MSC_VER)
359 # define V8_CC_MSVC 1
360 
361 # define V8_HAS_DECLSPEC_NOINLINE 1
362 # define V8_HAS_DECLSPEC_SELECTANY 1
363 
364 # define V8_HAS___FORCEINLINE 1
365 
366 #endif
367 
368 
369 // -----------------------------------------------------------------------------
370 // Helper macros
371 
372 // A macro used to make better inlining. Don't bother for debug builds.
373 // Use like:
374 // V8_INLINE int GetZero() { return 0; }
375 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
376 # define V8_INLINE inline __attribute__((always_inline))
377 #elif !defined(DEBUG) && V8_HAS___FORCEINLINE
378 # define V8_INLINE __forceinline
379 #else
380 # define V8_INLINE inline
381 #endif
382 
383 #if V8_HAS_BUILTIN_ASSUME_ALIGNED
384 # define V8_ASSUME_ALIGNED(ptr, alignment)
385  __builtin_assume_aligned((ptr), (alignment))
386 #else
387 # define V8_ASSUME_ALIGNED(ptr, alignment) (ptr)
388 #endif
389 
390 
391 // A macro to mark specific arguments as non-null.
392 // Use like:
393 // int add(int* x, int y, int* z) V8_NONNULL(1, 3) { return *x + y + *z; }
394 #if V8_HAS_ATTRIBUTE_NONNULL
395 # define V8_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
396 #else
397 # define V8_NONNULL(...) /* NOT SUPPORTED */
398 #endif
399 
400 
401 // A macro used to tell the compiler to never inline a particular function.
402 // Use like:
403 // V8_NOINLINE int GetMinusOne() { return -1; }
404 #if V8_HAS_ATTRIBUTE_NOINLINE
405 # define V8_NOINLINE __attribute__((noinline))
406 #elif V8_HAS_DECLSPEC_NOINLINE
407 # define V8_NOINLINE __declspec(noinline)
408 #else
409 # define V8_NOINLINE /* NOT SUPPORTED */
410 #endif
411 
412 
413 // A macro (V8_DEPRECATED) to mark classes or functions as deprecated.
414 #if defined(V8_DEPRECATION_WARNINGS)
415 # define V8_DEPRECATED(message) [[deprecated(message)]]
416 #else
417 # define V8_DEPRECATED(message)
418 #endif
419 
420 
421 // A macro (V8_DEPRECATE_SOON) to make it easier to see what will be deprecated.
422 #if defined(V8_IMMINENT_DEPRECATION_WARNINGS)
423 # define V8_DEPRECATE_SOON(message) [[deprecated(message)]]
424 #else
425 # define V8_DEPRECATE_SOON(message)
426 #endif
427 
428 
429 #if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 6)
430 # define V8_ENUM_DEPRECATED(message)
431 # define V8_ENUM_DEPRECATE_SOON(message)
432 #else
433 # define V8_ENUM_DEPRECATED(message) V8_DEPRECATED(message)
434 # define V8_ENUM_DEPRECATE_SOON(message) V8_DEPRECATE_SOON(message)
435 #endif
436 
437 
438 // A macro to provide the compiler with branch prediction information.
439 #if V8_HAS_BUILTIN_EXPECT
440 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
441 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1))
442 #else
443 # define V8_UNLIKELY(condition) (condition)
444 # define V8_LIKELY(condition) (condition)
445 #endif
446 
447 
448 // Annotate a function indicating the caller must examine the return value.
449 // Use like:
450 // int foo() V8_WARN_UNUSED_RESULT;
451 #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
452 #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
453 #else
454 #define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */
455 #endif
456 
457 
458 // Annotate a class or constructor indicating the caller must assign the
459 // constructed instances.
460 // Apply to the whole class like:
461 // class V8_NODISCARD Foo() { ... };
462 // or apply to just one constructor like:
463 // V8_NODISCARD Foo() { ... };
464 // [[nodiscard]] comes in C++17 but supported in clang with -std >= c++11.
465 #if V8_HAS_CPP_ATTRIBUTE_NODISCARD
466 #define V8_NODISCARD [[nodiscard]]
467 #else
468 #define V8_NODISCARD /* NOT SUPPORTED */
469 #endif
470 
471 // Helper macro to define no_sanitize attributes only with clang.
472 #if defined(__clang__) && defined(__has_attribute)
473 #if __has_attribute(no_sanitize)
474 #define V8_CLANG_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
475 #endif
476 #endif
477 #if !defined(V8_CLANG_NO_SANITIZE)
478 #define V8_CLANG_NO_SANITIZE(what)
479 #endif
480 
481 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
482 #error Inconsistent build configuration: To build the V8 shared library set
483  BUILDING_V8_SHARED, to include its headers for linking against the V8
484  shared library set USING_V8_SHARED.
485 #endif
486 
487 #ifdef V8_OS_WIN
488 
489 // Setup for Windows DLL export/import. When building the V8 DLL the
490 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
491 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
492 // static library or building a program which uses the V8 static library neither
493 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
494 #ifdef BUILDING_V8_SHARED
495 # define V8_EXPORT __declspec(dllexport)
496 #elif USING_V8_SHARED
497 # define V8_EXPORT __declspec(dllimport)
498 #else
499 # define V8_EXPORT
500 #endif // BUILDING_V8_SHARED
501 
502 #else // V8_OS_WIN
503 
504 // Setup for Linux shared library export.
505 #if V8_HAS_ATTRIBUTE_VISIBILITY
506 # ifdef BUILDING_V8_SHARED
507 # define V8_EXPORT __attribute__ ((visibility("default")))
508 # else
509 # define V8_EXPORT
510 # endif
511 #else
512 # define V8_EXPORT
513 #endif
514 
515 #endif // V8_OS_WIN
516 
517 // clang-format on
518 
519 #undef V8_HAS_CPP_ATTRIBUTE
520 
521 #endif // V8CONFIG_H_
V8_DEPRECATE_SOON
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:425
V8_DEPRECATED
#define V8_DEPRECATED(message)
Definition: v8config.h:417
V8_CLANG_NO_SANITIZE
#define V8_CLANG_NO_SANITIZE(what)
Definition: v8config.h:478