59 RecordX86_64Relocation(Writer, Asm, Fragment,
Fixup,
Target, FixedValue);
61 RecordX86Relocation(Writer, Asm, Fragment,
Fixup,
Target, FixedValue);
95void X86MachObjectWriter::RecordX86_64Relocation(
103 uint32_t FixupOffset =
Asm.getFragmentOffset(*Fragment) +
Fixup.getOffset();
108 unsigned IsExtern = 0;
110 const MCSymbol *RelSymbol =
nullptr;
120 Value += 1LL << Log2Size;
123 if (
Target.isAbsolute()) {
135 }
else if (
Target.getSymB()) {
137 if (
A->isTemporary())
142 if (
B->isTemporary())
148 Asm.getContext().reportError(
Fixup.getLoc(),
149 "unsupported relocation of modified symbol");
156 Asm.getContext().reportError(
157 Fixup.getLoc(),
"unsupported pc-relative relocation of difference");
171 if (A_Base == B_Base && A_Base) {
172 Asm.getContext().reportError(
173 Fixup.getLoc(),
"unsupported relocation with identical base");
179 if (
A->isUndefined() ||
B->isUndefined()) {
181 Asm.getContext().reportError(
Fixup.getLoc(),
182 "unsupported relocation with subtraction expression, symbol '" +
183 Name +
"' can not be undefined in a subtraction expression");
193 Index =
A->getFragment()->getParent()->getOrdinal() + 1;
199 (
Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (
Type << 28);
205 Index =
B->getFragment()->getParent()->getOrdinal() + 1;
214 RelSymbol = Writer->
getAtom(*Symbol);
220 if (
Symbol->isInSection()) {
232 if (RelSymbol != Symbol)
233 Value +=
Asm.getSymbolOffset(*Symbol) -
Asm.getSymbolOffset(*RelSymbol);
234 }
else if (
Symbol->isInSection() && !
Symbol->isVariable()) {
236 Index =
Symbol->getFragment()->getParent()->getOrdinal() + 1;
240 Value -= FixupAddress + (1 << Log2Size);
241 }
else if (
Symbol->isVariable()) {
250 Asm.getContext().reportError(
Fixup.getLoc(),
251 "unsupported relocation of variable '" +
256 Asm.getContext().reportError(
257 Fixup.getLoc(),
"unsupported relocation of undefined symbol '" +
276 Asm.getContext().reportError(
277 Fixup.getLoc(),
"unsupported symbol modifier in relocation");
296 switch (-(
Target.getConstant() + (1LL << Log2Size))) {
304 Asm.getContext().reportError(
306 "unsupported symbol modifier in branch relocation");
323 Asm.getContext().reportError(
324 Fixup.getLoc(),
"TLVP symbol modifier should have been rip-rel");
327 Asm.getContext().reportError(
328 Fixup.getLoc(),
"unsupported symbol modifier in relocation");
333 Asm.getContext().reportError(
335 "32-bit absolute addressing is not supported in 64-bit mode");
348 MRE.
r_word1 = (
Index << 0) | (IsPCRel << 24) | (Log2Size << 25) |
349 (IsExtern << 27) | (
Type << 28);
353bool X86MachObjectWriter::recordScatteredRelocation(
MachObjectWriter *Writer,
360 uint64_t OriginalFixedValue = FixedValue;
361 uint32_t FixupOffset =
Asm.getFragmentOffset(*Fragment) +
Fixup.getOffset();
368 if (!
A->getFragment()) {
369 Asm.getContext().reportError(
371 "symbol '" +
A->getName() +
372 "' can not be undefined in a subtraction expression");
378 FixedValue += SecAddr;
385 Asm.getContext().reportError(
388 "' can not be undefined in a subtraction expression");
408 if (FixupOffset > 0xffffff) {
410 format(
"0x%x", FixupOffset).print(Buffer,
sizeof(Buffer));
411 Asm.getContext().reportError(
Fixup.getLoc(),
412 Twine(
"Section too large, can't encode "
413 "r_address (") + Buffer +
414 ") into 24 bits of scattered "
415 "relocation entry.");
435 if (FixupOffset > 0xffffff) {
436 FixedValue = OriginalFixedValue;
442 MRE.
r_word0 = ((FixupOffset << 0) |
460 "Should only be called with a 32-bit TLVP relocation!");
464 unsigned IsPCRel = 0;
470 if (
auto *SymB =
Target.getSymB()) {
475 FixedValue = FixupAddress -
478 FixedValue += 1ULL << Log2Size;
503 recordTLVPRelocation(Writer, Asm, Fragment,
Fixup,
Target, FixedValue);
511 recordScatteredRelocation(Writer, Asm, Fragment,
Fixup,
Target, Log2Size,
519 A = &
Target.getSymA()->getSymbol();
531 recordScatteredRelocation(Writer, Asm, Fragment,
Fixup,
Target, Log2Size,
536 uint32_t FixupOffset =
Asm.getFragmentOffset(*Fragment) +
Fixup.getOffset();
539 const MCSymbol *RelSymbol =
nullptr;
541 if (
Target.isAbsolute()) {
548 assert(
A &&
"Unknown symbol data");
551 if (
A->isVariable()) {
553 if (
A->getVariableValue()->evaluateAsAbsolute(
566 if (!
A->isUndefined())
567 FixedValue -=
Asm.getSymbolOffset(*
A);
584 (
Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (
Type << 28);
588std::unique_ptr<MCObjectTargetWriter>
591 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_signed_4byte_relax
@ reloc_branch_4byte_pcrel
@ reloc_riprel_4byte_relax
@ reloc_riprel_4byte_relax_rex
@ reloc_riprel_4byte_movq_load
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.