Index: lld/ELF/Arch/AVR.cpp =================================================================== --- lld/ELF/Arch/AVR.cpp +++ lld/ELF/Arch/AVR.cpp @@ -74,6 +74,7 @@ case R_AVR_HI8_LDI_PM_NEG: case R_AVR_HH8_LDI_PM: case R_AVR_HH8_LDI_PM_NEG: + case R_AVR_LDS_STS_16: case R_AVR_PORT5: case R_AVR_PORT6: case R_AVR_CALL: @@ -170,6 +171,14 @@ writeLDI(loc, (-val >> 17) & 0xff); break; + case R_AVR_LDS_STS_16: { + checkUInt(loc, val, 7, rel); + const uint16_t hi = val >> 4; + const uint16_t lo = val & 0xf; + write16le(loc, (read16le(loc) & 0xf8f0) | ((hi << 8) | lo)); + break; + } + case R_AVR_PORT5: checkUInt(loc, val, 5, rel); write16le(loc, (read16le(loc) & 0xff07) | (val << 3)); Index: lld/test/ELF/avr-reloc.s =================================================================== --- lld/test/ELF/avr-reloc.s +++ lld/test/ELF/avr-reloc.s @@ -1,8 +1,8 @@ ; REQUIRES: avr ; RUN: llvm-mc -filetype=obj -triple=avr -mcpu=atmega328p %s -o %t.o ; RUN: ld.lld %t.o --defsym=a=0x12345678 --defsym=b=30 -o %t -; RUN: llvm-objdump -d --print-imm-hex %t | FileCheck %s -; RUN: llvm-objdump -s %t | FileCheck --check-prefix=HEX %s +; RUN: llvm-objdump -d --print-imm-hex --mcpu=atmega328p %t | FileCheck %s +; RUN: llvm-objdump -s --mcpu=atmega328p %t | FileCheck --check-prefix=HEX %s .section .LDI,"ax",@progbits ; CHECK-LABEL: section .LDI: @@ -43,13 +43,13 @@ ldi r20, pm_hi8(-(a)) ; R_AVR_HI8_LDI_PM_NEG ldi r20, pm_hh8(-(a)) ; R_AVR_HH8_LDI_PM_NEG -;; The disassembler is not yet able to decode those opcodes -;; 9e 8e std Y+30, r9 -;; 9e 8c ldd r9, Y+30 -;; 4e 96 adiw r24, 0x1e .section .SIX,"ax",@progbits -; HEX-LABEL: section .SIX: -; HEX-NEXT: 9e8e9e8c 4e96 +; CHECK-LABEL: section .SIX: +; CHECK: std Y+30, r9 +; CHECK-NEXT: ldd r9, Y+30 +; CHECK-NEXT: adiw r24, 0x1e +; HEX-LABEL: section .SIX: +; HEX-NEXT: 9e8e9e8c 4e96 std Y+b, r9 ; R_AVR_6 ldd r9, Y+b ; R_AVR_6 adiw r24, b ; R_AVR_6_ADIW @@ -75,6 +75,15 @@ breq foo + 32 ; R_AVR_7_PCREL breq foo - 32 ; R_AVR_7_PCREL +.section .LDSSTS,"ax",@progbits +; CHECK-LABEL: section .LDSSTS: +; CHECK: lds r20, 0x1e +; CHECK-NEXT: sts 0x1e, r21 +; HEX-LABEL: section .LDSSTS: +; HEX: {{.*}} 40911e00 50931e00 +lds r20, b ; R_AVR_16 +sts b, r21 ; R_AVR_16 + .section .DATA,"ax",@progbits ; HEX-LABEL: section .DATA: ; HEX-NEXT: {{.*}} 1e1e000f 00785634 12 Index: lld/test/ELF/avrtiny-reloc.s =================================================================== --- /dev/null +++ lld/test/ELF/avrtiny-reloc.s @@ -0,0 +1,69 @@ +; REQUIRES: avr +; RUN: llvm-mc -filetype=obj -triple=avr -mcpu=attiny10 %s -o %t.o +; RUN: ld.lld %t.o --defsym=a=0x12345678 --defsym=b=30 -o %t +; RUN: llvm-objdump -d --print-imm-hex --mcpu=attiny10 %t | FileCheck %s +; RUN: llvm-objdump -s --mcpu=attiny10 %t | FileCheck --check-prefix=HEX %s + +.section .LDI,"ax",@progbits +; CHECK-LABEL: section .LDI: +; CHECK: ldi r20, 0x78 +; CHECK-NEXT: ldi r20, 0x56 +; CHECK-NEXT: ldi r20, 0x34 +; CHECK-NEXT: ldi r20, 0x12 +; CHECK-NEXT: ldi r20, 0x3c +; CHECK-NEXT: ldi r20, 0x2b +; CHECK-NEXT: ldi r20, 0x1a +; CHECK-NEXT: ldi r20, 0xff +ldi r20, lo8(a) ; R_AVR_LO8_LDI +ldi r20, hi8(a) ; R_AVR_HI8_LDI +ldi r20, hh8(a) ; R_AVR_HH8_LDI +ldi r20, hhi8(a) ; R_AVR_MS8_LDI +ldi r20, pm_lo8(a) ; R_AVR_LO8_LDI_PM +ldi r20, pm_hi8(a) ; R_AVR_HI8_LDI_PM +ldi r20, pm_hh8(a) ; R_AVR_HH8_LDI_PM +ldi r20, b+225 ; R_AVR_LDI + + +.section .LDI_NEG,"ax",@progbits +; CHECK-LABEL: section .LDI_NEG: +; CHECK: ldi r20, 0x88 +; CHECK-NEXT: ldi r20, 0xa9 +; CHECK-NEXT: ldi r20, 0xcb +; CHECK-NEXT: ldi r20, 0xed +; CHECK-NEXT: ldi r20, 0xc4 +; CHECK-NEXT: ldi r20, 0xd4 +; CHECK-NEXT: ldi r20, 0xe5 +ldi r20, lo8(-(a)) ; R_AVR_LO8_LDI_NEG +ldi r20, hi8(-(a)) ; R_AVR_HI8_LDI_NEG +ldi r20, hh8(-(a)) ; R_AVR_HH8_LDI_NEG +ldi r20, hhi8(-(a)) ; R_AVR_MS8_LDI_NEG +ldi r20, pm_lo8(-(a)) ; R_AVR_LO8_LDI_PM_NEG +ldi r20, pm_hi8(-(a)) ; R_AVR_HI8_LDI_PM_NEG +ldi r20, pm_hh8(-(a)) ; R_AVR_HH8_LDI_PM_NEG + + +.section .PORT,"ax",@progbits +; CHECK-LABEL: section .PORT: +; CHECK: in r20, 0x1e +; CHECK-NEXT: sbic 0x1e, 0x1 +in r20, b ; R_AVR_PORT6 +sbic b, 1 ; R_AVR_PORT5 + + +.section .LDSSTS,"ax",@progbits +; CHECK-LABEL: section .LDSSTS: +; CHECK: lds r20, 0x1e +; CHECK-NEXT: sts 0x1e, r21 +; HEX-LABEL: section .LDSSTS: +; HEX: {{.*}} 4ea15ea9 +lds r20, b ; R_AVR_LDS_STS_16 +sts b, r21 ; R_AVR_LDS_STS_16 + + +.section .DATA,"ax",@progbits +; HEX-LABEL: section .DATA: +; HEX-NEXT: {{.*}} 1e1e000f 00785634 12 +.byte b ; R_AVR_8 +.short b ; R_AVR_16 +.short gs(b) ; R_AVR_16_PM +.long a ; R_AVR_32