Skip to content

Commit

Permalink
Addding relocation type for PPC 32 EABI (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajez133 authored Sep 24, 2024
1 parent 0f72cb7 commit c03e7e6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
5 changes: 4 additions & 1 deletion elftools/elf/descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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)
Expand Down
58 changes: 58 additions & 0 deletions elftools/elf/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c03e7e6

Please sign in to comment.