diff options
author | Arvid Ephraim Picciani <arvid.picciani@nokia.com> | 2010-08-31 11:58:01 (GMT) |
---|---|---|
committer | Arvid Ephraim Picciani <arvid.picciani@nokia.com> | 2010-08-31 12:15:42 (GMT) |
commit | af2b8878ba7bd153876a5531a8119a4bdbc6b257 (patch) | |
tree | 0f12033d6dcd95cefaa76f2702670d9baf780262 /src | |
parent | b3da295dc3a4e72d185f9eb767dfe1f518fb0b8a (diff) | |
download | Qt-af2b8878ba7bd153876a5531a8119a4bdbc6b257.zip Qt-af2b8878ba7bd153876a5531a8119a4bdbc6b257.tar.gz Qt-af2b8878ba7bd153876a5531a8119a4bdbc6b257.tar.bz2 |
revert 3c2a43f91e0225bde8d6e6d6076dfe2cddbc2f8e
to pass CI again after mystical failure
Reviewed-by: Olivier Goffart
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/plugin/plugin.pri | 6 | ||||
-rw-r--r-- | src/corelib/plugin/qelfparser_p.cpp | 234 | ||||
-rw-r--r-- | src/corelib/plugin/qelfparser_p.h | 103 | ||||
-rw-r--r-- | src/corelib/plugin/qlibrary.cpp | 28 |
4 files changed, 6 insertions, 365 deletions
diff --git a/src/corelib/plugin/plugin.pri b/src/corelib/plugin/plugin.pri index 2e7db5d..2e986ec 100644 --- a/src/corelib/plugin/plugin.pri +++ b/src/corelib/plugin/plugin.pri @@ -7,15 +7,13 @@ HEADERS += \ plugin/qlibrary_p.h \ plugin/qplugin.h \ plugin/quuid.h \ - plugin/qfactoryloader_p.h \ - plugin/qelfparser_p.h + plugin/qfactoryloader_p.h SOURCES += \ plugin/qpluginloader.cpp \ plugin/qfactoryloader.cpp \ plugin/quuid.cpp \ - plugin/qlibrary.cpp \ - plugin/qelfparser_p.cpp + plugin/qlibrary.cpp win32 { SOURCES += plugin/qlibrary_win.cpp diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp deleted file mode 100644 index 97008fd..0000000 --- a/src/corelib/plugin/qelfparser_p.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** 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" -#include <qdebug.h> - -QT_BEGIN_NAMESPACE - -// #define QELFPARSER_DEBUG 1 - -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, QLibraryPrivate *lib, long *pos, ulong *sectionlen) -{ -#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 (qstrcmp(shnam, ".qtplugin") == 0 || qstrcmp(shnam, ".rodata") == 0) { - if (!(sh.type & 0x1)) { - if (shnam[1] == 'r') { - if (lib) - lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) - .arg(QLatin1String("empty .rodata. not a library.")); - return Corrupt; - } -#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; - } - *pos = sh.offset; - *sectionlen = sh.size - 1; - if (shnam[1] == 'q') - return Ok; - } - s += e_shentsize; - } - return NoQtSection; -} - -QT_END_NAMESPACE - diff --git a/src/corelib/plugin/qelfparser_p.h b/src/corelib/plugin/qelfparser_p.h deleted file mode 100644 index 380d5a1..0000000 --- a/src/corelib/plugin/qelfparser_p.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef QELFPARSER_P_H -#define QELFPARSER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <qendian.h> -#include <qglobal.h> - -QT_BEGIN_NAMESPACE - -class QString; -class QLibraryPrivate; - -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, QLibraryPrivate *lib, long *pos, ulong *sectionlen); -}; - -QT_END_NAMESPACE - -#endif // QELFPARSER_P_H - diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 8f82cc4..1ca9d70 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "qplatformdefs.h" #include "qlibrary.h" @@ -60,7 +61,6 @@ #include <qdebug.h> #include <qvector.h> #include <qdir.h> -#include "qelfparser_p.h" QT_BEGIN_NAMESPACE @@ -365,31 +365,11 @@ static bool qt_unix_query(const QString &library, uint *version, bool *debug, QB fdlen = data.size(); } - /* - ELF binaries on GNU, have .qplugin sections. - */ - long pos = 0; + // verify that the pattern is present in the plugin const char pattern[] = "pattern=QT_PLUGIN_VERIFICATION_DATA"; const ulong plen = qstrlen(pattern); -#if defined (Q_OF_ELF) && defined(Q_CC_GNU) - int r = QElfParser().parse(filedata, fdlen, library, lib, &pos, &fdlen); - if (r == QElfParser::NoQtSection) { - if (pos > 0) { - // find inside .rodata - long rel = qt_find_pattern(filedata + pos, fdlen, pattern, plen); - if (rel < 0) { - pos = -1; - } else { - pos += rel; - } - } else { - pos = qt_find_pattern(filedata, fdlen, pattern, plen); - } - } else if (r != QElfParser::Ok) - return false; -#else - pos = qt_find_pattern(filedata, fdlen, pattern, plen); -#endif // defined(Q_OF_ELF) && defined(Q_CC_GNU) + long pos = qt_find_pattern(filedata, fdlen, pattern, plen); + bool ret = false; if (pos >= 0) ret = qt_parse_pattern(filedata + pos, version, debug, key); |