[lld] Fix R_AVR_7_PCREL and R_AVR_13_PCREL range checking (PR #92695)

via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 09:22:08 PDT 2024


aykevl wrote:

> I wonder how RJMP can jumps over 4kB on the ATtiny85 device. Is RJMP has a different encoding against other devices ?

I can't quickly find it in the instruction set manual, but I did find this:

> For AVR microcontrollers with Program memory not exceeding 4K words (8KB) this instruction can address the entire memory from every address location.

I assume it wraps around, because that's the only way I see that would make it possible to address the full 8kB of memory.
So for example if there's a `rjmp .+4094` at address 6114, it will jump to (6114 + 4094 + 2) = 10210, which wraps around to address 2018. (The +2 is the size of the instruction itself).

I also found this in the [attiny85 datasheet](https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf):

> The ATtiny25/45/85 Program Counter (PC) is 10/11/12 bits wide, thus addressing the 1024/2048/4096 Program memory locations

This means that the attiny85 program counter is 12 bits, which means that it will indeed wrap around (12 bits is 4096 words, is 8192 bytes).

For avr-ld, there's an option to enable/disable wraparound (but it appears that wraparound is enabled by default):
https://sourceware.org/binutils/docs-2.30/as/AVR-Options.html. See `-mno-wrap`. I don't know whether we can add a flag like that to lld, I'd much prefer if we didn't need a special chip-specific flag for this (in my opinion a better solution would be two different relocations: one with wraparound and one without - but that would break compatibility with avr-ld).

https://github.com/llvm/llvm-project/pull/92695


More information about the llvm-commits mailing list