From c03e7e6d7294248c1bdcac1576923fd898f4d9bf Mon Sep 17 00:00:00 2001 From: RAJEES RAHMAN P P <39120657+rajez133@users.noreply.github.com> Date: Tue, 24 Sep 2024 07:39:30 +0530 Subject: [PATCH] Addding relocation type for PPC 32 EABI (#532) --- elftools/elf/descriptions.py | 5 +++- elftools/elf/enums.py | 58 ++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/elftools/elf/descriptions.py b/elftools/elf/descriptions.py index 838668b2..5fc9a4a2 100644 --- a/elftools/elf/descriptions.py +++ b/elftools/elf/descriptions.py @@ -12,7 +12,7 @@ ENUM_RELOC_TYPE_ARM, ENUM_RELOC_TYPE_AARCH64, ENUM_RELOC_TYPE_PPC64, ENUM_RELOC_TYPE_MIPS, ENUM_ATTR_TAG_ARM, ENUM_ATTR_TAG_RISCV, ENUM_RELOC_TYPE_S390X, ENUM_RELOC_TYPE_LOONGARCH, ENUM_DT_FLAGS, - ENUM_DT_FLAGS_1) + ENUM_DT_FLAGS_1, ENUM_RELOC_TYPE_PPC) from .constants import ( P_FLAGS, RH_FLAGS, SH_FLAGS, SUNW_SYMINFO_FLAGS, VER_FLAGS) from ..common.utils import bytes2hex @@ -151,6 +151,8 @@ def describe_reloc_type(x, elffile): return _DESCR_RELOC_TYPE_AARCH64.get(x, _unknown) elif arch == '64-bit PowerPC': return _DESCR_RELOC_TYPE_PPC64.get(x, _unknown) + elif arch == 'PowerPC': + return _DESCR_RELOC_TYPE_PPC.get(x, _unknown) elif arch == 'IBM S/390': return _DESCR_RELOC_TYPE_S390X.get(x, _unknown) elif arch == 'MIPS': @@ -691,6 +693,7 @@ def _reverse_dict(d, low_priority=()): _DESCR_RELOC_TYPE_ARM = _reverse_dict(ENUM_RELOC_TYPE_ARM) _DESCR_RELOC_TYPE_AARCH64 = _reverse_dict(ENUM_RELOC_TYPE_AARCH64) _DESCR_RELOC_TYPE_PPC64 = _reverse_dict(ENUM_RELOC_TYPE_PPC64) +_DESCR_RELOC_TYPE_PPC = _reverse_dict(ENUM_RELOC_TYPE_PPC) _DESCR_RELOC_TYPE_S390X = _reverse_dict(ENUM_RELOC_TYPE_S390X) _DESCR_RELOC_TYPE_MIPS = _reverse_dict(ENUM_RELOC_TYPE_MIPS) _DESCR_RELOC_TYPE_LOONGARCH = _reverse_dict(ENUM_RELOC_TYPE_LOONGARCH) diff --git a/elftools/elf/enums.py b/elftools/elf/enums.py index 9e519ab4..6ab9db0c 100644 --- a/elftools/elf/enums.py +++ b/elftools/elf/enums.py @@ -1523,6 +1523,64 @@ R_PPC64_GNU_VTENTRY=254, ) +# https://example61560.files.wordpress.com/2016/11/powerpc_abi.pdf +# See 4.13.5 Relocation Types Table. +ENUM_RELOC_TYPE_PPC = dict( + R_PPC_NONE=0, + R_PPC_ADDR32=1, + R_PPC_ADDR24=2, + R_PPC_ADDR16=3, + R_PPC_ADDR16_LO=4, + R_PPC_ADDR16_HI=5, + R_PPC_ADDR16_HA=6, + R_PPC_ADDR14=7, + R_PPC_ADDR14_BRTAKEN=8, + R_PPC_ADDR14_BRNTAKEN=9, + R_PPC_REL24=10, + R_PPC_REL14=11, + R_PPC_REL14_BRTAKEN=12, + R_PPC_REL14_BRNTAKEN=13, + R_PPC_GOT16=14, + R_PPC_GOT16_LO=15, + R_PPC_GOT16_HI=16, + R_PPC_GOT16_HA=17, + R_PPC_PLTREL24=18, + R_PPC_COPY=19, + R_PPC_GLOB_DAT=20, + R_PPC_JMP_SLOT=21, + R_PPC_RELATIVE=22, + R_PPC_LOCAL24PC=23, + R_PPC_UADDR32=24, + R_PPC_UADDR16=25, + R_PPC_REL32=26, + R_PPC_PLT32=27, + R_PPC_PLTREL32=28, + R_PPC_PLT16_LO=29, + R_PPC_PLT16_HI=30, + R_PPC_PLT16_HA=31, + R_PPC_SECTOFF=33, + R_PPC_SECTOFF_LO=34, + R_PPC_SECTOFF_HI=35, + R_PPC_SECTOFF_HA=36, + R_PPC_ADDR30=37, + R_PPC_EMB_NADDR32=101, + R_PPC_EMB_NADDR16=102, + R_PPC_EMB_NADDR16_LO=103, + R_PPC_EMB_NADDR16_HI=104, + R_PPC_EMB_NADDR16_HA=105, + R_PPC_EMB_SDAI16=106, + R_PPC_EMB_SDA2I16=107, + R_PPC_EMB_SDA2REL=108, + R_PPC_EMB_SDA21=109, + R_PPC_EMB_MRKREF=110, + R_PPC_EMB_RELSEC16=111, + R_PPC_EMB_RELST_LO=112, + R_PPC_EMB_RELST_HI=113, + R_PPC_EMB_RELST_HA=114, + R_PPC_EMB_BIT_FLD=115, + R_PPC_EMB_RELSDA=116, +) + # https://gitlab.utu.fi/soft/binutils-gdb/-/blob/d18547d8b08615a58db18ad3e43f721dc92ae298/include/elf/v850.h ENUM_RELOC_TYPE_V850 = dict( R_V800_NONE=0,