[PATCH] fix Score absolute relocation on elf32 score
Danish Reyjavik
danishreyjavik@outlook.com
Wed Nov 13 16:49:47 GMT 2024
There's a bug with binutils creating a jump instruction with 24bit jumps: there are many j instructions, one of which is 24bit offsets, so note what the fix does:
- abs_value = value - rel_addr;
+ abs_value = (value < rel_addr) ? rel_addr - value : value - rel_addr;
that instruction is bugged when jumping backwards but most short j's will be converted to j!, so it went unnoticed
________________________________
From: Jan Beulich <jbeulich@suse.com>
Sent: 12 November 2024 09:18
To: Danish Reyjavik <danishreyjavik@outlook.com>
Cc: binutils@sourceware.org <binutils@sourceware.org>
Subject: Re: [PATCH] fix Score absolute relocation on elf32 score
On 11.11.2024 19:43, Danish Reyjavik wrote:
> diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c
> index d1a910f279..eb93c7cfa1 100644
I'm not a maintainer of the given target (and sadly there also is no-one
named to play that role), so I can't say anything about the correctness.
In particular as long as such a change comes with no description at all.
Jan
> --- bfd/elf32-score.c
> +++ bfd/elf32-score.c
> @@ -2165,7 +2165,7 @@ score_elf_final_link_relocate (reloc_howto_type *howto,
> if ((offset & 0x1000000) != 0)
> offset |= 0xfe000000;
> value += offset;
> - abs_value = value - rel_addr;
> + abs_value = (value < rel_addr) ? rel_addr - value : value - rel_addr;
> if ((abs_value & 0xfe000000) != 0)
> return bfd_reloc_overflow;
> addend = (addend & ~howto->src_mask)
> @@ -2241,7 +2241,7 @@ score_elf_final_link_relocate (reloc_howto_type *howto,
> if ((offset & 0x800) != 0) /* Offset is negative. */
> offset |= 0xfffff000;
> value += offset;
> - abs_value = value - rel_addr;
> + abs_value = (value < rel_addr) ? rel_addr - value : value - rel_addr;
> if ((abs_value & 0xfffff000) != 0)
> return bfd_reloc_overflow;
> addend = (addend & ~howto->src_mask) | (value & howto->src_mask);
> diff --git a/bfd/elf32-score7.c b/bfd/elf32-score7.c
> index ab5e32a29a..3bf4c30465 100644
> --- bfd/elf32-score7.c
> +++ bfd/elf32-score7.c
> @@ -2066,7 +2066,7 @@ score_elf_final_link_relocate (reloc_howto_type *howto,
> if ((offset & 0x1000000) != 0)
> offset |= 0xfe000000;
> value += offset;
> - abs_value = value - rel_addr;
> + abs_value = (value < rel_addr) ? rel_addr - value : value - rel_addr;
> if ((abs_value & 0xfe000000) != 0)
> return bfd_reloc_overflow;
> addend = (addend & ~howto->src_mask)
> @@ -2096,7 +2096,7 @@ score_elf_final_link_relocate (reloc_howto_type *howto,
> if ((offset & 0x800) != 0) /* Offset is negative. */
> offset |= 0xfffff000;
> value += offset;
> - abs_value = value - rel_addr;
> + abs_value = (value < rel_addr) ? rel_addr - value : value - rel_addr;
> if ((abs_value & 0xfffff000) != 0)
> return bfd_reloc_overflow;
> addend = (addend & ~howto->src_mask) | (value & howto->src_mask);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20241113/6c3242ae/attachment-0001.htm>
More information about the Binutils
mailing list