From 20594758fbdafaaa5fc789d79bd6697de738dc7e Mon Sep 17 00:00:00 2001 From: Wu Xiaotian Date: Fri, 21 Apr 2023 21:13:14 +0800 Subject: [PATCH] Add support for LoongArch (#470) refer: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_flags_identifies_abi_type_and_version --- elftools/elf/constants.py | 7 +++++++ elftools/elf/descriptions.py | 1 + elftools/elf/enums.py | 1 + scripts/readelf.py | 12 ++++++++++++ 4 files changed, 21 insertions(+) diff --git a/elftools/elf/constants.py b/elftools/elf/constants.py index 7cb21592..d3cb3a29 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 ff1edbf1..91552104 100644 --- a/elftools/elf/descriptions.py +++ b/elftools/elf/descriptions.py @@ -404,6 +404,7 @@ def describe_note_gnu_properties(properties): 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 c068a613..fe894d2c 100644 --- a/elftools/elf/enums.py +++ b/elftools/elf/enums.py @@ -257,6 +257,7 @@ 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 f44a0bea..14e29ae0 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -259,6 +259,18 @@ def decode_flags(self, flags): 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):