This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

mips: branches to external labels are broken


I've been trying to fix handling of branches to external or global
labels on mips, such that they work in ABIs that use RELA relocations
too.  I happened to uncover a number of major problems in the current
code that lead me to believe that we should simply give up on this
ability.

First off, R_MIPS_PC16 is *not* supposed to shift its addend right by
2 bits, according to the specs.  I read there was some discussion
about 3 years ago to support its use in branch instructions, but I
couldn't find a resolution on it, and the patch that introduced the
incorrect shift in R_MIPS_PC16, without adjusting the assembler
similarly, was never posted to this mailing list.

Currently, we have a number of horrible hacks in the assembler that
are meant to work around weirdnesses in BFD in terms of creating ELF
relocations.  They're all preceded by comments indicating they must be
broken, or that the brokenness is elsewhere, but they appear to work,
so they're kept in there.  Fact is, they work when the addend is
in-place, but not when it is not.  When it is not, it breaks badly,
and part of the brokenness has to do with the different behavior of
bfd_install_relocation() on pc_relative partial_inplace addends (I'm
convinced that addition should be taken out, but it would probably
break too much code for me to take the risk), part of it is the
short-circuiting of the relocation adjustments that
bfd_elf_generic_reloc() does when the addend of a relocation that
points at a non-section symbol is zero, that requires the horrible
hacks to compensate for the lack of adjustment that would result
should the adjustment in bfd_install_reloc be applied, and part of it
is because the addend installed in-place is divided by 4 twice, once
in the assembler, and once when the relocation value is computed in a
final link.

This is so messed up that, whenever I dared touching it to fix the
problems, they fired back at me, and I couldn't get anything that
actually worked again.  Worse yet: the work-arounds introduced for
in-place addends, that make use of ugly hacks such as adding a
constant to the addend and subtracting it from the in-place addend,
which has no effect on the final opcode after the relocation is
installed, but that ensures that we go through the adjustments that
pc-relative relocations are subject to in bfd_install_relocation(),
don't work when the relocation has partial_inplace set to false, since
the installed addend is disregarded.

After wasting hours on this problem, I tried to investigate what IRIX
did, only to find out that its assembler won't accept branches to
external labels, and its linker doesn't even recognize R_MIPS_PC16 as
a valid relocation type.  If we were to accept branches to external
labels, we should use the extension that was come up with for Embedded
PIC, but I'm not convinced we should do it, since there's really no
benefit in being able to branch to external symbols, since you can
hardly guarantee they're going to be in range.

Besides, even branching to local symbols in other sections can be a
bad idea, since if you do reloadable links of the object file such
that the target of the branch ends up more than 32Kb away from the
beginning of its section, you lose, because the addend can't be
represented in place.  Even if the branch would end up in range, e.g.,
if the branch instruction were near the beginning of the section that
is linked right after the large one containing the branch target,
close to its end.

The IRIX toolchain actually supports branches to global labels defined
in the same translation unit, in that it uses the offset of the label
into its section as the target of the branch, and emits the opcode as
if the label and the branch were in the same section.  If this
assumption is broken, the assembler silently generates incorrect code:
no warnings, no relocations.  Oops.

If we were to support branches to global symbols, doing it properly
would be far trickier than the current code does.  For example, if we
had a branch to a symbol that was defined in a shared library, but
happened to be overridden at run-time, the branch would likely be
out-of-range, and we wouldn't even have a dynamic relocation to mark
the branch instruction (which would force the code section to be
writable, eek).  We could help that by generating PLT entries for
branch targets that were global symbols, but such PLT entries would
clobber registers that branches are not supposed to clobber, and
branching into other loadable modules would probably require the $gp
to be initialized for the other module anyway, something that a branch
target isn't likely to do.  Not to mention that the PLT entry would
probably be out of range too...

