public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] BFD, MIPS: Fix the handling of branch relocations against absolute symbols
@ 2016-07-12  0:29 Maciej W. Rozycki
  2016-07-12  0:30 ` [PATCH, RFA 1/3] BFD: Let targets handle " Maciej W. Rozycki
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Maciej W. Rozycki @ 2016-07-12  0:29 UTC (permalink / raw)
  To: binutils

Hi,

 This small patch set fixes issues with limited-range PC-relative MIPS 
branch relocations against absolute local symbols, especially on REL 
targets.  Being PC-relative they cannot be resolved in GAS and have to be 
deferred to the static link time even though the symbol is constant and 
the limited range and LSB truncation means we need to be careful and avoid 
an overflow or losing bits.  As three independent issues need addressing 
here for a complete fix, I have split the change into self-contained 
parts.

 As 1/3 pokes at bfd/reloc.c and therefore requires a general maintainer's 
approval I'm sending these changes as an RFA, although I consider input 
for 2/3 and 3/3 optional.

  Maciej

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

* [PATCH, RFA 1/3] BFD: Let targets handle relocations against absolute symbols
  2016-07-12  0:29 [PATCH 0/3] BFD, MIPS: Fix the handling of branch relocations against absolute symbols Maciej W. Rozycki
@ 2016-07-12  0:30 ` Maciej W. Rozycki
  2016-07-12  6:15   ` Alan Modra
  2016-07-12  0:31 ` [PATCH 2/3] MIPS/GAS: Keep the ISA bit in the addend of branch relocations Maciej W. Rozycki
  2016-07-12  0:31 ` [PATCH 3/3] MIPS/GAS: Don't convert PC-relative REL relocations against absolute symbols Maciej W. Rozycki
  2 siblings, 1 reply; 6+ messages in thread
From: Maciej W. Rozycki @ 2016-07-12  0:30 UTC (permalink / raw)
  To: binutils

Fix a generic BFD issue with relocations against absolute symbols, which 
are installed without using any individual relocation handler provided 
by the backend.  This causes any absolute section's addend to be lost on 
REL targets such as o32 MIPS, and also relocation-specific calculation 
adjustments are not made.

As an example assembling this program:

$ cat test.s
	.text
foo:
	b	bar
	b	baz

	.set	bar, 0x1234
$ as -EB -32 -o test-o32.o test.s
$ as -EB -n32 -o test-n32.o test.s

produces this binary code:

$ objdump -dr test-o32.o test-n32.o

test-o32.o:     file format elf32-tradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	10000000 	b	4 <foo+0x4>
			0: R_MIPS_PC16	*ABS*
   4:	00000000 	nop
   8:	1000ffff 	b	8 <foo+0x8>
			8: R_MIPS_PC16	baz
   c:	00000000 	nop

test-n32.o:     file format elf32-ntradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	10000000 	b	4 <foo+0x4>
			0: R_MIPS_PC16	*ABS*+0x1230
   4:	00000000 	nop
   8:	10000000 	b	c <foo+0xc>
			8: R_MIPS_PC16	baz-0x4
   c:	00000000 	nop
$ 

where it is clearly visible in `test-o32.o', which uses REL relocations, 
that the absolute section's addend equivalent to the value of `bar' -- a 
reference to which cannot be fully resolved at the assembly time, 
because the reference is PC-relative -- has been lost, as has been the 
relocation-specific adjustment of -4, required to take into account the 
PC+4-relative calculation made by hardware with branches and seen in the 
external symbol reference to `baz' as the `ffff' addend encoded in the 
instruction word.  In `test-n32.o', which uses RELA relocations, the 
absolute section's addend has been correctly retained.

Give precedence then in `bfd_perform_relocation' and 
`bfd_install_relocation' to any individual relocation handler the 
backend selected may have provided, while still resorting to the generic 
calculation otherwise.  This retains the semantics which we've had since 
forever or before the beginning of our repository history, and is at the 
very least compatible with `bfd_elf_generic_reloc' being used as the 
handler.

Retain the `bfd_is_und_section' check unchanged at the beginning of 
`bfd_perform_relocation' since this does not affect the semantics of the 
function.  The check returns the same `bfd_reloc_undefined' code the 
check for a null `howto' does, so swapping the two does not matter.  
Also the check is is mutually exclusive with the `bfd_is_abs_section' 
check, since a section cannot be absolute and undefined both at once, so 
swapping the two does not matter either.

With this change applied the program quoted above now has the in-place 
addend correctly calculated and installed in the field being relocated:

$ objdump -dr fixed-o32.o

fixed-o32.o:     file format elf32-tradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	1000048c 	b	1234 <bar>
			0: R_MIPS_PC16	*ABS*
   4:	00000000 	nop
   8:	1000ffff 	b	8 <foo+0x8>
			8: R_MIPS_PC16	baz
   c:	00000000 	nop
$

Add a set of MIPS tests to cover the relevant cases, including absolute 
symbols with addends, and verifying that PC-relative relocations against 
symbols concerned resolve to the same value in the final link regardless 
of whether the REL or the RELA relocation form is used.  Exclude linker 
tests though which would overflow the in-place addend on REL targets and 
use them as dump patterns for RELA targets only.

	bfd/
	* reloc.c (bfd_perform_relocation): Try the `howto' handler 
	first with relocations against absolute symbols.
	(bfd_install_relocation): Likewise.

	gas/
	* testsuite/gas/mips/mips16-branch-absolute.d: Update patterns.
	* testsuite/gas/mips/branch-absolute.d: New test.
	* testsuite/gas/mips/branch-absolute-n32.d: New test.
	* testsuite/gas/mips/branch-absolute-n64.d: New test.
	* testsuite/gas/mips/branch-absolute-addend-n32.d: New test.
	* testsuite/gas/mips/branch-absolute-addend-n64.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-n32.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-n64.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n32.d: New 
	test.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n64.d: New 
	test.
	* testsuite/gas/mips/micromips-branch-absolute.d: New test.
	* testsuite/gas/mips/micromips-branch-absolute-n32.d: New test.
	* testsuite/gas/mips/micromips-branch-absolute-n64.d: New test.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n32.d: New 
	test.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n64.d: New 
	test.
	* testsuite/gas/mips/branch-absolute.s: New test source.
	* testsuite/gas/mips/branch-absolute-addend.s: New test source.
	* testsuite/gas/mips/mips16-branch-absolute-addend.s: New test 
	source.
	* testsuite/gas/mips/micromips-branch-absolute.s: New test 
	source.
	* testsuite/gas/mips/micromips-branch-absolute-addend.s: New 
	test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/branch-absolute.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-n32.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-n64.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-addend.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-addend-n32.d: New test.
	* testsuite/ld-mips-elf/branch-absolute-addend-n64.d: New test.
	* testsuite/ld-mips-elf/micromips-branch-absolute.d: New test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-n32.d: New 
	test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-n64.d: New 
	test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-addend.d: New 
	test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-addend-n32.d: 
	New test.
	* testsuite/ld-mips-elf/micromips-branch-absolute-addend-n64.d: 
	New test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests, except 
	from `branch-absolute-addend' and 
	`micromips-branch-absolute-addend', referred indirectly only.
---
Hi,

 As I have noted in the commit description I have visually verified the 
correctness of this change against the `bfd_elf_generic_reloc' handler, 
supposedly covering the vast majority of our ELF targets and hopefully 
mimicked correctly in any target-specific relocation handlers as well.

 I have also run this change against my usual set of 162 targets, with no 
regressions.  I realise hovewer that the coverage of this area may be weak 
across targets; even with the MIPS target itself there is a single test 
case for which the reloc.c update matters in any way, which is one I have 
only recently added myself for MIPS16 branch testing and the suspicious 
output of which was actually what prompted me to look into the problem in 
the first place.  It's early enough now in the development cycle however 
for any fallout to be shaken out before the 2.28 release; or so I hope, as 
it couldn't be any earlier really anyway.

 Adding test cases for other targets would be good I believe, but I'm 
not sure which ones might be affected, i.e. actually emit relocations 
against absolute symbols.

 OK to apply then?

  Maciej

binutils-bfd-symbol-absolute-reloc-howto.diff
Index: binutils/bfd/reloc.c
===================================================================
--- binutils.orig/bfd/reloc.c	2016-07-08 21:19:05.716435174 +0100
+++ binutils/bfd/reloc.c	2016-07-08 21:19:07.988439040 +0100
@@ -586,16 +586,6 @@ bfd_perform_relocation (bfd *abfd,
   asymbol *symbol;
 
   symbol = *(reloc_entry->sym_ptr_ptr);
-  if (bfd_is_abs_section (symbol->section)
-      && output_bfd != NULL)
-    {
-      reloc_entry->address += input_section->output_offset;
-      return bfd_reloc_ok;
-    }
-
-  /* PR 17512: file: 0f67f69d.  */
-  if (howto == NULL)
-    return bfd_reloc_undefined;
 
   /* If we are not producing relocatable output, return an error if
      the symbol is not defined.  An undefined weak symbol is
@@ -608,7 +598,7 @@ bfd_perform_relocation (bfd *abfd,
   /* If there is a function supplied to handle this relocation type,
      call it.  It'll return `bfd_reloc_continue' if further processing
      can be done.  */
