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 package mips64
32
33 import (
34 "cmd/internal/objabi"
35 "cmd/internal/sys"
36 "cmd/link/internal/ld"
37 "cmd/link/internal/loader"
38 "cmd/link/internal/sym"
39 "debug/elf"
40 )
41
42 func gentext(ctxt *ld.Link, ldr *loader.Loader) {}
43
44 func elfreloc1(ctxt *ld.Link, out *ld.OutBuf, ldr *loader.Loader, s loader.Sym, r loader.ExtReloc, ri int, sectoff int64) bool {
45
46
47
48
49
50
51
52
53
54
55 addend := r.Xadd
56
57 out.Write64(uint64(sectoff))
58
59 elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
60 out.Write32(uint32(elfsym))
61 out.Write8(0)
62 out.Write8(0)
63 out.Write8(0)
64 switch r.Type {
65 default:
66 return false
67 case objabi.R_ADDR, objabi.R_DWARFSECREF:
68 switch r.Size {
69 case 4:
70 out.Write8(uint8(elf.R_MIPS_32))
71 case 8:
72 out.Write8(uint8(elf.R_MIPS_64))
73 default:
74 return false
75 }
76 case objabi.R_ADDRMIPS:
77 out.Write8(uint8(elf.R_MIPS_LO16))
78 case objabi.R_ADDRMIPSU:
79 out.Write8(uint8(elf.R_MIPS_HI16))
80 case objabi.R_ADDRMIPSTLS:
81 out.Write8(uint8(elf.R_MIPS_TLS_TPREL_LO16))
82 if ctxt.Target.IsOpenbsd() {
83
84
85
86 addend += 0x7000
87 }
88 case objabi.R_CALLMIPS,
89 objabi.R_JMPMIPS:
90 out.Write8(uint8(elf.R_MIPS_26))
91 }
92 out.Write64(uint64(addend))
93
94 return true
95 }
96
97 func elfsetupplt(ctxt *ld.Link, plt, gotplt *loader.SymbolBuilder, dynamic loader.Sym) {
98 return
99 }
100
101 func machoreloc1(*sys.Arch, *ld.OutBuf, *loader.Loader, loader.Sym, loader.ExtReloc, int64) bool {
102 return false
103 }
104
105 func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loader.Reloc, s loader.Sym, val int64) (o int64, nExtReloc int, ok bool) {
106 if target.IsExternal() {
107 switch r.Type() {
108 default:
109 return val, 0, false
110
111 case objabi.R_ADDRMIPS,
112 objabi.R_ADDRMIPSU,
113 objabi.R_ADDRMIPSTLS,
114 objabi.R_CALLMIPS,
115 objabi.R_JMPMIPS:
116 return val, 1, true
117 }
118 }
119
120 const isOk = true
121 const noExtReloc = 0
122 rs := r.Sym()
123 switch r.Type() {
124 case objabi.R_ADDRMIPS,
125 objabi.R_ADDRMIPSU:
126 t := ldr.SymValue(rs) + r.Add()
127 if r.Type() == objabi.R_ADDRMIPS {
128 return int64(val&0xffff0000 | t&0xffff), noExtReloc, isOk
129 }
130 return int64(val&0xffff0000 | ((t+1<<15)>>16)&0xffff), noExtReloc, isOk
131 case objabi.R_ADDRMIPSTLS:
132
133 t := ldr.SymValue(rs) + r.Add() - 0x7000
134 if target.IsOpenbsd() {
135
136
137 t += 0x7000
138 }
139 if t < -32768 || t >= 32678 {
140 ldr.Errorf(s, "TLS offset out of range %d", t)
141 }
142 return int64(val&0xffff0000 | t&0xffff), noExtReloc, isOk
143 case objabi.R_CALLMIPS,
144 objabi.R_JMPMIPS:
145
146 t := ldr.SymValue(rs) + r.Add()
147 return int64(val&0xfc000000 | (t>>2)&^0xfc000000), noExtReloc, isOk
148 }
149
150 return val, 0, false
151 }
152
153 func archrelocvariant(*ld.Target, *loader.Loader, loader.Reloc, sym.RelocVariant, loader.Sym, int64, []byte) int64 {
154 return -1
155 }
156
157 func extreloc(target *ld.Target, ldr *loader.Loader, r loader.Reloc, s loader.Sym) (loader.ExtReloc, bool) {
158 switch r.Type() {
159 case objabi.R_ADDRMIPS,
160 objabi.R_ADDRMIPSU:
161 return ld.ExtrelocViaOuterSym(ldr, r, s), true
162
163 case objabi.R_ADDRMIPSTLS,
164 objabi.R_CALLMIPS,
165 objabi.R_JMPMIPS:
166 return ld.ExtrelocSimple(ldr, r), true
167 }
168 return loader.ExtReloc{}, false
169 }
170
View as plain text