blob: 34771223df9468de3b2f9f8f5cec2e901c6e70ff [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 Finkele3c26262015-10-08 22:23:54 +0000203 PageSize = 65536;
Hal Finkel47290642015-10-08 21:25:04 +0000204 VAStart = 0x10000000;
Rafael Espindolac4010882015-09-22 20:54:08 +0000205}
206void PPC64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
207 uint64_t PltEntryAddr) const {}
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000208bool PPC64TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
209 return false;
210}
211bool PPC64TargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
212 return false;
213}
Rafael Espindolac4010882015-09-22 20:54:08 +0000214void PPC64TargetInfo::relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000215 uint64_t BaseAddr, uint64_t SymVA) const {
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000216 typedef ELFFile<ELF64BE>::Elf_Rela Elf_Rela;
217 auto &Rel = *reinterpret_cast<const Elf_Rela *>(RelP);
218
219 uint64_t Offset = Rel.r_offset;
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000220 uint8_t *Loc = Buf + Offset;
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000221 switch (Type) {
222 case R_PPC64_ADDR64:
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000223 write64be(Loc, SymVA + Rel.r_addend);
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000224 break;
225 case R_PPC64_TOC:
226 // We don't create a TOC yet.
227 break;
228 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000229 error("unrecognized reloc " + Twine(Type));
Rafael Espindola3efa4e92015-09-22 21:12:55 +0000230 }
231}
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000232
233PPCTargetInfo::PPCTargetInfo() {
234 // PCRelReloc = FIXME
Rafael Espindola7f074422015-09-22 21:35:51 +0000235 // GotReloc = FIXME
Hal Finkele3c26262015-10-08 22:23:54 +0000236 PageSize = 65536;
Hal Finkel47290642015-10-08 21:25:04 +0000237 VAStart = 0x10000000;
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000238}
239void PPCTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
240 uint64_t PltEntryAddr) const {}
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000241bool PPCTargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
242 return false;
243}
244bool PPCTargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
245 return false;
246}
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000247void PPCTargetInfo::relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000248 uint64_t BaseAddr, uint64_t SymVA) const {}
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000249
250ARMTargetInfo::ARMTargetInfo() {
251 // PCRelReloc = FIXME
Rafael Espindola7f074422015-09-22 21:35:51 +0000252 // GotReloc = FIXME
Hal Finkel47290642015-10-08 21:25:04 +0000253 VAStart = 0x8000;
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000254}
255void ARMTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
256 uint64_t PltEntryAddr) const {}
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000257bool ARMTargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
258 return false;
259}
260bool ARMTargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
261 return false;
262}
Rafael Espindola1d6063e2015-09-22 21:24:52 +0000263void ARMTargetInfo::relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000264 uint64_t BaseAddr, uint64_t SymVA) const {}
Davide Italianocde93362015-09-26 00:32:04 +0000265
266AArch64TargetInfo::AArch64TargetInfo() {
267 // PCRelReloc = FIXME
268 // GotReloc = FIXME
Hal Finkel47290642015-10-08 21:25:04 +0000269 VAStart = 0x400000;
Davide Italianocde93362015-09-26 00:32:04 +0000270}
271void AArch64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
272 uint64_t PltEntryAddr) const {}
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000273bool AArch64TargetInfo::relocNeedsGot(uint32_t Type,
274 const SymbolBody &S) const {
275 return false;
276}
277bool AArch64TargetInfo::relocNeedsPlt(uint32_t Type,
278 const SymbolBody &S) const {
279 return false;
280}
Davide Italiano1d750a62015-09-27 08:45:38 +0000281
Davide Italianoef4be6b2015-10-06 19:01:32 +0000282static void updateAArch64Adr(uint8_t *L, uint64_t Imm) {
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000283 uint32_t ImmLo = (Imm & 0x3) << 29;
284 uint32_t ImmHi = ((Imm & 0x1FFFFC) >> 2) << 5;
285 uint64_t Mask = (0x3 << 29) | (0x7FFFF << 5);
Rui Ueyama87bc41b2015-10-06 18:54:43 +0000286 write32le(L, (read32le(L) & ~Mask) | ImmLo | ImmHi);
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000287}
288
Davide Italiano318ca222015-10-02 22:13:51 +0000289// Page(Expr) is the page address of the expression Expr, defined
290// as (Expr & ~0xFFF). (This applies even if the machine page size
Davide Italianod9b5be42015-10-02 22:17:09 +0000291// supported by the platform has a different value.)
Davide Italianoef4be6b2015-10-06 19:01:32 +0000292static uint64_t getAArch64Page(uint64_t Expr) {
Davide Italiano318ca222015-10-02 22:13:51 +0000293 return Expr & (~static_cast<uint64_t>(0xFFF));
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000294}
295
Davide Italianocde93362015-09-26 00:32:04 +0000296void AArch64TargetInfo::relocateOne(uint8_t *Buf, const void *RelP,
297 uint32_t Type, uint64_t BaseAddr,
Rui Ueyamaaf21d922015-10-08 20:06:07 +0000298 uint64_t SymVA) const {
Davide Italiano1d750a62015-09-27 08:45:38 +0000299 typedef ELFFile<ELF64LE>::Elf_Rela Elf_Rela;
300 auto &Rel = *reinterpret_cast<const Elf_Rela *>(RelP);
301
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000302 uint8_t *L = Buf + Rel.r_offset;
Davide Italiano1d750a62015-09-27 08:45:38 +0000303 uint64_t S = SymVA;
304 int64_t A = Rel.r_addend;
305 uint64_t P = BaseAddr + Rel.r_offset;
306 switch (Type) {
Davide Italianodf88f962015-10-04 00:59:16 +0000307 case R_AARCH64_ABS16:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000308 if (!isInt<16>(S + A))
309 error("Relocation R_AARCH64_ABS16 out of range");
Davide Italiano06d84322015-10-07 22:10:02 +0000310 write16le(L, S + A);
Davide Italianodf88f962015-10-04 00:59:16 +0000311 break;
312 case R_AARCH64_ABS32:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000313 if (!isInt<32>(S + A))
314 error("Relocation R_AARCH64_ABS32 out of range");
Davide Italiano06d84322015-10-07 22:10:02 +0000315 write32le(L, S + A);
Davide Italianodf88f962015-10-04 00:59:16 +0000316 break;
317 case R_AARCH64_ABS64:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000318 // No overflow check needed.
Davide Italiano06d84322015-10-07 22:10:02 +0000319 write64le(L, S + A);
Davide Italianodf88f962015-10-04 00:59:16 +0000320 break;
Davide Italiano0b6974b2015-10-03 19:56:07 +0000321 case R_AARCH64_ADD_ABS_LO12_NC:
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000322 // No overflow check needed.
323 or32le(L, ((S + A) & 0xFFF) << 10);
Davide Italiano0b6974b2015-10-03 19:56:07 +0000324 break;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000325 case R_AARCH64_ADR_PREL_LO21: {
326 uint64_t X = S + A - P;
327 if (!isInt<21>(X))
328 error("Relocation R_AARCH64_ADR_PREL_LO21 out of range");
329 updateAArch64Adr(L, X & 0x1FFFFF);
Davide Italiano1d750a62015-09-27 08:45:38 +0000330 break;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000331 }
332 case R_AARCH64_ADR_PREL_PG_HI21: {
333 uint64_t X = getAArch64Page(S + A) - getAArch64Page(P);
334 if (!isInt<33>(X))
335 error("Relocation R_AARCH64_ADR_PREL_PG_HI21 out of range");
336 updateAArch64Adr(L, (X >> 12) & 0x1FFFFF); // X[32:12]
Davide Italiano1f31a2c2015-10-02 22:00:42 +0000337 break;
Rui Ueyamaee8c53b2015-10-06 19:57:01 +0000338 }
Davide Italiano1d750a62015-09-27 08:45:38 +0000339 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000340 error("unrecognized reloc " + Twine(Type));
Davide Italiano1d750a62015-09-27 08:45:38 +0000341 }
342}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000343
344MipsTargetInfo::MipsTargetInfo() {
345 // PCRelReloc = FIXME
346 // GotReloc = FIXME
Hal Finkele3c26262015-10-08 22:23:54 +0000347 PageSize = 65536;
Hal Finkel47290642015-10-08 21:25:04 +0000348 VAStart = 0x400000;
Simon Atanasyan49829a12015-09-29 05:34:03 +0000349}
350
351void MipsTargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotEntryAddr,
352 uint64_t PltEntryAddr) const {}
353
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000354bool MipsTargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const {
355 return false;
356}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000357
Rafael Espindola3ef3a4c2015-09-29 23:22:16 +0000358bool MipsTargetInfo::relocNeedsPlt(uint32_t Type, const SymbolBody &S) const {
359 return false;
360}
Simon Atanasyan49829a12015-09-29 05:34:03 +0000361
362void MipsTargetInfo::relocateOne(uint8_t *Buf, const void *RelP, uint32_t Type,
Simon Atanasyan3b732ac2015-10-12 15:10:02 +0000363 uint64_t BaseAddr, uint64_t SymVA) const {
364 typedef ELFFile<ELF32LE>::Elf_Rel Elf_Rel;
365 auto &Rel = *reinterpret_cast<const Elf_Rel *>(RelP);
366
367 switch (Type) {
368 case R_MIPS_32:
369 add32le(Buf + Rel.r_offset, SymVA);
370 break;
371 default:
Rui Ueyama1c42afc2015-10-12 15:49:06 +0000372 error("unrecognized reloc " + Twine(Type));
Simon Atanasyan3b732ac2015-10-12 15:10:02 +0000373 }
374}
Rafael Espindola01205f72015-09-22 18:19:46 +0000375}
376}