1d8d293a26a4f94ca32df398a8e46c87fc669937
[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         jal   foo
45         nop
46
47 # Test R_MIPS_PC16 relocation.
48 # rtdyld-check:  decode_operand(insn2, 1)[15:0] = foo - insn2
49 insn2:
50         bal   foo
51         nop
52
53         move     $sp, $fp
54         ld      $ra, 32($sp)
55         ld      $fp, 24($sp)
56         daddiu  $sp, $sp, 32
57         jr      $ra
58         nop
59         .set    at
60         .set    macro
61         .set    reorder
62         .end    bar
63 $func_end0:
64         .size   bar, ($func_end0)-bar
65
66         .globl  main
67         .align  3
68         .type   main,@function
69         .set    nomicromips
70         .set    nomips16
71         .ent    main
72 main:
73         .frame  $fp,32,$ra
74         .mask   0x00000000,0
75         .fmask  0x00000000,0
76         .set    noreorder
77         .set    nomacro
78         .set    noat
79         daddiu  $sp, $sp, -32
80         sd      $ra, 24($sp)
81         sd      $fp, 16($sp)
82         sd      $gp, 8($sp)
83         move     $fp, $sp
84
85 # Check upper 16-bits of offset between the address of main function
86 # and the global offset table.
87 # rtdyld-check:  decode_operand(insn3, 1)[15:0] = ((section_addr(test_ELF_Mips64N64.o, .got) + 0x7ff0) - main + 0x8000)[31:16]
88 insn3:
89         lui     $1, %hi(%neg(%gp_rel(main)))
90         daddu   $1, $1, $25
91
92 # Check lower 16-bits of offset between the address of main function
93 # and the global offset table.
94 # rtdyld-check:  decode_operand(insn4, 2)[15:0] = ((section_addr(test_ELF_Mips64N64.o, .got) + 0x7ff0) - main)[15:0]
95 insn4:
96         daddiu  $1, $1, %lo(%neg(%gp_rel(main)))
97         sw      $zero, 4($fp)
98
99 # $gp register contains address of the .got section + 0x7FF0. 0x7FF0 is
100 # the offset of $gp from the beginning of the .got section. Check that we are
101 # loading address of the page pointer from correct offset. In this case
102 # the page pointer is the first entry in the .got section, so offset will be
103 # 0 - 0x7FF0.
104 # rtdyld-check:  decode_operand(insn5, 2)[15:0] = 0x8010
105 #
106 # Check that the global offset table contains the page pointer.
107 # rtdyld-check: *{8}(section_addr(test_ELF_Mips64N64.o, .got)) = (_str + 0x8000) & 0xffffffffffff0000
108 insn5:
109         ld      $25, %got_page(_str)($1)
110
111 # Check the offset of _str from the page pointer.
112 # rtdyld-check:  decode_operand(insn6, 2)[15:0] = _str[15:0]
113 insn6:
114         daddiu  $25, $25, %got_ofst(_str)
115
116 # Check that we are loading address of var from correct offset. In this case
117 # var is the second entry in the .got section, so offset will be 8 - 0x7FF0.
118 # rtdyld-check:  decode_operand(insn7, 2)[15:0] = 0x8018
119 #
120 # Check that the global offset table contains the address of the var.
121 # rtdyld-check: *{8}(section_addr(test_ELF_Mips64N64.o, .got) + 8) = var
122 insn7:
123         ld      $2, %got_disp(var)($1)
124         sd      $25, 0($2)
125
126 # Check that we are loading address of bar from correct offset. In this case
127 # bar is the third entry in the .got section, so offset will be 16 - 0x7FF0.
128 # rtdyld-check:  decode_operand(insn8, 2)[15:0] = 0x8020
129 #
130 # Check that the global offset table contains the address of the bar.
131 # rtdyld-check: *{8}(section_addr(test_ELF_Mips64N64.o, .got) + 16) = bar
132 insn8:
133         ld      $2, %call16(bar)($1)
134
135         move     $4, $25
136         move     $gp, $1
137         move     $25, $2
138         jalr    $25
139         nop
140         move     $sp, $fp
141         ld      $gp, 8($sp)
142         ld      $fp, 16($sp)
143         ld      $ra, 24($sp)
144         daddiu  $sp, $sp, 32
145         jr      $ra
146         nop
147         .set    at
148         .set    macro
149         .set    reorder
150         .end    main
151 $func_end1:
152         .size   main, ($func_end1)-main
153
154         .type   _str,@object
155         .section        .rodata.str1.1,"aMS",@progbits,1
156 _str:
157         .asciz  "test"
158         .size   _str, 5
159
160         .type   var,@object
161         .comm   var,8,8
162
163         .section        ".note.GNU-stack","",@progbits
164         .text