Skip to content

Commit 5833675

Browse files
joyeecheungrdw-msft
authored andcommitted
src: fix --disable-single-executable-application
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: nodejs#51808 Fixes: nodejs#51730 Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 990aeae commit 5833675

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/node.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -1445,13 +1445,16 @@ static ExitCode StartInternal(int argc, char** argv) {
14451445
});
14461446

14471447
uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME);
1448-
14491448
std::string sea_config = per_process::cli_options->experimental_sea_config;
14501449
if (!sea_config.empty()) {
1450+
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
14511451
return sea::BuildSingleExecutableBlob(
14521452
sea_config, result->args(), result->exec_args());
1453+
#else
1454+
fprintf(stderr, "Single executable application is disabled.\n");
1455+
return ExitCode::kGenericUserError;
1456+
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
14531457
}
1454-
14551458
// --build-snapshot indicates that we are in snapshot building mode.
14561459
if (per_process::cli_options->per_isolate->build_snapshot) {
14571460
if (per_process::cli_options->per_isolate->build_snapshot_config.empty() &&

src/node_sea.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include <tuple>
2828
#include <vector>
2929

30-
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
31-
3230
using node::ExitCode;
3331
using v8::ArrayBuffer;
3432
using v8::BackingStore;
@@ -189,6 +187,7 @@ SeaResource SeaDeserializer::Read() {
189187
}
190188

191189
std::string_view FindSingleExecutableBlob() {
190+
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
192191
CHECK(IsSingleExecutable());
193192
static const std::string_view result = []() -> std::string_view {
194193
size_t size;
@@ -209,6 +208,9 @@ std::string_view FindSingleExecutableBlob() {
209208
result.data(),
210209
result.size());
211210
return result;
211+
#else
212+
UNREACHABLE();
213+
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
212214
}
213215

214216
} // anonymous namespace
@@ -668,5 +670,3 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
668670

669671
NODE_BINDING_CONTEXT_AWARE_INTERNAL(sea, node::sea::Initialize)
670672
NODE_BINDING_EXTERNAL_REFERENCE(sea, node::sea::RegisterExternalReferences)
671-
672-
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)

src/node_sea.h

-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
55

6-
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
7-
86
#include <cinttypes>
97
#include <optional>
108
#include <string>
@@ -52,8 +50,6 @@ node::ExitCode BuildSingleExecutableBlob(
5250
} // namespace sea
5351
} // namespace node
5452

55-
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
56-
5753
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5854

5955
#endif // SRC_NODE_SEA_H_

0 commit comments

Comments
 (0)