[mips] Expand JAL instructions when PIC is enabled.
[oota-llvm.git] / test / ExecutionEngine / RuntimeDyld / Mips / ELF_Mips64r2N64_PIC_relocations.s
1 # RUN: llvm-mc -triple=mips64el-unknown-linux -relocation-model=pic -code-model=small -filetype=obj -o %T/test_ELF_Mips64N64.o %s
2 # RUN: llc -mtriple=mips64el-unknown-linux -relocation-model=pic -filetype=obj -o %T/test_ELF_ExternalFunction_Mips64N64.o %S/Inputs/ExternalFunction.ll
3 # RUN: llvm-rtdyld -triple=mips64el-unknown-linux -verify -map-section test_ELF_Mips64N64.o,.text=0x1000 -map-section test_ELF_ExternalFunction_Mips64N64.o,.text=0x10000 -check=%s %/T/test_ELF_Mips64N64.o %T/test_ELF_ExternalFunction_Mips64N64.o
4
5         .data
6 # Test R_MIPS_PC32 relocation.
7 # rtdyld-check: *{4}(R_MIPS_PC32) = (foo - R_MIPS_PC32)[31:0]
8 R_MIPS_PC32:
9         .word foo-.
10 # rtdyld-check: *{4}(R_MIPS_PC32 + 4) = (foo - tmp1)[31:0]
11 tmp1:
12         .4byte foo-tmp1
13
14         .text
15         .abicalls
16         .section        .mdebug.abi64,"",@progbits
17         .nan    legacy
18         .file   "ELF_Mips64N64_PIC_relocations.ll"
19         .text
20         .globl  bar
21         .align  3
22         .type   bar,@function
23         .set    nomicromips
24         .set    nomips16
25         .ent    bar
26 bar:
27         .frame  $fp,40,$ra
28         .mask   0x00000000,0
29         .fmask  0x00000000,0
30         .set    noreorder
31         .set    nomacro
32         .set    noat
33         daddiu  $sp, $sp, -40
34         sd      $ra, 32($sp)
35         sd      $fp, 24($sp)
36         move     $fp, $sp
37         sd      $4, 16($fp)
38         lb      $2, 0($4)
39         sd      $4, 8($fp)
40
41 # Test R_MIPS_26 relocation.
42 # rtdyld-check:  decode_operand(insn1, 0)[25:0] = foo
43 insn1:
44         .option pic0
45         jal   foo
46         .option pic2
47         nop
48
49 # Test R_MIPS_PC16 relocation.
50 # rtdyld-check:  decode_operand(insn2, 1)[15:0] = foo - insn2
51 insn2:
52         bal   foo
53         nop
54
55         move     $sp, $fp
56         ld      $ra, 32($sp)
57         ld      $fp, 24($sp)
58         daddiu  $sp, $sp, 32
59         jr      $ra
60         nop
61         .set    at
62         .set    macro
63         .set    reorder
64         .end    bar
65 $func_end0:
66         .size   bar, ($func_end0)-bar
67
68         .globl  main
69         .align  3
70         .type   main,@function
71         .set    nomicromips
72         .set    nomips16
73         .ent    main
74 main:
75         .frame  $fp,32,$ra
76         .mask   0x00000000,0
77         .fmask  0x00000000,0
78         .set    noreorder
79         .set    nomacro
80         .set    noat
81         daddiu  $sp, $sp, -32
82         sd      $ra, 24($sp)
83         sd      $fp, 16($sp)
84         sd      $gp, 8($sp)
85         move     $fp, $sp
86
87 # Check upper 16-bits of offset between the address of main function
88 # and the global offset table.
89 # rtdyld-check:  decode_operand(insn3, 1)[15:0] = ((section_addr(test_ELF_Mips64N64.o, .got) + 0x7ff0) - main + 0x8000)[31:16]
90 insn3:
91         lui     $1, %hi(%neg(%gp_rel(main)))
92         daddu   $1, $1, $25
93
94 # Check lower 16-bits of offset between the address of main function
95 # and the global offset table.
96 # rtdyld-check:  decode_operand(insn4, 2)[15:0] = ((section_addr(test_ELF_Mips64N64.o, .got) + 0x7ff0) - main)[15:0]
97 insn4:
98         daddiu  $1, $1, %lo(%neg(%gp_rel(main)))
99         sw      $zero, 4($fp)
100
101 # $gp register contains address of the .got section + 0x7FF0. 0x7FF0 is
102 # the offset of $gp from the beginning of the .got section. Check that we are
103 # loading address of the page pointer from correct offset. In this case
104 # the page pointer is the first entry in the .got section, so offset will be
105 # 0 - 0x7FF0.
106 # rtdyld-check:  decode_operand(insn5, 2)[15:0] = 0x8010
107 #
108 # Check that the global offset table contains the page pointer.
109 # rtdyld-check: *{8}(section_addr(test_ELF_Mips64N64.o, .got)) = (_str + 0x8000) & 0xffffffffffff0000
110 insn5:
111         ld      $25, %got_page(_str)($1)
112
113 # Check the offset of _str from the page pointer.
114 # rtdyld-check:  decode_operand(insn6, 2)[15:0] = _str[15:0]
115 insn6:
116         daddiu  $25, $25, %got_ofst(_str)
117
118 # Check that we are loading address of var from correct offset. In this case
119 # var is the second entry in the .got section, so offset will be 8 - 0x7FF0.
120 # rtdyld-check:  decode_operand(insn7, 2)[15:0] = 0x8018
121 #
122 # Check that the global offset table contains the address of the var.
123 # rtdyld-check: *{8}(section_addr(test_ELF_Mips64N64.o, .got) + 8) = var
124 insn7:
125         ld      $2, %got_disp(var)($1)
126         sd      $25, 0($2)
127
128 # Check that we are loading address of bar from correct offset. In this case
129 # bar is the third entry in the .got section, so offset will be 16 - 0x7FF0.
130 # rtdyld-check:  decode_operand(insn8, 2)[15:0] = 0x8020
131 #
132 # Check that the global offset table contains the address of the bar.
133 # rtdyld-check: *{8}(section_addr(test_ELF_Mips64N64.o, .got) + 16) = bar
134 insn8:
135         ld      $2, %call16(bar)($1)
136
137         move     $4, $25
138         move     $gp, $1
139         move     $25, $2
140         jalr    $25
141         nop
142         move     $sp, $fp
143         ld      $gp, 8($sp)
144         ld      $fp, 16($sp)
145         ld      $ra, 24($sp)
146         daddiu  $sp, $sp, 32
147         jr      $ra
148         nop
149         .set    at
150         .set    macro
151         .set    reorder
152         .end    main
153 $func_end1:
154         .size   main, ($func_end1)-main
155
156         .type   _str,@object
157         .section        .rodata.str1.1,"aMS",@progbits,1
158 _str:
159         .asciz  "test"
160         .size   _str, 5
161
162         .type   var,@object
163         .comm   var,8,8
164
165         .section        ".note.GNU-stack","",@progbits
166         .text