Skip to content

Commit 7ba16ea

Browse files
backesV8 LUCI CQ
authored andcommitted
[wasm] Skip random module generation code in official builds
The code now lives in src/ so the GenerateRandomWasmModule runtime function can use it; this increases the size of libv8.so though, so skip this code in official builds. To avoid compile failures we still define the GenerateRandomWasmModule function, but make it crash with an "UNIMPLEMENTED" message if it is ever invoked. The runtime function will just not be defined in official builds. [email protected] Bug: v8:14637 Change-Id: I306e73b74152f7432180a407e08d1cd381bb2372 Cq-Include-Trybots: luci.v8.try:v8_linux64_official_rel Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5328108 Reviewed-by: Jakob Kummerow <[email protected]> Commit-Queue: Clemens Backes <[email protected]> Cr-Commit-Position: refs/heads/main@{#92639}
1 parent a582c1f commit 7ba16ea

8 files changed

Lines changed: 87 additions & 45 deletions

File tree

BUILD.gn

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5718,7 +5718,6 @@ v8_source_set("v8_base_without_compiler") {
57185718
"src/wasm/constant-expression.cc",
57195719
"src/wasm/function-body-decoder.cc",
57205720
"src/wasm/function-compiler.cc",
5721-
"src/wasm/fuzzing/random-module-generation.cc",
57225721
"src/wasm/graph-builder-interface.cc",
57235722
"src/wasm/jump-table-assembler.cc",
57245723
"src/wasm/local-decl-encoder.cc",
@@ -5753,6 +5752,12 @@ v8_source_set("v8_base_without_compiler") {
57535752
"src/wasm/well-known-imports.cc",
57545753
"src/wasm/wrappers.cc",
57555754
]
5755+
if (!is_official_build) {
5756+
sources += [
5757+
### gcmole(all) ###
5758+
"src/wasm/fuzzing/random-module-generation.cc",
5759+
]
5760+
}
57565761
}
57575762

57585763
if (v8_enable_third_party_heap) {

src/base/macros.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,18 @@ bool is_inbounds(float_t v) {
427427
#define IF_TARGET_ARCH_64_BIT(V, ...) EXPAND(V(__VA_ARGS__))
428428
#else
429429
#define IF_TARGET_ARCH_64_BIT(V, ...)
430-
#endif
430+
#endif // V8_TARGET_ARCH_64_BIT
431+
432+
// Defines IF_OFFICIAL_BUILD and IF_NO_OFFICIAL_BUILD, to be used in macro lists
433+
// for elements that should only be there in official / non-official builds.
434+
#ifdef OFFICIAL_BUILD
435+
// EXPAND is needed to work around MSVC's broken __VA_ARGS__ expansion.
436+
#define IF_OFFICIAL_BUILD(V, ...) EXPAND(V(__VA_ARGS__))
437+
#define IF_NO_OFFICIAL_BUILD(V, ...)
438+
#else
439+
#define IF_OFFICIAL_BUILD(V, ...)
440+
#define IF_NO_OFFICIAL_BUILD(V, ...) EXPAND(V(__VA_ARGS__))
441+
#endif // OFFICIAL_BUILD
431442

432443
#ifdef GOOGLE3
433444
// Disable FRIEND_TEST macro in Google3.

src/runtime/runtime-test-wasm.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,11 @@ RUNTIME_FUNCTION(Runtime_CheckIsOnCentralStack) {
687687
return ReadOnlyRoots(isolate).undefined_value();
688688
}
689689

690-
RUNTIME_FUNCTION(Runtime_WasmGenerateRandomModule) {
691-
// Skip this runtime function in official builds to save binary size.
690+
// The GenerateRandomWasmModule function is only implemented in non-official
691+
// builds (to save binary size). Hence also skip the runtime function in
692+
// official builds.
692693
#ifndef OFFICIAL_BUILD
694+
RUNTIME_FUNCTION(Runtime_WasmGenerateRandomModule) {
693695
HandleScope scope{isolate};
694696
Zone temporary_zone{isolate->allocator(), "WasmGenerateRandomModule"};
695697
constexpr size_t kMaxInputBytes = 512;
@@ -746,9 +748,7 @@ RUNTIME_FUNCTION(Runtime_WasmGenerateRandomModule) {
746748
thrower.error_msg());
747749
}
748750
return *maybe_module_object.ToHandleChecked();
749-
#else
750-
return ReadOnlyRoots(isolate).undefined_value();
751-
#endif // DEBUG
752751
}
752+
#endif // OFFICIAL_BUILD
753753

754754
} // namespace v8::internal

src/runtime/runtime.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ bool Runtime::IsAllowListedForFuzzing(FunctionId id) {
219219
case Runtime::kNotifyIsolateForeground:
220220
case Runtime::kNotifyIsolateBackground:
221221
case Runtime::kIsEfficiencyModeEnabled:
222-
#if V8_ENABLE_WEBASSEMBLY
222+
#if V8_ENABLE_WEBASSEMBLY && !defined(OFFICIAL_BUILD)
223223
case Runtime::kWasmGenerateRandomModule:
224224
#endif // V8_ENABLE_WEBASSEMBLY
225225
return true;

src/runtime/runtime.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -687,41 +687,41 @@ namespace internal {
687687
F(WasmStringHash, 1, 1) \
688688
F(WasmSubstring, 3, 1)
689689

690-
#define FOR_EACH_INTRINSIC_WASM_TEST(F, I) \
691-
F(CheckIsOnCentralStack, 0, 1) \
692-
F(CountUnoptimizedWasmToJSWrapper, 1, 1) \
693-
F(DeserializeWasmModule, 2, 1) \
694-
F(DisallowWasmCodegen, 1, 1) \
695-
F(FlushWasmCode, 0, 1) \
696-
F(FreezeWasmLazyCompilation, 1, 1) \
697-
F(GetWasmExceptionTagId, 2, 1) \
698-
F(GetWasmExceptionValues, 1, 1) \
699-
F(GetWasmRecoveredTrapCount, 0, 1) \
700-
F(HasUnoptimizedJSToJSWrapper, 1, 1) \
701-
F(HasUnoptimizedWasmToJSWrapper, 1, 1) \
702-
F(IsAsmWasmCode, 1, 1) \
703-
F(IsLiftoffFunction, 1, 1) \
704-
F(IsThreadInWasm, 0, 1) \
705-
F(IsTurboFanFunction, 1, 1) \
706-
F(IsUncompiledWasmFunction, 1, 1) \
707-
F(IsWasmCode, 1, 1) \
708-
F(IsWasmDebugFunction, 1, 1) \
709-
F(IsWasmPartialOOBWriteNoop, 0, 1) \
710-
F(IsWasmTrapHandlerEnabled, 0, 1) \
711-
F(SerializeWasmModule, 1, 1) \
712-
F(SetWasmCompileControls, 2, 1) \
713-
F(SetWasmImportedStringsEnabled, 1, 1) \
714-
F(SetWasmInstantiateControls, 0, 1) \
715-
F(WasmCompiledExportWrappersCount, 0, 1) \
716-
F(WasmEnterDebugging, 0, 1) \
717-
F(WasmGenerateRandomModule, -1, 1) \
718-
F(WasmGetNumberOfInstances, 1, 1) \
719-
F(WasmLeaveDebugging, 0, 1) \
720-
F(WasmNumCodeSpaces, 1, 1) \
721-
F(WasmSwitchToTheCentralStackCount, 0, 1) \
722-
F(WasmTierUpFunction, 1, 1) \
723-
F(WasmTraceEnter, 0, 1) \
724-
F(WasmTraceExit, 1, 1) \
690+
#define FOR_EACH_INTRINSIC_WASM_TEST(F, I) \
691+
F(CheckIsOnCentralStack, 0, 1) \
692+
F(CountUnoptimizedWasmToJSWrapper, 1, 1) \
693+
F(DeserializeWasmModule, 2, 1) \
694+
F(DisallowWasmCodegen, 1, 1) \
695+
F(FlushWasmCode, 0, 1) \
696+
F(FreezeWasmLazyCompilation, 1, 1) \
697+
F(GetWasmExceptionTagId, 2, 1) \
698+
F(GetWasmExceptionValues, 1, 1) \
699+
F(GetWasmRecoveredTrapCount, 0, 1) \
700+
F(HasUnoptimizedJSToJSWrapper, 1, 1) \
701+
F(HasUnoptimizedWasmToJSWrapper, 1, 1) \
702+
F(IsAsmWasmCode, 1, 1) \
703+
F(IsLiftoffFunction, 1, 1) \
704+
F(IsThreadInWasm, 0, 1) \
705+
F(IsTurboFanFunction, 1, 1) \
706+
F(IsUncompiledWasmFunction, 1, 1) \
707+
F(IsWasmCode, 1, 1) \
708+
F(IsWasmDebugFunction, 1, 1) \
709+
F(IsWasmPartialOOBWriteNoop, 0, 1) \
710+
F(IsWasmTrapHandlerEnabled, 0, 1) \
711+
F(SerializeWasmModule, 1, 1) \
712+
F(SetWasmCompileControls, 2, 1) \
713+
F(SetWasmImportedStringsEnabled, 1, 1) \
714+
F(SetWasmInstantiateControls, 0, 1) \
715+
F(WasmCompiledExportWrappersCount, 0, 1) \
716+
F(WasmEnterDebugging, 0, 1) \
717+
IF_NO_OFFICIAL_BUILD(F, WasmGenerateRandomModule, -1, 1) \
718+
F(WasmGetNumberOfInstances, 1, 1) \
719+
F(WasmLeaveDebugging, 0, 1) \
720+
F(WasmNumCodeSpaces, 1, 1) \
721+
F(WasmSwitchToTheCentralStackCount, 0, 1) \
722+
F(WasmTierUpFunction, 1, 1) \
723+
F(WasmTraceEnter, 0, 1) \
724+
F(WasmTraceExit, 1, 1) \
725725
F(WasmTraceMemory, 1, 1)
726726

727727
#define FOR_EACH_INTRINSIC_WEAKREF(F, I) \

src/wasm/fuzzing/random-module-generation.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
#include "src/wasm/wasm-module.h"
1515
#include "src/wasm/wasm-opcodes-inl.h"
1616

17+
// This whole compilation unit should only be included in non-official builds to
18+
// reduce binary size (it's a testing-only implementation which lives in src/ so
19+
// that the GenerateRandomWasmModule runtime function can use it).
20+
#ifdef OFFICIAL_BUILD
21+
#error Exclude this compilation unit in official builds.
22+
#endif
23+
1724
namespace v8::internal::wasm::fuzzing {
1825

1926
namespace {
@@ -3527,8 +3534,6 @@ WasmInitExpr GenerateInitExpr(Zone* zone, DataRange& range,
35273534
}
35283535
} // namespace
35293536

3530-
// TODO(14637): Replace this by an empty implementation in release builds to
3531-
// reduce binary size.
35323537
base::Vector<uint8_t> GenerateRandomWasmModule(
35333538
Zone* zone, base::Vector<const uint8_t> data) {
35343539
WasmModuleBuilder builder(zone);

src/wasm/fuzzing/random-module-generation.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef V8_WASM_FUZZING_RANDOM_MODULE_GENERATION_H_
1010
#define V8_WASM_FUZZING_RANDOM_MODULE_GENERATION_H_
1111

12+
#include "src/base/logging.h"
1213
#include "src/base/vector.h"
1314

1415
namespace v8::internal {
@@ -20,11 +21,25 @@ namespace v8::internal::wasm::fuzzing {
2021
// Generate a valid Wasm module based on the given input bytes.
2122
// Returns an empty buffer on failure, valid module wire bytes otherwise.
2223
// The bytes will be allocated in the zone.
24+
#ifdef OFFICIAL_BUILD
25+
inline base::Vector<uint8_t> GenerateRandomWasmModule(
26+
Zone*, base::Vector<const uint8_t> data) {
27+
UNIMPLEMENTED();
28+
}
29+
30+
inline base::Vector<uint8_t> GenerateWasmModuleForInitExpressions(
31+
Zone*, base::Vector<const uint8_t> data, size_t* count) {
32+
UNIMPLEMENTED();
33+
}
34+
35+
#else
36+
// Defined in random-module-generation.cc.
2337
V8_EXPORT_PRIVATE base::Vector<uint8_t> GenerateRandomWasmModule(
2438
Zone*, base::Vector<const uint8_t> data);
2539

2640
V8_EXPORT_PRIVATE base::Vector<uint8_t> GenerateWasmModuleForInitExpressions(
2741
Zone*, base::Vector<const uint8_t> data, size_t* count);
42+
#endif
2843

2944
} // namespace v8::internal::wasm::fuzzing
3045

test/fuzzer/fuzzer.status

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@
3434
'wasm/regress-1464231.wasm': [SKIP],
3535
}], # no_simd_hardware == True
3636

37+
##############################################################################
38+
['official_build', {
39+
# Random Wasm module generation is not available on official builds.
40+
'wasm_compile/*': [FAIL],
41+
}], # 'official_build'
42+
3743
]

0 commit comments

Comments
 (0)