summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArvid Ephraim Picciani <arvid.picciani@nokia.com>2010-08-17 19:28:45 (GMT)
committerArvid Ephraim Picciani <arvid.picciani@nokia.com>2010-08-27 14:59:16 (GMT)
commit3c2a43f91e0225bde8d6e6d6076dfe2cddbc2f8e (patch)
treee299b1dbc2820c902eed9632b97e63c62f7308b0
parentde4fdc9743b4b4261ecf86b8891441ea293ba489 (diff)
downloadQt-3c2a43f91e0225bde8d6e6d6076dfe2cddbc2f8e.zip
Qt-3c2a43f91e0225bde8d6e6d6076dfe2cddbc2f8e.tar.gz
Qt-3c2a43f91e0225bde8d6e6d6076dfe2cddbc2f8e.tar.bz2
Optimize plugin loading on ELF platforms
-rw-r--r--src/corelib/global/qglobal.h6
-rw-r--r--src/corelib/plugin/plugin.pri6
-rw-r--r--src/corelib/plugin/qelfparser_p.cpp234
-rw-r--r--src/corelib/plugin/qelfparser_p.h78
-rw-r--r--src/corelib/plugin/qlibrary.cpp17
-rw-r--r--src/corelib/plugin/qplugin.h12
-rw-r--r--tests/auto/qpluginloader/elftest/.gitattributes10
-rwxr-xr-xtests/auto/qpluginloader/elftest/corrupt1.elf64.sobin0 -> 239745 bytes
-rwxr-xr-xtests/auto/qpluginloader/elftest/corrupt2.elf64.sobin0 -> 240097 bytes
-rwxr-xr-xtests/auto/qpluginloader/elftest/corrupt3.elf64.sobin0 -> 240097 bytes
-rw-r--r--tests/auto/qpluginloader/elftest/debugobj.sobin0 -> 507232 bytes
-rw-r--r--tests/auto/qpluginloader/elftest/garbage1.so4
-rw-r--r--tests/auto/qpluginloader/elftest/garbage2.so1
-rw-r--r--tests/auto/qpluginloader/elftest/garbage3.so1
-rw-r--r--tests/auto/qpluginloader/elftest/garbage4.so1
-rw-r--r--tests/auto/qpluginloader/elftest/garbage5.so2
-rw-r--r--tests/auto/qpluginloader/tst/tst.pro2
-rw-r--r--tests/auto/qpluginloader/tst_qpluginloader.cpp81
18 files changed, 449 insertions, 6 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index a8758cf..ede6dcd 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -2612,6 +2612,12 @@ QT_LICENSED_MODULE(DBus)
# define QT_NO_PROCESS
#endif
+#if defined (__ELF__)
+# if defined (Q_OS_LINUX) || defined (Q_OS_SOLARIS) || defined (Q_OS_FREEBSD) || defined (Q_OS_OPENBSD) || defined (Q_OS_IRIX)
+# define Q_OF_ELF
+# endif
+#endif
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/corelib/plugin/plugin.pri b/src/corelib/plugin/plugin.pri
index c05ff48..2e7db5d 100644
--- a/src/corelib/plugin/plugin.pri
+++ b/src/corelib/plugin/plugin.pri
@@ -7,13 +7,15 @@ HEADERS += \
plugin/qlibrary_p.h \
plugin/qplugin.h \
plugin/quuid.h \
- plugin/qfactoryloader_p.h
+ plugin/qfactoryloader_p.h \
+ plugin/qelfparser_p.h
SOURCES += \
plugin/qpluginloader.cpp \
plugin/qfactoryloader.cpp \
plugin/quuid.cpp \
- plugin/qlibrary.cpp
+ plugin/qlibrary.cpp \
+ plugin/qelfparser_p.cpp
win32 {
SOURCES += plugin/qlibrary_win.cpp
diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp
new file mode 100644
index 0000000..d837006
--- /dev/null
+++ b/src/corelib/plugin/qelfparser_p.cpp
@@ -0,0 +1,234 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "qlibrary_p.h"
+#include "qelfparser_p.h"
+
+// #define QELFPARSER_DEBUG 1
+
+#include <qdebug.h>
+
+const char *QElfParser::parseSectionHeader(const char *data, ElfSectionHeader *sh)
+{
+ sh->name = read<qelfword_t>(data);
+ data += sizeof(qelfword_t); // sh_name
+ sh->type = read<qelfword_t>(data);
+ data += sizeof(qelfword_t) // sh_type
+ + sizeof(qelfaddr_t) // sh_flags
+ + sizeof(qelfaddr_t); // sh_addr
+ sh->offset = read<qelfoff_t>(data);
+ data += sizeof(qelfoff_t); // sh_offset
+ sh->size = read<qelfword_t>(data);
+ data += sizeof(qelfword_t); // sh_size
+ return data;
+}
+
+int QElfParser::parse(const char *dataStart, ulong *fdlen, const QString &library, uint *version, bool *debug, QByteArray *key, QLibraryPrivate *lib, long *pos)
+{
+#if defined(QELFPARSER_DEBUG)
+ qDebug() << "QElfParser::parse " << library;
+#endif
+
+ if (*fdlen < 64){
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is not an ELF object (%2)").arg(library).arg(QLatin1String("file too small"));
+ return NotElf;
+ }
+ const char *data = dataStart;
+ if (qstrncmp(data, "\177ELF", 4) != 0) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is not an ELF object").arg(library);
+ return NotElf;
+ }
+ // 32 or 64 bit
+ if (data[4] != 1 && data[4] != 2) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("odd cpu architecture"));
+ return Corrupt;
+ }
+ m_bits = (data[4] << 5);
+
+ /* If you remove this check, to read ELF objects of a different arch, please make sure you modify the typedefs
+ to match the _plugin_ architecture.
+ */
+ if ((sizeof(void*) == 4 && m_bits != 32) || (sizeof(void*) == 8 && m_bits != 64)) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("wrong cpu architecture"));
+ return Corrupt;
+ }
+ // endian
+ if (data[5] == 0) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("odd endianess"));
+ return Corrupt;
+ }
+ m_endian = (data[5] == 1 ? ElfLittleEndian : ElfBigEndian);
+
+ data += 16 // e_ident
+ + sizeof(qelfhalf_t) // e_type
+ + sizeof(qelfhalf_t) // e_machine
+ + sizeof(qelfword_t) // e_version
+ + sizeof(qelfaddr_t) // e_entry
+ + sizeof(qelfoff_t); // e_phoff
+
+ qelfoff_t e_shoff = read<qelfoff_t> (data);
+ data += sizeof(qelfoff_t) // e_shoff
+ + sizeof(qelfword_t); // e_flags
+
+ qelfhalf_t e_shsize = read<qelfhalf_t> (data);
+
+ if (e_shsize > *fdlen) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("unexpected e_shsize"));
+ return Corrupt;
+ }
+
+ data += sizeof(qelfhalf_t) // e_ehsize
+ + sizeof(qelfhalf_t) // e_phentsize
+ + sizeof(qelfhalf_t); // e_phnum
+
+ qelfhalf_t e_shentsize = read<qelfhalf_t> (data);
+
+ if (e_shentsize % 8){
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("unexpected e_shentsize"));
+ return Corrupt;
+ }
+ data += sizeof(qelfhalf_t); // e_shentsize
+ qelfhalf_t e_shnum = read<qelfhalf_t> (data);
+ data += sizeof(qelfhalf_t); // e_shnum
+ qelfhalf_t e_shtrndx = read<qelfhalf_t> (data);
+ data += sizeof(qelfhalf_t); // e_shtrndx
+
+ if ((e_shnum * e_shentsize) >= *fdlen) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library)
+ .arg(QLatin1String("announced %2 sections, each %3 bytes, exceed file size"))
+ .arg(e_shnum).arg(e_shentsize);
+ return Corrupt;
+ }
+
+#if defined(QELFPARSER_DEBUG)
+ qDebug() << e_shnum << "sections starting at " << ("0x" + QByteArray::number(e_shoff, 16)).data() << "each" << e_shentsize << "bytes";
+#endif
+
+ ElfSectionHeader strtab;
+ qulonglong soff = e_shoff + e_shentsize * (e_shtrndx);
+
+ if ((soff + e_shentsize) >= *fdlen || soff % 8 || soff == 0) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library)
+ .arg(QLatin1String("strtab section seems to be at %1"))
+ .arg(QString::number(soff, 16));
+ return Corrupt;
+ }
+
+ parseSectionHeader(dataStart + soff, &strtab);
+ m_stringTableFileOffset = strtab.offset;
+
+ if ((m_stringTableFileOffset + e_shentsize) >= *fdlen || m_stringTableFileOffset == 0) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library)
+ .arg(QLatin1String("string table seems to be at %1"))
+ .arg(QString::number(soff, 16));
+ return Corrupt;
+ }
+
+#if defined(QELFPARSER_DEBUG)
+ qDebug(".shstrtab at 0x%s", QByteArray::number(m_stringTableFileOffset, 16).data());
+#endif
+
+ const char *s = dataStart + e_shoff;
+ for (int i = 0; i < e_shnum; ++i) {
+ ElfSectionHeader sh;
+ parseSectionHeader(s, &sh);
+ if (sh.name == 0) {
+ s += e_shentsize;
+ continue;
+ }
+ const char *shnam = dataStart + m_stringTableFileOffset + sh.name;
+
+ if (m_stringTableFileOffset + sh.name >= *fdlen) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library)
+ .arg(QLatin1String("section name %2 of %3 behind end of file"))
+ .arg(i).arg(e_shnum);
+ return Corrupt;
+ }
+
+#if defined(QELFPARSER_DEBUG)
+ qDebug() << "++++" << i << shnam;
+#endif
+
+ if (qstrncmp(shnam, ".qplugin", 8) == 0) {
+ if (!(sh.type & 0x1)) {
+#if defined(QELFPARSER_DEBUG)
+ qDebug()<<"section is not program data. skipped.";
+#endif
+ s += e_shentsize;
+ continue;
+ }
+
+ if (sh.offset == 0 || (sh.offset + sh.size) >= *fdlen) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library)
+ .arg(QLatin1String("missing section data. This is not a library."));
+ return Corrupt;
+ }
+ QList<QByteArray> shname = QByteArray::fromRawData(shnam,strlen(shnam)).split('.');
+ if (shname.count() < 4) {
+ if (lib)
+ lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library)
+ .arg(QLatin1String("incompatible .qtplugin section name"));
+ return Corrupt;
+ }
+
+ *debug = (shname.last() == "d");
+ *version = (shname.at(2).toUInt() << 16) | (shname.at(3).toUInt() << 8) | shname.at(4).toUInt();
+ *key = QByteArray(dataStart + sh.offset,sh.size-1);
+ *pos = sh.offset;
+ *fdlen = sh.size - 1;
+ return Ok;
+ }
+ s += e_shentsize;
+ }
+ return NoQtSection;
+}
+
diff --git a/src/corelib/plugin/qelfparser_p.h b/src/corelib/plugin/qelfparser_p.h
new file mode 100644
index 0000000..0d2b13d
--- /dev/null
+++ b/src/corelib/plugin/qelfparser_p.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qendian.h>
+
+typedef quint16 qelfhalf_t;
+typedef quint32 qelfword_t;
+typedef quintptr qelfoff_t;
+typedef quintptr qelfaddr_t;
+
+class QElfParser
+{
+public:
+ enum {Ok = 0, NotElf = 1, NoQtSection = 2, Corrupt = 3};
+ enum {ElfLittleEndian = 0, ElfBigEndian = 1};
+
+ struct ElfSectionHeader
+ {
+ qelfword_t name;
+ qelfword_t type;
+ qelfoff_t offset;
+ qelfword_t size;
+ };
+
+ int m_endian;
+ int m_bits;
+ int m_stringTableFileOffset;
+
+ template <typename T>
+ T read(const char *s)
+ {
+ if (m_endian == ElfBigEndian)
+ return qFromBigEndian<T>(reinterpret_cast<const uchar *>(s));
+ else
+ return qFromLittleEndian<T>(reinterpret_cast<const uchar *>(s));
+ }
+
+ const char *parseSectionHeader(const char* s, ElfSectionHeader *sh);
+ int parse(const char *m_s, ulong *fdlen, const QString &library, uint *version, bool *debug, QByteArray *key, QLibraryPrivate *lib, long *pos);
+};
+
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index 3eb50ef..451c244 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -38,7 +38,6 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-
#include "qplatformdefs.h"
#include "qlibrary.h"
@@ -61,6 +60,7 @@
#include <qdebug.h>
#include <qvector.h>
#include <qdir.h>
+#include "qelfparser_p.h"
QT_BEGIN_NAMESPACE
@@ -295,6 +295,7 @@ static bool qt_parse_pattern(const char *s, uint *version, bool *debug, QByteArr
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN) && !defined(QT_NO_PLUGIN_CHECK)
+#if !defined (Q_OF_ELF) || !defined(Q_CC_GNU)
static long qt_find_pattern(const char *s, ulong s_len,
const char *pattern, ulong p_len)
{
@@ -330,6 +331,7 @@ static long qt_find_pattern(const char *s, ulong s_len,
return -1;
}
+#endif // !defined (Q_OF_ELF) || !defined(Q_CC_GNU)
/*
This opens the specified library, mmaps it into memory, and searches
@@ -365,10 +367,18 @@ static bool qt_unix_query(const QString &library, uint *version, bool *debug, QB
fdlen = data.size();
}
- // verify that the pattern is present in the plugin
+ /*
+ ELF binaries on GNU, have .qplugin sections.
+ */
+ long pos = 0;
+#if defined (Q_OF_ELF) && defined(Q_CC_GNU)
+ int r = QElfParser().parse(filedata, &fdlen, library, version, debug, key, lib, &pos);
+ return (r == QElfParser::Ok);
+#else
const char pattern[] = "pattern=QT_PLUGIN_VERIFICATION_DATA";
const ulong plen = qstrlen(pattern);
- long pos = qt_find_pattern(filedata, fdlen, pattern, plen);
+ if (pos == 0)
+ pos = qt_find_pattern(filedata, fdlen, pattern, plen);
bool ret = false;
if (pos >= 0)
@@ -378,6 +388,7 @@ static bool qt_unix_query(const QString &library, uint *version, bool *debug, QB
lib->errorString = QLibrary::tr("Plugin verification data mismatch in '%1'").arg(library);
file.close();
return ret;
+#endif // defined(Q_OF_ELF) && defined(Q_CC_GNU)
}
#endif // Q_OS_UNIX && !Q_OS_MAC && !defined(Q_OS_SYMBIAN) && !defined(QT_NO_PLUGIN_CHECK)
diff --git a/src/corelib/plugin/qplugin.h b/src/corelib/plugin/qplugin.h
index 7f541f1..30c0c82 100644
--- a/src/corelib/plugin/qplugin.h
+++ b/src/corelib/plugin/qplugin.h
@@ -101,13 +101,17 @@ void Q_CORE_EXPORT qRegisterStaticPluginInstanceFunction(QtPluginInstanceFunctio
// NOTE: if you change pattern, you MUST change the pattern in
// qlibrary.cpp as well. changing the pattern will break all
// backwards compatibility as well (no old plugins will be loaded).
+// QT5: should probably remove the entire pattern thing and do the section
+// trick for all platforms. for now, keep it and fallback to scan for it.
# ifdef QPLUGIN_DEBUG_STR
# undef QPLUGIN_DEBUG_STR
# endif
# ifdef QT_NO_DEBUG
# define QPLUGIN_DEBUG_STR "false"
+# define QPLUGIN_SECTION_DEBUG_STR ""
# else
# define QPLUGIN_DEBUG_STR "true"
+# define QPLUGIN_SECTION_DEBUG_STR ".debug"
# endif
# define Q_PLUGIN_VERIFICATION_DATA \
static const char qt_plugin_verification_data[] = \
@@ -116,6 +120,13 @@ void Q_CORE_EXPORT qRegisterStaticPluginInstanceFunction(QtPluginInstanceFunctio
"debug="QPLUGIN_DEBUG_STR"\n" \
"buildkey="QT_BUILD_KEY;
+# if defined (Q_OF_ELF) && defined (Q_CC_GNU)
+# define Q_PLUGIN_VERIFICATION_SECTION \
+ __attribute__ ((section (".qplugin."QT_VERSION_STR QPLUGIN_SECTION_DEBUG_STR))) __attribute__((used)) static const char qt_plugin_build_key[] = QT_BUILD_KEY;
+# else
+# define Q_PLUGIN_VERIFICATION_SECTION
+# endif
+
# if defined (Q_OS_WIN32) && defined(Q_CC_BOR)
# define Q_STANDARD_CALL __stdcall
# else
@@ -123,6 +134,7 @@ void Q_CORE_EXPORT qRegisterStaticPluginInstanceFunction(QtPluginInstanceFunctio
# endif
# define Q_EXPORT_PLUGIN2(PLUGIN, PLUGINCLASS) \
+ Q_PLUGIN_VERIFICATION_SECTION \
Q_PLUGIN_VERIFICATION_DATA \
Q_EXTERN_C Q_DECL_EXPORT \
const char * Q_STANDARD_CALL qt_plugin_query_verification_data() \
diff --git a/tests/auto/qpluginloader/elftest/.gitattributes b/tests/auto/qpluginloader/elftest/.gitattributes
new file mode 100644
index 0000000..891192c
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/.gitattributes
@@ -0,0 +1,10 @@
+corrupt1.elf64.so set -crlf -diff
+corrupt2.elf64.so set -crlf -diff
+corrupt3.elf64.so set -crlf -diff
+debugobj.so set -crlf -diff
+garbage1.so set -crlf -diff
+garbage2.so set -crlf -diff
+garbage3.so set -crlf -diff
+garbage4.so set -crlf -diff
+garbage5.so set -crlf -diff
+
diff --git a/tests/auto/qpluginloader/elftest/corrupt1.elf64.so b/tests/auto/qpluginloader/elftest/corrupt1.elf64.so
new file mode 100755
index 0000000..12ce736
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/corrupt1.elf64.so
Binary files differ
diff --git a/tests/auto/qpluginloader/elftest/corrupt2.elf64.so b/tests/auto/qpluginloader/elftest/corrupt2.elf64.so
new file mode 100755
index 0000000..11fdc2c
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/corrupt2.elf64.so
Binary files differ
diff --git a/tests/auto/qpluginloader/elftest/corrupt3.elf64.so b/tests/auto/qpluginloader/elftest/corrupt3.elf64.so
new file mode 100755
index 0000000..94a2bc3
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/corrupt3.elf64.so
Binary files differ
diff --git a/tests/auto/qpluginloader/elftest/debugobj.so b/tests/auto/qpluginloader/elftest/debugobj.so
new file mode 100644
index 0000000..f0ee056
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/debugobj.so
Binary files differ
diff --git a/tests/auto/qpluginloader/elftest/garbage1.so b/tests/auto/qpluginloader/elftest/garbage1.so
new file mode 100644
index 0000000..0c74530
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/garbage1.so
@@ -0,0 +1,4 @@
+pcdL+&&e=
+oÒʎI ٝmg]!Z
+L')t
+N(e P)Y8G 6-y "Zk4?^n5$Y=#y \ No newline at end of file
diff --git a/tests/auto/qpluginloader/elftest/garbage2.so b/tests/auto/qpluginloader/elftest/garbage2.so
new file mode 100644
index 0000000..c06338e
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/garbage2.so
@@ -0,0 +1 @@
+v.YtKW3 \ No newline at end of file
diff --git a/tests/auto/qpluginloader/elftest/garbage3.so b/tests/auto/qpluginloader/elftest/garbage3.so
new file mode 100644
index 0000000..a24c523
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/garbage3.so
@@ -0,0 +1 @@
+ȂT-ڥ 쾜i8_xI׮x=4@[BKS$ \ No newline at end of file
diff --git a/tests/auto/qpluginloader/elftest/garbage4.so b/tests/auto/qpluginloader/elftest/garbage4.so
new file mode 100644
index 0000000..4f45cf5
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/garbage4.so
@@ -0,0 +1 @@
+ !\~Uu:9T+91QEǚxng5zh^t'mm*ˈdXH;vw+G 9L0! \ No newline at end of file
diff --git a/tests/auto/qpluginloader/elftest/garbage5.so b/tests/auto/qpluginloader/elftest/garbage5.so
new file mode 100644
index 0000000..f8c0a1d
--- /dev/null
+++ b/tests/auto/qpluginloader/elftest/garbage5.so
@@ -0,0 +1,2 @@
+Q
+-9 \ No newline at end of file
diff --git a/tests/auto/qpluginloader/tst/tst.pro b/tests/auto/qpluginloader/tst/tst.pro
index 2d757e7..e270120 100644
--- a/tests/auto/qpluginloader/tst/tst.pro
+++ b/tests/auto/qpluginloader/tst/tst.pro
@@ -27,3 +27,5 @@ symbian: {
DEPLOYMENT += libDep pluginDep
}
+
+DEFINES += SRCDIR=\\\"$$PWD/../\\\"
diff --git a/tests/auto/qpluginloader/tst_qpluginloader.cpp b/tests/auto/qpluginloader/tst_qpluginloader.cpp
index 1e382b8..9374dd0 100644
--- a/tests/auto/qpluginloader/tst_qpluginloader.cpp
+++ b/tests/auto/qpluginloader/tst_qpluginloader.cpp
@@ -100,6 +100,14 @@
# define PREFIX "lib"
#endif
+#ifdef QT_NO_DEBUG
+# define QLIBRARY_AS_DEBUG false
+#else
+# define QLIBRARY_AS_DEBUG true
+#endif
+
+// #define SHOW_ERRORS 1
+
static QString sys_qualifiedLibraryName(const QString &fileName)
{
QString currDir = QDir::currentPath();
@@ -119,10 +127,14 @@ public:
virtual ~tst_QPluginLoader();
private slots:
+ void clearPluginCache();
void errorString();
void loadHints();
void deleteinstanceOnUnload();
void checkingStubsFromDifferentDrives();
+ void loadDebugObj();
+ void loadCorruptElf();
+ void loadGarbage();
};
tst_QPluginLoader::tst_QPluginLoader()
@@ -134,7 +146,25 @@ tst_QPluginLoader::~tst_QPluginLoader()
{
}
-//#define SHOW_ERRORS 1
+void tst_QPluginLoader::clearPluginCache()
+{
+ QString regkey = QString::fromLatin1("Qt Plugin Cache %1.%2.%3")
+ .arg((QT_VERSION & 0xff0000) >> 16)
+ .arg((QT_VERSION & 0xff00) >> 8)
+ .arg(QLIBRARY_AS_DEBUG ? QLatin1String("debug") : QLatin1String("false"));
+#ifdef Q_WS_MAC
+#if defined(__x86_64__)
+ regkey += QLatin1String("-x86_64");
+#elif defined(__i386__)
+ regkey += QLatin1String("-i386");
+#elif defined(__ppc64__)
+ regkey += QLatin1String("-ppc64");
+#elif defined(__ppc__)
+ regkey += QLatin1String("-ppc");
+#endif
+#endif // Q_WS_MAC
+ QSettings(QSettings::UserScope, QLatin1String("Trolltech")).remove(regkey);
+}
void tst_QPluginLoader::errorString()
{
@@ -350,5 +380,54 @@ void tst_QPluginLoader::checkingStubsFromDifferentDrives()
#endif//Q_OS_SYMBIAN
}
+void tst_QPluginLoader::loadDebugObj()
+{
+#if defined (__ELF__)
+ QVERIFY(QFile::exists(SRCDIR "elftest/debugobj.so"));
+ QPluginLoader lib1(SRCDIR "elftest/debugobj.so");
+ QCOMPARE(lib1.load(), false);
+#endif
+}
+
+void tst_QPluginLoader::loadCorruptElf()
+{
+#if defined (__ELF__)
+if (sizeof(void*) == 8) {
+ QVERIFY(QFile::exists(SRCDIR "elftest/corrupt1.elf64.so"));
+
+ QPluginLoader lib1(SRCDIR "elftest/corrupt1.elf64.so");
+ QCOMPARE(lib1.load(), false);
+ QVERIFY(lib1.errorString().contains("not an ELF object"));
+
+ QPluginLoader lib2(SRCDIR "elftest/corrupt2.elf64.so");
+ QCOMPARE(lib2.load(), false);
+ QVERIFY(lib2.errorString().contains("invalid"));
+
+ QPluginLoader lib3(SRCDIR "elftest/corrupt3.elf64.so");
+ QCOMPARE(lib3.load(), false);
+ QVERIFY(lib3.errorString().contains("invalid"));
+} else if (sizeof(void*) == 4) {
+ QPluginLoader libW(SRCDIR "elftest/corrupt3.elf64.so");
+ QCOMPARE(libW.load(), false);
+ QVERIFY(libW.errorString().contains("architecture"));
+} else {
+ QFAIL("Please port QElfParser to this platform or blacklist this test.");
+}
+#endif
+}
+
+void tst_QPluginLoader::loadGarbage()
+{
+#if defined (Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
+ for (int i=0; i<5; i++) {
+ QPluginLoader lib(QString(SRCDIR "elftest/garbage%1.so").arg(i));
+ QCOMPARE(lib.load(), false);
+#ifdef SHOW_ERRORS
+ qDebug() << lib.errorString();
+#endif
+ }
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_QPluginLoader)
#include "tst_qpluginloader.moc"