* [PATCH] Fix PR 24564 - link fails for some rcalls/rjmps with wraparound
@ 2019-05-17 11:17 SenthilKumar.Selvaraj
2019-05-20 10:23 ` Nick Clifton
0 siblings, 1 reply; 2+ messages in thread
From: SenthilKumar.Selvaraj @ 2019-05-17 11:17 UTC (permalink / raw)
To: binutils; +Cc: nickc, chertykov
Hi,
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.
The patch fixes this by wrapping around even if adjusted distance is
equal to half of wrap around distance.
Ok to commit to master?
Regards
Senthil
bfd/ChangeLog:
2019-05-17 Senthil Kumar Selvaraj <senthilkumar.selvaraj@microchip.com>
* bfd/elf32-avr.c (avr_relative_distance_considering_wrap_around):
Wrap around even if distance equals avr_pc_wrap_around.
ld/ChangeLog:
2019-05-17 Senthil Kumar Selvaraj <senthilkumar.selvaraj@microchip.com>
* testsuite/ld-avr/wraparound-range-boundary.d: New test.
* testsuite/ld-avr/wraparound-range-boundary.s: New test.
diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
index d6842a03304..f8a843e16c8 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;
diff --git a/ld/testsuite/ld-avr/wraparound-range-boundary.d b/ld/testsuite/ld-avr/wraparound-range-boundary.d
new file mode 100644
index 00000000000..83c12f5e6ff
--- /dev/null
+++ b/ld/testsuite/ld-avr/wraparound-range-boundary.d
@@ -0,0 +1,17 @@
+#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>:
+ ...
+
diff --git a/ld/testsuite/ld-avr/wraparound-range-boundary.s b/ld/testsuite/ld-avr/wraparound-range-boundary.s
new file mode 100644
index 00000000000..fbea0e1b074
--- /dev/null
+++ b/ld/testsuite/ld-avr/wraparound-range-boundary.s
@@ -0,0 +1,6 @@
+.global main
+main:
+ rjmp target
+ .ds.b 4096
+target:
+ nop
--
2.19.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix PR 24564 - link fails for some rcalls/rjmps with wraparound
2019-05-17 11:17 [PATCH] Fix PR 24564 - link fails for some rcalls/rjmps with wraparound SenthilKumar.Selvaraj
@ 2019-05-20 10:23 ` Nick Clifton
0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2019-05-20 10:23 UTC (permalink / raw)
To: SenthilKumar.Selvaraj, binutils; +Cc: chertykov
Hi Senthil,
> bfd/ChangeLog:
> 2019-05-17 Senthil Kumar Selvaraj <senthilkumar.selvaraj@microchip.com>
>
> * bfd/elf32-avr.c (avr_relative_distance_considering_wrap_around):
> Wrap around even if distance equals avr_pc_wrap_around.
>
> ld/ChangeLog:
> 2019-05-17 Senthil Kumar Selvaraj <senthilkumar.selvaraj@microchip.com>
>
> * testsuite/ld-avr/wraparound-range-boundary.d: New test.
> * testsuite/ld-avr/wraparound-range-boundary.s: New test.
Approved - please apply.
Cheers
Nick
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-05-20 10:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-17 11:17 [PATCH] Fix PR 24564 - link fails for some rcalls/rjmps with wraparound SenthilKumar.Selvaraj
2019-05-20 10:23 ` Nick Clifton
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).