binutils-gdb/ld/testsuite/ld-avr/wraparound-range-boundary.d
Senthil Kumar Selvaraj 338ba75534 Fix PR 24564 - link fails for some rcalls/rjmps with wraparound
The current code to compute relative distance in the wrap around case does not
handle the edge case of the target (after adjusting for implicit PC increment)
being exactly half of the wrap around distance. This patch fixes that and adds a
testcase.

The range for a forward relative jump call is 4096 bytes ((2 * 2047) + (2 bytes
for the implicit PC increment)). If the target of the jump is at a distance of
4098 bytes, it is out of range for a forward jump - however, a backward jump can
still reach that address if pmem-wrap-around is 8192.

Assume address 0 has rjmp to address 4098. With a wrap around of 8192 and
*without* adjusting for the implicit PC increment of 2 bytes, rjmp .-4096 will
jump to address 4096 (wrap around at 8192 and decreasing addresses from then
on). Adjusting 2 bytes for the implicit PC increment, the actual target is 4098.

avr_relative_distance_considering_wrap_around though, does the wrap around only
if the passed in distance is less than half of the wrap around distance. In this
case, it is exactly equal to half (original distance 4098, adjusted distance of
4096 and wraparound of 8192), and the bypassed wrap around causes the reloc
overflow error.

Fix by wrapping around even if adjusted distance is equal to half of wrap around
distance.
2019-05-21 12:34:22 +05:30

18 lines
358 B
Makefile

#name: Wraparound works for jump target at pc-relative range boundary
#as: -m avr51
#ld: --pmem-wrap-around=8k -m avr51
#source: wraparound-range-boundary.s
#objdump: -d
#target: avr-*-*
#...
Disassembly of section .text:
00000000 <__ctors_end>:
0: 00 c8 rjmp .\-4096 ; 0xfffff002 <__eeprom_end\+0xff7ef002>
...
00001002 <target>:
...