blob: b6d0f45a37645d06dbd3675a3001a99c2b929b59 [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//===----------------------------------------------------------------------===//
9
10#include "Target.h"
Rafael Espindolac4010882015-09-22 20:54:08 +000011#include "Error.h"
Rui Ueyamaaf21d922015-10-08 20:06:07 +000012#include "OutputSections.h"
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000013#include "Symbols.h"
Rafael Espindola01205f72015-09-22 18:19:46 +000014
15#include "llvm/ADT/ArrayRef.h"
Rafael Espindolac4010882015-09-22 20:54:08 +000016#include "llvm/Object/ELF.h"
Rafael Espindola01205f72015-09-22 18:19:46 +000017#include "llvm/Support/Endian.h"
18#include "llvm/Support/ELF.h"
19
20using namespace llvm;
Rafael Espindolac4010882015-09-22 20:54:08 +000021using namespace llvm::object;
Rafael Espindola0872ea32015-09-24 14:16:02 +000022using namespace llvm::support::endian;
Rafael Espindola01205f72015-09-22 18:19:46 +000023using namespace llvm::ELF;
24
25namespace lld {
26namespace elf2 {
27
28std::unique_ptr<TargetInfo> Target;
29
30TargetInfo::~TargetInfo() {}
31
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +000032bool TargetInfo::relocPointsToGot(uint32_t Type) const { return false; }
33
Rafael Espindolaae244002015-10-05 19:30:12 +000034bool TargetInfo::isRelRelative(uint32_t Type) const { return true; }
35
Rafael Espindola7f074422015-09-22 21:35:51 +000036X86TargetInfo::X86TargetInfo() {
37 PCRelReloc = R_386_PC32;
38 GotReloc = R_386_GLOB_DAT;
Rafael Espindola8acb95c2015-09-29 14:42:37 +000039 GotRefReloc = R_386_GOT32;
Hal Finkel47290642015-10-08 21:25:04 +000040 VAStart = 0x10000;
Rafael Espindola7f074422015-09-22 21:35:51 +000041}
Rafael Espindola01205f72015-09-22 18:19:46 +000042
43void X86TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
44 uint64_t PltEntryAddr) const {
Rui Ueyama1500a902015-09-29 23:00:47 +000045 // jmpl *val; nop; nop
46 const uint8_t Inst[] = {0xff, 0x25, 0, 0, 0, 0, 0x90, 0x90};
47 memcpy(Buf, Inst, sizeof(Inst));
Rafael Espindola01205f72015-09-22 18:19:46 +000048 assert(isUInt<32>(GotEntryAddr));
Rui Ueyama1500a902015-09-29 23:00:47 +000049 write32le(Buf + 2, GotEntryAddr);
Rafael Espindola01205f72015-09-22 18:19:46 +000050}
51
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000052bool X86TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
Rui Ueyama5ba3ac42015-09-30 01:40:08 +000053 return Type == R_386_GOT32 || relocNeedsPlt(Type, S);
Rafael Espindola01205f72015-09-22 18:19:46 +000054}
55
Rafael Espindola6d7fcdb2015-09-29 13:36:32 +000056bool X86TargetInfo::relocPointsToGot(uint32_t Type) const {
57 return Type == R_386_GOTPC;
58}
59
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +000060bool X86TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
George Rimar730c2782015-10-07 18:46:13 +000061 return Type == R_386_PLT32 || (Type == R_386_PC32 && S.isShared());
Rafael Espindola01205f72015-09-22 18:19:46 +000062}
63
Rui Ueyama87bc41b2015-10-06 18:54:43 +000064static void add32le(uint8_t *L, int32_t V) { write32le(L, read32le(L) + V); }
Rui Ueyama87bc41b2015-10-06 18:54:43 +000065static void or32le(uint8_t *L, int32_t V) { write32le(L, read32le(L) | V); }
Rafael Espindola0872ea32015-09-24 14:16:02 +000066
Rafael Espindolac4010882015-09-22 20:54:08 +000067void X86TargetInfo::relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +000068 uint64_t BaseAddr, uint64_t SymVA) const {
Rafael Espindolac4010882015-09-22 20:54:08 +000069 typedef ELFFile<ELF32LE>::Elf_Rel Elf_Rel;
70 auto &Rel = *reinterpret_cast<const Elf_Rel *>(RelP);
71
72 uint32_t Offset = Rel.r_offset;
Rui Ueyama87bc41b2015-10-06 18:54:43 +000073 uint8_t *Loc = Buf + Offset;
Rafael Espindolac4010882015-09-22 20:54:08 +000074 switch (Type) {
Rafael Espindola8acb95c2015-09-29 14:42:37 +000075 case R_386_GOT32:
Rui Ueyamaaf21d922015-10-08 20:06:07 +000076 add32le(Loc, SymVA - Out<ELF32LE>::Got->getVA());
Rafael Espindola8acb95c2015-09-29 14:42:37 +000077 break;
Rafael Espindolac4010882015-09-22 20:54:08 +000078 case R_386_PC32:
Rui Ueyama87bc41b2015-10-06 18:54:43 +000079 add32le(Loc, SymVA - (BaseAddr + Offset));
Rafael Espindolac4010882015-09-22 20:54:08 +000080 break;
81 case R_386_32:
Rui Ueyama87bc41b2015-10-06 18:54:43 +000082 add32le(Loc, SymVA);
Rafael Espindolac4010882015-09-22 20:54:08 +000083 break;
84 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +000085 error("unrecognized reloc " + Twine(Type));
Rafael Espindolac4010882015-09-22 20:54:08 +000086 }
87}
88
Rafael Espindola7f074422015-09-22 21:35:51 +000089X86_64TargetInfo::X86_64TargetInfo() {
90 PCRelReloc = R_X86_64_PC32;
91 GotReloc = R_X86_64_GLOB_DAT;
Rafael Espindola8acb95c2015-09-29 14:42:37 +000092 GotRefReloc = R_X86_64_PC32;
Rafael Espindolaae244002015-10-05 19:30:12 +000093 RelativeReloc = R_X86_64_RELATIVE;
Hal Finkel47290642015-10-08 21:25:04 +000094
95 // On freebsd x86_64 the first page cannot be mmaped.
96 // On linux that is controled by vm.mmap_min_addr. At least on some x86_64
97 // installs that is 65536, so the first 15 pages cannot be used.
98 // Given that, the smallest value that can be used in here is 0x10000.
99 // If using 2MB pages, the smallest page aligned address that works is
100 // 0x200000, but it looks like every OS uses 4k pages for executables.
101 VAStart = 0x10000;
Rafael Espindola7f074422015-09-22 21:35:51 +0000102}
Rafael Espindola01205f72015-09-22 18:19:46 +0000103
104void X86_64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
105 uint64_t PltEntryAddr) const {
Rui Ueyama1500a902015-09-29 23:00:47 +0000106 // jmpq *val(%rip); nop; nop
107 const uint8_t Inst[] = {0xff, 0x25, 0, 0, 0, 0, 0x90, 0x90};
108 memcpy(Buf, Inst, sizeof(Inst));
Rafael Espindola01205f72015-09-22 18:19:46 +0000109
Rui Ueyamae3fbc892015-09-29 23:25:21 +0000110 uint64_t NextPC = PltEntryAddr + 6;
111 int64_t Delta = GotEntryAddr - NextPC;
Rafael Espindola01205f72015-09-22 18:19:46 +0000112 assert(isInt<32>(Delta));
Rui Ueyama1500a902015-09-29 23:00:47 +0000113 write32le(Buf + 2, Delta);
Rafael Espindola01205f72015-09-22 18:19:46 +0000114}
115
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000116bool X86_64TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
Rui Ueyama5ba3ac42015-09-30 01:40:08 +0000117 return Type == R_X86_64_GOTPCREL || relocNeedsPlt(Type, S);
Rafael Espindola01205f72015-09-22 18:19:46 +0000118}
119
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000120bool X86_64TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
Rafael Espindola01205f72015-09-22 18:19:46 +0000121 switch (Type) {
122 default:
123 return false;
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000124 case R_X86_64_PC32:
125 // This relocation is defined to have a value of (S + A - P).
Rafael Espindola3c412e12015-09-30 12:30:58 +0000126 // The problems start when a non PIC program calls a function in a shared
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000127 // library.
Rafael Espindola9a0db7c2015-09-29 23:23:53 +0000128 // In an ideal world, we could just report an error saying the relocation
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000129 // can overflow at runtime.
Rafael Espindola3c412e12015-09-30 12:30:58 +0000130 // In the real world with glibc, crt1.o has a R_X86_64_PC32 pointing to
131 // libc.so.
132 //
133 // The general idea on how to handle such cases is to create a PLT entry
134 // and use that as the function value.
135 //
136 // For the static linking part, we just return true and everything else
137 // will use the the PLT entry as the address.
138 //
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000139 // The remaining (unimplemented) problem is making sure pointer equality
Rafael Espindola3c412e12015-09-30 12:30:58 +0000140 // still works. We need the help of the dynamic linker for that. We
141 // let it know that we have a direct reference to a so symbol by creating
142 // an undefined symbol with a non zero st_value. Seeing that, the
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000143 // dynamic linker resolves the symbol to the value of the symbol we created.
144 // This is true even for got entries, so pointer equality is maintained.
145 // To avoid an infinite loop, the only entry that points to the
Rafael Espindola3c412e12015-09-30 12:30:58 +0000146 // real function is a dedicated got entry used by the plt. That is
147 // identified by special relocation types (R_X86_64_JUMP_SLOT,
148 // R_386_JMP_SLOT, etc).
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000149 return S.isShared();
Rafael Espindola01205f72015-09-22 18:19:46 +0000150 case R_X86_64_PLT32:
151 return true;
152 }
153}
Rafael Espindolac4010882015-09-22 20:54:08 +0000154
Rafael Espindolaae244002015-10-05 19:30:12 +0000155bool X86_64TargetInfo::isRelRelative(uint32_t Type) const {
156 switch (Type) {
157 default:
158 return false;
159 case R_X86_64_PC64:
160 case R_X86_64_PC32:
161 case R_X86_64_PC16:
162 case R_X86_64_PC8:
163 return true;
164 }
165}
166
Rafael Espindolac4010882015-09-22 20:54:08 +0000167void X86_64TargetInfo::relocateOne(uint8_t *Buf, const void *RelP,
168 uint32_t Type, uint64_t BaseAddr,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000169 uint64_t SymVA) const {
Rafael Espindolac4010882015-09-22 20:54:08 +0000170 typedef ELFFile<ELF64LE>::Elf_Rela Elf_Rela;
171 auto &Rel = *reinterpret_cast<const Elf_Rela *>(RelP);
172
173 uint64_t Offset = Rel.r_offset;
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000174 uint8_t *Loc = Buf + Offset;
Rafael Espindolac4010882015-09-22 20:54:08 +0000175 switch (Type) {
176 case R_X86_64_PC32:
Rafael Espindolacdfecff2015-09-23 20:08:25 +0000177 case R_X86_64_GOTPCREL:
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000178 write32le(Loc, SymVA + Rel.r_addend - (BaseAddr + Offset));
Rafael Espindolac4010882015-09-22 20:54:08 +0000179 break;
180 case R_X86_64_64:
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000181 write64le(Loc, SymVA + Rel.r_addend);
Rafael Espindolac4010882015-09-22 20:54:08 +0000182 break;
183 case R_X86_64_32: {
184 case R_X86_64_32S:
185 uint64_t VA = SymVA + Rel.r_addend;
186 if (Type == R_X86_64_32 && !isUInt<32>(VA))
187 error("R_X86_64_32 out of range");
188 else if (!isInt<32>(VA))
189 error("R_X86_64_32S out of range");
190
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000191 write32le(Loc, VA);
Rafael Espindolac4010882015-09-22 20:54:08 +0000192 break;
193 }
194 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000195 error("unrecognized reloc " + Twine(Type));
Rafael Espindolac4010882015-09-22 20:54:08 +0000196 }
197}
198
199PPC64TargetInfo::PPC64TargetInfo() {
200 // PCRelReloc = FIXME
Rafael Espindola7f074422015-09-22 21:35:51 +0000201 // GotReloc = FIXME
Hal Finkel6c2a3b82015-10-08 21:51:31 +0000202 PltEntrySize = 32;
Hal Finkelc848b322015-10-12 19:34:29 +0000203
204 // We need 64K pages (at least under glibc/Linux, the loader won't
205 // set different permissions on a finer granularity than that).
Hal Finkele3c26262015-10-08 22:23:54 +0000206 PageSize = 65536;
Hal Finkelc848b322015-10-12 19:34:29 +0000207
Hal Finkel47290642015-10-08 21:25:04 +0000208 VAStart = 0x10000000;
Rafael Espindolac4010882015-09-22 20:54:08 +0000209}
210void PPC64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
211 uint64_t PltEntryAddr) const {}
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000212bool PPC64TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
213 return false;
214}
215bool PPC64TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
216 return false;
217}
Rafael Espindolac4010882015-09-22 20:54:08 +0000218void PPC64TargetInfo::relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000219 uint64_t BaseAddr, uint64_t SymVA) const {
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000220 typedef ELFFile<ELF64BE>::Elf_Rela Elf_Rela;
221 auto &Rel = *reinterpret_cast<const Elf_Rela *>(RelP);
222
223 uint64_t Offset = Rel.r_offset;
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000224 uint8_t *Loc = Buf + Offset;
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000225 switch (Type) {
226 case R_PPC64_ADDR64:
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000227 write64be(Loc, SymVA + Rel.r_addend);
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000228 break;
229 case R_PPC64_TOC:
230 // We don't create a TOC yet.
231 break;
232 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000233 error("unrecognized reloc " + Twine(Type));
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000234 }
235}
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000236
237PPCTargetInfo::PPCTargetInfo() {
238 // PCRelReloc = FIXME
Rafael Espindola7f074422015-09-22 21:35:51 +0000239 // GotReloc = FIXME
Hal Finkele3c26262015-10-08 22:23:54 +0000240 PageSize = 65536;
Hal Finkel47290642015-10-08 21:25:04 +0000241 VAStart = 0x10000000;
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000242}
243void PPCTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
244 uint64_t PltEntryAddr) const {}
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000245bool PPCTargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
246 return false;
247}
248bool PPCTargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
249 return false;
250}
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000251void PPCTargetInfo::relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000252 uint64_t BaseAddr, uint64_t SymVA) const {}
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000253
254ARMTargetInfo::ARMTargetInfo() {
255 // PCRelReloc = FIXME
Rafael Espindola7f074422015-09-22 21:35:51 +0000256 // GotReloc = FIXME
Hal Finkel47290642015-10-08 21:25:04 +0000257 VAStart = 0x8000;
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000258}
259void ARMTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
260 uint64_t PltEntryAddr) const {}
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000261bool ARMTargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
262 return false;
263}
264bool ARMTargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
265 return false;
266}
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000267void ARMTargetInfo::relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000268 uint64_t BaseAddr, uint64_t SymVA) const {}
Davide Italianocde93362015-09-26 00:32:04 +0000269
270AArch64TargetInfo::AArch64TargetInfo() {
271 // PCRelReloc = FIXME
272 // GotReloc = FIXME
Hal Finkel47290642015-10-08 21:25:04 +0000273 VAStart = 0x400000;
Davide Italianocde93362015-09-26 00:32:04 +0000274}
275void AArch64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
276 uint64_t PltEntryAddr) const {}
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000277bool AArch64TargetInfo::relocNeedsGot(uint32_t Type,
278 const SymbolBody &S) const {
279 return false;
280}
281bool AArch64TargetInfo::relocNeedsPlt(uint32_t Type,
282 const SymbolBody &S) const {
283 return false;
284}
Davide Italiano1d750a62015-09-27 08:45:38 +0000285
Davide Italianoef4be6b2015-10-06 19:01:32 +0000286static void updateAArch64Adr(uint8_t *L, uint64_t Imm) {
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000287 uint32_t ImmLo = (Imm & 0x3) << 29;
288 uint32_t ImmHi = ((Imm & 0x1FFFFC) >> 2) << 5;
289 uint64_t Mask = (0x3 << 29) | (0x7FFFF << 5);
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000290 write32le(L, (read32le(L) & ~Mask) | ImmLo | ImmHi);
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000291}
292
Davide Italiano318ca222015-10-02 22:13:51 +0000293// Page(Expr) is the page address of the expression Expr, defined
294// as (Expr & ~0xFFF). (This applies even if the machine page size
Davide Italianod9b5be42015-10-02 22:17:09 +0000295// supported by the platform has a different value.)
Davide Italianoef4be6b2015-10-06 19:01:32 +0000296static uint64_t getAArch64Page(uint64_t Expr) {
Davide Italiano318ca222015-10-02 22:13:51 +0000297 return Expr & (~static_cast<uint64_t>(0xFFF));
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000298}
299
Davide Italianocde93362015-09-26 00:32:04 +0000300void AArch64TargetInfo::relocateOne(uint8_t *Buf, const void *RelP,
301 uint32_t Type, uint64_t BaseAddr,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000302 uint64_t SymVA) const {
Davide Italiano1d750a62015-09-27 08:45:38 +0000303 typedef ELFFile<ELF64LE>::Elf_Rela Elf_Rela;
304 auto &Rel = *reinterpret_cast<const Elf_Rela *>(RelP);
305
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000306 uint8_t *L = Buf + Rel.r_offset;
Davide Italiano1d750a62015-09-27 08:45:38 +0000307 uint64_t S = SymVA;
308 int64_t A = Rel.r_addend;
309 uint64_t P = BaseAddr + Rel.r_offset;
310 switch (Type) {
Davide Italianodf88f962015-10-04 00:59:16 +0000311 case R_AARCH64_ABS16:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000312 if (!isInt<16>(S + A))
313 error("Relocation R_AARCH64_ABS16 out of range");
Davide Italiano06d84322015-10-07 22:10:02 +0000314 write16le(L, S + A);
Davide Italianodf88f962015-10-04 00:59:16 +0000315 break;
316 case R_AARCH64_ABS32:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000317 if (!isInt<32>(S + A))
318 error("Relocation R_AARCH64_ABS32 out of range");
Davide Italiano06d84322015-10-07 22:10:02 +0000319 write32le(L, S + A);
Davide Italianodf88f962015-10-04 00:59:16 +0000320 break;
321 case R_AARCH64_ABS64:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000322 // No overflow check needed.
Davide Italiano06d84322015-10-07 22:10:02 +0000323 write64le(L, S + A);
Davide Italianodf88f962015-10-04 00:59:16 +0000324 break;
Davide Italiano0b6974b2015-10-03 19:56:07 +0000325 case R_AARCH64_ADD_ABS_LO12_NC:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000326 // No overflow check needed.
327 or32le(L, ((S + A) & 0xFFF) << 10);
Davide Italiano0b6974b2015-10-03 19:56:07 +0000328 break;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000329 case R_AARCH64_ADR_PREL_LO21: {
330 uint64_t X = S + A - P;
331 if (!isInt<21>(X))
332 error("Relocation R_AARCH64_ADR_PREL_LO21 out of range");
333 updateAArch64Adr(L, X & 0x1FFFFF);
Davide Italiano1d750a62015-09-27 08:45:38 +0000334 break;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000335 }
336 case R_AARCH64_ADR_PREL_PG_HI21: {
337 uint64_t X = getAArch64Page(S + A) - getAArch64Page(P);
338 if (!isInt<33>(X))
339 error("Relocation R_AARCH64_ADR_PREL_PG_HI21 out of range");
340 updateAArch64Adr(L, (X >> 12) & 0x1FFFFF); // X[32:12]
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000341 break;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000342 }
Davide Italiano1d750a62015-09-27 08:45:38 +0000343 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000344 error("unrecognized reloc " + Twine(Type));
Davide Italiano1d750a62015-09-27 08:45:38 +0000345 }
346}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000347
348MipsTargetInfo::MipsTargetInfo() {
349 // PCRelReloc = FIXME
350 // GotReloc = FIXME
Hal Finkele3c26262015-10-08 22:23:54 +0000351 PageSize = 65536;
Hal Finkel47290642015-10-08 21:25:04 +0000352 VAStart = 0x400000;
Simon Atanasyan49829a12015-09-29 05:34:03 +0000353}
354
355void MipsTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
356 uint64_t PltEntryAddr) const {}
357
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000358bool MipsTargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
359 return false;
360}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000361
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000362bool MipsTargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
363 return false;
364}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000365
366void MipsTargetInfo::relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Simon Atanasyan3b732ac2015-10-12 15:10:02 +0000367 uint64_t BaseAddr, uint64_t SymVA) const {
368 typedef ELFFile<ELF32LE>::Elf_Rel Elf_Rel;
369 auto &Rel = *reinterpret_cast<const Elf_Rel *>(RelP);
370
371 switch (Type) {
372 case R_MIPS_32:
373 add32le(Buf + Rel.r_offset, SymVA);
374 break;
375 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000376 error("unrecognized reloc " + Twine(Type));
Simon Atanasyan3b732ac2015-10-12 15:10:02 +0000377 }
378}
Rafael Espindola01205f72015-09-22 18:19:46 +0000379}
380}