1// REQUIRES: arm
2// RUN: llvm-mc -filetype=obj -triple=thumbv7-windows %s -o %t.obj
3// RUN: lld-link -entry:main -subsystem:console %t.obj -out:%t.exe -verbose 2>&1 | FileCheck -check-prefix=VERBOSE %s
4// RUN: llvm-objdump -d %t.exe --start-address=0x401000 --stop-address=0x401022 | FileCheck --check-prefix=MAIN %s
5// RUN: llvm-objdump -d %t.exe --start-address=0x501022 --stop-address=0x501032 | FileCheck --check-prefix=FUNC1 %s
6// RUN: llvm-objdump -d %t.exe --start-address=0x601032 | FileCheck --check-prefix=FUNC2 %s
7
8// VERBOSE: Added 3 thunks with margin {{.*}} in 1 passes
9
10    .syntax unified
11    .globl main
12    .globl func1
13    .text
14main:
15    bne func1
16    bne func2
17    // This should reuse the same thunk as func1 above
18    bne func1_alias
19    bx lr
20    .section .text$a, "xr"
21    .space 0x100000
22    .section .text$b, "xr"
23func1:
24func1_alias:
25    // This shouldn't reuse the func2 thunk from above, since it is out
26    // of range.
27    bne func2
28    bx lr
29    .section .text$c, "xr"
30    .space 0x100000
31    .section .text$d, "xr"
32func2:
33// Test using string tail merging. This is irrelevant to the thunking itself,
34// but running multiple passes of assignAddresses() calls finalizeAddresses()
35// multiple times; check that MergeChunk handles this correctly.
36    movw r0, :lower16:"??_C@string1"
37    movt r0, :upper16:"??_C@string1"
38    movw r1, :lower16:"??_C@string2"
39    movt r1, :upper16:"??_C@string2"
40    bx lr
41
42    .section .rdata,"dr",discard,"??_C@string1"
43    .globl "??_C@string1"
44"??_C@string1":
45    .asciz "foobar"
46    .section .rdata,"dr",discard,"??_C@string2"
47    .globl "??_C@string2"
48"??_C@string2":
49    .asciz "bar"
50
51// MAIN:    401000:       40 f0 05 80     bne.w   #10 <.text+0xe>
52// MAIN:    401004:       40 f0 08 80     bne.w   #16 <.text+0x18>
53// MAIN:    401008:       40 f0 01 80     bne.w   #2 <.text+0xe>
54// MAIN:    40100c:       70 47           bx      lr
55// func1 thunk
56// MAIN:    40100e:       40 f2 08 0c     movw    r12, #8
57// MAIN:    401012:       c0 f2 10 0c     movt    r12, #16
58// MAIN:    401016:       e7 44           add     pc,  r12
59// func2 thunk
60// MAIN:    401018:       40 f2 0e 0c     movw    r12, #14
61// MAIN:    40101c:       c0 f2 20 0c     movt    r12, #32
62// MAIN:    401020:       e7 44           add     pc,  r12
63
64// FUNC1:   501022:       40 f0 01 80     bne.w   #2 <.text+0x100028>
65// FUNC1:   501026:       70 47           bx      lr
66// func2 thunk
67// FUNC1:   501028:       4f f6 fe 7c     movw    r12, #65534
68// FUNC1:   50102c:       c0 f2 0f 0c     movt    r12, #15
69// FUNC1:   501030:       e7 44           add     pc,  r12
70
71// FUNC2:   601032:       42 f2 00 00     movw    r0, #8192
72// FUNC2:   601036:       c0 f2 60 00     movt    r0, #96
73// FUNC2:   60103a:       42 f2 03 01     movw    r1, #8195
74// FUNC2:   60103e:       c0 f2 60 01     movt    r1, #96
75// FUNC2:   601042:       70 47   bx      lr
76