Просмотр исходного кода

Merge remote-tracking branch 'origin/wip/relfix190fp' into wip/rollup028

# Conflicts:
#	tests/tests.cpp
Ka1-S 3 недель назад
Родитель
Сommit
13fe3d9798

+ 6 - 1
docs/PLUGIN_EXPORT.md

@@ -176,7 +176,7 @@ without the manifest the DLL fails to load with error 127.
   the three on exactly what an archive holds: plugexporttest on the CLAP and each VST3, pluginval on each VST3,
   clap-validator on the CLAP.
 - CI: `.github/workflows/plugins.yml` builds, packages and checks the download for Windows (zig on Ubuntu, checked on
-  windows-2022), Linux (Ubuntu 22.04 container, glibc check, editor pictures under Xvfb) and macOS (universal), then
+  windows-2022), Linux (Ubuntu 22.04 container, glibc check, no static TLS, editor pictures under Xvfb) and macOS (universal), then
   writes `LYNX-Plugins-<label>-SHA256SUMS.txt`. Started by hand on any branch (`workflow_dispatch`), or by `release.yml`
   on a release tag, which attaches the archives to the draft release (`plugins-publish`). The app's release doesn't wait
   for the plugins. Normal pushes don't build plugins.
@@ -269,6 +269,11 @@ controls stay hidden in the plugins for now.
 - Fixed in round 180b: FL hung on exit when the host unloaded the plugin DLL. LYNX's static image caches still held JUCE's
   Direct2D device, and freeing it under the loader lock deadlocked in the graphics driver. The last plugin instance
   now empties them (`ui/ImageCaches.h`), and a lint test keeps new static image caches registered.
+- Fixed in round 190fp: no host on Linux could load the 0.1.27 plugins ("cannot allocate memory in static TLS block";
+  the Linux archive was missing from that release). The crash guard's per-thread pointer (`platform/CrashGuard.cpp`) was
+  an initial-exec `thread_local`, which makes the module's whole TLS block (about 33 KB) static, far more than glibc
+  keeps for modules loaded with dlopen. In the plugins' runtime it is a pthread key now, and
+  `scripts/check-linux-compat.sh` fails any library that still has the `STATIC_TLS` flag.
 - Fixed in round 188b: a host restart (prepareToPlay) kept the engines of the last build, so a reverb's tail, LYNX Tune's
   detector history and Quell's state outlived it; it now starts from new engines, as a fresh instance.
 - The editors of all 27 effects were checked for FL wording (round 188b, `plugexporttest` pictures): none; the header no

+ 7 - 0
scripts/check-linux-compat.sh

@@ -26,5 +26,12 @@ fi
 if objdump -T "$BIN" | grep -qE '(GLIBCXX|CXXABI)_[0-9]'; then
     echo "ERROR: imports GLIBCXX/CXXABI symbols from the system's libstdc++"; fail=1
 fi
+# A library (a plugin a host loads with dlopen; not the executable, which has an interpreter) must not ask for static
+# TLS: glibc keeps only a small reserve for modules loaded later, and the host then fails to load it with "cannot
+# allocate memory in static TLS block" (the 0.1.27 Linux plugins on glibc 2.35, round 190fp). One initial-exec
+# thread_local makes the module's whole TLS block static.
+if ! readelf -lW "$BIN" | grep -q 'INTERP' && readelf -dW "$BIN" | grep -E '\((FLAGS)\)' | grep -q 'STATIC_TLS'; then
+    echo "ERROR: a library that asks for static TLS (DF_STATIC_TLS: an initial-exec thread_local); hosts can fail to load it"; fail=1
+fi
 [[ $fail == 0 ]] && echo "OK: runs with glibc $MAX and no system C++ runtime"
 exit $fail

+ 24 - 0
src/core/AutoScanPolicy.h

