Re: avr-ld rjmp 2-off anomaly

Ilya Lesokhin <[email protected]> Wed, 27 Oct 2021 08:10:06 +0300
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <CAEPKs0esfrNSYCC8qMdoKh1ZKXFfCRfPgRvnVZrgG1Jw8_8jGA@mail.gmail.com>
--0000000000003f1a4b05cf4e9cbb
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Seems to be the same issue as
https://sourceware.org/bugzilla/show_bug.cgi?id=3D13402.

On Wed, Oct 27, 2021 at 1:25 AM Karak=C3=B3 Tibor <[email protected]=
>
wrote:

> Hi,
>
> I ran into a weird situation regarding whether I compile and link the
> code in one go or in two phases.
>
> main.c:
>
> int main() {
>      asm("out 0x14, r24");
>          while (1) {
>          asm("out 0x16, r24");
>      }
> }
>
> When I run:
>
> avr-gcc -O main.c -o main_one.hex -mmcu=3Dattiny2313 -Wl,--oformat,ihex
>
> I get a different result compared to:
>
> avr-gcc -O main.c -o main_two.elf -mmcu=3Dattiny2313
> avr-ld -o main_two.elf.hex --oformat ihex main_two.elf
>
> $ avr-objdump -j .sec1 -d -m avr main_two.elf.hex
>
>   38:   fe cf           rjmp    .-4             ;  0x36
>
> It calculates the jump correctly.
>
> But the former one seems to introduce a 2-off bug when calculating the
> rjmps' offset:
>
> $ avr-objdump -j .sec1 -d -m avr main_one.hex
>
>    38:   ff cf           rjmp    .-2             ;  0x38
>
> The same goes for every rjmp.
>
> Is this a legit bug, or I am missing something?
>
>
> gcc-avr(1:5.4.0+Atmel3.6.2-1)
>
> binutils-avr(2.26.20160125+Atmel3.6.2-2)
>
>
> Br,
>
> Tibor
>
>
>

--0000000000003f1a4b05cf4e9cbb
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Seems to be the same issue as <a href=3D"https://sourcewar=
e.org/bugzilla/show_bug.cgi?id=3D13402">https://sourceware.org/bugzilla/sho=
w_bug.cgi?id=3D13402</a>.</div><br><div class=3D"gmail_quote"><div dir=3D"l=
tr" class=3D"gmail_attr">On Wed, Oct 27, 2021 at 1:25 AM Karak=C3=B3 Tibor =
&lt;<a href=3D"mailto:[email protected]">[email protected]</a=
>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px=
 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,=
<br>
<br>
I ran into a weird situation regarding whether I compile and link the <br>
code in one go or in two phases.<br>
<br>
main.c:<br>
<br>
int main() {<br>
=C2=A0=C2=A0=C2=A0=C2=A0 asm(&quot;out 0x14, r24&quot;);<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 while (1) {<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 asm(&quot;out 0x16, r24&qu=
ot;);<br>
=C2=A0=C2=A0=C2=A0=C2=A0 }<br>
}<br>
<br>
When I run:<br>
<br>
avr-gcc -O main.c -o main_one.hex -mmcu=3Dattiny2313 -Wl,--oformat,ihex<br>
<br>
I get a different result compared to:<br>
<br>
avr-gcc -O main.c -o main_two.elf -mmcu=3Dattiny2313<br>
avr-ld -o main_two.elf.hex --oformat ihex main_two.elf<br>
<br>
$ avr-objdump -j .sec1 -d -m avr main_two.elf.hex<br>
<br>
=C2=A0=C2=A038:=C2=A0=C2=A0 fe cf=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 rjmp=C2=A0=C2=A0=C2=A0 .-4=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;=C2=A0 0x36<br>
<br>
It calculates the jump correctly.<br>
<br>
But the former one seems to introduce a 2-off bug when calculating the <br>
rjmps&#39; offset:<br>
<br>
$ avr-objdump -j .sec1 -d -m avr main_one.hex<br>
<br>
=C2=A0=C2=A0 38:=C2=A0=C2=A0 ff cf=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 rjmp=C2=A0=C2=A0=C2=A0 .-2=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;=C2=A0 0x38<br>
<br>
The same goes for every rjmp.<br>
<br>
Is this a legit bug, or I am missing something?<br>
<br>
<br>
gcc-avr(1:5.4.0+Atmel3.6.2-1)<br>
<br>
binutils-avr(2.26.20160125+Atmel3.6.2-2)<br>
<br>
<br>
Br,<br>
<br>
Tibor<br>
<br>
<br>
</blockquote></div>

--0000000000003f1a4b05cf4e9cbb--