diff options
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/androiddeployqt/main.cpp | 2 | ||||
| -rw-r--r-- | src/tools/bootstrap/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/tools/macdeployqt/shared/shared.cpp | 27 | ||||
| -rw-r--r-- | src/tools/rcc/rcc.cpp | 93 |
4 files changed, 108 insertions, 18 deletions
diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp index 7f24df7eac2..c4e7101b372 100644 --- a/src/tools/androiddeployqt/main.cpp +++ b/src/tools/androiddeployqt/main.cpp @@ -173,7 +173,7 @@ struct Options QString versionName; QString versionCode; QByteArray minSdkVersion{"28"}; - QByteArray targetSdkVersion{"35"}; + QByteArray targetSdkVersion{"36"}; // lib c++ path QString stdCppPath; diff --git a/src/tools/bootstrap/CMakeLists.txt b/src/tools/bootstrap/CMakeLists.txt index e6f920dcf32..c12475d69af 100644 --- a/src/tools/bootstrap/CMakeLists.txt +++ b/src/tools/bootstrap/CMakeLists.txt @@ -220,6 +220,10 @@ target_link_libraries(Bootstrap PRIVATE PlatformCommonInternal) qt_internal_apply_gc_binaries(Bootstrap PUBLIC) set_target_properties(Bootstrap PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF) qt_internal_add_target_aliases(Bootstrap) +qt_internal_add_target_optimized_flags_for_debug_config_in_current_scope(Bootstrap) +qt_internal_enable_optimized_tools_lto(Bootstrap) +qt_internal_workaround_static_lib_gcc_lto_issue(Bootstrap) + qt_set_msvc_cplusplus_options(Bootstrap PUBLIC) qt_set_common_target_properties(Bootstrap) qt_internal_apply_intel_cet(Bootstrap PUBLIC) diff --git a/src/tools/macdeployqt/shared/shared.cpp b/src/tools/macdeployqt/shared/shared.cpp index 0731fb616ed..7f8590ae894 100644 --- a/src/tools/macdeployqt/shared/shared.cpp +++ b/src/tools/macdeployqt/shared/shared.cpp @@ -1008,6 +1008,31 @@ DeploymentInfo deployQtFrameworks(QList<FrameworkInfo> frameworks, rpathsUsed.append(framework.rpathUsed); } + // To properly find all dependencies of the current framework / library further down in + // getQtFrameworks, we need to get its rpaths, resolve them in the context of its original + // location before it is copied, and add them as candidate rpaths. + // + // This is necessary to handle cases like + // (1) QtNetwork.framework -> (2) libbrotlidec.dylib -> (3) libbrotlicommon.1.dylib + // to correctly resolve the path to (3) when it is referenced as + // '@rpath/libbrotlicommon.1.dylib' and (2) has an LC_RPATH of '@loader_path/../lib', and + // no other absolute rpaths. So the '@loader_path/../lib' will be resolved relative + // to (2)'s original location and its LC_RPATH. + // + // Otherwise we'd only have the Qt prefix and the current bundle app dir as rpath + // candidates, and once (2) is copied into the app bundle, there's no way + // '@rpath/libbrotlicommon.1.dylib' could resolve to the real path on disk from the two + // candidates above. + if (!framework.sourceFilePath.isEmpty()) { + const QList<QString> sourceRPaths = getBinaryRPaths(framework.sourceFilePath, true); + for (const QString &sourceRPath : sourceRPaths) { + const QDir sourceRPathDir(sourceRPath); + if (sourceRPathDir.exists() && !rpathsUsed.contains(sourceRPath)) { + rpathsUsed.append(sourceRPath); + } + } + } + // Copy the framework/dylib to the app bundle. const QString deployedBinaryPath = framework.isDylib ? copyDylib(framework, bundlePath) : copyFramework(framework, bundlePath); @@ -1032,7 +1057,7 @@ DeploymentInfo deployQtFrameworks(QList<FrameworkInfo> frameworks, for (const FrameworkInfo &dependency : dependencies) { if (dependency.rpathUsed.isEmpty()) { changeInstallName(bundlePath, dependency, QStringList() << deployedBinaryPath, useLoaderPath); - } else { + } else if (!rpathsUsed.contains(dependency.rpathUsed)) { rpathsUsed.append(dependency.rpathUsed); } diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 40bfa9c2863..6a6027d44f2 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -1,10 +1,12 @@ // Copyright (C) 2018 The Qt Company Ltd. // Copyright (C) 2018 Intel Corporation. +// Copyright (C) 2024 Christoph Cullmann <christoph@cullmann.io> // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "rcc.h" #include <qbytearray.h> +#include <qcryptographichash.h> #include <qdatetime.h> #include <qdebug.h> #include <qdir.h> @@ -90,8 +92,28 @@ public: QString resourceName() const; + struct DeduplicationKey { + RCCResourceLibrary::CompressionAlgorithm compressAlgo; + int compressLevel; + int compressThreshold; + QByteArray hash; + + bool operator==(const DeduplicationKey &other) const + { + return compressAlgo == other.compressAlgo && + compressLevel == other.compressLevel && + compressThreshold == other.compressThreshold && + hash == other.hash; + } + }; + + typedef QMultiHash<DeduplicationKey, RCCFileInfo*> DeduplicationMultiHash; + public: - qint64 writeDataBlob(RCCResourceLibrary &lib, qint64 offset, QString *errorMessage); + qint64 writeDataBlob(RCCResourceLibrary &lib, + qint64 offset, + DeduplicationMultiHash &dedupByContent, + QString *errorMessage); qint64 writeDataName(RCCResourceLibrary &, qint64 offset); void writeDataInfo(RCCResourceLibrary &lib); @@ -114,6 +136,11 @@ public: qint64 m_childOffset = 0; }; +static size_t qHash(const RCCFileInfo::DeduplicationKey &key, size_t seed) noexcept +{ + return qHashMulti(seed, key.compressAlgo, key.compressLevel, key.compressThreshold, key.hash); +} + RCCFileInfo::RCCFileInfo(const QString &name, const QFileInfo &fileInfo, QLocale::Language language, QLocale::Territory territory, uint flags, RCCResourceLibrary::CompressionAlgorithm compressAlgo, int compressLevel, @@ -217,8 +244,10 @@ void RCCFileInfo::writeDataInfo(RCCResourceLibrary &lib) } } -qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset, - QString *errorMessage) +qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, + qint64 offset, + DeduplicationMultiHash &dedupByContent, + QString *errorMessage) { const bool text = lib.m_format == RCCResourceLibrary::C_Code; const bool pass1 = lib.m_format == RCCResourceLibrary::Pass1; @@ -230,24 +259,58 @@ qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset, m_dataOffset = offset; QByteArray data; + // determine compession algorithm & level early as used in de-duplication keys + // this avoid corruption for the two pass variants (QTBUG-137546) +#if QT_CONFIG(zstd) + if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best && !m_noZstd) { + m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zstd; + m_compressLevel = 19; // not ZSTD_maxCLevel(), as 20+ are experimental + } +#endif +#ifndef QT_NO_COMPRESS + if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best) { + m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zlib; + m_compressLevel = 9; + } +#endif + if (!m_isEmpty) { - //find the data to be written - QFile file(m_fileInfo.absoluteFilePath()); + // find the data to be written + const QString absoluteFilePath = m_fileInfo.absoluteFilePath(); + QFile file(absoluteFilePath); if (!file.open(QFile::ReadOnly)) { - *errorMessage = msgOpenReadFailed(m_fileInfo.absoluteFilePath(), file.errorString()); + *errorMessage = msgOpenReadFailed(absoluteFilePath, file.errorString()); return 0; } - data = file.readAll(); + + // de-duplicate the same file content, we can re-use already written data + // we only do that if we have the same compression settings + const QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Sha256); + const DeduplicationKey key{m_compressAlgo, m_compressLevel, m_compressThreshold, hash}; + const QList<RCCFileInfo *> potentialCandidates = dedupByContent.values(key); + for (const RCCFileInfo *candidate : potentialCandidates) { + // check real content, we can have collisions + QFile candidateFile(candidate->m_fileInfo.absoluteFilePath()); + if (!candidateFile.open(QFile::ReadOnly)) { + *errorMessage = msgOpenReadFailed(candidate->m_fileInfo.absoluteFilePath(), + candidateFile.errorString()); + return 0; + } + if (data != candidateFile.readAll()) + continue; + // just remember the offset & flags with final compression state + // of the already written data and be done + m_dataOffset = candidate->m_dataOffset; + m_flags = candidate->m_flags; + return offset; + } + dedupByContent.insert(key, this); } // Check if compression is useful for this file if (data.size() != 0) { #if QT_CONFIG(zstd) - if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best && !m_noZstd) { - m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zstd; - m_compressLevel = 19; // not ZSTD_maxCLevel(), as 20+ are experimental - } if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zstd && !m_noZstd) { if (lib.m_zstdCCtx == nullptr) lib.m_zstdCCtx = ZSTD_createCCtx(); @@ -292,10 +355,6 @@ qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset, } #endif #ifndef QT_NO_COMPRESS - if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best) { - m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zlib; - m_compressLevel = 9; - } if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zlib) { QByteArray compressed = qCompress(reinterpret_cast<uchar *>(data.data()), data.size(), m_compressLevel); @@ -1168,6 +1227,7 @@ bool RCCResourceLibrary::writeDataBlobs() QStack<RCCFileInfo*> pending; pending.push(m_root); qint64 offset = 0; + RCCFileInfo::DeduplicationMultiHash dedupByContent; QString errorMessage; while (!pending.isEmpty()) { RCCFileInfo *file = pending.pop(); @@ -1176,7 +1236,8 @@ bool RCCResourceLibrary::writeDataBlobs() if (child->m_flags & RCCFileInfo::Directory) pending.push(child); else { - offset = child->writeDataBlob(*this, offset, &errorMessage); + offset = child->writeDataBlob(*this, offset, + dedupByContent, &errorMessage); if (offset == 0) { m_errorDevice->write(errorMessage.toUtf8()); return false; |
