avr-llvm / llvm

[MERGED UPSTREAM] AVR backend for the LLVM compiler library
220 stars 21 forks source link

Funky encoding of labels with negative offsets with PC-relative fixups #135

Closed dylanmckay closed 9 years ago

dylanmckay commented 9 years ago

Take the test/MC/AVR/inst-rjmp.s test for example, compile it using llvm-mc. You will see that everything is as it should be, except for the one jump that is to a previous point in the program.

inst-rjmp.s:

  rjmp  .+2
  rjmp  .-2
  rjmp  foo ; jump in question
  rjmp  .+8
  rjmp  end
  rjmp  .+0
end:
  rjmp .-4
  rjmp .-6

avr-objdump output:

00000000 <foo>:
   0:   01 c0           rjmp    .+2         ; 0x4 <foo+0x4>
   2:   ff cf           rjmp    .-2         ; 0x2 <foo+0x2>
   4:   fd c0           rjmp    .+506       ; 0x200 <end+0x1f4>
   6:   04 c0           rjmp    .+8         ; 0x10 <end+0x4>
   8:   01 c0           rjmp    .+2         ; 0xc <end>
   a:   00 c0           rjmp    .+0         ; 0xc <end>

0000000c <end>:
   c:   fe cf           rjmp    .-4         ; 0xa <foo+0xa>
   e:   fd cf           rjmp    .-6         ; 0xa <foo+0xa>

All is well, until what should be rjmp .-6 is actually rjmp .+506.

dylanmckay commented 9 years ago

Fixed in 482c47d9eeb23eb4c09adb34cde947c068a1f81a. Now that was a debugging session that took way longer than it should've :(

agnat commented 9 years ago

Boom

Awesome. I was just about to take a look.

Maybe we should start to (self-) assign the issues before working on them?

dylanmckay commented 9 years ago

Maybe we should start to (self-) assign the issues before working on them?

I was thinking the same, it seems to be a growing problem. Let's start using the GitHub assignee feature?

agnat commented 9 years ago

Let's start using the GitHub assignee feature?

Ack.