1 // Copyright 2013 the V8 project authors. All rights reserved. 2 // Redistribution and use in source and binary forms, with or without 3 // modification, are permitted provided that the following conditions are 4 // met: 5 // 6 // * Redistributions of source code must retain the above copyright 7 // notice, this list of conditions and the following disclaimer. 8 // * Redistributions in binary form must reproduce the above 9 // copyright notice, this list of conditions and the following 10 // disclaimer in the documentation and/or other materials provided 11 // with the distribution. 12 // * Neither the name of Google Inc. nor the names of its 13 // contributors may be used to endorse or promote products derived 14 // from this software without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 #ifndef V8CONFIG_H_ 29 #define V8CONFIG_H_ 30 31 // Platform headers for feature detection below. 32 #if defined(__ANDROID__) 33 # include <sys/cdefs.h> 34 #elif defined(__APPLE__) 35 # include <TargetConditionals.h> 36 #elif defined(__linux__) 37 # include <features.h> 38 #endif 39 40 41 // This macro allows to test for the version of the GNU C library (or 42 // a compatible C library that masquerades as glibc). It evaluates to 43 // 0 if libc is not GNU libc or compatible. 44 // Use like: 45 // #if V8_GLIBC_PREREQ(2, 3) 46 // ... 47 // #endif 48 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) 49 # define V8_GLIBC_PREREQ(major, minor) \ 50 ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor))) 51 #else 52 # define V8_GLIBC_PREREQ(major, minor) 0 53 #endif 54 55 56 // This macro allows to test for the version of the GNU C++ compiler. 57 // Note that this also applies to compilers that masquerade as GCC, 58 // for example clang and the Intel C++ compiler for Linux. 59 // Use like: 60 // #if V8_GNUC_PREREQ(4, 3, 1) 61 // ... 62 // #endif 63 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) 64 # define V8_GNUC_PREREQ(major, minor, patchlevel) \ 65 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ 66 ((major) * 10000 + (minor) * 100 + (patchlevel))) 67 #elif defined(__GNUC__) && defined(__GNUC_MINOR__) 68 # define V8_GNUC_PREREQ(major, minor, patchlevel) \ 69 ((__GNUC__ * 10000 + __GNUC_MINOR__) >= \ 70 ((major) * 10000 + (minor) * 100 + (patchlevel))) 71 #else 72 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 73 #endif 74 75 76 77 // ----------------------------------------------------------------------------- 78 // Operating system detection 79 // 80 // V8_OS_ANDROID - Android 81 // V8_OS_BSD - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD) 82 // V8_OS_CYGWIN - Cygwin 83 // V8_OS_DRAGONFLYBSD - DragonFlyBSD 84 // V8_OS_FREEBSD - FreeBSD 85 // V8_OS_LINUX - Linux 86 // V8_OS_MACOSX - Mac OS X 87 // V8_OS_NACL - Native Client 88 // V8_OS_NETBSD - NetBSD 89 // V8_OS_OPENBSD - OpenBSD 90 // V8_OS_POSIX - POSIX compatible (mostly everything except Windows) 91 // V8_OS_SOLARIS - Sun Solaris and OpenSolaris 92 // V8_OS_WIN - Microsoft Windows 93 94 #if defined(__ANDROID__) 95 # define V8_OS_ANDROID 1 96 # define V8_OS_LINUX 1 97 # define V8_OS_POSIX 1 98 #elif defined(__APPLE__) 99 # define V8_OS_BSD 1 100 # define V8_OS_MACOSX 1 101 # define V8_OS_POSIX 1 102 #elif defined(__native_client__) 103 # define V8_OS_NACL 1 104 # define V8_OS_POSIX 1 105 #elif defined(__CYGWIN__) 106 # define V8_OS_CYGWIN 1 107 # define V8_OS_POSIX 1 108 #elif defined(__linux__) 109 # define V8_OS_LINUX 1 110 # define V8_OS_POSIX 1 111 #elif defined(__sun) 112 # define V8_OS_POSIX 1 113 # define V8_OS_SOLARIS 1 114 #elif defined(__FreeBSD__) 115 # define V8_OS_BSD 1 116 # define V8_OS_FREEBSD 1 117 # define V8_OS_POSIX 1 118 #elif defined(__DragonFly__) 119 # define V8_OS_BSD 1 120 # define V8_OS_DRAGONFLYBSD 1 121 # define V8_OS_POSIX 1 122 #elif defined(__NetBSD__) 123 # define V8_OS_BSD 1 124 # define V8_OS_NETBSD 1 125 # define V8_OS_POSIX 1 126 #elif defined(__OpenBSD__) 127 # define V8_OS_BSD 1 128 # define V8_OS_OPENBSD 1 129 # define V8_OS_POSIX 1 130 #elif defined(_WIN32) 131 # define V8_OS_WIN 1 132 #endif 133 134 135 // ----------------------------------------------------------------------------- 136 // C library detection 137 // 138 // V8_LIBC_BIONIC - Bionic libc 139 // V8_LIBC_BSD - BSD libc derivate 140 // V8_LIBC_GLIBC - GNU C library 141 // V8_LIBC_UCLIBC - uClibc 142 // 143 // Note that testing for libc must be done using #if not #ifdef. For example, 144 // to test for the GNU C library, use: 145 // #if V8_LIBC_GLIBC 146 // ... 147 // #endif 148 149 #if defined(__BIONIC__) 150 # define V8_LIBC_BIONIC 1 151 # define V8_LIBC_BSD 1 152 #elif defined(__UCLIBC__) 153 # define V8_LIBC_UCLIBC 1 154 #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__) 155 # define V8_LIBC_GLIBC 1 156 #else 157 # define V8_LIBC_BSD V8_OS_BSD 158 #endif 159 160 161 // ----------------------------------------------------------------------------- 162 // Compiler detection 163 // 164 // V8_CC_CLANG - Clang 165 // V8_CC_GNU - GNU C++ 166 // V8_CC_INTEL - Intel C++ 167 // V8_CC_MINGW - Minimalist GNU for Windows 168 // V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32) 169 // V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64) 170 // V8_CC_MSVC - Microsoft Visual C/C++ 171 // 172 // C++11 feature detection 173 // 174 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported 175 // V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported 176 // V8_HAS_CXX11_STATIC_ASSERT - static_assert() supported 177 // V8_HAS_CXX11_DELETE - deleted functions supported 178 // V8_HAS_CXX11_FINAL - final marker supported 179 // V8_HAS_CXX11_OVERRIDE - override marker supported 180 // 181 // Compiler-specific feature detection 182 // 183 // V8_HAS___ALIGNOF - __alignof(type) operator supported 184 // V8_HAS___ALIGNOF__ - __alignof__(type) operator supported 185 // V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported 186 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) 187 // supported 188 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported 189 // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported 190 // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported 191 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported 192 // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result)) 193 // supported 194 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported 195 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported 196 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported 197 // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported 198 // V8_HAS___FINAL - __final supported in non-C++11 mode 199 // V8_HAS___FORCEINLINE - __forceinline supported 200 // V8_HAS_SEALED - MSVC style sealed marker supported 201 // 202 // Note that testing for compilers and/or features must be done using #if 203 // not #ifdef. For example, to test for Intel C++ Compiler, use: 204 // #if V8_CC_INTEL 205 // ... 206 // #endif 207 208 #if defined(__clang__) 209 210 # define V8_CC_CLANG 1 211 212 // Clang defines __alignof__ as alias for __alignof 213 # define V8_HAS___ALIGNOF 1 214 # define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF 215 216 # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned)) 217 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) 218 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) 219 # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline)) 220 # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused)) 221 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) 222 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ 223 (__has_attribute(warn_unused_result)) 224 225 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) 226 227 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas)) 228 # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert)) 229 # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions)) 230 # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control)) 231 # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control)) 232 233 #elif defined(__GNUC__) 234 235 # define V8_CC_GNU 1 236 // Intel C++ also masquerades as GCC 3.2.0 237 # define V8_CC_INTEL (defined(__INTEL_COMPILER)) 238 # define V8_CC_MINGW32 (defined(__MINGW32__)) 239 # define V8_CC_MINGW64 (defined(__MINGW64__)) 240 # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64) 241 242 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0)) 243 244 # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0)) 245 // always_inline is available in gcc 4.0 but not very reliable until 4.4. 246 // Works around "sorry, unimplemented: inlining failed" build errors with 247 // older compilers. 248 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0)) 249 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) 250 # define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0)) 251 # define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0)) 252 # define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0)) 253 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) 254 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ 255 (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0)) 256 257 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0)) 258 259 // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality 260 // without warnings (functionality used by the macros below). These modes 261 // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, 262 // more standardly, by checking whether __cplusplus has a C++11 or greater 263 // value. Current versions of g++ do not correctly set __cplusplus, so we check 264 // both for forward compatibility. 265 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L 266 # define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0)) 267 # define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0)) 268 # define V8_HAS_CXX11_STATIC_ASSERT (V8_GNUC_PREREQ(4, 3, 0)) 269 # define V8_HAS_CXX11_DELETE (V8_GNUC_PREREQ(4, 4, 0)) 270 # define V8_HAS_CXX11_OVERRIDE (V8_GNUC_PREREQ(4, 7, 0)) 271 # define V8_HAS_CXX11_FINAL (V8_GNUC_PREREQ(4, 7, 0)) 272 # else 273 // '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655. 274 # define V8_HAS___FINAL (V8_GNUC_PREREQ(4, 7, 0)) 275 # endif 276 277 #elif defined(_MSC_VER) 278 279 # define V8_CC_MSVC 1 280 281 # define V8_HAS___ALIGNOF 1 282 283 // Override control was added with Visual Studio 2005, but 284 // Visual Studio 2010 and earlier spell "final" as "sealed". 285 # define V8_HAS_CXX11_FINAL (_MSC_VER >= 1700) 286 # define V8_HAS_CXX11_OVERRIDE (_MSC_VER >= 1400) 287 # define V8_HAS_SEALED (_MSC_VER >= 1400) 288 289 # define V8_HAS_DECLSPEC_ALIGN 1 290 # define V8_HAS_DECLSPEC_DEPRECATED (_MSC_VER >= 1300) 291 # define V8_HAS_DECLSPEC_NOINLINE 1 292 293 # define V8_HAS___FORCEINLINE 1 294 295 #endif 296 297 298 // ----------------------------------------------------------------------------- 299 // Helper macros 300 301 // A macro used to make better inlining. Don't bother for debug builds. 302 // Use like: 303 // V8_INLINE int GetZero() { return 0; } 304 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE 305 # define V8_INLINE inline __attribute__((always_inline)) 306 #elif !defined(DEBUG) && V8_HAS___FORCEINLINE 307 # define V8_INLINE __forceinline 308 #else 309 # define V8_INLINE inline 310 #endif 311 312 313 // A macro used to tell the compiler to never inline a particular function. 314 // Don't bother for debug builds. 315 // Use like: 316 // V8_NOINLINE int GetMinusOne() { return -1; } 317 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE 318 # define V8_NOINLINE __attribute__((noinline)) 319 #elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE 320 # define V8_NOINLINE __declspec(noinline) 321 #else 322 # define V8_NOINLINE /* NOT SUPPORTED */ 323 #endif 324 325 326 // A macro to mark classes or functions as deprecated. 327 #if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE 328 # define V8_DEPRECATED(message, declarator) \ 329 declarator __attribute__((deprecated(message))) 330 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED 331 # define V8_DEPRECATED(message, declarator) \ 332 declarator __attribute__((deprecated)) 333 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED 334 # define V8_DEPRECATED(message, declarator) __declspec(deprecated) declarator 335 #else 336 # define V8_DEPRECATED(message, declarator) declarator 337 #endif 338 339 340 // A macro to mark variables or types as unused, avoiding compiler warnings. 341 #if V8_HAS_ATTRIBUTE_UNUSED 342 # define V8_UNUSED __attribute__((unused)) 343 #else 344 # define V8_UNUSED 345 #endif 346 347 348 // Annotate a function indicating the caller must examine the return value. 349 // Use like: 350 // int foo() V8_WARN_UNUSED_RESULT; 351 #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT 352 # define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 353 #else 354 # define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */ 355 #endif 356 357 358 // A macro to provide the compiler with branch prediction information. 359 #if V8_HAS_BUILTIN_EXPECT 360 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0)) 361 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1)) 362 #else 363 # define V8_UNLIKELY(condition) (condition) 364 # define V8_LIKELY(condition) (condition) 365 #endif 366 367 368 // A macro to specify that a method is deleted from the corresponding class. 369 // Any attempt to use the method will always produce an error at compile time 370 // when this macro can be implemented (i.e. if the compiler supports C++11). 371 // If the current compiler does not support C++11, use of the annotated method 372 // will still cause an error, but the error will most likely occur at link time 373 // rather than at compile time. As a backstop, method declarations using this 374 // macro should be private. 375 // Use like: 376 // class A { 377 // private: 378 // A(const A& other) V8_DELETE; 379 // A& operator=(const A& other) V8_DELETE; 380 // }; 381 #if V8_HAS_CXX11_DELETE 382 # define V8_DELETE = delete 383 #else 384 # define V8_DELETE /* NOT SUPPORTED */ 385 #endif 386 387 388 // Annotate a virtual method indicating it must be overriding a virtual 389 // method in the parent class. 390 // Use like: 391 // virtual void bar() V8_OVERRIDE; 392 #if V8_HAS_CXX11_OVERRIDE 393 # define V8_OVERRIDE override 394 #else 395 # define V8_OVERRIDE /* NOT SUPPORTED */ 396 #endif 397 398 399 // Annotate a virtual method indicating that subclasses must not override it, 400 // or annotate a class to indicate that it cannot be subclassed. 401 // Use like: 402 // class B V8_FINAL : public A {}; 403 // virtual void bar() V8_FINAL; 404 #if V8_HAS_CXX11_FINAL 405 # define V8_FINAL final 406 #elif V8_HAS___FINAL 407 # define V8_FINAL __final 408 #elif V8_HAS_SEALED 409 # define V8_FINAL sealed 410 #else 411 # define V8_FINAL /* NOT SUPPORTED */ 412 #endif 413 414 415 // This macro allows to specify memory alignment for structs, classes, etc. 416 // Use like: 417 // class V8_ALIGNED(16) MyClass { ... }; 418 // V8_ALIGNED(32) int array[42]; 419 #if V8_HAS_CXX11_ALIGNAS 420 # define V8_ALIGNED(n) alignas(n) 421 #elif V8_HAS_ATTRIBUTE_ALIGNED 422 # define V8_ALIGNED(n) __attribute__((aligned(n))) 423 #elif V8_HAS_DECLSPEC_ALIGN 424 # define V8_ALIGNED(n) __declspec(align(n)) 425 #else 426 # define V8_ALIGNED(n) /* NOT SUPPORTED */ 427 #endif 428 429 430 // This macro is similar to V8_ALIGNED(), but takes a type instead of size 431 // in bytes. If the compiler does not supports using the alignment of the 432 // |type|, it will align according to the |alignment| instead. For example, 433 // Visual Studio C++ cannot combine __declspec(align) and __alignof. The 434 // |alignment| must be a literal that is used as a kind of worst-case fallback 435 // alignment. 436 // Use like: 437 // struct V8_ALIGNAS(AnotherClass, 16) NewClass { ... }; 438 // V8_ALIGNAS(double, 8) int array[100]; 439 #if V8_HAS_CXX11_ALIGNAS 440 # define V8_ALIGNAS(type, alignment) alignas(type) 441 #elif V8_HAS___ALIGNOF__ && V8_HAS_ATTRIBUTE_ALIGNED 442 # define V8_ALIGNAS(type, alignment) __attribute__((aligned(__alignof__(type)))) 443 #else 444 # define V8_ALIGNAS(type, alignment) V8_ALIGNED(alignment) 445 #endif 446 447 448 // This macro returns alignment in bytes (an integer power of two) required for 449 // any instance of the given type, which is either complete type, an array type, 450 // or a reference type. 451 // Use like: 452 // size_t alignment = V8_ALIGNOF(double); 453 #if V8_HAS_CXX11_ALIGNOF 454 # define V8_ALIGNOF(type) alignof(type) 455 #elif V8_HAS___ALIGNOF 456 # define V8_ALIGNOF(type) __alignof(type) 457 #elif V8_HAS___ALIGNOF__ 458 # define V8_ALIGNOF(type) __alignof__(type) 459 #else 460 // Note that alignment of a type within a struct can be less than the 461 // alignment of the type stand-alone (because of ancient ABIs), so this 462 // should only be used as a last resort. 463 namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; } 464 # define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type)) 465 #endif 466 467 #endif // V8CONFIG_H_ 468