1 //===- Chunks.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 "Chunks.h" 11 #include "InputFiles.h" 12 #include "Symbols.h" 13 #include "Writer.h" 14 #include "lld/Common/ErrorHandler.h" 15 #include "llvm/ADT/Twine.h" 16 #include "llvm/BinaryFormat/COFF.h" 17 #include "llvm/Object/COFF.h" 18 #include "llvm/Support/Debug.h" 19 #include "llvm/Support/Endian.h" 20 #include "llvm/Support/raw_ostream.h" 21 #include <algorithm> 22 23 using namespace llvm; 24 using namespace llvm::object; 25 using namespace llvm::support::endian; 26 using namespace llvm::COFF; 27 using llvm::support::ulittle32_t; 28 29 namespace lld { 30 namespace coff { 31 32 SectionChunk::SectionChunk(ObjFile *F, const coff_section *H) 33 : Chunk(SectionKind), Repl(this), Header(H), File(F), 34 Relocs(File->getCOFFObj()->getRelocations(Header)), 35 NumRelocs(std::distance(Relocs.begin(), Relocs.end())) { 36 // Initialize SectionName. 37 File->getCOFFObj()->getSectionName(Header, SectionName); 38 39 Alignment = Header->getAlignment(); 40 41 // Chunks may be discarded during comdat merging. 42 Discarded = false; 43 44 // If linker GC is disabled, every chunk starts out alive. If linker GC is 45 // enabled, treat non-comdat sections as roots. Generally optimized object 46 // files will be built with -ffunction-sections or /Gy, so most things worth 47 // stripping will be in a comdat. 48 Live = !Config->DoGC || !isCOMDAT(); 49 } 50 51 static void add16(uint8_t *P, int16_t V) { write16le(P, read16le(P) + V); } 52 static void add32(uint8_t *P, int32_t V) { write32le(P, read32le(P) + V); } 53 static void add64(uint8_t *P, int64_t V) { write64le(P, read64le(P) + V); } 54 static void or16(uint8_t *P, uint16_t V) { write16le(P, read16le(P) | V); } 55 static void or32(uint8_t *P, uint32_t V) { write32le(P, read32le(P) | V); } 56 57 static void applySecRel(const SectionChunk *Sec, uint8_t *Off, 58 OutputSection *OS, uint64_t S) { 59 if (!OS) { 60 if (Sec->isCodeView()) 61 return; 62 fatal("SECREL relocation cannot be applied to absolute symbols"); 63 } 64 uint64_t SecRel = S - OS->getRVA(); 65 if (SecRel > UINT32_MAX) { 66 error("overflow in SECREL relocation in section: " + Sec->getSectionName()); 67 return; 68 } 69 add32(Off, SecRel); 70 } 71 72 static void applySecIdx(uint8_t *Off, OutputSection *OS) { 73 // If we have no output section, this must be an absolute symbol. Use the 74 // sentinel absolute symbol section index. 75 uint16_t SecIdx = OS ? OS->SectionIndex : DefinedAbsolute::OutputSectionIndex; 76 add16(Off, SecIdx); 77 } 78 79 void SectionChunk::applyRelX64(uint8_t *Off, uint16_t Type, OutputSection *OS, 80 uint64_t S, uint64_t P) const { 81 switch (Type) { 82 case IMAGE_REL_AMD64_ADDR32: add32(Off, S + Config->ImageBase); break; 83 case IMAGE_REL_AMD64_ADDR64: add64(Off, S + Config->ImageBase); break; 84 case IMAGE_REL_AMD64_ADDR32NB: add32(Off, S); break; 85 case IMAGE_REL_AMD64_REL32: add32(Off, S - P - 4); break; 86 case IMAGE_REL_AMD64_REL32_1: add32(Off, S - P - 5); break; 87 case IMAGE_REL_AMD64_REL32_2: add32(Off, S - P - 6); break; 88 case IMAGE_REL_AMD64_REL32_3: add32(Off, S - P - 7); break; 89 case IMAGE_REL_AMD64_REL32_4: add32(Off, S - P - 8); break; 90 case IMAGE_REL_AMD64_REL32_5: add32(Off, S - P - 9); break; 91 case IMAGE_REL_AMD64_SECTION: applySecIdx(Off, OS); break; 92 case IMAGE_REL_AMD64_SECREL: applySecRel(this, Off, OS, S); break; 93 default: 94 fatal("unsupported relocation type 0x" + Twine::utohexstr(Type)); 95 } 96 } 97 98 void SectionChunk::applyRelX86(uint8_t *Off, uint16_t Type, OutputSection *OS, 99 uint64_t S, uint64_t P) const { 100 switch (Type) { 101 case IMAGE_REL_I386_ABSOLUTE: break; 102 case IMAGE_REL_I386_DIR32: add32(Off, S + Config->ImageBase); break; 103 case IMAGE_REL_I386_DIR32NB: add32(Off, S); break; 104 case IMAGE_REL_I386_REL32: add32(Off, S - P - 4); break; 105 case IMAGE_REL_I386_SECTION: applySecIdx(Off, OS); break; 106 case IMAGE_REL_I386_SECREL: applySecRel(this, Off, OS, S); break; 107 default: 108 fatal("unsupported relocation type 0x" + Twine::utohexstr(Type)); 109 } 110 } 111 112 static void applyMOV(uint8_t *Off, uint16_t V) { 113 write16le(Off, (read16le(Off) & 0xfbf0) | ((V & 0x800) >> 1) | ((V >> 12) & 0xf)); 114 write16le(Off + 2, (read16le(Off + 2) & 0x8f00) | ((V & 0x700) << 4) | (V & 0xff)); 115 } 116 117 static uint16_t readMOV(uint8_t *Off) { 118 uint16_t Opcode1 = read16le(Off); 119 uint16_t Opcode2 = read16le(Off + 2); 120 uint16_t Imm = (Opcode2 & 0x00ff) | ((Opcode2 >> 4) & 0x0700); 121 Imm |= ((Opcode1 << 1) & 0x0800) | ((Opcode1 & 0x000f) << 12); 122 return Imm; 123 } 124 125 void applyMOV32T(uint8_t *Off, uint32_t V) { 126 uint16_t ImmW = readMOV(Off); // read MOVW operand 127 uint16_t ImmT = readMOV(Off + 4); // read MOVT operand 128 uint32_t Imm = ImmW | (ImmT << 16); 129 V += Imm; // add the immediate offset 130 applyMOV(Off, V); // set MOVW operand 131 applyMOV(Off + 4, V >> 16); // set MOVT operand 132 } 133 134 static void applyBranch20T(uint8_t *Off, int32_t V) { 135 uint32_t S = V < 0 ? 1 : 0; 136 uint32_t J1 = (V >> 19) & 1; 137 uint32_t J2 = (V >> 18) & 1; 138 or16(Off, (S << 10) | ((V >> 12) & 0x3f)); 139 or16(Off + 2, (J1 << 13) | (J2 << 11) | ((V >> 1) & 0x7ff)); 140 } 141 142 void applyBranch24T(uint8_t *Off, int32_t V) { 143 if (!isInt<25>(V)) 144 fatal("relocation out of range"); 145 uint32_t S = V < 0 ? 1 : 0; 146 uint32_t J1 = ((~V >> 23) & 1) ^ S; 147 uint32_t J2 = ((~V >> 22) & 1) ^ S; 148 or16(Off, (S << 10) | ((V >> 12) & 0x3ff)); 149 // Clear out the J1 and J2 bits which may be set. 150 write16le(Off + 2, (read16le(Off + 2) & 0xd000) | (J1 << 13) | (J2 << 11) | ((V >> 1) & 0x7ff)); 151 } 152 153 void SectionChunk::applyRelARM(uint8_t *Off, uint16_t Type, OutputSection *OS, 154 uint64_t S, uint64_t P) const { 155 // Pointer to thumb code must have the LSB set. 156 uint64_t SX = S; 157 if (OS && (OS->getPermissions() & IMAGE_SCN_MEM_EXECUTE)) 158 SX |= 1; 159 switch (Type) { 160 case IMAGE_REL_ARM_ADDR32: add32(Off, SX + Config->ImageBase); break; 161 case IMAGE_REL_ARM_ADDR32NB: add32(Off, SX); break; 162 case IMAGE_REL_ARM_MOV32T: applyMOV32T(Off, SX + Config->ImageBase); break; 163 case IMAGE_REL_ARM_BRANCH20T: applyBranch20T(Off, SX - P - 4); break; 164 case IMAGE_REL_ARM_BRANCH24T: applyBranch24T(Off, SX - P - 4); break; 165 case IMAGE_REL_ARM_BLX23T: applyBranch24T(Off, SX - P - 4); break; 166 case IMAGE_REL_ARM_SECTION: applySecIdx(Off, OS); break; 167 case IMAGE_REL_ARM_SECREL: applySecRel(this, Off, OS, S); break; 168 default: 169 fatal("unsupported relocation type 0x" + Twine::utohexstr(Type)); 170 } 171 } 172 173 // Interpret the existing immediate value as a byte offset to the 174 // target symbol, then update the instruction with the immediate as 175 // the page offset from the current instruction to the target. 176 static void applyArm64Addr(uint8_t *Off, uint64_t S, uint64_t P) { 177 uint32_t Orig = read32le(Off); 178 uint64_t Imm = ((Orig >> 29) & 0x3) | ((Orig >> 3) & 0x1FFFFC); 179 S += Imm; 180 Imm = (S >> 12) - (P >> 12); 181 uint32_t ImmLo = (Imm & 0x3) << 29; 182 uint32_t ImmHi = (Imm & 0x1FFFFC) << 3; 183 uint64_t Mask = (0x3 << 29) | (0x1FFFFC << 3); 184 write32le(Off, (Orig & ~Mask) | ImmLo | ImmHi); 185 } 186 187 // Update the immediate field in a AARCH64 ldr, str, and add instruction. 188 // Optionally limit the range of the written immediate by one or more bits 189 // (RangeLimit). 190 static void applyArm64Imm(uint8_t *Off, uint64_t Imm, uint32_t RangeLimit) { 191 uint32_t Orig = read32le(Off); 192 Imm += (Orig >> 10) & 0xFFF; 193 Orig &= ~(0xFFF << 10); 194 write32le(Off, Orig | ((Imm & (0xFFF >> RangeLimit)) << 10)); 195 } 196 197 // Add the 12 bit page offset to the existing immediate. 198 // Ldr/str instructions store the opcode immediate scaled 199 // by the load/store size (giving a larger range for larger 200 // loads/stores). The immediate is always (both before and after 201 // fixing up the relocation) stored scaled similarly. 202 // Even if larger loads/stores have a larger range, limit the 203 // effective offset to 12 bit, since it is intended to be a 204 // page offset. 205 static void applyArm64Ldr(uint8_t *Off, uint64_t Imm) { 206 uint32_t Orig = read32le(Off); 207 uint32_t Size = Orig >> 30; 208 // 0x04000000 indicates SIMD/FP registers 209 // 0x00800000 indicates 128 bit 210 if ((Orig & 0x4800000) == 0x4800000) 211 Size += 4; 212 if ((Imm & ((1 << Size) - 1)) != 0) 213 fatal("misaligned ldr/str offset"); 214 applyArm64Imm(Off, Imm >> Size, Size); 215 } 216 217 void SectionChunk::applyRelARM64(uint8_t *Off, uint16_t Type, OutputSection *OS, 218 uint64_t S, uint64_t P) const { 219 switch (Type) { 220 case IMAGE_REL_ARM64_PAGEBASE_REL21: applyArm64Addr(Off, S, P); break; 221 case IMAGE_REL_ARM64_PAGEOFFSET_12A: applyArm64Imm(Off, S & 0xfff, 0); break; 222 case IMAGE_REL_ARM64_PAGEOFFSET_12L: applyArm64Ldr(Off, S & 0xfff); break; 223 case IMAGE_REL_ARM64_BRANCH26: or32(Off, ((S - P) & 0x0FFFFFFC) >> 2); break; 224 case IMAGE_REL_ARM64_ADDR32: add32(Off, S + Config->ImageBase); break; 225 case IMAGE_REL_ARM64_ADDR32NB: add32(Off, S); break; 226 case IMAGE_REL_ARM64_ADDR64: add64(Off, S + Config->ImageBase); break; 227 default: 228 fatal("unsupported relocation type 0x" + Twine::utohexstr(Type)); 229 } 230 } 231 232 void SectionChunk::writeTo(uint8_t *Buf) const { 233 if (!hasData()) 234 return; 235 // Copy section contents from source object file to output file. 236 ArrayRef<uint8_t> A = getContents(); 237 memcpy(Buf + OutputSectionOff, A.data(), A.size()); 238 239 // Apply relocations. 240 size_t InputSize = getSize(); 241 for (const coff_relocation &Rel : Relocs) { 242 // Check for an invalid relocation offset. This check isn't perfect, because 243 // we don't have the relocation size, which is only known after checking the 244 // machine and relocation type. As a result, a relocation may overwrite the 245 // beginning of the following input section. 246 if (Rel.VirtualAddress >= InputSize) 247 fatal("relocation points beyond the end of its parent section"); 248 249 uint8_t *Off = Buf + OutputSectionOff + Rel.VirtualAddress; 250 251 // Get the output section of the symbol for this relocation. The output 252 // section is needed to compute SECREL and SECTION relocations used in debug 253 // info. 254 Defined *Sym = cast<Defined>(File->getSymbol(Rel.SymbolTableIndex)); 255 Chunk *C = Sym->getChunk(); 256 OutputSection *OS = C ? C->getOutputSection() : nullptr; 257 258 // Only absolute and __ImageBase symbols lack an output section. For any 259 // other symbol, this indicates that the chunk was discarded. Normally 260 // relocations against discarded sections are an error. However, debug info 261 // sections are not GC roots and can end up with these kinds of relocations. 262 // Skip these relocations. 263 if (!OS && !isa<DefinedAbsolute>(Sym) && !isa<DefinedSynthetic>(Sym)) { 264 if (isCodeView() || isDWARF()) 265 continue; 266 fatal("relocation against symbol in discarded section: " + 267 Sym->getName()); 268 } 269 uint64_t S = Sym->getRVA(); 270 271 // Compute the RVA of the relocation for relative relocations. 272 uint64_t P = RVA + Rel.VirtualAddress; 273 switch (Config->Machine) { 274 case AMD64: 275 applyRelX64(Off, Rel.Type, OS, S, P); 276 break; 277 case I386: 278 applyRelX86(Off, Rel.Type, OS, S, P); 279 break; 280 case ARMNT: 281 applyRelARM(Off, Rel.Type, OS, S, P); 282 break; 283 case ARM64: 284 applyRelARM64(Off, Rel.Type, OS, S, P); 285 break; 286 default: 287 llvm_unreachable("unknown machine type"); 288 } 289 } 290 } 291 292 void SectionChunk::addAssociative(SectionChunk *Child) { 293 AssocChildren.push_back(Child); 294 } 295 296 static uint8_t getBaserelType(const coff_relocation &Rel) { 297 switch (Config->Machine) { 298 case AMD64: 299 if (Rel.Type == IMAGE_REL_AMD64_ADDR64) 300 return IMAGE_REL_BASED_DIR64; 301 return IMAGE_REL_BASED_ABSOLUTE; 302 case I386: 303 if (Rel.Type == IMAGE_REL_I386_DIR32) 304 return IMAGE_REL_BASED_HIGHLOW; 305 return IMAGE_REL_BASED_ABSOLUTE; 306 case ARMNT: 307 if (Rel.Type == IMAGE_REL_ARM_ADDR32) 308 return IMAGE_REL_BASED_HIGHLOW; 309 if (Rel.Type == IMAGE_REL_ARM_MOV32T) 310 return IMAGE_REL_BASED_ARM_MOV32T; 311 return IMAGE_REL_BASED_ABSOLUTE; 312 case ARM64: 313 if (Rel.Type == IMAGE_REL_ARM64_ADDR64) 314 return IMAGE_REL_BASED_DIR64; 315 return IMAGE_REL_BASED_ABSOLUTE; 316 default: 317 llvm_unreachable("unknown machine type"); 318 } 319 } 320 321 // Windows-specific. 322 // Collect all locations that contain absolute addresses, which need to be 323 // fixed by the loader if load-time relocation is needed. 324 // Only called when base relocation is enabled. 325 void SectionChunk::getBaserels(std::vector<Baserel> *Res) { 326 for (const coff_relocation &Rel : Relocs) { 327 uint8_t Ty = getBaserelType(Rel); 328 if (Ty == IMAGE_REL_BASED_ABSOLUTE) 329 continue; 330 if (isa<DefinedAbsolute>(File->getSymbol(Rel.SymbolTableIndex))) 331 continue; 332 Res->emplace_back(RVA + Rel.VirtualAddress, Ty); 333 } 334 } 335 336 bool SectionChunk::hasData() const { 337 return !(Header->Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA); 338 } 339 340 uint32_t SectionChunk::getPermissions() const { 341 return Header->Characteristics & PermMask; 342 } 343 344 bool SectionChunk::isCOMDAT() const { 345 return Header->Characteristics & IMAGE_SCN_LNK_COMDAT; 346 } 347 348 void SectionChunk::printDiscardedMessage() const { 349 // Removed by dead-stripping. If it's removed by ICF, ICF already 350 // printed out the name, so don't repeat that here. 351 if (Sym && this == Repl) { 352 if (Discarded) 353 message("Discarded comdat symbol " + Sym->getName()); 354 else if (!Live) 355 message("Discarded " + Sym->getName()); 356 } 357 } 358 359 StringRef SectionChunk::getDebugName() { 360 if (Sym) 361 return Sym->getName(); 362 return ""; 363 } 364 365 ArrayRef<uint8_t> SectionChunk::getContents() const { 366 ArrayRef<uint8_t> A; 367 File->getCOFFObj()->getSectionContents(Header, A); 368 return A; 369 } 370 371 void SectionChunk::replace(SectionChunk *Other) { 372 Other->Repl = Repl; 373 Other->Live = false; 374 } 375 376 CommonChunk::CommonChunk(const COFFSymbolRef S) : Sym(S) { 377 // Common symbols are aligned on natural boundaries up to 32 bytes. 378 // This is what MSVC link.exe does. 379 Alignment = std::min(uint64_t(32), PowerOf2Ceil(Sym.getValue())); 380 } 381 382 uint32_t CommonChunk::getPermissions() const { 383 return IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | 384 IMAGE_SCN_MEM_WRITE; 385 } 386 387 void StringChunk::writeTo(uint8_t *Buf) const { 388 memcpy(Buf + OutputSectionOff, Str.data(), Str.size()); 389 } 390 391 ImportThunkChunkX64::ImportThunkChunkX64(Defined *S) : ImpSymbol(S) { 392 // Intel Optimization Manual says that all branch targets 393 // should be 16-byte aligned. MSVC linker does this too. 394 Alignment = 16; 395 } 396 397 void ImportThunkChunkX64::writeTo(uint8_t *Buf) const { 398 memcpy(Buf + OutputSectionOff, ImportThunkX86, sizeof(ImportThunkX86)); 399 // The first two bytes is a JMP instruction. Fill its operand. 400 write32le(Buf + OutputSectionOff + 2, ImpSymbol->getRVA() - RVA - getSize()); 401 } 402 403 void ImportThunkChunkX86::getBaserels(std::vector<Baserel> *Res) { 404 Res->emplace_back(getRVA() + 2); 405 } 406 407 void ImportThunkChunkX86::writeTo(uint8_t *Buf) const { 408 memcpy(Buf + OutputSectionOff, ImportThunkX86, sizeof(ImportThunkX86)); 409 // The first two bytes is a JMP instruction. Fill its operand. 410 write32le(Buf + OutputSectionOff + 2, 411 ImpSymbol->getRVA() + Config->ImageBase); 412 } 413 414 void ImportThunkChunkARM::getBaserels(std::vector<Baserel> *Res) { 415 Res->emplace_back(getRVA(), IMAGE_REL_BASED_ARM_MOV32T); 416 } 417 418 void ImportThunkChunkARM::writeTo(uint8_t *Buf) const { 419 memcpy(Buf + OutputSectionOff, ImportThunkARM, sizeof(ImportThunkARM)); 420 // Fix mov.w and mov.t operands. 421 applyMOV32T(Buf + OutputSectionOff, ImpSymbol->getRVA() + Config->ImageBase); 422 } 423 424 void ImportThunkChunkARM64::writeTo(uint8_t *Buf) const { 425 int64_t Off = ImpSymbol->getRVA() & 0xfff; 426 memcpy(Buf + OutputSectionOff, ImportThunkARM64, sizeof(ImportThunkARM64)); 427 applyArm64Addr(Buf + OutputSectionOff, ImpSymbol->getRVA(), RVA); 428 applyArm64Ldr(Buf + OutputSectionOff + 4, Off); 429 } 430 431 void LocalImportChunk::getBaserels(std::vector<Baserel> *Res) { 432 Res->emplace_back(getRVA()); 433 } 434 435 size_t LocalImportChunk::getSize() const { 436 return Config->is64() ? 8 : 4; 437 } 438 439 void LocalImportChunk::writeTo(uint8_t *Buf) const { 440 if (Config->is64()) { 441 write64le(Buf + OutputSectionOff, Sym->getRVA() + Config->ImageBase); 442 } else { 443 write32le(Buf + OutputSectionOff, Sym->getRVA() + Config->ImageBase); 444 } 445 } 446 447 void SEHTableChunk::writeTo(uint8_t *Buf) const { 448 ulittle32_t *Begin = reinterpret_cast<ulittle32_t *>(Buf + OutputSectionOff); 449 size_t Cnt = 0; 450 for (Defined *D : Syms) 451 Begin[Cnt++] = D->getRVA(); 452 std::sort(Begin, Begin + Cnt); 453 } 454 455 // Windows-specific. This class represents a block in .reloc section. 456 // The format is described here. 457 // 458 // On Windows, each DLL is linked against a fixed base address and 459 // usually loaded to that address. However, if there's already another 460 // DLL that overlaps, the loader has to relocate it. To do that, DLLs 461 // contain .reloc sections which contain offsets that need to be fixed 462 // up at runtime. If the loader finds that a DLL cannot be loaded to its 463 // desired base address, it loads it to somewhere else, and add <actual 464 // base address> - <desired base address> to each offset that is 465 // specified by the .reloc section. In ELF terms, .reloc sections 466 // contain relative relocations in REL format (as opposed to RELA.) 467 // 468 // This already significantly reduces the size of relocations compared 469 // to ELF .rel.dyn, but Windows does more to reduce it (probably because 470 // it was invented for PCs in the late '80s or early '90s.) Offsets in 471 // .reloc are grouped by page where the page size is 12 bits, and 472 // offsets sharing the same page address are stored consecutively to 473 // represent them with less space. This is very similar to the page 474 // table which is grouped by (multiple stages of) pages. 475 // 476 // For example, let's say we have 0x00030, 0x00500, 0x00700, 0x00A00, 477 // 0x20004, and 0x20008 in a .reloc section for x64. The uppermost 4 478 // bits have a type IMAGE_REL_BASED_DIR64 or 0xA. In the section, they 479 // are represented like this: 480 // 481 // 0x00000 -- page address (4 bytes) 482 // 16 -- size of this block (4 bytes) 483 // 0xA030 -- entries (2 bytes each) 484 // 0xA500 485 // 0xA700 486 // 0xAA00 487 // 0x20000 -- page address (4 bytes) 488 // 12 -- size of this block (4 bytes) 489 // 0xA004 -- entries (2 bytes each) 490 // 0xA008 491 // 492 // Usually we have a lot of relocations for each page, so the number of 493 // bytes for one .reloc entry is close to 2 bytes on average. 494 BaserelChunk::BaserelChunk(uint32_t Page, Baserel *Begin, Baserel *End) { 495 // Block header consists of 4 byte page RVA and 4 byte block size. 496 // Each entry is 2 byte. Last entry may be padding. 497 Data.resize(alignTo((End - Begin) * 2 + 8, 4)); 498 uint8_t *P = Data.data(); 499 write32le(P, Page); 500 write32le(P + 4, Data.size()); 501 P += 8; 502 for (Baserel *I = Begin; I != End; ++I) { 503 write16le(P, (I->Type << 12) | (I->RVA - Page)); 504 P += 2; 505 } 506 } 507 508 void BaserelChunk::writeTo(uint8_t *Buf) const { 509 memcpy(Buf + OutputSectionOff, Data.data(), Data.size()); 510 } 511 512 uint8_t Baserel::getDefaultType() { 513 switch (Config->Machine) { 514 case AMD64: 515 case ARM64: 516 return IMAGE_REL_BASED_DIR64; 517 case I386: 518 case ARMNT: 519 return IMAGE_REL_BASED_HIGHLOW; 520 default: 521 llvm_unreachable("unknown machine type"); 522 } 523 } 524 525 } // namespace coff 526 } // namespace lld 527