summaryrefslogtreecommitdiff
path: root/lld/test
diff options
context:
space:
mode:
authorBen Shi <powerman1st@163.com>2023-03-29 11:55:54 +0800
committerBen Shi <powerman1st@163.com>2023-04-28 11:42:06 +0800
commit229fcad7fc41bf4d1fcf106456bc429f85b37eab (patch)
treef1255819fa3914a300a9910116146a84106cb06b /lld/test
parent81d06268f47f089335076eb608c880fc0e60a677 (diff)
downloadllvm-229fcad7fc41bf4d1fcf106456bc429f85b37eab.tar.gz
[lld][ELF] Support relocations R_AVR_LO8_LDI_GS/R_AVR_HI8_LDI_GS
Relocations R_AVR_LO8_LDI_GS/R_AVR_HI8_LDI_GS (indirect calls via function pointers) only cover range 128KiB. They are equivalent to R_AVR_LO8_LDI_PM/R_AVR_HI8_LDI_PM within this range. But for function addresses beyond this range, GNU-ld emits trampolines. And this patch implements corresponding thunks for them in lld. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D147364
Diffstat (limited to 'lld/test')
-rw-r--r--lld/test/ELF/avr-reloc.s10
-rw-r--r--lld/test/ELF/avr-thunk-ldi-gs.s33
2 files changed, 41 insertions, 2 deletions
diff --git a/lld/test/ELF/avr-reloc.s b/lld/test/ELF/avr-reloc.s
index 36904f80dabb..172c0e03ba74 100644
--- a/lld/test/ELF/avr-reloc.s
+++ b/lld/test/ELF/avr-reloc.s
@@ -1,12 +1,12 @@
; REQUIRES: avr
; RUN: llvm-mc -filetype=obj -triple=avr -mcpu=atmega328p %s -o %t0.o
-; RUN: ld.lld %t0.o --defsym=a=0x12345678 --defsym=b=30 -o %t0
+; RUN: ld.lld %t0.o --defsym=a=0x12345678 --defsym=b=30 --defsym=c=0x15554 -o %t0
; RUN: llvm-objdump -d --print-imm-hex --mcpu=atmega328p %t0 | \
; RUN: FileCheck --check-prefixes=CHECK,AVR %s
; RUN: llvm-objdump -s --mcpu=atmega328p %t0 | \
; RUN: FileCheck --check-prefixes=HEX,AVRHEX %s
; RUN: llvm-mc -filetype=obj -triple=avr -mcpu=attiny10 %s --defsym=TINY=1 -o %t1.o
-; RUN: ld.lld %t1.o --defsym=a=0x12345678 --defsym=b=30 -o %t1
+; RUN: ld.lld %t1.o --defsym=a=0x12345678 --defsym=b=30 --defsym=c=0x15554 -o %t1
; RUN: llvm-objdump -d --print-imm-hex --mcpu=attiny10 %t1 | FileCheck %s
; RUN: llvm-objdump -s --mcpu=attiny10 %t1 | \
; RUN: FileCheck --check-prefixes=HEX,TINYHEX %s
@@ -20,7 +20,10 @@
; CHECK-NEXT: ldi r20, 0x3c
; CHECK-NEXT: ldi r20, 0x2b
; CHECK-NEXT: ldi r20, 0x1a
+; CHECK-NEXT: ldi r20, 0xaa
+; CHECK-NEXT: ldi r20, 0xaa
; 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
@@ -30,6 +33,9 @@ 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, lo8_gs(c) ; R_AVR_LO8_LDI_GS
+ldi r20, hi8_gs(c) ; R_AVR_HI8_LDI_GS
+
ldi r20, b+225
.section .LDI_NEG,"ax",@progbits
diff --git a/lld/test/ELF/avr-thunk-ldi-gs.s b/lld/test/ELF/avr-thunk-ldi-gs.s
new file mode 100644
index 000000000000..58de33780ba1
--- /dev/null
+++ b/lld/test/ELF/avr-thunk-ldi-gs.s
@@ -0,0 +1,33 @@
+; REQUIRES: avr
+; RUN: llvm-mc -filetype=obj -triple=avr -mcpu=atmega2560 %s -o %t.o
+; RUN: ld.lld %t.o --defsym=a=0x1fffe --defsym=b=0x20000 -o %t
+; RUN: llvm-objdump -d --print-imm-hex --no-show-raw-insn --mcpu=atmega2560 %t \
+; RUN: | FileCheck %s
+
+.section .LDI,"ax",@progbits
+
+;; CHECK-LABEL: <__AVRThunk_b>:
+;; CHECK-NEXT: 110b4: jmp 0x20000
+;; CHECK-LABEL: <__init>:
+;; CHECK-NEXT: 110b8: ldi r30, 0xff
+;; CHECK-NEXT: 110ba: ldi r31, 0xff
+;; CHECK-NEXT: 110bc: eicall
+;; The destination of the following two LDI instructions is
+;; __AVRThunk_b == 0x110b4, so they actually are
+;; ldi r30, ((0x110b4) >> 1) & 0xff
+;; ldi r31, ((0x110b4) >> 9)
+;; CHECK-NEXT: 110be: ldi r30, 0x5a
+;; CHECK-NEXT: 110c0: ldi r31, 0x88
+;; CHECK-NEXT: 110c2: eicall
+;; CHECK-NOT: __AVRThunk_a
+
+.globl __init
+__init:
+;; No thunk is needed, since the destination is in range [0, 0x1ffff].
+ldi r30, lo8_gs(a) ; R_AVR_LO8_LDI_GS
+ldi r31, hi8_gs(a) ; R_AVR_HI8_LDI_GS
+eicall
+;; A thunk is needed, since the destination is out of range.
+ldi r30, lo8_gs(b) ; R_AVR_LO8_LDI_GS
+ldi r31, hi8_gs(b) ; R_AVR_HI8_LDI_GS
+eicall