64 RecordX86_64Relocation(Writer, Asm, Layout, Fragment,
Fixup,
Target,
67 RecordX86Relocation(Writer, Asm, Layout, Fragment,
Fixup,
Target,
102void X86MachObjectWriter::RecordX86_64Relocation(
117 unsigned IsExtern = 0;
119 const MCSymbol *RelSymbol =
nullptr;
129 Value += 1LL << Log2Size;
132 if (
Target.isAbsolute()) {
144 }
else if (
Target.getSymB()) {
146 if (
A->isTemporary())
151 if (
B->isTemporary())
157 Asm.getContext().reportError(
Fixup.getLoc(),
158 "unsupported relocation of modified symbol");
165 Asm.getContext().reportError(
166 Fixup.getLoc(),
"unsupported pc-relative relocation of difference");
180 if (A_Base == B_Base && A_Base) {
181 Asm.getContext().reportError(
182 Fixup.getLoc(),
"unsupported relocation with identical base");
188 if (
A->isUndefined() ||
B->isUndefined()) {
190 Asm.getContext().reportError(
Fixup.getLoc(),
191 "unsupported relocation with subtraction expression, symbol '" +
192 Name +
"' can not be undefined in a subtraction expression");
202 Index =
A->getFragment()->getParent()->getOrdinal() + 1;
208 (
Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (
Type << 28);
214 Index =
B->getFragment()->getParent()->getOrdinal() + 1;
220 if (!
Asm.getContext().getAsmInfo()->isSectionAtomizableBySymbols(Sec))
223 RelSymbol =
Asm.getAtom(*Symbol);
229 if (
Symbol->isInSection()) {
241 if (RelSymbol != Symbol)
244 }
else if (
Symbol->isInSection() && !
Symbol->isVariable()) {
246 Index =
Symbol->getFragment()->getParent()->getOrdinal() + 1;
250 Value -= FixupAddress + (1 << Log2Size);
251 }
else if (
Symbol->isVariable()) {
254 bool isAbs =
Value->evaluateAsAbsolute(Res, Layout,
260 Asm.getContext().reportError(
Fixup.getLoc(),
261 "unsupported relocation of variable '" +
266 Asm.getContext().reportError(
267 Fixup.getLoc(),
"unsupported relocation of undefined symbol '" +
286 Asm.getContext().reportError(
287 Fixup.getLoc(),
"unsupported symbol modifier in relocation");
306 switch (-(
Target.getConstant() + (1LL << Log2Size))) {
314 Asm.getContext().reportError(
316 "unsupported symbol modifier in branch relocation");
333 Asm.getContext().reportError(
334 Fixup.getLoc(),
"TLVP symbol modifier should have been rip-rel");
337 Asm.getContext().reportError(
338 Fixup.getLoc(),
"unsupported symbol modifier in relocation");
343 Asm.getContext().reportError(
345 "32-bit absolute addressing is not supported in 64-bit mode");
358 MRE.
r_word1 = (
Index << 0) | (IsPCRel << 24) | (Log2Size << 25) |
359 (IsExtern << 27) | (
Type << 28);
363bool X86MachObjectWriter::recordScatteredRelocation(
MachObjectWriter *Writer,
371 uint64_t OriginalFixedValue = FixedValue;
379 if (!
A->getFragment()) {
380 Asm.getContext().reportError(
382 "symbol '" +
A->getName() +
383 "' can not be undefined in a subtraction expression");
389 FixedValue += SecAddr;
396 Asm.getContext().reportError(
399 "' can not be undefined in a subtraction expression");
419 if (FixupOffset > 0xffffff) {
421 format(
"0x%x", FixupOffset).print(Buffer,
sizeof(Buffer));
422 Asm.getContext().reportError(
Fixup.getLoc(),
423 Twine(
"Section too large, can't encode "
424 "r_address (") + Buffer +
425 ") into 24 bits of scattered "
426 "relocation entry.");
446 if (FixupOffset > 0xffffff) {
447 FixedValue = OriginalFixedValue;
453 MRE.
r_word0 = ((FixupOffset << 0) |
472 "Should only be called with a 32-bit TLVP relocation!");
476 unsigned IsPCRel = 0;
482 if (
auto *SymB =
Target.getSymB()) {
487 FixedValue = FixupAddress -
490 FixedValue += 1ULL << Log2Size;
516 recordTLVPRelocation(Writer, Asm, Layout, Fragment,
Fixup,
Target,
525 recordScatteredRelocation(Writer, Asm, Layout, Fragment,
Fixup,
526 Target, Log2Size, FixedValue);
533 A = &
Target.getSymA()->getSymbol();
545 recordScatteredRelocation(Writer, Asm, Layout, Fragment,
Fixup,
Target,
546 Log2Size, FixedValue))
553 const MCSymbol *RelSymbol =
nullptr;
555 if (
Target.isAbsolute()) {
562 assert(
A &&
"Unknown symbol data");
565 if (
A->isVariable()) {
567 if (
A->getVariableValue()->evaluateAsAbsolute(
580 if (!
A->isUndefined())
598 (
Index << 0) | (IsPCRel << 24) | (Log2Size << 25) | (
Type << 28);
602std::unique_ptr<MCObjectTargetWriter>
605 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)
Encapsulates the layout of an assembly file at a particular point in time.
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
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 MCAsmLayout &Layout, 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)
uint64_t getSymbolAddress(const MCSymbol &S, const MCAsmLayout &Layout) const
SectionAddrMap & getSectionAddressMap()
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 getFragmentAddress(const MCFragment *Fragment, const MCAsmLayout &Layout) 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.