|
| 1 | +# REQUIRES: hexagon |
| 2 | +# RUN: rm -rf %t && split-file %s %t && cd %t |
| 3 | +# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf main.s -o main.o |
| 4 | +# RUN: ld.lld main.o -o test |
| 5 | +# RUN: llvm-objdump -d --no-show-raw-insn test | FileCheck %s |
| 6 | + |
| 7 | +## Test thunk range scenarios for Hexagon R_HEX_B22_PCREL relocations. |
| 8 | +## R_HEX_B22_PCREL has a range of +/- 8MB (0x800000 bytes). |
| 9 | + |
| 10 | +#--- main.s |
| 11 | +.globl _start |
| 12 | +.type _start, %function |
| 13 | +_start: |
| 14 | + call target_within_range_max |
| 15 | + call target_beyond_range |
| 16 | + call target_within_range_min |
| 17 | + call target_beyond_range_min |
| 18 | + call target_multiple_calls |
| 19 | + call target_multiple_calls |
| 20 | + call target_close |
| 21 | + jumpr r31 |
| 22 | + |
| 23 | +target_close: |
| 24 | + jumpr r31 |
| 25 | + |
| 26 | +## Target at maximum positive range (8MB - 4 bytes from _start) |
| 27 | +## We need to account for the instructions above: 7 calls + 1 jumpr = 8 * 4 = 32 bytes |
| 28 | +.skip 0X7fffbc |
| 29 | +.globl target_within_range_max |
| 30 | +.type target_within_range_max, %function |
| 31 | +target_within_range_max: |
| 32 | + jumpr r31 |
| 33 | + |
| 34 | +## Target just beyond maximum positive range (needs thunk) |
| 35 | +.skip 8 |
| 36 | +.globl target_beyond_range |
| 37 | +.type target_beyond_range, %function |
| 38 | +target_beyond_range: |
| 39 | + call target_within_range_max |
| 40 | + jumpr r31 |
| 41 | + |
| 42 | +## Target for multiple calls test |
| 43 | +.skip 0x100000 |
| 44 | +.globl target_multiple_calls |
| 45 | +.type target_multiple_calls, %function |
| 46 | +target_multiple_calls: |
| 47 | + jumpr r31 |
| 48 | + |
| 49 | +## Now place targets at maximum negative range |
| 50 | +## We'll put these before _start in memory layout |
| 51 | +.section .text_negative, "ax", %progbits |
| 52 | + |
| 53 | +## Target at maximum negative range (-8MB + 4 bytes from _start) |
| 54 | +.globl target_within_range_min |
| 55 | +.type target_within_range_min, %function |
| 56 | +target_within_range_min: |
| 57 | + call target_close |
| 58 | + jumpr r31 |
| 59 | + |
| 60 | +.skip 0X7ffff4 |
| 61 | + |
| 62 | +## Target beyond maximum negative range (needs thunk) |
| 63 | +.globl target_beyond_range_min |
| 64 | +.type target_beyond_range_min, %function |
| 65 | +target_beyond_range_min: |
| 66 | + jumpr r31 |
| 67 | + |
| 68 | +## Verify thunk generation for targets beyond B22_PCREL range |
| 69 | +# CHECK: 000200b4 <__hexagon_thunk_target_within_range_min_from_.text.thunk>: |
| 70 | +# CHECK-NEXT: 200b4: { immext(#0x900000) |
| 71 | +# CHECK-NEXT: 200b8: jump 0x9200cc } |
| 72 | + |
| 73 | +# CHECK: 000200bc <__hexagon_thunk_target_beyond_range_min_from_.text.thunk>: |
| 74 | +# CHECK-NEXT: 200bc: { immext(#0x1100000) |
| 75 | +# CHECK-NEXT: 200c0: jump 0x11200c8 } |
| 76 | + |
| 77 | +# CHECK: 000200c4 <__hexagon_thunk_target_multiple_calls_from_.text.thunk>: |
| 78 | +# CHECK-NEXT: 200c4: { immext(#0x8fffc0) |
| 79 | +# CHECK-NEXT: 200c8: jump 0x9200c0 } |
| 80 | + |
| 81 | +## Verify _start calls - some direct, some via thunks |
| 82 | +# CHECK: 000200cc <_start>: |
| 83 | +# CHECK-NEXT: 200cc: { call 0x8200ac } |
| 84 | +# CHECK-NEXT: 200d0: { call 0x8200b8 } |
| 85 | +# CHECK-NEXT: 200d4: { call 0x200b4 } |
| 86 | +# CHECK-NEXT: 200d8: { call 0x200bc } |
| 87 | +# CHECK-NEXT: 200dc: { call 0x200c4 } |
| 88 | +# CHECK-NEXT: 200e0: { call 0x200c4 } |
| 89 | +# CHECK-NEXT: 200e4: { call 0x200ec } |
| 90 | + |
| 91 | +# CHECK: 000200ec <target_close>: |
| 92 | +# CHECK-NEXT: 200ec: { jumpr r31 } |
| 93 | + |
| 94 | +## Verify targets at maximum positive range (direct calls, no thunks needed) |
| 95 | +# CHECK: 008200ac <target_within_range_max>: |
| 96 | +# CHECK-NEXT: 8200ac: { jumpr r31 } |
| 97 | + |
| 98 | +# CHECK: 008200b8 <target_beyond_range>: |
| 99 | +# CHECK-NEXT: 8200b8: { call 0x8200ac } |
| 100 | +# CHECK-NEXT: 8200bc: { jumpr r31 } |
| 101 | + |
| 102 | +# CHECK: 009200c0 <target_multiple_calls>: |
| 103 | +# CHECK-NEXT: 9200c0: { jumpr r31 } |
| 104 | + |
| 105 | +## Verify targets in negative section and thunk for calling back to main section |
| 106 | +# CHECK: 009200c4 <__hexagon_thunk__from_.text.thunk>: |
| 107 | +# CHECK-NEXT: 9200c4: { immext(#0xff700000) |
| 108 | +# CHECK-NEXT: 9200c8: jump 0x200cc } |
| 109 | + |
| 110 | +# CHECK: 009200cc <target_within_range_min>: |
| 111 | +# CHECK-NEXT: 9200cc: { call 0x9200c4 } |
| 112 | +# CHECK-NEXT: 9200d0: { jumpr r31 } |
| 113 | + |
| 114 | +# CHECK: 011200c8 <target_beyond_range_min>: |
| 115 | +# CHECK-NEXT: 11200c8: { jumpr r31 } |
0 commit comments