Revert "Fix the build broken by r189315." and "Move everything depending on Object...
[oota-llvm.git] / lib / Target / X86 / MCTargetDesc / X86MachObjectWriter.cpp
1 //===-- X86MachObjectWriter.cpp - X86 Mach-O Writer -----------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "MCTargetDesc/X86MCTargetDesc.h"
11 #include "MCTargetDesc/X86FixupKinds.h"
12 #include "llvm/ADT/Twine.h"
13 #include "llvm/MC/MCAsmLayout.h"
14 #include "llvm/MC/MCAssembler.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCMachObjectWriter.h"
17 #include "llvm/MC/MCSectionMachO.h"
18 #include "llvm/MC/MCValue.h"
19 #include "llvm/Object/MachOFormat.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/Format.h"
22
23 using namespace llvm;
24 using namespace llvm::object;
25
26 namespace {
27 class X86MachObjectWriter : public MCMachObjectTargetWriter {
28   bool RecordScatteredRelocation(MachObjectWriter *Writer,
29                                  const MCAssembler &Asm,
30                                  const MCAsmLayout &Layout,
31                                  const MCFragment *Fragment,
32                                  const MCFixup &Fixup,
33                                  MCValue Target,
34                                  unsigned Log2Size,
35                                  uint64_t &FixedValue);
36   void RecordTLVPRelocation(MachObjectWriter *Writer,
37                             const MCAssembler &Asm,
38                             const MCAsmLayout &Layout,
39                             const MCFragment *Fragment,
40                             const MCFixup &Fixup,
41                             MCValue Target,
42                             uint64_t &FixedValue);
43
44   void RecordX86Relocation(MachObjectWriter *Writer,
45                               const MCAssembler &Asm,
46                               const MCAsmLayout &Layout,
47                               const MCFragment *Fragment,
48                               const MCFixup &Fixup,
49                               MCValue Target,
50                               uint64_t &FixedValue);
51   void RecordX86_64Relocation(MachObjectWriter *Writer,
52                               const MCAssembler &Asm,
53                               const MCAsmLayout &Layout,
54                               const MCFragment *Fragment,
55                               const MCFixup &Fixup,
56                               MCValue Target,
57                               uint64_t &FixedValue);
58 public:
59   X86MachObjectWriter(bool Is64Bit, uint32_t CPUType,
60                       uint32_t CPUSubtype)
61     : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype,
62                                /*UseAggressiveSymbolFolding=*/Is64Bit) {}
63
64   void RecordRelocation(MachObjectWriter *Writer,
65                         const MCAssembler &Asm, const MCAsmLayout &Layout,
66                         const MCFragment *Fragment, const MCFixup &Fixup,
67                         MCValue Target, uint64_t &FixedValue) {
68     if (Writer->is64Bit())
69       RecordX86_64Relocation(Writer, Asm, Layout, Fragment, Fixup, Target,
70                              FixedValue);
71     else
72       RecordX86Relocation(Writer, Asm, Layout, Fragment, Fixup, Target,
73                           FixedValue);
74   }
75 };
76 }
77
78 static bool isFixupKindRIPRel(unsigned Kind) {
79   return Kind == X86::reloc_riprel_4byte ||
80     Kind == X86::reloc_riprel_4byte_movq_load;
81 }
82
83 static unsigned getFixupKindLog2Size(unsigned Kind) {
84   switch (Kind) {
85   default:
86     llvm_unreachable("invalid fixup kind!");
87   case FK_PCRel_1:
88   case FK_Data_1: return 0;
89   case FK_PCRel_2:
90   case FK_Data_2: return 1;
91   case FK_PCRel_4:
92     // FIXME: Remove these!!!
93   case X86::reloc_riprel_4byte:
94   case X86::reloc_riprel_4byte_movq_load:
95   case X86::reloc_signed_4byte:
96   case FK_Data_4: return 2;
97   case FK_Data_8: return 3;
98   }
99 }
100
101 void X86MachObjectWriter::RecordX86_64Relocation(MachObjectWriter *Writer,
102                                                  const MCAssembler &Asm,
103                                                  const MCAsmLayout &Layout,
104                                                  const MCFragment *Fragment,
105                                                  const MCFixup &Fixup,
106                                                  MCValue Target,
107                                                  uint64_t &FixedValue) {
108   unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
109   unsigned IsRIPRel = isFixupKindRIPRel(Fixup.getKind());
110   unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
111
112   // See <reloc.h>.
113   uint32_t FixupOffset =
114     Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
115   uint32_t FixupAddress =
116     Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset();
117   int64_t Value = 0;
118   unsigned Index = 0;
119   unsigned IsExtern = 0;
120   unsigned Type = 0;
121
122   Value = Target.getConstant();
123
124   if (IsPCRel) {
125     // Compensate for the relocation offset, Darwin x86_64 relocations only have
126     // the addend and appear to have attempted to define it to be the actual
127     // expression addend without the PCrel bias. However, instructions with data
128     // following the relocation are not accommodated for (see comment below
129     // regarding SIGNED{1,2,4}), so it isn't exactly that either.
130     Value += 1LL << Log2Size;
131   }
132
133   if (Target.isAbsolute()) { // constant
134     // SymbolNum of 0 indicates the absolute section.
135     Type = macho::RIT_X86_64_Unsigned;
136     Index = 0;
137
138     // FIXME: I believe this is broken, I don't think the linker can understand
139     // it. I think it would require a local relocation, but I'm not sure if that
140     // would work either. The official way to get an absolute PCrel relocation
141     // is to use an absolute symbol (which we don't support yet).
142     if (IsPCRel) {
143       IsExtern = 1;
144       Type = macho::RIT_X86_64_Branch;
145     }
146   } else if (Target.getSymB()) { // A - B + constant
147     const MCSymbol *A = &Target.getSymA()->getSymbol();
148     MCSymbolData &A_SD = Asm.getSymbolData(*A);
149     const MCSymbolData *A_Base = Asm.getAtom(&A_SD);
150
151     const MCSymbol *B = &Target.getSymB()->getSymbol();
152     MCSymbolData &B_SD = Asm.getSymbolData(*B);
153     const MCSymbolData *B_Base = Asm.getAtom(&B_SD);
154
155     // Neither symbol can be modified.
156     if (Target.getSymA()->getKind() != MCSymbolRefExpr::VK_None ||
157         Target.getSymB()->getKind() != MCSymbolRefExpr::VK_None)
158       report_fatal_error("unsupported relocation of modified symbol");
159
160     // We don't support PCrel relocations of differences. Darwin 'as' doesn't
161     // implement most of these correctly.
162     if (IsPCRel)
163       report_fatal_error("unsupported pc-relative relocation of difference");
164
165     // The support for the situation where one or both of the symbols would
166     // require a local relocation is handled just like if the symbols were
167     // external.  This is certainly used in the case of debug sections where the
168     // section has only temporary symbols and thus the symbols don't have base
169     // symbols.  This is encoded using the section ordinal and non-extern
170     // relocation entries.
171
172     // Darwin 'as' doesn't emit correct relocations for this (it ends up with a
173     // single SIGNED relocation); reject it for now.  Except the case where both
174     // symbols don't have a base, equal but both NULL.
175     if (A_Base == B_Base && A_Base)
176       report_fatal_error("unsupported relocation with identical base");
177
178     // A subtraction expression where both symbols are undefined is a
179     // non-relocatable expression.
180     if (A->isUndefined() && B->isUndefined())
181       report_fatal_error("unsupported relocation with subtraction expression");
182
183     Value += Writer->getSymbolAddress(&A_SD, Layout) -
184       (A_Base == NULL ? 0 : Writer->getSymbolAddress(A_Base, Layout));
185     Value -= Writer->getSymbolAddress(&B_SD, Layout) -
186       (B_Base == NULL ? 0 : Writer->getSymbolAddress(B_Base, Layout));
187
188     if (A_Base) {
189       Index = A_Base->getIndex();
190       IsExtern = 1;
191     }
192     else {
193       Index = A_SD.getFragment()->getParent()->getOrdinal() + 1;
194       IsExtern = 0;
195     }
196     Type = macho::RIT_X86_64_Unsigned;
197
198     macho::RelocationEntry MRE;
199     MRE.Word0 = FixupOffset;
200     MRE.Word1 = ((Index     <<  0) |
201                  (IsPCRel   << 24) |
202                  (Log2Size  << 25) |
203                  (IsExtern  << 27) |
204                  (Type      << 28));
205     Writer->addRelocation(Fragment->getParent(), MRE);
206
207     if (B_Base) {
208       Index = B_Base->getIndex();
209       IsExtern = 1;
210     }
211     else {
212       Index = B_SD.getFragment()->getParent()->getOrdinal() + 1;
213       IsExtern = 0;
214     }
215     Type = macho::RIT_X86_64_Subtractor;
216   } else {
217     const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
218     MCSymbolData &SD = Asm.getSymbolData(*Symbol);
219     const MCSymbolData *Base = Asm.getAtom(&SD);
220
221     // Relocations inside debug sections always use local relocations when
222     // possible. This seems to be done because the debugger doesn't fully
223     // understand x86_64 relocation entries, and expects to find values that
224     // have already been fixed up.
225     if (Symbol->isInSection()) {
226       const MCSectionMachO &Section = static_cast<const MCSectionMachO&>(
227         Fragment->getParent()->getSection());
228       if (Section.hasAttribute(MCSectionMachO::S_ATTR_DEBUG))
229         Base = 0;
230     }
231
232     // x86_64 almost always uses external relocations, except when there is no
233     // symbol to use as a base address (a local symbol with no preceding
234     // non-local symbol).
235     if (Base) {
236       Index = Base->getIndex();
237       IsExtern = 1;
238
239       // Add the local offset, if needed.
240       if (Base != &SD)
241         Value += Layout.getSymbolOffset(&SD) - Layout.getSymbolOffset(Base);
242     } else if (Symbol->isInSection() && !Symbol->isVariable()) {
243       // The index is the section ordinal (1-based).
244       Index = SD.getFragment()->getParent()->getOrdinal() + 1;
245       IsExtern = 0;
246       Value += Writer->getSymbolAddress(&SD, Layout);
247
248       if (IsPCRel)
249         Value -= FixupAddress + (1 << Log2Size);
250     } else if (Symbol->isVariable()) {
251       const MCExpr *Value = Symbol->getVariableValue();
252       int64_t Res;
253       bool isAbs = Value->EvaluateAsAbsolute(Res, Layout,
254                                              Writer->getSectionAddressMap());
255       if (isAbs) {
256         FixedValue = Res;
257         return;
258       } else {
259         report_fatal_error("unsupported relocation of variable '" +
260                            Symbol->getName() + "'");
261       }
262     } else {
263       report_fatal_error("unsupported relocation of undefined symbol '" +
264                          Symbol->getName() + "'");
265     }
266
267     MCSymbolRefExpr::VariantKind Modifier = Target.getSymA()->getKind();
268     if (IsPCRel) {
269       if (IsRIPRel) {
270         if (Modifier == MCSymbolRefExpr::VK_GOTPCREL) {
271           // x86_64 distinguishes movq foo@GOTPCREL so that the linker can
272           // rewrite the movq to an leaq at link time if the symbol ends up in
273           // the same linkage unit.
274           if (unsigned(Fixup.getKind()) == X86::reloc_riprel_4byte_movq_load)
275             Type = macho::RIT_X86_64_GOTLoad;
276           else
277             Type = macho::RIT_X86_64_GOT;
278         }  else if (Modifier == MCSymbolRefExpr::VK_TLVP) {
279           Type = macho::RIT_X86_64_TLV;
280         }  else if (Modifier != MCSymbolRefExpr::VK_None) {
281           report_fatal_error("unsupported symbol modifier in relocation");
282         } else {
283           Type = macho::RIT_X86_64_Signed;
284
285           // The Darwin x86_64 relocation format has a problem where it cannot
286           // encode an address (L<foo> + <constant>) which is outside the atom
287           // containing L<foo>. Generally, this shouldn't occur but it does
288           // happen when we have a RIPrel instruction with data following the
289           // relocation entry (e.g., movb $012, L0(%rip)). Even with the PCrel
290           // adjustment Darwin x86_64 uses, the offset is still negative and the
291           // linker has no way to recognize this.
292           //
293           // To work around this, Darwin uses several special relocation types
294           // to indicate the offsets. However, the specification or
295           // implementation of these seems to also be incomplete; they should
296           // adjust the addend as well based on the actual encoded instruction
297           // (the additional bias), but instead appear to just look at the final
298           // offset.
299           switch (-(Target.getConstant() + (1LL << Log2Size))) {
300           case 1: Type = macho::RIT_X86_64_Signed1; break;
301           case 2: Type = macho::RIT_X86_64_Signed2; break;
302           case 4: Type = macho::RIT_X86_64_Signed4; break;
303           }
304         }
305       } else {
306         if (Modifier != MCSymbolRefExpr::VK_None)
307           report_fatal_error("unsupported symbol modifier in branch "
308                              "relocation");
309
310         Type = macho::RIT_X86_64_Branch;
311       }
312     } else {
313       if (Modifier == MCSymbolRefExpr::VK_GOT) {
314         Type = macho::RIT_X86_64_GOT;
315       } else if (Modifier == MCSymbolRefExpr::VK_GOTPCREL) {
316         // GOTPCREL is allowed as a modifier on non-PCrel instructions, in which
317         // case all we do is set the PCrel bit in the relocation entry; this is
318         // used with exception handling, for example. The source is required to
319         // include any necessary offset directly.
320         Type = macho::RIT_X86_64_GOT;
321         IsPCRel = 1;
322       } else if (Modifier == MCSymbolRefExpr::VK_TLVP) {
323         report_fatal_error("TLVP symbol modifier should have been rip-rel");
324       } else if (Modifier != MCSymbolRefExpr::VK_None)
325         report_fatal_error("unsupported symbol modifier in relocation");
326       else
327         Type = macho::RIT_X86_64_Unsigned;
328     }
329   }
330
331   // x86_64 always writes custom values into the fixups.
332   FixedValue = Value;
333
334   // struct relocation_info (8 bytes)
335   macho::RelocationEntry MRE;
336   MRE.Word0 = FixupOffset;
337   MRE.Word1 = ((Index     <<  0) |
338                (IsPCRel   << 24) |
339                (Log2Size  << 25) |
340                (IsExtern  << 27) |
341                (Type      << 28));
342   Writer->addRelocation(Fragment->getParent(), MRE);
343 }
344
345 bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
346                                                     const MCAssembler &Asm,
347                                                     const MCAsmLayout &Layout,
348                                                     const MCFragment *Fragment,
349                                                     const MCFixup &Fixup,
350                                                     MCValue Target,
351                                                     unsigned Log2Size,
352                                                     uint64_t &FixedValue) {
353   uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
354   unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
355   unsigned Type = macho::RIT_Vanilla;
356
357   // See <reloc.h>.
358   const MCSymbol *A = &Target.getSymA()->getSymbol();
359   MCSymbolData *A_SD = &Asm.getSymbolData(*A);
360
361   if (!A_SD->getFragment())
362     report_fatal_error("symbol '" + A->getName() +
363                        "' can not be undefined in a subtraction expression");
364
365   uint32_t Value = Writer->getSymbolAddress(A_SD, Layout);
366   uint64_t SecAddr = Writer->getSectionAddress(A_SD->getFragment()->getParent());
367   FixedValue += SecAddr;
368   uint32_t Value2 = 0;
369
370   if (const MCSymbolRefExpr *B = Target.getSymB()) {
371     MCSymbolData *B_SD = &Asm.getSymbolData(B->getSymbol());
372
373     if (!B_SD->getFragment())
374       report_fatal_error("symbol '" + B->getSymbol().getName() +
375                          "' can not be undefined in a subtraction expression");
376
377     // Select the appropriate difference relocation type.
378     //
379     // Note that there is no longer any semantic difference between these two
380     // relocation types from the linkers point of view, this is done solely for
381     // pedantic compatibility with 'as'.
382     Type = A_SD->isExternal() ? (unsigned)macho::RIT_Difference :
383       (unsigned)macho::RIT_Generic_LocalDifference;
384     Value2 = Writer->getSymbolAddress(B_SD, Layout);
385     FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
386   }
387
388   // Relocations are written out in reverse order, so the PAIR comes first.
389   if (Type == macho::RIT_Difference ||
390       Type == macho::RIT_Generic_LocalDifference) {
391     // If the offset is too large to fit in a scattered relocation,
392     // we're hosed. It's an unfortunate limitation of the MachO format.
393     if (FixupOffset > 0xffffff) {
394       char Buffer[32];
395       format("0x%x", FixupOffset).print(Buffer, sizeof(Buffer));
396       Asm.getContext().FatalError(Fixup.getLoc(),
397                          Twine("Section too large, can't encode "
398                                 "r_address (") + Buffer +
399                          ") into 24 bits of scattered "
400                          "relocation entry.");
401       llvm_unreachable("fatal error returned?!");
402     }
403
404     macho::RelocationEntry MRE;
405     MRE.Word0 = ((0         <<  0) |
406                  (macho::RIT_Pair  << 24) |
407                  (Log2Size  << 28) |
408                  (IsPCRel   << 30) |
409                  macho::RF_Scattered);
410     MRE.Word1 = Value2;
411     Writer->addRelocation(Fragment->getParent(), MRE);
412   } else {
413     // If the offset is more than 24-bits, it won't fit in a scattered
414     // relocation offset field, so we fall back to using a non-scattered
415     // relocation. This is a bit risky, as if the offset reaches out of
416     // the block and the linker is doing scattered loading on this
417     // symbol, things can go badly.
418     //
419     // Required for 'as' compatibility.
420     if (FixupOffset > 0xffffff)
421       return false;
422   }
423
424   macho::RelocationEntry MRE;
425   MRE.Word0 = ((FixupOffset <<  0) |
426                (Type        << 24) |
427                (Log2Size    << 28) |
428                (IsPCRel     << 30) |
429                macho::RF_Scattered);
430   MRE.Word1 = Value;
431   Writer->addRelocation(Fragment->getParent(), MRE);
432   return true;
433 }
434
435 void X86MachObjectWriter::RecordTLVPRelocation(MachObjectWriter *Writer,
436                                                const MCAssembler &Asm,
437                                                const MCAsmLayout &Layout,
438                                                const MCFragment *Fragment,
439                                                const MCFixup &Fixup,
440                                                MCValue Target,
441                                                uint64_t &FixedValue) {
442   assert(Target.getSymA()->getKind() == MCSymbolRefExpr::VK_TLVP &&
443          !is64Bit() &&
444          "Should only be called with a 32-bit TLVP relocation!");
445
446   unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
447   uint32_t Value = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
448   unsigned IsPCRel = 0;
449
450   // Get the symbol data.
451   MCSymbolData *SD_A = &Asm.getSymbolData(Target.getSymA()->getSymbol());
452   unsigned Index = SD_A->getIndex();
453
454   // We're only going to have a second symbol in pic mode and it'll be a
455   // subtraction from the picbase. For 32-bit pic the addend is the difference
456   // between the picbase and the next address.  For 32-bit static the addend is
457   // zero.
458   if (Target.getSymB()) {
459     // If this is a subtraction then we're pcrel.
460     uint32_t FixupAddress =
461       Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset();
462     MCSymbolData *SD_B = &Asm.getSymbolData(Target.getSymB()->getSymbol());
463     IsPCRel = 1;
464     FixedValue = (FixupAddress - Writer->getSymbolAddress(SD_B, Layout) +
465                   Target.getConstant());
466     FixedValue += 1ULL << Log2Size;
467   } else {
468     FixedValue = 0;
469   }
470
471   // struct relocation_info (8 bytes)
472   macho::RelocationEntry MRE;
473   MRE.Word0 = Value;
474   MRE.Word1 = ((Index                  <<  0) |
475                (IsPCRel                << 24) |
476                (Log2Size               << 25) |
477                (1                      << 27) | // Extern
478                (macho::RIT_Generic_TLV << 28)); // Type
479   Writer->addRelocation(Fragment->getParent(), MRE);
480 }
481
482 void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
483                                               const MCAssembler &Asm,
484                                               const MCAsmLayout &Layout,
485                                               const MCFragment *Fragment,
486                                               const MCFixup &Fixup,
487                                               MCValue Target,
488                                               uint64_t &FixedValue) {
489   unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
490   unsigned Log2Size = getFixupKindLog2Size(Fixup.getKind());
491
492   // If this is a 32-bit TLVP reloc it's handled a bit differently.
493   if (Target.getSymA() &&
494       Target.getSymA()->getKind() == MCSymbolRefExpr::VK_TLVP) {
495     RecordTLVPRelocation(Writer, Asm, Layout, Fragment, Fixup, Target,
496                          FixedValue);
497     return;
498   }
499
500   // If this is a difference or a defined symbol plus an offset, then we need a
501   // scattered relocation entry. Differences always require scattered
502   // relocations.
503   if (Target.getSymB()) {
504     RecordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup,
505                               Target, Log2Size, FixedValue);
506     return;
507   }
508
509   // Get the symbol data, if any.
510   MCSymbolData *SD = 0;
511   if (Target.getSymA())
512     SD = &Asm.getSymbolData(Target.getSymA()->getSymbol());
513
514   // If this is an internal relocation with an offset, it also needs a scattered
515   // relocation entry.
516   uint32_t Offset = Target.getConstant();
517   if (IsPCRel)
518     Offset += 1 << Log2Size;
519   // Try to record the scattered relocation if needed. Fall back to non
520   // scattered if necessary (see comments in RecordScatteredRelocation()
521   // for details).
522   if (Offset && SD && !Writer->doesSymbolRequireExternRelocation(SD) &&
523       RecordScatteredRelocation(Writer, Asm, Layout, Fragment, Fixup,
524                                 Target, Log2Size, FixedValue))
525     return;
526
527   // See <reloc.h>.
528   uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
529   unsigned Index = 0;
530   unsigned IsExtern = 0;
531   unsigned Type = 0;
532
533   if (Target.isAbsolute()) { // constant
534     // SymbolNum of 0 indicates the absolute section.
535     //
536     // FIXME: Currently, these are never generated (see code below). I cannot
537     // find a case where they are actually emitted.
538     Type = macho::RIT_Vanilla;
539   } else {
540     // Resolve constant variables.
541     if (SD->getSymbol().isVariable()) {
542       int64_t Res;
543       if (SD->getSymbol().getVariableValue()->EvaluateAsAbsolute(
544             Res, Layout, Writer->getSectionAddressMap())) {
545         FixedValue = Res;
546         return;
547       }
548     }
549
550     // Check whether we need an external or internal relocation.
551     if (Writer->doesSymbolRequireExternRelocation(SD)) {
552       IsExtern = 1;
553       Index = SD->getIndex();
554       // For external relocations, make sure to offset the fixup value to
555       // compensate for the addend of the symbol address, if it was
556       // undefined. This occurs with weak definitions, for example.
557       if (!SD->Symbol->isUndefined())
558         FixedValue -= Layout.getSymbolOffset(SD);
559     } else {
560       // The index is the section ordinal (1-based).
561       const MCSectionData &SymSD = Asm.getSectionData(
562         SD->getSymbol().getSection());
563       Index = SymSD.getOrdinal() + 1;
564       FixedValue += Writer->getSectionAddress(&SymSD);
565     }
566     if (IsPCRel)
567       FixedValue -= Writer->getSectionAddress(Fragment->getParent());
568
569     Type = macho::RIT_Vanilla;
570   }
571
572   // struct relocation_info (8 bytes)
573   macho::RelocationEntry MRE;
574   MRE.Word0 = FixupOffset;
575   MRE.Word1 = ((Index     <<  0) |
576                (IsPCRel   << 24) |
577                (Log2Size  << 25) |
578                (IsExtern  << 27) |
579                (Type      << 28));
580   Writer->addRelocation(Fragment->getParent(), MRE);
581 }
582
583 MCObjectWriter *llvm::createX86MachObjectWriter(raw_ostream &OS,
584                                                 bool Is64Bit,
585                                                 uint32_t CPUType,
586                                                 uint32_t CPUSubtype) {
587   return createMachObjectWriter(new X86MachObjectWriter(Is64Bit,
588                                                         CPUType,
589                                                         CPUSubtype),
590                                 OS, /*IsLittleEndian=*/true);
591 }