Skip to content

Commit

Permalink
fix: don't export private V8 symbols that can cause native node modul…
Browse files Browse the repository at this point in the history
…es to crash (#18281)
  • Loading branch information
torycl authored and miniak committed Jun 4, 2019
1 parent 7a2777c commit 794c878
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions patches/common/v8/.patches
Expand Up @@ -8,3 +8,4 @@ do_not_run_arm_arm64_mksnapshot_binaries.patch
deps_provide_more_v8_backwards_compatibility.patch
dcheck.patch
expose_protected_v8_platform_systemclocktimemillis.patch
do_not_export_private_v8_symbols_on_windows.patch
@@ -0,0 +1,52 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tomas Rycl <torycl@microsoft.com>
Date: Mon, 13 May 2019 15:48:48 +0200
Subject: Do not export private V8 symbols on Windows

This change stops private V8 symbols and internal crt methods being exported.
It fixes an issue where native node modules can import
incorrect CRT methods and crash on Windows.
It also reduces size of node.lib by 75%.

This patch can be safely removed if, when it is removed, `node.lib` does not
contain any standard C++ library exports (e.g. `std::ostringstream`).

diff --git a/BUILD.gn b/BUILD.gn
index 315c7079ed488461a456aff799b4d1f17b896150..0f668eae73686c02a7133df31a79e8a0a7b77707 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -273,6 +273,10 @@ config("internal_config") {
":v8_header_features",
]

+ if (!is_component_build && is_electron_build) {
+ defines += [ "HIDE_PRIVATE_SYMBOLS" ]
+ }
+
if (is_component_build || is_electron_build) {
defines += [ "BUILDING_V8_SHARED" ]
}
diff --git a/src/base/macros.h b/src/base/macros.h
index ad70e9820ddb4a63639ca7738c1836cb87766db5..d40be9b57294583f74594d88d9b7d7b937b2db3c 100644
--- a/src/base/macros.h
+++ b/src/base/macros.h
@@ -414,13 +414,17 @@ bool is_inbounds(float_t v) {
#ifdef V8_OS_WIN

// Setup for Windows shared library export.
+#if defined(HIDE_PRIVATE_SYMBOLS)
+#define V8_EXPORT_PRIVATE
+#else //if !defined(HIDE_PRIVATE_SYMBOLS)
#ifdef BUILDING_V8_SHARED
#define V8_EXPORT_PRIVATE __declspec(dllexport)
#elif USING_V8_SHARED
#define V8_EXPORT_PRIVATE __declspec(dllimport)
-#else
+#else //!(BUILDING_V8_SHARED || USING_V8_SHARED)
#define V8_EXPORT_PRIVATE
-#endif // BUILDING_V8_SHARED
+#endif
+#endif

#else // V8_OS_WIN

0 comments on commit 794c878

Please sign in to comment.