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