summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/qelfparser_p.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/plugin/qelfparser_p.cpp')
-rw-r--r--src/corelib/plugin/qelfparser_p.cpp82
1 files changed, 35 insertions, 47 deletions
diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp
index ed973e4323..7f6271cde4 100644
--- a/src/corelib/plugin/qelfparser_p.cpp
+++ b/src/corelib/plugin/qelfparser_p.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Copyright (C) 2021 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2021 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qelfparser_p.h"
@@ -58,6 +22,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
// ### Qt7: propagate the constant and eliminate dead code
static constexpr bool ElfNotesAreMandatory = QT_VERSION >= QT_VERSION_CHECK(7,0,0);
@@ -88,6 +54,10 @@ static Q_LOGGING_CATEGORY(lcElfParser, "qt.core.plugin.elfparser")
# define PT_GNU_PROPERTY 0x6474e553
#endif
+#ifndef PN_XNUM
+# define PN_XNUM 0xffff
+#endif
+
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wunused-const-variable")
@@ -141,14 +111,22 @@ struct ElfMachineCheck
static const Elf32_Half ExpectedMachine =
#if 0
// nothing
+#elif defined(Q_PROCESSOR_ALPHA)
+ EM_ALPHA
#elif defined(Q_PROCESSOR_ARM_32)
EM_ARM
#elif defined(Q_PROCESSOR_ARM_64)
EM_AARCH64
#elif defined(Q_PROCESSOR_BLACKFIN)
EM_BLACKFIN
+#elif defined(Q_PROCESSOR_HPPA)
+ EM_PARISC
#elif defined(Q_PROCESSOR_IA64)
EM_IA_64
+#elif defined(Q_PROCESSOR_LOONGARCH)
+ EM_LOONGARCH
+#elif defined(Q_PROCESSOR_M68K)
+ EM_68K
#elif defined(Q_PROCESSOR_MIPS)
EM_MIPS
#elif defined(Q_PROCESSOR_POWER_32)
@@ -162,10 +140,8 @@ struct ElfMachineCheck
#elif defined(Q_PROCESSOR_SH)
EM_SH
#elif defined(Q_PROCESSOR_SPARC_V9)
-# warning "Please confirm that this is correct for Linux and Solaris"
EM_SPARCV9
#elif defined(Q_PROCESSOR_SPARC_64)
-# warning "Please confirm that this is correct for Linux and Solaris"
EM_SPARCV9
#elif defined(Q_PROCESSOR_SPARC)
EM_SPARC
@@ -363,7 +339,7 @@ Q_DECL_UNUSED Q_DECL_COLD_FUNCTION static QDebug &operator<<(QDebug &d, ElfHeade
case ELFOSABI_SYSV: d << " (SYSV"; break;
case ELFOSABI_HPUX: d << " (HP-UX"; break;
case ELFOSABI_NETBSD: d << " (NetBSD"; break;
- case ELFOSABI_GNU: d << " (GNU/Linux"; break;
+ case ELFOSABI_LINUX: d << " (GNU/Linux"; break;
case ELFOSABI_SOLARIS: d << " (Solaris"; break;
case ELFOSABI_AIX: d << " (AIX"; break;
case ELFOSABI_IRIX: d << " (IRIX"; break;
@@ -407,17 +383,27 @@ Q_DECL_UNUSED Q_DECL_COLD_FUNCTION static QDebug &operator<<(QDebug &d, ElfHeade
switch (r.machine) {
// list definitely not exhaustive!
case EM_NONE: d << ", no machine"; break;
+ case EM_ALPHA: d << ", Alpha"; break;
+ case EM_68K: d << ", MC68000"; break;
case EM_ARM: d << ", ARM"; break;
case EM_AARCH64: d << ", AArch64"; break;
+#ifdef EM_BLACKFIN
case EM_BLACKFIN: d << ", Blackfin"; break;
+#endif
case EM_IA_64: d << ", IA-64"; break;
+#ifdef EM_LOONGARCH
+ case EM_LOONGARCH: d << ", LoongArch"; break;
+#endif
case EM_MIPS: d << ", MIPS"; break;
+ case EM_PARISC: d << ", HPPA"; break;
case EM_PPC: d << ", PowerPC"; break;
case EM_PPC64: d << ", PowerPC 64-bit"; break;
#ifdef EM_RISCV
case EM_RISCV: d << ", RISC-V"; break;
#endif
+#ifdef EM_S390
case EM_S390: d << ", S/390"; break;
+#endif
case EM_SH: d << ", SuperH"; break;
case EM_SPARC: d << ", SPARC"; break;
case EM_SPARCV9: d << ", SPARCv9"; break;
@@ -557,6 +543,8 @@ static bool preScanProgramHeaders(QByteArrayView data, const ErrorMaker &error)
// first, validate the extent of the full program header table
T::Word e_phnum = header->e_phnum;
+ if (e_phnum == PN_XNUM)
+ return error(QLibrary::tr("unimplemented: PN_XNUM program headers")), false;
T::Off offset = e_phnum * sizeof(T::Phdr); // can't overflow due to size of T::Half
if (qAddOverflow(offset, header->e_phoff, &offset) || offset > size_t(data.size()))
return error(QLibrary::tr("program header table extends past the end of the file")), false;
@@ -696,11 +684,11 @@ static QLibraryScanResult scanSections(QByteArrayView data, const ErrorMaker &er
const char *shstrtab_start = data.data() + offset;
shdr = sections;
for (int section = 0; shdr != sections_end; ++section, ++shdr) {
- QLatin1String name;
+ QLatin1StringView name;
if (shdr->sh_name < shstrtab_size) {
const char *namestart = shstrtab_start + shdr->sh_name;
size_t len = qstrnlen(namestart, shstrtab_size - shdr->sh_name);
- name = QLatin1String(namestart, len);
+ name = QLatin1StringView(namestart, len);
}
qEDebug << "section" << section << "name" << name << ElfSectionDebug{shdr};
@@ -711,13 +699,13 @@ static QLibraryScanResult scanSections(QByteArrayView data, const ErrorMaker &er
// sections aren't allowed to extend past the end of the file, unless
// they are NOBITS sections
if (shdr->sh_type == SHT_NOBITS)
- continue;;
+ continue;
if (T::Off end; qAddOverflow(shdr->sh_offset, shdr->sh_size, &end)
|| end > size_t(data.size())) {
- return error(QLibrary::tr("a section data extends past the end of the file"));
+ return error(QLibrary::tr("section contents extend past the end of the file"));
}
- if (name != QLatin1String(".qtmetadata"))
+ if (name != ".qtmetadata"_L1)
continue;
qEDebug << "found .qtmetadata section";
if (shdr->sh_size < sizeof(QPluginMetaData::MagicHeader))