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