feat: check Qt version w/o actually loading so file#74
Merged
BLumia merged 1 commit intolinuxdeepin:masterfrom Nov 3, 2025
Merged
feat: check Qt version w/o actually loading so file#74BLumia merged 1 commit intolinuxdeepin:masterfrom
BLumia merged 1 commit intolinuxdeepin:masterfrom
Conversation
历史代码中,会尝试使用 dlopen() 装载 Qt 插件文件,调用 qVersion 获取 插件版本信息,并 dlclose() 卸载插件文件. 这在 Qt 6.8.2+ 会导致崩溃 在 QCoreApplicationPrivate::sendThroughApplicationEvent, 由 qtbase 的 2b3e56e2b4198a940bb811964d0342868c391858 所致. 此处的目的仅仅是检查插件版本,而 dlopen() 本身即可能会执行一些代码, 导致污染当前线程,故转为使用解析 so 文件的 ELF 头的 .qtversion section 来解析 Qt 版本号,并优先使用此版本号进行判断. 此修改还增加了一个命令行选项用来验证 so 文件的 Qt 版本解析,以供临时 调试类场景使用. Log:
deepin pr auto review我来对这个代码变更进行详细审查:
改进建议:
if (!f.open(QIODevice::ReadOnly)) {
qWarning() << "Cannot open file:" << path << f.errorString();
return {};
}
#ifdef ELF_QT_VER_CHECK
// 添加对32位ELF的支持
if (is64) {
// 64位处理
} else {
// 32位处理
}
#endif
if (f.size() < sizeof(Elf64_Ehdr)) {
qWarning() << "File too small:" << path;
return {};
}
if (major == 0 || minor > 255 || patch > 255) {
qWarning() << "Invalid Qt version format:" << major << minor << patch;
return {};
}
/**
* @brief Parse Qt version from ELF header of a shared library
* @param path Path to the shared library file
* @return Qt version number if successful, null version number otherwise
*/
QVersionNumber qtVersionFromSo(const QString &path);总体来说,这是一个很好的改进,通过直接读取ELF头来获取Qt版本信息,避免了动态库加载的开销,同时提供了良好的可配置性和错误处理。 |
18202781743
reviewed
Oct 31, 2025
|
|
||
| bool checkLibraryQtVersion(const QString &soPath) | ||
| { | ||
| QVersionNumber libraryQtVersion = qtVersionFromSo(soPath); |
Contributor
There was a problem hiding this comment.
这里需要检查qt版本的so,是我们自己插件的库么?如果这样的话,qt本身不需要加载so就能够获取metadata,自定义的metadata有version,
18202781743
reviewed
Oct 31, 2025
| } | ||
|
|
||
| QLibrary library(soPath); | ||
| if (!library.load()) { |
Contributor
Member
Author
There was a problem hiding this comment.
不能,这个得走QPluginLoader::metaData,然后我实际尝试的情况是:
Failed to find metadata in lib /usr/lib64/deepin-service-manager/libplugin-dde-appearance.so: '/usr/lib64/deepin-service-manager/libplugin-dde-appearance.so' is not a Qt plugin (metadata not found)
18202781743
approved these changes
Oct 31, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, BLumia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

历史代码中,会尝试使用
dlopen()装载 Qt 插件文件,调用qVersion获取插件版本信息,并dlclose()卸载插件文件. 这在 Qt 6.8.2+ 会导致崩溃在 QCoreApplicationPrivate::sendThroughApplicationEvent, 由 qt/qtbase@2b3e56e 所致, 具体发生在dlclose()(上一个提交并未添加QLibrary::unload所以不会触发崩溃).此处的目的仅仅是检查插件版本,而
dlopen()本身即可能会执行一些代码,导致污染当前线程,故转为使用解析 so 文件的 ELF 头的.qtversionsection 来解析 Qt 版本号,并优先使用此版本号进行判断.此修改还增加了一个命令行选项用来验证 so 文件的 Qt 版本解析,以供临时调试类场景使用.