So, I'm convinced that supporting overriding of branch targets is a
bad idea, and that silently turning them into local branches, like the
SGI assembler does, is surprising.  Since I found only 3 occurrences
of branches to global symbols in mips64 Linux (the kernel), and only 1
occurrence in glibc, and the compiler never generates branches to
global symbols, I'm convinced disabling entirely branches to global or
undefined symbols is safe enough, so I'd like permission to do so,
with the first patch below.  It keeps embedded mips functional, in
that branches to undefined and global symbols are still generated and
handled properly, using the relocation defined as a GNU extension, as
it always has.  The second patch fixes R_MIPS_PC16 such that it
complies with the specification, even though I'd much rather error out
when such a relocation is encountered, given the ambiguity introduced
by the mis-use thereof we've made for some time.

No regressions on the mips-elf testsuite.  Ok to install?

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

	* tc-mips.c (RELAX_BRANCH_ENCODE): Remove reloc_s2 argument.
	Adjust callers.
	(RELAX_BRANCH_RELOC_S2): Delete.
	(append_insn): Use only BFD_RELOC_16_PCREL_S2 for branches.
	Do not handle BFD_RELOC_16_PCREL.
	(macro_build, mips_ip): Likewise.
	(md_pcrel_from): Return 4 for undefined symbols regardless of
	mips_pic.
	(md_apply_fix3): Use only BFD_RELOC_16_PCREL_S2 for branches.
	Don't dereference howto if no such relocation is available.
	Do not apply hack for in-place zero addend in NEWABI.
	(md_convert_frag): Use only BFD_RELOC_16_PCREL_S2 for branches.

Index: gas/config/tc-mips.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mips.c,v
retrieving revision 1.180
diff -u -p -r1.180 tc-mips.c
--- gas/config/tc-mips.c 18 Nov 2002 21:08:53 -0000 1.180
+++ gas/config/tc-mips.c 26 Nov 2002 02:33:09 -0000
@@ -714,16 +714,14 @@ static int mips_relax_branch;
 
 
    but it's not clear that it would actually improve performance.  */
-#define RELAX_BRANCH_ENCODE(reloc_s2, uncond, likely, link, toofar) \
+#define RELAX_BRANCH_ENCODE(uncond, likely, link, toofar) \
   ((relax_substateT) \
    (0xc0000000 \
     | ((toofar) ? 1 : 0) \
     | ((link) ? 2 : 0) \
     | ((likely) ? 4 : 0) \
-    | ((uncond) ? 8 : 0) \
-    | ((reloc_s2) ? 16 : 0)))
+    | ((uncond) ? 8 : 0)))
 #define RELAX_BRANCH_P(i) (((i) & 0xf0000000) == 0xc0000000)
-#define RELAX_BRANCH_RELOC_S2(i) (((i) & 16) != 0)
 #define RELAX_BRANCH_UNCOND(i) (((i) & 8) != 0)
 #define RELAX_BRANCH_LIKELY(i) (((i) & 4) != 0)
 #define RELAX_BRANCH_LINK(i) (((i) & 2) != 0)
