binutils-gdb/ld/testsuite/ld-avr
Senthil Kumar Selvaraj bf1865065f Fix PR ld/20545 - relaxation bugs in avr backend
Prior to the patch, addends for relocs were being adjusted even if
they went beyond an alignment boundary. This is wrong - to
preserve alignment constraints, the relaxation logic adds as many padding
bytes at the alignment boundary as was deleted, so addends beyond the
boundary should not be adjusted. avr-prop-7.s reproduces this
scenario.

Also, prior to this patch, the relaxation logic assumed that the addr
parameter pointed to the middle of the instruction to be deleted, and
that addr - count would therefore be the shrinked instruction's
address. This is true when actually shrinking instructions.

The alignment constraints handling logic also invokes the same logic
though, with addr as the starting offset of padding bytes and
with count as the number of bytes to be deleted. Calculating the
shrinked insn's address as addr - count is obviously wrong in this
case - that offset would point to count bytes before the last
non-padded byte. avr-prop-8.s reproduces this scenario.

To fix scenario 1, the patch adds an additional check to ensure reloc addends
aren't adjusted if they cross a shrink boundary. The shrink boundary
is either the section size or an alignment boundary. Addends pointing
at an alignment boundary don't need to be adjusted, as padding would
occur and keep the boundary the same. Addends pointing at section size
need to be adjusted though, as no padding occurs and the section size
itself would get decremented. The patch records whether padding
occured (did_pad) and uses that to detect and handle this condition.

To fix scenario 2, the patch adds an additional parameter
(delete_shrinks_insn) to elf32_avr_relax_delete_bytes to distinguish
instruction bytes deletion from padding bytes deletion. It then uses that to
correctly set shrinked_insn_address.

bfd/ChangeLog:

2016-09-02  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR ld/20545
	* elf32-avr.c (elf32_avr_relax_delete_bytes): Add parameter
	delete_shrinks_insn. Modify computation of shrinked_insn_address.
	Compute shrink_boundary and adjust addend only if
	addend_within_shrink_boundary.
	(elf32_avr_relax_section): Modify calls to
	elf32_avr_relax_delete_bytes to pass extra parameter.

ld/ChangeLog:

2016-09-02  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	PR ld/20545
	* testsuite/ld-avr/avr-prop-7.d: New test.
	* testsuite/ld-avr/avr-prop-7.s: New test.
	* testsuite/ld-avr/avr-prop-8.d: New test.
	* testsuite/ld-avr/avr-prop-8.s: New test.
2016-09-06 12:28:37 +05:30
..
avr-prop-1.d AVR/ld: Use .avr.prop data during linker relaxation. 2015-02-25 23:19:11 +00:00
avr-prop-1.s AVR/ld: Use .avr.prop data during linker relaxation. 2015-02-25 23:19:11 +00:00
avr-prop-2.d AVR/ld: Use .avr.prop data during linker relaxation. 2015-02-25 23:19:11 +00:00
avr-prop-2.s AVR/ld: Use .avr.prop data during linker relaxation. 2015-02-25 23:19:11 +00:00
avr-prop-3.d AVR/ld: Use .avr.prop data during linker relaxation. 2015-02-25 23:19:11 +00:00
avr-prop-3.s AVR/ld: Use .avr.prop data during linker relaxation. 2015-02-25 23:19:11 +00:00
avr-prop-4.d AVR/ld: Use .avr.prop data during linker relaxation. 2015-02-25 23:19:11 +00:00
avr-prop-4.s AVR/ld: Use .avr.prop data during linker relaxation. 2015-02-25 23:19:11 +00:00
avr-prop-5.d Fix PR 20221 - adjust syms and relocs only if relax shrunk section. 2016-06-09 19:17:43 +03:00
avr-prop-5.s Fix PR 20221 - adjust syms and relocs only if relax shrunk section. 2016-06-09 19:17:43 +03:00
avr-prop-6.d Fix PR ld/20254 2016-06-15 12:47:46 +05:30
avr-prop-6.s Fix PR ld/20254 2016-06-15 12:47:46 +05:30
avr-prop-7.d Fix PR ld/20545 - relaxation bugs in avr backend 2016-09-06 12:28:37 +05:30
avr-prop-7.s Fix PR ld/20545 - relaxation bugs in avr backend 2016-09-06 12:28:37 +05:30
avr-prop-8.d Fix PR ld/20545 - relaxation bugs in avr backend 2016-09-06 12:28:37 +05:30
avr-prop-8.s Fix PR ld/20545 - relaxation bugs in avr backend 2016-09-06 12:28:37 +05:30
avr.exp Copyright update for binutils 2016-01-01 23:00:01 +10:30
gc-section-debugline.d Fix possible failure in the AVR linker tests. 2016-03-18 09:51:47 +00:00
lds-mega.d Print symbol names in comments for LDS/STS disassembly. 2016-06-09 19:00:57 +03:00
lds-mega.s Print symbol names in comments for LDS/STS disassembly. 2016-06-09 19:00:57 +03:00
lds-tiny.d Print symbol names in comments for LDS/STS disassembly. 2016-06-09 19:00:57 +03:00
lds-tiny.s Print symbol names in comments for LDS/STS disassembly. 2016-06-09 19:00:57 +03:00
norelax_diff.d
per-function-debugline.s Define DIFF_EXPR_OK for avr target to allow PC relative difference relocation. 2015-07-08 21:41:52 +03:00
region_overflow.d This patch modifies the AVR linker script templates to use __<name>_REGION_LENGTH__ symbols, if provided, for setting memory region lengths, defaulting to the current constant values otherwise. 2015-02-24 11:26:28 +00:00
region_overflow.s This patch modifies the AVR linker script templates to use __<name>_REGION_LENGTH__ symbols, if provided, for setting memory region lengths, defaulting to the current constant values otherwise. 2015-02-24 11:26:28 +00:00
relax_diff.d
relax-02.d When relaxing, update size of symbols. 2014-11-03 20:34:13 +00:00
relax-02.s
relax-03.d When relaxing, update size of symbols. 2014-11-03 20:34:13 +00:00
relax-03.s
relax-elf-flags-01.d AVR/ld: Propagate link-relax elf header flag correctly. 2014-12-23 15:45:11 +00:00
relax-elf-flags-02.d AVR: Assembler now prepares for linker relaxation by default. 2014-12-24 21:27:43 +00:00
relax-elf-flags-03.d AVR: Assembler now prepares for linker relaxation by default. 2014-12-24 21:27:43 +00:00
relax-elf-flags-04.d AVR: Assembler now prepares for linker relaxation by default. 2014-12-24 21:27:43 +00:00
relax-elf-flags-05.d AVR: Assembler now prepares for linker relaxation by default. 2014-12-24 21:27:43 +00:00
relax-elf-flags-06.d AVR: Assembler now prepares for linker relaxation by default. 2014-12-24 21:27:43 +00:00
relax-elf-flags-07.d AVR/ld: Propagate link-relax elf header flag correctly. 2014-12-23 15:45:11 +00:00
relax-elf-flags-08.d AVR/ld: Propagate link-relax elf header flag correctly. 2014-12-23 15:45:11 +00:00
relax-elf-flags-a.s AVR/ld: Propagate link-relax elf header flag correctly. 2014-12-23 15:45:11 +00:00
relax-elf-flags-b.s AVR/ld: Propagate link-relax elf header flag correctly. 2014-12-23 15:45:11 +00:00
relax.s