Skip to content

Commit 7f09d98

Browse files
joyeecheungtargos
authored andcommittedOct 2, 2024
sea: don't set code cache flags when snapshot is used
When both useCodeCache and useSnapshot are set, we generate the snapshot and skip the generation of the code cache since the snapshot already includes the code cache. But we previously still persist the code cache setting in the flags that got serialized into the SEA, so the resulting executable would still try to read the code cache even if it's not added to the SEA, leading to a flaky crash caused by OOB on some platforms. This patch fixes the crash by ignoring the code cache setting when generating the flag if both snapshot and code cache is configured. PR-URL: #54120 Fixes: #50740 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent c114585 commit 7f09d98

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed
 

‎src/node_sea.cc

+15-13
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,14 @@ std::optional<SeaConfig> ParseSingleExecutableConfig(
373373
return std::nullopt;
374374
}
375375
if (use_code_cache.value()) {
376-
result.flags |= SeaFlags::kUseCodeCache;
376+
if (use_snapshot.value()) {
377+
// TODO(joyeecheung): code cache in snapshot should be configured by
378+
// separate snapshot configurations.
379+
FPrintF(stderr,
380+
"\"useCodeCache\" is redundant when \"useSnapshot\" is true\n");
381+
} else {
382+
result.flags |= SeaFlags::kUseCodeCache;
383+
}
377384
}
378385

379386
auto assets_opt = parser.GetTopLevelStringDict("assets");
@@ -529,19 +536,14 @@ ExitCode GenerateSingleExecutableBlob(
529536
std::optional<std::string_view> optional_sv_code_cache;
530537
std::string code_cache;
531538
if (static_cast<bool>(config.flags & SeaFlags::kUseCodeCache)) {
532-
if (builds_snapshot_from_main) {
533-
FPrintF(stderr,
534-
"\"useCodeCache\" is redundant when \"useSnapshot\" is true\n");
535-
} else {
536-
std::optional<std::string> optional_code_cache =
537-
GenerateCodeCache(config.main_path, main_script);
538-
if (!optional_code_cache.has_value()) {
539-
FPrintF(stderr, "Cannot generate V8 code cache\n");
540-
return ExitCode::kGenericUserError;
541-
}
542-
code_cache = optional_code_cache.value();
543-
optional_sv_code_cache = code_cache;
539+
std::optional<std::string> optional_code_cache =
540+
GenerateCodeCache(config.main_path, main_script);
541+
if (!optional_code_cache.has_value()) {
542+
FPrintF(stderr, "Cannot generate V8 code cache\n");
543+
return ExitCode::kGenericUserError;
544544
}
545+
code_cache = optional_code_cache.value();
546+
optional_sv_code_cache = code_cache;
545547
}
546548

547549
std::unordered_map<std::string, std::string> assets;

0 commit comments

Comments
 (0)
Please sign in to comment.