Lines Matching +full:block +full:- +full:fixup
1 //===-- X86MachObjectWriter.cpp - X86 Mach-O Writer -----------------------===//
8 //===----------------------------------------------------------------------===//
32 const MCFixup &Fixup,
40 const MCFixup &Fixup,
48 const MCFixup &Fixup,
53 const MCFragment *Fragment, const MCFixup &Fixup,
62 const MCFixup &Fixup, MCValue Target, in recordRelocation() argument
64 if (Writer->is64Bit()) in recordRelocation()
65 RecordX86_64Relocation(Writer, Asm, Layout, Fragment, Fixup, Target, in recordRelocation()
68 RecordX86Relocation(Writer, Asm, Layout, Fragment, Fixup, Target, in recordRelocation()
84 llvm_unreachable("invalid fixup kind!"); in getFixupKindLog2Size()
104 const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, in RecordX86_64Relocation() argument
106 unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind()); in RecordX86_64Relocation()
107 unsigned IsRIPRel = isFixupKindRIPRel(Fixup.getKind()); in RecordX86_64Relocation()
108 unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind()); in RecordX86_64Relocation()
112 Layout.getFragmentOffset(Fragment) + Fixup.getOffset(); in RecordX86_64Relocation()
114 Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset(); in RecordX86_64Relocation()
144 } else if (Target.getSymB()) { // A - B + constant in RecordX86_64Relocation()
145 const MCSymbol *A = &Target.getSymA()->getSymbol(); in RecordX86_64Relocation()
146 if (A->isTemporary()) in RecordX86_64Relocation()
147 A = &Writer->findAliasedSymbol(*A); in RecordX86_64Relocation()
150 const MCSymbol *B = &Target.getSymB()->getSymbol(); in RecordX86_64Relocation()
151 if (B->isTemporary()) in RecordX86_64Relocation()
152 B = &Writer->findAliasedSymbol(*B); in RecordX86_64Relocation()
156 if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None || in RecordX86_64Relocation()
157 Target.getSymB()->getKind() != MCSymbolRefExpr::VK_None) { in RecordX86_64Relocation()
158 Asm.getContext().reportError(Fixup.getLoc(), in RecordX86_64Relocation()
167 Fixup.getLoc(), "unsupported pc-relative relocation of difference"); in RecordX86_64Relocation()
175 // symbols. This is encoded using the section ordinal and non-extern in RecordX86_64Relocation()
183 Fixup.getLoc(), "unsupported relocation with identical base"); in RecordX86_64Relocation()
188 // non-relocatable expression. in RecordX86_64Relocation()
189 if (A->isUndefined() || B->isUndefined()) { in RecordX86_64Relocation()
190 StringRef Name = A->isUndefined() ? A->getName() : B->getName(); in RecordX86_64Relocation()
191 Asm.getContext().reportError(Fixup.getLoc(), in RecordX86_64Relocation()
197 Value += Writer->getSymbolAddress(*A, Layout) - in RecordX86_64Relocation()
198 (!A_Base ? 0 : Writer->getSymbolAddress(*A_Base, Layout)); in RecordX86_64Relocation()
199 Value -= Writer->getSymbolAddress(*B, Layout) - in RecordX86_64Relocation()
200 (!B_Base ? 0 : Writer->getSymbolAddress(*B_Base, Layout)); in RecordX86_64Relocation()
203 Index = A->getFragment()->getParent()->getOrdinal() + 1; in RecordX86_64Relocation()
210 Writer->addRelocation(A_Base, Fragment->getParent(), MRE); in RecordX86_64Relocation()
215 Index = B->getFragment()->getParent()->getOrdinal() + 1; in RecordX86_64Relocation()
218 const MCSymbol *Symbol = &Target.getSymA()->getSymbol(); in RecordX86_64Relocation()
219 if (Symbol->isTemporary() && Value) { in RecordX86_64Relocation()
220 const MCSection &Sec = Symbol->getSection(); in RecordX86_64Relocation()
221 if (!Asm.getContext().getAsmInfo()->isSectionAtomizableBySymbols(Sec)) in RecordX86_64Relocation()
222 Symbol->setUsedInReloc(); in RecordX86_64Relocation()
230 if (Symbol->isInSection()) { in RecordX86_64Relocation()
232 static_cast<const MCSectionMachO &>(*Fragment->getParent()); in RecordX86_64Relocation()
239 // non-local symbol). in RecordX86_64Relocation()
243 Value += Layout.getSymbolOffset(*Symbol) - in RecordX86_64Relocation()
245 } else if (Symbol->isInSection() && !Symbol->isVariable()) { in RecordX86_64Relocation()
246 // The index is the section ordinal (1-based). in RecordX86_64Relocation()
247 Index = Symbol->getFragment()->getParent()->getOrdinal() + 1; in RecordX86_64Relocation()
248 Value += Writer->getSymbolAddress(*Symbol, Layout); in RecordX86_64Relocation()
251 Value -= FixupAddress + (1 << Log2Size); in RecordX86_64Relocation()
252 } else if (Symbol->isVariable()) { in RecordX86_64Relocation()
253 const MCExpr *Value = Symbol->getVariableValue(); in RecordX86_64Relocation()
255 bool isAbs = Value->evaluateAsAbsolute(Res, Layout, in RecordX86_64Relocation()
256 Writer->getSectionAddressMap()); in RecordX86_64Relocation()
261 Asm.getContext().reportError(Fixup.getLoc(), in RecordX86_64Relocation()
263 Symbol->getName() + "'"); in RecordX86_64Relocation()
268 Fixup.getLoc(), "unsupported relocation of undefined symbol '" + in RecordX86_64Relocation()
269 Symbol->getName() + "'"); in RecordX86_64Relocation()
273 MCSymbolRefExpr::VariantKind Modifier = Target.getSymA()->getKind(); in RecordX86_64Relocation()
280 if (unsigned(Fixup.getKind()) == X86::reloc_riprel_4byte_movq_load) in RecordX86_64Relocation()
288 Fixup.getLoc(), "unsupported symbol modifier in relocation"); in RecordX86_64Relocation()
307 switch (-(Target.getConstant() + (1LL << Log2Size))) { in RecordX86_64Relocation()
316 Fixup.getLoc(), in RecordX86_64Relocation()
327 // GOTPCREL is allowed as a modifier on non-PCrel instructions, in which in RecordX86_64Relocation()
335 Fixup.getLoc(), "TLVP symbol modifier should have been rip-rel"); in RecordX86_64Relocation()
339 Fixup.getLoc(), "unsupported symbol modifier in relocation"); in RecordX86_64Relocation()
343 unsigned Kind = Fixup.getKind(); in RecordX86_64Relocation()
346 Fixup.getLoc(), in RecordX86_64Relocation()
347 "32-bit absolute addressing is not supported in 64-bit mode"); in RecordX86_64Relocation()
362 Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE); in RecordX86_64Relocation()
369 const MCFixup &Fixup, in recordScatteredRelocation() argument
374 uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset(); in recordScatteredRelocation()
375 unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind()); in recordScatteredRelocation()
379 const MCSymbol *A = &Target.getSymA()->getSymbol(); in recordScatteredRelocation()
381 if (!A->getFragment()) { in recordScatteredRelocation()
383 Fixup.getLoc(), in recordScatteredRelocation()
384 "symbol '" + A->getName() + in recordScatteredRelocation()
389 uint32_t Value = Writer->getSymbolAddress(*A, Layout); in recordScatteredRelocation()
390 uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent()); in recordScatteredRelocation()
395 const MCSymbol *SB = &B->getSymbol(); in recordScatteredRelocation()
397 if (!SB->getFragment()) { in recordScatteredRelocation()
399 Fixup.getLoc(), in recordScatteredRelocation()
400 "symbol '" + B->getSymbol().getName() + in recordScatteredRelocation()
410 Type = A->isExternal() ? (unsigned)MachO::GENERIC_RELOC_SECTDIFF in recordScatteredRelocation()
412 Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout); in recordScatteredRelocation()
413 FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent()); in recordScatteredRelocation()
424 Asm.getContext().reportError(Fixup.getLoc(), in recordScatteredRelocation()
439 Writer->addRelocation(nullptr, Fragment->getParent(), MRE); in recordScatteredRelocation()
441 // If the offset is more than 24-bits, it won't fit in a scattered in recordScatteredRelocation()
442 // relocation offset field, so we fall back to using a non-scattered in recordScatteredRelocation()
444 // the block and the linker is doing scattered loading on this in recordScatteredRelocation()
461 Writer->addRelocation(nullptr, Fragment->getParent(), MRE); in recordScatteredRelocation()
469 const MCFixup &Fixup, in recordTLVPRelocation() argument
472 assert(Target.getSymA()->getKind() == MCSymbolRefExpr::VK_TLVP && in recordTLVPRelocation()
474 "Should only be called with a 32-bit TLVP relocation!"); in recordTLVPRelocation()
476 unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind()); in recordTLVPRelocation()
477 uint32_t Value = Layout.getFragmentOffset(Fragment)+Fixup.getOffset(); in recordTLVPRelocation()
481 // subtraction from the picbase. For 32-bit pic the addend is the difference in recordTLVPRelocation()
482 // between the picbase and the next address. For 32-bit static the addend is in recordTLVPRelocation()
487 Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset(); in recordTLVPRelocation()
490 FixupAddress - in recordTLVPRelocation()
491 Writer->getSymbolAddress(Target.getSymB()->getSymbol(), Layout) + in recordTLVPRelocation()
503 Writer->addRelocation(&Target.getSymA()->getSymbol(), Fragment->getParent(), in recordTLVPRelocation()
511 const MCFixup &Fixup, in RecordX86Relocation() argument
514 unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind()); in RecordX86Relocation()
515 unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind()); in RecordX86Relocation()
517 // If this is a 32-bit TLVP reloc it's handled a bit differently. in RecordX86Relocation()
519 Target.getSymA()->getKind() == MCSymbolRefExpr::VK_TLVP) { in RecordX86Relocation()
520 recordTLVPRelocation(Writer, Asm, Layout, Fragment, Fixup, Target, in RecordX86Relocation()
529 recordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup, in RecordX86Relocation()
537 A = &Target.getSymA()->getSymbol(); in RecordX86Relocation()
547 if (Offset && A && !Writer->doesSymbolRequireExternRelocation(*A) && in RecordX86Relocation()
548 recordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup, Target, in RecordX86Relocation()
553 uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset(); in RecordX86Relocation()
566 if (A->isVariable()) { in RecordX86Relocation()
568 if (A->getVariableValue()->evaluateAsAbsolute( in RecordX86Relocation()
569 Res, Layout, Writer->getSectionAddressMap())) { in RecordX86Relocation()
576 if (Writer->doesSymbolRequireExternRelocation(*A)) { in RecordX86Relocation()
578 // For external relocations, make sure to offset the fixup value to in RecordX86Relocation()
581 if (!A->isUndefined()) in RecordX86Relocation()
582 FixedValue -= Layout.getSymbolOffset(*A); in RecordX86Relocation()
584 // The index is the section ordinal (1-based). in RecordX86Relocation()
585 const MCSection &Sec = A->getSection(); in RecordX86Relocation()
587 FixedValue += Writer->getSectionAddress(&Sec); in RecordX86Relocation()
590 FixedValue -= Writer->getSectionAddress(Fragment->getParent()); in RecordX86Relocation()
600 Writer->addRelocation(RelSymbol, Fragment->getParent(), MRE); in RecordX86Relocation()