aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorSenthil Kumar Selvaraj <senthilkumar.selvaraj@microchip.com>2019-05-16 17:16:36 +0530
committerSenthil Kumar Selvaraj <senthilkumar.selvaraj@microchip.com>2019-05-21 12:34:22 +0530
commit338ba75534fbfeb64d7009f29a89f25826a1f4d2 (patch)
tree49680dd9ed1d62be18a568a14643e7fffeb4c204 /bfd
parentda0523c66604dc11b8787d3e0123ea80a2503f14 (diff)
downloadgdb-338ba75534fbfeb64d7009f29a89f25826a1f4d2.zip
gdb-338ba75534fbfeb64d7009f29a89f25826a1f4d2.tar.gz
gdb-338ba75534fbfeb64d7009f29a89f25826a1f4d2.tar.bz2
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.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/elf32-avr.c2
2 files changed, 7 insertions, 1 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index e463fed..0d7eda4 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-21 Senthil Kumar Selvaraj <senthilkumar.selvaraj@microchip.com>
+
+ PR ld/24564
+ * bfd/elf32-avr.c (avr_relative_distance_considering_wrap_around):
+ Wrap around even if distance equals avr_pc_wrap_around.
+
2019-05-20 Nick Clifton <nickc@redhat.com>
* po/fr.po: Updated French translation.
diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
index d6842a0..f8a843e 100644
--- a/bfd/elf32-avr.c
+++ b/bfd/elf32-avr.c
@@ -910,7 +910,7 @@ avr_relative_distance_considering_wrap_around (unsigned int distance)
unsigned int wrap_around_mask = avr_pc_wrap_around - 1;
int dist_with_wrap_around = distance & wrap_around_mask;
- if (dist_with_wrap_around > ((int) (avr_pc_wrap_around >> 1)))
+ if (dist_with_wrap_around >= ((int) (avr_pc_wrap_around >> 1)))
dist_with_wrap_around -= avr_pc_wrap_around;
return dist_with_wrap_around;