Skip to content

Commit

Permalink
src: fix --disable-single-executable-application
Browse files Browse the repository at this point in the history
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: #51808
Fixes: #51730
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
joyeecheung authored and richardlau committed Mar 25, 2024
1 parent 6500f89 commit ffbe6b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Expand Down
8 changes: 4 additions & 4 deletions src/node_sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include <tuple>
#include <vector>

#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)

using node::ExitCode;
using v8::ArrayBuffer;
using v8::BackingStore;
Expand Down Expand Up @@ -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;
Expand All @@ -209,6 +208,9 @@ std::string_view FindSingleExecutableBlob() {
result.data(),
result.size());
return result;
#else
UNREACHABLE();
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
}

} // anonymous namespace
Expand Down Expand Up @@ -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)
4 changes: 0 additions & 4 deletions src/node_sea.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)

#include <cinttypes>
#include <optional>
#include <string>
Expand Down Expand Up @@ -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_

0 comments on commit ffbe6b4

Please sign in to comment.