Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LoongArch Support #1

Open
wants to merge 2 commits into
base: la64/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/python/examples/elf_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def print_header(binary):

if header.machine_type == lief.ELF.ARCH.HEXAGON:
eflags_str = " - ".join([str(s).split(".")[-1] for s in header.hexagon_flags_list])

if header.machine_type == lief.ELF.ARCH.LOONGARCH:
eflags_str = " - ".join([str(s).split(".")[-1] for s in header.loongarch_flags_list])
print(identity)
print(format_ide.format("Magic:", identity[0], identity[1], identity[2], identity[3]))
print(format_str.format("Class:", str(header.identity_class).split(".")[-1]))
Expand Down
3 changes: 2 additions & 1 deletion api/python/src/Abstract/pyEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ void init_enums(py::module& m) {
.value(PY_ENUM(ARCHITECTURES::ARCH_SYSZ))
.value(PY_ENUM(ARCHITECTURES::ARCH_XCORE))
.value(PY_ENUM(ARCHITECTURES::ARCH_INTEL))
.value(PY_ENUM(ARCHITECTURES::ARCH_RISCV));
.value(PY_ENUM(ARCHITECTURES::ARCH_RISCV))
.value(PY_ENUM(ARCHITECTURES::ARCH_LOONGARCH));

py::enum_<MODES>(m, "MODES")
.value(PY_ENUM(MODES::MODE_NONE))
Expand Down
11 changes: 11 additions & 0 deletions api/python/src/ELF/objects/pyHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ void create<Header>(py::module& m) {
":attr:`~lief.ELF.Header.processor_flag`",
py::return_value_policy::reference_internal)

.def_property_readonly("loongarch_flags_list",
&Header::loongarch_flags_list,
"Return a list of " RST_CLASS_REF(lief.ELF.LOONGARCH_EFLAGS) " present in "
":attr:`~lief.ELF.Header.processor_flag`",
py::return_value_policy::reference_internal)

.def_property("header_size",
static_cast<getter_t<uint32_t>>(&Header::header_size),
static_cast<setter_t<uint32_t>>(&Header::header_size),
Expand Down Expand Up @@ -230,6 +236,11 @@ void create<Header>(py::module& m) {
"Check if the given " RST_CLASS_REF(lief.ELF.HEXAGON_EFLAGS) " is present in "
":attr:`~lief.ELF.Header.processor_flag`")

.def("__contains__",
static_cast<bool (Header::*)(LOONGARCH_EFLAGS) const>(&Header::has),
"Check if the given " RST_CLASS_REF(lief.ELF.LOONGARCH_EFLAGS) " is present in "
":attr:`~lief.ELF.Header.processor_flag`")

.def("__str__",
[] (const Header& header)
{
Expand Down
97 changes: 96 additions & 1 deletion api/python/src/ELF/pyEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ void init_enums(py::module& m) {
.value(PY_ENUM(ARCH::EM_CSR_KALIMBA))
.value(PY_ENUM(ARCH::EM_AMDGPU))
.value(PY_ENUM(ARCH::EM_RISCV))
.value(PY_ENUM(ARCH::EM_BPF));
.value(PY_ENUM(ARCH::EM_BPF))
.value(PY_ENUM(ARCH::EM_LOONGARCH));


//! Enum for the *sh_type* of ElfXX_Shdr;
Expand Down Expand Up @@ -1079,6 +1080,96 @@ void init_enums(py::module& m) {
.value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC18_S3))
.value(PY_ENUM(RELOC_MIPS::R_MICROMIPS_PC19_S2));

LIEF::enum_<RELOC_LOONGARCH>(m, "RELOCATION_LOONGARCH")
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_NONE))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_32))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_64))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_RELATIVE))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_COPY))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_JUMP_SLOT))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_DTPMOD32))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_DTPMOD64))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_DTPREL32))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_DTPREL64))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_TPREL32))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_TPREL64))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_IRELATIVE))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_MARK_LA))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_MARK_PCREL))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_PCREL))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_ABSOLUTE))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_DUP))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_GPREL))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_TPREL))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_GOT))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_TLS_GD))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_PUSH_PLT_PCREL))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_ASSERT))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_NOT))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_SUB))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_SL))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_SR))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_ADD))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_AND))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_IF_ELSE))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_5))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_U_10_12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_16))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_10_16_S2))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_5_20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_0_5_10_16_S2))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_S_0_10_10_16_S2))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SOP_POP_32_U))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD8))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD16))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD24))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD32))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ADD64))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB8))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB16))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB24))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB32))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_SUB64))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GNU_VTINHERIT))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GNU_VTENTRY))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_B16))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_B21))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_B26))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ABS_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ABS_LO12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ABS64_LO20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_ABS64_HI12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_PCALA_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_PCALA_LO12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_PCALA64_LO20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_PCALA64_HI12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT_PC_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT_PC_LO12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT64_PC_LO20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT64_PC_HI12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT_LO12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT64_LO20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_GOT64_HI12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LE_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LE_LO12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LE64_LO20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LE64_HI12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE_PC_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE_PC_LO12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE64_PC_LO20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE64_PC_HI12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE_LO12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE64_LO20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_IE64_HI12))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LD_PC_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_LD_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_GD_PC_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_TLS_GD_HI20))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_32_PCREL))
.value(PY_ENUM(RELOC_LOONGARCH::R_LARCH_RELAX));

