public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: On resolving the MIPS gas branch reloc issue
       [not found] <20030225092644.GE25303@rembrandt.csv.ica.uni-stuttgart.de>
@ 2003-02-26  4:17 ` Eric Christopher
  2003-02-26  8:29   ` Thiemo Seufer
       [not found]   ` <20030227001413.GY31111@bubble.sa.bigpond.net.au>
  0 siblings, 2 replies; 19+ messages in thread
From: Eric Christopher @ 2003-02-26  4:17 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: binutils


> Comments?
> 

I like it. Clean, appears to be useful, and does what it should. Give it
a shot through the testsuite and gcc (yes, i realize it probably
shouldn't be generated, but I'm paranoid) and let me know. Also, Alan or
Nick should ack the global parts if they like them.

-eric

-- 
o/~ Cry havoc... o/~

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-02-26  4:17 ` On resolving the MIPS gas branch reloc issue Eric Christopher
@ 2003-02-26  8:29   ` Thiemo Seufer
  2003-02-26 12:40     ` Maciej W. Rozycki
                       ` (2 more replies)
       [not found]   ` <20030227001413.GY31111@bubble.sa.bigpond.net.au>
  1 sibling, 3 replies; 19+ messages in thread
From: Thiemo Seufer @ 2003-02-26  8:29 UTC (permalink / raw)
  To: Eric Christopher; +Cc: binutils

Eric Christopher wrote:
> 
> > Comments?
> > 
> 
> I like it. Clean, appears to be useful, and does what it should. Give it
> a shot through the testsuite and gcc (yes, i realize it probably
> shouldn't be generated, but I'm paranoid) and let me know. Also, Alan or
> Nick should ack the global parts if they like them.

Well, this patch changes the definition of R_MIPS_PC16 (used for branch
relocations) from a plain addend to a rightshift 2 addend. This reflects
the hardware capabilities.
The old version, written according to the ABI spec, was useless, therefore
it was unused with the exception of some half-working/half-broken behaviour
in binutils, and the ABI people at MIPS say it was a typo in the spec and
should have never been defined this way.

The Embedded PIC ABI did something similiar earlier but with a GNU
extension relocation. To keep compatible to it, we need now one new
BFD_RELOC_MIPSEMB_16_PCREL_S2 bfd reloc, because BFD has no way to
find out the ABI early enough.

This patch fixes the problem of branches to globals in the same file,
which were disallowed in december. Tested for mips64-linux and mips-linux
with no new regressions.


Thiemo


2003-02-26  Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>

	/bfd/ChangeLog
	* elf32-mips.c (elf_mips_howto_table_rel): Change definition of
	R_MIPS_PC16 to rightshift 2.
	(elf_reloc_map mips_reloc_map): Map to rightshifted BFD reloc.
	(bfd_elf32_bfd_reloc_type_lookup): Support
	BFD_RELOC_MIPSEMB_16_PCREL_S2.
	* elf64-mips.c (mips_elf64_howto_table_rel): Change definition of
	R_MIPS_PC16 to rightshift 2.
	(mips_elf64_howto_table_rela): Likewise.
	(mips_reloc_map): Map to rightshifted BFD reloc.
	* elfn32-mips.c: The same as in elf64-mips.c.
	* elfxx-mips.c (mips_elf_got_for_ibfd): Typo in comment.
	(mips_elf_calculate_relocation): Handle rightshifted addends for
	R_MIPS_PC16.
	* reloc.c (BFD_RELOC_MIPSEMB_16_PCREL_S2): New BFD relocation for
	MIPS Embedded PIC. Remove superfluous empty COMMENT.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.

	/gas/ChangeLog
	* config/tc-mips.c (append_insn): Add handling of
	BFD_RELOC_MIPSEMB_16_PCREL_S2. Avoid emitting unneeded
	BFD_RELOC_16_PCREL_S2 relocs and add earlier warnings about
	misaligned address and reange overflow.
	(macro_build): Add handling of BFD_RELOC_MIPSEMB_16_PCREL_S2. Add
	earlier warnings about misaligned address and reange overflow.
	(mips_ip): Add handling of BFD_RELOC_MIPSEMB_16_PCREL_S2.
	(md_apply_fix): Likewise. Fix warning output.
	(tc_gen_reloc): Add handling of BFD_RELOC_MIPSEMB_16_PCREL_S2.
	Allow BFD_RELOC_16_PCREL_S2 for all ABIs.
	(md_convert_frag): Add handling of BFD_RELOC_MIPSEMB_16_PCREL_S2.

	/tas/testsuite/ChangeLog
	* gas/mips/bge.d: Reactivate external branch tests.
	* gas/mips/bge.s: Likewise.
	* gas/mips/bgeu.d: Likewise.
	* gas/mips/bgeu.s: Likewise.
	* gas/mips/blt.d: Likewise.
	* gas/mips/blt.s: Likewise.
	* gas/mips/bltu.d: Likewise.
	* gas/mips/bltu.s: Likewise.
	* gas/mips/branch-misc-2.d: New File.
	* gas/mips/branch-misc-2.l: Remove.
	* gas/mips/mips.exp: Adjust branch-misc-2 test.


diff -urpNX /bigdisk/src/gcc-exclude source-orig/bfd/elf32-mips.c source/bfd/elf32-mips.c
--- source-orig/bfd/elf32-mips.c	Sat Jan 25 01:30:58 2003
+++ source/bfd/elf32-mips.c	Wed Feb 26 07:31:24 2003
@@ -261,9 +261,11 @@ static reloc_howto_type elf_mips_howto_t
 	 0x0000ffff,		/* dst_mask */
 	 FALSE),		/* pcrel_offset */
 
