[v1,1/1] bfd: microblaze: Fix bug in TLSTPREL Relocation

Message ID 20230927124918.1584074-1-neal.frager@amd.com
State Accepted, archived
Headers
Series [v1,1/1] bfd: microblaze: Fix bug in TLSTPREL Relocation |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed

Commit Message

Neal Frager Sept. 27, 2023, 12:49 p.m. UTC
  Fixed the problem related to the fixup/relocations TLSTPREL.
When the fixup is applied the addend is not added at the correct offset
of the instruction. The offset is hard coded considering its big endian
and it fails for Little endian. This patch allows support for both
big & little-endian compilers.

This patch has been tested for years of AMD Xilinx Yocto
releases as part of the following patch set:

https://github.com/Xilinx/meta-xilinx/tree/master/meta-microblaze/recipes-devtools/binutils/binutils

Signed-off-by: nagaraju <nagaraju.mekala@amd.com>
Signed-off-by: Neal Frager <neal.frager@amd.com>
---
 bfd/elf32-microblaze.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Nick Clifton Sept. 27, 2023, 3:24 p.m. UTC | #1
Hi Neal,

> Fixed the problem related to the fixup/relocations TLSTPREL.
> When the fixup is applied the addend is not added at the correct offset
> of the instruction. The offset is hard coded considering its big endian
> and it fails for Little endian. This patch allows support for both
> big & little-endian compilers.
> 
> This patch has been tested for years of AMD Xilinx Yocto
> releases as part of the following patch set:
> 
> https://github.com/Xilinx/meta-xilinx/tree/master/meta-microblaze/recipes-devtools/binutils/binutils
> 
> Signed-off-by: nagaraju <nagaraju.mekala@amd.com>
> Signed-off-by: Neal Frager <neal.frager@amd.com>
> ---
>   bfd/elf32-microblaze.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Patch approved, please apply.

Cheers
   Nick
  
Michael Eager Sept. 29, 2023, 3:36 p.m. UTC | #2
On 9/27/23 08:24, Nick Clifton via Binutils wrote:
> Hi Neal,
> 
>> Fixed the problem related to the fixup/relocations TLSTPREL.
>> When the fixup is applied the addend is not added at the correct offset
>> of the instruction. The offset is hard coded considering its big endian
>> and it fails for Little endian. This patch allows support for both
>> big & little-endian compilers.
>>
>> This patch has been tested for years of AMD Xilinx Yocto
>> releases as part of the following patch set:
>>
>> https://github.com/Xilinx/meta-xilinx/tree/master/meta-microblaze/recipes-devtools/binutils/binutils
>>
>> Signed-off-by: nagaraju <nagaraju.mekala@amd.com>
>> Signed-off-by: Neal Frager <neal.frager@amd.com>
>> ---
>>   bfd/elf32-microblaze.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> Patch approved, please apply.
> 
> Cheers
>    Nick

Committed.
  

Patch

diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index bbc70fdf4e3..a7e81c70fc8 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -1467,9 +1467,9 @@  microblaze_elf_relocate_section (bfd *output_bfd,
 	      relocation += addend;
 	      relocation -= dtprel_base(info);
 	      bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
-			  contents + offset + 2);
+			  contents + offset + endian);
 	      bfd_put_16 (input_bfd, relocation & 0xffff,
-			  contents + offset + 2 + INST_WORD_SIZE);
+			  contents + offset + endian + INST_WORD_SIZE);
 	      break;
 	    case (int) R_MICROBLAZE_TEXTREL_64:
 	    case (int) R_MICROBLAZE_TEXTREL_32_LO: