v8config.h 15 KB

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