blob: 20b64e2eeb9cd19899da12d9786304e1408d9a43 [file] [log] [blame]
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +00001//===- lib/MC/MCAssembler.cpp - Assembler Backend Implementation ----------===//
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
Daniel Dunbar0adcd352009-08-25 21:10:45 +000010#define DEBUG_TYPE "assembler"
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000011#include "llvm/MC/MCAssembler.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000012#include "llvm/ADT/Statistic.h"
13#include "llvm/ADT/StringExtras.h"
14#include "llvm/ADT/Twine.h"
15#include "llvm/MC/MCAsmBackend.h"
Daniel Dunbar18ff2cc2010-03-11 05:53:33 +000016#include "llvm/MC/MCAsmLayout.h"
Daniel Dunbarb36052f2010-03-19 10:43:23 +000017#include "llvm/MC/MCCodeEmitter.h"
Rafael Espindolafea753b2010-12-24 21:22:02 +000018#include "llvm/MC/MCContext.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000019#include "llvm/MC/MCDwarf.h"
Daniel Dunbar1253a6f2009-10-16 01:58:03 +000020#include "llvm/MC/MCExpr.h"
Craig Topperf1d0f772012-03-26 06:58:25 +000021#include "llvm/MC/MCFixupKindInfo.h"
Daniel Dunbar53b23382010-03-19 09:28:59 +000022#include "llvm/MC/MCObjectWriter.h"
Kevin Enderbyc0957932010-09-30 16:52:03 +000023#include "llvm/MC/MCSection.h"
Daniel Dunbar1253a6f2009-10-16 01:58:03 +000024#include "llvm/MC/MCSymbol.h"
25#include "llvm/MC/MCValue.h"
Daniel Dunbarac2884a2010-03-25 22:49:09 +000026#include "llvm/Support/Debug.h"
Daniel Dunbar0705fbf2009-08-21 18:29:01 +000027#include "llvm/Support/ErrorHandling.h"
Jim Grosbach2d39a0e2012-08-08 23:56:06 +000028#include "llvm/Support/LEB128.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000029#include "llvm/Support/TargetRegistry.h"
30#include "llvm/Support/raw_ostream.h"
Daniel Dunbarf6346762010-02-13 09:29:02 +000031
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000032using namespace llvm;
33
Daniel Dunbarff547842010-03-23 23:47:14 +000034namespace {
35namespace stats {
Eli Bendersky8ddc5a12012-12-07 17:59:21 +000036STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total");
Eli Bendersky6ac81f52012-12-10 18:59:39 +000037STATISTIC(EmittedInstFragments,
38 "Number of emitted assembler fragments - instruction");
39STATISTIC(EmittedDataFragments,
40 "Number of emitted assembler fragments - data");
41STATISTIC(EmittedAlignFragments,
42 "Number of emitted assembler fragments - align");
43STATISTIC(EmittedFillFragments,
44 "Number of emitted assembler fragments - fill");
45STATISTIC(EmittedOrgFragments,
46 "Number of emitted assembler fragments - org");
Jim Grosbachf77d5b12011-12-06 00:03:48 +000047STATISTIC(evaluateFixup, "Number of evaluated fixups");
Daniel Dunbarac2884a2010-03-25 22:49:09 +000048STATISTIC(FragmentLayouts, "Number of fragment layouts");
Daniel Dunbarff547842010-03-23 23:47:14 +000049STATISTIC(ObjectBytes, "Number of emitted object file bytes");
Daniel Dunbarac2884a2010-03-25 22:49:09 +000050STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
51STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
Daniel Dunbarff547842010-03-23 23:47:14 +000052}
53}
Daniel Dunbar0adcd352009-08-25 21:10:45 +000054
Daniel Dunbar8f4d1462009-08-28 07:08:35 +000055// FIXME FIXME FIXME: There are number of places in this file where we convert
56// what is a 64-bit assembler value used for computation into a value in the
57// object file, which may truncate it. We should detect that truncation where
58// invalid and report errors back.
59
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +000060/* *** */
61
Daniel Dunbar9005d452010-05-14 00:37:21 +000062MCAsmLayout::MCAsmLayout(MCAssembler &Asm)
Rafael Espindola4f4363a2010-12-07 23:32:26 +000063 : Assembler(Asm), LastValidFragment()
Daniel Dunbar9005d452010-05-14 00:37:21 +000064 {
Daniel Dunbarbc1a0cf2010-05-12 15:42:59 +000065 // Compute the section layout order. Virtual sections must go last.
66 for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
Rafael Espindolaf2dc4aa2010-11-17 20:03:54 +000067 if (!it->getSection().isVirtualSection())
Daniel Dunbarbc1a0cf2010-05-12 15:42:59 +000068 SectionOrder.push_back(&*it);
69 for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
Rafael Espindolaf2dc4aa2010-11-17 20:03:54 +000070 if (it->getSection().isVirtualSection())
Daniel Dunbarbc1a0cf2010-05-12 15:42:59 +000071 SectionOrder.push_back(&*it);
72}
73
Eli Benderskyd52a2c02012-12-12 19:54:05 +000074bool MCAsmLayout::isFragmentValid(const MCFragment *F) const {
Rafael Espindola4f4363a2010-12-07 23:32:26 +000075 const MCSectionData &SD = *F->getParent();
76 const MCFragment *LastValid = LastValidFragment.lookup(&SD);
77 if (!LastValid)
78 return false;
79 assert(LastValid->getParent() == F->getParent());
80 return F->getLayoutOrder() <= LastValid->getLayoutOrder();
Daniel Dunbar9005d452010-05-14 00:37:21 +000081}
82
Eli Benderskyf43e3fd2012-12-10 20:13:43 +000083void MCAsmLayout::invalidateFragmentsAfter(MCFragment *F) {
Eli Benderskyd52a2c02012-12-12 19:54:05 +000084 // If this fragment wasn't already valid, we don't need to do anything.
85 if (!isFragmentValid(F))
Daniel Dunbar47b3ec42010-05-14 00:51:14 +000086 return;
Daniel Dunbar0cc8bd42010-03-25 19:35:56 +000087
Rafael Espindola2bf6afc2010-12-15 08:45:53 +000088 // Otherwise, reset the last valid fragment to this fragment.
Rafael Espindola4f4363a2010-12-07 23:32:26 +000089 const MCSectionData &SD = *F->getParent();
Rafael Espindola2bf6afc2010-12-15 08:45:53 +000090 LastValidFragment[&SD] = F;
Daniel Dunbar47b3ec42010-05-14 00:51:14 +000091}
Daniel Dunbar0cc8bd42010-03-25 19:35:56 +000092
Eli Benderskyd52a2c02012-12-12 19:54:05 +000093void MCAsmLayout::ensureValid(const MCFragment *F) const {
Rafael Espindola4f4363a2010-12-07 23:32:26 +000094 MCSectionData &SD = *F->getParent();
95
96 MCFragment *Cur = LastValidFragment[&SD];
97 if (!Cur)
98 Cur = &*SD.begin();
99 else
100 Cur = Cur->getNextNode();
101
Eli Benderskyd52a2c02012-12-12 19:54:05 +0000102 // Advance the layout position until the fragment is valid.
103 while (!isFragmentValid(F)) {
104 assert(Cur && "Layout bookkeeping error");
105 const_cast<MCAsmLayout*>(this)->layoutFragment(Cur);
Rafael Espindola4f4363a2010-12-07 23:32:26 +0000106 Cur = Cur->getNextNode();
Daniel Dunbar47b3ec42010-05-14 00:51:14 +0000107 }
Daniel Dunbar0cc8bd42010-03-25 19:35:56 +0000108}
109
Daniel Dunbar432cd5f2010-03-25 02:00:02 +0000110uint64_t MCAsmLayout::getFragmentOffset(const MCFragment *F) const {
Eli Benderskyd52a2c02012-12-12 19:54:05 +0000111 ensureValid(F);
Daniel Dunbar432cd5f2010-03-25 02:00:02 +0000112 assert(F->Offset != ~UINT64_C(0) && "Address not set!");
113 return F->Offset;
114}
115
Rafael Espindolaffd902b2010-12-06 02:57:26 +0000116uint64_t MCAsmLayout::getSymbolOffset(const MCSymbolData *SD) const {
Daniel Dunbarc8497b62011-04-29 18:20:20 +0000117 const MCSymbol &S = SD->getSymbol();
118
119 // If this is a variable, then recursively evaluate now.
120 if (S.isVariable()) {
121 MCValue Target;
122 if (!S.getVariableValue()->EvaluateAsRelocatable(Target, *this))
123 report_fatal_error("unable to evaluate offset for variable '" +
124 S.getName() + "'");
125
126 // Verify that any used symbols are defined.
127 if (Target.getSymA() && Target.getSymA()->getSymbol().isUndefined())
128 report_fatal_error("unable to evaluate offset to undefined symbol '" +
129 Target.getSymA()->getSymbol().getName() + "'");
130 if (Target.getSymB() && Target.getSymB()->getSymbol().isUndefined())
131 report_fatal_error("unable to evaluate offset to undefined symbol '" +
132 Target.getSymB()->getSymbol().getName() + "'");
Jim Grosbach684457d2011-10-26 22:44:41 +0000133
Daniel Dunbarc8497b62011-04-29 18:20:20 +0000134 uint64_t Offset = Target.getConstant();
135 if (Target.getSymA())
136 Offset += getSymbolOffset(&Assembler.getSymbolData(
137 Target.getSymA()->getSymbol()));
138 if (Target.getSymB())
139 Offset -= getSymbolOffset(&Assembler.getSymbolData(
140 Target.getSymB()->getSymbol()));
141 return Offset;
142 }
143
Rafael Espindolaffd902b2010-12-06 02:57:26 +0000144 assert(SD->getFragment() && "Invalid getOffset() on undefined symbol!");
145 return getFragmentOffset(SD->getFragment()) + SD->getOffset();
146}
147
Daniel Dunbar2661f112010-05-13 03:19:50 +0000148uint64_t MCAsmLayout::getSectionAddressSize(const MCSectionData *SD) const {
Daniel Dunbarafc6acd2010-05-14 00:37:11 +0000149 // The size is the last fragment's end offset.
Daniel Dunbar2661f112010-05-13 03:19:50 +0000150 const MCFragment &F = SD->getFragmentList().back();
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000151 return getFragmentOffset(&F) + getAssembler().computeFragmentSize(*this, F);
Daniel Dunbar5d428512010-03-25 02:00:07 +0000152}
153
154uint64_t MCAsmLayout::getSectionFileSize(const MCSectionData *SD) const {
Daniel Dunbar2661f112010-05-13 03:19:50 +0000155 // Virtual sections have no file size.
Rafael Espindolaf2dc4aa2010-11-17 20:03:54 +0000156 if (SD->getSection().isVirtualSection())
Daniel Dunbar2661f112010-05-13 03:19:50 +0000157 return 0;
158
159 // Otherwise, the file size is the same as the address space size.
160 return getSectionAddressSize(SD);
Daniel Dunbar5d428512010-03-25 02:00:07 +0000161}
162
Eli Bendersky4766ef42012-12-20 19:05:53 +0000163uint64_t MCAsmLayout::computeBundlePadding(const MCFragment *F,
164 uint64_t FOffset, uint64_t FSize) {
165 uint64_t BundleSize = Assembler.getBundleAlignSize();
166 assert(BundleSize > 0 &&
167 "computeBundlePadding should only be called if bundling is enabled");
168 uint64_t BundleMask = BundleSize - 1;
169 uint64_t OffsetInBundle = FOffset & BundleMask;
170
171 // If the fragment would cross a bundle boundary, add enough padding until
172 // the end of the current bundle.
173 if (OffsetInBundle + FSize > BundleSize)
174 return BundleSize - OffsetInBundle;
175 else
176 return 0;
177}
178
Daniel Dunbar207e06e2010-03-24 03:43:40 +0000179/* *** */
180
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000181MCFragment::MCFragment() : Kind(FragmentType(~0)) {
182}
183
Daniel Dunbar36880e72010-07-28 20:28:45 +0000184MCFragment::~MCFragment() {
185}
186
Daniel Dunbar5e835962009-08-26 02:48:04 +0000187MCFragment::MCFragment(FragmentType _Kind, MCSectionData *_Parent)
Rafael Espindola2bf6afc2010-12-15 08:45:53 +0000188 : Kind(_Kind), Parent(_Parent), Atom(0), Offset(~UINT64_C(0))
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000189{
Daniel Dunbar5e835962009-08-26 02:48:04 +0000190 if (Parent)
191 Parent->getFragmentList().push_back(this);
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000192}
193
194/* *** */
195
Eli Bendersky64d9a322012-12-07 19:13:57 +0000196MCEncodedFragment::~MCEncodedFragment() {
197}
198
199/* *** */
200
Daniel Dunbar81e40002009-08-27 00:38:04 +0000201MCSectionData::MCSectionData() : Section(0) {}
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000202
203MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
Daniel Dunbar81e40002009-08-27 00:38:04 +0000204 : Section(&_Section),
Rafael Espindolaf8803fe2010-12-06 03:48:09 +0000205 Ordinal(~UINT32_C(0)),
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000206 Alignment(1),
Eli Bendersky4766ef42012-12-20 19:05:53 +0000207 BundleLocked(false), BundleGroupBeforeFirstInst(false),
Daniel Dunbare1ec6172010-02-02 21:44:01 +0000208 HasInstructions(false)
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000209{
210 if (A)
211 A->getSectionList().push_back(this);
212}
213
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000214/* *** */
215
Daniel Dunbarefbb5332009-09-01 04:09:03 +0000216MCSymbolData::MCSymbolData() : Symbol(0) {}
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +0000217
Daniel Dunbarcb579b32009-08-31 08:08:06 +0000218MCSymbolData::MCSymbolData(const MCSymbol &_Symbol, MCFragment *_Fragment,
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +0000219 uint64_t _Offset, MCAssembler *A)
Daniel Dunbarefbb5332009-09-01 04:09:03 +0000220 : Symbol(&_Symbol), Fragment(_Fragment), Offset(_Offset),
Daniel Dunbar8f4d1462009-08-28 07:08:35 +0000221 IsExternal(false), IsPrivateExtern(false),
Matt Fleming6c8b3d22010-08-16 18:34:31 +0000222 CommonSize(0), SymbolSize(0), CommonAlign(0),
223 Flags(0), Index(0)
Daniel Dunbarf3d2ef02009-08-22 10:13:24 +0000224{
225 if (A)
226 A->getSymbolList().push_back(this);
227}
228
229/* *** */
230
Evan Cheng78c10ee2011-07-25 23:24:55 +0000231MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
Daniel Dunbarfeb7ba32010-12-17 02:45:41 +0000232 MCCodeEmitter &Emitter_, MCObjectWriter &Writer_,
233 raw_ostream &OS_)
234 : Context(Context_), Backend(Backend_), Emitter(Emitter_), Writer(Writer_),
Eli Benderskybc873612012-12-20 22:51:52 +0000235 OS(OS_), BundleAlignSize(0), RelaxAll(false), NoExecStack(false),
236 SubsectionsViaSymbols(false) {
Daniel Dunbar6009db42009-08-26 21:22:22 +0000237}
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000238
239MCAssembler::~MCAssembler() {
240}
241
Pedro Artigas5399d252012-12-12 22:59:46 +0000242void MCAssembler::reset() {
243 Sections.clear();
244 Symbols.clear();
245 SectionMap.clear();
246 SymbolMap.clear();
247 IndirectSymbols.clear();
248 DataRegions.clear();
249 ThumbFuncs.clear();
250 RelaxAll = false;
251 NoExecStack = false;
252 SubsectionsViaSymbols = false;
Pedro Artigas99cbdde2012-12-14 18:52:11 +0000253
254 // reset objects owned by us
255 getBackend().reset();
256 getEmitter().reset();
257 getWriter().reset();
Pedro Artigas5399d252012-12-12 22:59:46 +0000258}
259
Daniel Dunbar843aa1f2010-06-16 20:04:29 +0000260bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const {
Daniel Dunbar23869852010-03-19 03:18:09 +0000261 // Non-temporary labels should always be visible to the linker.
Daniel Dunbar843aa1f2010-06-16 20:04:29 +0000262 if (!Symbol.isTemporary())
Daniel Dunbar23869852010-03-19 03:18:09 +0000263 return true;
264
265 // Absolute temporary labels are never visible.
Daniel Dunbar843aa1f2010-06-16 20:04:29 +0000266 if (!Symbol.isInSection())
Daniel Dunbar23869852010-03-19 03:18:09 +0000267 return false;
268
269 // Otherwise, check if the section requires symbols even for temporary labels.
Daniel Dunbar843aa1f2010-06-16 20:04:29 +0000270 return getBackend().doesSectionRequireSymbols(Symbol.getSection());
Daniel Dunbar23869852010-03-19 03:18:09 +0000271}
272
Rafael Espindolab8141102010-09-27 18:13:03 +0000273const MCSymbolData *MCAssembler::getAtom(const MCSymbolData *SD) const {
Daniel Dunbar8ad0dcc2010-03-19 03:18:15 +0000274 // Linker visible symbols define atoms.
Daniel Dunbar843aa1f2010-06-16 20:04:29 +0000275 if (isSymbolLinkerVisible(SD->getSymbol()))
Daniel Dunbar8ad0dcc2010-03-19 03:18:15 +0000276 return SD;
277
278 // Absolute and undefined symbols have no defining atom.
279 if (!SD->getFragment())
280 return 0;
281
Daniel Dunbara5f1d572010-05-12 00:38:17 +0000282 // Non-linker visible symbols in sections which can't be atomized have no
283 // defining atom.
284 if (!getBackend().isSectionAtomizable(
285 SD->getFragment()->getParent()->getSection()))
286 return 0;
287
Daniel Dunbar651804c2010-05-11 17:22:50 +0000288 // Otherwise, return the atom for the containing fragment.
289 return SD->getFragment()->getAtom();
Daniel Dunbar8ad0dcc2010-03-19 03:18:15 +0000290}
291
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000292bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
Daniel Dunbarc90e30a2010-05-26 15:18:56 +0000293 const MCFixup &Fixup, const MCFragment *DF,
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000294 MCValue &Target, uint64_t &Value) const {
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000295 ++stats::evaluateFixup;
Daniel Dunbarff547842010-03-23 23:47:14 +0000296
Rafael Espindola33a38a12010-12-22 16:11:57 +0000297 if (!Fixup.getValue()->EvaluateAsRelocatable(Target, Layout))
Jim Grosbachf3c93672012-01-27 00:51:23 +0000298 getContext().FatalError(Fixup.getLoc(), "expected relocatable expression");
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000299
Rafael Espindolafea753b2010-12-24 21:22:02 +0000300 bool IsPCRel = Backend.getFixupKindInfo(
301 Fixup.getKind()).Flags & MCFixupKindInfo::FKF_IsPCRel;
302
303 bool IsResolved;
304 if (IsPCRel) {
305 if (Target.getSymB()) {
306 IsResolved = false;
307 } else if (!Target.getSymA()) {
308 IsResolved = false;
309 } else {
Rafael Espindola908159b2011-02-16 03:25:55 +0000310 const MCSymbolRefExpr *A = Target.getSymA();
311 const MCSymbol &SA = A->getSymbol();
312 if (A->getKind() != MCSymbolRefExpr::VK_None ||
313 SA.AliasedSymbol().isUndefined()) {
Rafael Espindolafea753b2010-12-24 21:22:02 +0000314 IsResolved = false;
315 } else {
316 const MCSymbolData &DataA = getSymbolData(SA);
317 IsResolved =
318 getWriter().IsSymbolRefDifferenceFullyResolvedImpl(*this, DataA,
319 *DF, false, true);
320 }
321 }
322 } else {
323 IsResolved = Target.isAbsolute();
324 }
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000325
326 Value = Target.getConstant();
327
Daniel Dunbar9a1d2002010-03-18 00:59:10 +0000328 if (const MCSymbolRefExpr *A = Target.getSymA()) {
Rafael Espindola94ed5fc2010-11-15 16:33:49 +0000329 const MCSymbol &Sym = A->getSymbol().AliasedSymbol();
330 if (Sym.isDefined())
Rafael Espindola85f2ecc2010-12-07 00:27:36 +0000331 Value += Layout.getSymbolOffset(&getSymbolData(Sym));
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000332 }
Daniel Dunbar9a1d2002010-03-18 00:59:10 +0000333 if (const MCSymbolRefExpr *B = Target.getSymB()) {
Rafael Espindola94ed5fc2010-11-15 16:33:49 +0000334 const MCSymbol &Sym = B->getSymbol().AliasedSymbol();
335 if (Sym.isDefined())
Rafael Espindola85f2ecc2010-12-07 00:27:36 +0000336 Value -= Layout.getSymbolOffset(&getSymbolData(Sym));
Daniel Dunbar939f8d72010-03-19 03:18:12 +0000337 }
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000338
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000339
Daniel Dunbar2761fc42010-12-16 03:20:06 +0000340 bool ShouldAlignPC = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
Owen Anderson47dbd422010-12-15 18:48:27 +0000341 MCFixupKindInfo::FKF_IsAlignedDownTo32Bits;
342 assert((ShouldAlignPC ? IsPCRel : true) &&
343 "FKF_IsAlignedDownTo32Bits is only allowed on PC-relative fixups!");
344
Owen Anderson05018c22010-12-09 20:27:52 +0000345 if (IsPCRel) {
Owen Anderson175fb362010-12-17 21:49:48 +0000346 uint32_t Offset = Layout.getFragmentOffset(DF) + Fixup.getOffset();
Jim Grosbach684457d2011-10-26 22:44:41 +0000347
Owen Anderson47dbd422010-12-15 18:48:27 +0000348 // A number of ARM fixups in Thumb mode require that the effective PC
349 // address be determined as the 32-bit aligned version of the actual offset.
Owen Andersond18e0112010-12-15 19:24:24 +0000350 if (ShouldAlignPC) Offset &= ~0x3;
Owen Anderson175fb362010-12-17 21:49:48 +0000351 Value -= Offset;
Owen Anderson05018c22010-12-09 20:27:52 +0000352 }
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000353
Jim Grosbach7b25ecf2012-02-27 21:36:23 +0000354 // Let the backend adjust the fixup value if necessary, including whether
355 // we need a relocation.
356 Backend.processFixupValue(*this, Layout, Fixup, DF, Target, Value,
357 IsResolved);
Jim Grosbach47500202010-12-14 18:46:57 +0000358
Daniel Dunbardf3c8f22010-03-12 21:00:49 +0000359 return IsResolved;
360}
361
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000362uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
Rafael Espindola7a459032010-12-21 20:35:18 +0000363 const MCFragment &F) const {
Daniel Dunbar2c18d3b2010-05-13 18:35:06 +0000364 switch (F.getKind()) {
365 case MCFragment::FT_Data:
366 return cast<MCDataFragment>(F).getContents().size();
367 case MCFragment::FT_Fill:
368 return cast<MCFillFragment>(F).getSize();
369 case MCFragment::FT_Inst:
370 return cast<MCInstFragment>(F).getInstSize();
371
Rafael Espindola3ff57092010-11-02 17:22:24 +0000372 case MCFragment::FT_LEB:
Rafael Espindoladb74aea2010-12-04 21:58:52 +0000373 return cast<MCLEBFragment>(F).getContents().size();
Rafael Espindola3ff57092010-11-02 17:22:24 +0000374
Rafael Espindola7a459032010-12-21 20:35:18 +0000375 case MCFragment::FT_Align: {
376 const MCAlignFragment &AF = cast<MCAlignFragment>(F);
377 unsigned Offset = Layout.getFragmentOffset(&AF);
378 unsigned Size = OffsetToAlignment(Offset, AF.getAlignment());
Owen Anderson15b7a982012-08-29 22:18:56 +0000379 // If we are padding with nops, force the padding to be larger than the
380 // minimum nop size.
381 if (Size > 0 && AF.hasEmitNops()) {
382 while (Size % getBackend().getMinimumNopSize())
383 Size += AF.getAlignment();
384 }
Rafael Espindola7a459032010-12-21 20:35:18 +0000385 if (Size > AF.getMaxBytesToEmit())
386 return 0;
387 return Size;
388 }
Daniel Dunbar2c18d3b2010-05-13 18:35:06 +0000389
Rafael Espindola7a459032010-12-21 20:35:18 +0000390 case MCFragment::FT_Org: {
391 MCOrgFragment &OF = cast<MCOrgFragment>(F);
392 int64_t TargetLocation;
393 if (!OF.getOffset().EvaluateAsAbsolute(TargetLocation, Layout))
394 report_fatal_error("expected assembly-time absolute expression");
395
396 // FIXME: We need a way to communicate this error.
397 uint64_t FragmentOffset = Layout.getFragmentOffset(&OF);
398 int64_t Size = TargetLocation - FragmentOffset;
399 if (Size < 0 || Size >= 0x40000000)
400 report_fatal_error("invalid .org offset '" + Twine(TargetLocation) +
401 "' (at offset '" + Twine(FragmentOffset) + "')");
402 return Size;
403 }
Kevin Enderbyc0957932010-09-30 16:52:03 +0000404
Rafael Espindola187d8332010-11-07 02:07:12 +0000405 case MCFragment::FT_Dwarf:
Rafael Espindoladb74aea2010-12-04 21:58:52 +0000406 return cast<MCDwarfLineAddrFragment>(F).getContents().size();
Rafael Espindola245a1e22010-12-28 05:39:27 +0000407 case MCFragment::FT_DwarfFrame:
408 return cast<MCDwarfCallFrameFragment>(F).getContents().size();
Daniel Dunbar2c18d3b2010-05-13 18:35:06 +0000409 }
410
Craig Topper85814382012-02-07 05:05:23 +0000411 llvm_unreachable("invalid fragment kind");
Daniel Dunbar2c18d3b2010-05-13 18:35:06 +0000412}
413
Eli Benderskyd52a2c02012-12-12 19:54:05 +0000414void MCAsmLayout::layoutFragment(MCFragment *F) {
Daniel Dunbar9005d452010-05-14 00:37:21 +0000415 MCFragment *Prev = F->getPrevNode();
Daniel Dunbarf0d17d22010-05-12 21:35:25 +0000416
Eli Benderskyd52a2c02012-12-12 19:54:05 +0000417 // We should never try to recompute something which is valid.
418 assert(!isFragmentValid(F) && "Attempt to recompute a valid fragment!");
419 // We should never try to compute the fragment layout if its predecessor
420 // isn't valid.
421 assert((!Prev || isFragmentValid(Prev)) &&
422 "Attempt to compute fragment before its predecessor!");
Daniel Dunbarf0d17d22010-05-12 21:35:25 +0000423
424 ++stats::FragmentLayouts;
425
Daniel Dunbarb69fc042010-05-13 20:40:12 +0000426 // Compute fragment offset and size.
Rafael Espindola85f2ecc2010-12-07 00:27:36 +0000427 if (Prev)
Eli Bendersky4766ef42012-12-20 19:05:53 +0000428 F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev);
429 else
430 F->Offset = 0;
Rafael Espindola4f4363a2010-12-07 23:32:26 +0000431 LastValidFragment[F->getParent()] = F;
Eli Bendersky4766ef42012-12-20 19:05:53 +0000432
433 // If bundling is enabled and this fragment has instructions in it, it has to
434 // obey the bundling restrictions. With padding, we'll have:
435 //
436 //
437 // BundlePadding
438 // |||
439 // -------------------------------------
440 // Prev |##########| F |
441 // -------------------------------------
442 // ^
443 // |
444 // F->Offset
445 //
446 // The fragment's offset will point to after the padding, and its computed
447 // size won't include the padding.
448 //
449 if (Assembler.isBundlingEnabled() && F->hasInstructions()) {
450 assert(isa<MCEncodedFragment>(F) &&
451 "Only MCEncodedFragment implementations have instructions");
452 uint64_t FSize = Assembler.computeFragmentSize(*this, *F);
453
454 if (FSize > Assembler.getBundleAlignSize())
455 report_fatal_error("Fragment can't be larger than a bundle size");
456
457 uint64_t RequiredBundlePadding = computeBundlePadding(F, F->Offset, FSize);
458 if (RequiredBundlePadding > UINT8_MAX)
459 report_fatal_error("Padding cannot exceed 255 bytes");
460 F->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
461 F->Offset += RequiredBundlePadding;
462 }
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000463}
464
Eli Bendersky64d9a322012-12-07 19:13:57 +0000465/// \brief Write the contents of a fragment to the given object writer. Expects
466/// a MCEncodedFragment.
467static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) {
468 MCEncodedFragment &EF = cast<MCEncodedFragment>(F);
Eli Bendersky550f0ad2012-12-07 22:06:56 +0000469 OW->WriteBytes(EF.getContents());
Eli Bendersky64d9a322012-12-07 19:13:57 +0000470}
471
472/// \brief Write the fragment \p F to the output file.
473static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
474 const MCFragment &F) {
Daniel Dunbar5d2477c2010-12-17 02:45:59 +0000475 MCObjectWriter *OW = &Asm.getWriter();
Eli Bendersky4766ef42012-12-20 19:05:53 +0000476
477 // Should NOP padding be written out before this fragment?
478 unsigned BundlePadding = F.getBundlePadding();
479 if (BundlePadding > 0) {
480 assert(Asm.isBundlingEnabled() &&
481 "Writing bundle padding with disabled bundling");
482 assert(F.hasInstructions() &&
483 "Writing bundle padding for a fragment without instructions");
484
485 if (!Asm.getBackend().writeNopData(BundlePadding, OW))
486 report_fatal_error("unable to write NOP sequence of " +
487 Twine(BundlePadding) + " bytes");
488 }
489
490 // This variable (and its dummy usage) is to participate in the assert at
491 // the end of the function.
Daniel Dunbar53b23382010-03-19 09:28:59 +0000492 uint64_t Start = OW->getStream().tell();
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000493 (void) Start;
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000494
Daniel Dunbarff547842010-03-23 23:47:14 +0000495 ++stats::EmittedFragments;
Daniel Dunbar0adcd352009-08-25 21:10:45 +0000496
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000497 // FIXME: Embed in fragments instead?
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000498 uint64_t FragmentSize = Asm.computeFragmentSize(Layout, F);
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000499 switch (F.getKind()) {
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000500 case MCFragment::FT_Align: {
Eli Bendersky6ac81f52012-12-10 18:59:39 +0000501 ++stats::EmittedAlignFragments;
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000502 MCAlignFragment &AF = cast<MCAlignFragment>(F);
Daniel Dunbar432cd5f2010-03-25 02:00:02 +0000503 uint64_t Count = FragmentSize / AF.getValueSize();
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000504
Daniel Dunbare73d49e2010-05-12 22:51:27 +0000505 assert(AF.getValueSize() && "Invalid virtual align in concrete fragment!");
506
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000507 // FIXME: This error shouldn't actually occur (the front end should emit
508 // multiple .align directives to enforce the semantics it wants), but is
509 // severe enough that we want to report it. How to handle this?
Daniel Dunbar432cd5f2010-03-25 02:00:02 +0000510 if (Count * AF.getValueSize() != FragmentSize)
Chris Lattner75361b62010-04-07 22:58:41 +0000511 report_fatal_error("undefined .align directive, value size '" +
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000512 Twine(AF.getValueSize()) +
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000513 "' is not a divisor of padding size '" +
Daniel Dunbar432cd5f2010-03-25 02:00:02 +0000514 Twine(FragmentSize) + "'");
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000515
Kevin Enderby6e720482010-02-23 18:26:34 +0000516 // See if we are aligning with nops, and if so do that first to try to fill
517 // the Count bytes. Then if that did not fill any bytes or there are any
Sylvestre Ledruc8e41c52012-07-23 08:51:15 +0000518 // bytes left to fill use the Value and ValueSize to fill the rest.
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +0000519 // If we are aligning with nops, ask that target to emit the right data.
Daniel Dunbar1c154132010-05-12 22:56:23 +0000520 if (AF.hasEmitNops()) {
Jim Grosbachec343382012-01-18 18:52:16 +0000521 if (!Asm.getBackend().writeNopData(Count, OW))
Chris Lattner75361b62010-04-07 22:58:41 +0000522 report_fatal_error("unable to write nop sequence of " +
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +0000523 Twine(Count) + " bytes");
524 break;
Kevin Enderby6e720482010-02-23 18:26:34 +0000525 }
526
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +0000527 // Otherwise, write out in multiples of the value size.
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000528 for (uint64_t i = 0; i != Count; ++i) {
529 switch (AF.getValueSize()) {
Craig Topper85814382012-02-07 05:05:23 +0000530 default: llvm_unreachable("Invalid size!");
Daniel Dunbarbdd92812010-03-19 09:28:55 +0000531 case 1: OW->Write8 (uint8_t (AF.getValue())); break;
532 case 2: OW->Write16(uint16_t(AF.getValue())); break;
533 case 4: OW->Write32(uint32_t(AF.getValue())); break;
534 case 8: OW->Write64(uint64_t(AF.getValue())); break;
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000535 }
536 }
537 break;
538 }
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000539
Eli Bendersky64d9a322012-12-07 19:13:57 +0000540 case MCFragment::FT_Data:
Eli Bendersky8ddc5a12012-12-07 17:59:21 +0000541 ++stats::EmittedDataFragments;
Eli Bendersky64d9a322012-12-07 19:13:57 +0000542 writeFragmentContents(F, OW);
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000543 break;
Eli Bendersky64d9a322012-12-07 19:13:57 +0000544
545 case MCFragment::FT_Inst:
546 ++stats::EmittedInstFragments;
547 writeFragmentContents(F, OW);
548 break;
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000549
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000550 case MCFragment::FT_Fill: {
Eli Bendersky6ac81f52012-12-10 18:59:39 +0000551 ++stats::EmittedFillFragments;
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000552 MCFillFragment &FF = cast<MCFillFragment>(F);
Daniel Dunbare2fee5b2010-05-12 22:51:35 +0000553
554 assert(FF.getValueSize() && "Invalid virtual align in concrete fragment!");
555
Daniel Dunbar3153fec2010-05-12 22:51:32 +0000556 for (uint64_t i = 0, e = FF.getSize() / FF.getValueSize(); i != e; ++i) {
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000557 switch (FF.getValueSize()) {
Craig Topper85814382012-02-07 05:05:23 +0000558 default: llvm_unreachable("Invalid size!");
Daniel Dunbarbdd92812010-03-19 09:28:55 +0000559 case 1: OW->Write8 (uint8_t (FF.getValue())); break;
560 case 2: OW->Write16(uint16_t(FF.getValue())); break;
561 case 4: OW->Write32(uint32_t(FF.getValue())); break;
562 case 8: OW->Write64(uint64_t(FF.getValue())); break;
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000563 }
564 }
565 break;
566 }
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000567
Rafael Espindola3ff57092010-11-02 17:22:24 +0000568 case MCFragment::FT_LEB: {
569 MCLEBFragment &LF = cast<MCLEBFragment>(F);
Rafael Espindoladb74aea2010-12-04 21:58:52 +0000570 OW->WriteBytes(LF.getContents().str());
Rafael Espindola3ff57092010-11-02 17:22:24 +0000571 break;
572 }
573
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000574 case MCFragment::FT_Org: {
Eli Bendersky6ac81f52012-12-10 18:59:39 +0000575 ++stats::EmittedOrgFragments;
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000576 MCOrgFragment &OF = cast<MCOrgFragment>(F);
577
Daniel Dunbar432cd5f2010-03-25 02:00:02 +0000578 for (uint64_t i = 0, e = FragmentSize; i != e; ++i)
Daniel Dunbarbdd92812010-03-19 09:28:55 +0000579 OW->Write8(uint8_t(OF.getValue()));
Daniel Dunbard6f761e2009-08-21 23:07:38 +0000580
581 break;
582 }
Kevin Enderbyc0957932010-09-30 16:52:03 +0000583
584 case MCFragment::FT_Dwarf: {
585 const MCDwarfLineAddrFragment &OF = cast<MCDwarfLineAddrFragment>(F);
Rafael Espindoladb74aea2010-12-04 21:58:52 +0000586 OW->WriteBytes(OF.getContents().str());
Kevin Enderbyc0957932010-09-30 16:52:03 +0000587 break;
588 }
Rafael Espindola245a1e22010-12-28 05:39:27 +0000589 case MCFragment::FT_DwarfFrame: {
590 const MCDwarfCallFrameFragment &CF = cast<MCDwarfCallFrameFragment>(F);
591 OW->WriteBytes(CF.getContents().str());
592 break;
593 }
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000594 }
595
Eli Bendersky4766ef42012-12-20 19:05:53 +0000596 assert(OW->getStream().tell() - Start == FragmentSize &&
597 "The stream should advance by fragment size");
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000598}
599
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000600void MCAssembler::writeSectionData(const MCSectionData *SD,
Daniel Dunbar5d2477c2010-12-17 02:45:59 +0000601 const MCAsmLayout &Layout) const {
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000602 // Ignore virtual sections.
Rafael Espindolaf2dc4aa2010-11-17 20:03:54 +0000603 if (SD->getSection().isVirtualSection()) {
Daniel Dunbar054be922010-05-13 03:50:50 +0000604 assert(Layout.getSectionFileSize(SD) == 0 && "Invalid size for section!");
Daniel Dunbare2fee5b2010-05-12 22:51:35 +0000605
606 // Check that contents are only things legal inside a virtual section.
607 for (MCSectionData::const_iterator it = SD->begin(),
608 ie = SD->end(); it != ie; ++it) {
609 switch (it->getKind()) {
Craig Topper85814382012-02-07 05:05:23 +0000610 default: llvm_unreachable("Invalid fragment in virtual section!");
Daniel Dunbarc983b202010-08-18 18:22:37 +0000611 case MCFragment::FT_Data: {
612 // Check that we aren't trying to write a non-zero contents (or fixups)
613 // into a virtual section. This is to support clients which use standard
614 // directives to fill the contents of virtual sections.
615 MCDataFragment &DF = cast<MCDataFragment>(*it);
616 assert(DF.fixup_begin() == DF.fixup_end() &&
617 "Cannot have fixups in virtual section!");
618 for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i)
619 assert(DF.getContents()[i] == 0 &&
620 "Invalid data value for virtual section!");
621 break;
622 }
Daniel Dunbare2fee5b2010-05-12 22:51:35 +0000623 case MCFragment::FT_Align:
Daniel Dunbarc983b202010-08-18 18:22:37 +0000624 // Check that we aren't trying to write a non-zero value into a virtual
625 // section.
626 assert((!cast<MCAlignFragment>(it)->getValueSize() ||
627 !cast<MCAlignFragment>(it)->getValue()) &&
Daniel Dunbare2fee5b2010-05-12 22:51:35 +0000628 "Invalid align in virtual section!");
629 break;
630 case MCFragment::FT_Fill:
631 assert(!cast<MCFillFragment>(it)->getValueSize() &&
632 "Invalid fill in virtual section!");
633 break;
Daniel Dunbare2fee5b2010-05-12 22:51:35 +0000634 }
635 }
636
Daniel Dunbard5a8e982009-08-28 05:49:21 +0000637 return;
638 }
639
Daniel Dunbar5d2477c2010-12-17 02:45:59 +0000640 uint64_t Start = getWriter().getStream().tell();
Jim Grosbachb5762bf2012-09-18 23:05:18 +0000641 (void)Start;
Daniel Dunbar7eb85192009-10-16 01:58:15 +0000642
Eli Bendersky64d9a322012-12-07 19:13:57 +0000643 for (MCSectionData::const_iterator it = SD->begin(), ie = SD->end();
644 it != ie; ++it)
645 writeFragment(*this, Layout, *it);
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000646
Daniel Dunbar5d2477c2010-12-17 02:45:59 +0000647 assert(getWriter().getStream().tell() - Start ==
648 Layout.getSectionAddressSize(SD));
Daniel Dunbar0705fbf2009-08-21 18:29:01 +0000649}
650
Rafael Espindola179821a2010-12-06 19:08:48 +0000651
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000652uint64_t MCAssembler::handleFixup(const MCAsmLayout &Layout,
Daniel Dunbar5d2477c2010-12-17 02:45:59 +0000653 MCFragment &F,
654 const MCFixup &Fixup) {
Rafael Espindola179821a2010-12-06 19:08:48 +0000655 // Evaluate the fixup.
656 MCValue Target;
657 uint64_t FixedValue;
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000658 if (!evaluateFixup(Layout, Fixup, &F, Target, FixedValue)) {
Rafael Espindola179821a2010-12-06 19:08:48 +0000659 // The fixup was unresolved, we need a relocation. Inform the object
660 // writer of the relocation, and give it an opportunity to adjust the
661 // fixup value if need be.
Daniel Dunbar5d2477c2010-12-17 02:45:59 +0000662 getWriter().RecordRelocation(*this, Layout, &F, Fixup, Target, FixedValue);
Rafael Espindola179821a2010-12-06 19:08:48 +0000663 }
664 return FixedValue;
665 }
666
Daniel Dunbarfeb7ba32010-12-17 02:45:41 +0000667void MCAssembler::Finish() {
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000668 DEBUG_WITH_TYPE("mc-dump", {
669 llvm::errs() << "assembler backend - pre-layout\n--\n";
670 dump(); });
671
Daniel Dunbar61066db2010-05-13 02:34:14 +0000672 // Create the layout object.
Daniel Dunbar8d39eb42010-03-22 20:35:35 +0000673 MCAsmLayout Layout(*this);
Daniel Dunbar61066db2010-05-13 02:34:14 +0000674
Daniel Dunbar337718e2010-05-14 00:37:14 +0000675 // Create dummy fragments and assign section ordinals.
Daniel Dunbar49ed9212010-05-13 08:43:37 +0000676 unsigned SectionIndex = 0;
Daniel Dunbar49ed9212010-05-13 08:43:37 +0000677 for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) {
678 // Create dummy fragments to eliminate any empty sections, this simplifies
679 // layout.
Duncan Sands6f74f692010-06-29 13:30:08 +0000680 if (it->getFragmentList().empty())
Rafael Espindolad80781b2010-09-15 21:48:40 +0000681 new MCDataFragment(it);
Daniel Dunbar49ed9212010-05-13 08:43:37 +0000682
683 it->setOrdinal(SectionIndex++);
Daniel Dunbar337718e2010-05-14 00:37:14 +0000684 }
Daniel Dunbar49ed9212010-05-13 08:43:37 +0000685
Daniel Dunbar337718e2010-05-14 00:37:14 +0000686 // Assign layout order indices to sections and fragments.
Daniel Dunbar337718e2010-05-14 00:37:14 +0000687 for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {
688 MCSectionData *SD = Layout.getSectionOrder()[i];
689 SD->setLayoutOrder(i);
690
Rafael Espindola4f4363a2010-12-07 23:32:26 +0000691 unsigned FragmentIndex = 0;
Eli Benderskyd52a2c02012-12-12 19:54:05 +0000692 for (MCSectionData::iterator iFrag = SD->begin(), iFragEnd = SD->end();
693 iFrag != iFragEnd; ++iFrag)
694 iFrag->setLayoutOrder(FragmentIndex++);
Daniel Dunbar49ed9212010-05-13 08:43:37 +0000695 }
696
Daniel Dunbar61066db2010-05-13 02:34:14 +0000697 // Layout until everything fits.
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000698 while (layoutOnce(Layout))
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000699 continue;
700
701 DEBUG_WITH_TYPE("mc-dump", {
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000702 llvm::errs() << "assembler backend - post-relaxation\n--\n";
703 dump(); });
704
705 // Finalize the layout, including fragment lowering.
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000706 finishLayout(Layout);
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000707
708 DEBUG_WITH_TYPE("mc-dump", {
709 llvm::errs() << "assembler backend - final-layout\n--\n";
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000710 dump(); });
711
Daniel Dunbarff547842010-03-23 23:47:14 +0000712 uint64_t StartOffset = OS.tell();
Reid Klecknerc96a82a2010-07-22 05:58:53 +0000713
Daniel Dunbarbacba992010-03-19 07:09:33 +0000714 // Allow the object writer a chance to perform post-layout binding (for
715 // example, to set the index fields in the symbol data).
Daniel Dunbar5d2477c2010-12-17 02:45:59 +0000716 getWriter().ExecutePostLayoutBinding(*this, Layout);
Daniel Dunbarbacba992010-03-19 07:09:33 +0000717
Daniel Dunbarb1e98942010-03-19 07:09:47 +0000718 // Evaluate and apply the fixups, generating relocation entries as necessary.
Daniel Dunbarb1e98942010-03-19 07:09:47 +0000719 for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) {
720 for (MCSectionData::iterator it2 = it->begin(),
721 ie2 = it->end(); it2 != ie2; ++it2) {
Eli Bendersky64d9a322012-12-07 19:13:57 +0000722 MCEncodedFragment *F = dyn_cast<MCEncodedFragment>(it2);
723 if (F) {
724 for (MCEncodedFragment::fixup_iterator it3 = F->fixup_begin(),
725 ie3 = F->fixup_end(); it3 != ie3; ++it3) {
Rafael Espindola179821a2010-12-06 19:08:48 +0000726 MCFixup &Fixup = *it3;
Eli Bendersky64d9a322012-12-07 19:13:57 +0000727 uint64_t FixedValue = handleFixup(Layout, *F, Fixup);
728 getBackend().applyFixup(Fixup, F->getContents().data(),
729 F->getContents().size(), FixedValue);
Rafael Espindola179821a2010-12-06 19:08:48 +0000730 }
Daniel Dunbarb1e98942010-03-19 07:09:47 +0000731 }
732 }
733 }
734
Daniel Dunbarbacba992010-03-19 07:09:33 +0000735 // Write the object file.
Daniel Dunbar5d2477c2010-12-17 02:45:59 +0000736 getWriter().WriteObject(*this, Layout);
Daniel Dunbarff547842010-03-23 23:47:14 +0000737
738 stats::ObjectBytes += OS.tell() - StartOffset;
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000739}
740
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000741bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
Jim Grosbach370b78d2011-12-06 00:47:03 +0000742 const MCInstFragment *DF,
Daniel Dunbar8d39eb42010-03-22 20:35:35 +0000743 const MCAsmLayout &Layout) const {
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000744 // If we cannot resolve the fixup value, it requires relaxation.
745 MCValue Target;
746 uint64_t Value;
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000747 if (!evaluateFixup(Layout, Fixup, DF, Target, Value))
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000748 return true;
749
Jim Grosbach370b78d2011-12-06 00:47:03 +0000750 return getBackend().fixupNeedsRelaxation(Fixup, Value, DF, Layout);
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000751}
752
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000753bool MCAssembler::fragmentNeedsRelaxation(const MCInstFragment *IF,
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000754 const MCAsmLayout &Layout) const {
755 // If this inst doesn't ever need relaxation, ignore it. This occurs when we
756 // are intentionally pushing out inst fragments, or because we relaxed a
757 // previous instruction to one that doesn't need relaxation.
Jim Grosbachec343382012-01-18 18:52:16 +0000758 if (!getBackend().mayNeedRelaxation(IF->getInst()))
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000759 return false;
760
761 for (MCInstFragment::const_fixup_iterator it = IF->fixup_begin(),
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000762 ie = IF->fixup_end(); it != ie; ++it)
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000763 if (fixupNeedsRelaxation(*it, IF, Layout))
Daniel Dunbard8036fb2010-03-23 05:09:03 +0000764 return true;
765
766 return false;
767}
768
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000769bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
Rafael Espindola3ff57092010-11-02 17:22:24 +0000770 MCInstFragment &IF) {
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000771 if (!fragmentNeedsRelaxation(&IF, Layout))
Rafael Espindola3ff57092010-11-02 17:22:24 +0000772 return false;
773
774 ++stats::RelaxedInstructions;
775
776 // FIXME-PERF: We could immediately lower out instructions if we can tell
777 // they are fully resolved, to avoid retesting on later passes.
778
779 // Relax the fragment.
780
781 MCInst Relaxed;
Jim Grosbachec343382012-01-18 18:52:16 +0000782 getBackend().relaxInstruction(IF.getInst(), Relaxed);
Rafael Espindola3ff57092010-11-02 17:22:24 +0000783
784 // Encode the new instruction.
785 //
786 // FIXME-PERF: If it matters, we could let the target do this. It can
787 // probably do so more efficiently in many cases.
788 SmallVector<MCFixup, 4> Fixups;
789 SmallString<256> Code;
790 raw_svector_ostream VecOS(Code);
791 getEmitter().EncodeInstruction(Relaxed, VecOS, Fixups);
792 VecOS.flush();
793
794 // Update the instruction fragment.
Rafael Espindola3ff57092010-11-02 17:22:24 +0000795 IF.setInst(Relaxed);
Eli Bendersky64d9a322012-12-07 19:13:57 +0000796 IF.getContents() = Code;
797 IF.getFixups() = Fixups;
Rafael Espindola3ff57092010-11-02 17:22:24 +0000798
Rafael Espindola3ff57092010-11-02 17:22:24 +0000799 return true;
800}
801
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000802bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) {
Rafael Espindoladb74aea2010-12-04 21:58:52 +0000803 int64_t Value = 0;
804 uint64_t OldSize = LF.getContents().size();
Rafael Espindolad88cac02011-04-26 02:17:58 +0000805 bool IsAbs = LF.getValue().EvaluateAsAbsolute(Value, Layout);
806 (void)IsAbs;
807 assert(IsAbs);
Rafael Espindoladb74aea2010-12-04 21:58:52 +0000808 SmallString<8> &Data = LF.getContents();
809 Data.clear();
810 raw_svector_ostream OSE(Data);
Rafael Espindola3ff57092010-11-02 17:22:24 +0000811 if (LF.isSigned())
Jim Grosbach2d39a0e2012-08-08 23:56:06 +0000812 encodeSLEB128(Value, OSE);
Rafael Espindola3ff57092010-11-02 17:22:24 +0000813 else
Jim Grosbach2d39a0e2012-08-08 23:56:06 +0000814 encodeULEB128(Value, OSE);
Rafael Espindoladb74aea2010-12-04 21:58:52 +0000815 OSE.flush();
816 return OldSize != LF.getContents().size();
Rafael Espindola3ff57092010-11-02 17:22:24 +0000817}
818
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000819bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout,
Jim Grosbachf68a26b2011-12-06 00:13:09 +0000820 MCDwarfLineAddrFragment &DF) {
Rafael Espindoladb74aea2010-12-04 21:58:52 +0000821 int64_t AddrDelta = 0;
822 uint64_t OldSize = DF.getContents().size();
Rafael Espindola835439a2010-12-22 22:04:28 +0000823 bool IsAbs = DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout);
824 (void)IsAbs;
825 assert(IsAbs);
Rafael Espindola187d8332010-11-07 02:07:12 +0000826 int64_t LineDelta;
827 LineDelta = DF.getLineDelta();
Rafael Espindoladb74aea2010-12-04 21:58:52 +0000828 SmallString<8> &Data = DF.getContents();
829 Data.clear();
830 raw_svector_ostream OSE(Data);
831 MCDwarfLineAddr::Encode(LineDelta, AddrDelta, OSE);
832 OSE.flush();
833 return OldSize != Data.size();
Rafael Espindola187d8332010-11-07 02:07:12 +0000834}
835
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000836bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
Rafael Espindola245a1e22010-12-28 05:39:27 +0000837 MCDwarfCallFrameFragment &DF) {
838 int64_t AddrDelta = 0;
839 uint64_t OldSize = DF.getContents().size();
840 bool IsAbs = DF.getAddrDelta().EvaluateAsAbsolute(AddrDelta, Layout);
841 (void)IsAbs;
842 assert(IsAbs);
843 SmallString<8> &Data = DF.getContents();
844 Data.clear();
845 raw_svector_ostream OSE(Data);
Rafael Espindola4eafe102011-05-08 14:35:21 +0000846 MCDwarfFrameEmitter::EncodeAdvanceLoc(AddrDelta, OSE);
Rafael Espindola245a1e22010-12-28 05:39:27 +0000847 OSE.flush();
848 return OldSize != Data.size();
849}
850
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000851bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) {
852 // Holds the first fragment which needed relaxing during this layout. It will
853 // remain NULL if none were relaxed.
Eli Benderskyd52a2c02012-12-12 19:54:05 +0000854 // When a fragment is relaxed, all the fragments following it should get
855 // invalidated because their offset is going to change.
856 MCFragment *FirstRelaxedFragment = NULL;
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000857
Eli Benderskyd52a2c02012-12-12 19:54:05 +0000858 // Attempt to relax all the fragments in the section.
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000859 for (MCSectionData::iterator I = SD.begin(), IE = SD.end(); I != IE; ++I) {
860 // Check if this is a fragment that needs relaxation.
861 bool RelaxedFrag = false;
862 switch(I->getKind()) {
Rafael Espindola62b83b62010-12-21 04:22:09 +0000863 default:
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000864 break;
Rafael Espindola62b83b62010-12-21 04:22:09 +0000865 case MCFragment::FT_Inst:
Eli Bendersky37a98302012-12-11 17:16:00 +0000866 assert(!getRelaxAll() &&
867 "Did not expect a MCInstFragment in RelaxAll mode");
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000868 RelaxedFrag = relaxInstruction(Layout, *cast<MCInstFragment>(I));
Rafael Espindola62b83b62010-12-21 04:22:09 +0000869 break;
Rafael Espindola62b83b62010-12-21 04:22:09 +0000870 case MCFragment::FT_Dwarf:
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000871 RelaxedFrag = relaxDwarfLineAddr(Layout,
872 *cast<MCDwarfLineAddrFragment>(I));
Rafael Espindola62b83b62010-12-21 04:22:09 +0000873 break;
Rafael Espindola245a1e22010-12-28 05:39:27 +0000874 case MCFragment::FT_DwarfFrame:
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000875 RelaxedFrag =
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000876 relaxDwarfCallFrameFragment(Layout,
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000877 *cast<MCDwarfCallFrameFragment>(I));
Rafael Espindola245a1e22010-12-28 05:39:27 +0000878 break;
879 case MCFragment::FT_LEB:
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000880 RelaxedFrag = relaxLEB(Layout, *cast<MCLEBFragment>(I));
Rafael Espindola245a1e22010-12-28 05:39:27 +0000881 break;
Rafael Espindola62b83b62010-12-21 04:22:09 +0000882 }
Eli Benderskyd52a2c02012-12-12 19:54:05 +0000883 if (RelaxedFrag && !FirstRelaxedFragment)
884 FirstRelaxedFragment = I;
Rafael Espindola62b83b62010-12-21 04:22:09 +0000885 }
Eli Benderskyd52a2c02012-12-12 19:54:05 +0000886 if (FirstRelaxedFragment) {
887 Layout.invalidateFragmentsAfter(FirstRelaxedFragment);
Rafael Espindola62b83b62010-12-21 04:22:09 +0000888 return true;
889 }
890 return false;
891}
892
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000893bool MCAssembler::layoutOnce(MCAsmLayout &Layout) {
Daniel Dunbarff547842010-03-23 23:47:14 +0000894 ++stats::RelaxationSteps;
895
Daniel Dunbar0cc8bd42010-03-25 19:35:56 +0000896 bool WasRelaxed = false;
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000897 for (iterator it = begin(), ie = end(); it != ie; ++it) {
898 MCSectionData &SD = *it;
Eli Benderskyf43e3fd2012-12-10 20:13:43 +0000899 while (layoutSectionOnce(Layout, SD))
Rafael Espindola62b83b62010-12-21 04:22:09 +0000900 WasRelaxed = true;
Daniel Dunbarf08fde42010-03-12 22:07:14 +0000901 }
902
Daniel Dunbar0cc8bd42010-03-25 19:35:56 +0000903 return WasRelaxed;
Daniel Dunbarfb4a6b32009-08-21 09:11:24 +0000904}
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000905
Jim Grosbachf77d5b12011-12-06 00:03:48 +0000906void MCAssembler::finishLayout(MCAsmLayout &Layout) {
Rafael Espindolab4172fa2010-12-04 22:47:22 +0000907 // The layout is done. Mark every fragment as valid.
Rafael Espindola4f4363a2010-12-07 23:32:26 +0000908 for (unsigned int i = 0, n = Layout.getSectionOrder().size(); i != n; ++i) {
909 Layout.getFragmentOffset(&*Layout.getSectionOrder()[i]->rbegin());
910 }
Daniel Dunbar3f4dcd92010-03-22 23:16:48 +0000911}
912
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000913// Debugging methods
914
915namespace llvm {
916
Daniel Dunbarc90e30a2010-05-26 15:18:56 +0000917raw_ostream &operator<<(raw_ostream &OS, const MCFixup &AF) {
918 OS << "<MCFixup" << " Offset:" << AF.getOffset()
Daniel Dunbar482ad802010-05-26 15:18:31 +0000919 << " Value:" << *AF.getValue()
920 << " Kind:" << AF.getKind() << ">";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000921 return OS;
922}
923
924}
925
Manman Ren286c4dc2012-09-12 05:06:18 +0000926#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000927void MCFragment::dump() {
928 raw_ostream &OS = llvm::errs();
929
Daniel Dunbare614e392010-05-26 06:50:57 +0000930 OS << "<";
931 switch (getKind()) {
932 case MCFragment::FT_Align: OS << "MCAlignFragment"; break;
933 case MCFragment::FT_Data: OS << "MCDataFragment"; break;
934 case MCFragment::FT_Fill: OS << "MCFillFragment"; break;
935 case MCFragment::FT_Inst: OS << "MCInstFragment"; break;
936 case MCFragment::FT_Org: OS << "MCOrgFragment"; break;
Kevin Enderbyc0957932010-09-30 16:52:03 +0000937 case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break;
Rafael Espindola245a1e22010-12-28 05:39:27 +0000938 case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break;
Rafael Espindola3ff57092010-11-02 17:22:24 +0000939 case MCFragment::FT_LEB: OS << "MCLEBFragment"; break;
Daniel Dunbare614e392010-05-26 06:50:57 +0000940 }
941
Daniel Dunbar337718e2010-05-14 00:37:14 +0000942 OS << "<MCFragment " << (void*) this << " LayoutOrder:" << LayoutOrder
Eli Bendersky4766ef42012-12-20 19:05:53 +0000943 << " Offset:" << Offset
944 << " HasInstructions:" << hasInstructions()
945 << " BundlePadding:" << getBundlePadding() << ">";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000946
Daniel Dunbare614e392010-05-26 06:50:57 +0000947 switch (getKind()) {
948 case MCFragment::FT_Align: {
949 const MCAlignFragment *AF = cast<MCAlignFragment>(this);
950 if (AF->hasEmitNops())
951 OS << " (emit nops)";
Daniel Dunbare614e392010-05-26 06:50:57 +0000952 OS << "\n ";
953 OS << " Alignment:" << AF->getAlignment()
954 << " Value:" << AF->getValue() << " ValueSize:" << AF->getValueSize()
955 << " MaxBytesToEmit:" << AF->getMaxBytesToEmit() << ">";
956 break;
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +0000957 }
Daniel Dunbare614e392010-05-26 06:50:57 +0000958 case MCFragment::FT_Data: {
959 const MCDataFragment *DF = cast<MCDataFragment>(this);
960 OS << "\n ";
961 OS << " Contents:[";
962 const SmallVectorImpl<char> &Contents = DF->getContents();
963 for (unsigned i = 0, e = Contents.size(); i != e; ++i) {
964 if (i) OS << ",";
965 OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
Daniel Dunbar0bcf0742010-02-13 09:28:43 +0000966 }
Daniel Dunbare614e392010-05-26 06:50:57 +0000967 OS << "] (" << Contents.size() << " bytes)";
968
Eli Bendersky5c10f502012-12-05 22:11:02 +0000969 if (DF->fixup_begin() != DF->fixup_end()) {
Daniel Dunbare614e392010-05-26 06:50:57 +0000970 OS << ",\n ";
971 OS << " Fixups:[";
972 for (MCDataFragment::const_fixup_iterator it = DF->fixup_begin(),
973 ie = DF->fixup_end(); it != ie; ++it) {
974 if (it != DF->fixup_begin()) OS << ",\n ";
975 OS << *it;
976 }
977 OS << "]";
978 }
979 break;
Daniel Dunbar0bcf0742010-02-13 09:28:43 +0000980 }
Daniel Dunbare614e392010-05-26 06:50:57 +0000981 case MCFragment::FT_Fill: {
982 const MCFillFragment *FF = cast<MCFillFragment>(this);
983 OS << " Value:" << FF->getValue() << " ValueSize:" << FF->getValueSize()
984 << " Size:" << FF->getSize();
985 break;
986 }
987 case MCFragment::FT_Inst: {
988 const MCInstFragment *IF = cast<MCInstFragment>(this);
989 OS << "\n ";
990 OS << " Inst:";
991 IF->getInst().dump_pretty(OS);
992 break;
993 }
994 case MCFragment::FT_Org: {
995 const MCOrgFragment *OF = cast<MCOrgFragment>(this);
996 OS << "\n ";
997 OS << " Offset:" << OF->getOffset() << " Value:" << OF->getValue();
998 break;
999 }
Kevin Enderbyc0957932010-09-30 16:52:03 +00001000 case MCFragment::FT_Dwarf: {
1001 const MCDwarfLineAddrFragment *OF = cast<MCDwarfLineAddrFragment>(this);
1002 OS << "\n ";
1003 OS << " AddrDelta:" << OF->getAddrDelta()
1004 << " LineDelta:" << OF->getLineDelta();
1005 break;
1006 }
Rafael Espindola245a1e22010-12-28 05:39:27 +00001007 case MCFragment::FT_DwarfFrame: {
1008 const MCDwarfCallFrameFragment *CF = cast<MCDwarfCallFrameFragment>(this);
1009 OS << "\n ";
1010 OS << " AddrDelta:" << CF->getAddrDelta();
1011 break;
1012 }
Rafael Espindola3ff57092010-11-02 17:22:24 +00001013 case MCFragment::FT_LEB: {
1014 const MCLEBFragment *LF = cast<MCLEBFragment>(this);
1015 OS << "\n ";
1016 OS << " Value:" << LF->getValue() << " Signed:" << LF->isSigned();
1017 break;
1018 }
Daniel Dunbare614e392010-05-26 06:50:57 +00001019 }
Daniel Dunbar0bcf0742010-02-13 09:28:43 +00001020 OS << ">";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +00001021}
1022
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +00001023void MCSectionData::dump() {
1024 raw_ostream &OS = llvm::errs();
1025
1026 OS << "<MCSectionData";
Eli Bendersky4766ef42012-12-20 19:05:53 +00001027 OS << " Alignment:" << getAlignment()
1028 << " Fragments:[\n ";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +00001029 for (iterator it = begin(), ie = end(); it != ie; ++it) {
1030 if (it != begin()) OS << ",\n ";
1031 it->dump();
1032 }
1033 OS << "]>";
1034}
1035
1036void MCSymbolData::dump() {
1037 raw_ostream &OS = llvm::errs();
1038
1039 OS << "<MCSymbolData Symbol:" << getSymbol()
1040 << " Fragment:" << getFragment() << " Offset:" << getOffset()
1041 << " Flags:" << getFlags() << " Index:" << getIndex();
1042 if (isCommon())
1043 OS << " (common, size:" << getCommonSize()
1044 << " align: " << getCommonAlignment() << ")";
1045 if (isExternal())
1046 OS << " (external)";
1047 if (isPrivateExtern())
1048 OS << " (private extern)";
1049 OS << ">";
1050}
1051
1052void MCAssembler::dump() {
1053 raw_ostream &OS = llvm::errs();
1054
1055 OS << "<MCAssembler\n";
Daniel Dunbar45aefff2010-03-09 01:12:23 +00001056 OS << " Sections:[\n ";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +00001057 for (iterator it = begin(), ie = end(); it != ie; ++it) {
1058 if (it != begin()) OS << ",\n ";
1059 it->dump();
1060 }
1061 OS << "],\n";
1062 OS << " Symbols:[";
1063
1064 for (symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
Daniel Dunbar45aefff2010-03-09 01:12:23 +00001065 if (it != symbol_begin()) OS << ",\n ";
Daniel Dunbarb7c3a4b2010-02-13 09:28:03 +00001066 it->dump();
1067 }
1068 OS << "]>\n";
1069}
Manman Rencc77eec2012-09-06 19:55:56 +00001070#endif
David Blaikie2d24e2a2011-12-20 02:50:00 +00001071
1072// anchors for MC*Fragment vtables
Eli Bendersky64d9a322012-12-07 19:13:57 +00001073void MCEncodedFragment::anchor() { }
David Blaikie2d24e2a2011-12-20 02:50:00 +00001074void MCDataFragment::anchor() { }
1075void MCInstFragment::anchor() { }
1076void MCAlignFragment::anchor() { }
1077void MCFillFragment::anchor() { }
1078void MCOrgFragment::anchor() { }
1079void MCLEBFragment::anchor() { }
1080void MCDwarfLineAddrFragment::anchor() { }
1081void MCDwarfCallFrameFragment::anchor() { }