Add support for LoongArch (#470)
authorWu Xiaotian <wuxiaotian@zhcn.cc>
Fri, 21 Apr 2023 13:13:14 +0000 (21:13 +0800)
committerGitHub <noreply@github.com>
Fri, 21 Apr 2023 13:13:14 +0000 (06:13 -0700)
refer: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_flags_identifies_abi_type_and_version

elftools/elf/constants.py
elftools/elf/descriptions.py
elftools/elf/enums.py
scripts/readelf.py

index 7cb215927c65c8528d781852f19bafd566523d43..d3cb3a29d8884dc6738291cbbb2d8dba43c0d09a 100644 (file)
@@ -60,6 +60,13 @@ class E_FLAGS(object):
     EF_RISCV_RVE=0x00000008
     EF_RISCV_TSO=0x00000010
 
+    EF_LOONGARCH_ABI=0x000000C0
+    EF_LOONGARCH_ABI_V0=0x00000000
+    EF_LOONGARCH_ABI_V1=0x00000040
+    EF_LOONGARCH_FLOAT_ABI=0x00000003
+    EF_LOONGARCH_FLOAT_ABI_SOFT=0x00000001
+    EF_LOONGARCH_FLOAT_ABI_SINGLE=0x00000002
+    EF_LOONGARCH_FLOAT_ABI_DOUBLE=0x00000003
 
 class E_FLAGS_MASKS(object):
     """Masks to be used for convenience when working with E_FLAGS
index ff1edbf1403857573d52437bf35a56cad05342bb..915521041050bea5e9b9ed47776dd61df390dbf1 100644 (file)
@@ -404,6 +404,7 @@ _DESCR_E_MACHINE = dict(
     EM_PPC='PowerPC',
     EM_PPC64='PowerPC64',
     EM_RISCV='RISC-V',
+    EM_LOONGARCH='LoongArch',
     RESERVED='RESERVED',
 )
 
index c068a613b27cc84edc2373772c4d2859cf330d85..fe894d2c228dc8c3bd8175d3125dfdf41f88f048 100644 (file)
@@ -257,6 +257,7 @@ ENUM_E_MACHINE = dict(
     EM_RISCV         = 243, # RISC-V
     EM_BPF           = 247,    # Linux BPF - in-kernel virtual machine
     EM_CSKY          = 252,    # C-SKY
+    EM_LOONGARCH     = 258, # LoongArch
     EM_FRV           = 0x5441, # Fujitsu FR-V
     # Reservations
     # reserved  11-14   Reserved for future use
index f44a0beaf6d71aa51682a8b5b66619d4119d22c7..14e29ae01e04995f61c8e66d5bb5b45bb076d6b1 100755 (executable)
@@ -259,6 +259,18 @@ class ReadElf(object):
             if (flags & E_FLAGS.EF_RISCV_FLOAT_ABI) == E_FLAGS.EF_RISCV_FLOAT_ABI_QUAD:
                 description += ", quad-float ABI"
 
+        elif self.elffile['e_machine'] == "EM_LOONGARCH":
+            if (flags & E_FLAGS.EF_LOONGARCH_FLOAT_ABI) == E_FLAGS.EF_LOONGARCH_FLOAT_ABI_SOFT:
+                description += ", SOFT-FLOAT"
+            if (flags & E_FLAGS.EF_LOONGARCH_FLOAT_ABI) == E_FLAGS.EF_LOONGARCH_FLOAT_ABI_SINGLE:
+                description += ", SINGLE-FLOAT"
+            if (flags & E_FLAGS.EF_LOONGARCH_FLOAT_ABI) == E_FLAGS.EF_LOONGARCH_FLOAT_ABI_DOUBLE:
+                description += ", DOUBLE-FLOAT"
+            if (flags & E_FLAGS.EF_LOONGARCH_ABI) == E_FLAGS.EF_LOONGARCH_ABI_V0:
+                description += ", OBJ-v0"
+            if (flags & E_FLAGS.EF_LOONGARCH_ABI) == E_FLAGS.EF_LOONGARCH_ABI_V1:
+                description += ", OBJ-v1"
+
         return description
 
     def display_program_headers(self, show_heading=True):