tools: relocate-rela: Fix ELF decoding on big-endian hosts
authorSamuel Holland <samuel@sholland.org>
Fri, 15 Jul 2022 06:40:25 +0000 (01:40 -0500)
committerMichal Simek <michal.simek@amd.com>
Tue, 26 Jul 2022 06:23:54 +0000 (08:23 +0200)
commit5e0e1a86d327d0e3330aee737559dd15a3b27bd7
tree35587760956fd35d974bc7207c0d0cc6623699a9
parent71f07731488e9ade674ee396208317ab2db3cce1
tools: relocate-rela: Fix ELF decoding on big-endian hosts

The new ELF decoding logic assumed that the target binary has the same
endianness as the host, which broke building ARM64 firmware binaries on
big-endian machines.

This commit fixes the ELF64 decoding to be host-endianness-neutral, and
applies the same changes to the ELF32 decoding. It does not fix the
microblaze-specific dynamic symbol decoding.

It also corrects the functions used for byte swapping in rela_elf64()
and rela_elf32(). The result is the same, but semantically the code is
converting bytes read from a foreign-endianness file to host byte order.

Fixes: 4c9e2d643460 ("tools: relocate-rela: Read rela start/end directly from ELF")
Fixes: a1405d9cfedb ("tools: relocate-rela: Check that relocation works only for EM_AARCH64")
Signed-off-by: Samuel Holland <samuel@sholland.org>
Link: https://lore.kernel.org/r/20220715064026.54551-1-samuel@sholland.org
Signed-off-by: Michal Simek <michal.simek@amd.com>
tools/relocate-rela.c