[PATCH] tools: relocate-rela: Fix BE symtab handling

Angelo Dureghello angelo at kernel-space.org
Sat Aug 26 09:40:58 CEST 2023


Hi Marek,

thanks !

Reviewed-by: Angelo Dureghello <angelo at kernel-space.org>


On 31/07/23 12:16 AM, Marek Vasut wrote:
> 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 at mailbox.org>
> ---
> Cc: Angelo Dureghello <angelo at kernel-space.org>
> Cc: Angelo Durgehello <angelo.dureghello at timesys.com>
> Cc: Bin Meng <bmeng.cn at gmail.com>
> Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>
> Cc: Huan Wang <alison.wang at nxp.com>
> Cc: Marek Vasut <marek.vasut+renesas at mailbox.org>
> Cc: Michal Simek <michal.simek at amd.com>
> Cc: Ovidiu Panait <ovpanait at gmail.com>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Zong Li <zong.li at sifive.com>
> ---
>   tools/relocate-rela.c | 18 ++++++++++++++----
>   1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c
> index f230ec5676c..e28e7fcc6f5 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",




More information about the U-Boot mailing list