| 1 | // Test PLT section parsing on arm. |
| 2 | |
| 3 | // REQUIRES: ld.lld |
| 4 | |
| 5 | // RUN: %clang --target=armv6a-none-linux-gnueabi -fuse-ld=lld \ |
| 6 | // RUN: -nostdlib -nostdinc -shared %s -o %t.v6a |
| 7 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 8 | // RUN: -d %t.v6a | FileCheck %s --check-prefixes=CHECK,LE |
| 9 | |
| 10 | // Test PLT section parsing on armeb. |
| 11 | |
| 12 | // RUN: %clang --target=armv6aeb-none-linux-gnueabi -fuse-ld=lld \ |
| 13 | // RUN: -nostdlib -nostdinc -shared %s -o %t.v6aeb |
| 14 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 15 | // RUN: -d %t.v6aeb | FileCheck %s --check-prefixes=CHECK,BE |
| 16 | // RUN: obj2yaml %t.v6aeb | FileCheck %s --check-prefixes=NOBE8 |
| 17 | |
| 18 | // Test PLT section parsing on armeb with be8. |
| 19 | |
| 20 | // RUN: %clang --target=armv7aeb-none-linux-gnueabi -fuse-ld=lld \ |
| 21 | // RUN: -nostdlib -nostdinc -shared %s -o %t.v7aeb |
| 22 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 23 | // RUN: -d %t.v7aeb | FileCheck %s --check-prefixes=CHECK,BE |
| 24 | // RUN: obj2yaml %t.v7aeb | FileCheck %s --check-prefixes=BE8 |
| 25 | |
| 26 | // LE: file format elf32-littlearm |
| 27 | // BE: file format elf32-bigarm |
| 28 | // NOBE8-NOT: EF_ARM_BE8 |
| 29 | // BE8: EF_ARM_BE8 |
| 30 | |
| 31 | // CHECK: Disassembly of section .text: |
| 32 | // CHECK-EMPTY: |
| 33 | // CHECK-NEXT: <_start>: |
| 34 | // CHECK-NEXT: push {r11, lr} |
| 35 | // CHECK-NEXT: mov r11, sp |
| 36 | // CHECK-NEXT: bl {{.*}} <func1@plt> |
| 37 | // CHECK-NEXT: bl {{.*}} <func2@plt> |
| 38 | // CHECK-NEXT: bl {{.*}} <func3@plt> |
| 39 | |
| 40 | // CHECK: Disassembly of section .plt: |
| 41 | // CHECK: <func1@plt>: |
| 42 | // CHECK-NEXT: add r12, pc, #0, #12 |
| 43 | // CHECK-NEXT: add r12, r12, #32, #20 |
| 44 | // CHECK-NEXT: ldr pc, [r12, #132]! |
| 45 | // CHECK-NEXT: .word 0xd4d4d4d4 |
| 46 | // CHECK-EMPTY: |
| 47 | // CHECK-NEXT: <func2@plt>: |
| 48 | // CHECK-NEXT: add r12, pc, #0, #12 |
| 49 | // CHECK-NEXT: add r12, r12, #32, #20 |
| 50 | // CHECK-NEXT: ldr pc, [r12, #120]! |
| 51 | // CHECK-NEXT: .word 0xd4d4d4d4 |
| 52 | // CHECK-EMPTY: |
| 53 | // CHECK-NEXT: <func3@plt>: |
| 54 | // CHECK-NEXT: add r12, pc, #0, #12 |
| 55 | // CHECK-NEXT: add r12, r12, #32, #20 |
| 56 | // CHECK-NEXT: ldr pc, [r12, #108]! |
| 57 | // CHECK-NEXT: .word 0xd4d4d4d4 |
| 58 | |
| 59 | // Test PLT section parsing on thumb. |
| 60 | |
| 61 | // RUN: %clang --target=thumbv8.1m.main-none-linux-eabi \ |
| 62 | // RUN: -c %s -o %t.v8.o |
| 63 | // RUN: ld.lld --shared %t.v8.o -o %t.v8 |
| 64 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 65 | // RUN: -d %t.v8 | FileCheck %s --check-prefixes=THUMB,LE |
| 66 | |
| 67 | // Test PLT section parsing on thumbeb. |
| 68 | |
| 69 | // RUN: %clang --target=thumbebv8.1m.main-none-linux-eabi \ |
| 70 | // RUN: -c %s -o %t.v8eb.o |
| 71 | // RUN: ld.lld --shared %t.v8eb.o -o %t.v8eb |
| 72 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 73 | // RUN: -d %t.v8eb | FileCheck %s --check-prefixes=THUMB,BE |
| 74 | // RUN: obj2yaml %t.v8eb | FileCheck %s --check-prefixes=NOBE8 |
| 75 | |
| 76 | // Test PLT section parsing on thumbeb with be8. |
| 77 | |
| 78 | // RUN: %clang --target=thumbebv8.1m.main-none-linux-eabi \ |
| 79 | // RUN: -c %s -o %t.v8eb.be8.o |
| 80 | // RUN: ld.lld --shared --be8 %t.v8eb.be8.o -o %t.v8eb.be8 |
| 81 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 82 | // RUN: -d %t.v8eb.be8 | FileCheck %s --check-prefixes=THUMB,BE |
| 83 | // RUN: obj2yaml %t.v8eb.be8 | FileCheck %s --check-prefixes=BE8 |
| 84 | |
| 85 | // THUMB: Disassembly of section .text: |
| 86 | // THUMB-EMPTY: |
| 87 | // THUMB-NEXT: <_start>: |
| 88 | // THUMB-NEXT: push {r7, lr} |
| 89 | // THUMB-NEXT: mov r7, sp |
| 90 | // THUMB-NEXT: bl {{.*}} <func1@plt> |
| 91 | // THUMB-NEXT: bl {{.*}} <func2@plt> |
| 92 | // THUMB-NEXT: bl {{.*}} <func3@plt> |
| 93 | |
| 94 | // THUMB: Disassembly of section .plt: |
| 95 | // THUMB-EMPTY: |
| 96 | // THUMB: <func1@plt>: |
| 97 | // THUMB-NEXT: movw r12, #136 |
| 98 | // THUMB-NEXT: movt r12, #2 |
| 99 | // THUMB-NEXT: add r12, pc |
| 100 | // THUMB-NEXT: ldr.w pc, [r12] |
| 101 | // THUMB-NEXT: b 0x |
| 102 | // THUMB-EMPTY: |
| 103 | // THUMB-NEXT: <func2@plt>: |
| 104 | // THUMB-NEXT: movw r12, #124 |
| 105 | // THUMB-NEXT: movt r12, #2 |
| 106 | // THUMB-NEXT: add r12, pc |
| 107 | // THUMB-NEXT: ldr.w pc, [r12] |
| 108 | // THUMB-NEXT: b 0x |
| 109 | // THUMB-EMPTY: |
| 110 | // THUMB-NEXT: <func3@plt>: |
| 111 | // THUMB-NEXT: movw r12, #112 |
| 112 | // THUMB-NEXT: movt r12, #2 |
| 113 | // THUMB-NEXT: add r12, pc |
| 114 | // THUMB-NEXT: ldr.w pc, [r12] |
| 115 | // THUMB-NEXT: b 0x |
| 116 | |
| 117 | // Test PLT section with long entries parsing on arm. |
| 118 | |
| 119 | // RUN: echo "SECTIONS { \ |
| 120 | // RUN: .text 0x1000 : { *(.text) } \ |
| 121 | // RUN: .plt 0x2000 : { *(.plt) *(.plt.*) } \ |
| 122 | // RUN: .got.plt 0x9000000 : { *(.got.plt) } \ |
| 123 | // RUN: }" > %t.long.script |
| 124 | |
| 125 | // RUN: %clang --target=armv6a-none-linux-gnueabi -fuse-ld=lld \ |
| 126 | // RUN: -Xlinker --script=%t.long.script -nostdlib -nostdinc \ |
| 127 | // RUN: -shared %s -o %t.v6a.long |
| 128 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 129 | // RUN: -d %t.v6a.long | FileCheck %s --check-prefixes=CHECKLONG,LE |
| 130 | |
| 131 | // Test PLT section with long entries parsing on armeb. |
| 132 | |
| 133 | // RUN: %clang --target=armv6aeb-none-linux-gnueabi -fuse-ld=lld \ |
| 134 | // RUN: -Xlinker --script=%t.long.script -nostdlib -nostdinc \ |
| 135 | // RUN: -shared %s -o %t.v6aeb.long |
| 136 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 137 | // RUN: -d %t.v6aeb.long | FileCheck %s --check-prefixes=CHECKLONG,BE |
| 138 | // RUN: obj2yaml %t.v6aeb.long | FileCheck %s --check-prefixes=NOBE8 |
| 139 | |
| 140 | // Test PLT section with long entries parsing on armeb with be8. |
| 141 | |
| 142 | // RUN: %clang --target=armv7aeb-none-linux-gnueabi -fuse-ld=lld \ |
| 143 | // RUN: -Xlinker --script=%t.long.script -nostdlib -nostdinc \ |
| 144 | // RUN: -shared %s -o %t.v7aeb.long |
| 145 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 146 | // RUN: -d %t.v7aeb.long | FileCheck %s --check-prefixes=CHECKLONG,BE |
| 147 | // RUN: obj2yaml %t.v7aeb.long | FileCheck %s --check-prefixes=BE8 |
| 148 | |
| 149 | // CHECKLONG: Disassembly of section .text: |
| 150 | // CHECKLONG-EMPTY: |
| 151 | // CHECKLONG-NEXT: <_start>: |
| 152 | // CHECKLONG-NEXT: push {r11, lr} |
| 153 | // CHECKLONG-NEXT: mov r11, sp |
| 154 | // CHECKLONG-NEXT: bl 0x2020 <func1@plt> |
| 155 | // CHECKLONG-NEXT: bl 0x2030 <func2@plt> |
| 156 | // CHECKLONG-NEXT: bl 0x2040 <func3@plt> |
| 157 | |
| 158 | // CHECKLONG: Disassembly of section .plt: |
| 159 | // CHECKLONG: 00002020 <func1@plt>: |
| 160 | // CHECKLONG-NEXT: ldr r12, [pc, #4] |
| 161 | // CHECKLONG-NEXT: add r12, r12, pc |
| 162 | // CHECKLONG-NEXT: ldr pc, [r12] |
| 163 | // CHECKLONG-NEXT: .word 0x08ffdfe0 |
| 164 | // CHECKLONG-EMPTY: |
| 165 | // CHECKLONG-NEXT: 00002030 <func2@plt>: |
| 166 | // CHECKLONG-NEXT: ldr r12, [pc, #4] |
| 167 | // CHECKLONG-NEXT: add r12, r12, pc |
| 168 | // CHECKLONG-NEXT: ldr pc, [r12] |
| 169 | // CHECKLONG-NEXT: .word 0x08ffdfd4 |
| 170 | // CHECKLONG-EMPTY: |
| 171 | // CHECKLONG-NEXT: 00002040 <func3@plt>: |
| 172 | // CHECKLONG-NEXT: ldr r12, [pc, #4] |
| 173 | // CHECKLONG-NEXT: add r12, r12, pc |
| 174 | // CHECKLONG-NEXT: ldr pc, [r12] |
| 175 | // CHECKLONG-NEXT: .word 0x08ffdfc8 |
| 176 | |
| 177 | // Test PLT section with mixed long and short entries parsing on arm. |
| 178 | |
| 179 | // RUN: echo "SECTIONS { \ |
| 180 | // RUN: .text 0x1000 : { *(.text) } \ |
| 181 | // RUN: .plt 0x2000 : { *(.plt) *(.plt.*) } \ |
| 182 | // RUN: .got.plt 0x8002020 : { *(.got.plt) } \ |
| 183 | // RUN: }" > %t.mix.script |
| 184 | |
| 185 | // RUN: %clang --target=armv6a-none-linux-gnueabi -fuse-ld=lld \ |
| 186 | // RUN: -Xlinker --script=%t.mix.script -nostdlib -nostdinc \ |
| 187 | // RUN: -shared %s -o %t.v6a.mix |
| 188 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 189 | // RUN: -d %t.v6a.mix | FileCheck %s --check-prefixes=CHECKMIX,LE |
| 190 | |
| 191 | // Test PLT section with mixed long and short entries parsing on armeb. |
| 192 | |
| 193 | // RUN: %clang --target=armv6aeb-none-linux-gnueabi -fuse-ld=lld \ |
| 194 | // RUN: -Xlinker --script=%t.mix.script -nostdlib -nostdinc \ |
| 195 | // RUN: -shared %s -o %t.v6aeb.mix |
| 196 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 197 | // RUN: -d %t.v6aeb.mix | FileCheck %s --check-prefixes=CHECKMIX,BE |
| 198 | // RUN: obj2yaml %t.v6aeb.mix | FileCheck %s --check-prefixes=NOBE8 |
| 199 | |
| 200 | // Test PLT section with mixed long and short entries parsing on armeb with be8. |
| 201 | |
| 202 | // RUN: %clang --target=armv7aeb-none-linux-gnueabi -fuse-ld=lld \ |
| 203 | // RUN: -Xlinker --script=%t.mix.script -nostdlib -nostdinc \ |
| 204 | // RUN: -shared %s -o %t.v7aeb.mix |
| 205 | // RUN: llvm-objdump --no-show-raw-insn --no-print-imm-hex \ |
| 206 | // RUN: -d %t.v7aeb.mix | FileCheck %s --check-prefixes=CHECKMIX,BE |
| 207 | // RUN: obj2yaml %t.v7aeb.mix | FileCheck %s --check-prefixes=BE8 |
| 208 | |
| 209 | // CHECKMIX: Disassembly of section .text: |
| 210 | // CHECKMIX-EMPTY: |
| 211 | // CHECKMIX-NEXT: <_start>: |
| 212 | // CHECKMIX-NEXT: push {r11, lr} |
| 213 | // CHECKMIX-NEXT: mov r11, sp |
| 214 | // CHECKMIX-NEXT: bl 0x2020 <func1@plt> |
| 215 | // CHECKMIX-NEXT: bl 0x2030 <func2@plt> |
| 216 | // CHECKMIX-NEXT: bl 0x2040 <func3@plt> |
| 217 | |
| 218 | // CHECKMIX: Disassembly of section .plt: |
| 219 | // CHECKMIX: 00002020 <func1@plt>: |
| 220 | // CHECKMIX-NEXT: ldr r12, [pc, #4] |
| 221 | // CHECKMIX-NEXT: add r12, r12, pc |
| 222 | // CHECKMIX-NEXT: ldr pc, [r12] |
| 223 | // CHECKMIX-NEXT: .word 0x08000000 |
| 224 | // CHECKMIX-EMPTY: |
| 225 | // CHECKMIX-NEXT: 00002030 <func2@plt>: |
| 226 | // CHECKMIX-NEXT: add r12, pc, #133169152 |
| 227 | // CHECKMIX-NEXT: add r12, r12, #1044480 |
| 228 | // CHECKMIX-NEXT: ldr pc, [r12, #4088]! |
| 229 | // CHECKMIX-NEXT: .word 0xd4d4d4d4 |
| 230 | // CHECKMIX-EMPTY: |
| 231 | // CHECKMIX-NEXT: 00002040 <func3@plt>: |
| 232 | // CHECKMIX-NEXT: add r12, pc, #133169152 |
| 233 | // CHECKMIX-NEXT: add r12, r12, #1044480 |
| 234 | // CHECKMIX-NEXT: ldr pc, [r12, #4076]! |
| 235 | // CHECKMIX-NEXT: .word 0xd4d4d4d4 |
| 236 | |
| 237 | extern void *func1(); |
| 238 | extern void *func2(); |
| 239 | extern void *func3(); |
| 240 | |
| 241 | void _start() { |
| 242 | func1(); |
| 243 | func2(); |
| 244 | func3(); |
| 245 | } |
| 246 | |