133 lines · plain
1# REQUIRES: aarch642# RUN: rm -rf %t && split-file %s %t3 4# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/a.s -o %t/a.o5# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/unpaired.s -o %t/unpaired.o6# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/lone-ldr.s -o %t/lone-ldr.o7 8# RUN: ld.lld %t/a.o -T %t/out-of-adr-range.t -o %t/a9# RUN: llvm-objdump --no-show-raw-insn -d %t/a | FileCheck %s10 11## Symbol 'x' is nonpreemptible, the relaxation should be applied.12## This test verifies the encoding when the register x1 is used.13# CHECK: adrp x114# CHECK-NEXT: add x1, x115 16## ADRP contains a nonzero addend, no relaxations should be applied.17# CHECK-NEXT: adrp x218# CHECK-NEXT: ldr19 20## LDR contains a nonzero addend, no relaxations should be applied.21# CHECK-NEXT: adrp x322# CHECK-NEXT: ldr23 24## LDR and ADRP use different registers, no relaxations should be applied.25# CHECK-NEXT: adrp x426# CHECK-NEXT: ldr27 28## LDR and ADRP use different registers, no relaxations should be applied.29# CHECK-NEXT: adrp x630# CHECK-NEXT: ldr31 32# RUN: ld.lld %t/a.o -T %t/within-adr-range.t -o %t/a33# RUN: llvm-objdump --no-show-raw-insn -d %t/a | FileCheck --check-prefix=ADR %s34 35## Symbol 'x' is nonpreemptible, the relaxation should be applied.36# ADR: nop37# ADR-NEXT: adr x138 39## Symbol 'x' is nonpreemptible, but --no-relax surpresses relaxations.40# RUN: ld.lld %t/a.o -T %t/out-of-adr-range.t --no-relax -o %t/no-relax41# RUN: llvm-objdump --no-show-raw-insn -d %t/no-relax | \42# RUN: FileCheck --check-prefix=X1-NO-RELAX %s43 44# X1-NO-RELAX: adrp x145# X1-NO-RELAX-NEXT: ldr46 47## Symbol 'x' is nonpreemptible, but the address is not within adrp range.48# RUN: ld.lld %t/a.o -T %t/out-of-range.t -o %t/out-of-range49# RUN: llvm-objdump --no-show-raw-insn -d %t/out-of-range | \50# RUN: FileCheck --check-prefix=X1-NO-RELAX %s51 52## Relocations do not appear in pairs, no relaxations should be applied.53# RUN: ld.lld %t/unpaired.o -o %t/unpaired54# RUN: llvm-objdump --no-show-raw-insn -d %t/unpaired | \55# RUN: FileCheck --check-prefix=UNPAIRED %s56 57# UNPAIRED: adrp x058# UNPAIRED-NEXT: b59# UNPAIRED-NEXT: adrp x060# UNPAIRED: ldr x061 62## Relocations do not appear in pairs, no relaxations should be applied.63# RUN: ld.lld %t/lone-ldr.o -o %t/lone-ldr64# RUN: llvm-objdump --no-show-raw-insn -d %t/lone-ldr | \65# RUN: FileCheck --check-prefix=LONE-LDR %s66 67# LONE-LDR: ldr x068 69## This linker script ensures that .rodata and .text are sufficiently (>1M)70## far apart so that the adrp + ldr pair cannot be relaxed to adr + nop.71#--- out-of-adr-range.t72SECTIONS {73 .rodata 0x1000: { *(.rodata) }74 .text 0x200100: { *(.text) }75}76 77## This linker script ensures that .rodata and .text are sufficiently (<1M)78## close to each other so that the adrp + ldr pair can be relaxed to nop + adr.79#--- within-adr-range.t80SECTIONS {81 .rodata 0x1000: { *(.rodata) }82 .text 0x2000: { *(.text) }83}84 85## This linker script ensures that .rodata and .text are sufficiently (>4GB)86## far apart so that the adrp + ldr pair cannot be relaxed.87#--- out-of-range.t88SECTIONS {89 .rodata 0x1000: { *(.rodata) }90 .text 0x100002000: { *(.text) }91}92 93#--- a.s94.rodata95.hidden x96x:97.word 1098.text99.global _start100_start:101 adrp x1, :got:x102 ldr x1, [x1, #:got_lo12:x]103 adrp x2, :got:x+1104 ldr x2, [x2, #:got_lo12:x]105 adrp x3, :got:x106 ldr x3, [x3, #:got_lo12:x+8]107 adrp x4, :got:x108 ldr x5, [x4, #:got_lo12:x]109 adrp x6, :got:x110 ldr x6, [x0, #:got_lo12:x]111 112#--- unpaired.s113.text114.hidden x115x:116 nop117.global _start118_start:119 adrp x0, :got:x120 b L121 adrp x0, :got:x122L:123 ldr x0, [x0, #:got_lo12:x]124 125#--- lone-ldr.s126.text127.hidden x128x:129 nop130.global _start131_start:132 ldr x0, [x0, #:got_lo12:x]133