Fix relocatable prefix for hardware-specific Linux builds

Since Qt 5.3.0 we recommend that Linux distributions place a
SSE2-enabled copy of QtCore in a $PREFIX/lib/sse2 subdirectory (see Qt
5.3.0 changelog for details). Same for other hardware capabilities like
AVX2 and AVX512.

This use case was broken with the introduction of the 'relocatable'
feature, because the prefix is determined from the location of
libQt5Core.so and the relative path from libdir to prefix, which is
baked in at configure time.

We now try to locate the libdir below the prefix, and if that fails try
again in the upper directories.

Fixes: QTBUG-78948
Change-Id: Ieec6e1484974e19335cf08ae0df3ee5c0e316d28
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2019-10-08 11:35:06 +02:00
parent 386768298c
commit a6ece9e88a

View File

@ -569,6 +569,23 @@ static QString getRelocatablePrefix()
#error "The chosen platform / config does not support querying for a dynamic prefix."
#endif
#if defined(Q_OS_LINUX) && !defined(QT_STATIC) && defined(__GLIBC__)
// QTBUG-78948: libQt5Core.so may be located in subdirectories below libdir.
// See "Hardware capabilities" in the ld.so documentation and the Qt 5.3.0
// changelog regarding SSE2 support.
const QString libdir = QString::fromLatin1(
qt_configure_strs + qt_configure_str_offsets[QLibraryInfo::LibrariesPath - 1]);
QDir prefixDir(prefixPath);
while (!prefixDir.exists(libdir)) {
prefixDir.cdUp();
prefixPath = prefixDir.absolutePath();
if (prefixDir.isRoot()) {
prefixPath.clear();
break;
}
}
#endif
Q_ASSERT_X(!prefixPath.isEmpty(), "getRelocatablePrefix",
"Failed to find the Qt prefix path.");
return prefixPath;