|
| 1 | +# RUN: rm -rf %t && split-file %s %t |
| 2 | +# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/use.s -o %t/use-le.o |
| 3 | +# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/def.s -o %t/def-le.o |
| 4 | +# RUN: llvm-mc -filetype=obj -triple=aarch64 %t/rel.s -o %t/rel-le.o |
| 5 | + |
| 6 | +## Deactivation symbol used without being defined: instruction emitted as usual. |
| 7 | +# RUN: ld.lld -o %t/undef-le %t/use-le.o --emit-relocs |
| 8 | +# RUN: llvm-objdump -r %t/undef-le | FileCheck --check-prefix=RELOC %s |
| 9 | +# RUN: llvm-objdump -d %t/undef-le | FileCheck --check-prefix=UNDEF %s |
| 10 | +# RUN: ld.lld -pie -o %t/undef-le %t/use-le.o --emit-relocs |
| 11 | +# RUN: llvm-objdump -r %t/undef-le | FileCheck --check-prefix=RELOC %s |
| 12 | +# RUN: llvm-objdump -d %t/undef-le | FileCheck --check-prefix=UNDEF %s |
| 13 | + |
| 14 | +## Deactivation symbol defined: instructions overwritten with NOPs. |
| 15 | +# RUN: ld.lld -o %t/def-le %t/use-le.o %t/def-le.o --emit-relocs |
| 16 | +# RUN: llvm-objdump -r %t/def-le | FileCheck --check-prefix=RELOC %s |
| 17 | +# RUN: llvm-objdump -d %t/def-le | FileCheck --check-prefix=DEF %s |
| 18 | +# RUN: ld.lld -pie -o %t/def-le %t/use-le.o %t/def-le.o --emit-relocs |
| 19 | +# RUN: llvm-objdump -r %t/def-le | FileCheck --check-prefix=RELOC %s |
| 20 | +# RUN: llvm-objdump -d %t/def-le | FileCheck --check-prefix=DEF %s |
| 21 | + |
| 22 | +## Relocation pointing to a non-SHN_UNDEF non-SHN_ABS symbol is an error. |
| 23 | +# RUN: not ld.lld -o %t/rel-le %t/use-le.o %t/rel-le.o 2>&1 | FileCheck --check-prefix=ERROR %s |
| 24 | +# RUN: not ld.lld -pie -o %t/rel-le %t/use-le.o %t/rel-le.o 2>&1 | FileCheck --check-prefix=ERROR %s |
| 25 | + |
| 26 | +## Behavior unchanged by endianness: relocation always written as little endian. |
| 27 | +# RUN: llvm-mc -filetype=obj -triple=aarch64_be %t/use.s -o %t/use-be.o |
| 28 | +# RUN: llvm-mc -filetype=obj -triple=aarch64_be %t/def.s -o %t/def-be.o |
| 29 | +# RUN: llvm-mc -filetype=obj -triple=aarch64_be %t/rel.s -o %t/rel-be.o |
| 30 | +# RUN: ld.lld -o %t/undef-be %t/use-be.o --emit-relocs |
| 31 | +# RUN: llvm-objdump -r %t/undef-be | FileCheck --check-prefix=RELOC %s |
| 32 | +# RUN: llvm-objdump -d %t/undef-be | FileCheck --check-prefix=UNDEF %s |
| 33 | +# RUN: ld.lld -pie -o %t/undef-be %t/use-be.o --emit-relocs |
| 34 | +# RUN: llvm-objdump -r %t/undef-be | FileCheck --check-prefix=RELOC %s |
| 35 | +# RUN: llvm-objdump -d %t/undef-be | FileCheck --check-prefix=UNDEF %s |
| 36 | +# RUN: ld.lld -o %t/def-be %t/use-be.o %t/def-be.o --emit-relocs |
| 37 | +# RUN: llvm-objdump -r %t/def-be | FileCheck --check-prefix=RELOC %s |
| 38 | +# RUN: llvm-objdump -d %t/def-be | FileCheck --check-prefix=DEF %s |
| 39 | +# RUN: ld.lld -pie -o %t/def-be %t/use-be.o %t/def-be.o --emit-relocs |
| 40 | +# RUN: llvm-objdump -r %t/def-be | FileCheck --check-prefix=RELOC %s |
| 41 | +# RUN: llvm-objdump -d %t/def-be | FileCheck --check-prefix=DEF %s |
| 42 | +# RUN: not ld.lld -o %t/rel-be %t/use-be.o %t/rel-be.o 2>&1 | FileCheck --check-prefix=ERROR %s |
| 43 | +# RUN: not ld.lld -pie -o %t/rel-be %t/use-be.o %t/rel-be.o 2>&1 | FileCheck --check-prefix=ERROR %s |
| 44 | + |
| 45 | +# RELOC: R_AARCH64_JUMP26 |
| 46 | +# RELOC-NEXT: R_AARCH64_PATCHINST ds |
| 47 | +# RELOC-NEXT: R_AARCH64_PATCHINST ds |
| 48 | +# RELOC-NEXT: R_AARCH64_PATCHINST ds0+0xd503201f |
| 49 | + |
| 50 | +#--- use.s |
| 51 | +.weak ds |
| 52 | +.weak ds0 |
| 53 | +# This instruction has a single relocation: the DS relocation. |
| 54 | +# UNDEF: add x0, x1, x2 |
| 55 | +# DEF: nop |
| 56 | +# ERROR: R_AARCH64_PATCHINST relocation against non-absolute symbol ds |
| 57 | +.reloc ., R_AARCH64_PATCHINST, ds |
| 58 | +add x0, x1, x2 |
| 59 | +# This instruction has two relocations: the DS relocation and the JUMP26 to f1. |
| 60 | +# Make sure that the DS relocation takes precedence. |
| 61 | +.reloc ., R_AARCH64_PATCHINST, ds |
| 62 | +# UNDEF: b {{.*}} <f1> |
| 63 | +# DEF: nop |
| 64 | +# ERROR: R_AARCH64_PATCHINST relocation against non-absolute symbol ds |
| 65 | +b f1 |
| 66 | +# Alternative representation: instruction opcode stored in addend. |
| 67 | +# UNDEF: add x3, x4, x5 |
| 68 | +# DEF: nop |
| 69 | +# ERROR: R_AARCH64_PATCHINST relocation against non-absolute symbol ds0 |
| 70 | +.reloc ., R_AARCH64_PATCHINST, ds0 + 0xd503201f |
| 71 | +add x3, x4, x5 |
| 72 | + |
| 73 | +.section .text.f1,"ax",@progbits |
| 74 | +f1: |
| 75 | +ret |
| 76 | + |
| 77 | +#--- def.s |
| 78 | +.globl ds |
| 79 | +ds = 0xd503201f |
| 80 | +.globl ds0 |
| 81 | +ds0 = 0 |
| 82 | + |
| 83 | +#--- rel.s |
| 84 | +.globl ds |
| 85 | +ds: |
| 86 | +.globl ds0 |
| 87 | +ds0: |
0 commit comments