Skip to content

Commit 7a64998

Browse files
committed
[lld][AVR] Allow R_AVR_13_PCREL to overflow
This matches the behavior of avr-ld, and is needed for devices like the ATtiny85 which only have rjmp/rcall (no jmp/call) but have 8kB of flash memory. Without this change, jumps over 4kB would not be possible on the ATtiny85.
1 parent b60ee41 commit 7a64998

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lld/ELF/Arch/AVR.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ void AVR::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
238238
break;
239239
}
240240
case R_AVR_13_PCREL: {
241-
checkInt(loc, val - 2, 13, rel);
242241
checkAlignment(loc, val, 2, rel);
243242
const uint16_t target = (val - 2) >> 1;
244243
write16le(loc, (read16le(loc) & 0xf000) | (target & 0xfff));

lld/test/ELF/avr-reloc-error.s

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ brlt callee2
3434
__start:
3535

3636
# PCREL13-NOT: callee0
37-
# PCREL13: error: {{.*}} relocation R_AVR_13_PCREL out of range: {{.*}} is not in [-4096, 4095]; references 'callee1'
3837
# PCREL13: error: {{.*}} improper alignment for relocation R_AVR_13_PCREL: {{.*}} is not aligned to 2 bytes
3938
rjmp callee0
4039
rcall callee1

lld/test/ELF/avr-reloc.s

+8
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ sbic b, 1 ; R_AVR_PORT5
8282
; CHECK-NEXT: rjmp .-36
8383
; CHECK-NEXT: breq .+26
8484
; CHECK-NEXT: breq .-40
85+
; CHECK-NEXT: rjmp .-4096
86+
; CHECK-NEXT: rjmp .+4094
87+
; CHECK-NEXT: rjmp .+4094
88+
; CHECK-NEXT: rjmp .-4096
8589
; CHECK-NEXT: breq .-128
8690
; CHECK-NEXT: breq .+126
8791
; HEX-LABEL: section .PCREL:
@@ -91,6 +95,10 @@ rjmp foo + 32 ; R_AVR_13_PCREL
9195
rjmp foo - 32 ; R_AVR_13_PCREL
9296
breq foo + 32 ; R_AVR_7_PCREL
9397
breq foo - 32 ; R_AVR_7_PCREL
98+
rjmp 1f - 4096 $ 1: ; R_AVR_13_PCREL
99+
rjmp 1f + 4094 $ 1: ; R_AVR_13_PCREL
100+
rjmp 1f - 4098 $ 1: ; R_AVR_13_PCREL (overflow)
101+
rjmp 1f + 4096 $ 1: ; R_AVR_13_PCREL (overflow)
94102
breq 1f - 128 $ 1: ; R_AVR_7_PCREL
95103
breq 1f + 126 $ 1: ; R_AVR_7_PCREL
96104

0 commit comments

Comments
 (0)