-  if (howto->special_function)
+  if (howto && howto->special_function)
     {
       bfd_reloc_status_type cont;
       cont = howto->special_function (abfd, reloc_entry, symbol, data,
@@ -618,6 +608,17 @@ bfd_perform_relocation (bfd *abfd,
 	return cont;
     }
 
+  if (bfd_is_abs_section (symbol->section)
+      && output_bfd != NULL)
+    {
+      reloc_entry->address += input_section->output_offset;
+      return bfd_reloc_ok;
+    }
+
+  /* PR 17512: file: 0f67f69d.  */
+  if (howto == NULL)
+    return bfd_reloc_undefined;
+
   /* Is the address of the relocation really within the section?
      Include the size of the reloc in the test for out of range addresses.
      PR 17512: file: c146ab8b, 46dff27f, 38e53ebf.  */
@@ -981,16 +982,11 @@ bfd_install_relocation (bfd *abfd,
   bfd_byte *data;
 
   symbol = *(reloc_entry->sym_ptr_ptr);
-  if (bfd_is_abs_section (symbol->section))
-    {
-      reloc_entry->address += input_section->output_offset;
-      return bfd_reloc_ok;
-    }
 
   /* If there is a function supplied to handle this relocation type,
      call it.  It'll return `bfd_reloc_continue' if further processing
      can be done.  */
-  if (howto->special_function)
+  if (howto && howto->special_function)
     {
       bfd_reloc_status_type cont;
 
@@ -1005,6 +1001,15 @@ bfd_install_relocation (bfd *abfd,
 	return cont;
     }
 
+  if (bfd_is_abs_section (symbol->section))
+    {
+      reloc_entry->address += input_section->output_offset;
+      return bfd_reloc_ok;
+    }
+
+  /* No need to check for howto != NULL if !bfd_is_abs_section as
+     it will have been checked in `bfd_perform_relocation already'.  */
+
   /* Is the address of the relocation really within the section?  */
   octets = reloc_entry->address * bfd_octets_per_byte (abfd);
   if (octets + bfd_get_reloc_size (howto)
Index: binutils/gas/testsuite/gas/mips/branch-absolute-addend-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/branch-absolute-addend-n32.d	2016-07-08 21:19:08.016759122 +0100
@@ -0,0 +1,25 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch to absolute expression with addend (n32)
+#as: -n32 -march=from-abi
+#source: branch-absolute-addend.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 10000000 	b	00001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04110000 	bal	0000100c <foo\+0xc>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04100000 	bltzal	zero,00001014 <foo\+0x14>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 10400000 	beqz	v0,0000101c <foo\+0x1c>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 14400000 	bnez	v0,00001024 <foo\+0x24>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/branch-absolute-addend-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/branch-absolute-addend-n64.d	2016-07-08 21:19:08.028846795 +0100
@@ -0,0 +1,35 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch to absolute expression with addend (n64)
+#as: -64 -march=from-abi
+#source: branch-absolute-addend.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 10000000 	b	0000000000001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04110000 	bal	000000000000100c <foo\+0xc>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04100000 	bltzal	zero,0000000000001014 <foo\+0x14>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 10400000 	beqz	v0,000000000000101c <foo\+0x1c>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 14400000 	bnez	v0,0000000000001024 <foo\+0x24>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 00000000 	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/branch-absolute-addend.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/branch-absolute-addend.s	2016-07-08 21:19:08.042994873 +0100
@@ -0,0 +1,20 @@
+	.text
+
+	.space	0x1000
+
+	.globl	foo
+	.ent	foo
+foo:
+	b	bar + 0x1234
+	bal	bar + 0x1234
+	bltzal	$0, bar + 0x1234
+	beqz	$2, bar + 0x1234
+	bnez	$2, bar + 0x1234
+	nop
+	.end	foo
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	4, 0
+	.space	16
+
+	.set	bar, 0x12345678
Index: binutils/gas/testsuite/gas/mips/branch-absolute-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/branch-absolute-n32.d	2016-07-08 21:19:08.051045708 +0100
@@ -0,0 +1,25 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch to absolute expression (n32)
+#as: -n32 -march=from-abi
+#source: branch-absolute.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 10000000 	b	00001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04110000 	bal	0000100c <foo\+0xc>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04100000 	bltzal	zero,00001014 <foo\+0x14>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 10400000 	beqz	v0,0000101c <foo\+0x1c>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 14400000 	bnez	v0,00001024 <foo\+0x24>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/branch-absolute-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/branch-absolute-n64.d	2016-07-08 21:19:08.072163870 +0100
@@ -0,0 +1,35 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch to absolute expression (n64)
+#as: -64 -march=from-abi
+#source: branch-absolute.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 10000000 	b	0000000000001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04110000 	bal	000000000000100c <foo\+0xc>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04100000 	bltzal	zero,0000000000001014 <foo\+0x14>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 10400000 	beqz	v0,000000000000101c <foo\+0x1c>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 14400000 	bnez	v0,0000000000001024 <foo\+0x24>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 00000000 	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/branch-absolute.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/branch-absolute.d	2016-07-08 21:24:21.781606132 +0100
@@ -0,0 +1,24 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch to absolute expression
+#as: -32
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 1000048c 	b	00002234 <bar\+0x1000>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 0411048c 	bal	0000223c <bar\+0x1008>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 0410048c 	bltzal	zero,00002244 <bar\+0x1010>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 1040048c 	beqz	v0,0000224c <bar\+0x1018>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 1440048c 	bnez	v0,00002254 <bar\+0x1020>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 00000000 	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/branch-absolute.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/branch-absolute.s	2016-07-08 21:19:08.085244286 +0100
@@ -0,0 +1,20 @@
+	.text
+
+	.space	0x1000
+
+	.globl	foo
+	.ent	foo
+foo:
+	b	bar
+	bal	bar
+	bltzal	$0, bar
+	beqz	$2, bar
+	bnez	$2, bar
+	nop
+	.end	foo
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	4, 0
+	.space	16
+
+	.set	bar, 0x1234
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n32.d	2016-07-08 21:19:08.099329070 +0100
@@ -0,0 +1,26 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS branch to absolute expression with addend (n32)
+#as: -n32 -march=from-abi
+#source: micromips-branch-absolute-addend.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 9400 0000 	b	00001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 4060 0000 	bal	0000100a <foo\+0xa>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 4020 0000 	bltzal	zero,00001012 <foo\+0x12>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 9402 0000 	beqz	v0,0000101a <foo\+0x1a>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> b402 0000 	bnez	v0,00001020 <foo\+0x20>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 0c00      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n64.d	2016-07-08 21:19:08.102353406 +0100
@@ -0,0 +1,36 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS branch to absolute expression with addend (n64)
+#as: -64 -march=from-abi
+#source: micromips-branch-absolute-addend.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 9400 0000 	b	0000000000001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 4060 0000 	bal	000000000000100a <foo\+0xa>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 4020 0000 	bltzal	zero,0000000000001012 <foo\+0x12>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 9402 0000 	beqz	v0,000000000000101a <foo\+0x1a>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> b402 0000 	bnez	v0,0000000000001020 <foo\+0x20>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 0c00      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend.s	2016-07-08 21:19:08.107428656 +0100
@@ -0,0 +1,22 @@
+	.text
+
+	.space	0x1000
+
+	.globl	foo
+	.ent	foo
+	.set	micromips
+foo:
+	b	bar + 0x1234
+	bal	bar + 0x1234
+	bltzal	$0, bar + 0x1234
+	beqz	$2, bar + 0x1234
+	bnez	$2, bar + 0x1234
+	nop
+	.set	nomips16
+	.end	foo
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	4, 0
+	.space	16
+
+	.set	bar, 0x12345679
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-n32.d	2016-07-08 21:19:08.110485694 +0100
@@ -0,0 +1,26 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS branch to absolute expression (n32)
+#as: -n32 -march=from-abi
+#source: micromips-branch-absolute.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 9400 0000 	b	00001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 4060 0000 	bal	0000100a <foo\+0xa>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 4020 0000 	bltzal	zero,00001012 <foo\+0x12>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 9402 0000 	beqz	v0,0000101a <foo\+0x1a>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> b402 0000 	bnez	v0,00001020 <foo\+0x20>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 0c00      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-n64.d	2016-07-08 21:19:08.118543950 +0100
@@ -0,0 +1,36 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS branch to absolute expression (n64)
+#as: -64 -march=from-abi
+#source: micromips-branch-absolute.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 9400 0000 	b	0000000000001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 4060 0000 	bal	000000000000100a <foo\+0xa>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 4020 0000 	bltzal	zero,0000000000001012 <foo\+0x12>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 9402 0000 	beqz	v0,000000000000101a <foo\+0x1a>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> b402 0000 	bnez	v0,0000000000001020 <foo\+0x20>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 0c00      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute.d	2016-07-08 21:19:08.126604399 +0100
@@ -0,0 +1,25 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS branch to absolute expression
+#as: -32
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 9400 fffe 	b	00001000 <foo>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 4060 fffe 	bal	00001006 <foo\+0x6>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 4020 fffe 	bltzal	zero,0000100e <foo\+0xe>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 9402 fffe 	beqz	v0,00001016 <foo\+0x16>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> b402 fffe 	bnez	v0,0000101c <foo\+0x1c>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 0c00      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute.s	2016-07-08 21:19:08.134684465 +0100
@@ -0,0 +1,22 @@
+	.text
+
+	.space	0x1000
+
+	.globl	foo
+	.ent	foo
+	.set	micromips
+foo:
+	b	bar
+	bal	bar
+	bltzal	$0, bar
+	beqz	$2, bar
+	bnez	$2, bar
+	nop
+	.set	nomips16
+	.end	foo
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	4, 0
+	.space	16
+
+	.set	bar, 0x1235
Index: binutils/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips.exp	2016-07-08 21:19:05.750893387 +0100
+++ binutils/gas/testsuite/gas/mips/mips.exp	2016-07-08 21:19:08.139787584 +0100
@@ -611,6 +611,13 @@ if { [istarget mips*-*-vxworks*] } {
 	run_dump_test "branch-local-n32-1"
 	run_dump_test "branch-local-n64-1"
     }
+    run_dump_test "branch-absolute"
+    if $has_newabi {
+	run_dump_test "branch-absolute-n32"
+	run_dump_test "branch-absolute-addend-n32"
+	run_dump_test "branch-absolute-n64"
+	run_dump_test "branch-absolute-addend-n64"
+    }
 
     run_dump_test_arches "nal-1" [mips_arch_list_matching mips1 !micromips]
     run_dump_test_arches "nal-2" [mips_arch_list_matching mips1 !micromips]
@@ -1273,6 +1280,13 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "micromips-branch-delay"
     run_dump_test "micromips-warn-branch-delay"
     run_dump_test "micromips-warn-branch-delay-1"
+    run_dump_test "micromips-branch-absolute"
+    if $has_newabi {
+	run_dump_test "micromips-branch-absolute-n32"
+	run_dump_test "micromips-branch-absolute-addend-n32"
+	run_dump_test "micromips-branch-absolute-n64"
+	run_dump_test "micromips-branch-absolute-addend-n64"
+    }
     run_dump_test "micromips-b16"
     run_list_test "micromips-ill"
 
@@ -1379,6 +1393,12 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "mips16-branch-addend-2"
     run_dump_test "mips16-branch-addend-3"
     run_dump_test "mips16-branch-absolute"
+    if $has_newabi {
+	run_dump_test "mips16-branch-absolute-n32"
+	run_dump_test "mips16-branch-absolute-addend-n32"
+	run_dump_test "mips16-branch-absolute-n64"
+	run_dump_test "mips16-branch-absolute-addend-n64"
+    }
     run_dump_test "mips16-absolute-reloc-0"
     run_dump_test "mips16-absolute-reloc-1"
     run_dump_test "mips16-absolute-reloc-2"
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n32.d	2016-07-08 21:19:08.148872892 +0100
@@ -0,0 +1,21 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 branch to absolute expression with addend (n32)
+#as: -n32 -march=from-abi
+#source: mips16-branch-absolute-addend.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> f000 1000 	b	00001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> f000 6000 	bteqz	00001008 <foo\+0x8>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> f000 6100 	btnez	0000100c <foo\+0xc>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> f000 2200 	beqz	v0,00001010 <foo\+0x10>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> f000 2a00 	bnez	v0,00001014 <foo\+0x14>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 6500      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n64.d	2016-07-08 21:19:08.173194587 +0100
@@ -0,0 +1,31 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 branch to absolute expression with addend (n64)
+#as: -64 -march=from-abi
+#source: mips16-branch-absolute-addend.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> f000 1000 	b	0000000000001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> f000 6000 	bteqz	0000000000001008 <foo\+0x8>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> f000 6100 	btnez	000000000000100c <foo\+0xc>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> f000 2200 	beqz	v0,0000000000001010 <foo\+0x10>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> f000 2a00 	bnez	v0,0000000000001014 <foo\+0x14>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[0-9a-f]+ <[^>]*> 6500      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend.s	2016-07-08 21:19:08.175254369 +0100
@@ -0,0 +1,22 @@
+	.text
+
+	.space	0x1000
+
+	.globl	foo
+	.ent	foo
+	.set	mips16
+foo:
+	b	bar + 0x1234
+	bteqz	bar + 0x1234
+	btnez	bar + 0x1234
+	beqz	$2, bar + 0x1234
+	bnez	$2, bar + 0x1234
+	nop
+	.set	nomips16
+	.end	foo
+
+# Force some (non-delay-slot) zero bytes, to make 'objdump' print ...
+	.align	4, 0
+	.space	16
+
+	.set	bar, 0x12345679
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-n32.d	2016-07-08 21:19:08.206452288 +0100
@@ -0,0 +1,21 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 branch to absolute expression (n32)
+#as: -n32 -march=from-abi
+#source: mips16-branch-absolute.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> f000 1000 	b	00001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> f000 6000 	bteqz	00001008 <foo\+0x8>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> f000 6100 	btnez	0000100c <foo\+0xc>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> f000 2200 	beqz	v0,00001010 <foo\+0x10>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> f000 2a00 	bnez	v0,00001014 <foo\+0x14>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 6500      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-n64.d	2016-07-08 21:19:08.224649016 +0100
@@ -0,0 +1,31 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 branch to absolute expression (n64)
+#as: -64 -march=from-abi
+#source: mips16-branch-absolute.s
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> f000 1000 	b	0000000000001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> f000 6000 	bteqz	0000000000001008 <foo\+0x8>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> f000 6100 	btnez	000000000000100c <foo\+0xc>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> f000 2200 	beqz	v0,0000000000001010 <foo\+0x10>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> f000 2a00 	bnez	v0,0000000000001014 <foo\+0x14>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[0-9a-f]+ <[^>]*> 6500      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips16-branch-absolute.d	2016-07-08 21:19:05.786155267 +0100
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute.d	2016-07-08 21:19:08.233708718 +0100
@@ -6,15 +6,15 @@
 
 Disassembly of section \.text:
 	\.\.\.
-[0-9a-f]+ <[^>]*> f000 1000 	b	00001004 <foo\+0x4>
+[0-9a-f]+ <[^>]*> f101 1018 	b	00002234 <bar\+0x1000>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f000 6000 	bteqz	00001008 <foo\+0x8>
+[0-9a-f]+ <[^>]*> f101 6018 	bteqz	00002238 <bar\+0x1004>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f000 6100 	btnez	0000100c <foo\+0xc>
+[0-9a-f]+ <[^>]*> f101 6118 	btnez	0000223c <bar\+0x1008>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f000 2200 	beqz	v0,00001010 <foo\+0x10>
+[0-9a-f]+ <[^>]*> f101 2218 	beqz	v0,00002240 <bar\+0x100c>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f000 2a00 	bnez	v0,00001014 <foo\+0x14>
+[0-9a-f]+ <[^>]*> f101 2a18 	bnez	v0,00002244 <bar\+0x1010>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
 [0-9a-f]+ <[^>]*> 6500      	nop
 	\.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/branch-absolute-addend-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/branch-absolute-addend-n32.d	2016-07-08 21:19:08.270359599 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS link branch to absolute expression with addend (n32)
+#source: ../../../gas/testsuite/gas/mips/branch-absolute-addend.s
+#as: -EB -n32 -march=from-abi
+#ld: -EB -Ttext 0x12340000 -e foo
+#dump: branch-absolute-addend.d
Index: binutils/ld/testsuite/ld-mips-elf/branch-absolute-addend-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/branch-absolute-addend-n64.d	2016-07-08 21:19:08.289569620 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS link branch to absolute expression with addend (n64)
+#source: ../../../gas/testsuite/gas/mips/branch-absolute-addend.s
+#as: -EB -64 -march=from-abi
+#ld: -EB -Ttext 0x12340000 -e foo
+#dump: branch-absolute-addend.d
Index: binutils/ld/testsuite/ld-mips-elf/branch-absolute-addend.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/branch-absolute-addend.d	2016-07-08 21:19:08.298656112 +0100
@@ -0,0 +1,21 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS link branch to absolute expression with addend
+#source: ../../../gas/testsuite/gas/mips/branch-absolute-addend.s
+#as: -EB -32
+#ld: -EB -Ttext 0x12340000 -e foo
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 1000162a 	b	0*123468ac <bar\+0x1234>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04111628 	bal	0*123468ac <bar\+0x1234>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04101626 	bltzal	zero,0*123468ac <bar\+0x1234>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 10401624 	beqz	v0,0*123468ac <bar\+0x1234>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 14401622 	bnez	v0,0*123468ac <bar\+0x1234>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+	\.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/branch-absolute-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/branch-absolute-n32.d	2016-07-08 21:19:08.304709036 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS link branch to absolute expression (n32)
+#source: ../../../gas/testsuite/gas/mips/branch-absolute.s
+#as: -EB -n32 -march=from-abi
+#ld: -EB -Ttext 0 -e foo
+#dump: branch-absolute.d
Index: binutils/ld/testsuite/ld-mips-elf/branch-absolute-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/branch-absolute-n64.d	2016-07-08 21:19:08.306771300 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS link branch to absolute expression (n64)
+#source: ../../../gas/testsuite/gas/mips/branch-absolute.s
+#as: -EB -64 -march=from-abi
+#ld: -EB -Ttext 0 -e foo
+#dump: branch-absolute.d
Index: binutils/ld/testsuite/ld-mips-elf/branch-absolute.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/branch-absolute.d	2016-07-08 21:19:08.315013401 +0100
@@ -0,0 +1,21 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS link branch to absolute expression
+#source: ../../../gas/testsuite/gas/mips/branch-absolute.s
+#as: -EB -32
+#ld: -EB -Ttext 0 -e foo
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 1000008c 	b	0+001234 <bar>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 0411008a 	bal	0+001234 <bar>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 04100088 	bltzal	zero,0+001234 <bar>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 10400086 	beqz	v0,0+001234 <bar>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 14400084 	bnez	v0,0+001234 <bar>
+[0-9a-f]+ <[^>]*> 00000000 	nop
+	\.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-addend-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-addend-n32.d	2016-07-08 21:19:08.317029262 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS link branch to absolute expression with addend (n32)
+#source: ../../../gas/testsuite/gas/mips/micromips-branch-absolute-addend.s
+#as: -EB -n32 -march=from-abi
+#ld: -EB -Ttext 0x12340000 -e foo
+#dump: micromips-branch-absolute-addend.d
Index: binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-addend-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-addend-n64.d	2016-07-08 21:19:08.319061226 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS link branch to absolute expression with addend (n64)
+#source: ../../../gas/testsuite/gas/mips/micromips-branch-absolute-addend.s
+#as: -EB -64 -march=from-abi
+#ld: -EB -Ttext 0x12340000 -e foo
+#dump: micromips-branch-absolute-addend.d
Index: binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-addend.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-addend.d	2016-07-08 21:19:08.321072575 +0100
@@ -0,0 +1,22 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS link branch to absolute expression with addend
+#source: ../../../gas/testsuite/gas/mips/micromips-branch-absolute-addend.s
+#as: -EB -32
+#ld: -EB -Ttext 0x12340000 -e foo
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 9400 2c54 	b	0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 4060 2c51 	bal	0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 4020 2c4d 	bltzal	zero,0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 9402 2c49 	beqz	v0,0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> b402 2c46 	bnez	v0,0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 0c00      	nop
+	\.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-n32.d	2016-07-08 21:19:08.324184902 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS link branch to absolute expression (n32)
+#source: ../../../gas/testsuite/gas/mips/micromips-branch-absolute.s
+#as: -EB -n32 -march=from-abi
+#ld: -EB -Ttext 0 -e foo
+#dump: micromips-branch-absolute.d
Index: binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute-n64.d	2016-07-08 21:19:08.346504845 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS link branch to absolute expression (n64)
+#source: ../../../gas/testsuite/gas/mips/micromips-branch-absolute.s
+#as: -EB -64 -march=from-abi
+#ld: -EB -Ttext 0 -e foo
+#dump: micromips-branch-absolute.d
Index: binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/micromips-branch-absolute.d	2016-07-08 21:19:08.355591900 +0100
@@ -0,0 +1,22 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS link branch to absolute expression
+#source: ../../../gas/testsuite/gas/mips/micromips-branch-absolute.s
+#as: -EB -32
+#ld: -EB -Ttext 0 -e foo
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 9400 0118 	b	0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 4060 0115 	bal	0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 4020 0111 	bltzal	zero,0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 9402 010d 	beqz	v0,0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> b402 010a 	bnez	v0,0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 0c00      	nop
+	\.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
--- binutils.orig/ld/testsuite/ld-mips-elf/mips-elf.exp	2016-07-08 21:19:05.830845860 +0100
+++ binutils/ld/testsuite/ld-mips-elf/mips-elf.exp	2016-07-08 21:19:08.358664315 +0100
@@ -143,12 +143,33 @@ run_dump_test "mips16-1"
 # MIPS branch offset final link checking.
 run_dump_test "branch-misc-1"
 run_dump_test "branch-misc-2"
+run_dump_test "branch-absolute" [list [list ld $abi_ldflags(o32)]]
+if $has_newabi {
+    run_dump_test "branch-absolute-n32" [list [list ld $abi_ldflags(n32)]]
+    run_dump_test "branch-absolute-addend-n32" \
+					[list [list ld $abi_ldflags(n32)]]
+    run_dump_test "branch-absolute-n64" [list [list ld $abi_ldflags(n64)]]
+    run_dump_test "branch-absolute-addend-n64" \
+					[list [list ld $abi_ldflags(n64)]]
+}
 
 run_dump_test "mips16-branch-2" [list [list ld $abi_ldflags(o32)]]
 run_dump_test "mips16-branch-3" [list [list ld $abi_ldflags(o32)]]
 run_dump_test "mips16-branch-addend-2" [list [list ld $abi_ldflags(o32)]]
 run_dump_test "mips16-branch-addend-3" [list [list ld $abi_ldflags(o32)]]
 
+run_dump_test "micromips-branch-absolute" [list [list ld $abi_ldflags(o32)]]
+if $has_newabi {
+    run_dump_test "micromips-branch-absolute-n32" \
+					[list [list ld $abi_ldflags(n32)]]
+    run_dump_test "micromips-branch-absolute-addend-n32" \
+					[list [list ld $abi_ldflags(n32)]]
+    run_dump_test "micromips-branch-absolute-n64" \
+					[list [list ld $abi_ldflags(n64)]]
+    run_dump_test "micromips-branch-absolute-addend-n64" \
+					[list [list ld $abi_ldflags(n64)]]
+}
+
 # Jalx test
 run_dump_test "jalx-1"
 

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

* [PATCH 2/3] MIPS/GAS: Keep the ISA bit in the addend of branch relocations
  2016-07-12  0:29 [PATCH 0/3] BFD, MIPS: Fix the handling of branch relocations against absolute symbols Maciej W. Rozycki
  2016-07-12  0:30 ` [PATCH, RFA 1/3] BFD: Let targets handle " Maciej W. Rozycki
@ 2016-07-12  0:31 ` Maciej W. Rozycki
  2016-07-12  0:31 ` [PATCH 3/3] MIPS/GAS: Don't convert PC-relative REL relocations against absolute symbols Maciej W. Rozycki
  2 siblings, 0 replies; 6+ messages in thread
From: Maciej W. Rozycki @ 2016-07-12  0:31 UTC (permalink / raw)
  To: binutils

Correct a problem with the ISA bit being stripped from the addend of 
compressed branch relocations, affecting RELA targets.  It has been 
there since microMIPS support has been added, with:

commit df58fc944dbc6d5efd8d3826241b64b6af22f447
Author: Richard Sandiford <rdsandiford@googlemail.com>
Date:   Sun Jul 24 14:20:15 2011 +0000

<https://sourceware.org/ml/binutils/2011-07/msg00198.html>, ("MIPS: 
microMIPS ASE support") and R_MICROMIPS_PC7_S1, R_MICROMIPS_PC10_S1 and 
R_MICROMIPS_PC16_S1 relocations originally affected, and the 
R_MIPS16_PC16_S1 relocation recently added with commit c9775dde3277 
("MIPS16: Add R_MIPS16_PC16_S1 branch relocation support") actually 
triggering a linker error, due to its heightened processing strictness 
level:

$ cat test.s
	.text
	.set	mips16
foo:
	b	bar

	.set	bar, 0x1235
	.align	4, 0
$ as -EB -n32 -o test.o test.s
$ objdump -dr test.o

test.o:     file format elf32-ntradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	f000 1000 	b	4 <foo+0x4>
			0: R_MIPS16_PC16_S1	*ABS*+0x1230
	...
$ ld -melf32btsmipn32 -Ttext 0 -e 0 -o test test.o
test.o: In function `foo':
(.text+0x0): Branch to a non-instruction-aligned address
$

This is because the ISA bit of the branch target does not match the ISA
bit of the referring branch, hardwired to 1 of course.

Retain the ISA bit then, so that the linker knows this is really MIPS16
code referred:

$ objdump -dr fixed.o

fixed.o:     file format elf32-ntradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	f000 1000 	b	4 <foo+0x4>
			0: R_MIPS16_PC16_S1	*ABS*+0x1231
	...
$ ld -melf32btsmipn32 -Ttext 0 -e 0 -o fixed fixed.o
$

Add a set of MIPS16 tests to cover the relevant cases, excluding linker 
tests though which would overflow the in-place addend on REL targets and 
use them as dump patterns for RELA targets only.

	gas/
	* config/tc-mips.c (md_apply_fix) <BFD_RELOC_MIPS16_16_PCREL_S1>
	<BFD_RELOC_MICROMIPS_7_PCREL_S1, BFD_RELOC_MICROMIPS_10_PCREL_S1>
	<BFD_RELOC_MICROMIPS_16_PCREL_S1>: Keep the ISA bit in the 
	addend calculated.
	* testsuite/gas/mips/mips16-branch-absolute.s: Set the ISA bit 
	in `bar', export `foo'.
	* testsuite/gas/mips/mips16-branch-absolute.d: Adjust 
	accordingly.
	* testsuite/gas/mips/mips16-branch-absolute-n32.d: Likewise.
	* testsuite/gas/mips/mips16-branch-absolute-n64.d: Likewise.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n32.d: 
	Likewise.
	* testsuite/gas/mips/mips16-branch-absolute-addend-n64.d: 
	Likewise.

	ld/
	* testsuite/ld-mips-elf/mips16-branch-absolute.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-n32.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-n64.d: New test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-addend.d: New 
	test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d: New 
	test.
	* testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d: New 
	test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests, except 
	from `mips16-branch-absolute' and 
	`mips16-branch-absolute-addend', referred indirectly only.
---
Hi,

 This has been split off from a later change, one of those I originally 
intended to include with 2.27, so that full test suite coverage can be 
provided for the issues with branch relocations being fixed.

 We should have retained the ISA bit in the addend from the beginning, but 
I gather the matter has been missed as microMIPS support was being added, 
as its use has been almost exclusively limited to the o32 ABI which uses 
REL relocations and therefore loses the ISA bit anyway, as there is no 
room for it in the in-place addend.  I think this all has to be sorted out 
finally, also for microMIPS relocations, to avoid the situation where a 
branch to opposite-ISA code is silently accepted where regular and 
compressed MIPS code has been interlinked by accident.  This is especially 
important with the prospect of GCC using branches for tail calls in MIPS16 
code, but also applies to handcoded regular and compressed MIPS assembly 
code that may be out there.

 This is the first step.  I'll push it once 1/3 has been approved.

  Maciej

binutils-mips-gas-branch-addend-isa-bit.diff
Index: binutils/gas/config/tc-mips.c
===================================================================
--- binutils.orig/gas/config/tc-mips.c	2016-07-08 21:48:29.502180936 +0100
+++ binutils/gas/config/tc-mips.c	2016-07-08 21:50:21.263286460 +0100
@@ -15188,15 +15188,7 @@ md_apply_fix (fixS *fixP, valueT *valP, 
     case BFD_RELOC_MICROMIPS_7_PCREL_S1:
     case BFD_RELOC_MICROMIPS_10_PCREL_S1:
     case BFD_RELOC_MICROMIPS_16_PCREL_S1:
-      /* We adjust the offset back to even.  */
-      if ((*valP & 0x1) != 0)
-	--(*valP);
-
-      if (! fixP->fx_done)
-	break;
-
-      /* Should never visit here, because we keep the relocation.  */
-      abort ();
+      gas_assert (!fixP->fx_done);
       break;
 
     case BFD_RELOC_VTABLE_INHERIT:
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n32.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n32.d	2016-07-08 21:48:29.507258747 +0100
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n32.d	2016-07-08 21:50:21.317347527 +0100
@@ -8,14 +8,14 @@
 Disassembly of section \.text:
 	\.\.\.
 [0-9a-f]+ <[^>]*> f000 1000 	b	00001004 <foo\+0x4>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> f000 6000 	bteqz	00001008 <foo\+0x8>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> f000 6100 	btnez	0000100c <foo\+0xc>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> f000 2200 	beqz	v0,00001010 <foo\+0x10>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> f000 2a00 	bnez	v0,00001014 <foo\+0x14>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 6500      	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n64.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n64.d	2016-07-08 21:48:29.511308434 +0100
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend-n64.d	2016-07-08 21:50:21.338480563 +0100
@@ -8,24 +8,24 @@
 Disassembly of section \.text:
 	\.\.\.
 [0-9a-f]+ <[^>]*> f000 1000 	b	0000000000001004 <foo\+0x4>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> f000 6000 	bteqz	0000000000001008 <foo\+0x8>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> f000 6100 	btnez	000000000000100c <foo\+0xc>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> f000 2200 	beqz	v0,0000000000001010 <foo\+0x10>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> f000 2a00 	bnez	v0,0000000000001014 <foo\+0x14>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a8
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 6500      	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-n32.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips16-branch-absolute-n32.d	2016-07-08 21:48:29.516353361 +0100
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-n32.d	2016-07-08 21:50:21.358614767 +0100
@@ -8,14 +8,14 @@
 Disassembly of section \.text:
 	\.\.\.
 [0-9a-f]+ <[^>]*> f000 1000 	b	00001004 <foo\+0x4>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> f000 6000 	bteqz	00001008 <foo\+0x8>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> f000 6100 	btnez	0000100c <foo\+0xc>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> f000 2200 	beqz	v0,00001010 <foo\+0x10>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> f000 2a00 	bnez	v0,00001014 <foo\+0x14>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 6500      	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-n64.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips16-branch-absolute-n64.d	2016-07-08 21:48:29.520452441 +0100
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-n64.d	2016-07-08 21:50:21.369737541 +0100
@@ -8,24 +8,24 @@
 Disassembly of section \.text:
 	\.\.\.
 [0-9a-f]+ <[^>]*> f000 1000 	b	0000000000001004 <foo\+0x4>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> f000 6000 	bteqz	0000000000001008 <foo\+0x8>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> f000 6100 	btnez	000000000000100c <foo\+0xc>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> f000 2200 	beqz	v0,0000000000001010 <foo\+0x10>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> f000 2a00 	bnez	v0,0000000000001014 <foo\+0x14>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 6500      	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips16-branch-absolute.d	2016-07-08 21:48:29.572209300 +0100
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute.d	2016-07-08 21:50:21.385988871 +0100
@@ -6,15 +6,15 @@
 
 Disassembly of section \.text:
 	\.\.\.
-[0-9a-f]+ <[^>]*> f101 1018 	b	00002234 <bar\+0x1000>
+[0-9a-f]+ <[^>]*> f101 1018 	b	00002234 <bar\+0xfff>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f101 6018 	bteqz	00002238 <bar\+0x1004>
+[0-9a-f]+ <[^>]*> f101 6018 	bteqz	00002238 <bar\+0x1003>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f101 6118 	btnez	0000223c <bar\+0x1008>
+[0-9a-f]+ <[^>]*> f101 6118 	btnez	0000223c <bar\+0x1007>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f101 2218 	beqz	v0,00002240 <bar\+0x100c>
+[0-9a-f]+ <[^>]*> f101 2218 	beqz	v0,00002240 <bar\+0x100b>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f101 2a18 	bnez	v0,00002244 <bar\+0x1010>
+[0-9a-f]+ <[^>]*> f101 2a18 	bnez	v0,00002244 <bar\+0x100f>
 [ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
 [0-9a-f]+ <[^>]*> 6500      	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute.s
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips16-branch-absolute.s	2016-07-08 21:48:29.535663794 +0100
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute.s	2016-07-08 21:50:21.390058321 +0100
@@ -2,6 +2,7 @@
 
 	.space	0x1000
 
+	.globl	foo
 	.ent	foo
 	.set	mips16
 foo:
@@ -18,4 +19,4 @@
 	.align	4, 0
 	.space	16
 
-	.set	bar, 0x1234
+	.set	bar, 0x1235
Index: binutils/ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
--- binutils.orig/ld/testsuite/ld-mips-elf/mips-elf.exp	2016-07-08 21:48:29.584338779 +0100
+++ binutils/ld/testsuite/ld-mips-elf/mips-elf.exp	2016-07-08 21:50:21.415276575 +0100
@@ -157,6 +157,16 @@ run_dump_test "mips16-branch-2" [list [l
 run_dump_test "mips16-branch-3" [list [list ld $abi_ldflags(o32)]]
 run_dump_test "mips16-branch-addend-2" [list [list ld $abi_ldflags(o32)]]
 run_dump_test "mips16-branch-addend-3" [list [list ld $abi_ldflags(o32)]]
+if $has_newabi {
+    run_dump_test "mips16-branch-absolute-n32" \
+					[list [list ld $abi_ldflags(n32)]]
+    run_dump_test "mips16-branch-absolute-addend-n32" \
+					[list [list ld $abi_ldflags(n32)]]
+    run_dump_test "mips16-branch-absolute-n64" \
+					[list [list ld $abi_ldflags(n64)]]
+    run_dump_test "mips16-branch-absolute-addend-n64" \
+					[list [list ld $abi_ldflags(n64)]]
+}
 
 run_dump_test "micromips-branch-absolute" [list [list ld $abi_ldflags(o32)]]
 if $has_newabi {
Index: binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n32.d	2016-07-08 21:50:21.428383488 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression with addend (n32)
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute-addend.s
+#as: -EB -n32 -march=from-abi
+#ld: -EB -Ttext 0x12340000 -e foo
+#dump: mips16-branch-absolute-addend.d
Index: binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend-n64.d	2016-07-08 21:50:21.430396892 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression with addend (n64)
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute-addend.s
+#as: -EB -64 -march=from-abi
+#ld: -EB -Ttext 0x12340000 -e foo
+#dump: mips16-branch-absolute-addend.d
Index: binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-addend.d	2016-07-08 21:50:21.432411946 +0100
@@ -0,0 +1,17 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression with addend
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute-addend.s
+#as: -EB -32
+#ld: -EB -Ttext 0x12340000 -e foo
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> f445 1014 	b	0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> f445 6012 	bteqz	0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> f445 6110 	btnez	0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> f445 220e 	beqz	v0,0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> f445 2a0c 	bnez	v0,0*123468ac <bar\+0x1233>
+[0-9a-f]+ <[^>]*> 6500      	nop
+	\.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n32.d	2016-07-08 21:50:21.456834554 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression (n32)
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute.s
+#as: -EB -n32 -march=from-abi
+#ld: -EB -Ttext 0 -e foo
+#dump: mips16-branch-absolute.d
Index: binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute-n64.d	2016-07-08 21:50:21.466954433 +0100
@@ -0,0 +1,6 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression (n64)
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute.s
+#as: -EB -64 -march=from-abi
+#ld: -EB -Ttext 0 -e foo
+#dump: mips16-branch-absolute.d
Index: binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/ld/testsuite/ld-mips-elf/mips16-branch-absolute.d	2016-07-08 21:50:21.469009153 +0100
@@ -0,0 +1,17 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 link branch to absolute expression
+#source: ../../../gas/testsuite/gas/mips/mips16-branch-absolute.s
+#as: -EB -32
+#ld: -EB -Ttext 0 -e foo
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> f100 1018 	b	0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> f100 6016 	bteqz	0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> f100 6114 	btnez	0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> f100 2212 	beqz	v0,0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> f100 2a10 	bnez	v0,0+001234 <foo\+0x234>
+[0-9a-f]+ <[^>]*> 6500      	nop
+	\.\.\.

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

* [PATCH 3/3] MIPS/GAS: Don't convert PC-relative REL relocations against absolute symbols
  2016-07-12  0:29 [PATCH 0/3] BFD, MIPS: Fix the handling of branch relocations against absolute symbols Maciej W. Rozycki
  2016-07-12  0:30 ` [PATCH, RFA 1/3] BFD: Let targets handle " Maciej W. Rozycki
  2016-07-12  0:31 ` [PATCH 2/3] MIPS/GAS: Keep the ISA bit in the addend of branch relocations Maciej W. Rozycki
@ 2016-07-12  0:31 ` Maciej W. Rozycki
  2 siblings, 0 replies; 6+ messages in thread
From: Maciej W. Rozycki @ 2016-07-12  0:31 UTC (permalink / raw)
  To: binutils

Don't convert PC-relative REL relocations against absolute symbols to 
section-relative references and retain the original symbol reference 
instead.  Offsets into the absolute section may overflow the limited 
range of their in-place addend field, causing an assembly error, e.g.:

$ cat test.s
	.text
	.globl	foo
	.ent	foo
foo:
	b	bar
	.end	foo

	.set	bar, 0x12345678
$ as -EB -32 -o test.o test.s
test.s: Assembler messages:
test.s:3: Error: relocation overflow
$

With the original reference retained the source can now be assembled and 
linked successfully:

$ as -EB -32 -o test.o test.s
$ objdump -dr test.o

test.o:     file format elf32-tradbigmips

Disassembly of section .text:

00000000 <foo>:
   0:	1000ffff 	b	0 <foo>
			0: R_MIPS_PC16	bar
   4:	00000000 	nop
	...
$ ld -melf32btsmip -Ttext 0x12340000 -e foo -o test test.o
$ objdump -dr test

test:     file format elf32-tradbigmips

Disassembly of section .text:

12340000 <foo>:
12340000:	1000159d 	b	12345678 <bar>
12340004:	00000000 	nop
	...
$

For simplicity always retain the original symbol reference, even if it 
would indeed fit.

Making TC_FORCE_RELOCATION_ABS separate from TC_FORCE_RELOCATION causes 
R_MICROMIPS_PC7_S1, R_MICROMIPS_PC10_S1 and R_MICROMIPS_PC16_S1 branch 
relocations against absolute symbols to be converted on RELA targets to 
section-relative references.  This is an intended effect of this change.  
Absolute symbols carry no ISA annotation in their `st_other' field and 
their value is not going to change with linker relaxation, so it is safe 
to discard the original reference and keep the calculated final symbol 
value only in the relocation's addend.

Similarly R6 R_MIPS_PCHI16 and R_MIPS_PCLO16 relocations referring
absolute symbols can be safely converted even on REL targets, as there
the in-place addend of these relocations covers the entire 32-bit 
address space so it can hold the calculated final symbol value, and 
likewise the value referred won't be affected by any linker relaxation.

Add a set of suitable test cases and enable REL linker tests which now
work and were previously used as dump patterns for RELA tests only.

	gas/
	* config/tc-mips.h (TC_FORCE_RELOCATION_ABS): New macro.
	(mips_force_relocation_abs): New prototype.
	* config/tc-mips.c (mips_force_relocation_abs): New function.
	* testsuite/gas/mips/branch-absolute.d: Adjust dump patterns.
	* testsuite/gas/mips/mips16-branch-absolute.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-n32.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-n64.d: Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n32.d: 
	Likewise.
	* testsuite/gas/mips/micromips-branch-absolute-addend-n64.d: 
	Likewise.
	* testsuite/gas/mips/branch-absolute-addend.d: New test.
	* testsuite/gas/mips/mips16-branch-absolute-addend.d: New test.
	* testsuite/gas/mips/micromips-branch-absolute-addend.d: New 
	test.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	* testsuite/ld-mips-elf/mips-elf.exp: Run 
	`branch-absolute-addend', `mips16-branch-absolute', 
	`mips16-branch-absolute-addend' and 
	`micromips-branch-absolute-addend'.
---
Hi,

 I'll push it once 1/3 has been approved.

  Maciej

binutils-mips-gas-reloc-absolute.diff
Index: binutils/gas/config/tc-mips.c
===================================================================
--- binutils.orig/gas/config/tc-mips.c	2016-07-08 21:50:21.000000000 +0100
+++ binutils/gas/config/tc-mips.c	2016-07-08 22:16:44.765712347 +0100
@@ -14814,6 +14814,22 @@ mips_force_relocation (fixS *fixp)
   return 0;
 }
 
+/* Implement TC_FORCE_RELOCATION_ABS.  */
+
+bfd_boolean
+mips_force_relocation_abs (fixS *fixp)
+{
+  if (generic_force_reloc (fixp))
+    return TRUE;
+
+  /* These relocations do not have enough bits in the in-place addend
+     to hold an arbitrary absolute section's offset.  */
+  if (HAVE_IN_PLACE_ADDENDS && limited_pcrel_reloc_p (fixp->fx_r_type))
+    return TRUE;
+
+  return FALSE;
+}
+
 /* Read the instruction associated with RELOC from BUF.  */
 
 static unsigned int
Index: binutils/gas/config/tc-mips.h
===================================================================
--- binutils.orig/gas/config/tc-mips.h	2016-07-08 21:47:55.000000000 +0100
+++ binutils/gas/config/tc-mips.h	2016-07-08 22:16:44.775791638 +0100
@@ -142,6 +142,9 @@ extern int mips_force_relocation (struct
 #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEG) \
   (! SEG_NORMAL (SEG) || mips_force_relocation (FIX))
 
+#define TC_FORCE_RELOCATION_ABS(FIX) mips_force_relocation_abs (FIX)
+extern bfd_boolean mips_force_relocation_abs (struct fix *);
+
 /* 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: binutils/gas/testsuite/gas/mips/branch-absolute-addend.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/branch-absolute-addend.d	2016-07-08 22:16:44.822246006 +0100
@@ -0,0 +1,24 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS branch to absolute expression with addend
+#as: -32
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 1000048c 	b	00002234 <foo\+0x1234>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 0411048c 	bal	0000223c <foo\+0x123c>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 0410048c 	bltzal	zero,00002244 <foo\+0x1244>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 1040048c 	beqz	v0,0000224c <foo\+0x124c>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
+[0-9a-f]+ <[^>]*> 00000000 	nop
+[0-9a-f]+ <[^>]*> 1440048c 	bnez	v0,00002254 <foo\+0x1254>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
+[0-9a-f]+ <[^>]*> 00000000 	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/branch-absolute.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/branch-absolute.d	2016-07-08 21:47:55.000000000 +0100
+++ binutils/gas/testsuite/gas/mips/branch-absolute.d	2016-07-08 22:16:44.830398394 +0100
@@ -6,19 +6,19 @@
 
 Disassembly of section \.text:
 	\.\.\.
-[0-9a-f]+ <[^>]*> 1000048c 	b	00002234 <bar\+0x1000>
-[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 1000ffff 	b	00001000 <foo>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
 [0-9a-f]+ <[^>]*> 00000000 	nop
-[0-9a-f]+ <[^>]*> 0411048c 	bal	0000223c <bar\+0x1008>
-[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 0411ffff 	bal	00001008 <foo\+0x8>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
 [0-9a-f]+ <[^>]*> 00000000 	nop
-[0-9a-f]+ <[^>]*> 0410048c 	bltzal	zero,00002244 <bar\+0x1010>
-[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 0410ffff 	bltzal	zero,00001010 <foo\+0x10>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
 [0-9a-f]+ <[^>]*> 00000000 	nop
-[0-9a-f]+ <[^>]*> 1040048c 	beqz	v0,0000224c <bar\+0x1018>
-[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 1040ffff 	beqz	v0,00001018 <foo\+0x18>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
 [0-9a-f]+ <[^>]*> 00000000 	nop
-[0-9a-f]+ <[^>]*> 1440048c 	bnez	v0,00002254 <bar\+0x1020>
-[ 	]*[0-9a-f]+: R_MIPS_PC16	\*ABS\*
+[0-9a-f]+ <[^>]*> 1440ffff 	bnez	v0,00001020 <foo\+0x20>
+[ 	]*[0-9a-f]+: R_MIPS_PC16	bar
 [0-9a-f]+ <[^>]*> 00000000 	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n32.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n32.d	2016-07-08 21:47:55.000000000 +0100
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n32.d	2016-07-08 22:16:44.834429865 +0100
@@ -8,19 +8,19 @@
 Disassembly of section \.text:
 	\.\.\.
 [0-9a-f]+ <[^>]*> 9400 0000 	b	00001004 <foo\+0x4>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> 4060 0000 	bal	0000100a <foo\+0xa>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0000 0000 	nop
 [0-9a-f]+ <[^>]*> 4020 0000 	bltzal	zero,00001012 <foo\+0x12>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0000 0000 	nop
 [0-9a-f]+ <[^>]*> 9402 0000 	beqz	v0,0000101a <foo\+0x1a>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> b402 0000 	bnez	v0,00001020 <foo\+0x20>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> 0c00      	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n64.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n64.d	2016-07-08 21:47:55.000000000 +0100
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend-n64.d	2016-07-08 22:16:44.837453365 +0100
@@ -8,29 +8,29 @@
 Disassembly of section \.text:
 	\.\.\.
 [0-9a-f]+ <[^>]*> 9400 0000 	b	0000000000001004 <foo\+0x4>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> 4060 0000 	bal	000000000000100a <foo\+0xa>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0000 0000 	nop
 [0-9a-f]+ <[^>]*> 4020 0000 	bltzal	zero,0000000000001012 <foo\+0x12>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0000 0000 	nop
 [0-9a-f]+ <[^>]*> 9402 0000 	beqz	v0,000000000000101a <foo\+0x1a>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> b402 0000 	bnez	v0,0000000000001020 <foo\+0x20>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1230
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x123468a9
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> 0c00      	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-addend.d	2016-07-08 22:16:44.847614676 +0100
@@ -0,0 +1,25 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: microMIPS branch to absolute expression with addend
+#as: -32
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> 9400 0918 	b	00002234 <foo\+0x1234>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 4060 0918 	bal	0000223a <foo\+0x123a>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 4020 0918 	bltzal	zero,00002242 <foo\+0x1242>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0000 0000 	nop
+[0-9a-f]+ <[^>]*> 9402 0918 	beqz	v0,0000224a <foo\+0x124a>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> b402 0918 	bnez	v0,00002250 <foo\+0x1250>
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 0c00      	nop
+[0-9a-f]+ <[^>]*> 0c00      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-n32.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/micromips-branch-absolute-n32.d	2016-07-08 21:47:55.000000000 +0100
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-n32.d	2016-07-08 22:16:44.868791891 +0100
@@ -8,19 +8,19 @@
 Disassembly of section \.text:
 	\.\.\.
 [0-9a-f]+ <[^>]*> 9400 0000 	b	00001004 <foo\+0x4>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> 4060 0000 	bal	0000100a <foo\+0xa>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0000 0000 	nop
 [0-9a-f]+ <[^>]*> 4020 0000 	bltzal	zero,00001012 <foo\+0x12>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0000 0000 	nop
 [0-9a-f]+ <[^>]*> 9402 0000 	beqz	v0,0000101a <foo\+0x1a>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> b402 0000 	bnez	v0,00001020 <foo\+0x20>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> 0c00      	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/micromips-branch-absolute-n64.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/micromips-branch-absolute-n64.d	2016-07-08 21:47:55.000000000 +0100
+++ binutils/gas/testsuite/gas/mips/micromips-branch-absolute-n64.d	2016-07-08 22:16:44.872893175 +0100
@@ -8,29 +8,29 @@
 Disassembly of section \.text:
 	\.\.\.
 [0-9a-f]+ <[^>]*> 9400 0000 	b	0000000000001004 <foo\+0x4>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> 4060 0000 	bal	000000000000100a <foo\+0xa>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0000 0000 	nop
 [0-9a-f]+ <[^>]*> 4020 0000 	bltzal	zero,0000000000001012 <foo\+0x12>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0000 0000 	nop
 [0-9a-f]+ <[^>]*> 9402 0000 	beqz	v0,000000000000101a <foo\+0x1a>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> b402 0000 	bnez	v0,0000000000001020 <foo\+0x20>
-[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	bar-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
-[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*-0x4
+[ 	]*[0-9a-f]+: R_MICROMIPS_PC16_S1	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
+[ 	]*[0-9a-f]+: R_MIPS_NONE	\*ABS\*\+0x1231
 [0-9a-f]+ <[^>]*> 0c00      	nop
 [0-9a-f]+ <[^>]*> 0c00      	nop
 	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips.exp	2016-07-08 21:47:55.000000000 +0100
+++ binutils/gas/testsuite/gas/mips/mips.exp	2016-07-08 22:16:44.876925601 +0100
@@ -612,6 +612,7 @@ if { [istarget mips*-*-vxworks*] } {
 	run_dump_test "branch-local-n64-1"
     }
     run_dump_test "branch-absolute"
+    run_dump_test "branch-absolute-addend"
     if $has_newabi {
 	run_dump_test "branch-absolute-n32"
 	run_dump_test "branch-absolute-addend-n32"
@@ -1281,6 +1282,7 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "micromips-warn-branch-delay"
     run_dump_test "micromips-warn-branch-delay-1"
     run_dump_test "micromips-branch-absolute"
+    run_dump_test "micromips-branch-absolute-addend"
     if $has_newabi {
 	run_dump_test "micromips-branch-absolute-n32"
 	run_dump_test "micromips-branch-absolute-addend-n32"
@@ -1393,6 +1395,7 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "mips16-branch-addend-2"
     run_dump_test "mips16-branch-addend-3"
     run_dump_test "mips16-branch-absolute"
+    run_dump_test "mips16-branch-absolute-addend"
     if $has_newabi {
 	run_dump_test "mips16-branch-absolute-n32"
 	run_dump_test "mips16-branch-absolute-addend-n32"
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute-addend.d	2016-07-08 22:16:44.892032613 +0100
@@ -0,0 +1,20 @@
+#objdump: -dr --prefix-addresses --show-raw-insn
+#name: MIPS16 branch to absolute expression with addend
+#as: -32
+
+.*: +file format .*mips.*
+
+Disassembly of section \.text:
+	\.\.\.
+[0-9a-f]+ <[^>]*> f101 1018 	b	00002234 <foo\+0x1234>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f101 6018 	bteqz	00002238 <foo\+0x1238>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f101 6118 	btnez	0000223c <foo\+0x123c>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f101 2218 	beqz	v0,00002240 <foo\+0x1240>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f101 2a18 	bnez	v0,00002244 <foo\+0x1244>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> 6500      	nop
+	\.\.\.
Index: binutils/gas/testsuite/gas/mips/mips16-branch-absolute.d
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips16-branch-absolute.d	2016-07-08 21:50:21.000000000 +0100
+++ binutils/gas/testsuite/gas/mips/mips16-branch-absolute.d	2016-07-08 22:16:44.909181788 +0100
@@ -6,15 +6,15 @@
 
 Disassembly of section \.text:
 	\.\.\.
-[0-9a-f]+ <[^>]*> f101 1018 	b	00002234 <bar\+0xfff>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f101 6018 	bteqz	00002238 <bar\+0x1003>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f101 6118 	btnez	0000223c <bar\+0x1007>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f101 2218 	beqz	v0,00002240 <bar\+0x100b>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
-[0-9a-f]+ <[^>]*> f101 2a18 	bnez	v0,00002244 <bar\+0x100f>
-[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	\*ABS\*
+[0-9a-f]+ <[^>]*> f7ff 101e 	b	00001000 <foo>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f7ff 601e 	bteqz	00001004 <foo\+0x4>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f7ff 611e 	btnez	00001008 <foo\+0x8>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f7ff 221e 	beqz	v0,0000100c <foo\+0xc>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
+[0-9a-f]+ <[^>]*> f7ff 2a1e 	bnez	v0,00001010 <foo\+0x10>
+[ 	]*[0-9a-f]+: R_MIPS16_PC16_S1	bar
 [0-9a-f]+ <[^>]*> 6500      	nop
 	\.\.\.
Index: binutils/ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
--- binutils.orig/ld/testsuite/ld-mips-elf/mips-elf.exp	2016-07-08 21:50:21.000000000 +0100
+++ binutils/ld/testsuite/ld-mips-elf/mips-elf.exp	2016-07-08 22:16:44.926340159 +0100
@@ -144,6 +144,7 @@ run_dump_test "mips16-1"
 run_dump_test "branch-misc-1"
 run_dump_test "branch-misc-2"
 run_dump_test "branch-absolute" [list [list ld $abi_ldflags(o32)]]
+run_dump_test "branch-absolute-addend" [list [list ld $abi_ldflags(o32)]]
 if $has_newabi {
     run_dump_test "branch-absolute-n32" [list [list ld $abi_ldflags(n32)]]
     run_dump_test "branch-absolute-addend-n32" \
@@ -157,6 +158,9 @@ run_dump_test "mips16-branch-2" [list [l
 run_dump_test "mips16-branch-3" [list [list ld $abi_ldflags(o32)]]
 run_dump_test "mips16-branch-addend-2" [list [list ld $abi_ldflags(o32)]]
 run_dump_test "mips16-branch-addend-3" [list [list ld $abi_ldflags(o32)]]
+run_dump_test "mips16-branch-absolute" [list [list ld $abi_ldflags(o32)]]
+run_dump_test "mips16-branch-absolute-addend" \
+					[list [list ld $abi_ldflags(o32)]]
 if $has_newabi {
     run_dump_test "mips16-branch-absolute-n32" \
 					[list [list ld $abi_ldflags(n32)]]
@@ -169,6 +173,8 @@ if $has_newabi {
 }
 
 run_dump_test "micromips-branch-absolute" [list [list ld $abi_ldflags(o32)]]
+run_dump_test "micromips-branch-absolute-addend" \
+					[list [list ld $abi_ldflags(o32)]]
 if $has_newabi {
     run_dump_test "micromips-branch-absolute-n32" \
 					[list [list ld $abi_ldflags(n32)]]

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

* Re: [PATCH, RFA 1/3] BFD: Let targets handle relocations against absolute symbols
  2016-07-12  0:30 ` [PATCH, RFA 1/3] BFD: Let targets handle " Maciej W. Rozycki
@ 2016-07-12  6:15   ` Alan Modra
  2016-07-14 19:15     ` Maciej W. Rozycki
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2016-07-12  6:15 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: binutils

On Tue, Jul 12, 2016 at 01:30:01AM +0100, Maciej W. Rozycki wrote:
> 	* reloc.c (bfd_perform_relocation): Try the `howto' handler 
> 	first with relocations against absolute symbols.
> 	(bfd_install_relocation): Likewise.

The patch looks reasonable to me, so OK.  Like you I'm a little
concerned about existing howto->special_function behaving correctly
with absolute symbols, but I guess we can fix any issues as we find
them.  Did you perform any ld -r tests?

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [PATCH, RFA 1/3] BFD: Let targets handle relocations against absolute symbols
  2016-07-12  6:15   ` Alan Modra
@ 2016-07-14 19:15     ` Maciej W. Rozycki
  0 siblings, 0 replies; 6+ messages in thread
From: Maciej W. Rozycki @ 2016-07-14 19:15 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On Tue, 12 Jul 2016, Alan Modra wrote:

> > 	* reloc.c (bfd_perform_relocation): Try the `howto' handler 
> > 	first with relocations against absolute symbols.
> > 	(bfd_install_relocation): Likewise.
> 
> The patch looks reasonable to me, so OK.  Like you I'm a little
> concerned about existing howto->special_function behaving correctly
> with absolute symbols, but I guess we can fix any issues as we find
> them.  Did you perform any ld -r tests?

 Not originally, however now that you mentioned it I ran `ld -r' across a 
few of the test cases included with these patches, both o32 and n32 and 
the output is unchanged and correct without or with this change applied.  
I'd expect that actually -- whether the in-place addend is left untouched 
or rewritten on copying input to output does not matter because offsets 
from the absolute section do not change with incremental linking.

 Out of curiosity I picked a non-ELF target using in-place addends and 
PC-relative relocations, `i386-linuxaout'.  I tried code similar to my 
MIPS test cases, using the JMP instruction instead.  So interestingly 
enough it is unaffected by my change, because its `md_apply_fix' function 
(in gas/config/tc-i386.c) always initialises the relocated field, 
regardless of whether relocation is complete (`fixP->fx_done' is TRUE) or 
an external relocation is requested.  It uses `md_number_to_chars' for 
this purpose, ignoring any special function the relevant relocation's 
`howto' structure may have.

 The MIPS target's `md_apply_fix' function also initialises the relocated 
field, but only if `fixP->fx_done' is TRUE (with the use of a specialised 
handler, `mips16_immed_extend', for mangled MIPS16 encodings), deferring 
any outstanding relocations to BFD.  We could make the MIPS target mimic 
i386, but it does not appear to me to be a move in the right direction -- 
I'd rather made i386 defer to BFD as well, so that the processing of 
external relocations is made in one place, avoiding the risk of having 
disjoint sets of bugs across the places where relocation processing 
happens, and consequently reducing the maintenance burden.

 Especially as up to my change proposed here relocations against absolute 
symbols were the only exception handled differently.  Therefore, and with 
your approval, I have committed this change now (I have pushed the other 
two as well).  Thanks for your review.

  Maciej

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

end of thread, other threads:[~2016-07-14 19:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-12  0:29 [PATCH 0/3] BFD, MIPS: Fix the handling of branch relocations against absolute symbols Maciej W. Rozycki
2016-07-12  0:30 ` [PATCH, RFA 1/3] BFD: Let targets handle " Maciej W. Rozycki
2016-07-12  6:15   ` Alan Modra
2016-07-14 19:15     ` Maciej W. Rozycki
2016-07-12  0:31 ` [PATCH 2/3] MIPS/GAS: Keep the ISA bit in the addend of branch relocations Maciej W. Rozycki
2016-07-12  0:31 ` [PATCH 3/3] MIPS/GAS: Don't convert PC-relative REL relocations against absolute symbols Maciej W. Rozycki

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).