From 8842391e5c1c1e751d5d8fca53556d9e8c80196b Mon Sep 17 00:00:00 2001 From: Yuhang Zhao Date: Mon, 23 Oct 2023 13:10:44 +0800 Subject: [PATCH] windeployqt: improve MSVC runtime detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MSVC runtime dlls also include vccorelibXXX.dll, concrtXXX.dll, beside these traditional dlls, it's also possible to link against the new UCRT runtime, the ucrtbase.dll (and possibly including the API Set dlls), so we need to add some more checks to make windeployqt more robust. I've tested a custom Qt build locally, which I managed to make it link to ucrtbase.dll only, and this code works fine. Pick-to: 6.6 Change-Id: I00bc8666d8850aac279b8747465879e39348ba02 Reviewed-by: Oliver Wolff Reviewed-by: Timothée Keller --- src/tools/windeployqt/utils.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tools/windeployqt/utils.cpp b/src/tools/windeployqt/utils.cpp index badb81d7c38..1e5b01ff50d 100644 --- a/src/tools/windeployqt/utils.cpp +++ b/src/tools/windeployqt/utils.cpp @@ -673,13 +673,23 @@ static inline MsvcDebugRuntimeResult checkMsvcDebugRuntime(const QStringList &de qsizetype pos = 0; if (lib.startsWith("MSVCR"_L1, Qt::CaseInsensitive) || lib.startsWith("MSVCP"_L1, Qt::CaseInsensitive) - || lib.startsWith("VCRUNTIME"_L1, Qt::CaseInsensitive)) { + || lib.startsWith("VCRUNTIME"_L1, Qt::CaseInsensitive) + || lib.startsWith("VCCORLIB"_L1, Qt::CaseInsensitive) + || lib.startsWith("CONCRT"_L1, Qt::CaseInsensitive) + || lib.startsWith("UCRTBASE"_L1, Qt::CaseInsensitive)) { qsizetype lastDotPos = lib.lastIndexOf(u'.'); pos = -1 == lastDotPos ? 0 : lastDotPos - 1; } - if (pos > 0 && lib.contains("_app"_L1, Qt::CaseInsensitive)) - pos -= 4; + if (pos > 0) { + const auto removeExtraSuffix = [&lib, &pos](const QString &suffix) -> void { + if (lib.contains(suffix, Qt::CaseInsensitive)) + pos -= suffix.size(); + }; + removeExtraSuffix("_app"_L1); + removeExtraSuffix("_atomic_wait"_L1); + removeExtraSuffix("_codecvt_ids"_L1); + } if (pos) return lib.at(pos).toLower() == u'd' ? MsvcDebugRuntime : MsvcReleaseRuntime;