blob: 4f2b0a16ea05d97a6cfa7bedca42711f44e90d45 [file] [log] [blame]
Rafael Espindola01205f72015-09-22 18:19:46 +00001//===- Target.cpp ---------------------------------------------------------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Rui Ueyama34f29242015-10-13 19:51:57 +00009//
Rui Ueyama66072272015-10-15 19:52:27 +000010// Machine-specific things, such as applying relocations, creation of
11// GOT or PLT entries, etc., are handled in this file.
12//
13// Refer the ELF spec for the single letter varaibles, S, A or P, used
14// in this file. SA is S+A.
Rui Ueyama34f29242015-10-13 19:51:57 +000015//
16//===----------------------------------------------------------------------===//
Rafael Espindola01205f72015-09-22 18:19:46 +000017
18#include "Target.h"
Rafael Espindolac4010882015-09-22 20:54:08 +000019#include "Error.h"
Rui Ueyamaaf21d922015-10-08 20:06:07 +000020#include "OutputSections.h"
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000021#include "Symbols.h"
Rafael Espindola01205f72015-09-22 18:19:46 +000022
23#include "llvm/ADT/ArrayRef.h"
Rafael Espindolac4010882015-09-22 20:54:08 +000024#include "llvm/Object/ELF.h"
Rafael Espindola01205f72015-09-22 18:19:46 +000025#include "llvm/Support/Endian.h"
26#include "llvm/Support/ELF.h"
27
28using namespace llvm;
Rafael Espindolac4010882015-09-22 20:54:08 +000029using namespace llvm::object;
Rafael Espindola0872ea32015-09-24 14:16:02 +000030using namespace llvm::support::endian;
Rafael Espindola01205f72015-09-22 18:19:46 +000031using namespace llvm::ELF;
32
33namespace lld {
34namespace elf2 {
35
36std::unique_ptr<TargetInfo> Target;
37
Rui Ueyamaefc23de2015-10-14 21:30:32 +000038static void add32le(uint8_t *L, int32_t V) { write32le(L, read32le(L) + V); }
39static void add32be(uint8_t *L, int32_t V) { write32be(L, read32be(L) + V); }
40static void or32le(uint8_t *L, int32_t V) { write32le(L, read32le(L) | V); }
41
42template <bool IsLE> static void add32(uint8_t *L, int32_t V);
43template <> void add32<true>(uint8_t *L, int32_t V) { add32le(L, V); }
44template <> void add32<false>(uint8_t *L, int32_t V) { add32be(L, V); }
45
46namespace {
47class X86TargetInfo final : public TargetInfo {
48public:
49 X86TargetInfo();
George Rimar648a2c32015-10-20 08:54:27 +000050 void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;
51 void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
52 uint64_t PltEntryAddr) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000053 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +000054 uint64_t PltEntryAddr, int32_t Index) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000055 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
56 bool relocPointsToGot(uint32_t Type) const override;
57 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rui Ueyama96f0e0b2015-10-23 02:40:46 +000058 void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
Rui Ueyama66072272015-10-15 19:52:27 +000059 uint64_t SA) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000060};
61
62class X86_64TargetInfo final : public TargetInfo {
63public:
64 X86_64TargetInfo();
65 unsigned getPLTRefReloc(unsigned Type) const override;
George Rimar648a2c32015-10-20 08:54:27 +000066 void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;
67 void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
68 uint64_t PltEntryAddr) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000069 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +000070 uint64_t PltEntryAddr, int32_t Index) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000071 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
72 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rui Ueyama96f0e0b2015-10-23 02:40:46 +000073 void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
Rui Ueyama66072272015-10-15 19:52:27 +000074 uint64_t SA) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000075 bool isRelRelative(uint32_t Type) const override;
76};
77
78class PPC64TargetInfo final : public TargetInfo {
79public:
80 PPC64TargetInfo();
George Rimar648a2c32015-10-20 08:54:27 +000081 void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;
82 void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
83 uint64_t PltEntryAddr) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000084 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +000085 uint64_t PltEntryAddr, int32_t Index) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000086 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
87 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rui Ueyama96f0e0b2015-10-23 02:40:46 +000088 void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
Rui Ueyama66072272015-10-15 19:52:27 +000089 uint64_t SA) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000090 bool isRelRelative(uint32_t Type) const override;
91};
92
Rui Ueyamaefc23de2015-10-14 21:30:32 +000093class AArch64TargetInfo final : public TargetInfo {
94public:
95 AArch64TargetInfo();
George Rimar648a2c32015-10-20 08:54:27 +000096 void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;
97 void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
98 uint64_t PltEntryAddr) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +000099 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +0000100 uint64_t PltEntryAddr, int32_t Index) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +0000101 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
102 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000103 void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
Rui Ueyama66072272015-10-15 19:52:27 +0000104 uint64_t SA) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +0000105};
106
107template <class ELFT> class MipsTargetInfo final : public TargetInfo {
108public:
109 MipsTargetInfo();
George Rimar648a2c32015-10-20 08:54:27 +0000110 void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override;
111 void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
112 uint64_t PltEntryAddr) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +0000113 void writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +0000114 uint64_t PltEntryAddr, int32_t Index) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +0000115 bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override;
116 bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override;
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000117 void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
Rui Ueyama66072272015-10-15 19:52:27 +0000118 uint64_t SA) const override;
Rui Ueyamaefc23de2015-10-14 21:30:32 +0000119};
120} // anonymous namespace
121
Rui Ueyama91004392015-10-13 16:08:15 +0000122TargetInfo *createTarget() {
123 switch (Config->EMachine) {
124 case EM_386:
125 return new X86TargetInfo();
126 case EM_AARCH64:
127 return new AArch64TargetInfo();
128 case EM_MIPS:
Simon Atanasyan9c2d7882015-10-14 14:24:46 +0000129 switch (Config->EKind) {
130 case ELF32LEKind:
131 return new MipsTargetInfo<ELF32LE>();
132 case ELF32BEKind:
133 return new MipsTargetInfo<ELF32BE>();
134 default:
135 error("Unsupported MIPS target");
136 }
Rui Ueyama91004392015-10-13 16:08:15 +0000137 case EM_PPC64:
138 return new PPC64TargetInfo();
139 case EM_X86_64:
140 return new X86_64TargetInfo();
141 }
142 error("Unknown target machine");
143}
144
Rafael Espindola01205f72015-09-22 18:19:46 +0000145TargetInfo::~TargetInfo() {}
146
Rafael Espindola227556e2015-10-14 16:15:46 +0000147unsigned TargetInfo::getPLTRefReloc(unsigned Type) const { return PCRelReloc; }
148
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +0000149bool TargetInfo::relocPointsToGot(uint32_t Type) const { return false; }
150
Rafael Espindolaae244002015-10-05 19:30:12 +0000151bool TargetInfo::isRelRelative(uint32_t Type) const { return true; }
152
Rafael Espindola7f074422015-09-22 21:35:51 +0000153X86TargetInfo::X86TargetInfo() {
154 PCRelReloc = R_386_PC32;
155 GotReloc = R_386_GLOB_DAT;
Rafael Espindola8acb95c2015-09-29 14:42:37 +0000156 GotRefReloc = R_386_GOT32;
George Rimar648a2c32015-10-20 08:54:27 +0000157 PltReloc = R_386_JUMP_SLOT;
Rafael Espindola7f074422015-09-22 21:35:51 +0000158}
Rafael Espindola01205f72015-09-22 18:19:46 +0000159
George Rimar648a2c32015-10-20 08:54:27 +0000160void X86TargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {}
161void X86TargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
162 uint64_t PltEntryAddr) const {}
163
Rafael Espindola01205f72015-09-22 18:19:46 +0000164void X86TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +0000165 uint64_t PltEntryAddr, int32_t Index) const {
Rui Ueyamac58656c2015-10-13 16:59:30 +0000166 // jmpl *val; nop; nop
167 const uint8_t Inst[] = {0xff, 0x25, 0, 0, 0, 0, 0x90, 0x90};
Rui Ueyama1500a902015-09-29 23:00:47 +0000168 memcpy(Buf, Inst, sizeof(Inst));
Rui Ueyamac58656c2015-10-13 16:59:30 +0000169 assert(isUInt<32>(GotEntryAddr));
170 write32le(Buf + 2, GotEntryAddr);
Rafael Espindola01205f72015-09-22 18:19:46 +0000171}
172
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000173bool X86TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
Rui Ueyama5ba3ac42015-09-30 01:40:08 +0000174 return Type == R_386_GOT32 || relocNeedsPlt(Type, S);
Rafael Espindola01205f72015-09-22 18:19:46 +0000175}
176
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +0000177bool X86TargetInfo::relocPointsToGot(uint32_t Type) const {
178 return Type == R_386_GOTPC;
179}
180
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000181bool X86TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
George Rimar730c2782015-10-07 18:46:13 +0000182 return Type == R_386_PLT32 || (Type == R_386_PC32 && S.isShared());
Rafael Espindola01205f72015-09-22 18:19:46 +0000183}
184
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000185void X86TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
186 uint64_t P, uint64_t SA) const {
Rafael Espindolac4010882015-09-22 20:54:08 +0000187 switch (Type) {
Rafael Espindola8acb95c2015-09-29 14:42:37 +0000188 case R_386_GOT32:
Rui Ueyama66072272015-10-15 19:52:27 +0000189 add32le(Loc, SA - Out<ELF32LE>::Got->getVA());
Rafael Espindola8acb95c2015-09-29 14:42:37 +0000190 break;
Rafael Espindolac4010882015-09-22 20:54:08 +0000191 case R_386_PC32:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000192 add32le(Loc, SA - P);
Rafael Espindolac4010882015-09-22 20:54:08 +0000193 break;
194 case R_386_32:
Rui Ueyama66072272015-10-15 19:52:27 +0000195 add32le(Loc, SA);
Rafael Espindolac4010882015-09-22 20:54:08 +0000196 break;
197 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000198 error("unrecognized reloc " + Twine(Type));
Rafael Espindolac4010882015-09-22 20:54:08 +0000199 }
200}
201
Rafael Espindola7f074422015-09-22 21:35:51 +0000202X86_64TargetInfo::X86_64TargetInfo() {
203 PCRelReloc = R_X86_64_PC32;
204 GotReloc = R_X86_64_GLOB_DAT;
Rafael Espindola8acb95c2015-09-29 14:42:37 +0000205 GotRefReloc = R_X86_64_PC32;
George Rimar648a2c32015-10-20 08:54:27 +0000206 PltReloc = R_X86_64_JUMP_SLOT;
Rafael Espindolaae244002015-10-05 19:30:12 +0000207 RelativeReloc = R_X86_64_RELATIVE;
George Rimar648a2c32015-10-20 08:54:27 +0000208 LazyRelocations = true;
209 PltEntrySize = 16;
210 PltZeroEntrySize = 16;
211}
212
213void X86_64TargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {
214 // Skip 6 bytes of "jmpq *got(%rip)"
215 write32le(Buf, Plt + 6);
216}
217
218void X86_64TargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
219 uint64_t PltEntryAddr) const {
220 const uint8_t PltData[] = {
221 0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // pushq GOT+8(%rip)
222 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp *GOT+16(%rip)
223 0x0f, 0x1f, 0x40, 0x00 // nopl 0x0(rax)
224 };
225 memcpy(Buf, PltData, sizeof(PltData));
226 write32le(Buf + 2, GotEntryAddr - PltEntryAddr + 2); // GOT+8
227 write32le(Buf + 8, GotEntryAddr - PltEntryAddr + 4); // GOT+16
Rafael Espindola7f074422015-09-22 21:35:51 +0000228}
Rafael Espindola01205f72015-09-22 18:19:46 +0000229
230void X86_64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +0000231 uint64_t PltEntryAddr,
232 int32_t Index) const {
233 const uint8_t Inst[] = {
234 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmpq *got(%rip)
235 0x68, 0x00, 0x00, 0x00, 0x00, // pushq <relocation index>
236 0xe9, 0x00, 0x00, 0x00, 0x00 // jmpq plt[0]
237 };
Rui Ueyama1500a902015-09-29 23:00:47 +0000238 memcpy(Buf, Inst, sizeof(Inst));
Rafael Espindola01205f72015-09-22 18:19:46 +0000239
George Rimar648a2c32015-10-20 08:54:27 +0000240 write32le(Buf + 2, GotEntryAddr - PltEntryAddr - 6);
241 write32le(Buf + 7, Index);
242 write32le(Buf + 12, -Index * PltEntrySize - PltZeroEntrySize - 16);
Rafael Espindola01205f72015-09-22 18:19:46 +0000243}
244
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000245bool X86_64TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
Rui Ueyama5ba3ac42015-09-30 01:40:08 +0000246 return Type == R_X86_64_GOTPCREL || relocNeedsPlt(Type, S);
Rafael Espindola01205f72015-09-22 18:19:46 +0000247}
248
Rafael Espindola227556e2015-10-14 16:15:46 +0000249unsigned X86_64TargetInfo::getPLTRefReloc(unsigned Type) const {
250 switch (Type) {
251 case R_X86_64_32:
252 return R_X86_64_32;
253 case R_X86_64_PC32:
254 case R_X86_64_PLT32:
255 return R_X86_64_PC32;
256 }
257 llvm_unreachable("Unexpected relocation");
258}
259
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000260bool X86_64TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
Rafael Espindola01205f72015-09-22 18:19:46 +0000261 switch (Type) {
262 default:
263 return false;
Rafael Espindola227556e2015-10-14 16:15:46 +0000264 case R_X86_64_32:
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000265 case R_X86_64_PC32:
266 // This relocation is defined to have a value of (S + A - P).
Rafael Espindola3c412e12015-09-30 12:30:58 +0000267 // The problems start when a non PIC program calls a function in a shared
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000268 // library.
Rafael Espindola9a0db7c2015-09-29 23:23:53 +0000269 // In an ideal world, we could just report an error saying the relocation
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000270 // can overflow at runtime.
Rafael Espindola3c412e12015-09-30 12:30:58 +0000271 // In the real world with glibc, crt1.o has a R_X86_64_PC32 pointing to
272 // libc.so.
273 //
274 // The general idea on how to handle such cases is to create a PLT entry
275 // and use that as the function value.
276 //
277 // For the static linking part, we just return true and everything else
278 // will use the the PLT entry as the address.
279 //
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000280 // The remaining (unimplemented) problem is making sure pointer equality
Rafael Espindola3c412e12015-09-30 12:30:58 +0000281 // still works. We need the help of the dynamic linker for that. We
282 // let it know that we have a direct reference to a so symbol by creating
283 // an undefined symbol with a non zero st_value. Seeing that, the
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000284 // dynamic linker resolves the symbol to the value of the symbol we created.
285 // This is true even for got entries, so pointer equality is maintained.
286 // To avoid an infinite loop, the only entry that points to the
Rafael Espindola3c412e12015-09-30 12:30:58 +0000287 // real function is a dedicated got entry used by the plt. That is
288 // identified by special relocation types (R_X86_64_JUMP_SLOT,
289 // R_386_JMP_SLOT, etc).
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000290 return S.isShared();
Rafael Espindola01205f72015-09-22 18:19:46 +0000291 case R_X86_64_PLT32:
George Rimar8911d852015-10-16 23:52:24 +0000292 return canBePreempted(&S, true);
Rafael Espindola01205f72015-09-22 18:19:46 +0000293 }
294}
Rafael Espindolac4010882015-09-22 20:54:08 +0000295
Rafael Espindolaae244002015-10-05 19:30:12 +0000296bool X86_64TargetInfo::isRelRelative(uint32_t Type) const {
297 switch (Type) {
298 default:
299 return false;
300 case R_X86_64_PC64:
301 case R_X86_64_PC32:
302 case R_X86_64_PC16:
303 case R_X86_64_PC8:
Rafael Espindola69535df2015-10-19 05:20:01 +0000304 case R_X86_64_PLT32:
Rafael Espindolaae244002015-10-05 19:30:12 +0000305 return true;
306 }
307}
308
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000309void X86_64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
310 uint64_t P, uint64_t SA) const {
Rafael Espindolac4010882015-09-22 20:54:08 +0000311 switch (Type) {
312 case R_X86_64_PC32:
Rafael Espindolacdfecff2015-09-23 20:08:25 +0000313 case R_X86_64_GOTPCREL:
Rafael Espindola5045e442015-10-18 03:13:46 +0000314 case R_X86_64_PLT32:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000315 write32le(Loc, SA - P);
Rafael Espindolac4010882015-09-22 20:54:08 +0000316 break;
317 case R_X86_64_64:
Rui Ueyama66072272015-10-15 19:52:27 +0000318 write64le(Loc, SA);
Rafael Espindolac4010882015-09-22 20:54:08 +0000319 break;
Rui Ueyama3835b492015-10-23 16:13:27 +0000320 case R_X86_64_32:
Rafael Espindolac4010882015-09-22 20:54:08 +0000321 case R_X86_64_32S:
Rui Ueyama66072272015-10-15 19:52:27 +0000322 if (Type == R_X86_64_32 && !isUInt<32>(SA))
Rafael Espindolac4010882015-09-22 20:54:08 +0000323 error("R_X86_64_32 out of range");
Rui Ueyama66072272015-10-15 19:52:27 +0000324 else if (!isInt<32>(SA))
Rafael Espindolac4010882015-09-22 20:54:08 +0000325 error("R_X86_64_32S out of range");
Rui Ueyama66072272015-10-15 19:52:27 +0000326 write32le(Loc, SA);
Rafael Espindolac4010882015-09-22 20:54:08 +0000327 break;
Rafael Espindolac4010882015-09-22 20:54:08 +0000328 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000329 error("unrecognized reloc " + Twine(Type));
Rafael Espindolac4010882015-09-22 20:54:08 +0000330 }
331}
332
Hal Finkel3c8cc672015-10-12 20:56:18 +0000333// Relocation masks following the #lo(value), #hi(value), #ha(value),
334// #higher(value), #highera(value), #highest(value), and #highesta(value)
335// macros defined in section 4.5.1. Relocation Types of the PPC-elf64abi
336// document.
Rui Ueyamac44e5a12015-10-23 16:54:58 +0000337static uint16_t applyPPCLo(uint64_t V) { return V; }
338static uint16_t applyPPCHi(uint64_t V) { return V >> 16; }
339static uint16_t applyPPCHa(uint64_t V) { return (V + 0x8000) >> 16; }
340static uint16_t applyPPCHigher(uint64_t V) { return V >> 32; }
341static uint16_t applyPPCHighera(uint64_t V) { return (V + 0x8000) >> 32; }
Hal Finkel3c8cc672015-10-12 20:56:18 +0000342static uint16_t applyPPCHighest(uint64_t V) { return V >> 48; }
Hal Finkel3c8cc672015-10-12 20:56:18 +0000343static uint16_t applyPPCHighesta(uint64_t V) { return (V + 0x8000) >> 48; }
344
Rafael Espindolac4010882015-09-22 20:54:08 +0000345PPC64TargetInfo::PPC64TargetInfo() {
Hal Finkel3c8cc672015-10-12 20:56:18 +0000346 PCRelReloc = R_PPC64_REL24;
347 GotReloc = R_PPC64_GLOB_DAT;
348 GotRefReloc = R_PPC64_REL64;
Hal Finkelbe0823d2015-10-12 20:58:52 +0000349 RelativeReloc = R_PPC64_RELATIVE;
Hal Finkel6c2a3b82015-10-08 21:51:31 +0000350 PltEntrySize = 32;
Hal Finkelc848b322015-10-12 19:34:29 +0000351
352 // We need 64K pages (at least under glibc/Linux, the loader won't
353 // set different permissions on a finer granularity than that).
Hal Finkele3c26262015-10-08 22:23:54 +0000354 PageSize = 65536;
Hal Finkel736c7412015-10-15 07:49:07 +0000355
356 // The PPC64 ELF ABI v1 spec, says:
357 //
358 // It is normally desirable to put segments with different characteristics
359 // in separate 256 Mbyte portions of the address space, to give the
360 // operating system full paging flexibility in the 64-bit address space.
361 //
362 // And because the lowest non-zero 256M boundary is 0x10000000, PPC64 linkers
363 // use 0x10000000 as the starting address.
364 VAStart = 0x10000000;
Rafael Espindolac4010882015-09-22 20:54:08 +0000365}
Hal Finkel3c8cc672015-10-12 20:56:18 +0000366
Hal Finkel6f97c2b2015-10-16 21:55:40 +0000367uint64_t getPPC64TocBase() {
Hal Finkel3c8cc672015-10-12 20:56:18 +0000368 // The TOC consists of sections .got, .toc, .tocbss, .plt in that
369 // order. The TOC starts where the first of these sections starts.
370
371 // FIXME: This obviously does not do the right thing when there is no .got
372 // section, but there is a .toc or .tocbss section.
373 uint64_t TocVA = Out<ELF64BE>::Got->getVA();
374 if (!TocVA)
375 TocVA = Out<ELF64BE>::Plt->getVA();
376
377 // Per the ppc64-elf-linux ABI, The TOC base is TOC value plus 0x8000
378 // thus permitting a full 64 Kbytes segment. Note that the glibc startup
379 // code (crt1.o) assumes that you can get from the TOC base to the
380 // start of the .toc section with only a single (signed) 16-bit relocation.
381 return TocVA + 0x8000;
382}
383
George Rimar648a2c32015-10-20 08:54:27 +0000384void PPC64TargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {}
385void PPC64TargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
386 uint64_t PltEntryAddr) const {}
Rafael Espindolac4010882015-09-22 20:54:08 +0000387void PPC64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +0000388 uint64_t PltEntryAddr, int32_t Index) const {
Hal Finkel3c8cc672015-10-12 20:56:18 +0000389 uint64_t Off = GotEntryAddr - getPPC64TocBase();
390
391 // FIXME: What we should do, in theory, is get the offset of the function
392 // descriptor in the .opd section, and use that as the offset from %r2 (the
393 // TOC-base pointer). Instead, we have the GOT-entry offset, and that will
394 // be a pointer to the function descriptor in the .opd section. Using
395 // this scheme is simpler, but requires an extra indirection per PLT dispatch.
396
Hal Finkelfa92f682015-10-13 21:47:34 +0000397 write32be(Buf, 0xf8410028); // std %r2, 40(%r1)
Hal Finkel3c8cc672015-10-12 20:56:18 +0000398 write32be(Buf + 4, 0x3d620000 | applyPPCHa(Off)); // addis %r11, %r2, X@ha
399 write32be(Buf + 8, 0xe98b0000 | applyPPCLo(Off)); // ld %r12, X@l(%r11)
400 write32be(Buf + 12, 0xe96c0000); // ld %r11,0(%r12)
401 write32be(Buf + 16, 0x7d6903a6); // mtctr %r11
402 write32be(Buf + 20, 0xe84c0008); // ld %r2,8(%r12)
403 write32be(Buf + 24, 0xe96c0010); // ld %r11,16(%r12)
404 write32be(Buf + 28, 0x4e800420); // bctr
405}
406
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000407bool PPC64TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
Hal Finkel3c8cc672015-10-12 20:56:18 +0000408 if (relocNeedsPlt(Type, S))
409 return true;
410
411 switch (Type) {
412 default: return false;
413 case R_PPC64_GOT16:
414 case R_PPC64_GOT16_LO:
415 case R_PPC64_GOT16_HI:
416 case R_PPC64_GOT16_HA:
417 case R_PPC64_GOT16_DS:
418 case R_PPC64_GOT16_LO_DS:
419 return true;
420 }
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000421}
Hal Finkel3c8cc672015-10-12 20:56:18 +0000422
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000423bool PPC64TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
Hal Finkel3c8cc672015-10-12 20:56:18 +0000424 // These are function calls that need to be redirected through a PLT stub.
Hal Finkel82281982015-10-17 00:48:20 +0000425 return Type == R_PPC64_REL24 && canBePreempted(&S, false);
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000426}
Hal Finkel3c8cc672015-10-12 20:56:18 +0000427
Hal Finkelbe0823d2015-10-12 20:58:52 +0000428bool PPC64TargetInfo::isRelRelative(uint32_t Type) const {
429 switch (Type) {
430 default:
Hal Finkelbe0823d2015-10-12 20:58:52 +0000431 return true;
Hal Finkel00918622015-10-16 19:01:50 +0000432 case R_PPC64_TOC:
433 case R_PPC64_ADDR64:
434 return false;
Hal Finkelbe0823d2015-10-12 20:58:52 +0000435 }
436}
437
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000438void PPC64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
439 uint64_t P, uint64_t SA) const {
Hal Finkel3c8cc672015-10-12 20:56:18 +0000440 uint64_t TB = getPPC64TocBase();
441
Hal Finkel3c8cc672015-10-12 20:56:18 +0000442 // For a TOC-relative relocation, adjust the addend and proceed in terms of
443 // the corresponding ADDR16 relocation type.
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000444 switch (Type) {
Rafael Espindola826941a2015-10-15 18:19:39 +0000445 case R_PPC64_TOC16: Type = R_PPC64_ADDR16; SA -= TB; break;
446 case R_PPC64_TOC16_DS: Type = R_PPC64_ADDR16_DS; SA -= TB; break;
447 case R_PPC64_TOC16_LO: Type = R_PPC64_ADDR16_LO; SA -= TB; break;
448 case R_PPC64_TOC16_LO_DS: Type = R_PPC64_ADDR16_LO_DS; SA -= TB; break;
449 case R_PPC64_TOC16_HI: Type = R_PPC64_ADDR16_HI; SA -= TB; break;
450 case R_PPC64_TOC16_HA: Type = R_PPC64_ADDR16_HA; SA -= TB; break;
Hal Finkel3c8cc672015-10-12 20:56:18 +0000451 default: break;
452 }
453
Hal Finkel3c8cc672015-10-12 20:56:18 +0000454 switch (Type) {
455 case R_PPC64_ADDR16:
Rui Ueyama9e82fa22015-10-15 19:39:36 +0000456 if (!isInt<16>(SA))
Hal Finkel33e17a72015-10-15 16:17:30 +0000457 error("Relocation R_PPC64_ADDR16 overflow");
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000458 write16be(Loc, SA);
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000459 break;
Hal Finkel3c8cc672015-10-12 20:56:18 +0000460 case R_PPC64_ADDR16_DS:
Rui Ueyama9e82fa22015-10-15 19:39:36 +0000461 if (!isInt<16>(SA))
Hal Finkel3c8cc672015-10-12 20:56:18 +0000462 error("Relocation R_PPC64_ADDR16_DS overflow");
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000463 write16be(Loc, (read16be(Loc) & 3) | (SA & ~3));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000464 break;
465 case R_PPC64_ADDR16_LO:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000466 write16be(Loc, applyPPCLo(SA));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000467 break;
468 case R_PPC64_ADDR16_LO_DS:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000469 write16be(Loc, (read16be(Loc) & 3) | (applyPPCLo(SA) & ~3));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000470 break;
471 case R_PPC64_ADDR16_HI:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000472 write16be(Loc, applyPPCHi(SA));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000473 break;
474 case R_PPC64_ADDR16_HA:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000475 write16be(Loc, applyPPCHa(SA));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000476 break;
477 case R_PPC64_ADDR16_HIGHER:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000478 write16be(Loc, applyPPCHigher(SA));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000479 break;
480 case R_PPC64_ADDR16_HIGHERA:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000481 write16be(Loc, applyPPCHighera(SA));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000482 break;
483 case R_PPC64_ADDR16_HIGHEST:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000484 write16be(Loc, applyPPCHighest(SA));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000485 break;
486 case R_PPC64_ADDR16_HIGHESTA:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000487 write16be(Loc, applyPPCHighesta(SA));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000488 break;
489 case R_PPC64_ADDR14: {
Rui Ueyama9e82fa22015-10-15 19:39:36 +0000490 if ((SA & 3) != 0)
Hal Finkel3c8cc672015-10-12 20:56:18 +0000491 error("Improper alignment for relocation R_PPC64_ADDR14");
492
493 // Preserve the AA/LK bits in the branch instruction
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000494 uint8_t AALK = Loc[3];
495 write16be(Loc + 2, (AALK & 3) | (SA & 0xfffc));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000496 break;
497 }
498 case R_PPC64_REL16_LO:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000499 write16be(Loc, applyPPCLo(SA - P));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000500 break;
501 case R_PPC64_REL16_HI:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000502 write16be(Loc, applyPPCHi(SA - P));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000503 break;
504 case R_PPC64_REL16_HA:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000505 write16be(Loc, applyPPCHa(SA - P));
Hal Finkel3c8cc672015-10-12 20:56:18 +0000506 break;
507 case R_PPC64_ADDR32:
Rui Ueyama9e82fa22015-10-15 19:39:36 +0000508 if (!isInt<32>(SA))
Hal Finkel3c8cc672015-10-12 20:56:18 +0000509 error("Relocation R_PPC64_ADDR32 overflow");
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000510 write32be(Loc, SA);
Hal Finkel3c8cc672015-10-12 20:56:18 +0000511 break;
512 case R_PPC64_REL24: {
Hal Finkel82281982015-10-17 00:48:20 +0000513 // If we have an undefined weak symbol, we might get here with a symbol
514 // address of zero. That could overflow, but the code must be unreachable,
515 // so don't bother doing anything at all.
516 if (!SA)
517 break;
518
Hal Finkeldaedc122015-10-12 23:16:53 +0000519 uint64_t PltStart = Out<ELF64BE>::Plt->getVA();
520 uint64_t PltEnd = PltStart + Out<ELF64BE>::Plt->getSize();
Rui Ueyama9e82fa22015-10-15 19:39:36 +0000521 bool InPlt = PltStart <= SA && SA < PltEnd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000522
523 if (!InPlt && Out<ELF64BE>::Opd) {
524 // If this is a local call, and we currently have the address of a
525 // function-descriptor, get the underlying code address instead.
526 uint64_t OpdStart = Out<ELF64BE>::Opd->getVA();
527 uint64_t OpdEnd = OpdStart + Out<ELF64BE>::Opd->getSize();
Rui Ueyama9e82fa22015-10-15 19:39:36 +0000528 bool InOpd = OpdStart <= SA && SA < OpdEnd;
Hal Finkeldaedc122015-10-12 23:16:53 +0000529
530 if (InOpd)
Rui Ueyama9e82fa22015-10-15 19:39:36 +0000531 SA = read64be(&Out<ELF64BE>::OpdBuf[SA - OpdStart]);
Hal Finkeldaedc122015-10-12 23:16:53 +0000532 }
533
Hal Finkel3c8cc672015-10-12 20:56:18 +0000534 uint32_t Mask = 0x03FFFFFC;
Rui Ueyama9e82fa22015-10-15 19:39:36 +0000535 if (!isInt<24>(SA - P))
Hal Finkel3c8cc672015-10-12 20:56:18 +0000536 error("Relocation R_PPC64_REL24 overflow");
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000537 write32be(Loc, (read32be(Loc) & ~Mask) | ((SA - P) & Mask));
Hal Finkel87bbd5f2015-10-12 21:19:18 +0000538
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000539 uint32_t Nop = 0x60000000;
540 if (InPlt && Loc + 8 <= BufEnd && read32be(Loc + 4) == Nop)
541 write32be(Loc + 4, 0xe8410028); // ld %r2, 40(%r1)
Hal Finkel3c8cc672015-10-12 20:56:18 +0000542 break;
543 }
544 case R_PPC64_REL32:
Rui Ueyama9e82fa22015-10-15 19:39:36 +0000545 if (!isInt<32>(SA - P))
Hal Finkel3c8cc672015-10-12 20:56:18 +0000546 error("Relocation R_PPC64_REL32 overflow");
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000547 write32be(Loc, SA - P);
Hal Finkel3c8cc672015-10-12 20:56:18 +0000548 break;
549 case R_PPC64_REL64:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000550 write64be(Loc, SA - P);
Hal Finkel3c8cc672015-10-12 20:56:18 +0000551 break;
552 case R_PPC64_ADDR64:
Hal Finkel6f97c2b2015-10-16 21:55:40 +0000553 case R_PPC64_TOC:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000554 write64be(Loc, SA);
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000555 break;
556 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000557 error("unrecognized reloc " + Twine(Type));
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000558 }
559}
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000560
Rui Ueyama9cfc8e02015-10-21 21:13:35 +0000561AArch64TargetInfo::AArch64TargetInfo() {}
George Rimar648a2c32015-10-20 08:54:27 +0000562
563void AArch64TargetInfo::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {}
564void AArch64TargetInfo::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
565 uint64_t PltEntryAddr) const {}
Davide Italianocde93362015-09-26 00:32:04 +0000566void AArch64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +0000567 uint64_t PltEntryAddr, int32_t Index) const {}
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000568bool AArch64TargetInfo::relocNeedsGot(uint32_t Type,
569 const SymbolBody &S) const {
570 return false;
571}
572bool AArch64TargetInfo::relocNeedsPlt(uint32_t Type,
573 const SymbolBody &S) const {
574 return false;
575}
Davide Italiano1d750a62015-09-27 08:45:38 +0000576
Davide Italianoef4be6b2015-10-06 19:01:32 +0000577static void updateAArch64Adr(uint8_t *L, uint64_t Imm) {
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000578 uint32_t ImmLo = (Imm & 0x3) << 29;
579 uint32_t ImmHi = ((Imm & 0x1FFFFC) >> 2) << 5;
580 uint64_t Mask = (0x3 << 29) | (0x7FFFF << 5);
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000581 write32le(L, (read32le(L) & ~Mask) | ImmLo | ImmHi);
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000582}
583
Davide Italiano318ca222015-10-02 22:13:51 +0000584// Page(Expr) is the page address of the expression Expr, defined
585// as (Expr & ~0xFFF). (This applies even if the machine page size
Davide Italianod9b5be42015-10-02 22:17:09 +0000586// supported by the platform has a different value.)
Davide Italianoef4be6b2015-10-06 19:01:32 +0000587static uint64_t getAArch64Page(uint64_t Expr) {
Davide Italiano318ca222015-10-02 22:13:51 +0000588 return Expr & (~static_cast<uint64_t>(0xFFF));
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000589}
590
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000591void AArch64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
592 uint32_t Type, uint64_t P,
593 uint64_t SA) const {
Davide Italiano1d750a62015-09-27 08:45:38 +0000594 switch (Type) {
Davide Italianodf88f962015-10-04 00:59:16 +0000595 case R_AARCH64_ABS16:
Rafael Espindola826941a2015-10-15 18:19:39 +0000596 if (!isInt<16>(SA))
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000597 error("Relocation R_AARCH64_ABS16 out of range");
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000598 write16le(Loc, SA);
Davide Italianodf88f962015-10-04 00:59:16 +0000599 break;
600 case R_AARCH64_ABS32:
Rafael Espindola826941a2015-10-15 18:19:39 +0000601 if (!isInt<32>(SA))
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000602 error("Relocation R_AARCH64_ABS32 out of range");
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000603 write32le(Loc, SA);
Davide Italianodf88f962015-10-04 00:59:16 +0000604 break;
605 case R_AARCH64_ABS64:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000606 // No overflow check needed.
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000607 write64le(Loc, SA);
Davide Italianodf88f962015-10-04 00:59:16 +0000608 break;
Davide Italiano0b6974b2015-10-03 19:56:07 +0000609 case R_AARCH64_ADD_ABS_LO12_NC:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000610 // No overflow check needed.
Davide Italianoa7165742015-10-16 21:06:55 +0000611 // This relocation stores 12 bits and there's no instruction
612 // to do it. Instead, we do a 32 bits store of the value
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000613 // of r_addend bitwise-or'ed Loc. This assumes that the addend
614 // bits in Loc are zero.
615 or32le(Loc, (SA & 0xFFF) << 10);
Davide Italiano0b6974b2015-10-03 19:56:07 +0000616 break;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000617 case R_AARCH64_ADR_PREL_LO21: {
Rafael Espindola826941a2015-10-15 18:19:39 +0000618 uint64_t X = SA - P;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000619 if (!isInt<21>(X))
620 error("Relocation R_AARCH64_ADR_PREL_LO21 out of range");
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000621 updateAArch64Adr(Loc, X & 0x1FFFFF);
Davide Italiano1d750a62015-09-27 08:45:38 +0000622 break;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000623 }
624 case R_AARCH64_ADR_PREL_PG_HI21: {
Rafael Espindola826941a2015-10-15 18:19:39 +0000625 uint64_t X = getAArch64Page(SA) - getAArch64Page(P);
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000626 if (!isInt<33>(X))
627 error("Relocation R_AARCH64_ADR_PREL_PG_HI21 out of range");
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000628 updateAArch64Adr(Loc, (X >> 12) & 0x1FFFFF); // X[32:12]
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000629 break;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000630 }
Davide Italianob12d6682015-10-28 16:14:18 +0000631 case R_AARCH64_PREL64:
632 // No overflow check needed.
633 write64le(Loc, SA - P);
634 break;
Davide Italiano1d750a62015-09-27 08:45:38 +0000635 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000636 error("unrecognized reloc " + Twine(Type));
Davide Italiano1d750a62015-09-27 08:45:38 +0000637 }
638}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000639
Simon Atanasyan9c2d7882015-10-14 14:24:46 +0000640template <class ELFT> MipsTargetInfo<ELFT>::MipsTargetInfo() {
Hal Finkele3c26262015-10-08 22:23:54 +0000641 PageSize = 65536;
Simon Atanasyan49829a12015-09-29 05:34:03 +0000642}
643
Simon Atanasyan9c2d7882015-10-14 14:24:46 +0000644template <class ELFT>
George Rimar648a2c32015-10-20 08:54:27 +0000645void MipsTargetInfo<ELFT>::writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const {}
646template <class ELFT>
647void MipsTargetInfo<ELFT>::writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr,
648 uint64_t PltEntryAddr) const {}
649template <class ELFT>
Simon Atanasyan9c2d7882015-10-14 14:24:46 +0000650void MipsTargetInfo<ELFT>::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
George Rimar648a2c32015-10-20 08:54:27 +0000651 uint64_t PltEntryAddr, int32_t Index) const {}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000652
Simon Atanasyan9c2d7882015-10-14 14:24:46 +0000653template <class ELFT>
654bool MipsTargetInfo<ELFT>::relocNeedsGot(uint32_t Type,
655 const SymbolBody &S) const {
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000656 return false;
657}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000658
Simon Atanasyan9c2d7882015-10-14 14:24:46 +0000659template <class ELFT>
660bool MipsTargetInfo<ELFT>::relocNeedsPlt(uint32_t Type,
661 const SymbolBody &S) const {
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000662 return false;
663}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000664
Simon Atanasyan9c2d7882015-10-14 14:24:46 +0000665template <class ELFT>
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000666void MipsTargetInfo<ELFT>::relocateOne(uint8_t *Loc, uint8_t *BufEnd,
667 uint32_t Type, uint64_t P,
668 uint64_t SA) const {
Simon Atanasyan9c2d7882015-10-14 14:24:46 +0000669 const bool IsLE = ELFT::TargetEndianness == support::little;
Simon Atanasyan3b732ac2015-10-12 15:10:02 +0000670 switch (Type) {
671 case R_MIPS_32:
Rui Ueyama96f0e0b2015-10-23 02:40:46 +0000672 add32<IsLE>(Loc, SA);
Simon Atanasyan3b732ac2015-10-12 15:10:02 +0000673 break;
674 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000675 error("unrecognized reloc " + Twine(Type));
Simon Atanasyan3b732ac2015-10-12 15:10:02 +0000676 }
677}
Rafael Espindola01205f72015-09-22 18:19:46 +0000678}
679}