From 00adf2d4698cba8b2829652c2bc38c23df3d0ac0 Mon Sep 17 00:00:00 2001
From: Julian Brown <julian@codesourcery.com>
Date: Fri, 1 May 2009 13:50:10 +0000
Subject: [PATCH] 	gas/ 	* config/tc-arm.c (do_t_blx): Always use
 BFD_RELOC_THUMB_PCREL_BLX. 	(md_pcrel_from_section): Align address for
 BLX. 	(tc_gen_reloc): Change BFD_RELOC_THUMB_PCREL_BLX relocations to 
 BFD_RELOC_THUMB_PCREL_BRANCH23 for EABI v4+.

---
 gas/ChangeLog       |  7 +++++++
 gas/config/tc-arm.c | 23 +++++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 2591b090a5b..7ac1bf5f21a 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,10 @@
+2009-05-01  Julian Brown  <julian@codesourcery.com>
+
+	* config/tc-arm.c (do_t_blx): Always use BFD_RELOC_THUMB_PCREL_BLX.
+	(md_pcrel_from_section): Align address for BLX.
+	(tc_gen_reloc): Change BFD_RELOC_THUMB_PCREL_BLX relocations to
+	BFD_RELOC_THUMB_PCREL_BRANCH23 for EABI v4+.
+
 2009-04-29  DJ Delorie  <dj@redhat.com>
 
 	* config/tc-mep.c (md_begin): Check coprocessor type.
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index 581ffcd03a7..6615acafde8 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -9002,12 +9002,7 @@ do_t_blx (void)
     {
       /* No register.  This must be BLX(1).  */
       inst.instruction = 0xf000e800;
-#ifdef OBJ_ELF
-      if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
-	inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
-      else
-#endif
-	inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
+      inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
       inst.reloc.pc_rel = 1;
     }
 }
@@ -18213,9 +18208,13 @@ md_pcrel_from_section (fixS * fixP, segT seg)
     case BFD_RELOC_THUMB_PCREL_BRANCH20:
     case BFD_RELOC_THUMB_PCREL_BRANCH23:
     case BFD_RELOC_THUMB_PCREL_BRANCH25:
-    case BFD_RELOC_THUMB_PCREL_BLX:
       return base + 4;
 
+      /* BLX is like branches above, but forces the low two bits of PC to
+	 zero.  */
+    case BFD_RELOC_THUMB_PCREL_BLX:
+      return (base + 4) & ~3;
+
       /* ARM mode branches are offset by +8.  However, the Windows CE
 	 loader expects the relocation not to take this into account.  */
     case BFD_RELOC_ARM_PCREL_BRANCH:
@@ -19737,7 +19736,6 @@ tc_gen_reloc (asection *section, fixS *fixp)
     case BFD_RELOC_THUMB_PCREL_BRANCH20:
     case BFD_RELOC_THUMB_PCREL_BRANCH23:
     case BFD_RELOC_THUMB_PCREL_BRANCH25:
-    case BFD_RELOC_THUMB_PCREL_BLX:
     case BFD_RELOC_VTABLE_ENTRY:
     case BFD_RELOC_VTABLE_INHERIT:
 #ifdef TE_PE
@@ -19746,6 +19744,15 @@ tc_gen_reloc (asection *section, fixS *fixp)
       code = fixp->fx_r_type;
       break;
 
+    case BFD_RELOC_THUMB_PCREL_BLX:
+#ifdef OBJ_ELF
+      if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
+	code = BFD_RELOC_THUMB_PCREL_BRANCH23;
+      else
+#endif
+	code = BFD_RELOC_THUMB_PCREL_BLX;
+      break;
+
     case BFD_RELOC_ARM_LITERAL:
     case BFD_RELOC_ARM_HWLITERAL:
       /* If this is called then the a literal has