From: Wu Xiaotian Date: Fri, 21 Apr 2023 13:13:14 +0000 (+0800) Subject: Add support for LoongArch (#470) X-Git-Tag: v0.30~10 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=20594758fbdafaaa5fc789d79bd6697de738dc7e;p=pyelftools.git Add support for LoongArch (#470) refer: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_flags_identifies_abi_type_and_version --- diff --git a/elftools/elf/constants.py b/elftools/elf/constants.py index 7cb2159..d3cb3a2 100644 --- a/elftools/elf/constants.py +++ b/elftools/elf/constants.py @@ -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 diff --git a/elftools/elf/descriptions.py b/elftools/elf/descriptions.py index ff1edbf..9155210 100644 --- a/elftools/elf/descriptions.py +++ b/elftools/elf/descriptions.py @@ -404,6 +404,7 @@ _DESCR_E_MACHINE = dict( EM_PPC='PowerPC', EM_PPC64='PowerPC64', EM_RISCV='RISC-V', + EM_LOONGARCH='LoongArch', RESERVED='RESERVED', ) diff --git a/elftools/elf/enums.py b/elftools/elf/enums.py index c068a61..fe894d2 100644 --- a/elftools/elf/enums.py +++ b/elftools/elf/enums.py @@ -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 diff --git a/scripts/readelf.py b/scripts/readelf.py index f44a0be..14e29ae 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -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):