Maciej W. Rozycki 0c11728627 BFD: Let targets handle relocations against absolute symbols
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.
2016-07-14 20:06:37 +01:00
..
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-07-11 15:24:35 +02:00
2016-06-14 13:12:00 +09:30
2016-01-01 23:00:01 +10:30
2016-07-05 11:28:46 +01:00
2016-06-14 13:24:37 +09:30
2016-01-01 23:00:01 +10:30
2016-06-14 13:12:00 +09:30
2016-06-14 13:12:00 +09:30
2016-05-28 11:17:20 +09:30
2016-06-14 13:12:00 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-06-24 23:26:29 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-06-07 22:04:38 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-06-15 12:47:46 +05:30
2016-01-01 23:00:01 +10:30
2016-06-28 17:04:30 +01:00
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-06-01 21:26:32 -04:00
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-06-01 21:26:32 -04:00
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-06-07 22:04:38 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-06-01 21:26:32 -04:00
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-02-26 05:01:34 -08:00
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-06-14 13:12:00 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-04-26 20:09:57 -04:00
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-03-21 16:31:46 +00:00
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-07-05 11:28:46 +01:00
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-07-14 00:00:24 +00:00
2016-05-28 11:17:20 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-03-31 07:30:56 -04:00
2016-06-14 13:12:00 +09:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30
2016-01-01 23:00:01 +10:30

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

BFD is an object file library.  It permits applications to use the
same routines to process object files regardless of their format.

BFD is used by the GNU debugger, assembler, linker, and the binary
utilities.

The documentation on using BFD is scanty and may be occasionally
incorrect.  Pointers to documentation problems, or an entirely
rewritten manual, would be appreciated.

There is some BFD internals documentation in doc/bfdint.texi which may
help programmers who want to modify BFD.

BFD is normally built as part of another package.  See the build
instructions for that package, probably in a README file in the
appropriate directory.

BFD supports the following configure options:

  --target=TARGET
	The default target for which to build the library.  TARGET is
	a configuration target triplet, such as sparc-sun-solaris.
  --enable-targets=TARGET,TARGET,TARGET...
	Additional targets the library should support.  To include
	support for all known targets, use --enable-targets=all.
  --enable-64-bit-bfd
	Include support for 64 bit targets.  This is automatically
	turned on if you explicitly request a 64 bit target, but not
	for --enable-targets=all.  This requires a compiler with a 64
	bit integer type, such as gcc.
  --enable-shared
	Build BFD as a shared library.
  --with-mmap
	Use mmap when accessing files.  This is faster on some hosts,
	but slower on others.  It may not work on all hosts.

Report bugs with BFD to bug-binutils@gnu.org.

Patches are encouraged.  When sending patches, always send the output
of diff -u or diff -c from the original file to the new file.  Do not
send default diff output.  Do not make the diff from the new file to
the original file.  Remember that any patch must not break other
systems.  Remember that BFD must support cross compilation from any
host to any target, so patches which use ``#ifdef HOST'' are not
acceptable.  Please also read the ``Reporting Bugs'' section of the
gcc manual.

Bug reports without patches will be remembered, but they may never get
fixed until somebody volunteers to fix them.

Copyright (C) 2012-2016 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.