• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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=0x403000 --stop-address=0x403008 | FileCheck --check-prefix=FUNC01 %s
5// RUN: llvm-objdump -d %t.exe --start-address=0x404ffa --stop-address=0x405012 | FileCheck --check-prefix=FUNC01-THUNKS %s
6
7// VERBOSE: Added {{.*}} thunks with margin 204800 in 2 passes
8
9    .syntax unified
10    .globl main
11    .text
12main:
13    b  func01
14    bx lr
15
16.irp i, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18
17    .section .text$\i\()a, "xr"
18    .balign 8192
19func\i:
20    bne far_func\i
21    bne func_within_margin\i
22    // Originally, the first section is less than 8192 bytes large, and the
23    // second one follows almost directly. After adding one thunk after
24    // the first section, the second one will move forward by 8192 bytes
25    // due to the alignment.
26    .space 8192 - 8 - 4
27
28    .section .text$\i\()b, "xr"
29    .balign 8192
30align\i:
31    nop
32.endr
33
34    .section .text$999, "xr"
35tail:
36    .space 0x100000 - 100*1024 - 18*8192*2
37    // Initially, these symbols are within range from all the sections above,
38    // even when taking the initial margin into account. After adding thunks
39    // to all the sections above, some of these are also out of range, forcing
40    // running a second pass.
41.irp i, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18
42func_within_margin\i:
43    nop
44.endr
45    .space 0x100000
46
47    // These are always out of range.
48.irp i, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18
49far_func\i:
50    nop
51.endr
52    bx lr
53
54// FUNC01: 403000:       41 f0 fc 87     bne.w   #8184 <.text+0x3ffc>
55// FUNC01: 403004:       41 f0 ff 87     bne.w   #8190 <.text+0x4006>
56
57// Check that we only have two thunks here, even if we created the first
58// thunk twice (once in the first pass, then thrown away and recreated
59// in the second pass).
60
61// FUNC01-THUNKS: 404ffa:       00 00           movs    r0,  r0
62// The instruction above is padding from the .space
63// FUNC01-THUNKS: 404ffc:       47 f2 1e 0c     movw    r12, #28702
64// FUNC01-THUNKS: 405000:       c0 f2 20 0c     movt    r12, #32
65// FUNC01-THUNKS: 405004:       e7 44           add     pc,  r12
66// FUNC01-THUNKS: 405006:       46 f6 f0 7c     movw    r12, #28656
67// FUNC01-THUNKS: 40500a:       c0 f2 10 0c     movt    r12, #16
68// FUNC01-THUNKS: 40500e:       e7 44           add     pc, r12
69// The instruction below is padding from the .balign
70// FUNC01-THUNKS: 405010:       cc cc           ldm     r4!, {r2, r3, r6, r7}
71