From 57960ab075b9e7a471c42ddea6a2abbc2994ec83 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 12 Sep 2021 20:07:40 -0700 Subject: Q{Elf,Mach}Parser: simplify the return codes The multi-state return code was a legacy of how Arvid wrote the ELF parser code back in the day, the fact that it scanned for two different types of plugins in Qt 4 and that the metadata could exist in different places. None of that matters nowadays: who cares if the file is a corrupt binary, not a valid binary, does not have the right architecture, or has no suitable section? It's not a plugin, period. The Qt 4 plugin mechanism was removed for Qt 5.0 in commit 7443895857fdaee132c8efc643e471f02b3d0fa4 ("Remove support for Qt 4 style plugins"). Change-Id: I42eb903a916645db9900fffd16a442d800399b98 Reviewed-by: Lars Knoll Reviewed-by: Oswald Buddenhagen --- src/corelib/plugin/qmachparser.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/corelib/plugin/qmachparser.cpp') diff --git a/src/corelib/plugin/qmachparser.cpp b/src/corelib/plugin/qmachparser.cpp index 9d0b4de4f5..db4453dffe 100644 --- a/src/corelib/plugin/qmachparser.cpp +++ b/src/corelib/plugin/qmachparser.cpp @@ -42,7 +42,6 @@ #if defined(Q_OF_MACH_O) #include -#include "qlibrary_p.h" #include #include @@ -81,15 +80,16 @@ typedef section my_section; static const uint32_t my_magic = MH_MAGIC; #endif -static int ns(const QString &reason, const QString &library, QString *errorString) +Q_DECL_COLD_FUNCTION +static QLibraryScanResult ns(const QString &reason, const QString &library, QString *errorString) { if (errorString) *errorString = QLibrary::tr("'%1' is not a valid Mach-O binary (%2)") .arg(library, reason.isEmpty() ? QLibrary::tr("file is corrupt") : reason); - return QMachOParser::NotSuitable; + return {}; } -int QMachOParser::parse(const char *m_s, ulong fdlen, const QString &library, QString *errorString, qsizetype *pos, qsizetype *sectionlen) +QLibraryScanResult QMachOParser::parse(const char *m_s, ulong fdlen, const QString &library, QString *errorString) { // The minimum size of a Mach-O binary we're interested in. // It must have a full Mach header, at least one segment and at least one @@ -146,9 +146,7 @@ int QMachOParser::parse(const char *m_s, ulong fdlen, const QString &library, QS library, errorString); } - // from this point on, fdlen is specific to this architecture // from this point on, everything is in host byte order - *pos = reinterpret_cast(header) - m_s; // (re-)check the CPU type // ### should we check the CPU subtype? Maybe on ARM? @@ -197,9 +195,8 @@ int QMachOParser::parse(const char *m_s, ulong fdlen, const QString &library, QS || Q_UNLIKELY(fdlen < sect[j].offset + sect[j].size)) return ns(QString(), library, errorString); - *pos += sect[j].offset; - *sectionlen = sect[j].size; - return QtMetaDataSection; + qsizetype pos = reinterpret_cast(header) - m_s + sect[j].offset; + return { pos, qsizetype(sect[j].size) }; } } @@ -207,11 +204,10 @@ int QMachOParser::parse(const char *m_s, ulong fdlen, const QString &library, QS seg = reinterpret_cast(reinterpret_cast(seg) + seg->cmdsize); } -// // No Qt section was found, but at least we know that where the proper architecture's boundaries are -// return NoQtSection; + // No .qtmetadata section was found if (errorString) *errorString = QLibrary::tr("'%1' is not a Qt plugin").arg(library); - return NotSuitable; + return {}; } QT_END_NAMESPACE -- cgit v1.2.3