Generalize relocTargetBits
to work with non-word-aligned relocation addends (as in PowerPC and RISC-V)
#39
Labels
relocTargetBits
to work with non-word-aligned relocation addends (as in PowerPC and RISC-V)
#39
While working on #35, I realized that the
relocTargetBits
method ofIsRelocationType
is not capable of handling certain relocation types in PowerPC code. To recap:elf-edit/src/Data/ElfEdit/Relocations/Common.hs
Lines 91 to 98 in 3ba7d71
Currently,
relocTargetBits
assumes that the bits needed for the relocation addend will always start at a word alignment. For instance, here are the different addend sizes in the x86-64 System V ABI:Each relocation entry is 64 bits, but certain relocation types may only use 8, 16, or 32 bits of the entry (starting from the LSBs). Regardless, the addend calculations will always happen at 64-bit-sized word boundaries, which greatly simplifies the bitwise arithmetic needed to compute the addends (see this code in
macaw
).Things aren't quite so simple in PowerPC, however. For instance, here are the different addend sizes in the PPC32 ABI:
This time, each relocation entry is 32 bits. What is unusual is that the
low24
andlow14
relocation fields do not start from the LSBs of a 32-bit word, but rather from somewhere in the middle of the word. Alow24
relocation addend starts from the 7th LSB of the word, and alow14
relocation addend starts from the 17th LSB of the word. This means that we cannot use the addend-computing code inmacaw
as-is withlow24
orlow14
relocation fields, as this code does not account for the bit offsets required.In order to fix this, we will likely need to augment
relocTargetBits
with additional information about bit offsets (the PPC32 refers to this as "displacement"). Luckily,low24
/low14
relocation fields aren't super common, so I am opting not to fix this issue for now, instead leaving this here as a reminder to revisit the issue should we need to support such relocations properly.The text was updated successfully, but these errors were encountered: