From 0435ac5ae5d2fa9da8561fd47802ca742061e462 Mon Sep 17 00:00:00 2001
From: Mahesh Bodapati <mbodapat@xilinx.com>
Date: Mon, 24 Jan 2022 16:21:33 +0530
Subject: [PATCH] [Patch,MicroBlaze] : Fixing the imm/imml generation for 16
 bit argument [CR-1115234].

---
 bfd/elf32-microblaze.c | 6 +++++-
 bfd/elf64-microblaze.c | 5 ++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index 37a1873570..290e70e0f4 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -1977,7 +1977,11 @@ microblaze_elf_relax_section (bfd *abfd,
       else
 	symval += irel->r_addend;
 
-      if ((symval & 0xffff8000) == 0)
+      /* Check for imm command argument value to decide if
+       * we need full 32-bit value for next command */
+      if ((symval & 0xffff8000) == 0
+	  || (symval & 0xffff8000) == 0xffff8000)
+
 	{
 	  /* We can delete this instruction.  */
 	  sec->relax[sec->relax_count].addr = irel->r_offset;
diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
index bd1c7d3b1f..7bad93e706 100644
--- a/bfd/elf64-microblaze.c
+++ b/bfd/elf64-microblaze.c
@@ -1987,7 +1987,10 @@ microblaze_elf_relax_section (bfd *abfd,
       else
 	symval += irel->r_addend;
 
-      if ((symval & 0xffff8000) == 0)
+      /* Check for imm command argument value to decide if
+       * we need full 32-bit value for next command */
+      if ((symval & 0xffff8000) == 0
+	  || (symval & 0xffff8000) == 0xffff8000)
 	{
           /* We can delete this instruction.  */
 	  sec->relax[sec->relax_count].addr = irel->r_offset;
-- 
2.17.1

