Skip to content

Commit 9b164c6

Browse files
joyeecheungrichardlau
authored andcommittedMar 25, 2024
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: #51808 Fixes: #51730 Reviewed-By: Tobias Nießen <[email protected]>
1 parent 3be5ff9 commit 9b164c6

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
@@ -1441,13 +1441,16 @@ static ExitCode StartInternal(int argc, char** argv) {
14411441
});
14421442

14431443
uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME);
1444-
14451444
std::string sea_config = per_process::cli_options->experimental_sea_config;
14461445
if (!sea_config.empty()) {
1446+
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
14471447
return sea::BuildSingleExecutableBlob(
14481448
sea_config, result->args(), result->exec_args());
1449+
#else
1450+
fprintf(stderr, "Single executable application is disabled.\n");
1451+
return ExitCode::kGenericUserError;
1452+
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
14491453
}
1450-
14511454
// --build-snapshot indicates that we are in snapshot building mode.
14521455
if (per_process::cli_options->per_isolate->build_snapshot) {
14531456
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)
Please sign in to comment.