V8
head
Loading...
Searching...
No Matches
include
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
// gcc 10 defines __cplusplus to "an unspecified value strictly larger than
9
// 201703L" for its experimental -std=gnu++2a config.
10
// TODO(leszeks): Change to `__cplusplus <= 202002L` once we only support
11
// compilers with full C++20 support.
12
#if __cplusplus <= 201703L
13
#error "C++20 or later required."
14
#endif
15
16
#ifdef V8_GN_HEADER
17
#if !__has_include("v8-gn.h"
)
18
#error Missing v8-gn.h. The configuration for v8 is missing from the include \
19
path. Add it with -I<path> to the command line
20
#endif
21
#include "v8-gn.h"
// NOLINT(build/include_directory)
22
#endif
23
24
#include <memory>
25
// clang-format off
26
27
// Platform headers for feature detection below.
28
#if defined(__ANDROID__)
29
# include <sys/cdefs.h>
30
#elif defined(__APPLE__)
31
# include <TargetConditionals.h>
32
#elif defined(__linux__)
33
# include <features.h>
34
#elif defined(__MVS__)
35
# include "zos-base.h"
36
#endif
37
38
39
// This macro allows to test for the version of the GNU C library (or
40
// a compatible C library that masquerades as glibc). It evaluates to
41
// 0 if libc is not GNU libc or compatible.
42
// Use like:
43
// #if V8_GLIBC_PREREQ(2, 3)
44
// ...
45
// #endif
46
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
47
# define V8_GLIBC_PREREQ(major, minor) \
48
((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor)))
49
#else
50
# define V8_GLIBC_PREREQ(major, minor) 0
51
#endif
52
53
54
// This macro allows to test for the version of the GNU C++ compiler.
55
// Note that this also applies to compilers that masquerade as GCC,
56
// for example clang and the Intel C++ compiler for Linux.
57
// Use like:
58
// #if V8_GNUC_PREREQ(4, 3, 1)
59
// ...
60
// #endif
61
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
62
# define V8_GNUC_PREREQ(major, minor, patchlevel) \
63
((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \
64
((major) * 10000 + (minor) * 100 + (patchlevel)))
65
#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
66
# define V8_GNUC_PREREQ(major, minor, patchlevel) \
67
((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= \
68
((major) * 10000 + (minor) * 100 + (patchlevel)))
69
#else
70
# define V8_GNUC_PREREQ(major, minor, patchlevel) 0
71
#endif
72
73
74
75
// -----------------------------------------------------------------------------
76
// Operating system detection (host)
77
//
78
// V8_OS_ANDROID - Android
79
// V8_OS_BSD - BSDish (macOS, Net/Free/Open/DragonFlyBSD)
80
// V8_OS_CYGWIN - Cygwin
81
// V8_OS_DRAGONFLYBSD - DragonFlyBSD
82
// V8_OS_FREEBSD - FreeBSD
83
// V8_OS_FUCHSIA - Fuchsia
84
// V8_OS_LINUX - Linux (Android, ChromeOS, Linux, ...)
85
// V8_OS_DARWIN - Darwin (macOS, iOS)
86
// V8_OS_MACOS - macOS
87
// V8_OS_IOS - iOS
88
// V8_OS_NETBSD - NetBSD
89
// V8_OS_OPENBSD - OpenBSD
90
// V8_OS_POSIX - POSIX compatible (mostly everything except Windows)
91
// V8_OS_QNX - QNX Neutrino
92
// V8_OS_SOLARIS - Sun Solaris and OpenSolaris
93
// V8_OS_STARBOARD - Starboard (platform abstraction for Cobalt)
94
// V8_OS_AIX - AIX
95
// V8_OS_WIN - Microsoft Windows
96
// V8_OS_ZOS - z/OS
97
98
#if defined(__ANDROID__)
99
# define V8_OS_ANDROID 1
100
# define V8_OS_LINUX 1
101
# define V8_OS_POSIX 1
102
# define V8_OS_STRING "android"
103
104
#elif defined(__APPLE__)
105
# define V8_OS_POSIX 1
106
# define V8_OS_BSD 1
107
# define V8_OS_DARWIN 1
108
# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
109
# define V8_OS_IOS 1
110
# define V8_OS_STRING "ios"
111
# else
112
# define V8_OS_MACOS 1
113
# define V8_OS_STRING "macos"
114
# endif
// defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
115
116
#elif defined(__CYGWIN__)
117
# define V8_OS_CYGWIN 1
118
# define V8_OS_POSIX 1
119
# define V8_OS_STRING "cygwin"
120
121
#elif defined(__linux__)
122
# define V8_OS_LINUX 1
123
# define V8_OS_POSIX 1
124
# define V8_OS_STRING "linux"
125
126
#elif defined(__sun)
127
# define V8_OS_POSIX 1
128
# define V8_OS_SOLARIS 1
129
# define V8_OS_STRING "sun"
130
131
#elif defined(STARBOARD)
132
# define V8_OS_STARBOARD 1
133
# define V8_OS_STRING "starboard"
134
135
#elif defined(_AIX)
136
# define V8_OS_POSIX 1
137
# define V8_OS_AIX 1
138
# define V8_OS_STRING "aix"
139
140
#elif defined(__FreeBSD__)
141
# define V8_OS_BSD 1
142
# define V8_OS_FREEBSD 1
143
# define V8_OS_POSIX 1
144
# define V8_OS_STRING "freebsd"
145
146
#elif defined(__Fuchsia__)
147
# define V8_OS_FUCHSIA 1
148
# define V8_OS_POSIX 1
149
# define V8_OS_STRING "fuchsia"
150
151
#elif defined(__DragonFly__)
152
# define V8_OS_BSD 1
153
# define V8_OS_DRAGONFLYBSD 1
154
# define V8_OS_POSIX 1
155
# define V8_OS_STRING "dragonflybsd"
156
157
#elif defined(__NetBSD__)
158
# define V8_OS_BSD 1
159
# define V8_OS_NETBSD 1
160
# define V8_OS_POSIX 1
161
# define V8_OS_STRING "netbsd"
162
163
#elif defined(__OpenBSD__)
164
# define V8_OS_BSD 1
165
# define V8_OS_OPENBSD 1
166
# define V8_OS_POSIX 1
167
# define V8_OS_STRING "openbsd"
168
169
#elif defined(__QNXNTO__)
170
# define V8_OS_POSIX 1
171
# define V8_OS_QNX 1
172
# define V8_OS_STRING "qnx"
173
174
#elif defined(_WIN32)
175
# define V8_OS_WIN 1
176
# define V8_OS_STRING "windows"
177
178
#elif defined(__MVS__)
179
# define V8_OS_POSIX 1
180
# define V8_OS_ZOS 1
181
# define V8_OS_STRING "zos"
182
#endif
183
184
// -----------------------------------------------------------------------------
185
// Operating system detection (target)
186
//
187
// V8_TARGET_OS_ANDROID
188
// V8_TARGET_OS_FUCHSIA
189
// V8_TARGET_OS_IOS
190
// V8_TARGET_OS_LINUX
191
// V8_TARGET_OS_MACOS
192
// V8_TARGET_OS_WIN
193
// V8_TARGET_OS_CHROMEOS
194
//
195
// If not set explicitly, these fall back to corresponding V8_OS_ values.
196
197
#ifdef V8_HAVE_TARGET_OS
198
199
// The target OS is provided, just check that at least one known value is set.
200
# if !defined(V8_TARGET_OS_ANDROID) \
201
&& !defined(V8_TARGET_OS_FUCHSIA) \
202
&& !defined(V8_TARGET_OS_IOS) \
203
&& !defined(V8_TARGET_OS_LINUX) \
204
&& !defined(V8_TARGET_OS_MACOS) \
205
&& !defined(V8_TARGET_OS_WIN) \
206
&& !defined(V8_TARGET_OS_CHROMEOS)
207
# error No known target OS defined.
208
# endif
209
210
#else
// V8_HAVE_TARGET_OS
211
212
# if defined(V8_TARGET_OS_ANDROID) \
213
|| defined(V8_TARGET_OS_FUCHSIA) \
214
|| defined(V8_TARGET_OS_IOS) \
215
|| defined(V8_TARGET_OS_LINUX) \
216
|| defined(V8_TARGET_OS_MACOS) \
217
|| defined(V8_TARGET_OS_WIN) \
218
|| defined(V8_TARGET_OS_CHROMEOS)
219
# error A target OS is defined but V8_HAVE_TARGET_OS is unset.
220
# endif
221
222
// Fall back to the detected host OS.
223
#ifdef V8_OS_ANDROID
224
# define V8_TARGET_OS_ANDROID
225
#endif
226
227
#ifdef V8_OS_FUCHSIA
228
# define V8_TARGET_OS_FUCHSIA
229
#endif
230
231
#ifdef V8_OS_IOS
232
# define V8_TARGET_OS_IOS
233
#endif
234
235
#ifdef V8_OS_LINUX
236
# define V8_TARGET_OS_LINUX
237
#endif
238
239
#ifdef V8_OS_MACOS
240
# define V8_TARGET_OS_MACOS
241
#endif
242
243
#ifdef V8_OS_WIN
244
# define V8_TARGET_OS_WIN
245
#endif
246
247
#endif
// V8_HAVE_TARGET_OS
248
249
#if defined(V8_TARGET_OS_ANDROID)
250
# define V8_TARGET_OS_STRING "android"
251
#elif defined(V8_TARGET_OS_FUCHSIA)
252
# define V8_TARGET_OS_STRING "fuchsia"
253
#elif defined(V8_TARGET_OS_IOS)
254
# define V8_TARGET_OS_STRING "ios"
255
#elif defined(V8_TARGET_OS_LINUX)
256
# define V8_TARGET_OS_STRING "linux"
257
#elif defined(V8_TARGET_OS_MACOS)
258
# define V8_TARGET_OS_STRING "macos"
259
#elif defined(V8_TARGET_OS_WINDOWS)
260
# define V8_TARGET_OS_STRING "windows"
261
#else
262
# define V8_TARGET_OS_STRING "unknown"
263
#endif
264
265
// -----------------------------------------------------------------------------
266
// C library detection
267
//
268
// V8_LIBC_MSVCRT - MSVC libc
269
// V8_LIBC_BIONIC - Bionic libc
270
// V8_LIBC_BSD - BSD libc derivate
271
// V8_LIBC_GLIBC - GNU C library
272
// V8_LIBC_UCLIBC - uClibc
273
//
274
// Note that testing for libc must be done using #if not #ifdef. For example,
275
// to test for the GNU C library, use:
276
// #if V8_LIBC_GLIBC
277
// ...
278
// #endif
279
280
#if defined (_MSC_VER)
281
# define V8_LIBC_MSVCRT 1
282
#elif defined(__BIONIC__)
283
# define V8_LIBC_BIONIC 1
284
# define V8_LIBC_BSD 1
285
#elif defined(__UCLIBC__)
286
// Must test for UCLIBC before GLIBC, as UCLIBC pretends to be GLIBC.
287
# define V8_LIBC_UCLIBC 1
288
#elif defined(__GLIBC__) || defined(__GNU_LIBRARY__)
289
# define V8_LIBC_GLIBC 1
290
#else
291
# define V8_LIBC_BSD V8_OS_BSD
292
#endif
293
294
295
// -----------------------------------------------------------------------------
296
// Compiler detection
297
//
298
// V8_CC_GNU - GCC, or clang in gcc mode
299
// V8_CC_INTEL - Intel C++
300
// V8_CC_MINGW - Minimalist GNU for Windows
301
// V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32)
302
// V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64)
303
// V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode
304
//
305
// C++11 feature detection
306
//
307
// Compiler-specific feature detection
308
//
309
// V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline))
310
// supported
311
// V8_HAS_ATTRIBUTE_CONSTINIT - __attribute__((require_constant_
312
// initialization))
313
// supported
314
// V8_HAS_ATTRIBUTE_NONNULL - __attribute__((nonnull)) supported
315
// V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported
316
// V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported
317
// V8_HAS_ATTRIBUTE_USED - __attribute__((used)) supported
318
// V8_HAS_ATTRIBUTE_RETAIN - __attribute__((retain)) supported
319
// V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported
320
// V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
321
// supported
322
// V8_HAS_CPP_ATTRIBUTE_NODISCARD - [[nodiscard]] supported
323
// V8_HAS_CPP_ATTRIBUTE_NO_UNIQUE_ADDRESS
324
// - [[no_unique_address]] supported
325
// V8_HAS_BUILTIN_ADD_OVERFLOW - __builtin_add_overflow() supported
326
// V8_HAS_BUILTIN_BIT_CAST - __builtin_bit_cast() supported
327
// V8_HAS_BUILTIN_BSWAP16 - __builtin_bswap16() supported
328
// V8_HAS_BUILTIN_BSWAP32 - __builtin_bswap32() supported
329
// V8_HAS_BUILTIN_BSWAP64 - __builtin_bswap64() supported
330
// V8_HAS_BUILTIN_CLZ - __builtin_clz() supported
331
// V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported
332
// V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported
333
// V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported
334
// V8_HAS_BUILTIN_MUL_OVERFLOW - __builtin_mul_overflow() supported
335
// V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported
336
// V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported
337
// V8_HAS_BUILTIN_SMUL_OVERFLOW - __builtin_smul_overflow() supported
338
// V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported
339
// V8_HAS_BUILTIN_SUB_OVERFLOW - __builtin_sub_overflow() supported
340
// V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported
341
// V8_HAS_COMPUTED_GOTO - computed goto/labels as values
342
// supported
343
// V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported
344
// V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported
345
// V8_HAS___FORCEINLINE - __forceinline supported
346
//
347
// Note that testing for compilers and/or features must be done using #if
348
// not #ifdef. For example, to test for Intel C++ Compiler, use:
349
// #if V8_CC_INTEL
350
// ...
351
// #endif
352
353
#if defined(__has_cpp_attribute)
354
#define V8_HAS_CPP_ATTRIBUTE(FEATURE) __has_cpp_attribute(FEATURE)
355
#else
356
#define V8_HAS_CPP_ATTRIBUTE(FEATURE) 0
357
#endif
358
359
#if defined(__clang__)
360
361
#if defined(__GNUC__)
// Clang in gcc mode.
362
# define V8_CC_GNU 1
363
#endif
364
365
# define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
366
# define V8_HAS_ATTRIBUTE_CONSTINIT \
367
(__has_attribute(require_constant_initialization))
368
# define V8_HAS_ATTRIBUTE_CONST (__has_attribute(const))
369
# define V8_HAS_ATTRIBUTE_NONNULL (__has_attribute(nonnull))
370
# define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
371
# define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
372
# define V8_HAS_ATTRIBUTE_USED (__has_attribute(used))
373
# define V8_HAS_ATTRIBUTE_RETAIN (__has_attribute(retain))
374
// Support for the "preserve_most" attribute is limited:
375
// - 32-bit platforms do not implement it,
376
// - component builds fail because _dl_runtime_resolve clobbers registers,
377
// - we see crashes on arm64 on Windows (https://crbug.com/1409934), which can
378
// hopefully be fixed in the future.
379
// Additionally, the initial implementation in clang <= 16 overwrote the return
380
// register(s) in the epilogue of a preserve_most function, so we only use
381
// preserve_most in clang >= 17 (see https://reviews.llvm.org/D143425).
382
#if (defined(_M_X64) || defined(__x86_64__)
/* x64 (everywhere) */
\
383
|| ((defined(__AARCH64EL__) || defined(_M_ARM64))
/* arm64, but ... */
\
384
&& !defined(_WIN32)))
/* not on windows */
\
385
&& !defined(COMPONENT_BUILD)
/* no component build */
\
386
&& __clang_major__ >= 17
/* clang >= 17 */
387
# define V8_HAS_ATTRIBUTE_PRESERVE_MOST (__has_attribute(preserve_most))
388
#endif
389
# define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
390
# define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
391
(__has_attribute(warn_unused_result))
392
# define V8_HAS_ATTRIBUTE_WEAK (__has_attribute(weak))
393
394
# define V8_HAS_CPP_ATTRIBUTE_NODISCARD (V8_HAS_CPP_ATTRIBUTE(nodiscard))
395
# define V8_HAS_CPP_ATTRIBUTE_NO_UNIQUE_ADDRESS \
396
(V8_HAS_CPP_ATTRIBUTE(no_unique_address))
397
398
# define V8_HAS_BUILTIN_ADD_OVERFLOW (__has_builtin(__builtin_add_overflow))
399
# define V8_HAS_BUILTIN_ASSUME (__has_builtin(__builtin_assume))
400
# define V8_HAS_BUILTIN_ASSUME_ALIGNED (__has_builtin(__builtin_assume_aligned))
401
# define V8_HAS_BUILTIN_BIT_CAST (__has_builtin(__builtin_bit_cast))
402
# define V8_HAS_BUILTIN_BSWAP16 (__has_builtin(__builtin_bswap16))
403
# define V8_HAS_BUILTIN_BSWAP32 (__has_builtin(__builtin_bswap32))
404
# define V8_HAS_BUILTIN_BSWAP64 (__has_builtin(__builtin_bswap64))
405
# define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz))
406
# define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz))
407
# define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
408
# define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address))
409
# define V8_HAS_BUILTIN_MUL_OVERFLOW (__has_builtin(__builtin_mul_overflow))
410
# define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount))
411
# define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow))
412
# define V8_HAS_BUILTIN_SMUL_OVERFLOW (__has_builtin(__builtin_smul_overflow))
413
# define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow))
414
# define V8_HAS_BUILTIN_SUB_OVERFLOW (__has_builtin(__builtin_sub_overflow))
415
# define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow))
416
# define V8_HAS_BUILTIN_UNREACHABLE (__has_builtin(__builtin_unreachable))
417
418
// Clang has no __has_feature for computed gotos.
419
// GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
420
# define V8_HAS_COMPUTED_GOTO 1
421
422
#elif defined(__GNUC__)
423
424
# define V8_CC_GNU 1
425
# if defined(__INTEL_COMPILER)
// Intel C++ also masquerades as GCC 3.2.0
426
# define V8_CC_INTEL 1
427
# endif
428
# if defined(__MINGW32__)
429
# define V8_CC_MINGW32 1
430
# endif
431
# if defined(__MINGW64__)
432
# define V8_CC_MINGW64 1
433
# endif
434
# define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
435
436
// FYI: __has_builtin is only available with GCC 10 and later, so explicitly
437
// check GCC version numbers to enable features. TODO(leszeks): Merge feature
438
// enabling for GCC 10 and later into the Clang section above, and leave this
439
// section for GCC 9 and earlier.
440
441
// always_inline is available in gcc 4.0 but not very reliable until 4.4.
442
// Works around "sorry, unimplemented: inlining failed" build errors with
443
// older compilers.
444
# define V8_HAS_ATTRIBUTE_ALWAYS_INLINE 1
445
# define V8_HAS_ATTRIBUTE_NOINLINE 1
446
# define V8_HAS_ATTRIBUTE_UNUSED 1
447
# define V8_HAS_ATTRIBUTE_VISIBILITY 1
448
# define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT (!V8_CC_INTEL)
449
# define V8_HAS_ATTRIBUTE_WEAK 1
450
451
// [[nodiscard]] does not work together with with
452
// __attribute__((visibility(""))) on GCC 7.4 which is why there is no define
453
// for V8_HAS_CPP_ATTRIBUTE_NODISCARD. See https://crbug.com/v8/11707.
454
455
# define V8_HAS_BUILTIN_ASSUME_ALIGNED 1
456
# if __GNUC__ >= 11
457
# define V8_HAS_BUILTIN_BIT_CAST 1
458
# endif
459
# define V8_HAS_BUILTIN_CLZ 1
460
# define V8_HAS_BUILTIN_CTZ 1
461
# define V8_HAS_BUILTIN_EXPECT 1
462
# define V8_HAS_BUILTIN_FRAME_ADDRESS 1
463
# define V8_HAS_BUILTIN_POPCOUNT 1
464
# define V8_HAS_BUILTIN_UNREACHABLE 1
465
466
// GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
467
#define V8_HAS_COMPUTED_GOTO 1
468
469
#endif
470
471
#if defined(_MSC_VER)
472
# define V8_CC_MSVC 1
473
474
# define V8_HAS_DECLSPEC_NOINLINE 1
475
# define V8_HAS_DECLSPEC_SELECTANY 1
476
477
# define V8_HAS___FORCEINLINE 1
478
479
#endif
480
481
482
// -----------------------------------------------------------------------------
483
// Helper macros
484
485
// A macro used to make better inlining. Don't bother for debug builds.
486
// Use like:
487
// V8_INLINE int GetZero() { return 0; }
488
#if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
489
# define V8_INLINE inline __attribute__((always_inline))
490
#elif !defined(DEBUG) && V8_HAS___FORCEINLINE
491
# define V8_INLINE __forceinline
492
#else
493
# define V8_INLINE inline
494
#endif
495
496
#if V8_HAS_BUILTIN_ASSUME
497
#ifdef DEBUG
498
// In debug mode, check assumptions in addition to adding annotations.
499
// This helps GCC (and maybe other compilers) figure out that certain
500
// situations are unreachable.
501
# define V8_ASSUME(condition) \
502
do { \
503
DCHECK(condition); \
504
__builtin_assume(condition); \
505
} while (false)
506
#else
// DEBUG
507
# define V8_ASSUME __builtin_assume
508
#endif
// DEBUG
509
#elif V8_HAS_BUILTIN_UNREACHABLE
510
# define V8_ASSUME(condition) \
511
do { \
512
DCHECK(condition); \
513
if (!(condition)) __builtin_unreachable(); \
514
} while (false)
515
#else
516
# define V8_ASSUME USE
517
#endif
518
519
// Prefer c++20 std::assume_aligned. Don't use it on MSVC though, because it's
520
// not happy with our large 4GB alignment values.
521
#if __cplusplus >= 202002L && defined(__cpp_lib_assume_aligned) && !V8_CC_MSVC
522
# define V8_ASSUME_ALIGNED(ptr, alignment) \
523
std::assume_aligned<(alignment)>(ptr)
524
#elif V8_HAS_BUILTIN_ASSUME_ALIGNED
525
# define V8_ASSUME_ALIGNED(ptr, alignment) \
526
__builtin_assume_aligned((ptr), (alignment))
527
#else
528
# define V8_ASSUME_ALIGNED(ptr, alignment) (ptr)
529
#endif
530
531
// A macro to mark functions whose values don't change (e.g. across calls)
532
// and thereby compiler is free to hoist and fold multiple calls together.
533
// Use like:
534
// V8_CONST int foo() { ... }
535
#if V8_HAS_ATTRIBUTE_CONST
536
# define V8_CONST __attribute__((const))
537
#else
538
# define V8_CONST
539
#endif
540
541
// A macro to mark a declaration as requiring constant initialization.
542
// Use like:
543
// int* foo V8_CONSTINIT;
544
#if V8_HAS_ATTRIBUTE_CONSTINIT
545
# define V8_CONSTINIT __attribute__((require_constant_initialization))
546
#else
547
# define V8_CONSTINIT
548
#endif
549
550
551
// A macro to mark specific arguments as non-null.
552
// Use like:
553
// int add(int* x, int y, int* z) V8_NONNULL(1, 3) { return *x + y + *z; }
554
#if V8_HAS_ATTRIBUTE_NONNULL
555
# define V8_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
556
#else
557
# define V8_NONNULL(...)
/* NOT SUPPORTED */
558
#endif
559
560
561
// A macro used to tell the compiler to never inline a particular function.
562
// Use like:
563
// V8_NOINLINE int GetMinusOne() { return -1; }
564
#if V8_HAS_ATTRIBUTE_NOINLINE
565
# define V8_NOINLINE __attribute__((noinline))
566
#elif V8_HAS_DECLSPEC_NOINLINE
567
# define V8_NOINLINE __declspec(noinline)
568
#else
569
# define V8_NOINLINE
/* NOT SUPPORTED */
570
#endif
571
572
573
// A macro used to change the calling conventions to preserve all registers (no
574
// caller-saved registers). Use this for cold functions called from hot
575
// functions.
576
// Use like:
577
// V8_NOINLINE V8_PRESERVE_MOST void UnlikelyMethod();
578
#if V8_HAS_ATTRIBUTE_PRESERVE_MOST
579
# define V8_PRESERVE_MOST __attribute__((preserve_most))
580
#else
581
# define V8_PRESERVE_MOST
/* NOT SUPPORTED */
582
#endif
583
584
585
// A macro (V8_DEPRECATED) to mark classes or functions as deprecated.
586
#if defined(V8_DEPRECATION_WARNINGS)
587
# define V8_DEPRECATED(message) [[deprecated(message)]]
588
#else
589
# define V8_DEPRECATED(message)
590
#endif
591
592
593
// A macro (V8_DEPRECATE_SOON) to make it easier to see what will be deprecated.
594
#if defined(V8_IMMINENT_DEPRECATION_WARNINGS)
595
# define V8_DEPRECATE_SOON(message) [[deprecated(message)]]
596
#else
597
# define V8_DEPRECATE_SOON(message)
598
#endif
599
600
601
#if defined(V8_IMMINENT_DEPRECATION_WARNINGS) || \
602
defined(V8_DEPRECATION_WARNINGS)
603
#if defined(V8_CC_MSVC)
604
# define START_ALLOW_USE_DEPRECATED() \
605
__pragma(warning(push)) \
606
__pragma(warning(disable : 4996))
607
# define END_ALLOW_USE_DEPRECATED() __pragma(warning(pop))
608
#else
// !defined(V8_CC_MSVC)
609
# define START_ALLOW_USE_DEPRECATED() \
610
_Pragma("GCC diagnostic push"
) \
611
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
612
#define END_ALLOW_USE_DEPRECATED() _Pragma("GCC diagnostic pop"
)
613
#endif
// !defined(V8_CC_MSVC)
614
#else
// !(defined(V8_IMMINENT_DEPRECATION_WARNINGS) ||
615
// defined(V8_DEPRECATION_WARNINGS))
616
#define START_ALLOW_USE_DEPRECATED()
617
#define END_ALLOW_USE_DEPRECATED()
618
#endif
// !(defined(V8_IMMINENT_DEPRECATION_WARNINGS) ||
619
// defined(V8_DEPRECATION_WARNINGS))
620
#define ALLOW_COPY_AND_MOVE_WITH_DEPRECATED_FIELDS(ClassName) \
621
START_ALLOW_USE_DEPRECATED() \
622
ClassName(const ClassName&) = default; \
623
ClassName(ClassName&&) = default; \
624
ClassName& operator=(const ClassName&) = default; \
625
ClassName& operator=(ClassName&&) = default; \
626
END_ALLOW_USE_DEPRECATED()
627
628
629
#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 6)
630
# define V8_ENUM_DEPRECATED(message)
631
# define V8_ENUM_DEPRECATE_SOON(message)
632
#else
633
# define V8_ENUM_DEPRECATED(message) V8_DEPRECATED(message)
634
# define V8_ENUM_DEPRECATE_SOON(message) V8_DEPRECATE_SOON(message)
635
#endif
636
637
638
// A macro to provide the compiler with branch prediction information.
639
#if V8_HAS_BUILTIN_EXPECT
640
# define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
641
# define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1))
642
#else
643
# define V8_UNLIKELY(condition) (condition)
644
# define V8_LIKELY(condition) (condition)
645
#endif
646
647
648
// Annotate a function indicating the caller must examine the return value.
649
// Use like:
650
// int foo() V8_WARN_UNUSED_RESULT;
651
#if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
652
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
653
#else
654
#define V8_WARN_UNUSED_RESULT
/* NOT SUPPORTED */
655
#endif
656
657
658
// Annotate functions/variables as weak to allow overriding the symbol.
659
#if V8_HAS_ATTRIBUTE_WEAK
660
#define V8_WEAK __attribute__((weak))
661
#else
662
#define V8_WEAK
/* NOT SUPPORTED */
663
#endif
664
665
666
// Annotate a class or constructor indicating the caller must assign the
667
// constructed instances.
668
// Apply to the whole class like:
669
// class V8_NODISCARD Foo() { ... };
670
// or apply to just one constructor like:
671
// V8_NODISCARD Foo() { ... };
672
// [[nodiscard]] comes in C++17 but supported in clang with -std >= c++11.
673
#if V8_HAS_CPP_ATTRIBUTE_NODISCARD
674
#define V8_NODISCARD [[nodiscard]]
675
#else
676
#define V8_NODISCARD
/* NOT SUPPORTED */
677
#endif
678
679
// The no_unique_address attribute allows tail padding in a non-static data
680
// member to overlap other members of the enclosing class (and in the special
681
// case when the type is empty, permits it to fully overlap other members). The
682
// field is laid out as if a base class were encountered at the corresponding
683
// point within the class (except that it does not share a vptr with the
684
// enclosing object).
685
//
686
// Apply to a data member like:
687
//
688
// class Foo {
689
// V8_NO_UNIQUE_ADDRESS Bar bar_;
690
// };
691
//
692
// [[no_unique_address]] comes in C++20 but supported in clang with
693
// -std >= c++11.
694
#if V8_HAS_CPP_ATTRIBUTE_NO_UNIQUE_ADDRESS
695
#define V8_NO_UNIQUE_ADDRESS [[no_unique_address]]
696
#else
697
#define V8_NO_UNIQUE_ADDRESS
/* NOT SUPPORTED */
698
#endif
699
700
// Marks a type as being eligible for the "trivial" ABI despite having a
701
// non-trivial destructor or copy/move constructor. Such types can be relocated
702
// after construction by simply copying their memory, which makes them eligible
703
// to be passed in registers. The canonical example is std::unique_ptr.
704
//
705
// Use with caution; this has some subtle effects on constructor/destructor
706
// ordering and will be very incorrect if the type relies on its address
707
// remaining constant. When used as a function argument (by value), the value
708
// may be constructed in the caller's stack frame, passed in a register, and
709
// then used and destructed in the callee's stack frame. A similar thing can
710
// occur when values are returned.
711
//
712
// TRIVIAL_ABI is not needed for types which have a trivial destructor and
713
// copy/move constructors, since those are automatically trivial by the ABI
714
// spec.
715
//
716
// It is also not likely to be effective on types too large to be passed in one
717
// or two registers on typical target ABIs.
718
//
719
// See also:
720
// https://clang.llvm.org/docs/AttributeReference.html#trivial-abi
721
// https://libcxx.llvm.org/docs/DesignDocs/UniquePtrTrivialAbi.html
722
#if defined(__clang__) && defined(__has_attribute)
723
#if __has_attribute(trivial_abi)
724
#define V8_TRIVIAL_ABI [[clang::trivial_abi]]
725
#define V8_HAS_ATTRIBUTE_TRIVIAL_ABI 1
726
#endif
// __has_attribute(trivial_abi)
727
#endif
// defined(__clang__) && defined(__has_attribute)
728
#if !defined(V8_TRIVIAL_ABI)
729
#define V8_TRIVIAL_ABI
730
#define V8_HAS_ATTRIBUTE_TRIVIAL_ABI 0
731
#endif
732
733
// Helper macro to define no_sanitize attributes only with clang.
734
#if defined(__clang__) && defined(__has_attribute)
735
#if __has_attribute(no_sanitize)
736
#define V8_CLANG_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
737
#endif
738
#endif
739
#if !defined(V8_CLANG_NO_SANITIZE)
740
#define V8_CLANG_NO_SANITIZE(what)
741
#endif
742
743
// Exposing private symbols requires exposing public symbols too.
744
#ifdef BUILDING_V8_SHARED_PRIVATE
745
#define BUILDING_V8_SHARED
746
#endif
747
748
#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
749
#error Inconsistent build configuration: To build the V8 shared library \
750
set BUILDING_V8_SHARED, to include its headers for linking against the \
751
V8 shared library set USING_V8_SHARED.
752
#endif
753
754
#ifdef V8_OS_WIN
755
756
// Setup for Windows DLL export/import. When building the V8 DLL the
757
// BUILDING_V8_SHARED needs to be defined. When building a program which uses
758
// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
759
// static library or building a program which uses the V8 static library neither
760
// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
761
#ifdef BUILDING_V8_SHARED
762
# define V8_EXPORT __declspec(dllexport)
763
#elif USING_V8_SHARED
764
# define V8_EXPORT __declspec(dllimport)
765
#else
766
# define V8_EXPORT
767
#endif
// BUILDING_V8_SHARED
768
769
#else
// V8_OS_WIN
770
771
// Setup for Linux shared library export.
772
#if V8_HAS_ATTRIBUTE_VISIBILITY
773
# ifdef BUILDING_V8_SHARED
774
# define V8_EXPORT __attribute__ ((visibility("default"
)))
775
# else
776
# define V8_EXPORT
777
# endif
778
#else
779
# define V8_EXPORT
780
#endif
781
782
#endif
// V8_OS_WIN
783
784
// clang-format on
785
786
// Processor architecture detection. For more info on what's defined, see:
787
// http://msdn.microsoft.com/en-us/library/b0084kay.aspx
788
// http://www.agner.org/optimize/calling_conventions.pdf
789
// or with gcc, run: "echo | gcc -E -dM -"
790
// The V8_HOST_ARCH_* macros correspond to the architecture on which V8, as a
791
// virtual machine and compiler, runs. Don't confuse this with the architecture
792
// on which V8 is built.
793
#if defined(_M_X64) || defined(__x86_64__)
794
#define V8_HOST_ARCH_X64 1
795
#if defined(__x86_64__) && __SIZEOF_POINTER__ == 4
// Check for x32.
796
#define V8_HOST_ARCH_32_BIT 1
797
#else
798
#define V8_HOST_ARCH_64_BIT 1
799
#endif
800
#elif defined(_M_IX86) || defined(__i386__)
801
#define V8_HOST_ARCH_IA32 1
802
#define V8_HOST_ARCH_32_BIT 1
803
#elif defined(__AARCH64EL__) || defined(_M_ARM64)
804
#define V8_HOST_ARCH_ARM64 1
805
#define V8_HOST_ARCH_64_BIT 1
806
#elif defined(__ARMEL__)
807
#define V8_HOST_ARCH_ARM 1
808
#define V8_HOST_ARCH_32_BIT 1
809
#elif defined(__mips64)
810
#define V8_HOST_ARCH_MIPS64 1
811
#define V8_HOST_ARCH_64_BIT 1
812
#elif defined(__loongarch_lp64)
813
#define V8_HOST_ARCH_LOONG64 1
814
#define V8_HOST_ARCH_64_BIT 1
815
#elif defined(__PPC64__) || defined(_ARCH_PPC64)
816
#define V8_HOST_ARCH_PPC64 1
817
#define V8_HOST_ARCH_64_BIT 1
818
#elif defined(__PPC__) || defined(_ARCH_PPC)
819
#define V8_HOST_ARCH_PPC 1
820
#define V8_HOST_ARCH_32_BIT 1
821
#elif defined(__s390__) || defined(__s390x__)
822
#define V8_HOST_ARCH_S390 1
823
#if defined(__s390x__)
824
#define V8_HOST_ARCH_64_BIT 1
825
#else
826
#define V8_HOST_ARCH_32_BIT 1
827
#endif
828
#elif defined(__riscv) || defined(__riscv__)
829
#if __riscv_xlen == 64
830
#define V8_HOST_ARCH_RISCV64 1
831
#define V8_HOST_ARCH_64_BIT 1
832
#elif __riscv_xlen == 32
833
#define V8_HOST_ARCH_RISCV32 1
834
#define V8_HOST_ARCH_32_BIT 1
835
#else
836
#error "Cannot detect Riscv's bitwidth"
837
#endif
838
#else
839
#error "Host architecture was not detected as supported by v8"
840
#endif
841
842
// Target architecture detection. This corresponds to the architecture for which
843
// V8's JIT will generate code (the last stage of the canadian cross-compiler).
844
// The macros may be set externally. If not, detect in the same way as the host
845
// architecture, that is, target the native environment as presented by the
846
// compiler.
847
#if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_IA32 && !V8_TARGET_ARCH_ARM && \
848
!V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_MIPS64 && !V8_TARGET_ARCH_PPC && \
849
!V8_TARGET_ARCH_PPC64 && !V8_TARGET_ARCH_S390 && \
850
!V8_TARGET_ARCH_RISCV64 && !V8_TARGET_ARCH_LOONG64 && \
851
!V8_TARGET_ARCH_RISCV32
852
#if defined(_M_X64) || defined(__x86_64__)
853
#define V8_TARGET_ARCH_X64 1
854
#elif defined(_M_IX86) || defined(__i386__)
855
#define V8_TARGET_ARCH_IA32 1
856
#elif defined(__AARCH64EL__) || defined(_M_ARM64)
857
#define V8_TARGET_ARCH_ARM64 1
858
#elif defined(__ARMEL__)
859
#define V8_TARGET_ARCH_ARM 1
860
#elif defined(__mips64)
861
#define V8_TARGET_ARCH_MIPS64 1
862
#elif defined(__loongarch_lp64)
863
#define V8_TARGET_ARCH_LOONG64 1
864
#elif defined(_ARCH_PPC64)
865
#define V8_TARGET_ARCH_PPC64 1
866
#elif defined(_ARCH_PPC)
867
#define V8_TARGET_ARCH_PPC 1
868
#elif defined(__s390__)
869
#define V8_TARGET_ARCH_S390 1
870
#if defined(__s390x__)
871
#define V8_TARGET_ARCH_S390X 1
872
#endif
873
#elif defined(__riscv) || defined(__riscv__)
874
#if __riscv_xlen == 64
875
#define V8_TARGET_ARCH_RISCV64 1
876
#elif __riscv_xlen == 32
877
#define V8_TARGET_ARCH_RISCV32 1
878
#endif
879
#else
880
#error Target architecture was not detected as supported by v8
881
#endif
882
#endif
883
884
// Determine architecture pointer size.
885
#if V8_TARGET_ARCH_IA32
886
#define V8_TARGET_ARCH_32_BIT 1
887
#elif V8_TARGET_ARCH_X64
888
#if !V8_TARGET_ARCH_32_BIT && !V8_TARGET_ARCH_64_BIT
889
#if defined(__x86_64__) && __SIZEOF_POINTER__ == 4
// Check for x32.
890
#define V8_TARGET_ARCH_32_BIT 1
891
#else
892
#define V8_TARGET_ARCH_64_BIT 1
893
#endif
894
#endif
895
#elif V8_TARGET_ARCH_ARM
896
#define V8_TARGET_ARCH_32_BIT 1
897
#elif V8_TARGET_ARCH_ARM64
898
#define V8_TARGET_ARCH_64_BIT 1
899
#elif V8_TARGET_ARCH_MIPS
900
#define V8_TARGET_ARCH_32_BIT 1
901
#elif V8_TARGET_ARCH_MIPS64
902
#define V8_TARGET_ARCH_64_BIT 1
903
#elif V8_TARGET_ARCH_LOONG64
904
#define V8_TARGET_ARCH_64_BIT 1
905
#elif V8_TARGET_ARCH_PPC
906
#define V8_TARGET_ARCH_32_BIT 1
907
#elif V8_TARGET_ARCH_PPC64
908
#define V8_TARGET_ARCH_64_BIT 1
909
#elif V8_TARGET_ARCH_S390
910
#if V8_TARGET_ARCH_S390X
911
#define V8_TARGET_ARCH_64_BIT 1
912
#else
913
#define V8_TARGET_ARCH_32_BIT 1
914
#endif
915
#elif V8_TARGET_ARCH_RISCV64
916
#define V8_TARGET_ARCH_64_BIT 1
917
#elif V8_TARGET_ARCH_RISCV32
918
#define V8_TARGET_ARCH_32_BIT 1
919
#else
920
#error Unknown target architecture pointer size
921
#endif
922
923
// Check for supported combinations of host and target architectures.
924
#if V8_TARGET_ARCH_IA32 && !V8_HOST_ARCH_IA32
925
#error Target architecture ia32 is only supported on ia32 host
926
#endif
927
#if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT && \
928
!((V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64) && V8_HOST_ARCH_64_BIT))
929
#error Target architecture x64 is only supported on x64 and arm64 host
930
#endif
931
#if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT && \
932
!(V8_HOST_ARCH_X64 && V8_HOST_ARCH_32_BIT))
933
#error Target architecture x32 is only supported on x64 host with x32 support
934
#endif
935
#if (V8_TARGET_ARCH_ARM && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM))
936
#error Target architecture arm is only supported on arm and ia32 host
937
#endif
938
#if (V8_TARGET_ARCH_ARM64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64))
939
#error Target architecture arm64 is only supported on arm64 and x64 host
940
#endif
941
#if (V8_TARGET_ARCH_MIPS64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_MIPS64))
942
#error Target architecture mips64 is only supported on mips64 and x64 host
943
#endif
944
#if (V8_TARGET_ARCH_RISCV64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_RISCV64))
945
#error Target architecture riscv64 is only supported on riscv64 and x64 host
946
#endif
947
#if (V8_TARGET_ARCH_RISCV32 && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_RISCV32))
948
#error Target architecture riscv32 is only supported on riscv32 and ia32 host
949
#endif
950
#if (V8_TARGET_ARCH_LOONG64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_LOONG64))
951
#error Target architecture loong64 is only supported on loong64 and x64 host
952
#endif
953
954
// Determine architecture endianness.
955
#if V8_TARGET_ARCH_IA32
956
#define V8_TARGET_LITTLE_ENDIAN 1
957
#elif V8_TARGET_ARCH_X64
958
#define V8_TARGET_LITTLE_ENDIAN 1
959
#elif V8_TARGET_ARCH_ARM
960
#define V8_TARGET_LITTLE_ENDIAN 1
961
#elif V8_TARGET_ARCH_ARM64
962
#define V8_TARGET_LITTLE_ENDIAN 1
963
#elif V8_TARGET_ARCH_LOONG64
964
#define V8_TARGET_LITTLE_ENDIAN 1
965
#elif V8_TARGET_ARCH_MIPS64
966
#if defined(__MIPSEB__) || defined(V8_TARGET_ARCH_MIPS64_BE)
967
#define V8_TARGET_BIG_ENDIAN 1
968
#else
969
#define V8_TARGET_LITTLE_ENDIAN 1
970
#endif
971
#elif defined(__BIG_ENDIAN__)
// FOR PPCGR on AIX
972
#define V8_TARGET_BIG_ENDIAN 1
973
#elif V8_TARGET_ARCH_PPC_LE
974
#define V8_TARGET_LITTLE_ENDIAN 1
975
#elif V8_TARGET_ARCH_PPC_BE
976
#define V8_TARGET_BIG_ENDIAN 1
977
#elif V8_TARGET_ARCH_S390
978
#if V8_TARGET_ARCH_S390_LE_SIM
979
#define V8_TARGET_LITTLE_ENDIAN 1
980
#else
981
#define V8_TARGET_BIG_ENDIAN 1
982
#endif
983
#elif V8_TARGET_ARCH_RISCV32 || V8_TARGET_ARCH_RISCV64
984
#define V8_TARGET_LITTLE_ENDIAN 1
985
#elif defined(__BYTE_ORDER__)
986
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
987
#define V8_TARGET_BIG_ENDIAN 1
988
#else
989
#define V8_TARGET_LITTLE_ENDIAN 1
990
#endif
991
#else
992
#error Unknown target architecture endianness
993
#endif
994
995
#undef V8_HAS_CPP_ATTRIBUTE
996
997
#if !defined(V8_STATIC_ROOTS)
998
#define V8_STATIC_ROOTS_BOOL false
999
#else
1000
#define V8_STATIC_ROOTS_BOOL true
1001
#endif
1002
1003
#endif
// V8CONFIG_H_