64 RecordX86_64Relocation(Writer,
Asm, Layout, Fragment, Fixup,
Target,
67 RecordX86Relocation(Writer,
Asm, Layout, Fragment, Fixup,
Target,
102 void 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))
229 if (
Symbol->isInSection()) {
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);
363 bool 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);
602 std::unique_ptr<MCObjectTargetWriter>
605 return std::make_unique<X86MachObjectWriter>(Is64Bit,
CPUType, CPUSubtype);