From b79d7a53b206d45258833db77242f14902769376 Mon Sep 17 00:00:00 2001 From: Sergey Markelov Date: Mon, 5 Aug 2024 12:21:25 -0400 Subject: [PATCH] linux: Fix TLS error on dlopen of libcef.so (fixes #3616) --- patch/patch.cfg | 5 +++ .../third_party_sentencepiece_3616.patch | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 patch/patches/third_party_sentencepiece_3616.patch diff --git a/patch/patch.cfg b/patch/patch.cfg index fa6b9c5e3..e0abdaef0 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -730,5 +730,10 @@ patches = [ # hidden menu items. # https://github.com/chromiumembedded/cef/issues/3577 'name': 'ui_menu_model_3577' + }, + { + # linux: Fix cannot allocate memory in static TLS block in dlopen libcef.so + # https://github.com/chromiumembedded/cef/issues/3616 + 'name': 'third_party_sentencepiece_3616' } ] diff --git a/patch/patches/third_party_sentencepiece_3616.patch b/patch/patches/third_party_sentencepiece_3616.patch new file mode 100644 index 000000000..16cbb9e53 --- /dev/null +++ b/patch/patches/third_party_sentencepiece_3616.patch @@ -0,0 +1,33 @@ +diff --git third_party/sentencepiece/src/src/util.cc third_party/sentencepiece/src/src/util.cc +index 538b00b..61c4e5d 100644 +--- third_party/sentencepiece/src/src/util.cc ++++ third_party/sentencepiece/src/src/util.cc +@@ -16,6 +16,7 @@ + + #include + #include ++#include + + namespace sentencepiece { + +@@ -187,8 +190,18 @@ std::mt19937 *GetRandomGenerator() { + } + #else + std::mt19937 *GetRandomGenerator() { +- thread_local static std::mt19937 mt(GetRandomGeneratorSeed()); +- return &mt; ++ // Thread-locals occupy stack space in every thread ever created by the ++ // program, even if that thread never uses the thread-local variable. ++ // ++ // https://maskray.me/blog/2021-02-14-all-about-thread-local-storage ++ // ++ // sizeof(std::mt19937) is several kilobytes, so it is safer to put that on ++ // the heap, leaving only a pointer to it in thread-local storage. This must ++ // be a unique_ptr, not a raw pointer, so that the generator is not leaked on ++ // thread exit. ++ thread_local static auto mt = ++ std::make_unique(GetRandomGeneratorSeed()); ++ return mt.get(); + } + #endif + } // namespace random