@@ -0,0 +1,24 @@
+#pragma once
+
+// When LYNX starts a full background plugin scan by itself (round 190fp). A scan loads every plugin, and on a PC with
+// expired licences each of those can open its own licence box (QA 190fd: 20+ in a row), so LYNX only scans by itself
+// when the user asked for it:
+//   - at start-up: the setup wizard was finished or skipped once, and "Look for new plugins in the background at every
+//     start" is on (the default);
+//   - when the setup wizard is finished: that same box is ticked there, and "Scan now" has not already started one.
+//     With the box unticked, Finish saves the folders and scans nothing; "Scan now" in the wizard, the plugin picker's
+//     Scan button and the plugin menus' "Scan for plugins" still scan at once. Skip never scans.
+// (Our REA notes have no record of FL Studio's own first-run scan, so this follows the box's wording.)
+
+namespace lynx::autoscan
+{
+constexpr bool atStartup (bool persistentWindow, bool setupDone, bool scanAtEveryStart) noexcept
+{
+    return persistentWindow && setupDone && scanAtEveryStart;
+}
+
+constexpr bool onWizardFinish (bool scanAtEveryStartTicked, bool scanAlreadyStarted) noexcept
+{
+    return scanAtEveryStartTicked && ! scanAlreadyStarted;
+}
+} // namespace lynx::autoscan

+ 10 - 2
src/platform/CrashGuard.cpp

@@ -87,7 +87,15 @@ struct GuardFrame
 
 // The armed frame of this thread. The handler reads it, so it must not allocate on first use: Linux' thread_local
 // pointer in the executable is static TLS (initial-exec); macOS' thread_local may allocate lazily, so a pthread key.
-#if defined(__APPLE__)
+// LYNX's exported plugins (this file is in their runtime, cmake/LynxPlugins.cmake, the only build that defines
+// LYNX_EXPORT_VERSION) are modules a host loads with dlopen: there one initial-exec variable makes the module's whole
+// TLS block static (DF_STATIC_TLS), glibc keeps only a small reserve for that, and hosts on glibc 2.35 failed to load
+// the 0.1.27 Linux plugins ("cannot allocate memory in static TLS block", round 190fp). They use the key as well
+// (pthread_getspecific does not allocate; scripts/check-linux-compat.sh fails a plugin that asks for static TLS).
+#if defined(LYNX_EXPORT_VERSION)
+ #define LYNX_GUARD_FRAME_KEY 1
+#endif
+#if defined(__APPLE__) || defined(LYNX_GUARD_FRAME_KEY)
 pthread_key_t frameKey;
 GuardFrame* currentFrame() noexcept { return static_cast<GuardFrame*> (pthread_getspecific (frameKey)); }
 void setCurrentFrame (GuardFrame* f) noexcept { pthread_setspecific (frameKey, f); }
