Skip to content

Commit 4b20192

Browse files
committed
build: stop exporting V8's internals from the optimized runtime
set_target_properties takes key/value pairs, so the unquoted PROPERTIES LINK_FLAGS -Wl,--allow-multiple-definition -Wl,--exclude-libs=ALL -Wl,--gc-sections set LINK_FLAGS to only -Wl,--allow-multiple-definition and then read -Wl,--exclude-libs=ALL as a property name whose value was -Wl,--gc-sections, which CMake silently discarded. libNativeScript.so was therefore exporting 72,662 dynamic symbols on arm64-v8a, 12.1 MiB of them .dynstr for names V8 never meant to publish. Quote the flag list so all three apply, and hide the internals with a linker version script rather than --exclude-libs=ALL: the latter would also hide V8's public API, which plugins link against. exported-symbols.map keeps the JNI entry points and v8::/cppgc:: public API global and everything else local. arm64-v8a, stripped: 47,433,360 -> 26,773,104 bytes; 72,662 -> 1,748 exported symbols, of which 8 v8::internal:: template instantiations whose demangled name begins with a v8::Maybe<T> return type.
1 parent bab7ce3 commit 4b20192

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

test-app/runtime/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ set(NATIVES_BLOB_INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDRO
174174
if (OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
175175
set_target_properties(
176176
NativeScript
177-
PROPERTIES LINK_FLAGS -Wl,--allow-multiple-definition -Wl,--exclude-libs=ALL -Wl,--gc-sections
177+
# The version script keeps V8's public API linkable for plugins while hiding
178+
# the ~60k v8::internal:: symbols the static monolith would otherwise export.
179+
PROPERTIES LINK_FLAGS "-Wl,--allow-multiple-definition -Wl,--gc-sections -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exported-symbols.map"
178180
INTERFACE_INCLUDE_DIRECTORIES NATIVES_BLOB_INCLUDE_DIRECTORIES
179181
)
180182
else ()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* V8's public API lives directly under v8:: with an uppercase first letter
3+
* (v8::Isolate, v8::Context, ...) while everything private is nested in
4+
* v8::internal::. The split has to be made by case here: lld resolves a symbol
5+
* matched by both a global: and a local: pattern in favour of global:, so the
6+
* internals cannot be carved back out with a "local: v8::internal::*" entry.
7+
*
8+
* Patterns must stay unquoted -- a quoted string is matched literally, not as a
9+
* wildcard.
10+
*/
11+
{
12+
global:
13+
Java_*;
14+
JNI_OnLoad;
15+
extern "C++" {
16+
v8::[A-Z]*;
17+
v8::api_internal::*;
18+
v8::platform::*;
19+
cppgc::[A-Z]*;
20+
};
21+
local:
22+
*;
23+
};

0 commit comments

Comments
 (0)