LIEF::enum_<DYNSYM_COUNT_METHODS>(m, "DYNSYM_COUNT_METHODS")
.value(PY_ENUM(DYNSYM_COUNT_METHODS::COUNT_AUTO))
Expand Down Expand Up @@ -1208,6 +1299,10 @@ void init_enums(py::module& m) {
.value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_ISA_V4))
.value(PY_ENUM(HEXAGON_EFLAGS::EF_HEXAGON_ISA_V5));

LIEF::enum_<LOONGARCH_EFLAGS>(m, "LOONGARCH_EFLAGS", py::arithmetic())
.value(PY_ENUM(LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_SOFT_FLOAT))
.value(PY_ENUM(LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_SINGLE_FLOAT))
.value(PY_ENUM(LOONGARCH_EFLAGS::EF_LOONGARCH_ABI_DOUBLE_FLOAT));

LIEF::enum_<IDENTITY>(m, "IDENTITY")
.value(PY_ENUM(IDENTITY::EI_MAG0))
Expand Down
1 change: 1 addition & 0 deletions include/LIEF/Abstract/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum ARCHITECTURES {
ARCH_XCORE = 8,
ARCH_INTEL = 9,
ARCH_RISCV = 10,
ARCH_LOONGARCH = 11,
};

enum MODES {
Expand Down
2 changes: 2 additions & 0 deletions include/LIEF/ELF/EnumToString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ LIEF_API const char* to_string(PPC64_EFLAGS e);
LIEF_API const char* to_string(ARM_EFLAGS e);
LIEF_API const char* to_string(MIPS_EFLAGS e);
LIEF_API const char* to_string(HEXAGON_EFLAGS e);
LIEF_API const char* to_string(LOONGARCH_EFLAGS e);
LIEF_API const char* to_string(RELOC_LOONGARCH e);



Expand Down
7 changes: 7 additions & 0 deletions include/LIEF/ELF/Header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LIEF_API Header : public Object {
using mips_flags_list_t = flags_list_t<MIPS_EFLAGS>;
using hexagon_flags_list_t = flags_list_t<HEXAGON_EFLAGS>;
using ppc64_flags_list_t = flags_list_t<PPC64_EFLAGS>;
using loongarch_flags_list_t = flags_list_t<LOONGARCH_EFLAGS>;

public:
Header();
Expand Down Expand Up @@ -117,6 +118,12 @@ class LIEF_API Header : public Object {
//! Return a list of HEXAGON_EFLAGS present in processor_flag()
hexagon_flags_list_t hexagon_flags_list() const;

//! Check if the given flag is present in processor_flag()
bool has(LOONGARCH_EFLAGS f) const;

//! Return a list of LOONGARCH_EFLAGS present in processor_flag()
loongarch_flags_list_t loongarch_flags_list() const;

//! Size of the current header
//!
//! This size should be 64 for an ``ELF64`` binary and 52 for an ``ELF32``.
Expand Down
1 change: 1 addition & 0 deletions include/LIEF/ELF/Relocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class LIEF_API Relocation : public LIEF::Relocation {
//! * RELOC_HEXAGON
//! * RELOC_SYSTEMZ
//! * RELOC_SPARC
//! * RELOC_LOONGARCH
uint32_t type() const;

//! Check if the relocation uses the explicit addend() field (this is usually the case for 64 bits binaries)
Expand Down
1 change: 1 addition & 0 deletions include/LIEF/ELF/RelocationSizes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ int32_t get_reloc_size(RELOC_AARCH64 R);
int32_t get_reloc_size(RELOC_POWERPC32 R);
int32_t get_reloc_size(RELOC_POWERPC64 R);
int32_t get_reloc_size(RELOC_MIPS R);
int32_t get_reloc_size(RELOC_LOONGARCH R);

}
}
Expand Down
102 changes: 102 additions & 0 deletions include/LIEF/ELF/Relocations/LoongArch.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

#ifndef ELF_RELOC
#error "ELF_RELOC must be defined"
#endif

ELF_RELOC(R_LARCH_NONE, 0)
ELF_RELOC(R_LARCH_32, 1)
ELF_RELOC(R_LARCH_64, 2)
ELF_RELOC(R_LARCH_RELATIVE, 3)
ELF_RELOC(R_LARCH_COPY, 4)
ELF_RELOC(R_LARCH_JUMP_SLOT, 5)
ELF_RELOC(R_LARCH_TLS_DTPMOD32, 6)
ELF_RELOC(R_LARCH_TLS_DTPMOD64, 7)
ELF_RELOC(R_LARCH_TLS_DTPREL32, 8)
ELF_RELOC(R_LARCH_TLS_DTPREL64, 9)
ELF_RELOC(R_LARCH_TLS_TPREL32, 10)
ELF_RELOC(R_LARCH_TLS_TPREL64, 11)
ELF_RELOC(R_LARCH_IRELATIVE, 12)

ELF_RELOC(R_LARCH_MARK_LA, 20)
ELF_RELOC(R_LARCH_MARK_PCREL, 21)

ELF_RELOC(R_LARCH_SOP_PUSH_PCREL, 22)

ELF_RELOC(R_LARCH_SOP_PUSH_ABSOLUTE, 23)

ELF_RELOC(R_LARCH_SOP_PUSH_DUP, 24)
ELF_RELOC(R_LARCH_SOP_PUSH_GPREL, 25)
ELF_RELOC(R_LARCH_SOP_PUSH_TLS_TPREL, 26)
ELF_RELOC(R_LARCH_SOP_PUSH_TLS_GOT, 27)
ELF_RELOC(R_LARCH_SOP_PUSH_TLS_GD, 28)
ELF_RELOC(R_LARCH_SOP_PUSH_PLT_PCREL, 29)

ELF_RELOC(R_LARCH_SOP_ASSERT, 30)
ELF_RELOC(R_LARCH_SOP_NOT, 31)
ELF_RELOC(R_LARCH_SOP_SUB, 32)
ELF_RELOC(R_LARCH_SOP_SL, 33)
ELF_RELOC(R_LARCH_SOP_SR, 34)
ELF_RELOC(R_LARCH_SOP_ADD, 35)
ELF_RELOC(R_LARCH_SOP_AND, 36)
ELF_RELOC(R_LARCH_SOP_IF_ELSE, 37)
ELF_RELOC(R_LARCH_SOP_POP_32_S_10_5, 38)
ELF_RELOC(R_LARCH_SOP_POP_32_U_10_12, 39)
ELF_RELOC(R_LARCH_SOP_POP_32_S_10_12, 40)
ELF_RELOC(R_LARCH_SOP_POP_32_S_10_16, 41)
ELF_RELOC(R_LARCH_SOP_POP_32_S_10_16_S2, 42)
ELF_RELOC(R_LARCH_SOP_POP_32_S_5_20, 43)
ELF_RELOC(R_LARCH_SOP_POP_32_S_0_5_10_16_S2, 44)
ELF_RELOC(R_LARCH_SOP_POP_32_S_0_10_10_16_S2, 45)
ELF_RELOC(R_LARCH_SOP_POP_32_U, 46)

ELF_RELOC(R_LARCH_ADD8, 47)
ELF_RELOC(R_LARCH_ADD16, 48)
ELF_RELOC(R_LARCH_ADD24, 49)
ELF_RELOC(R_LARCH_ADD32, 50)
ELF_RELOC(R_LARCH_ADD64, 51)
ELF_RELOC(R_LARCH_SUB8, 52)
ELF_RELOC(R_LARCH_SUB16, 53)
ELF_RELOC(R_LARCH_SUB24, 54)
ELF_RELOC(R_LARCH_SUB32, 55)
ELF_RELOC(R_LARCH_SUB64, 56)

ELF_RELOC(R_LARCH_GNU_VTINHERIT, 57)
ELF_RELOC(R_LARCH_GNU_VTENTRY, 58)

ELF_RELOC(R_LARCH_B16, 64)
ELF_RELOC(R_LARCH_B21, 65)
ELF_RELOC(R_LARCH_B26, 66)
ELF_RELOC(R_LARCH_ABS_HI20, 67)
ELF_RELOC(R_LARCH_ABS_LO12, 68)
ELF_RELOC(R_LARCH_ABS64_LO20, 69)
ELF_RELOC(R_LARCH_ABS64_HI12, 70)
ELF_RELOC(R_LARCH_PCALA_HI20, 71)
ELF_RELOC(R_LARCH_PCALA_LO12, 72)
ELF_RELOC(R_LARCH_PCALA64_LO20, 73)
ELF_RELOC(R_LARCH_PCALA64_HI12, 74)
ELF_RELOC(R_LARCH_GOT_PC_HI20, 75)
ELF_RELOC(R_LARCH_GOT_PC_LO12, 76)
ELF_RELOC(R_LARCH_GOT64_PC_LO20, 77)
ELF_RELOC(R_LARCH_GOT64_PC_HI12, 78)
ELF_RELOC(R_LARCH_GOT_HI20, 79)
ELF_RELOC(R_LARCH_GOT_LO12, 80)
ELF_RELOC(R_LARCH_GOT64_LO20, 81)
ELF_RELOC(R_LARCH_GOT64_HI12, 82)
ELF_RELOC(R_LARCH_TLS_LE_HI20, 83)
ELF_RELOC(R_LARCH_TLS_LE_LO12, 84)
ELF_RELOC(R_LARCH_TLS_LE64_LO20, 85)
ELF_RELOC(R_LARCH_TLS_LE64_HI12, 86)
ELF_RELOC(R_LARCH_TLS_IE_PC_HI20, 87)
ELF_RELOC(R_LARCH_TLS_IE_PC_LO12, 88)
ELF_RELOC(R_LARCH_TLS_IE64_PC_LO20, 89)
ELF_RELOC(R_LARCH_TLS_IE64_PC_HI12, 90)
ELF_RELOC(R_LARCH_TLS_IE_HI20, 91)
ELF_RELOC(R_LARCH_TLS_IE_LO12, 92)
ELF_RELOC(R_LARCH_TLS_IE64_LO20, 93)
ELF_RELOC(R_LARCH_TLS_IE64_HI12, 94)
ELF_RELOC(R_LARCH_TLS_LD_PC_HI20, 95)
ELF_RELOC(R_LARCH_TLS_LD_HI20, 96)
ELF_RELOC(R_LARCH_TLS_GD_PC_HI20, 97)
ELF_RELOC(R_LARCH_TLS_GD_HI20, 98)
ELF_RELOC(R_LARCH_32_PCREL, 99)
ELF_RELOC(R_LARCH_RELAX, 100)
16 changes: 14 additions & 2 deletions include/LIEF/ELF/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ enum class ARCH: size_t {
EM_CSR_KALIMBA = 219, /**< CSR Kalimba architecture family */
EM_AMDGPU = 224, /**< AMD GPU architecture */
EM_RISCV = 243, /**< RISC-V */
EM_BPF = 247 /**< eBPF Filter */
EM_BPF = 247, /**< eBPF Filter */
EM_LOONGARCH = 258 /**< LoongArch */
};


Expand Down Expand Up @@ -346,6 +347,11 @@ enum class RELOC_SPARC: size_t {
#include "LIEF/ELF/Relocations/Sparc.def"
};

/* ELF Relocation types for LoongArch. */
enum class RELOC_LOONGARCH: size_t {
#include "LIEF/ELF/Relocations/LoongArch.def"
};

#undef ELF_RELOC

/* Specific e_flags for PPC64 */
Expand Down Expand Up @@ -449,7 +455,12 @@ enum class HEXAGON_EFLAGS: size_t {
EF_HEXAGON_ISA_V5 = 0x00000040 /* Hexagon V5 ISA */
};


/* LoongArch Specific e_flags */
enum class LOONGARCH_EFLAGS: size_t {
EF_LOONGARCH_ABI_SOFT_FLOAT = 0x1,
EF_LOONGARCH_ABI_SINGLE_FLOAT = 0x2,
EF_LOONGARCH_ABI_DOUBLE_FLOAT = 0x3
};


/** Special section indices. */
Expand Down Expand Up @@ -998,6 +1009,7 @@ ENABLE_BITMASK_OPERATORS(LIEF::ELF::ELF_SEGMENT_FLAGS)
ENABLE_BITMASK_OPERATORS(LIEF::ELF::ARM_EFLAGS)
ENABLE_BITMASK_OPERATORS(LIEF::ELF::MIPS_EFLAGS)
ENABLE_BITMASK_OPERATORS(LIEF::ELF::HEXAGON_EFLAGS)
ENABLE_BITMASK_OPERATORS(LIEF::ELF::LOONGARCH_EFLAGS)
ENABLE_BITMASK_OPERATORS(LIEF::ELF::ELF_SECTION_FLAGS)
ENABLE_BITMASK_OPERATORS(LIEF::ELF::DYNAMIC_FLAGS)
ENABLE_BITMASK_OPERATORS(LIEF::ELF::DYNAMIC_FLAGS_1)
Expand Down
15 changes: 13 additions & 2 deletions include/LIEF/ELF/enums.inc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ enum _LIEF_EN(ARCH) {
_LIEF_EI(EM_CSR_KALIMBA) = 219, /**< CSR Kalimba architecture family */
_LIEF_EI(EM_AMDGPU) = 224, /**< AMD GPU architecture */
_LIEF_EI(EM_RISCV) = 243, /**< RISC-V */
_LIEF_EI(EM_BPF) = 247 /**< eBPF Filter */
_LIEF_EI(EM_BPF) = 247, /**< eBPF Filter */
_LIEF_EI(EM_LOONGARCH) = 258 /**< LoongArch */
};


Expand Down Expand Up @@ -321,6 +322,11 @@ enum _LIEF_EN(RELOC_SPARC) {
#include "LIEF/ELF/Relocations/Sparc.def"
};

/* ELF Relocation types for LoongArch. */
enum _LIEF_EN(RELOC_LOONGARCH) {
#include "LIEF/ELF/Relocations/LoongArch.def"
};

#undef ELF_RELOC

/* Specific e_flags for PPC64 */
Expand Down Expand Up @@ -425,7 +431,12 @@ enum _LIEF_EN(HEXAGON_EFLAGS) {
};



/* LoongArch Specific e_flags */
enum _LIEF_EN(LOONGARCH_EFLAGS) {
_LIEF_EI(EF_LOONGARCH_ABI_SOFT_FLOAT) = 0x1,
_LIEF_EI(EF_LOONGARCH_ABI_SINGLE_FLOAT) = 0x2,
_LIEF_EI(EF_LOONGARCH_ABI_DOUBLE_FLOAT) = 0x3
};

/** Special section indices. */
enum _LIEF_EN(SYMBOL_SECTION_INDEX) {
Expand Down
Loading