@@ -1948,9 +1946,7 @@ append_insn (place, ip, address_expr, re
 
   if (place == NULL
       && address_expr
-      && ((*reloc_type == BFD_RELOC_16_PCREL
-	   && address_expr->X_op != O_constant)
-	  || *reloc_type == BFD_RELOC_16_PCREL_S2)
+      && *reloc_type == BFD_RELOC_16_PCREL_S2
       && (pinfo & INSN_UNCOND_BRANCH_DELAY || pinfo & INSN_COND_BRANCH_DELAY
 	  || pinfo & INSN_COND_BRANCH_LIKELY)
       && mips_relax_branch
@@ -1967,8 +1963,7 @@ append_insn (place, ip, address_expr, re
 		     (pinfo & INSN_UNCOND_BRANCH_DELAY) ? -1
 		     : (pinfo & INSN_COND_BRANCH_LIKELY) ? 1 : 0), 4,
 		    RELAX_BRANCH_ENCODE
-		    (*reloc_type == BFD_RELOC_16_PCREL_S2,
-		     pinfo & INSN_UNCOND_BRANCH_DELAY,
+		    (pinfo & INSN_UNCOND_BRANCH_DELAY,
 		     pinfo & INSN_COND_BRANCH_LIKELY,
 		     pinfo & INSN_WRITE_GPR_31,
 		     0),
@@ -2072,10 +2067,6 @@ append_insn (place, ip, address_expr, re
 		 | ((address_expr->X_add_number & 0x3fffc) >> 2));
 	      break;
 
-	    case BFD_RELOC_16_PCREL:
-	      ip->insn_opcode |= address_expr->X_add_number & 0xffff;
-	      break;
-
 	    case BFD_RELOC_16_PCREL_S2:
 	      goto need_reloc;
 
@@ -2091,8 +2082,7 @@ 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
-				      || *reloc_type == BFD_RELOC_16_PCREL_S2),
+				     *reloc_type == BFD_RELOC_16_PCREL_S2,
 				     reloc_type[0]);
 
 	      /* These relocations can have an addend that won't fit in
@@ -3059,10 +3049,7 @@ macro_build (place, counter, ep, name, f
 	      ep = NULL;
 	    }
 	  else
-	    if (mips_pic == EMBEDDED_PIC)
-	      *r = BFD_RELOC_16_PCREL_S2;
-	    else
-	      *r = BFD_RELOC_16_PCREL;
+	    *r = BFD_RELOC_16_PCREL_S2;
 	  continue;
 
 	case 'a':
@@ -8955,10 +8942,7 @@ mips_ip (str, ip)
 	      continue;
 
 	    case 'p':		/* pc relative offset */
-	      if (mips_pic == EMBEDDED_PIC)
-		*offset_reloc = BFD_RELOC_16_PCREL_S2;
-	      else
-		*offset_reloc = BFD_RELOC_16_PCREL;
+	      *offset_reloc = BFD_RELOC_16_PCREL_S2;
 	      my_getExpression (&offset_expr, s);
 	      s = expr_end;
 	      continue;
@@ -10809,14 +10793,7 @@ md_pcrel_from (fixP)
   if (OUTPUT_FLAVOR != bfd_target_aout_flavour
       && fixP->fx_addsy != (symbolS *) NULL
       && ! S_IS_DEFINED (fixP->fx_addsy))
-    {
-      /* This makes a branch to an undefined symbol be a branch to the
-	 current location.  */
-      if (mips_pic == EMBEDDED_PIC)
-	return 4;
-      else
-	return 1;
-    }
+    return 4;
 
   /* Return the address of the delay slot.  */
   return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
@@ -11047,7 +11024,7 @@ md_apply_fix3 (fixP, valP, seg)
 	  value -= symval;
 
 	  howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
-	  if (value != 0 && howto->partial_inplace
+	  if (value != 0 && howto && howto->partial_inplace
 	      && (! fixP->fx_pcrel || howto->pcrel_offset))
 	    {
 	      /* In this case, the bfd_install_relocation routine will
@@ -11111,8 +11088,7 @@ 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
-	       && fixP->fx_r_type != BFD_RELOC_16_PCREL_S2)
+	  if (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
 	      || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
 	    value += fixP->fx_frag->fr_address + fixP->fx_where;
 	}
@@ -11286,15 +11262,12 @@ md_apply_fix3 (fixP, valP, seg)
 	as_bad_where (fixP->fx_file, fixP->fx_line,
 		      _("Branch to odd address (%lx)"), (long) value);
 
-      /* Fall through.  */
-
-    case BFD_RELOC_16_PCREL:
       /*
        * We need to save the bits in the instruction since fixup_segment()
        * might be deleting the relocation entry (i.e., a branch within
        * the current segment).
        */
-      if (!fixP->fx_done && value != 0)
+      if (!fixP->fx_done && (value != 0 || HAVE_NEWABI))
 	break;
       /* If 'value' is zero, the remaining reloc code won't actually
 	 do the store, so it must be done here.  This is probably
@@ -12901,8 +12874,7 @@ relaxed_branch_length (fragp, sec, updat
 
   if (fragp && update && toofar != RELAX_BRANCH_TOOFAR (fragp->fr_subtype))
     fragp->fr_subtype
-      = RELAX_BRANCH_ENCODE (RELAX_BRANCH_RELOC_S2 (fragp->fr_subtype),
-			     RELAX_BRANCH_UNCOND (fragp->fr_subtype),
+      = RELAX_BRANCH_ENCODE (RELAX_BRANCH_UNCOND (fragp->fr_subtype),
 			     RELAX_BRANCH_LIKELY (fragp->fr_subtype),
 			     RELAX_BRANCH_LINK (fragp->fr_subtype),
 			     toofar);
@@ -13396,9 +13368,7 @@ md_convert_frag (abfd, asec, fragp)
 
 	  fixp = fix_new_exp (fragp, buf - (bfd_byte *)fragp->fr_literal,
 			      4, &exp, 1,
-			      RELAX_BRANCH_RELOC_S2 (fragp->fr_subtype)
-			      ? BFD_RELOC_16_PCREL_S2
-			      : BFD_RELOC_16_PCREL);
+			      BFD_RELOC_16_PCREL_S2);
 	  fixp->fx_file = fragp->fr_file;
 	  fixp->fx_line = fragp->fr_line;
 	  
Index: gas/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* gas/mips/beq.d: Comment out branches to undefined symbols,
	no longer supported.
	* gas/mips/beq.s: Likewise.
	* gas/mips/bge.d: Likewise.
	* 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/mips.exp: Change branch-misc-2 test to run_list_test.
	* gas/mips/branch-misc-2.d: Removed.
	* gas/mips/branch-misc-2.s: Added branches to undefined symbols.
	* gas/mips/branch-misc-2.l: New.

? gas/testsuite/gas/mips/branch-misc-2.l
Index: gas/testsuite/gas/mips/beq.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/beq.d,v
retrieving revision 1.4
diff -u -p -r1.4 beq.d
--- gas/testsuite/gas/mips/beq.d 23 Oct 2001 19:20:28 -0000 1.4
+++ gas/testsuite/gas/mips/beq.d 26 Nov 2002 02:33:13 -0000
@@ -39,10 +39,10 @@ Disassembly of section .text:
 0+20070 <[^>]*> jal	0+0000 <text_label>
 [ 	]*20070: (MIPS_JMP|JMPADDR|R_MIPS_26)	.text
 0+20074 <[^>]*> nop
-0+20078 <[^>]*> b	0+20078 <text_label\+0x20078>
-[ 	]*20078: R_MIPS_PC16	external_label
-0+2007c <[^>]*> nop
-0+20080 <[^>]*> bal	0+20080 <text_label\+0x20080>
-[ 	]*20080: R_MIPS_PC16	external_label
-0+20084 <[^>]*> nop
+#0+20078 <[^>]*> b	0+20078 <text_label\+0x20078>
+#[ 	]*20078: R_MIPS_PC16	external_label
+#0+2007c <[^>]*> nop
+#0+20080 <[^>]*> bal	0+20080 <text_label\+0x20080>
+#[ 	]*20080: R_MIPS_PC16	external_label
+#0+20084 <[^>]*> nop
 	...
Index: gas/testsuite/gas/mips/beq.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/beq.s,v
retrieving revision 1.4
diff -u -p -r1.4 beq.s
--- gas/testsuite/gas/mips/beq.s 5 Sep 2002 00:05:44 -0000 1.4
+++ gas/testsuite/gas/mips/beq.s 26 Nov 2002 02:33:13 -0000
@@ -23,8 +23,8 @@ text_label:	
 	bal	text_label
 
 # Branch to an external label.
-	b	external_label
-	bal	external_label
+#	b	external_label
+#	bal	external_label
 
 # Force at least 8 (non-delay-slot) zero bytes, to make 'objdump' print ...
 	.space	8
Index: gas/testsuite/gas/mips/bge.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/bge.d,v
retrieving revision 1.4
diff -u -p -r1.4 bge.d
--- gas/testsuite/gas/mips/bge.d 23 Oct 2001 19:20:28 -0000 1.4
+++ gas/testsuite/gas/mips/bge.d 26 Nov 2002 02:33:13 -0000
@@ -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
 	...
Index: gas/testsuite/gas/mips/bge.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/bge.s,v
retrieving revision 1.2
diff -u -p -r1.2 bge.s
--- gas/testsuite/gas/mips/bge.s 7 Sep 2001 05:00:37 -0000 1.2
+++ gas/testsuite/gas/mips/bge.s 26 Nov 2002 02:33:13 -0000
@@ -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
Index: gas/testsuite/gas/mips/bgeu.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/bgeu.d,v
retrieving revision 1.4
diff -u -p -r1.4 bgeu.d
--- gas/testsuite/gas/mips/bgeu.d 23 Oct 2001 19:20:28 -0000 1.4
+++ gas/testsuite/gas/mips/bgeu.d 26 Nov 2002 02:33:13 -0000
@@ -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
 	...
Index: gas/testsuite/gas/mips/bgeu.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/bgeu.s,v
retrieving revision 1.2
diff -u -p -r1.2 bgeu.s
--- gas/testsuite/gas/mips/bgeu.s 7 Sep 2001 05:00:37 -0000 1.2
+++ gas/testsuite/gas/mips/bgeu.s 26 Nov 2002 02:33:13 -0000
@@ -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
Index: gas/testsuite/gas/mips/blt.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/blt.d,v
retrieving revision 1.4
diff -u -p -r1.4 blt.d
--- gas/testsuite/gas/mips/blt.d 23 Oct 2001 19:20:28 -0000 1.4
+++ gas/testsuite/gas/mips/blt.d 26 Nov 2002 02:33:13 -0000
@@ -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
 	...
Index: gas/testsuite/gas/mips/blt.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/blt.s,v
retrieving revision 1.2
diff -u -p -r1.2 blt.s
--- gas/testsuite/gas/mips/blt.s 7 Sep 2001 05:00:37 -0000 1.2
+++ gas/testsuite/gas/mips/blt.s 26 Nov 2002 02:33:13 -0000
@@ -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
Index: gas/testsuite/gas/mips/bltu.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/bltu.d,v
retrieving revision 1.4
diff -u -p -r1.4 bltu.d
--- gas/testsuite/gas/mips/bltu.d 23 Oct 2001 19:20:28 -0000 1.4
+++ gas/testsuite/gas/mips/bltu.d 26 Nov 2002 02:33:13 -0000
@@ -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
 	...
Index: gas/testsuite/gas/mips/bltu.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/bltu.s,v
retrieving revision 1.2
diff -u -p -r1.2 bltu.s
--- gas/testsuite/gas/mips/bltu.s 7 Sep 2001 05:00:37 -0000 1.2
+++ gas/testsuite/gas/mips/bltu.s 26 Nov 2002 02:33:13 -0000
@@ -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
Index: gas/testsuite/gas/mips/branch-misc-2.d
===================================================================
RCS file: gas/testsuite/gas/mips/branch-misc-2.d
diff -N gas/testsuite/gas/mips/branch-misc-2.d
--- gas/testsuite/gas/mips/branch-misc-2.d 23 Oct 2002 03:11:47 -0000 1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,33 +0,0 @@
-#objdump: -dr --prefix-addresses --show-raw-insn
-#name: MIPS branch-misc-2
-
-# Test the branches to global symbols in current file.
-
-.*: +file format .*mips.*
-
-Disassembly of section .text:
-	\.\.\.
-	\.\.\.
-	\.\.\.
-0+003c <[^>]*> 0411fffc 	bal	00000030 <g3\+0x8>
-[ 	]*3c: R_MIPS_PC16	g1
-0+0040 <[^>]*> 00000000 	nop
-0+0044 <[^>]*> 0411fffc 	bal	00000038 <g3\+0x10>
-[ 	]*44: R_MIPS_PC16	g2
-0+0048 <[^>]*> 00000000 	nop
-0+004c <[^>]*> 0411fffc 	bal	00000040 <x\+0x4>
-[ 	]*4c: R_MIPS_PC16	g3
-0+0050 <[^>]*> 00000000 	nop
-0+0054 <[^>]*> 0411fffc 	bal	00000048 <x\+0xc>
-[ 	]*54: R_MIPS_PC16	g4
-0+0058 <[^>]*> 00000000 	nop
-0+005c <[^>]*> 0411fffc 	bal	00000050 <x\+0x14>
-[ 	]*5c: R_MIPS_PC16	g5
-0+0060 <[^>]*> 00000000 	nop
-0+0064 <[^>]*> 0411fffc 	bal	00000058 <x\+0x1c>
-[ 	]*64: R_MIPS_PC16	g6
-0+0068 <[^>]*> 00000000 	nop
-	\.\.\.
-	\.\.\.
-	\.\.\.
-	\.\.\.
Index: gas/testsuite/gas/mips/branch-misc-2.l
===================================================================
RCS file: gas/testsuite/gas/mips/branch-misc-2.l
diff -N gas/testsuite/gas/mips/branch-misc-2.l
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/mips/branch-misc-2.l 26 Nov 2002 02:33:13 -0000
@@ -0,0 +1,9 @@
+.*: 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
Index: gas/testsuite/gas/mips/branch-misc-2.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/branch-misc-2.s,v
retrieving revision 1.1
diff -u -p -r1.1 branch-misc-2.s
--- gas/testsuite/gas/mips/branch-misc-2.s 18 Sep 2002 20:50:46 -0000 1.1
+++ gas/testsuite/gas/mips/branch-misc-2.s 26 Nov 2002 02:33:13 -0000
@@ -7,6 +7,8 @@
 	.globl g5 .text
 	.globl g6 .text
 
+	.globl x1 .text
+
 	.text
 g1:
 	.space 20
@@ -29,6 +31,9 @@ g4:
 g5:
 	.space 20
 g6:
+
+	b	x1
+	b	x2
 
 # Force at least 8 (non-delay-slot) zero bytes, to make 'objdump' print ...
 	.space	8
Index: gas/testsuite/gas/mips/mips.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/mips/mips.exp,v
retrieving revision 1.50
diff -u -p -r1.50 mips.exp
--- gas/testsuite/gas/mips/mips.exp 21 Oct 2002 14:59:30 -0000 1.50
+++ gas/testsuite/gas/mips/mips.exp 26 Nov 2002 02:33:14 -0000
@@ -57,7 +57,7 @@ if { [istarget mips*-*-*] } then {
     run_dump_test "blt"
     run_dump_test "bltu"
     run_dump_test "branch-misc-1"
-    run_dump_test "branch-misc-2"
+    run_list_test "branch-misc-2" ""
 
     if $ilocks {
 	run_dump_test "div-ilocks"
Index: bfd/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* elfxx-mips.c (mips_elf_calculate_relocation): Don't divide
	addend by 4.

Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.31
diff -u -p -r1.31 elfxx-mips.c
--- bfd/elfxx-mips.c 19 Nov 2002 20:52:32 -0000 1.31
+++ bfd/elfxx-mips.c 26 Nov 2002 02:30:08 -0000
@@ -2533,7 +2533,6 @@ mips_elf_calculate_relocation (abfd, inp
     case R_MIPS_PC16:
       value = mips_elf_sign_extend (addend, 16) + symbol - p;
       overflowed_p = mips_elf_overflow_p (value, 16);
-      value = (bfd_vma) ((bfd_signed_vma) value / 4);
       break;
 
     case R_MIPS_GOT_HI16:
-- 
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]