aboutsummaryrefslogtreecommitdiff
path: root/test/ELF/mips-got16.s
blob: ef80418ef0329d9251545996b3bd23564a4a3ed8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Check R_MIPS_GOT16 relocation calculation.

# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -shared -o %t.so
# RUN: llvm-objdump -d -t %t.so | FileCheck %s
# RUN: llvm-readobj -r -mips-plt-got %t.so | FileCheck -check-prefix=GOT %s

# REQUIRES: mips

# CHECK:      Disassembly of section .text:
# CHECK-NEXT: __start:
# CHECK-NEXT:    10000:       8f 88 80 18     lw      $8, -32744($gp)
# CHECK-NEXT:    10004:       21 08 00 2c     addi    $8, $8, 44
# CHECK-NEXT:    10008:       8f 88 80 1c     lw      $8, -32740($gp)
# CHECK-NEXT:    1000c:       21 08 90 00     addi    $8, $8, -28672
# CHECK-NEXT:    10010:       8f 88 80 20     lw      $8, -32736($gp)
# CHECK-NEXT:    10014:       21 08 90 04     addi    $8, $8, -28668
# CHECK-NEXT:    10018:       8f 88 80 20     lw      $8, -32736($gp)
# CHECK-NEXT:    1001c:       21 08 10 04     addi    $8, $8, 4100
# CHECK-NEXT:    10020:       8f 88 80 28     lw      $8, -32728($gp)
# CHECK-NEXT:    10024:       21 08 10 08     addi    $8, $8, 4104
# CHECK-NEXT:    10028:       8f 88 80 2c     lw      $8, -32724($gp)
#
# CHECK: SYMBOL TABLE:
# CHECK: 00051008         .data           00000000 .hidden bar
# CHECK: 00000000         *UND*           00000000 foo

# GOT:      Relocations [
# GOT-NEXT: ]

# GOT:      Primary GOT {
# GOT-NEXT:   Canonical gp value: 0x27FF0
# GOT-NEXT:   Reserved entries [
# GOT-NEXT:     Entry {
# GOT-NEXT:       Address: 0x20000
# GOT-NEXT:       Access: -32752
# GOT-NEXT:       Initial: 0x0
# GOT-NEXT:       Purpose: Lazy resolver
# GOT-NEXT:     }
# GOT-NEXT:     Entry {
# GOT-NEXT:       Address: 0x20004
# GOT-NEXT:       Access: -32748
# GOT-NEXT:       Initial: 0x80000000
# GOT-NEXT:       Purpose: Module pointer (GNU extension)
# GOT-NEXT:     }
# GOT-NEXT:   ]
# GOT-NEXT:   Local entries [
# GOT-NEXT:     Entry {
# GOT-NEXT:       Address: 0x20008
# GOT-NEXT:       Access: -32744
# GOT-NEXT:       Initial: 0x10000
#                          ^-- (0x1002c + 0x8000) & ~0xffff
# GOT-NEXT:     }
# GOT-NEXT:     Entry {
# GOT-NEXT:       Address: 0x2000C
# GOT-NEXT:       Access: -32740
# GOT-NEXT:       Initial: 0x40000
#                          ^-- (0x39000 + 0x8000) & ~0xffff
# GOT-NEXT:     }
# GOT-NEXT:     Entry {
# GOT-NEXT:       Address: 0x20010
# GOT-NEXT:       Access: -32736
# GOT-NEXT:       Initial: 0x50000
#                          ^-- (0x39000 + 0x10004 + 0x8000) & ~0xffff
#                          ^-- (0x39000 + 0x18004 + 0x8000) & ~0xffff
# GOT-NEXT:     }
# GOT-NEXT:     Entry {
# GOT-NEXT:       Address: 0x20014
# GOT-NEXT:       Access: -32732
# GOT-NEXT:       Initial: 0x0
#                          ^-- redundant unused entry
# GOT-NEXT:     }
# GOT-NEXT:     Entry {
# GOT-NEXT:       Address: 0x20018
# GOT-NEXT:       Access: -327
# GOT-NEXT:       Initial: 0x51008
#                          ^-- 'bar' address
# GOT-NEXT:     }
# GOT-NEXT:   ]
# GOT-NEXT:   Global entries [
# GOT-NEXT:     Entry {
# GOT-NEXT:       Address: 0x2001C
# GOT-NEXT:       Access: -32724
# GOT-NEXT:       Initial: 0x0
# GOT-NEXT:       Value: 0x0
# GOT-NEXT:       Type: None
# GOT-NEXT:       Section: Undefined
# GOT-NEXT:       Name: foo@
# GOT-NEXT:     }
# GOT-NEXT:   ]
# GOT-NEXT:   Number of TLS and multi-GOT entries: 0
# GOT-NEXT: }

  .text
  .globl  __start
__start:
  lw      $t0,%got($LC0)($gp)
  addi    $t0,$t0,%lo($LC0)
  lw      $t0,%got($LC1)($gp)
  addi    $t0,$t0,%lo($LC1)
  lw      $t0,%got($LC1+0x10004)($gp)
  addi    $t0,$t0,%lo($LC1+0x10004)
  lw      $t0,%got($LC1+0x18004)($gp)
  addi    $t0,$t0,%lo($LC1+0x18004)
  lw      $t0,%got(bar)($gp)
  addi    $t0,$t0,%lo(bar)
  lw      $t0,%got(foo)($gp)
$LC0:
  nop

  .data
  .space 0x9000
$LC1:
  .word 0
  .space 0x18000
  .word 0
.global bar
.hidden bar
bar:
  .word 0