diff options
author | Marek Vasut <marek.vasut+renesas@mailbox.org> | 2023-07-31 00:16:52 +0200 |
---|---|---|
committer | Angelo Dureghello <angelo@kernel-space.org> | 2023-09-06 13:28:19 +0200 |
commit | 0ad3eef38121b378cac1383b13b7365b1b9b1922 (patch) | |
tree | e8b27126fb0bb759b91320ca1ad6c9be7530b164 | |
parent | b53ab97150314674edc25508f4fc528be2baa73f (diff) | |
download | u-boot-0ad3eef38121b378cac1383b13b7365b1b9b1922.zip u-boot-0ad3eef38121b378cac1383b13b7365b1b9b1922.tar.gz u-boot-0ad3eef38121b378cac1383b13b7365b1b9b1922.tar.bz2 |
tools: relocate-rela: Fix BE symtab handling
The symtab contains data in target endianness, convert the data to
native endianness before doing any operations and on them, and back
to target endianness before updating the bin file.
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Tested-by: Michal Simek <michal.simek@amd.com> # microblaze, arm64
Reviewed-by: Angelo Dureghello <angelo@kernel-space.org>
-rw-r--r-- | tools/relocate-rela.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index f230ec5..e28e7fc 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -78,6 +78,14 @@ static uint32_t elf32_to_cpu(uint32_t data) return be32_to_cpu(data); } +static uint32_t cpu_to_elf32(uint32_t data) +{ + if (ei_data == ELFDATA2LSB) + return cpu_to_le32(data); + + return cpu_to_be32(data); +} + static bool supported_rela(Elf64_Rela *rela) { uint64_t mask = 0xffffffffULL; /* would be different on 32-bit */ @@ -602,14 +610,16 @@ static int rela_elf32(char **argv, FILE *f) } debug("Symbol description:\n"); - debug(" st_name:\t0x%x\n", symbols.st_name); - debug(" st_value:\t0x%x\n", symbols.st_value); - debug(" st_size:\t0x%x\n", symbols.st_size); + debug(" st_name:\t0x%x\n", elf32_to_cpu(symbols.st_name)); + debug(" st_value:\t0x%x\n", elf32_to_cpu(symbols.st_value)); + debug(" st_size:\t0x%x\n", elf32_to_cpu(symbols.st_size)); - value = swrela.r_addend + symbols.st_value; + value = swrela.r_addend + elf32_to_cpu(symbols.st_value); debug("Value:\t0x%x\n", value); + value = cpu_to_elf32(value); + if (fseek(f, addr, SEEK_SET) < 0) { fprintf(stderr, "%s: %s: seek to %" PRIx32 " failed: %s\n", |