-  /* 16 bit PC relative reference.  */
+  /* 16 bit PC relative reference.  Note that the ABI document has a typo
+     and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
+     We do the right thing here.  */
   HOWTO (R_MIPS_PC16,		/* type */
-	 0,			/* rightshift */
+	 2,			/* rightshift */
 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
 	 16,			/* bitsize */
 	 TRUE,			/* pc_relative */
@@ -1401,7 +1403,7 @@ static const struct elf_reloc_map mips_r
   { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
   { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
   { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
-  { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
+  { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
   { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
   { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
   { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
@@ -1458,7 +1460,7 @@ bfd_elf32_bfd_reloc_type_lookup (abfd, c
       return &elf_mips_gnu_rel_hi16;
     case BFD_RELOC_PCREL_LO16:
       return &elf_mips_gnu_rel_lo16;
-    case BFD_RELOC_16_PCREL_S2:
+    case BFD_RELOC_MIPSEMB_16_PCREL_S2:
       return &elf_mips_gnu_rel16_s2;
     case BFD_RELOC_64_PCREL:
       return &elf_mips_gnu_pcrel64;
diff -urpNX /bigdisk/src/gcc-exclude source-orig/bfd/elf64-mips.c source/bfd/elf64-mips.c
--- source-orig/bfd/elf64-mips.c	Sat Jan 25 01:30:58 2003
+++ source/bfd/elf64-mips.c	Wed Feb 26 07:31:24 2003
@@ -300,9 +300,11 @@ static reloc_howto_type mips_elf64_howto
 	 0x0000ffff,		/* dst_mask */
 	 FALSE),		/* pcrel_offset */
 
-  /* 16 bit PC relative reference.  */
+  /* 16 bit PC relative reference.  Note that the ABI document has a typo
+     and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
+     We do the right thing here.  */
   HOWTO (R_MIPS_PC16,		/* type */
-	 0,			/* rightshift */
+	 2,			/* rightshift */
 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
 	 16,			/* bitsize */
 	 TRUE,			/* pc_relative */
@@ -795,9 +797,11 @@ static reloc_howto_type mips_elf64_howto
 	 0x0000ffff,		/* dst_mask */
 	 FALSE),		/* pcrel_offset */
 
-  /* 16 bit PC relative reference.  */
+  /* 16 bit PC relative reference.  Note that the ABI document has a typo
+     and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
+     We do the right thing here.  */
   HOWTO (R_MIPS_PC16,		/* type */
-	 0,			/* rightshift */
+	 2,			/* rightshift */
 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
 	 16,			/* bitsize */
 	 TRUE,			/* pc_relative */
@@ -1894,7 +1898,7 @@ static const struct elf_reloc_map mips_r
   /* There is no BFD reloc for R_MIPS_REL32.  */
   { BFD_RELOC_64, R_MIPS_64 },
   { BFD_RELOC_CTOR, R_MIPS_64 },
-  { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
+  { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
   { BFD_RELOC_HI16_S, R_MIPS_HI16 },
   { BFD_RELOC_LO16, R_MIPS_LO16 },
   { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
diff -urpNX /bigdisk/src/gcc-exclude source-orig/bfd/elfn32-mips.c source/bfd/elfn32-mips.c
--- source-orig/bfd/elfn32-mips.c	Sat Jan 25 01:30:58 2003
+++ source/bfd/elfn32-mips.c	Wed Feb 26 07:31:24 2003
@@ -275,9 +275,11 @@ static reloc_howto_type elf_mips_howto_t
 	 0x0000ffff,		/* dst_mask */
 	 FALSE),		/* pcrel_offset */
 
-  /* 16 bit PC relative reference.  */
+  /* 16 bit PC relative reference.  Note that the ABI document has a typo
+     and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
+     We do the right thing here.  */
   HOWTO (R_MIPS_PC16,		/* type */
-	 0,			/* rightshift */
+	 2,			/* rightshift */
 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
 	 16,			/* bitsize */
 	 TRUE,			/* pc_relative */
@@ -772,9 +774,11 @@ static reloc_howto_type elf_mips_howto_t
 	 0x0000ffff,		/* dst_mask */
 	 FALSE),		/* pcrel_offset */
 
-  /* 16 bit PC relative reference.  */
+  /* 16 bit PC relative reference.  Note that the ABI document has a typo
+     and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
+     We do the right thing here.  */
   HOWTO (R_MIPS_PC16,		/* type */
-	 0,			/* rightshift */
+	 2,			/* rightshift */
 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
 	 16,			/* bitsize */
 	 TRUE,			/* pc_relative */
@@ -1837,7 +1841,7 @@ static const struct elf_reloc_map mips_r
   /* There is no BFD reloc for R_MIPS_REL32.  */
   { BFD_RELOC_CTOR, R_MIPS_32 },
   { BFD_RELOC_64, R_MIPS_64 },
-  { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
+  { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
   { BFD_RELOC_HI16_S, R_MIPS_HI16 },
   { BFD_RELOC_LO16, R_MIPS_LO16 },
   { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
diff -urpNX /bigdisk/src/gcc-exclude source-orig/bfd/elfxx-mips.c source/bfd/elfxx-mips.c
--- source-orig/bfd/elfxx-mips.c	Wed Jan 29 18:30:31 2003
+++ source/bfd/elfxx-mips.c	Wed Feb 26 07:23:02 2003
@@ -496,7 +496,6 @@ static struct mips_got_info *mips_elf_go
 static bfd *reldyn_sorting_bfd;
 
 /* Nonzero if ABFD is using the N32 ABI.  */
-
 #define ABI_N32_P(abfd) \
   ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
 
@@ -2130,7 +2129,7 @@ mips_elf_bfd2got_entry_eq (entry1, entry
   return e1->bfd == e2->bfd;
 }
 
-/* In a multi-got link, determine the GOT to be used for IBDF.  G must
+/* In a multi-got link, determine the GOT to be used for IBFD.  G must
    be the master GOT data.  */
 
 static struct mips_got_info *
@@ -3317,12 +3316,6 @@ mips_elf_calculate_relocation (abfd, inp
       value &= howto->dst_mask;
       break;
 
-    case R_MIPS_GNU_REL16_S2:
-      value = symbol + mips_elf_sign_extend (addend << 2, 18) - p;
-      overflowed_p = mips_elf_overflow_p (value, 18);
-      value = (value >> 2) & howto->dst_mask;
-      break;
-
     case R_MIPS_GNU_REL_HI16:
       /* Instead of subtracting 'p' here, we should be subtracting the
 	 equivalent value for the LO part of the reloc, since the value
@@ -3451,8 +3444,10 @@ mips_elf_calculate_relocation (abfd, inp
       break;
 
     case R_MIPS_PC16:
-      value = mips_elf_sign_extend (addend, 16) + symbol - p;
-      overflowed_p = mips_elf_overflow_p (value, 16);
+    case R_MIPS_GNU_REL16_S2:
+      value = mips_elf_sign_extend (addend << 2, 18) + symbol - p;
+      overflowed_p = mips_elf_overflow_p (value, 18);
+      value = (value >> 2) & howto->dst_mask;
       break;
 
     case R_MIPS_GOT_HI16:
diff -urpNX /bigdisk/src/gcc-exclude source-orig/bfd/reloc.c source/bfd/reloc.c
--- source-orig/bfd/reloc.c	Sat Jan 25 01:30:59 2003
+++ source/bfd/reloc.c	Wed Feb 26 07:20:19 2003
@@ -2080,7 +2080,10 @@ ENUM
   BFD_RELOC_PCREL_LO16
 ENUMDOC
   Like BFD_RELOC_LO16, but PC relative.
-
+ENUM
+  BFD_RELOC_MIPSEMB_16_PCREL_S2
+ENUMDOC
+  Like BFD_RELOC_16_PCREL_S2, but for MIPS Embedded PIC.
 ENUM
   BFD_RELOC_MIPS_LITERAL
 ENUMDOC
@@ -2149,7 +2152,6 @@ ENUMX
   BFD_RELOC_FRV_GPRELLO
 ENUMDOC
   Fujitsu Frv Relocations.
-COMMENT
 COMMENT
 ENUMDOC
   MIPS ELF relocations.
diff -urpNX /bigdisk/src/gcc-exclude source-orig/bfd/libbfd.h source/bfd/libbfd.h
--- source-orig/bfd/libbfd.h	Sat Jan 25 01:30:59 2003
+++ source/bfd/libbfd.h	Wed Feb 26 07:20:19 2003
@@ -850,6 +850,7 @@ static const char *const bfd_reloc_code_
   "BFD_RELOC_LO16",
   "BFD_RELOC_PCREL_HI16_S",
   "BFD_RELOC_PCREL_LO16",
+  "BFD_RELOC_MIPSEMB_16_PCREL_S2",
   "BFD_RELOC_MIPS_LITERAL",
   "BFD_RELOC_MIPS_GOT16",
   "BFD_RELOC_MIPS_CALL16",
diff -urpNX /bigdisk/src/gcc-exclude source-orig/bfd/bfd-in2.h source/bfd/bfd-in2.h
--- source-orig/bfd/bfd-in2.h	Wed Jan 29 18:30:31 2003
+++ source/bfd/bfd-in2.h	Wed Feb 26 07:20:19 2003
@@ -2301,6 +2301,9 @@ to compensate for the borrow when the lo
 /* Like BFD_RELOC_LO16, but PC relative.  */
   BFD_RELOC_PCREL_LO16,
 
+/* Like BFD_RELOC_16_PCREL_S2, but for MIPS Embedded PIC.  */
+  BFD_RELOC_MIPSEMB_16_PCREL_S2,
+
 /* Relocation against a MIPS literal section.  */
   BFD_RELOC_MIPS_LITERAL,
 
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/config/tc-mips.c source/gas/config/tc-mips.c
--- source-orig/gas/config/tc-mips.c	Wed Jan 29 18:30:32 2003
+++ source/gas/config/tc-mips.c	Wed Feb 26 07:20:19 2003
@@ -2016,7 +2016,8 @@ append_insn (place, ip, address_expr, re
 
   if (place == NULL
       && address_expr
-      && *reloc_type == BFD_RELOC_16_PCREL_S2
+      && (*reloc_type == BFD_RELOC_16_PCREL_S2
+	  || *reloc_type == BFD_RELOC_MIPSEMB_16_PCREL_S2)
       && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY
 	  || pinfo & INSN_COND_BRANCH_LIKELY)
       && mips_relax_branch
@@ -2138,6 +2139,18 @@ append_insn (place, ip, address_expr, re
 	      break;
 
 	    case BFD_RELOC_16_PCREL_S2:
+	      if ((address_expr->X_add_number & 3) != 0)
+		as_bad (_("branch to misaligned address (0x%lx)"),
+			(unsigned long) address_expr->X_add_number);
+	      if (mips_relax_branch)
+		goto need_reloc;
+	      if ((address_expr->X_add_number + 0x20000) & ~0x3ffff)
+		as_bad (_("branch address range overflow (0x%lx)"),
+			(unsigned long) address_expr->X_add_number);
+	      ip->insn_opcode |= (address_expr->X_add_number >> 2) & 0xffff;
+	      break;
+
+	    case BFD_RELOC_MIPSEMB_16_PCREL_S2:
 	      goto need_reloc;
 
 	    default:
@@ -2152,7 +2165,8 @@ append_insn (place, ip, address_expr, re
 	    {
 	      fixp[0] = fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
 				     address_expr,
-				     *reloc_type == BFD_RELOC_16_PCREL_S2,
+				     (*reloc_type == BFD_RELOC_16_PCREL_S2
+				      || *reloc_type == BFD_RELOC_MIPSEMB_16_PCREL_S2),
 				     reloc_type[0]);
 
 	      /* These relocations can have an addend that won't fit in
@@ -3107,20 +3121,32 @@ macro_build (place, counter, ep, name, f
 
 	case 'p':
 	  assert (ep != NULL);
+
 	  /*
 	   * This allows macro() to pass an immediate expression for
 	   * creating short branches without creating a symbol.
-	   * Note that the expression still might come from the assembly
-	   * input, in which case the value is not checked for range nor
-	   * is a relocation entry generated (yuck).
+	   *
+	   * We don't allow branch relaxation for these branches, as
+	   * they should only appear in ".set nomacro" anyway.
 	   */
 	  if (ep->X_op == O_constant)
 	    {
+	      if ((ep->X_add_number & 3) != 0)
+		as_bad (_("branch to misaligned address (0x%lx)"),
+			(unsigned long) ep->X_add_number);
+	      if ((ep->X_add_number + 0x20000) & ~0x3ffff)
+		as_bad (_("branch address range overflow (0x%lx)"),
+			(unsigned long) ep->X_add_number);
 	      insn.insn_opcode |= (ep->X_add_number >> 2) & 0xffff;
 	      ep = NULL;
 	    }
 	  else
-	    *r = BFD_RELOC_16_PCREL_S2;
+	    {
+	      if (mips_pic == EMBEDDED_PIC)
+		*r = BFD_RELOC_MIPSEMB_16_PCREL_S2;
+	      else
+		*r = BFD_RELOC_16_PCREL_S2;
+	    }
 	  continue;
 
 	case 'a':
@@ -9185,7 +9211,10 @@ mips_ip (str, ip)
 	      continue;
 
 	    case 'p':		/* pc relative offset */
-	      *offset_reloc = BFD_RELOC_16_PCREL_S2;
+	      if (mips_pic == EMBEDDED_PIC)
+		*offset_reloc = BFD_RELOC_MIPSEMB_16_PCREL_S2;
+	      else
+		*offset_reloc = BFD_RELOC_16_PCREL_S2;
 	      my_getExpression (&offset_expr, s);
 	      s = expr_end;
 	      continue;
@@ -11335,7 +11364,8 @@ md_apply_fix3 (fixP, valP, seg)
 	  /* BFD's REL handling, for MIPS, is _very_ weird.
 	     This gives the right results, but it can't possibly
 	     be the way things are supposed to work.  */
-	  if (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
+	  if ((fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
+	       && fixP->fx_r_type != BFD_RELOC_MIPSEMB_16_PCREL_S2)
 	      || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
 	    value += fixP->fx_frag->fr_address + fixP->fx_where;
 	}
@@ -11505,9 +11535,10 @@ md_apply_fix3 (fixP, valP, seg)
       break;
 
     case BFD_RELOC_16_PCREL_S2:
+    case BFD_RELOC_MIPSEMB_16_PCREL_S2:
       if ((value & 0x3) != 0)
 	as_bad_where (fixP->fx_file, fixP->fx_line,
-		      _("Branch to odd address (%lx)"), (long) value);
+		      _("Branch to misaligned address (%lx)"), (long) value);
 
       /*
        * We need to save the bits in the instruction since fixup_segment()
@@ -11520,8 +11551,7 @@ md_apply_fix3 (fixP, valP, seg)
 	 do the store, so it must be done here.  This is probably
 	 a bug somewhere.  */
       if (!fixP->fx_done
-	  && (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
-	      || fixP->fx_addsy == NULL			/* ??? */
+	  && (fixP->fx_addsy == NULL			/* ??? */
 	      || ! S_IS_DEFINED (fixP->fx_addsy)))
 	value -= fixP->fx_frag->fr_address + fixP->fx_where;
 
@@ -13509,6 +13539,7 @@ tc_gen_reloc (section, fixp)
 	case BFD_RELOC_32_PCREL:
 	case BFD_RELOC_64_PCREL:
 	case BFD_RELOC_16_PCREL_S2:
+	case BFD_RELOC_MIPSEMB_16_PCREL_S2:
 	case BFD_RELOC_PCREL_HI16_S:
 	case BFD_RELOC_PCREL_LO16:
 	  break;
@@ -13532,17 +13563,7 @@ tc_gen_reloc (section, fixp)
     reloc->addend += S_GET_VALUE (fixp->fx_addsy);
 #endif
 
-  /* To support a PC relative reloc when generating embedded PIC code
-     for ECOFF, we use a Cygnus extension.  We check for that here to
-     make sure that we don't let such a reloc escape normally.  */
-  if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
-       || OUTPUT_FLAVOR == bfd_target_elf_flavour)
-      && code == BFD_RELOC_16_PCREL_S2
-      && mips_pic != EMBEDDED_PIC)
-    reloc->howto = NULL;
-  else
-    reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
-
+  reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
   if (reloc->howto == NULL)
     {
       as_bad_where (fixp->fx_file, fixp->fx_line,
@@ -13628,8 +13649,9 @@ md_convert_frag (abfd, asec, fragp)
 	  exp.X_add_number = fragp->fr_offset;
 
 	  fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
-			      4, &exp, 1,
-			      BFD_RELOC_16_PCREL_S2);
+			      4, &exp, 1, ((mips_pic == EMBEDDED_PIC)
+					   ? BFD_RELOC_MIPSEMB_16_PCREL_S2
+					   : BFD_RELOC_16_PCREL_S2));
 	  fixp->fx_file = fragp->fr_file;
 	  fixp->fx_line = fragp->fr_line;
 
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/bge.d source/gas/testsuite/gas/mips/bge.d
--- source-orig/gas/testsuite/gas/mips/bge.d	Thu Dec 19 23:55:25 2002
+++ source/gas/testsuite/gas/mips/bge.d	Wed Feb 26 07:20:19 2003
@@ -51,20 +51,20 @@ Disassembly of section .text:
 0+00a8 <[^>]*> slt	at,a1,a0
 0+00ac <[^>]*> bnezl	at,0+0000 <text_label>
 0+00b0 <[^>]*> nop
-#0+00b4 <[^>]*> slt	at,a0,a1
-#0+00b8 <[^>]*> beqz	at,000000b8 <text_label\+0xb8>
-#[ 	]*b8: R_MIPS_PC16	external_label
-#0+00bc <[^>]*> nop
-#0+00c0 <[^>]*> slt	at,a1,a0
-#0+00c4 <[^>]*> bnez	at,000000c4 <text_label\+0xc4>
-#[ 	]*c4: R_MIPS_PC16	external_label
-#0+00c8 <[^>]*> nop
-#0+00cc <[^>]*> slt	at,a0,a1
-#0+00d0 <[^>]*> beqzl	at,000000d0 <text_label\+0xd0>
-#[ 	]*d0: R_MIPS_PC16	external_label
-#0+00d4 <[^>]*> nop
-#0+00d8 <[^>]*> slt	at,a1,a0
-#0+00dc <[^>]*> bnezl	at,000000dc <text_label\+0xdc>
-#[ 	]*dc: R_MIPS_PC16	external_label
-#0+00e0 <[^>]*> nop
+0+00b4 <[^>]*> slt	at,a0,a1
+0+00b8 <[^>]*> beqz	at,000000b8 <text_label\+0xb8>
+[ 	]*b8: R_MIPS_PC16	external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> slt	at,a1,a0
+0+00c4 <[^>]*> bnez	at,000000c4 <text_label\+0xc4>
+[ 	]*c4: R_MIPS_PC16	external_label
+0+00c8 <[^>]*> nop
+0+00cc <[^>]*> slt	at,a0,a1
+0+00d0 <[^>]*> beqzl	at,000000d0 <text_label\+0xd0>
+[ 	]*d0: R_MIPS_PC16	external_label
+0+00d4 <[^>]*> nop
+0+00d8 <[^>]*> slt	at,a1,a0
+0+00dc <[^>]*> bnezl	at,000000dc <text_label\+0xdc>
+[ 	]*dc: R_MIPS_PC16	external_label
+0+00e0 <[^>]*> nop
 	...
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/bge.s source/gas/testsuite/gas/mips/bge.s
--- source-orig/gas/testsuite/gas/mips/bge.s	Thu Dec 19 23:55:25 2002
+++ source/gas/testsuite/gas/mips/bge.s	Wed Feb 26 07:20:19 2003
@@ -25,10 +25,10 @@ text_label:	
 	bgtl	$4,$5,text_label
 
 # Branch to an external label.
-#	bge	$4,$5,external_label
-#	bgt	$4,$5,external_label
-#	bgel	$4,$5,external_label
-#	bgtl	$4,$5,external_label
+	bge	$4,$5,external_label
+	bgt	$4,$5,external_label
+	bgel	$4,$5,external_label
+	bgtl	$4,$5,external_label
 
 # Round to a 16 byte boundary, for ease in testing multiple targets.
 	nop
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/bgeu.d source/gas/testsuite/gas/mips/bgeu.d
--- source-orig/gas/testsuite/gas/mips/bgeu.d	Thu Dec 19 23:55:25 2002
+++ source/gas/testsuite/gas/mips/bgeu.d	Wed Feb 26 07:20:19 2003
@@ -45,20 +45,20 @@ Disassembly of section .text:
 0+0090 <[^>]*> sltu	at,a1,a0
 0+0094 <[^>]*> bnezl	at,0+0000 <text_label>
 0+0098 <[^>]*> nop
-#0+009c <[^>]*> sltu	at,a0,a1
-#0+00a0 <[^>]*> beqz	at,000000a0 <text_label\+0xa0>
-#[ 	]*a0: R_MIPS_PC16	external_label
-#0+00a4 <[^>]*> nop
-#0+00a8 <[^>]*> sltu	at,a1,a0
-#0+00ac <[^>]*> bnez	at,000000ac <text_label\+0xac>
-#[ 	]*ac: R_MIPS_PC16	external_label
-#0+00b0 <[^>]*> nop
-#0+00b4 <[^>]*> sltu	at,a0,a1
-#0+00b8 <[^>]*> beqzl	at,000000b8 <text_label\+0xb8>
-#[ 	]*b8: R_MIPS_PC16	external_label
-#0+00bc <[^>]*> nop
-#0+00c0 <[^>]*> sltu	at,a1,a0
-#0+00c4 <[^>]*> bnezl	at,000000c4 <text_label\+0xc4>
-#[ 	]*c4: R_MIPS_PC16	external_label
-#0+00c8 <[^>]*> nop
+0+009c <[^>]*> sltu	at,a0,a1
+0+00a0 <[^>]*> beqz	at,000000a0 <text_label\+0xa0>
+[ 	]*a0: R_MIPS_PC16	external_label
+0+00a4 <[^>]*> nop
+0+00a8 <[^>]*> sltu	at,a1,a0
+0+00ac <[^>]*> bnez	at,000000ac <text_label\+0xac>
+[ 	]*ac: R_MIPS_PC16	external_label
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> sltu	at,a0,a1
+0+00b8 <[^>]*> beqzl	at,000000b8 <text_label\+0xb8>
+[ 	]*b8: R_MIPS_PC16	external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> sltu	at,a1,a0
+0+00c4 <[^>]*> bnezl	at,000000c4 <text_label\+0xc4>
+[ 	]*c4: R_MIPS_PC16	external_label
+0+00c8 <[^>]*> nop
 	...
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/bgeu.s source/gas/testsuite/gas/mips/bgeu.s
--- source-orig/gas/testsuite/gas/mips/bgeu.s	Thu Dec 19 23:55:25 2002
+++ source/gas/testsuite/gas/mips/bgeu.s	Wed Feb 26 07:20:19 2003
@@ -23,10 +23,10 @@ text_label:	
 	bgtul	$4,$5,text_label
 
 # Branch to an external label.
-#	bgeu	$4,$5,external_label
-#	bgtu	$4,$5,external_label
-#	bgeul	$4,$5,external_label
-#	bgtul	$4,$5,external_label
+	bgeu	$4,$5,external_label
+	bgtu	$4,$5,external_label
+	bgeul	$4,$5,external_label
+	bgtul	$4,$5,external_label
 
 # Round to a 16 byte boundary, for ease in testing multiple targets.
 	nop
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/blt.d source/gas/testsuite/gas/mips/blt.d
--- source-orig/gas/testsuite/gas/mips/blt.d	Thu Dec 19 23:55:25 2002
+++ source/gas/testsuite/gas/mips/blt.d	Wed Feb 26 07:20:19 2003
@@ -51,20 +51,20 @@ Disassembly of section .text:
 0+00a8 <[^>]*> slt	at,a1,a0
 0+00ac <[^>]*> beqzl	at,0+0000 <text_label>
 0+00b0 <[^>]*> nop
-#0+00b4 <[^>]*> slt	at,a0,a1
-#0+00b8 <[^>]*> bnez	at,000000b8 <text_label\+0xb8>
-#[ 	]*b8: R_MIPS_PC16	external_label
-#0+00bc <[^>]*> nop
-#0+00c0 <[^>]*> slt	at,a1,a0
-#0+00c4 <[^>]*> beqz	at,000000c4 <text_label\+0xc4>
-#[ 	]*c4: R_MIPS_PC16	external_label
-#0+00c8 <[^>]*> nop
-#0+00cc <[^>]*> slt	at,a0,a1
-#0+00d0 <[^>]*> bnezl	at,000000d0 <text_label\+0xd0>
-#[ 	]*d0: R_MIPS_PC16	external_label
-#0+00d4 <[^>]*> nop
-#0+00d8 <[^>]*> slt	at,a1,a0
-#0+00dc <[^>]*> beqzl	at,000000dc <text_label\+0xdc>
-#[ 	]*dc: R_MIPS_PC16	external_label
-#0+00e0 <[^>]*> nop
+0+00b4 <[^>]*> slt	at,a0,a1
+0+00b8 <[^>]*> bnez	at,000000b8 <text_label\+0xb8>
+[ 	]*b8: R_MIPS_PC16	external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> slt	at,a1,a0
+0+00c4 <[^>]*> beqz	at,000000c4 <text_label\+0xc4>
+[ 	]*c4: R_MIPS_PC16	external_label
+0+00c8 <[^>]*> nop
+0+00cc <[^>]*> slt	at,a0,a1
+0+00d0 <[^>]*> bnezl	at,000000d0 <text_label\+0xd0>
+[ 	]*d0: R_MIPS_PC16	external_label
+0+00d4 <[^>]*> nop
+0+00d8 <[^>]*> slt	at,a1,a0
+0+00dc <[^>]*> beqzl	at,000000dc <text_label\+0xdc>
+[ 	]*dc: R_MIPS_PC16	external_label
+0+00e0 <[^>]*> nop
 	...
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/blt.s source/gas/testsuite/gas/mips/blt.s
--- source-orig/gas/testsuite/gas/mips/blt.s	Thu Dec 19 23:55:26 2002
+++ source/gas/testsuite/gas/mips/blt.s	Wed Feb 26 07:20:19 2003
@@ -25,10 +25,10 @@ text_label:	
 	blel	$4,$5,text_label
 
 # Branch to an external label.
-#	blt	$4,$5,external_label
-#	ble	$4,$5,external_label
-#	bltl	$4,$5,external_label
-#	blel	$4,$5,external_label
+	blt	$4,$5,external_label
+	ble	$4,$5,external_label
+	bltl	$4,$5,external_label
+	blel	$4,$5,external_label
 
 # Round to a 16 byte boundary, for ease in testing multiple targets.
 	nop
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/bltu.d source/gas/testsuite/gas/mips/bltu.d
--- source-orig/gas/testsuite/gas/mips/bltu.d	Thu Dec 19 23:55:26 2002
+++ source/gas/testsuite/gas/mips/bltu.d	Wed Feb 26 07:20:19 2003
@@ -45,20 +45,20 @@ Disassembly of section .text:
 0+0090 <[^>]*> sltu	at,a1,a0
 0+0094 <[^>]*> beqzl	at,0+0000 <text_label>
 0+0098 <[^>]*> nop
-#0+009c <[^>]*> sltu	at,a0,a1
-#0+00a0 <[^>]*> bnez	at,000000a0 <text_label\+0xa0>
-#[ 	]*a0: R_MIPS_PC16	external_label
-#0+00a4 <[^>]*> nop
-#0+00a8 <[^>]*> sltu	at,a1,a0
-#0+00ac <[^>]*> beqz	at,000000ac <text_label\+0xac>
-#[ 	]*ac: R_MIPS_PC16	external_label
-#0+00b0 <[^>]*> nop
-#0+00b4 <[^>]*> sltu	at,a0,a1
-#0+00b8 <[^>]*> bnezl	at,000000b8 <text_label\+0xb8>
-#[ 	]*b8: R_MIPS_PC16	external_label
-#0+00bc <[^>]*> nop
-#0+00c0 <[^>]*> sltu	at,a1,a0
-#0+00c4 <[^>]*> beqzl	at,000000c4 <text_label\+0xc4>
-#[ 	]*c4: R_MIPS_PC16	external_label
-#0+00c8 <[^>]*> nop
+0+009c <[^>]*> sltu	at,a0,a1
+0+00a0 <[^>]*> bnez	at,000000a0 <text_label\+0xa0>
+[ 	]*a0: R_MIPS_PC16	external_label
+0+00a4 <[^>]*> nop
+0+00a8 <[^>]*> sltu	at,a1,a0
+0+00ac <[^>]*> beqz	at,000000ac <text_label\+0xac>
+[ 	]*ac: R_MIPS_PC16	external_label
+0+00b0 <[^>]*> nop
+0+00b4 <[^>]*> sltu	at,a0,a1
+0+00b8 <[^>]*> bnezl	at,000000b8 <text_label\+0xb8>
+[ 	]*b8: R_MIPS_PC16	external_label
+0+00bc <[^>]*> nop
+0+00c0 <[^>]*> sltu	at,a1,a0
+0+00c4 <[^>]*> beqzl	at,000000c4 <text_label\+0xc4>
+[ 	]*c4: R_MIPS_PC16	external_label
+0+00c8 <[^>]*> nop
 	...
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/bltu.s source/gas/testsuite/gas/mips/bltu.s
--- source-orig/gas/testsuite/gas/mips/bltu.s	Thu Dec 19 23:55:26 2002
+++ source/gas/testsuite/gas/mips/bltu.s	Wed Feb 26 07:20:19 2003
@@ -23,10 +23,10 @@ text_label:	
 	bleul	$4,$5,text_label
 
 # Branch to an external label.
-#	bltu	$4,$5,external_label
-#	bleu	$4,$5,external_label
-#	bltul	$4,$5,external_label
-#	bleul	$4,$5,external_label
+	bltu	$4,$5,external_label
+	bleu	$4,$5,external_label
+	bltul	$4,$5,external_label
+	bleul	$4,$5,external_label
 
 # Round to a 16 byte boundary, for ease in testing multiple targets.
 	nop
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/branch-misc-2.d source/gas/testsuite/gas/mips/branch-misc-2.d
--- source-orig/gas/testsuite/gas/mips/branch-misc-2.d	Thu Jan  1 01:00:00 1970
+++ source/gas/testsuite/gas/mips/branch-misc-2.d	Wed Feb 26 07:20:19 2003
@@ -0,0 +1,39 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch-misc-2
+
+# Test the backward branches to globals symbols in current file.
+
+.*: +file format .*mips.*
+
+Disassembly of section .text:
+	\.\.\.
+	\.\.\.
+	\.\.\.
+0+003c <[^>]*> 0411ffff 	bal	0000003c <x>
+[ 	]*3c: R_MIPS_PC16	g1
+0+0040 <[^>]*> 00000000 	nop
+0+0044 <[^>]*> 0411ffff 	bal	00000044 <x\+0x8>
+[ 	]*44: R_MIPS_PC16	g2
+0+0048 <[^>]*> 00000000 	nop
+0+004c <[^>]*> 0411ffff 	bal	0000004c <x\+0x10>
+[ 	]*4c: R_MIPS_PC16	g3
+0+0050 <[^>]*> 00000000 	nop
+0+0054 <[^>]*> 0411ffff 	bal	00000054 <x\+0x18>
+[ 	]*54: R_MIPS_PC16	g4
+0+0058 <[^>]*> 00000000 	nop
+0+005c <[^>]*> 0411ffff 	bal	0000005c <x\+0x20>
+[ 	]*5c: R_MIPS_PC16	g5
+0+0060 <[^>]*> 00000000 	nop
+0+0064 <[^>]*> 0411ffff 	bal	00000064 <x\+0x28>
+[ 	]*64: R_MIPS_PC16	g6
+0+0068 <[^>]*> 00000000 	nop
+	\.\.\.
+	\.\.\.
+	\.\.\.
+0+00a8 <[^>]*> 1000ffff 	b	000000a8 <g6>
+[ 	]*a8: R_MIPS_PC16	x1
+0+00ac <[^>]*> 00000000 	nop
+0+00b0 <[^>]*> 1000ffff 	b	000000b0 <g6\+0x8>
+[ 	]*b0: R_MIPS_PC16	x2
+0+00b4 <[^>]*> 00000000 	nop
+	\.\.\.
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/branch-misc-2.l source/gas/testsuite/gas/mips/branch-misc-2.l
--- source-orig/gas/testsuite/gas/mips/branch-misc-2.l	Thu Dec 12 05:40:22 2002
+++ source/gas/testsuite/gas/mips/branch-misc-2.l	Thu Jan  1 01:00:00 1970
@@ -1,9 +0,0 @@
-.*: Assembler messages:
-.*:21: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:22: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:23: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:24: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:25: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:26: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:35: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:36: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
diff -urpNX /bigdisk/src/gcc-exclude source-orig/gas/testsuite/gas/mips/mips.exp source/gas/testsuite/gas/mips/mips.exp
--- source-orig/gas/testsuite/gas/mips/mips.exp	Wed Jan 29 18:30:33 2003
+++ source/gas/testsuite/gas/mips/mips.exp	Wed Feb 26 07:20:19 2003
@@ -407,7 +407,7 @@ if { [istarget mips*-*-*] } then {
     run_dump_test_arches "blt"		[mips_arch_list_matching mips2]
     run_dump_test_arches "bltu"		[mips_arch_list_matching mips2]
     run_dump_test_arches "branch-misc-1" [mips_arch_list_matching mips1]
-    run_list_test_arches "branch-misc-2" "" [mips_arch_list_matching mips1]
+    run_dump_test_arches "branch-misc-2" [mips_arch_list_matching mips1]
 
     if $ilocks {
 	run_dump_test "div-ilocks"

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-02-26  8:29   ` Thiemo Seufer
@ 2003-02-26 12:40     ` Maciej W. Rozycki
       [not found]     ` <mailpost.1046248250.18752@news-sj1-1>
  2003-03-04  6:11     ` Alexandre Oliva
  2 siblings, 0 replies; 19+ messages in thread
From: Maciej W. Rozycki @ 2003-02-26 12:40 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: Eric Christopher, binutils

On Wed, 26 Feb 2003, Thiemo Seufer wrote:

> Well, this patch changes the definition of R_MIPS_PC16 (used for branch
> relocations) from a plain addend to a rightshift 2 addend. This reflects
> the hardware capabilities.
> The old version, written according to the ABI spec, was useless, therefore
> it was unused with the exception of some half-working/half-broken behaviour
> in binutils, and the ABI people at MIPS say it was a typo in the spec and
> should have never been defined this way.

 I hope this will get accepted this time -- my attempt to fix it a few
years ago was unfortunately rejected as breaking the ABI, even though both
the definition and the current implementation are indeed useless.

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
       [not found]     ` <mailpost.1046248250.18752@news-sj1-1>
@ 2003-02-26 17:11       ` cgd
  2003-02-26 17:33         ` Thiemo Seufer
  0 siblings, 1 reply; 19+ messages in thread
From: cgd @ 2003-02-26 17:11 UTC (permalink / raw)
  To: ica2_ts; +Cc: Eric Christopher, binutils

At Wed, 26 Feb 2003 08:30:50 +0000 (UTC), "Thiemo Seufer" wrote:
> The old version, written according to the ABI spec, was useless, therefore
> it was unused with the exception of some half-working/half-broken behaviour
> in binutils, and the ABI people at MIPS say it was a typo in the spec and
> should have never been defined this way.

in other words, you've _created_ a new element of an ABI.

ultimately, the ability to branch to externs or syms in other sections
is probably the right thing, but, well, if it's gonna be implemented
by inventing something new in the ABI (because, well, what's there now
obviously can't be used).  i'd really like to see it in an ABI
document _first_.  Otherwise, it'll be implemented, and somebody'll
change their mind about how it should work, and then some significant
have the ABI change out from under them.


> This patch fixes the problem of branches to globals in the same file,

I don't believe you need to actually create a new element of the ABI
to do this, though...

(well, s/same file/same file, same section/ ... it's pedantry, but
somebody just corrected me in the same way.  8-)


cgd

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-02-26 17:11       ` cgd
@ 2003-02-26 17:33         ` Thiemo Seufer
  2003-02-26 18:02           ` Eric Christopher
  0 siblings, 1 reply; 19+ messages in thread
From: Thiemo Seufer @ 2003-02-26 17:33 UTC (permalink / raw)
  To: cgd; +Cc: Eric Christopher, binutils

cgd@broadcom.com wrote:
> At Wed, 26 Feb 2003 08:30:50 +0000 (UTC), "Thiemo Seufer" wrote:
> > The old version, written according to the ABI spec, was useless, therefore
> > it was unused with the exception of some half-working/half-broken behaviour
> > in binutils, and the ABI people at MIPS say it was a typo in the spec and
> > should have never been defined this way.
> 
> in other words, you've _created_ a new element of an ABI.

I implemented it in the way it should have been long before.

> ultimately, the ability to branch to externs or syms in other sections
> is probably the right thing, but, well, if it's gonna be implemented
> by inventing something new in the ABI (because, well, what's there now
> obviously can't be used).  i'd really like to see it in an ABI
> document _first_.

This would be nice, but for MIPS there were many ABIs announced and
few were ever formally specified.

> Otherwise, it'll be implemented, and somebody'll
> change their mind about how it should work, and then some significant
> have the ABI change out from under them.

That's IMHO pretty unlikely, given that MIPS Corp. "owns" the ABI
and they agree on this interpretation of the Spec.

> > This patch fixes the problem of branches to globals in the same file,
> 
> I don't believe you need to actually create a new element of the ABI
> to do this, though...

The alternative would be to simply allow the GNU extension reloc for the
other ABIs, but then GNU binutils won't be compatible to other toolchains.
I forgot to mention that the SDE MIPS Tools (formerly Algorithmics, now
AFAIK the official MIPS toolchain) have used R_MIPS_PC16 for years in the
way my patch does now for binutils.

So, if nobody comes up with an implementation adhering to the ABI wording,
there shouldn't be any problem.


Thiemo

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-02-26 17:33         ` Thiemo Seufer
@ 2003-02-26 18:02           ` Eric Christopher
  2003-02-28 12:22             ` Maciej W. Rozycki
  0 siblings, 1 reply; 19+ messages in thread
From: Eric Christopher @ 2003-02-26 18:02 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: cgd, binutils


> > in other words, you've _created_ a new element of an ABI.
> 
> I implemented it in the way it should have been long before.
> 

Thanks.

> > Otherwise, it'll be implemented, and somebody'll
> > change their mind about how it should work, and then some significant
> > have the ABI change out from under them.
> 
> That's IMHO pretty unlikely, given that MIPS Corp. "owns" the ABI
> and they agree on this interpretation of the Spec.
> 

Nah. I'd fully believe that they'd change the ABI here. There should be
at least some... official document out of MIPS with these changes. I
doubt I'll see it though.

> The alternative would be to simply allow the GNU extension reloc for the
> other ABIs, but then GNU binutils won't be compatible to other toolchains.
> I forgot to mention that the SDE MIPS Tools (formerly Algorithmics, now
> AFAIK the official MIPS toolchain) have used R_MIPS_PC16 for years in the
> way my patch does now for binutils.
> 

I care less about compatibility with other tools than doing the right
thing here. Why don't we have a friendly local MIPS licensee talk to
them?

-eric

-- 
o/~ Cry havoc... o/~

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
       [not found]     ` <1046317246.5258.8.camel@ghostwheel.ges.redhat.com>
@ 2003-02-27 14:34       ` Nick Clifton
  0 siblings, 0 replies; 19+ messages in thread
From: Nick Clifton @ 2003-02-27 14:34 UTC (permalink / raw)
  To: ica2_ts; +Cc: echristo, binutils

Hi Thiemo,

> > The changes might be in global files, but they're MIPS specific,
> > aren't they?  I think that gives you the right and responsibility to
> > OK the patch.

> The changes might be in global files, but they're MIPS specific,
> aren't they?  I think that gives you the right and responsibility to
> OK the patch.

Correct - even though reloc.c is a global file, the change is MIPS
specific so Eric can approve it.

Anyway...

> 2003-02-26  Thiemo Seufer <seufer at csv dot ica dot uni-stuttgart dot de>
> 
> 	/bfd/ChangeLog
> 	* elf32-mips.c (elf_mips_howto_table_rel): Change definition of
> 	R_MIPS_PC16 to rightshift 2.
> 	(elf_reloc_map mips_reloc_map): Map to rightshifted BFD reloc.
> 	(bfd_elf32_bfd_reloc_type_lookup): Support
> 	BFD_RELOC_MIPSEMB_16_PCREL_S2.
> 	* elf64-mips.c (mips_elf64_howto_table_rel): Change definition of
> 	R_MIPS_PC16 to rightshift 2.
> 	(mips_elf64_howto_table_rela): Likewise.
> 	(mips_reloc_map): Map to rightshifted BFD reloc.
> 	* elfn32-mips.c: The same as in elf64-mips.c.
> 	* elfxx-mips.c (mips_elf_got_for_ibfd): Typo in comment.
> 	(mips_elf_calculate_relocation): Handle rightshifted addends for
> 	R_MIPS_PC16.
> 	* reloc.c (BFD_RELOC_MIPSEMB_16_PCREL_S2): New BFD relocation for
> 	MIPS Embedded PIC. Remove superfluous empty COMMENT.
> 	* libbfd.h: Regenerate.
> 	* bfd-in2.h: Regenerate.
> 
> 	/gas/ChangeLog
> 	* config/tc-mips.c (append_insn): Add handling of
> 	BFD_RELOC_MIPSEMB_16_PCREL_S2. Avoid emitting unneeded
> 	BFD_RELOC_16_PCREL_S2 relocs and add earlier warnings about
> 	misaligned address and reange overflow.
> 	(macro_build): Add handling of BFD_RELOC_MIPSEMB_16_PCREL_S2. Add
> 	earlier warnings about misaligned address and reange overflow.
> 	(mips_ip): Add handling of BFD_RELOC_MIPSEMB_16_PCREL_S2.
> 	(md_apply_fix): Likewise. Fix warning output.
> 	(tc_gen_reloc): Add handling of BFD_RELOC_MIPSEMB_16_PCREL_S2.
> 	Allow BFD_RELOC_16_PCREL_S2 for all ABIs.
> 	(md_convert_frag): Add handling of BFD_RELOC_MIPSEMB_16_PCREL_S2.
> 
> 	/tas/testsuite/ChangeLog
> 	* gas/mips/bge.d: Reactivate external branch tests.
> 	* gas/mips/bge.s: Likewise.
> 	* gas/mips/bgeu.d: Likewise.
> 	* gas/mips/bgeu.s: Likewise.
> 	* gas/mips/blt.d: Likewise.
> 	* gas/mips/blt.s: Likewise.
> 	* gas/mips/bltu.d: Likewise.
> 	* gas/mips/bltu.s: Likewise.
> 	* gas/mips/branch-misc-2.d: New File.
> 	* gas/mips/branch-misc-2.l: Remove.
> 	* gas/mips/mips.exp: Adjust branch-misc-2 test.

Approved (global and mips specific changes) - please apply.

Cheers
        Nick

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-02-26 18:02           ` Eric Christopher
@ 2003-02-28 12:22             ` Maciej W. Rozycki
  2003-02-28 22:57               ` Eric Christopher
  0 siblings, 1 reply; 19+ messages in thread
From: Maciej W. Rozycki @ 2003-02-28 12:22 UTC (permalink / raw)
  To: Eric Christopher; +Cc: Dominic Sweetman, Thiemo Seufer, cgd, binutils

On 26 Feb 2003, Eric Christopher wrote:

> > The alternative would be to simply allow the GNU extension reloc for the
> > other ABIs, but then GNU binutils won't be compatible to other toolchains.
> > I forgot to mention that the SDE MIPS Tools (formerly Algorithmics, now
> > AFAIK the official MIPS toolchain) have used R_MIPS_PC16 for years in the
> > way my patch does now for binutils.
> 
> I care less about compatibility with other tools than doing the right
> thing here. Why don't we have a friendly local MIPS licensee talk to
> them?

 I hope the following statement from Dominic Sweetman clears any doubt.

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

---------- Forwarded message ----------
Message-ID: <15967.10141.166760.373070@arsenal.mips.com>
Date: Fri, 28 Feb 2003 09:10:53 +0000
From: Dominic Sweetman <dom@mips.com>
To: "Maciej W. Rozycki" <macro@ds2.pg.gda.pl>,
    Linux-MIPS <linux-mips@linux-mips.org>
Cc: Mike Uhler <uhler@mips.com>, "Kevin D. Kissell" <kevink@mips.com>,
    Nigel Stephens <nigel@mips.com>, Dominic Sweetman <dom@mips.com>,
    Ralf Baechle <ralf@linux-mips.org>
Subject: Re: The MIPS' statement on R_MIPS_PC16 relocations


Maciej W. Rozycki (macro@ds2.pg.gda.pl) writes:

> Thiemo wants to reimplement R_MIPS_PC16 relocations to be useful for
> branches which requires a relocation's addend to be shifted left by two
> before processing and then shifting a calculated value right by two before
> applying to the relocated field (similarly to what is done for R_MIPS_26
> relocations).  The ABI currently defines these relocations to be handled
> without any shifts rendering them useless for branches and probably
> anything else.  I suspect that may actually be a typo or a
> misunderstanding that happened when working on the document. 

The existing definition is nonsense - I won't guess how it happened,
but there's no reason to keep it.  Thiemo has MIPS Technologies'
thanks and blessing in making this change.  Please let our Nigel
Stephens know when it's done (mailto:nigel@mips.com) and he'll
double-check it.

I'm sure you'll put comments in the code noting that this is different
from the document.

There's a more tricky question, which is how we're going to document
this.  I'm currently trying to create a more user-friendly (and
accurate) ABI document, but had not yet got to the relocation types...

-- 
Dominic Sweetman, 
MIPS Technologies (UK)
The Fruit Farm, Ely Road, Chittering, CAMBS CB5 9PH, ENGLAND
phone: +44 1223 706205 / fax: +44 1223 706250 / swbrd: +44 1223 706200
http://www.mips.com

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-02-28 12:22             ` Maciej W. Rozycki
@ 2003-02-28 22:57               ` Eric Christopher
  2003-02-28 23:21                 ` Dominic Sweetman
  0 siblings, 1 reply; 19+ messages in thread
From: Eric Christopher @ 2003-02-28 22:57 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: Dominic Sweetman, Thiemo Seufer, cgd, binutils


> > I care less about compatibility with other tools than doing the right
> > thing here. Why don't we have a friendly local MIPS licensee talk to
> > them?
> 
>  I hope the following statement from Dominic Sweetman clears any doubt.
> 

Not as much as I'd like.

> There's a more tricky question, which is how we're going to document
> this.  I'm currently trying to create a more user-friendly (and
> accurate) ABI document, but had not yet got to the relocation types...
> 

Is he creating a new document or a new abi?

I'd prefer to have it in writing and accepted by the community before
making any more changes.

Dominic: What's going on here? :)

-eric

-- 
o/~ Cry havoc... o/~

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-02-28 22:57               ` Eric Christopher
@ 2003-02-28 23:21                 ` Dominic Sweetman
  2003-03-01  0:03                   ` Eric Christopher
  0 siblings, 1 reply; 19+ messages in thread
From: Dominic Sweetman @ 2003-02-28 23:21 UTC (permalink / raw)
  To: Eric Christopher
  Cc: Maciej W. Rozycki, Dominic Sweetman, Thiemo Seufer, cgd, binutils


Eric Christopher (echristo@redhat.com) writes:

> Is he creating a new document or a new abi?

A new document, which is supposed to describe all the existing ABIs
(o32, n32, n64).

I'm *not* very keen to transcribe bunches of C structures defining
object files into acres of tables in a manual; but we haven't
re-written anything about object files yet.

It isn't clear that n32/n64 are the right standards for embedded use,
particularly in a world (unlike the SGI one where they were invented)
which has 32-bit as well as 64-bit CPUs.  But knowing what we've got
is a sensible first step to talking about anything else.

-- 
Dominic Sweetman
MIPS Technologies
The Fruit Farm, Ely Road, Chittering, CAMBS CB5 9PH, ENGLAND
phone +44 1223 706205/fax +44 1223 706250/swbrd +44 1223 706200
http://www.algor.co.uk


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-02-28 23:21                 ` Dominic Sweetman
@ 2003-03-01  0:03                   ` Eric Christopher
  2003-03-02 16:49                     ` Dominic Sweetman
  0 siblings, 1 reply; 19+ messages in thread
From: Eric Christopher @ 2003-03-01  0:03 UTC (permalink / raw)
  To: Dominic Sweetman
  Cc: Maciej W. Rozycki, Dominic Sweetman, Thiemo Seufer, cgd, binutils

On Fri, 2003-02-28 at 15:21, Dominic Sweetman wrote:
> 
> Eric Christopher (echristo@redhat.com) writes:
> 
> > Is he creating a new document or a new abi?
> 
> A new document, which is supposed to describe all the existing ABIs
> (o32, n32, n64).
> 

OK.

> I'm *not* very keen to transcribe bunches of C structures defining
> object files into acres of tables in a manual; but we haven't
> re-written anything about object files yet.
> 

Are you documenting what's written in code or what _should_ be written
in code?

> It isn't clear that n32/n64 are the right standards for embedded use,
> particularly in a world (unlike the SGI one where they were invented)
> which has 32-bit as well as 64-bit CPUs.  But knowing what we've got
> is a sensible first step to talking about anything else.
> 

I agree.

-eric

-- 
o/~ Cry havoc... o/~

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-03-01  0:03                   ` Eric Christopher
@ 2003-03-02 16:49                     ` Dominic Sweetman
  0 siblings, 0 replies; 19+ messages in thread
From: Dominic Sweetman @ 2003-03-02 16:49 UTC (permalink / raw)
  To: Eric Christopher
  Cc: Dominic Sweetman, Maciej W. Rozycki, Dominic Sweetman,
	Thiemo Seufer, cgd, binutils


Eric Christopher (echristo@redhat.com) writes:

> Are you documenting what's written in code or what _should_ be written
> in code?

For o32 I'm basically documenting what's written in code, unless it's
obviously stupid (GNU practice is more cogent than an ancient dusty
manual). 

Sometime in the future, maybe we'll turn it round the other way!

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-02-26  8:29   ` Thiemo Seufer
  2003-02-26 12:40     ` Maciej W. Rozycki
       [not found]     ` <mailpost.1046248250.18752@news-sj1-1>
@ 2003-03-04  6:11     ` Alexandre Oliva
  2003-03-09 21:21       ` Thiemo Seufer
  2 siblings, 1 reply; 19+ messages in thread
From: Alexandre Oliva @ 2003-03-04  6:11 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: Eric Christopher, binutils

On Feb 26, 2003, Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de> wrote:

> The Embedded PIC ABI did something similiar earlier but with a GNU
> extension relocation. To keep compatible to it, we need now one new
> BFD_RELOC_MIPSEMB_16_PCREL_S2 bfd reloc, because BFD has no way to
> find out the ABI early enough.

Have you tested this heavily with n32 and/or n64?  I ran into all
sorts of trouble because of weirdnesses such as the code next to the
following comments in gas/config/tc-mips.c:

	      /* In this case, the bfd_install_relocation routine will
		 incorrectly add the symbol value back in.  We just want
		 the addend to appear in the object file.

		 howto->pcrel_offset is added for R_MIPS_PC16, which is
		 generated for code like

		 	globl g1 .text
			.text
			.space 20
		 g1:
		 x:
		 	bal g1
	       */


	      /* Make sure the addend is still non-zero.  If it became zero
		 after the last operation, set it to a spurious value and
		 subtract the same value from the object file's contents.  */


      /* This code was generated using trial and error and so is
	 fragile and not trustworthy.  If you change it, you should
	 rerun the elf-rel, elf-rel2, and empic testcases and ensure
	 they still pass.  */

	  /* BFD's REL handling, for MIPS, is _very_ weird.
	     This gives the right results, but it can't possibly
	     be the way things are supposed to work.  */


      /* If 'value' is zero, the remaining reloc code won't actually
	 do the store, so it must be done here.  This is probably
	 a bug somewhere.  */


All of these chunks assume REL relocations, and since n32 and n64 use
RELA, there's no way to generate appropriate relocations for certain
border values that trigger special conditions in the generic
relocation handling code.  I tried very hard to fix them, but failed.
I wish the fix was this simple :-(

Perhaps we should just go with branches to symbols in the same
sections for now?  Do you still have patch that you send me the other
day to that effect handy?  Perhaps you could propose it here as well?

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-03-04  6:11     ` Alexandre Oliva
@ 2003-03-09 21:21       ` Thiemo Seufer
  2003-03-09 22:31         ` Alexandre Oliva
  2003-03-11 17:15         ` Alexandre Oliva
  0 siblings, 2 replies; 19+ messages in thread
From: Thiemo Seufer @ 2003-03-09 21:21 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: Eric Christopher, binutils

Alexandre Oliva wrote:
> On Feb 26, 2003, Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de> wrote:
> 
> > The Embedded PIC ABI did something similiar earlier but with a GNU
> > extension relocation. To keep compatible to it, we need now one new
> > BFD_RELOC_MIPSEMB_16_PCREL_S2 bfd reloc, because BFD has no way to
> > find out the ABI early enough.
> 
> Have you tested this heavily with n32 and/or n64?

I did some successful tests, mainly for n64 non-PIC, but nothing
really complicated WRT branch relocations. The testsuite worked,
too, but OTOH there still aren't NewaBI tests.

> I ran into all
> sorts of trouble because of weirdnesses

I guess you are talking about mips*-linux, not mips*-irix.
The IRIX linker is likely to have troubles with R_MIPS_PC16 relocs.

> such as the code next to the
> following comments in gas/config/tc-mips.c:
> 
> 	      /* In this case, the bfd_install_relocation routine will
> 		 incorrectly add the symbol value back in.  We just want
> 		 the addend to appear in the object file.
> 
> 		 howto->pcrel_offset is added for R_MIPS_PC16, which is
> 		 generated for code like
> 
> 		 	globl g1 .text
> 			.text
> 			.space 20
> 		 g1:
> 		 x:
> 		 	bal g1
> 	       */
> 
> 
> 	      /* Make sure the addend is still non-zero.  If it became zero
> 		 after the last operation, set it to a spurious value and
> 		 subtract the same value from the object file's contents.  */
> 
> 
>       /* This code was generated using trial and error and so is
> 	 fragile and not trustworthy.  If you change it, you should
> 	 rerun the elf-rel, elf-rel2, and empic testcases and ensure
> 	 they still pass.  */
> 
> 	  /* BFD's REL handling, for MIPS, is _very_ weird.
> 	     This gives the right results, but it can't possibly
> 	     be the way things are supposed to work.  */
> 
> 
>       /* If 'value' is zero, the remaining reloc code won't actually
> 	 do the store, so it must be done here.  This is probably
> 	 a bug somewhere.  */
> 
> 
> All of these chunks assume REL relocations, and since n32 and n64 use
> RELA, there's no way to generate appropriate relocations for certain
> border values that trigger special conditions in the generic
> relocation handling code.  I tried very hard to fix them, but failed.
> I wish the fix was this simple :-(

Can you send me some testcases for these? I'd like to look into it.

> Perhaps we should just go with branches to symbols in the same
> sections for now?  Do you still have patch that you send me the other
> day to that effect handy?  Perhaps you could propose it here as well?

IMHO it's better to keep the current version and fix NewABI.
I'll propose the other patch only as a last resort thing.


Thiemo

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-03-09 21:21       ` Thiemo Seufer
@ 2003-03-09 22:31         ` Alexandre Oliva
  2003-03-09 22:49           ` Thiemo Seufer
  2003-03-11 17:15         ` Alexandre Oliva
  1 sibling, 1 reply; 19+ messages in thread
From: Alexandre Oliva @ 2003-03-09 22:31 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: Eric Christopher, binutils

On Mar  9, 2003, Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de> wrote:

> I guess you are talking about mips*-linux, not mips*-irix.

Yup.  mips64-linux, specifically.

> Can you send me some testcases for these?

Build glibc for n32 or n64, using the patch for glibc 2.3.1 I posted
to the glibc mailing list a while back.  Not even ld.so works.  I
haven't gone as far as creating a small testcase for it, but I
remember it did trigger the conditions I listed.

>> Perhaps we should just go with branches to symbols in the same
>> sections for now?  Do you still have patch that you send me the other
>> day to that effect handy?  Perhaps you could propose it here as well?

> IMHO it's better to keep the current version and fix NewABI.
> I'll propose the other patch only as a last resort thing.

Understood.  Well, I can only wish you good luck and hope you succeed
where I failed.  I wasted only 1 or 2 days on this, so perhaps being
smarter and/or having more time, you can succeed.  I hope the pointers
to the locations where I remember having found problems help.

Still, if you could post the patch here, I'm sure it could help those
who want just a stop-gap solution for branches to global symbols
within the same section, while the full-fledged solution is still
being worked on.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-03-09 22:31         ` Alexandre Oliva
@ 2003-03-09 22:49           ` Thiemo Seufer
  2003-03-10 18:56             ` Alexandre Oliva
  0 siblings, 1 reply; 19+ messages in thread
From: Thiemo Seufer @ 2003-03-09 22:49 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: Eric Christopher, binutils

Alexandre Oliva wrote:
[snip]
> >> Perhaps we should just go with branches to symbols in the same
> >> sections for now?  Do you still have patch that you send me the other
> >> day to that effect handy?  Perhaps you could propose it here as well?
> 
> > IMHO it's better to keep the current version and fix NewABI.
> > I'll propose the other patch only as a last resort thing.
> 
> Understood.  Well, I can only wish you good luck and hope you succeed
> where I failed.  I wasted only 1 or 2 days on this, so perhaps being
> smarter and/or having more time, you can succeed.  I hope the pointers
> to the locations where I remember having found problems help.
> 
> Still, if you could post the patch here, I'm sure it could help those
> who want just a stop-gap solution for branches to global symbols
> within the same section, while the full-fledged solution is still
> being worked on.

http://sources.redhat.com/ml/binutils/2003-02/msg00179.html worked for me,
but I'm not sure about it's correctness.


Thiemo

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-03-09 22:49           ` Thiemo Seufer
@ 2003-03-10 18:56             ` Alexandre Oliva
  0 siblings, 0 replies; 19+ messages in thread
From: Alexandre Oliva @ 2003-03-10 18:56 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: Eric Christopher, binutils

[-- Attachment #1: Type: text/plain, Size: 424 bytes --]

On Mar  9, 2003, Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de> wrote:

> http://sources.redhat.com/ml/binutils/2003-02/msg00179.html worked for me,
> but I'm not sure about it's correctness.

Here's my take on it.  I wrote this before realizing your patch, that
I believe to be broken, had already gone in, so I post it mostly for
reference.  I'll see if I can dig out some testcases to show the
problems I had in mind.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mips-branch-to-global.patch --]
[-- Type: text/x-patch, Size: 7459 bytes --]

Index: gas/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* config/tc-mips.c (mips_validate_fix): New function.
	* config/tc-mips.h (TC_VALIDATE_FIX): Define.
	(mips_validate_fix): Declare.

Index: gas/config/tc-mips.c
===================================================================
RCS file: /cvs/uberbaum/gas/config/tc-mips.c,v
retrieving revision 1.193
diff -u -p -r1.193 tc-mips.c
--- gas/config/tc-mips.c 21 Feb 2003 10:28:27 -0000 1.193
+++ gas/config/tc-mips.c 10 Mar 2003 18:52:46 -0000
@@ -11026,6 +11026,85 @@ mips_force_relocation (fixp)
 	      || fixp->fx_r_type == BFD_RELOC_PCREL_LO16));
 }
 
+/* This hook is called before a fix is simplified.  We don't really
+   decide whether to skip a fix here.  Rather, we turn global symbols
+   used as branch targets into local symbols, such that they undergo
+   simplification.  We can only do this if the symbol is defined and
+   it is in the same section as the branch.  If this doesn't hold, we
+   emit a better error message than just saying the relocation is not
+   valid for the selected object format.
+
+   FIXP is the fix-up we're going to try to simplify, SEG is the
+   segment in which the fix up occurs.  The return value should be
+   non-zero to indicate the fix-up is valid for further
+   simplifications.  */
+
+int
+mips_validate_fix (fixP, seg)
+     struct fix *fixP;
+     asection *seg;
+{
+  /* There's a lot of discussion on whether it should be possible to
+     use R_MIPS_PC16 to represent branch relocations.  The outcome
+     seems to be that it can, but gas/bfd are very broken in creating
+     RELA relocations for this, so for now we only accept branches to
+     symbols in the same section.  Anything else is of dubious value,
+     since there's no guarantee that at link time the symbol would be
+     in range.  Even for branches to local symbols this is arguably
+     wrong, since it we assume the symbol is not going to be
+     overridden, which should be possible per ELF library semantics,
+     but then, there isn't a dynamic relocation that could be used to
+     this effect, and the target would likely be out of range as well.
+
+     Unfortunately, it seems that there is too much code out there
+     that relies on branches to symbols that are global to be resolved
+     as if they were local, like the IRIX tools do, so we do it as
+     well, but with a warning so that people are reminded to fix their
+     code.  If we ever get back to using R_MIPS_PC16 for branch
+     targets, this entire block should go away (and probably the
+     whole function).  */
+
+  if (fixP->fx_r_type == BFD_RELOC_16_PCREL_S2
+      && (((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
+	    || OUTPUT_FLAVOR == bfd_target_elf_flavour)
+	   && mips_pic != EMBEDDED_PIC)
+	  || bfd_reloc_type_lookup (stdoutput, BFD_RELOC_16_PCREL_S2) == NULL)
+      && fixP->fx_addsy)
+    {
+      if (! S_IS_DEFINED (fixP->fx_addsy))
+	{
+	  as_bad_where (fixP->fx_file, fixP->fx_line,
+			_("Cannot branch to undefined symbol."));
+	  /* Avoid any further errors about this fixup.  */
+	  fixP->fx_done = 1;
+	}
+      else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
+	{
+	  as_bad_where (fixP->fx_file, fixP->fx_line,
+			_("Cannot branch to symbol in another section."));
+	  fixP->fx_done = 1;
+	}
+      else if (S_IS_EXTERNAL (fixP->fx_addsy))
+	{
+	  symbolS *sym = fixP->fx_addsy;
+
+	  as_warn_where (fixP->fx_file, fixP->fx_line,
+			 _("Pretending global symbol used as branch target is local."));
+
+	  fixP->fx_addsy = symbol_create (S_GET_NAME (sym),
+					  S_GET_SEGMENT (sym),
+					  S_GET_VALUE (sym),
+					  symbol_get_frag (sym));
+	  copy_symbol_attributes (fixP->fx_addsy, sym);
+	  S_CLEAR_EXTERNAL (fixP->fx_addsy);
+	  assert (symbol_resolved_p (sym));
+	  symbol_mark_resolved (fixP->fx_addsy);
+	}
+    }
+
+  return 1;
+}
+
 #ifdef OBJ_ELF
 static int
 mips_need_elf_addend_fixup (fixP)
Index: gas/config/tc-mips.h
===================================================================
RCS file: /cvs/uberbaum/gas/config/tc-mips.h,v
retrieving revision 1.23
diff -u -p -r1.23 tc-mips.h
--- gas/config/tc-mips.h 24 Jan 2003 01:12:30 -0000 1.23
+++ gas/config/tc-mips.h 10 Mar 2003 18:52:46 -0000
@@ -140,6 +140,15 @@ extern int mips_fix_adjustable PARAMS ((
 #define TC_FORCE_RELOCATION(FIX) mips_force_relocation (FIX)
 extern int mips_force_relocation PARAMS ((struct fix *));
 
+/* We use this to turn branches to global symbols into branches to
+   local symbols, so that they can be simplified.  */
+#define TC_VALIDATE_FIX(fixp, this_segment, skip_label) \
+  do \
+    if (! mips_validate_fix ((fixp), (this_segment))) \
+      goto skip_label; \
+  while (0)
+extern int mips_validate_fix PARAMS ((struct fix *, asection *));
+
 /* Register mask variables.  These are set by the MIPS assembly code
    and used by ECOFF and possibly other object file formats.  */
 extern unsigned long mips_gprmask;
Index: gas/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* gas/mips/branch-misc-2.s: Add branch to symbol in another
	section.
	* gas/mips/branch-misc-2.l: Update error messages and warnings.

Index: gas/testsuite/gas/mips/branch-misc-2.l
===================================================================
RCS file: /cvs/uberbaum/gas/testsuite/gas/mips/Attic/branch-misc-2.l,v
retrieving revision 1.1
diff -u -p -r1.1 branch-misc-2.l
--- gas/testsuite/gas/mips/branch-misc-2.l 12 Dec 2002 04:40:22 -0000 1.1
+++ gas/testsuite/gas/mips/branch-misc-2.l 10 Mar 2003 18:52:50 -0000
@@ -1,9 +1,10 @@
 .*: Assembler messages:
-.*:21: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:22: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:23: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:24: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:25: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:26: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:35: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
-.*:36: Error: Can not represent BFD_RELOC_16_PCREL_S2 relocation in this object file format
+.*:21: Warning: Pretending global symbol used as branch target is local.
+.*:22: Warning: Pretending global symbol used as branch target is local.
+.*:23: Warning: Pretending global symbol used as branch target is local.
+.*:24: Warning: Pretending global symbol used as branch target is local.
+.*:25: Warning: Pretending global symbol used as branch target is local.
+.*:26: Warning: Pretending global symbol used as branch target is local.
+.*:35: Error: Cannot branch to undefined symbol.
+.*:36: Error: Cannot branch to undefined symbol.
+.*:37: Error: Cannot branch to symbol in another section.
Index: gas/testsuite/gas/mips/branch-misc-2.s
===================================================================
RCS file: /cvs/uberbaum/gas/testsuite/gas/mips/branch-misc-2.s,v
retrieving revision 1.2
diff -u -p -r1.2 branch-misc-2.s
--- gas/testsuite/gas/mips/branch-misc-2.s 12 Dec 2002 04:40:22 -0000 1.2
+++ gas/testsuite/gas/mips/branch-misc-2.s 10 Mar 2003 18:52:50 -0000
@@ -34,6 +34,10 @@ g6:
 
 	b	x1
 	b	x2
+	b	.Ldata
 
 # Force at least 8 (non-delay-slot) zero bytes, to make 'objdump' print ...
 	.space	8
+
+	.data
+.Ldata:

[-- Attachment #3: Type: text/plain, Size: 289 bytes --]


-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
  2003-03-09 21:21       ` Thiemo Seufer
  2003-03-09 22:31         ` Alexandre Oliva
@ 2003-03-11 17:15         ` Alexandre Oliva
  1 sibling, 0 replies; 19+ messages in thread
From: Alexandre Oliva @ 2003-03-11 17:15 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: Eric Christopher, binutils

On Mar  9, 2003, Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de> wrote:

> I did some successful tests, mainly for n64 non-PIC, but nothing
> really complicated WRT branch relocations. The testsuite worked,
> too, but OTOH there still aren't NewaBI tests.

Here's a simple test, for starters:

$ cat t.s
.globl foo
.space 8
.ent foo
foo:
.space 16
        b foo
.end foo
$ as -64 -KPIC t.s -o t.o
$ objdump -dr t.o
[snip]
0000000000000008 <foo>:
        ...
  18:   10000000        b       1c <foo+0x14>
                        18: R_MIPS_PC16 foo+0x14
[snip]
$ ld -melf64btsmip t.o -o t
$ objdump -dr t
[snip]
00000000100000e8 <foo>:
        ...
    100000f8:   10000001        b       10000100 <foo+0x18>
[snip]

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: On resolving the MIPS gas branch reloc issue
@ 2003-03-01  3:52 Sean McNeil
  0 siblings, 0 replies; 19+ messages in thread
From: Sean McNeil @ 2003-03-01  3:52 UTC (permalink / raw)
  To: binutils

When can I look forward to this change being incorporated into CVS?  I
am looking at a problem right now that is hindered by the fact that
branches to global symbols is currently broken.

Sean


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2003-03-11 17:15 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20030225092644.GE25303@rembrandt.csv.ica.uni-stuttgart.de>
2003-02-26  4:17 ` On resolving the MIPS gas branch reloc issue Eric Christopher
2003-02-26  8:29   ` Thiemo Seufer
2003-02-26 12:40     ` Maciej W. Rozycki
     [not found]     ` <mailpost.1046248250.18752@news-sj1-1>
2003-02-26 17:11       ` cgd
2003-02-26 17:33         ` Thiemo Seufer
2003-02-26 18:02           ` Eric Christopher
2003-02-28 12:22             ` Maciej W. Rozycki
2003-02-28 22:57               ` Eric Christopher
2003-02-28 23:21                 ` Dominic Sweetman
2003-03-01  0:03                   ` Eric Christopher
2003-03-02 16:49                     ` Dominic Sweetman
2003-03-04  6:11     ` Alexandre Oliva
2003-03-09 21:21       ` Thiemo Seufer
2003-03-09 22:31         ` Alexandre Oliva
2003-03-09 22:49           ` Thiemo Seufer
2003-03-10 18:56             ` Alexandre Oliva
2003-03-11 17:15         ` Alexandre Oliva
     [not found]   ` <20030227001413.GY31111@bubble.sa.bigpond.net.au>
     [not found]     ` <1046317246.5258.8.camel@ghostwheel.ges.redhat.com>
2003-02-27 14:34       ` Nick Clifton
2003-03-01  3:52 Sean McNeil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).