Skip to content

Commit

Permalink
Add support for LoongArch (eliben#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetist authored Apr 21, 2023
1 parent 62ad1bd commit 2059475
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions elftools/elf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions elftools/elf/descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)

Expand Down
1 change: 1 addition & 0 deletions elftools/elf/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions scripts/readelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2059475

Please sign in to comment.