v8config.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. #ifdef V8_GN_HEADER
  7. #if __cplusplus >= 201703L && !__has_include("v8-gn.h")
  8. #error Missing v8-gn.h. The configuration for v8 is missing from the include \
  9. path. Add it with -I<path> to the command line
  10. #endif
  11. #include "v8-gn.h" // NOLINT(build/include_directory)
  12. #endif
  13. // clang-format off
  14. // Platform headers for feature detection below.
  15. #if defined(__ANDROID__)
  16. # include <sys/cdefs.h>
  17. #elif defined(__APPLE__)
  18. # include <TargetConditionals.h>
  19. #elif defined(__linux__)
  20. # include <features.h>
  21. #endif
  22. // This macro allows to test for the version of the GNU C library (or
  23. // a compatible C library that masquerades as glibc). It evaluates to
  24. // 0 if libc is not GNU libc or compatible.
  25. // Use like:
  26. // #if V8_GLIBC_PREREQ(2, 3)
  27. // ...
  28. // #endif
  29. #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
  30. # define V8_GLIBC_PREREQ(major, minor) \
  31. ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor)))
  32. #else
  33. # define V8_GLIBC_PREREQ(major, minor) 0
  34. #endif
  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. // Operating system detection (host)
  55. //
  56. // V8_OS_ANDROID - Android
  57. // V8_OS_BSD - BSDish (macOS, Net/Free/Open/DragonFlyBSD)
  58. // V8_OS_CYGWIN - Cygwin
  59. // V8_OS_DRAGONFLYBSD - DragonFlyBSD
  60. // V8_OS_FREEBSD - FreeBSD
  61. // V8_OS_FUCHSIA - Fuchsia
  62. // V8_OS_LINUX - Linux (Android, ChromeOS, Linux, ...)
  63. // V8_OS_DARWIN - Darwin (macOS, iOS)
  64. // V8_OS_MACOS - macOS
  65. // V8_OS_IOS - iOS
  66. // V8_OS_NETBSD - NetBSD
  67. // V8_OS_OPENBSD - OpenBSD
  68. // V8_OS_POSIX - POSIX compatible (mostly everything except Windows)
  69. // V8_OS_QNX - QNX Neutrino
  70. // V8_OS_SOLARIS - Sun Solaris and OpenSolaris
  71. // V8_OS_STARBOARD - Starboard (platform abstraction for Cobalt)
  72. // V8_OS_AIX - AIX
  73. // V8_OS_WIN - Microsoft Windows
  74. #if defined(__ANDROID__)
  75. # define V8_OS_ANDROID 1
  76. # define V8_OS_LINUX 1
  77. # define V8_OS_POSIX 1
  78. # define V8_OS_STRING "android"
  79. #elif defined(__APPLE__)
  80. # define V8_OS_POSIX 1
  81. # define V8_OS_BSD 1
  82. # define V8_OS_DARWIN 1
  83. # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
  84. # define V8_OS_IOS 1
  85. # define V8_OS_STRING "ios"
  86. # else
  87. # define V8_OS_MACOS 1
  88. # define V8_OS_STRING "macos"
  89. # endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
  90. #elif defined(__CYGWIN__)
  91. # define V8_OS_CYGWIN 1
  92. # define V8_OS_POSIX 1
  93. # define V8_OS_STRING "cygwin"
  94. #elif defined(__linux__)
  95. # define V8_OS_LINUX 1
  96. # define V8_OS_POSIX 1
  97. # define V8_OS_STRING "linux"
  98. #elif defined(__sun)
  99. # define V8_OS_POSIX 1
  100. # define V8_OS_SOLARIS 1
  101. # define V8_OS_STRING "sun"
  102. #elif defined(STARBOARD)
  103. # define V8_OS_STARBOARD 1
  104. # define V8_OS_STRING "starboard"
  105. #elif defined(_AIX)
  106. # define V8_OS_POSIX 1
  107. # define V8_OS_AIX 1
  108. # define V8_OS_STRING "aix"
  109. #elif defined(__FreeBSD__)
  110. # define V8_OS_BSD 1
  111. # define V8_OS_FREEBSD 1
  112. # define V8_OS_POSIX 1
  113. # define V8_OS_STRING "freebsd"
  114. #elif defined(__Fuchsia__)
  115. # define V8_OS_FUCHSIA 1
  116. # define V8_OS_POSIX 1
  117. # define V8_OS_STRING "fuchsia"
  118. #elif defined(__DragonFly__)
  119. # define V8_OS_BSD 1
  120. # define V8_OS_DRAGONFLYBSD 1
  121. # define V8_OS_POSIX 1
  122. # define V8_OS_STRING "dragonflybsd"
  123. #elif defined(__NetBSD__)
  124. # define V8_OS_BSD 1
  125. # define V8_OS_NETBSD 1
  126. # define V8_OS_POSIX 1
  127. # define V8_OS_STRING "netbsd"
  128. #elif defined(__OpenBSD__)
  129. # define V8_OS_BSD 1
  130. # define V8_OS_OPENBSD 1
  131. # define V8_OS_POSIX 1
  132. # define V8_OS_STRING "openbsd"
  133. #elif defined(__QNXNTO__)
  134. # define V8_OS_POSIX 1
  135. # define V8_OS_QNX 1
  136. # define V8_OS_STRING "qnx"
  137. #elif defined(_WIN32)
  138. # define V8_OS_WIN 1
  139. # define V8_OS_STRING "windows"
  140. #endif
  141. // -----------------------------------------------------------------------------
  142. // Operating system detection (target)
  143. //
  144. // V8_TARGET_OS_ANDROID
  145. // V8_TARGET_OS_FUCHSIA
  146. // V8_TARGET_OS_IOS
  147. // V8_TARGET_OS_LINUX
  148. // V8_TARGET_OS_MACOS
  149. // V8_TARGET_OS_WIN
  150. //
  151. // If not set explicitly, these fall back to corresponding V8_OS_ values.
  152. #ifdef V8_HAVE_TARGET_OS
  153. // The target OS is provided, just check that at least one known value is set.
  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_MACOS) \
  159. && !defined(V8_TARGET_OS_WIN)
  160. # error No known target OS defined.
  161. # endif
  162. #else // V8_HAVE_TARGET_OS
  163. # if defined(V8_TARGET_OS_ANDROID) \
  164. || defined(V8_TARGET_OS_FUCHSIA) \
  165. || defined(V8_TARGET_OS_IOS) \
  166. || defined(V8_TARGET_OS_LINUX) \
  167. || defined(V8_TARGET_OS_MACOS) \
  168. || defined(V8_TARGET_OS_WIN)
  169. # error A target OS is defined but V8_HAVE_TARGET_OS is unset.
  170. # endif
  171. // Fall back to the detected host OS.
  172. #ifdef V8_OS_ANDROID
  173. # define V8_TARGET_OS_ANDROID
  174. #endif
  175. #ifdef V8_OS_FUCHSIA
  176. # define V8_TARGET_OS_FUCHSIA
  177. #endif
  178. #ifdef V8_OS_IOS
  179. # define V8_TARGET_OS_IOS
  180. #endif
  181. #ifdef V8_OS_LINUX
  182. # define V8_TARGET_OS_LINUX
  183. #endif
  184. #ifdef V8_OS_MACOS
  185. # define V8_TARGET_OS_MACOS
  186. #endif
  187. #ifdef V8_OS_WIN
  188. # define V8_TARGET_OS_WIN
  189. #endif
  190. #endif // V8_HAVE_TARGET_OS
  191. #if defined(V8_TARGET_OS_ANDROID)
  192. # define V8_TARGET_OS_STRING "android"
  193. #elif defined(V8_TARGET_OS_FUCHSIA)
  194. # define V8_TARGET_OS_STRING "fuchsia"
  195. #elif defined(V8_TARGET_OS_IOS)
  196. # define V8_TARGET_OS_STRING "ios"
  197. #elif defined(V8_TARGET_OS_LINUX)
  198. # define V8_TARGET_OS_STRING "linux"
  199. #elif defined(V8_TARGET_OS_MACOS)
  200. # define V8_TARGET_OS_STRING "macos"
  201. #elif defined(V8_TARGET_OS_WINDOWS)
  202. # define V8_TARGET_OS_STRING "windows"
  203. #else
  204. # define V8_TARGET_OS_STRING "unknown"
  205. #endif
  206. // -----------------------------------------------------------------------------
  207. // C library detection
  208. //
  209. // V8_LIBC_MSVCRT - MSVC libc
  210. // V8_LIBC_BIONIC - Bionic libc
  211. // V8_LIBC_BSD - BSD libc derivate
  212. // V8_LIBC_GLIBC - GNU C library
  213. // V8_LIBC_UCLIBC - uClibc
  214. //
  215. // Note that testing for libc must be done using #if not #ifdef. For example,
  216. // to test for the GNU C library, use:
  217. // #if V8_LIBC_GLIBC
  218. // ...
  219. // #endif
  220. #if defined (_MSC_VER)
  221. # define V8_LIBC_MSVCRT 1
  222. #elif defined(__BIONIC__)
  223. # define V8_LIBC_BIONIC 1
  224. # define V8_LIBC_BSD 1
  225. #elif defined(__UCLIBC__)
  226. // Must test for UCLIBC before GLIBC, as UCLIBC pretends to be GLIBC.
  227. # define V8_LIBC_UCLIBC 1
  228. #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__)
  229. # define V8_LIBC_GLIBC 1
  230. #else
  231. # define V8_LIBC_BSD V8_OS_BSD
  232. #endif
  233. // -----------------------------------------------------------------------------
  234. // Compiler detection
  235. //
  236. // V8_CC_GNU - GCC, or clang in gcc mode
  237. // V8_CC_INTEL - Intel C++
  238. // V8_CC_MINGW - Minimalist GNU for Windows
  239. // V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32)
  240. // V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64)
  241. // V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode
  242. //
  243. // C++11 feature detection
  244. //
  245. // Compiler-specific feature detection
  246. //
  247. // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline))
  248. // supported
  249. // V8_HAS_ATTRIBUTE_NONNULL - __attribute__((nonnull)) supported
  250. // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported
  251. // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported
  252. // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported
  253. // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
  254. // supported
  255. // V8_HAS_CPP_ATTRIBUTE_NODISCARD - [[nodiscard]] supported
  256. // V8_HAS_CPP_ATTRIBUTE_NO_UNIQUE_ADDRESS
  257. // - [[no_unique_address]] supported
  258. // V8_HAS_BUILTIN_BSWAP16 - __builtin_bswap16() supported
  259. // V8_HAS_BUILTIN_BSWAP32 - __builtin_bswap32() supported
  260. // V8_HAS_BUILTIN_BSWAP64 - __builtin_bswap64() supported
  261. // V8_HAS_BUILTIN_CLZ - __builtin_clz() supported
  262. // V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported
  263. // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported
  264. // V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported
  265. // V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported
  266. // V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported
  267. // V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported
  268. // V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported
  269. // V8_HAS_COMPUTED_GOTO - computed goto/labels as values
  270. // supported
  271. // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported
  272. // V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported
  273. // V8_HAS___FORCEINLINE - __forceinline supported
  274. //
  275. // Note that testing for compilers and/or features must be done using #if
  276. // not #ifdef. For example, to test for Intel C++ Compiler, use:
  277. // #if V8_CC_INTEL
  278. // ...
  279. // #endif
  280. #if defined(__has_cpp_attribute)
  281. #define V8_HAS_CPP_ATTRIBUTE(FEATURE) __has_cpp_attribute(FEATURE)
  282. #else
  283. #define V8_HAS_CPP_ATTRIBUTE(FEATURE) 0
  284. #endif
  285. #if defined(__clang__)
  286. #if defined(__GNUC__) // Clang in gcc mode.
  287. # define V8_CC_GNU 1
  288. #endif
  289. # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
  290. # define V8_HAS_ATTRIBUTE_NONNULL (__has_attribute(nonnull))
  291. # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
  292. # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
  293. # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
  294. # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
  295. (__has_attribute(warn_unused_result))
  296. # define V8_HAS_CPP_ATTRIBUTE_NODISCARD (V8_HAS_CPP_ATTRIBUTE(nodiscard))
  297. # define V8_HAS_CPP_ATTRIBUTE_NO_UNIQUE_ADDRESS \
  298. (V8_HAS_CPP_ATTRIBUTE(no_unique_address))
  299. # define V8_HAS_BUILTIN_ASSUME_ALIGNED (__has_builtin(__builtin_assume_aligned))
  300. # define V8_HAS_BUILTIN_BSWAP16 (__has_builtin(__builtin_bswap16))
  301. # define V8_HAS_BUILTIN_BSWAP32 (__has_builtin(__builtin_bswap32))
  302. # define V8_HAS_BUILTIN_BSWAP64 (__has_builtin(__builtin_bswap64))
  303. # define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz))
  304. # define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz))
  305. # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
  306. # define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address))
  307. # define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount))
  308. # define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow))
  309. # define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow))
  310. # define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow))
  311. // Clang has no __has_feature for computed gotos.
  312. // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
  313. # define V8_HAS_COMPUTED_GOTO 1
  314. #elif defined(__GNUC__)
  315. # define V8_CC_GNU 1
  316. # if defined(__INTEL_COMPILER) // Intel C++ also masquerades as GCC 3.2.0
  317. # define V8_CC_INTEL 1
  318. # endif
  319. # if defined(__MINGW32__)
  320. # define V8_CC_MINGW32 1
  321. # endif
  322. # if defined(__MINGW64__)
  323. # define V8_CC_MINGW64 1
  324. # endif
  325. # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
  326. // always_inline is available in gcc 4.0 but not very reliable until 4.4.
  327. // Works around "sorry, unimplemented: inlining failed" build errors with
  328. // older compilers.
  329. # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE 1
  330. # define V8_HAS_ATTRIBUTE_NOINLINE 1
  331. # define V8_HAS_ATTRIBUTE_UNUSED 1
  332. # define V8_HAS_ATTRIBUTE_VISIBILITY 1
  333. # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT (!V8_CC_INTEL)
  334. // [[nodiscard]] does not work together with with
  335. // __attribute__((visibility(""))) on GCC 7.4 which is why there is no define
  336. // for V8_HAS_CPP_ATTRIBUTE_NODISCARD. See https://crbug.com/v8/11707.
  337. # define V8_HAS_BUILTIN_ASSUME_ALIGNED 1
  338. # define V8_HAS_BUILTIN_CLZ 1
  339. # define V8_HAS_BUILTIN_CTZ 1
  340. # define V8_HAS_BUILTIN_EXPECT 1
  341. # define V8_HAS_BUILTIN_FRAME_ADDRESS 1
  342. # define V8_HAS_BUILTIN_POPCOUNT 1
  343. // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
  344. #define V8_HAS_COMPUTED_GOTO 1
  345. #endif
  346. #if defined(_MSC_VER)
  347. # define V8_CC_MSVC 1
  348. # define V8_HAS_DECLSPEC_NOINLINE 1
  349. # define V8_HAS_DECLSPEC_SELECTANY 1
  350. # define V8_HAS___FORCEINLINE 1
  351. #endif
  352. // -----------------------------------------------------------------------------
  353. // Helper macros
  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. #if V8_HAS_BUILTIN_ASSUME_ALIGNED
  365. # define V8_ASSUME_ALIGNED(ptr, alignment) \
  366. __builtin_assume_aligned((ptr), (alignment))
  367. #else
  368. # define V8_ASSUME_ALIGNED(ptr, alignment) (ptr)
  369. #endif
  370. // A macro to mark specific arguments as non-null.
  371. // Use like:
  372. // int add(int* x, int y, int* z) V8_NONNULL(1, 3) { return *x + y + *z; }
  373. #if V8_HAS_ATTRIBUTE_NONNULL
  374. # define V8_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
  375. #else
  376. # define V8_NONNULL(...) /* NOT SUPPORTED */
  377. #endif
  378. // A macro used to tell the compiler to never inline a particular function.
  379. // Use like:
  380. // V8_NOINLINE int GetMinusOne() { return -1; }
  381. #if V8_HAS_ATTRIBUTE_NOINLINE
  382. # define V8_NOINLINE __attribute__((noinline))
  383. #elif V8_HAS_DECLSPEC_NOINLINE
  384. # define V8_NOINLINE __declspec(noinline)
  385. #else
  386. # define V8_NOINLINE /* NOT SUPPORTED */
  387. #endif
  388. // A macro (V8_DEPRECATED) to mark classes or functions as deprecated.
  389. #if defined(V8_DEPRECATION_WARNINGS)
  390. # define V8_DEPRECATED(message) [[deprecated(message)]]
  391. #else
  392. # define V8_DEPRECATED(message)
  393. #endif
  394. // A macro (V8_DEPRECATE_SOON) to make it easier to see what will be deprecated.
  395. #if defined(V8_IMMINENT_DEPRECATION_WARNINGS)
  396. # define V8_DEPRECATE_SOON(message) [[deprecated(message)]]
  397. #else
  398. # define V8_DEPRECATE_SOON(message)
  399. #endif
  400. #if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 6)
  401. # define V8_ENUM_DEPRECATED(message)
  402. # define V8_ENUM_DEPRECATE_SOON(message)
  403. #else
  404. # define V8_ENUM_DEPRECATED(message) V8_DEPRECATED(message)
  405. # define V8_ENUM_DEPRECATE_SOON(message) V8_DEPRECATE_SOON(message)
  406. #endif
  407. // A macro to provide the compiler with branch prediction information.
  408. #if V8_HAS_BUILTIN_EXPECT
  409. # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
  410. # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1))
  411. #else
  412. # define V8_UNLIKELY(condition) (condition)
  413. # define V8_LIKELY(condition) (condition)
  414. #endif
  415. // Annotate a function indicating the caller must examine the return value.
  416. // Use like:
  417. // int foo() V8_WARN_UNUSED_RESULT;
  418. #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
  419. #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  420. #else
  421. #define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */
  422. #endif
  423. // Annotate a class or constructor indicating the caller must assign the
  424. // constructed instances.
  425. // Apply to the whole class like:
  426. // class V8_NODISCARD Foo() { ... };
  427. // or apply to just one constructor like:
  428. // V8_NODISCARD Foo() { ... };
  429. // [[nodiscard]] comes in C++17 but supported in clang with -std >= c++11.
  430. #if V8_HAS_CPP_ATTRIBUTE_NODISCARD
  431. #define V8_NODISCARD [[nodiscard]]
  432. #else
  433. #define V8_NODISCARD /* NOT SUPPORTED */
  434. #endif
  435. // The no_unique_address attribute allows tail padding in a non-static data
  436. // member to overlap other members of the enclosing class (and in the special
  437. // case when the type is empty, permits it to fully overlap other members). The
  438. // field is laid out as if a base class were encountered at the corresponding
  439. // point within the class (except that it does not share a vptr with the
  440. // enclosing object).
  441. //
  442. // Apply to a data member like:
  443. //
  444. // class Foo {
  445. // V8_NO_UNIQUE_ADDRESS Bar bar_;
  446. // };
  447. //
  448. // [[no_unique_address]] comes in C++20 but supported in clang with
  449. // -std >= c++11.
  450. #if V8_HAS_CPP_ATTRIBUTE_NO_UNIQUE_ADDRESS
  451. #define V8_NO_UNIQUE_ADDRESS [[no_unique_address]]
  452. #else
  453. #define V8_NO_UNIQUE_ADDRESS /* NOT SUPPORTED */
  454. #endif
  455. // Helper macro to define no_sanitize attributes only with clang.
  456. #if defined(__clang__) && defined(__has_attribute)
  457. #if __has_attribute(no_sanitize)
  458. #define V8_CLANG_NO_SANITIZE(what) __attribute__((no_sanitize(what)))
  459. #endif
  460. #endif
  461. #if !defined(V8_CLANG_NO_SANITIZE)
  462. #define V8_CLANG_NO_SANITIZE(what)
  463. #endif
  464. #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
  465. #error Inconsistent build configuration: To build the V8 shared library \
  466. set BUILDING_V8_SHARED, to include its headers for linking against the \
  467. V8 shared library set USING_V8_SHARED.
  468. #endif
  469. #ifdef V8_OS_WIN
  470. // Setup for Windows DLL export/import. When building the V8 DLL the
  471. // BUILDING_V8_SHARED needs to be defined. When building a program which uses
  472. // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
  473. // static library or building a program which uses the V8 static library neither
  474. // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
  475. #ifdef BUILDING_V8_SHARED
  476. # define V8_EXPORT __declspec(dllexport)
  477. #elif USING_V8_SHARED
  478. # define V8_EXPORT __declspec(dllimport)
  479. #else
  480. # define V8_EXPORT
  481. #endif // BUILDING_V8_SHARED
  482. #else // V8_OS_WIN
  483. // Setup for Linux shared library export.
  484. #if V8_HAS_ATTRIBUTE_VISIBILITY
  485. # ifdef BUILDING_V8_SHARED
  486. # define V8_EXPORT __attribute__ ((visibility("default")))
  487. # else
  488. # define V8_EXPORT
  489. # endif
  490. #else
  491. # define V8_EXPORT
  492. #endif
  493. #endif // V8_OS_WIN
  494. // The sandbox is available (i.e. defined) when pointer compression
  495. // is enabled, but it is only used when V8_SANDBOX is enabled as
  496. // well. This allows better test coverage of the sandbox.
  497. #if defined(V8_COMPRESS_POINTERS)
  498. #define V8_SANDBOX_IS_AVAILABLE
  499. #endif
  500. #if defined(V8_SANDBOX) && !defined(V8_SANDBOX_IS_AVAILABLE)
  501. #error Inconsistent configuration: sandbox is enabled but not available
  502. #endif
  503. // From C++17 onwards, static constexpr member variables are defined to be
  504. // "inline", and adding a separate definition for them can trigger deprecation
  505. // warnings. For C++14 and below, however, these definitions are required.
  506. #if __cplusplus < 201703L && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)
  507. #define V8_STATIC_CONSTEXPR_VARIABLES_NEED_DEFINITIONS
  508. #endif
  509. // clang-format on
  510. #undef V8_HAS_CPP_ATTRIBUTE
  511. #endif // V8CONFIG_H_