59 RecordX86_64Relocation(Writer, Asm, Fragment,
Fixup,
Target, FixedValue);
61 RecordX86Relocation(Writer, Asm, Fragment,
Fixup,
Target, FixedValue);
101void X86MachObjectWriter::RecordX86_64Relocation(
109 uint32_t FixupOffset =
Asm.getFragmentOffset(*Fragment) +
Fixup.getOffset();
114 unsigned IsExtern = 0;
116 const MCSymbol *RelSymbol =
nullptr;
126 Value += 1LL << Log2Size;
129 if (
Target.isAbsolute()) {
141 }
else if (
Target.getSymB()) {
143 if (
A->isTemporary())
148 if (
B->isTemporary())
154 Asm.getContext().reportError(
Fixup.getLoc(),
155 "unsupported relocation of modified symbol");
162 Asm.getContext().reportError(
163 Fixup.getLoc(),
"unsupported pc-relative relocation of difference");
177 if (A_Base == B_Base && A_Base) {
178 Asm.getContext().reportError(
179 Fixup.getLoc(),
"unsupported relocation with identical base");
185 if (
A->isUndefined() ||
B->isUndefined()) {
187 Asm.getContext().reportError(
Fixup.getLoc(),
188 "unsupported relocation with subtraction expression, symbol '" +
189 Name +
"' can not be undefined in a subtraction expression");
199 Index =
A->getFragment()->getParent()->getOrdinal() + 1;
205 (
Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (
Type << 28);
211 Index =
B->getFragment()->getParent()->getOrdinal() + 1;
220 RelSymbol = Writer->
getAtom(*Symbol);
226 if (
Symbol->isInSection()) {
238 if (RelSymbol != Symbol)
239 Value +=
Asm.getSymbolOffset(*Symbol) -
Asm.getSymbolOffset(*RelSymbol);
240 }
else if (
Symbol->isInSection() && !
Symbol->isVariable()) {
242 Index =
Symbol->getFragment()->getParent()->getOrdinal() + 1;
246 Value -= FixupAddress + (1 << Log2Size);
247 }
else if (
Symbol->isVariable()) {
256 Asm.getContext().reportError(
Fixup.getLoc(),
257 "unsupported relocation of variable '" +
262 Asm.getContext().reportError(
263 Fixup.getLoc(),
"unsupported relocation of undefined symbol '" +
282 Asm.getContext().reportError(
283 Fixup.getLoc(),
"unsupported symbol modifier in relocation");
302 switch (-(
Target.getConstant() + (1LL << Log2Size))) {
310 Asm.getContext().reportError(
312 "unsupported symbol modifier in branch relocation");
329 Asm.getContext().reportError(
330 Fixup.getLoc(),
"TLVP symbol modifier should have been rip-rel");
333 Asm.getContext().reportError(
334 Fixup.getLoc(),
"unsupported symbol modifier in relocation");
339 Asm.getContext().reportError(
341 "32-bit absolute addressing is not supported in 64-bit mode");
354 MRE.
r_word1 = (
Index << 0) | (IsPCRel << 24) | (Log2Size << 25) |
355 (IsExtern << 27) | (
Type << 28);
359bool X86MachObjectWriter::recordScatteredRelocation(
MachObjectWriter *Writer,
366 uint64_t OriginalFixedValue = FixedValue;
367 uint32_t FixupOffset =
Asm.getFragmentOffset(*Fragment) +
Fixup.getOffset();
374 if (!
A->getFragment()) {
375 Asm.getContext().reportError(
377 "symbol '" +
A->getName() +
378 "' can not be undefined in a subtraction expression");
384 FixedValue += SecAddr;
391 Asm.getContext().reportError(
394 "' can not be undefined in a subtraction expression");
414 if (FixupOffset > 0xffffff) {
416 format(
"0x%x", FixupOffset).print(Buffer,
sizeof(Buffer));
417 Asm.getContext().reportError(
Fixup.getLoc(),
418 Twine(
"Section too large, can't encode "
419 "r_address (") + Buffer +
420 ") into 24 bits of scattered "
421 "relocation entry.");
441 if (FixupOffset > 0xffffff) {
442 FixedValue = OriginalFixedValue;
448 MRE.
r_word0 = ((FixupOffset << 0) |
466 "Should only be called with a 32-bit TLVP relocation!");
470 unsigned IsPCRel = 0;
476 if (
auto *SymB =
Target.getSymB()) {
481 FixedValue = FixupAddress -
484 FixedValue += 1ULL << Log2Size;
509 recordTLVPRelocation(Writer, Asm, Fragment,
Fixup,
Target, FixedValue);
517 recordScatteredRelocation(Writer, Asm, Fragment,
Fixup,
Target, Log2Size,
525 A = &
Target.getSymA()->getSymbol();
537 recordScatteredRelocation(Writer, Asm, Fragment,
Fixup,
Target, Log2Size,
542 uint32_t FixupOffset =
Asm.getFragmentOffset(*Fragment) +
Fixup.getOffset();
545 const MCSymbol *RelSymbol =
nullptr;
547 if (
Target.isAbsolute()) {
554 assert(
A &&
"Unknown symbol data");
557 if (
A->isVariable()) {
559 if (
A->getVariableValue()->evaluateAsAbsolute(
572 if (!
A->isUndefined())
573 FixedValue -=
Asm.getSymbolOffset(*
A);
590 (
Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (
Type << 28);
594std::unique_ptr<MCObjectTargetWriter>
597 return std::make_unique<X86MachObjectWriter>(Is64Bit, CPUType, CPUSubtype);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool is64Bit(const char *name)
static bool isFixupKindRIPRel(unsigned Kind)
static unsigned getFixupKindLog2Size(unsigned Kind)
static bool isSectionAtomizableBySymbols(const MCSection &Section)
True if the section is atomized using the symbols in it.
Base class for the full range of assembler expressions which are needed for parsing.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
MCSection * getParent() const
virtual void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
This represents a section on a Mach-O system (used by Mac OS X).
Instances of this class represent a uniqued identifier for a section in the current translation unit.
unsigned getOrdinal() const
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
VariantKind getKind() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
StringRef getName() const
getName - Get the symbol name.
MCFragment * getFragment(bool SetUsed=true) const
This represents an "assembler immediate".
bool doesSymbolRequireExternRelocation(const MCSymbol &S)
SectionAddrMap & getSectionAddressMap()
uint64_t getFragmentAddress(const MCAssembler &Asm, const MCFragment *Fragment) const
uint64_t getSectionAddress(const MCSection *Sec) const
void addRelocation(const MCSymbol *RelSymbol, const MCSection *Sec, MachO::any_relocation_info &MRE)
bool isFixupKindPCRel(const MCAssembler &Asm, unsigned Kind)
const MCSymbol & findAliasedSymbol(const MCSymbol &Sym) const
uint64_t getSymbolAddress(const MCSymbol &S, const MCAssembler &Asm) const
const MCSymbol * getAtom(const MCSymbol &S) const
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ S_ATTR_DEBUG
S_ATTR_DEBUG - A debug section.
@ GENERIC_RELOC_LOCAL_SECTDIFF
@ X86_64_RELOC_SUBTRACTOR
@ reloc_riprel_4byte_movq_load_rex2
@ reloc_signed_4byte_relax
@ reloc_branch_4byte_pcrel
@ reloc_riprel_4byte_relax
@ reloc_riprel_4byte_relax_evex
@ reloc_riprel_4byte_relax_rex
@ reloc_riprel_4byte_movq_load
@ reloc_riprel_4byte_relax_rex2
This is an optimization pass for GlobalISel generic memory operations.
@ FK_PCRel_4
A four-byte pc relative fixup.
@ FK_PCRel_2
A two-byte pc relative fixup.
@ FK_Data_8
A eight-byte fixup.
@ FK_Data_1
A one-byte fixup.
@ FK_Data_4
A four-byte fixup.
@ FK_PCRel_1
A one-byte pc relative fixup.
@ FK_Data_2
A two-byte fixup.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
std::unique_ptr< MCObjectTargetWriter > createX86MachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype)
Construct an X86 Mach-O object writer.