From bdc16f086f1664b56d8add0691c9a80d7997efd9 Mon Sep 17 00:00:00 2001 From: WANG Xuerui Date: Tue, 25 Oct 2022 14:36:52 +0800 Subject: Add LoongArch detection - detect the LoongArch architecture, define Q_PROCESSOR_LOONGARCH and Q_PROCESSOR_LOONGARCH_{32,64} appropriately - document the macros as being available starting from 6.5 - add LoongArch ELF support in QElfParser Change-Id: I438146af49ec3adacacec84c27c9f4abaa542830 Reviewed-by: Thiago Macieira --- src/corelib/global/archdetect.cpp | 4 ++++ src/corelib/global/qprocessordetection.h | 14 ++++++++++++ src/corelib/global/qprocessordetection.qdoc | 34 +++++++++++++++++++++++++++++ src/corelib/plugin/qelfparser_p.cpp | 5 +++++ 4 files changed, 57 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/global/archdetect.cpp b/src/corelib/global/archdetect.cpp index 188ec2d176..0c08393ab9 100644 --- a/src/corelib/global/archdetect.cpp +++ b/src/corelib/global/archdetect.cpp @@ -25,6 +25,10 @@ # define ARCH_PROCESSOR "x86_64" #elif defined(Q_PROCESSOR_IA64) # define ARCH_PROCESSOR "ia64" +#elif defined(Q_PROCESSOR_LOONGARCH_32) +# define ARCH_PROCESSOR "loongarch32" +#elif defined(Q_PROCESSOR_LOONGARCH_64) +# define ARCH_PROCESSOR "loongarch64" #elif defined(Q_PROCESSOR_M68K) # define ARCH_PROCESSOR "m68k" #elif defined(Q_PROCESSOR_MIPS_64) diff --git a/src/corelib/global/qprocessordetection.h b/src/corelib/global/qprocessordetection.h index 1b6139152e..6ca1d23933 100644 --- a/src/corelib/global/qprocessordetection.h +++ b/src/corelib/global/qprocessordetection.h @@ -199,6 +199,20 @@ # define Q_PROCESSOR_WORDSIZE 8 // Q_BYTE_ORDER not defined, use endianness auto-detection +/* + LoongArch family, known variants: 32- and 64-bit + + LoongArch is little-endian. +*/ +#elif defined(__loongarch__) +# define Q_PROCESSOR_LOONGARCH +# if __loongarch_grlen == 64 +# define Q_PROCESSOR_LOONGARCH_64 +# else +# define Q_PROCESSOR_LOONGARCH_32 +# endif +# define Q_BYTE_ORDER Q_LITTLE_ENDIAN + /* Motorola 68000 family, no revisions or variants diff --git a/src/corelib/global/qprocessordetection.qdoc b/src/corelib/global/qprocessordetection.qdoc index 08486a4433..e6605fb9b9 100644 --- a/src/corelib/global/qprocessordetection.qdoc +++ b/src/corelib/global/qprocessordetection.qdoc @@ -105,6 +105,40 @@ \sa QSysInfo::buildCpuArchitecture() */ +/*! + \macro Q_PROCESSOR_LOONGARCH + \relates + \since 6.5 + + Defined if the application is compiled for LoongArch processors. + + \sa QSysInfo::buildCpuArchitecture() +*/ + +/*! + \macro Q_PROCESSOR_LOONGARCH_32 + \relates + \since 6.5 + + Defined if the application is compiled for 32-bit LoongArch processors. + The \l Q_PROCESSOR_LOONGARCH macro is also defined when + Q_PROCESSOR_LOONGARCH_32 is defined. + + \sa QSysInfo::buildCpuArchitecture() +*/ + +/*! + \macro Q_PROCESSOR_LOONGARCH_64 + \relates + \since 6.5 + + Defined if the application is compiled for 64-bit LoongArch processors. + The \l Q_PROCESSOR_LOONGARCH macro is also defined when + Q_PROCESSOR_LOONGARCH_64 is defined. + + \sa QSysInfo::buildCpuArchitecture() +*/ + /*! \macro Q_PROCESSOR_M68K \relates diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp index 4388c6babe..b7c6760864 100644 --- a/src/corelib/plugin/qelfparser_p.cpp +++ b/src/corelib/plugin/qelfparser_p.cpp @@ -122,6 +122,8 @@ struct ElfMachineCheck 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) @@ -387,6 +389,9 @@ Q_DECL_UNUSED Q_DECL_COLD_FUNCTION static QDebug &operator<<(QDebug &d, ElfHeade 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; -- cgit v1.2.3