Lines Matching +full:loc +full:- +full:code

1 //===- X86.cpp ------------------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
28 const uint8_t *loc) const override;
37 void relocate(uint8_t *loc, const Relocation &rel,
62 // Align to the non-PAE large page size (known as a superpage or huge page). in X86()
63 // FreeBSD automatically promotes large, superpage-aligned allocations. in X86()
73 const uint8_t *loc) const { in getRelExpr()
97 // These relocations are arguably mis-designed because their calculations in getRelExpr()
103 // x86 does not support PC-relative data access. Therefore, in order to in getRelExpr()
104 // access GOT contents, a GOT address needs to be known at link-time in getRelExpr()
105 // (which means non-PIC) or compilers have to emit code to get a GOT in getRelExpr()
106 // address at runtime (which means code is position-independent but in getRelExpr()
107 // compilers need to emit extra code for each GOT access.) This decision in getRelExpr()
108 // is made at compile-time. In the latter case, compilers emit code to in getRelExpr()
121 // offset in the table is known. It's G + A - GOT. in getRelExpr()
127 // The following code implements it. We assume that Loc[0] is the first byte in getRelExpr()
129 // instruction. That means a ModRM byte is at Loc[-1]. By taking a look at in getRelExpr()
131 // absolute address (R_GOT) or a register-relative address (R_GOTPLT). in getRelExpr()
132 return (loc[-1] & 0xc7) == 0x5 ? R_GOT : R_GOTPLT; in getRelExpr()
148 error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) + in getRelExpr()
167 write32le(buf, mainPart->dynamic->getVA()); in writeGotPltHeader()
190 if (config->isPic) { in writePltHeader()
206 uint32_t gotPlt = in.gotPlt->getVA(); in writePltHeader()
213 unsigned relOff = in.relaPlt->entsize * sym.getPltIdx(); in writePlt()
214 if (config->isPic) { in writePlt()
221 write32le(buf + 2, sym.getGotPltVA() - in.gotPlt->getVA()); in writePlt()
233 write32le(buf + 12, in.plt->getVA() - pltEntryAddr - 16); in writePlt()
283 void X86::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const { in relocate() argument
287 // being used for some 16-bit programs such as boot loaders, so in relocate()
289 checkIntUInt(loc, val, 8, rel); in relocate()
290 *loc = val; in relocate()
293 checkInt(loc, val, 8, rel); in relocate()
294 *loc = val; in relocate()
297 checkIntUInt(loc, val, 16, rel); in relocate()
298 write16le(loc, val); in relocate()
301 // R_386_PC16 is normally used with 16 bit code. In that situation in relocate()
311 checkInt(loc, val, 17, rel); in relocate()
312 write16le(loc, val); in relocate()
335 checkInt(loc, val, 32, rel); in relocate()
336 write32le(loc, val); in relocate()
339 // The addend is stored in the second 32-bit word. in relocate()
340 write32le(loc + 4, val); in relocate()
347 static void relaxTlsGdToLe(uint8_t *loc, const Relocation &rel, uint64_t val) { in relaxTlsGdToLe() argument
349 // Convert (loc[-2] == 0x04) in relaxTlsGdToLe()
360 uint8_t *w = loc[-2] == 0x04 ? loc - 3 : loc - 2; in relaxTlsGdToLe()
367 if (memcmp(loc - 2, "\x8d\x83", 2)) { in relaxTlsGdToLe()
368 error(getErrorLocation(loc - 2) + in relaxTlsGdToLe()
372 loc[-1] = 0x05; in relaxTlsGdToLe()
373 write32le(loc, val); in relaxTlsGdToLe()
377 loc[0] = 0x66; in relaxTlsGdToLe()
378 loc[1] = 0x90; in relaxTlsGdToLe()
382 static void relaxTlsGdToIe(uint8_t *loc, const Relocation &rel, uint64_t val) { in relaxTlsGdToIe() argument
384 // Convert (loc[-2] == 0x04) in relaxTlsGdToIe()
394 uint8_t *w = loc[-2] == 0x04 ? loc - 3 : loc - 2; in relaxTlsGdToIe()
399 if (memcmp(loc - 2, "\x8d\x83", 2)) { in relaxTlsGdToIe()
400 error(getErrorLocation(loc - 2) + in relaxTlsGdToIe()
404 loc[-2] = 0x8b; in relaxTlsGdToIe()
405 write32le(loc, val); in relaxTlsGdToIe()
409 loc[0] = 0x66; in relaxTlsGdToIe()
410 loc[1] = 0x90; in relaxTlsGdToIe()
416 static void relaxTlsIeToLe(uint8_t *loc, const Relocation &rel, uint64_t val) { in relaxTlsIeToLe() argument
420 // position dependent code. in relaxTlsIeToLe()
421 uint8_t reg = (loc[-1] >> 3) & 7; in relaxTlsIeToLe()
424 if (loc[-1] == 0xa1) { in relaxTlsIeToLe()
425 // "movl foo@indntpoff,%eax" -> "movl $foo,%eax" in relaxTlsIeToLe()
428 loc[-1] = 0xb8; in relaxTlsIeToLe()
429 } else if (loc[-2] == 0x8b) { in relaxTlsIeToLe()
430 // "movl foo@indntpoff,%reg" -> "movl $foo,%reg" in relaxTlsIeToLe()
431 loc[-2] = 0xc7; in relaxTlsIeToLe()
432 loc[-1] = 0xc0 | reg; in relaxTlsIeToLe()
434 // "addl foo@indntpoff,%reg" -> "addl $foo,%reg" in relaxTlsIeToLe()
435 loc[-2] = 0x81; in relaxTlsIeToLe()
436 loc[-1] = 0xc0 | reg; in relaxTlsIeToLe()
440 if (loc[-2] == 0x8b) { in relaxTlsIeToLe()
441 // "movl foo@gottpoff(%rip),%reg" -> "movl $foo,%reg" in relaxTlsIeToLe()
442 loc[-2] = 0xc7; in relaxTlsIeToLe()
443 loc[-1] = 0xc0 | reg; in relaxTlsIeToLe()
445 // "addl foo@gotntpoff(%rip),%reg" -> "leal foo(%reg),%reg" in relaxTlsIeToLe()
446 loc[-2] = 0x8d; in relaxTlsIeToLe()
447 loc[-1] = 0x80 | (reg << 3) | reg; in relaxTlsIeToLe()
450 write32le(loc, val); in relaxTlsIeToLe()
453 static void relaxTlsLdToLe(uint8_t *loc, const Relocation &rel, uint64_t val) { in relaxTlsLdToLe() argument
455 write32le(loc, val); in relaxTlsLdToLe()
459 if (loc[4] == 0xe8) { in relaxTlsLdToLe()
469 memcpy(loc - 2, inst, sizeof(inst)); in relaxTlsLdToLe()
481 memcpy(loc - 2, inst, sizeof(inst)); in relaxTlsLdToLe()
485 uint64_t secAddr = sec.getOutputSection()->addr; in relocateAlloc()
487 secAddr += s->outSecOff; in relocateAlloc()
489 uint8_t *loc = buf + rel.offset; in relocateAlloc() local
496 relaxTlsGdToIe(loc, rel, val); in relocateAlloc()
500 relaxTlsGdToLe(loc, rel, val); in relocateAlloc()
503 relaxTlsLdToLe(loc, rel, val); in relocateAlloc()
506 relaxTlsIeToLe(loc, rel, val); in relocateAlloc()
509 relocate(loc, rel, val); in relocateAlloc()
535 in.ibtPlt->getVA() + IBTPltHeaderSize + s.getPltIdx() * pltEntrySize; in writeGotPlt()
541 if (config->isPic) { in writePlt()
548 write32le(buf + 6, sym.getGotPltVA() - in.gotPlt->getVA()); in writePlt()
575 write32le(buf + 10, -pltHeaderSize - sizeof(inst) * i - 30); in writeIBTPlt()
633 unsigned relOff = in.relaPlt->entsize * sym.getPltIdx(); in writePlt()
645 uint32_t ebx = in.gotPlt->getVA(); in writePlt()
646 unsigned off = pltEntryAddr - in.plt->getVA(); in writePlt()
647 write32le(buf + 3, sym.getGotPltVA() - ebx); in writePlt()
648 write32le(buf + 8, -off - 12 + 32); in writePlt()
649 write32le(buf + 13, -off - 17 + 18); in writePlt()
651 write32le(buf + 23, -off - 27); in writePlt()
685 uint32_t gotPlt = in.gotPlt->getVA(); in writePltHeader()
692 unsigned relOff = in.relaPlt->entsize * sym.getPltIdx(); in writePlt()
705 unsigned off = pltEntryAddr - in.plt->getVA(); in writePlt()
707 write32le(buf + 7, -off - 11 + 32); in writePlt()
708 write32le(buf + 12, -off - 16 + 17); in writePlt()
710 write32le(buf + 22, -off - 26); in writePlt()
714 if (config->zRetpolineplt) { in getX86TargetInfo()
715 if (config->isPic) { in getX86TargetInfo()
723 if (config->andFeatures & GNU_PROPERTY_X86_FEATURE_1_IBT) { in getX86TargetInfo()