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