From 9b164c6eec88be28b8c469c5a18e45140c02ca0e Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 19 Feb 2024 19:15:14 +0100 Subject: [PATCH] src: fix --disable-single-executable-application MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously it would not compile if the build is configured with --disable-single-executable-application because we use directives to exclude the definition of SEA-related code completely. This patch changes them so that the SEA code are still compiled and internals can still check whether the executable is an SEA. The executable would not try to load the SEA blob at all if SEA is disabled. If future modifications to the C++ code attempt to load the SEA blob when SEA is disabled, UNREACHABLE() would be raised. If user attempt to generate the SEA blob with --experimental-sea-config with an executable that disables SEA, they would get an error. PR-URL: https://github.com/nodejs/node/pull/51808 Fixes: https://github.com/nodejs/node/issues/51730 Reviewed-By: Tobias Nießen --- src/node.cc | 7 +++++-- src/node_sea.cc | 8 ++++---- src/node_sea.h | 4 ---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/node.cc b/src/node.cc index 2b41e904180bed..10e04ed8a28bd0 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1441,13 +1441,16 @@ static ExitCode StartInternal(int argc, char** argv) { }); uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME); - std::string sea_config = per_process::cli_options->experimental_sea_config; if (!sea_config.empty()) { +#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION) return sea::BuildSingleExecutableBlob( sea_config, result->args(), result->exec_args()); +#else + fprintf(stderr, "Single executable application is disabled.\n"); + return ExitCode::kGenericUserError; +#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION) } - // --build-snapshot indicates that we are in snapshot building mode. if (per_process::cli_options->per_isolate->build_snapshot) { if (per_process::cli_options->per_isolate->build_snapshot_config.empty() && diff --git a/src/node_sea.cc b/src/node_sea.cc index a254c910edf238..c2b409de731c6e 100644 --- a/src/node_sea.cc +++ b/src/node_sea.cc @@ -27,8 +27,6 @@ #include #include -#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION) - using node::ExitCode; using v8::ArrayBuffer; using v8::BackingStore; @@ -189,6 +187,7 @@ SeaResource SeaDeserializer::Read() { } std::string_view FindSingleExecutableBlob() { +#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION) CHECK(IsSingleExecutable()); static const std::string_view result = []() -> std::string_view { size_t size; @@ -209,6 +208,9 @@ std::string_view FindSingleExecutableBlob() { result.data(), result.size()); return result; +#else + UNREACHABLE(); +#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION) } } // anonymous namespace @@ -668,5 +670,3 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { NODE_BINDING_CONTEXT_AWARE_INTERNAL(sea, node::sea::Initialize) NODE_BINDING_EXTERNAL_REFERENCE(sea, node::sea::RegisterExternalReferences) - -#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION) diff --git a/src/node_sea.h b/src/node_sea.h index bea9d579a2aa64..f90ef63cc7fd33 100644 --- a/src/node_sea.h +++ b/src/node_sea.h @@ -3,8 +3,6 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION) - #include #include #include @@ -52,8 +50,6 @@ node::ExitCode BuildSingleExecutableBlob( } // namespace sea } // namespace node -#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION) - #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_SEA_H_