@@ -297,7 +305,7 @@ void installFaultGuard() noexcept
     Dl_info self {};
     if (dladdr (reinterpret_cast<const void*> (&installFaultGuard), &self) != 0)
         ownImage = self.dli_fbase;
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(LYNX_GUARD_FRAME_KEY)
     pthread_key_create (&frameKey, nullptr);
 #endif
     {

+ 3 - 2
src/ui/MainComponent.cpp

@@ -6,6 +6,7 @@
 #include "ui/GamepadInput.h"
 #include "ui/ThemeSettings.h"
 #include "ui/ColourPicker.h"
+#include "core/AutoScanPolicy.h"
 #include "core/DrawMode.h"
 #include "core/SessionKeys.h"
 #include "core/EditorLimit.h"
@@ -816,9 +817,9 @@ MainComponent::MainComponent (AudioEngine& e, bool restoreUserSettings)
 
     // new or updated plugins since the last run: an incremental scan in the background (unchanged files are
     // skipped), a few seconds after start so it doesn't compete with loading; the first run asks in the wizard
-    if (persistent && setupWizardDone() && backgroundScanAtStart() && platform::testMode())
+    if (autoscan::atStartup (persistent, setupWizardDone(), backgroundScanAtStart()) && platform::testMode())
         platform::testModeLog ("background plugin scan at start");
-    else if (persistent && setupWizardDone() && backgroundScanAtStart())
+    else if (autoscan::atStartup (persistent, setupWizardDone(), backgroundScanAtStart()))
         juce::Timer::callAfterDelay (4000, [safe = juce::Component::SafePointer<MainComponent> (this)] {
             if (safe != nullptr)
                 safe->engine.getPluginHost().startBackgroundScan();

+ 5 - 2
src/ui/SetupWizard.cpp

@@ -4,6 +4,7 @@
 
 #include <juce_audio_utils/juce_audio_utils.h>
 
+#include "core/AutoScanPolicy.h"
 #include "core/LayoutStyle.h"
 #include "engine/AudioEngine.h"
 #include "engine/FlStudio.h"
@@ -380,8 +381,10 @@ private:
         markSetupWizardDone();
         if (runningAsAppImage())
             setAppImageMenuEntry (menuEntry.getToggleState());
-        if (! scanStarted)
-            engine.getPluginHost().startBackgroundScan(); // keeps going after the window closes
+        // (keeps going after the window closes) only when asked for: with "every start" unticked, nothing scans here
+        // (round 190fp: a scan can bring up one licence box per expired plugin)
+        if (autoscan::onWizardFinish (scanAtStart.getToggleState(), scanStarted))
+            engine.getPluginHost().startBackgroundScan();
         const auto chosen = languageBox.getSelectedId() - 1;
         const auto& languages = i18n::languages();
         const auto language = chosen >= 0 && chosen < (int) languages.size() ? juce::String (languages[(std::size_t) chosen].id) : i18n::saved();

+ 2 - 1
src/ui/SetupWizard.h

@@ -10,7 +10,8 @@ class AudioEngine;
 
 // First-run setup (small and skippable; Options > Setup wizard reopens it): language, audio device with a test
 // sound, plugin folders (the standard VST3/CLAP folders plus the ones FL Studio uses on this PC), and a plugin
-// scan that runs in the background (it keeps going after the window closes).
+// scan that runs in the background (it keeps going after the window closes): "Scan now", or Finish with "Look for new
+// plugins in the background at every start" ticked; unticked, Finish scans nothing (core/AutoScanPolicy.h).
 // It is shown as an overlay on top of the main window (`makeSetupWizardOverlay`: the caller adds it over its whole
 // area and deletes it, asynchronously, when `onClose` runs — after Skip, Finish or Escape).
 // `onLanguage(id)` runs when another language was chosen (the caller saves it and offers a restart).

+ 77 - 0
tests/Relfix190fpTests.inc

@@ -0,0 +1,77 @@
+// Round 190fp: the two release problems of 0.1.27.
+// (1) The Linux plugin download was missing from the release: every host on Ubuntu 22.04 (glibc 2.35) failed to load
+//     LYNX Plugins.clap and the VST3s ("cannot allocate memory in static TLS block"). The crash guard's thread_local
+//     frame pointer (platform/CrashGuard.cpp, round 190dt) was initial-exec; in a module a host loads with dlopen that
+//     one variable makes the module's whole TLS block static (DF_STATIC_TLS), and glibc keeps only a small reserve for
+//     those. In the exported plugins' runtime the frame is now a pthread key (as on macOS), and
+//     scripts/check-linux-compat.sh fails a library that still asks for static TLS.
+// (2) Finishing the setup wizard started a full plugin scan even with "Look for new plugins in the background at every
+//     start" unticked (QA 190fd O1: 20+ licence boxes on a PC with expired trials). core/AutoScanPolicy.h decides.
+
+#include "core/AutoScanPolicy.h"
+
+TEST (relfix190fp_wizard_finish_scans_only_when_asked)
+{
+    using namespace lynx::autoscan;
+    // ticked (the default): Finish starts the scan, unless "Scan now" already did
+    CHECK (onWizardFinish (true, false));
+    CHECK (! onWizardFinish (true, true));
+    // unticked: no scan on Finish, whether or not one already ran
+    CHECK (! onWizardFinish (false, false));
+    CHECK (! onWizardFinish (false, true));
+    // start-up: only a persistent window, after the wizard, with the box on
+    CHECK (atStartup (true, true, true));
+    CHECK (! atStartup (true, true, false));
+    CHECK (! atStartup (true, false, true));
+    CHECK (! atStartup (false, true, true));
+    static_assert (! onWizardFinish (false, false) && atStartup (true, true, true));
+}
+
+TEST (relfix190fp_wizard_and_start_use_the_policy)
+{
+    using namespace i18ntest;
+    const auto wizard = readFile ("src/ui/SetupWizard.cpp");
+    const auto finish = wizard.find ("void finishSetup()");
+    CHECK (finish != std::string::npos);
+    const auto end = wizard.find ("\n    }\n", finish);
+    CHECK (end != std::string::npos);
+    const auto body = wizard.substr (finish, end - finish);
+    CHECK (body.find ("autoscan::onWizardFinish (scanAtStart.getToggleState(), scanStarted)") != std::string::npos);
+    // the old unconditional start is gone
+    CHECK (body.find ("if (! scanStarted)") == std::string::npos);
+    // "Scan now" still scans at once
+    CHECK (wizard.find ("scanNow.onClick") != std::string::npos);
+
+    const auto main = readFile ("src/ui/MainComponent.cpp");
+    CHECK (main.find ("autoscan::atStartup (persistent, setupWizardDone(), backgroundScanAtStart())") != std::string::npos);
+}
+
+TEST (relfix190fp_crash_guard_has_no_static_tls_in_plugins)
+{
+    using namespace i18ntest;
+    const auto guard = readFile ("src/platform/CrashGuard.cpp");
+    const auto tls = guard.find ("tls_model (\"initial-exec\")");
+    CHECK (tls != std::string::npos);
+    // the initial-exec variable sits in the #else of a branch that the exported plugins' runtime takes
+    const auto branch = guard.rfind ("#if defined(__APPLE__) || defined(LYNX_GUARD_FRAME_KEY)", tls);
+    CHECK (branch != std::string::npos);
+    const auto elseAt = guard.find ("#else", branch);
+    CHECK (elseAt != std::string::npos && elseAt < tls && guard.find ("#endif", branch) > tls);
+    // ...set by the define only that runtime has (cmake/LynxPlugins.cmake)
+    const auto define = guard.find ("#if defined(LYNX_EXPORT_VERSION)");
+    CHECK (define != std::string::npos && define < branch);
+    CHECK (guard.find ("#define LYNX_GUARD_FRAME_KEY 1", define) < branch);
+    // the key is created on install for the same builds
+    CHECK (guard.find ("#if defined(__APPLE__) || defined(LYNX_GUARD_FRAME_KEY)\n    pthread_key_create (&frameKey, nullptr);")
+           != std::string::npos);
+    const auto plugins = readFile ("cmake/LynxPlugins.cmake");
+    const auto defines = plugins.find ("set(LYNX_PLUGIN_DEFINES");
+    CHECK (defines != std::string::npos && plugins.find ("LYNX_EXPORT_VERSION=", defines) != std::string::npos);
+    CHECK (plugins.find ("target_compile_definitions(lynx_plugin_runtime PUBLIC ${LYNX_PLUGIN_DEFINES})") != std::string::npos);
+
+    // the release check fails a Linux library that asks for static TLS
+    const auto compat = readFile ("scripts/check-linux-compat.sh");
+    const auto check = compat.find ("STATIC_TLS");
+    CHECK (check != std::string::npos);
+    CHECK (compat.find ("fail=1", check) != std::string::npos);
+}

+ 1 - 0
tests/tests.cpp

@@ -17569,3 +17569,4 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Flfix190ezTests.inc"
 #include "Rcfix190fcTests.inc"
 #include "Follow190fgTests.inc"
+#include "Relfix190fpTests.inc"