Skip to content

Commit

Permalink
src: lazily initialize global BuiltinLoader
Browse files Browse the repository at this point in the history
Using simdutf during startup can fail when compilation units are
linked in the wrong order by a static initialization order issue.

nodejs#46235 would also solve this,
but since that is a larger effort, this patch focuses on solving
the immediate problem. Alternatively, simdutf should arguably
be made usable during static initialization, but that is also not
as straightforward as this patch.

Fixes: nodejs#46235
  • Loading branch information
addaleax committed Jan 18, 2023
1 parent 671ffd7 commit 636924e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ using v8::String;
using v8::Undefined;
using v8::Value;

BuiltinLoader BuiltinLoader::instance_;

BuiltinLoader::BuiltinLoader() : config_(GetConfig()), has_code_cache_(false) {
LoadJavaScriptSource();
#ifdef NODE_SHARED_BUILTIN_CJS_MODULE_LEXER_LEXER_PATH
Expand All @@ -55,6 +53,7 @@ BuiltinLoader::BuiltinLoader() : config_(GetConfig()), has_code_cache_(false) {
}

BuiltinLoader* BuiltinLoader::GetInstance() {
static BuiltinLoader instance_;
return &instance_;
}

Expand Down
1 change: 0 additions & 1 deletion src/node_builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class NODE_EXTERN_PRIVATE BuiltinLoader {

static void AddExternalizedBuiltin(const char* id, const char* filename);

static BuiltinLoader instance_;
BuiltinCategories builtin_categories_;
BuiltinSourceMap source_;
BuiltinCodeCacheMap code_cache_;
Expand Down
2 changes: 1 addition & 1 deletion test/cctest/test_per_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using node::builtins::BuiltinSourceMap;
class PerProcessTest : public ::testing::Test {
protected:
static const BuiltinSourceMap get_sources_for_test() {
return BuiltinLoader::instance_.source_;
return BuiltinLoader::GetInstance()->source_;
}
};

Expand Down

0 comments on commit 636924e

Please sign in to comment.