LLVM  4.0.0
MCELFStreamer.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCELFStreamer.cpp - ELF Object Output -----------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file assembles .s files and emits ELF .o object files.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/MC/MCELFStreamer.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/SmallPtrSet.h"
17 #include "llvm/MC/MCAsmBackend.h"
18 #include "llvm/MC/MCAsmLayout.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCAssembler.h"
21 #include "llvm/MC/MCCodeEmitter.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCExpr.h"
24 #include "llvm/MC/MCInst.h"
27 #include "llvm/MC/MCObjectWriter.h"
28 #include "llvm/MC/MCSection.h"
29 #include "llvm/MC/MCSectionELF.h"
30 #include "llvm/MC/MCSymbolELF.h"
31 #include "llvm/MC/MCSymbol.h"
32 #include "llvm/MC/MCValue.h"
33 #include "llvm/Support/Debug.h"
34 #include "llvm/Support/ELF.h"
38 
39 using namespace llvm;
40 
41 bool MCELFStreamer::isBundleLocked() const {
43 }
44 
46 }
47 
48 void MCELFStreamer::mergeFragment(MCDataFragment *DF,
49  MCDataFragment *EF) {
50  MCAssembler &Assembler = getAssembler();
51 
52  if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
53  uint64_t FSize = EF->getContents().size();
54 
55  if (FSize > Assembler.getBundleAlignSize())
56  report_fatal_error("Fragment can't be larger than a bundle size");
57 
58  uint64_t RequiredBundlePadding = computeBundlePadding(
59  Assembler, EF, DF->getContents().size(), FSize);
60 
61  if (RequiredBundlePadding > UINT8_MAX)
62  report_fatal_error("Padding cannot exceed 255 bytes");
63 
64  if (RequiredBundlePadding > 0) {
65  SmallString<256> Code;
66  raw_svector_ostream VecOS(Code);
67  MCObjectWriter *OW = Assembler.getBackend().createObjectWriter(VecOS);
68 
69  EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
70 
71  Assembler.writeFragmentPadding(*EF, FSize, OW);
72  delete OW;
73 
74  DF->getContents().append(Code.begin(), Code.end());
75  }
76  }
77 
78  flushPendingLabels(DF, DF->getContents().size());
79 
80  for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) {
81  EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() +
82  DF->getContents().size());
83  DF->getFixups().push_back(EF->getFixups()[i]);
84  }
85  DF->setHasInstructions(true);
86  DF->getContents().append(EF->getContents().begin(), EF->getContents().end());
87 }
88 
89 void MCELFStreamer::InitSections(bool NoExecStack) {
90  MCContext &Ctx = getContext();
93 
94  if (NoExecStack)
96 }
97 
99  auto *Symbol = cast<MCSymbolELF>(S);
100  assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
101 
103 
104  const MCSectionELF &Section =
105  static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
106  if (Section.getFlags() & ELF::SHF_TLS)
107  Symbol->setType(ELF::STT_TLS);
108 }
109 
111  // Let the target do whatever target specific stuff it needs to do.
113  // Do any generic stuff we need to do.
114  switch (Flag) {
115  case MCAF_SyntaxUnified: return; // no-op here.
116  case MCAF_Code16: return; // Change parsing mode; no-op here.
117  case MCAF_Code32: return; // Change parsing mode; no-op here.
118  case MCAF_Code64: return; // Change parsing mode; no-op here.
121  return;
122  }
123 
124  llvm_unreachable("invalid assembler flag!");
125 }
126 
127 // If bundle alignment is used and there are any instructions in the section, it
128 // needs to be aligned to at least the bundle size.
129 static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
130  MCSection *Section) {
131  if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions() &&
132  Section->getAlignment() < Assembler.getBundleAlignSize())
133  Section->setAlignment(Assembler.getBundleAlignSize());
134 }
135 
137  const MCExpr *Subsection) {
138  MCSection *CurSection = getCurrentSectionOnly();
139  if (CurSection && isBundleLocked())
140  report_fatal_error("Unterminated .bundle_lock when changing a section");
141 
143  // Ensure the previous section gets aligned if necessary.
144  setSectionAlignmentForBundling(Asm, CurSection);
145  auto *SectionELF = static_cast<const MCSectionELF *>(Section);
146  const MCSymbol *Grp = SectionELF->getGroup();
147  if (Grp)
148  Asm.registerSymbol(*Grp);
149 
150  this->MCObjectStreamer::ChangeSection(Section, Subsection);
151  MCContext &Ctx = getContext();
152  auto *Begin = cast_or_null<MCSymbolELF>(Section->getBeginSymbol());
153  if (!Begin) {
154  Begin = Ctx.getOrCreateSectionSymbol(*SectionELF);
155  Section->setBeginSymbol(Begin);
156  }
157  if (Begin->isUndefined()) {
158  Asm.registerSymbol(*Begin);
159  Begin->setType(ELF::STT_SECTION);
160  }
161 }
162 
164  getAssembler().registerSymbol(*Symbol);
167  Alias->setVariableValue(Value);
168 }
169 
170 // When GNU as encounters more than one .type declaration for an object it seems
171 // to use a mechanism similar to the one below to decide which type is actually
172 // used in the object file. The greater of T1 and T2 is selected based on the
173 // following ordering:
174 // STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
175 // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
176 // provided type).
177 static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
180  if (T1 == Type)
181  return T2;
182  if (T2 == Type)
183  return T1;
184  }
185 
186  return T2;
187 }
188 
190  auto *Symbol = cast<MCSymbolELF>(S);
191  // Indirect symbols are handled differently, to match how 'as' handles
192  // them. This makes writing matching .o files easier.
193  if (Attribute == MCSA_IndirectSymbol) {
194  // Note that we intentionally cannot use the symbol data here; this is
195  // important for matching the string table that 'as' generates.
196  IndirectSymbolData ISD;
197  ISD.Symbol = Symbol;
199  getAssembler().getIndirectSymbols().push_back(ISD);
200  return true;
201  }
202 
203  // Adding a symbol attribute always introduces the symbol, note that an
204  // important side effect of calling registerSymbol here is to register
205  // the symbol with the assembler.
207 
208  // The implementation of symbol attributes is designed to match 'as', but it
209  // leaves much to desired. It doesn't really make sense to arbitrarily add and
210  // remove flags, but 'as' allows this (in particular, see .desc).
211  //
212  // In the future it might be worth trying to make these operations more well
213  // defined.
214  switch (Attribute) {
215  case MCSA_LazyReference:
216  case MCSA_Reference:
217  case MCSA_SymbolResolver:
218  case MCSA_PrivateExtern:
219  case MCSA_WeakDefinition:
221  case MCSA_Invalid:
222  case MCSA_IndirectSymbol:
223  return false;
224 
225  case MCSA_NoDeadStrip:
226  // Ignore for now.
227  break;
228 
230  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
231  Symbol->setBinding(ELF::STB_GNU_UNIQUE);
232  Symbol->setExternal(true);
233  break;
234 
235  case MCSA_Global:
236  Symbol->setBinding(ELF::STB_GLOBAL);
237  Symbol->setExternal(true);
238  break;
239 
240  case MCSA_WeakReference:
241  case MCSA_Weak:
242  Symbol->setBinding(ELF::STB_WEAK);
243  Symbol->setExternal(true);
244  break;
245 
246  case MCSA_Local:
247  Symbol->setBinding(ELF::STB_LOCAL);
248  Symbol->setExternal(false);
249  break;
250 
252  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
253  break;
254 
256  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
257  break;
258 
259  case MCSA_ELF_TypeObject:
260  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
261  break;
262 
263  case MCSA_ELF_TypeTLS:
264  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
265  break;
266 
267  case MCSA_ELF_TypeCommon:
268  // TODO: Emit these as a common symbol.
269  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
270  break;
271 
272  case MCSA_ELF_TypeNoType:
273  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
274  break;
275 
276  case MCSA_Protected:
277  Symbol->setVisibility(ELF::STV_PROTECTED);
278  break;
279 
280  case MCSA_Hidden:
281  Symbol->setVisibility(ELF::STV_HIDDEN);
282  break;
283 
284  case MCSA_Internal:
285  Symbol->setVisibility(ELF::STV_INTERNAL);
286  break;
287 
288  case MCSA_AltEntry:
289  llvm_unreachable("ELF doesn't support the .alt_entry attribute");
290  }
291 
292  return true;
293 }
294 
296  unsigned ByteAlignment) {
297  auto *Symbol = cast<MCSymbolELF>(S);
299 
300  if (!Symbol->isBindingSet()) {
301  Symbol->setBinding(ELF::STB_GLOBAL);
302  Symbol->setExternal(true);
303  }
304 
305  Symbol->setType(ELF::STT_OBJECT);
306 
307  if (Symbol->getBinding() == ELF::STB_LOCAL) {
311  SwitchSection(&Section);
312 
313  EmitValueToAlignment(ByteAlignment, 0, 1, 0);
314  EmitLabel(Symbol);
315  EmitZeros(Size);
316 
317  // Update the maximum alignment of the section if necessary.
318  if (ByteAlignment > Section.getAlignment())
319  Section.setAlignment(ByteAlignment);
320 
321  SwitchSection(P.first, P.second);
322  } else {
323  if(Symbol->declareCommon(Size, ByteAlignment))
324  report_fatal_error("Symbol: " + Symbol->getName() +
325  " redeclared as different type");
326  }
327 
328  cast<MCSymbolELF>(Symbol)
329  ->setSize(MCConstantExpr::create(Size, getContext()));
330 }
331 
333  cast<MCSymbolELF>(Symbol)->setSize(Value);
334 }
335 
337  unsigned ByteAlignment) {
338  auto *Symbol = cast<MCSymbolELF>(S);
339  // FIXME: Should this be caught and done earlier?
341  Symbol->setBinding(ELF::STB_LOCAL);
342  Symbol->setExternal(false);
343  EmitCommonSymbol(Symbol, Size, ByteAlignment);
344 }
345 
346 void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
347  SMLoc Loc) {
348  if (isBundleLocked())
349  report_fatal_error("Emitting values inside a locked bundle is forbidden");
350  fixSymbolsInTLSFixups(Value);
351  MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
352 }
353 
355  int64_t Value,
356  unsigned ValueSize,
357  unsigned MaxBytesToEmit) {
358  if (isBundleLocked())
359  report_fatal_error("Emitting values inside a locked bundle is forbidden");
360  MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
361  ValueSize, MaxBytesToEmit);
362 }
363 
364 // Add a symbol for the file name of this module. They start after the
365 // null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol
366 // with the same name may appear.
368  getAssembler().addFileName(Filename);
369 }
370 
373  ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
374  PushSection();
375  SwitchSection(Comment);
376  if (!SeenIdent) {
377  EmitIntValue(0, 1);
378  SeenIdent = true;
379  }
380  EmitBytes(IdentString);
381  EmitIntValue(0, 1);
382  PopSection();
383 }
384 
385 void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
386  switch (expr->getKind()) {
387  case MCExpr::Target:
388  cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
389  break;
390  case MCExpr::Constant:
391  break;
392 
393  case MCExpr::Binary: {
394  const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
395  fixSymbolsInTLSFixups(be->getLHS());
396  fixSymbolsInTLSFixups(be->getRHS());
397  break;
398  }
399 
400  case MCExpr::SymbolRef: {
401  const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
402  switch (symRef.getKind()) {
403  default:
404  return;
450  break;
451  }
453  cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
454  break;
455  }
456 
457  case MCExpr::Unary:
458  fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
459  break;
460  }
461 }
462 
463 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
464  const MCSubtargetInfo &STI) {
465  this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
466  MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
467 
468  for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
469  fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
470 }
471 
472 void MCELFStreamer::EmitInstToData(const MCInst &Inst,
473  const MCSubtargetInfo &STI) {
474  MCAssembler &Assembler = getAssembler();
476  SmallString<256> Code;
477  raw_svector_ostream VecOS(Code);
478  Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
479 
480  for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
481  fixSymbolsInTLSFixups(Fixups[i].getValue());
482 
483  // There are several possibilities here:
484  //
485  // If bundling is disabled, append the encoded instruction to the current data
486  // fragment (or create a new such fragment if the current fragment is not a
487  // data fragment).
488  //
489  // If bundling is enabled:
490  // - If we're not in a bundle-locked group, emit the instruction into a
491  // fragment of its own. If there are no fixups registered for the
492  // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
493  // MCDataFragment.
494  // - If we're in a bundle-locked group, append the instruction to the current
495  // data fragment because we want all the instructions in a group to get into
496  // the same fragment. Be careful not to do that for the first instruction in
497  // the group, though.
498  MCDataFragment *DF;
499 
500  if (Assembler.isBundlingEnabled()) {
502  if (Assembler.getRelaxAll() && isBundleLocked())
503  // If the -mc-relax-all flag is used and we are bundle-locked, we re-use
504  // the current bundle group.
505  DF = BundleGroups.back();
506  else if (Assembler.getRelaxAll() && !isBundleLocked())
507  // When not in a bundle-locked group and the -mc-relax-all flag is used,
508  // we create a new temporary fragment which will be later merged into
509  // the current fragment.
510  DF = new MCDataFragment();
511  else if (isBundleLocked() && !Sec.isBundleGroupBeforeFirstInst())
512  // If we are bundle-locked, we re-use the current fragment.
513  // The bundle-locking directive ensures this is a new data fragment.
514  DF = cast<MCDataFragment>(getCurrentFragment());
515  else if (!isBundleLocked() && Fixups.size() == 0) {
516  // Optimize memory usage by emitting the instruction to a
517  // MCCompactEncodedInstFragment when not in a bundle-locked group and
518  // there are no fixups registered.
520  insert(CEIF);
521  CEIF->getContents().append(Code.begin(), Code.end());
522  return;
523  } else {
524  DF = new MCDataFragment();
525  insert(DF);
526  }
528  // If this fragment is for a group marked "align_to_end", set a flag
529  // in the fragment. This can happen after the fragment has already been
530  // created if there are nested bundle_align groups and an inner one
531  // is the one marked align_to_end.
532  DF->setAlignToBundleEnd(true);
533  }
534 
535  // We're now emitting an instruction in a bundle group, so this flag has
536  // to be turned off.
538  } else {
540  }
541 
542  // Add the fixups and data.
543  for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
544  Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
545  DF->getFixups().push_back(Fixups[i]);
546  }
547  DF->setHasInstructions(true);
548  DF->getContents().append(Code.begin(), Code.end());
549 
550  if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
551  if (!isBundleLocked()) {
552  mergeFragment(getOrCreateDataFragment(), DF);
553  delete DF;
554  }
555  }
556 }
557 
558 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
559  assert(AlignPow2 <= 30 && "Invalid bundle alignment");
560  MCAssembler &Assembler = getAssembler();
561  if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 ||
562  Assembler.getBundleAlignSize() == 1U << AlignPow2))
563  Assembler.setBundleAlignSize(1U << AlignPow2);
564  else
565  report_fatal_error(".bundle_align_mode cannot be changed once set");
566 }
567 
568 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
570 
571  // Sanity checks
572  //
573  if (!getAssembler().isBundlingEnabled())
574  report_fatal_error(".bundle_lock forbidden when bundling is disabled");
575 
576  if (!isBundleLocked())
578 
579  if (getAssembler().getRelaxAll() && !isBundleLocked()) {
580  // TODO: drop the lock state and set directly in the fragment
581  MCDataFragment *DF = new MCDataFragment();
582  BundleGroups.push_back(DF);
583  }
584 
587 }
588 
591 
592  // Sanity checks
593  if (!getAssembler().isBundlingEnabled())
594  report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
595  else if (!isBundleLocked())
596  report_fatal_error(".bundle_unlock without matching lock");
597  else if (Sec.isBundleGroupBeforeFirstInst())
598  report_fatal_error("Empty bundle-locked group is forbidden");
599 
600  // When the -mc-relax-all flag is used, we emit instructions to fragments
601  // stored on a stack. When the bundle unlock is emitted, we pop a fragment
602  // from the stack a merge it to the one below.
603  if (getAssembler().getRelaxAll()) {
604  assert(!BundleGroups.empty() && "There are no bundle groups");
605  MCDataFragment *DF = BundleGroups.back();
606 
607  // FIXME: Use BundleGroups to track the lock state instead.
609 
610  // FIXME: Use more separate fragments for nested groups.
611  if (!isBundleLocked()) {
612  mergeFragment(getOrCreateDataFragment(), DF);
613  BundleGroups.pop_back();
614  delete DF;
615  }
616 
619  } else
621 }
622 
624  // Ensure the last section gets aligned if necessary.
625  MCSection *CurSection = getCurrentSectionOnly();
627 
628  EmitFrames(nullptr);
629 
631 }
632 
635  bool RelaxAll) {
636  MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE);
637  if (RelaxAll)
638  S->getAssembler().setRelaxAll(true);
639  return S;
640 }
641 
643  llvm_unreachable("Generic ELF doesn't support this directive");
644 }
645 
646 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
647  llvm_unreachable("ELF doesn't support this directive");
648 }
649 
651  llvm_unreachable("ELF doesn't support this directive");
652 }
653 
655  llvm_unreachable("ELF doesn't support this directive");
656 }
657 
659  llvm_unreachable("ELF doesn't support this directive");
660 }
661 
663  llvm_unreachable("ELF doesn't support this directive");
664 }
665 
667  uint64_t Size, unsigned ByteAlignment) {
668  llvm_unreachable("ELF doesn't support this directive");
669 }
670 
672  uint64_t Size, unsigned ByteAlignment) {
673  llvm_unreachable("ELF doesn't support this directive");
674 }
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
MCSymbolELF * getOrCreateSectionSymbol(const MCSectionELF &Section)
Definition: MCContext.cpp:127
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:40
virtual MCObjectWriter * createObjectWriter(raw_pwrite_stream &OS) const =0
Create a new MCObjectWriter instance for use by the assembler backend to emit the final object file...
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:243
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
LLVMContext & Context
const MCSymbol & getSymbol() const
Definition: MCExpr.h:311
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:298
bool hasInstructions() const
Definition: MCSection.h:137
size_t i
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void EmitLabel(MCSymbol *Symbol) override
Emit a label for Symbol into the current section.
.type _foo, STT_OBJECT # aka
Definition: MCDirectives.h:25
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
Not a valid directive.
Definition: MCDirectives.h:20
void EmitBundleUnlock() override
Ends a bundle-locked group.
void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
void EmitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, unsigned ByteAlignment=0) override
Emit the zerofill section and an optional symbol.
unsigned getBundleAlignSize() const
Definition: MCAssembler.h:293
void setAlignment(unsigned Value)
Definition: MCSection.h:118
void writeFragmentPadding(const MCFragment &F, uint64_t FSize, MCObjectWriter *OW) const
Write the necessary bundle padding to the given object writer.
ExprKind getKind() const
Definition: MCExpr.h:70
unsigned getFlags() const
Definition: MCSectionELF.h:76
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:37
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:262
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:490
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
void PushSection()
Save the current and previous section on the section stack.
Definition: MCStreamer.h:324
This is a compact (memory-size-wise) fragment for holding an encoded instruction (non-relaxable) that...
Definition: MCFragment.h:235
void EmitCOFFSymbolType(int Type) override
Emit the type of the symbol.
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
std::vector< IndirectSymbolData > & getIndirectSymbols()
Definition: MCAssembler.h:335
.type _foo, STT_NOTYPE # aka
Definition: MCDirectives.h:28
unsigned getAlignment() const
Definition: MCSection.h:117
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:296
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override
Start emitting COFF symbol definition.
MCContext & getContext() const
Definition: MCAssembler.h:258
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2)
Defines the object file and target independent interfaces used by the assembler backend to write nati...
void EmitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
MCFragment * getCurrentFragment() const
ExternalFunctions * EF
void EmitFileDirective(StringRef Filename) override
Switch to a new logical file.
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition: MCStreamer.h:297
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment=0) override
Emit a thread local bss (.tbss) symbol.
void setRelaxAll(bool Value)
Definition: MCAssembler.h:289
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:302
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void EmitLabel(MCSymbol *Symbol) override
Emit a label for Symbol into the current section.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:161
void setAlignToBundleEnd(bool V)
Definition: MCFragment.h:112
.local (ELF)
Definition: MCDirectives.h:35
.no_dead_strip (MachO)
Definition: MCDirectives.h:36
MCContext & getContext() const
Definition: MCStreamer.h:221
void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override
Set the DescValue for the Symbol.
void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void setSubsectionsViaSymbols(bool Value)
Definition: MCAssembler.h:279
Context object for machine code objects.
Definition: MCContext.h:51
#define F(x, y, z)
Definition: MD5.cpp:51
void EmitThumbFunc(MCSymbol *Func) override
Note in the output that the specified Func is a Thumb mode function (ARM target only).
void setHasInstructions(bool V)
Definition: MCFragment.h:223
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:51
.type _foo, STT_GNU_IFUNC
Definition: MCDirectives.h:24
.alt_entry (MachO)
Definition: MCDirectives.h:38
void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
Definition: MCStreamer.h:44
.protected (ELF)
Definition: MCDirectives.h:40
void setBundleAlignSize(unsigned Size)
Definition: MCAssembler.h:295
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
.lazy_reference (MachO)
Definition: MCDirectives.h:34
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:175
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:85
.reference (MachO)
Definition: MCDirectives.h:41
Unary expressions.
Definition: MCExpr.h:40
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:121
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:249
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
.hidden (ELF)
Definition: MCDirectives.h:31
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:514
#define P(N)
void EmitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Definition: MCStreamer.cpp:173
Streaming machine code generation interface.
Definition: MCStreamer.h:161
.weak_def_can_be_hidden (MachO)
Definition: MCDirectives.h:45
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
void insert(MCFragment *F)
void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:829
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:115
static void setSectionAlignmentForBundling(const MCAssembler &Assembler, MCSection *Section)
MCAssembler & getAssembler()
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:23
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
bool getRelaxAll() const
Definition: MCAssembler.h:288
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:200
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:50
MCSection * getTextSection() const
void EmitFrames(MCAsmBackend *MAB)
.weak_reference (MachO)
Definition: MCDirectives.h:44
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:392
Binary assembler expressions.
Definition: MCExpr.h:388
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCFragment *F, uint64_t FOffset, uint64_t FSize)
Compute the amount of padding required before the fragment F to obey bundling restrictions, where FOffset is the fragment's offset in its section and FSize is the fragment's size.
Definition: MCFragment.cpp:192
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
bool isBundlingEnabled() const
Definition: MCAssembler.h:291
.indirect_symbol (MachO)
Definition: MCDirectives.h:32
.type _foo, STT_TLS # aka
Definition: MCDirectives.h:26
MCSymbol * getBeginSymbol()
Definition: MCSection.h:106
MCStreamer * createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll)
Takes ownership of TAB and CE.
void setVariableValue(const MCExpr *Value)
Definition: MCSymbol.cpp:42
MCSymbolAttr
Definition: MCDirectives.h:19
void addFileName(StringRef FileName)
Definition: MCAssembler.h:405
void flushPendingLabels(MCFragment *F, uint64_t FOffset=0)
If any labels have been emitted but not assigned fragments, ensure that they get assigned, either to F if possible or to a new data fragment.
.syntax (ARM/ELF)
Definition: MCDirectives.h:49
.internal (ELF)
Definition: MCDirectives.h:33
.code32 (X86) / .code 32 (ARM)
Definition: MCDirectives.h:52
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:517
.type _foo, STT_COMMON # aka
Definition: MCDirectives.h:27
.code64 (X86)
Definition: MCDirectives.h:53
void setBundlePadding(uint8_t N)
Set the padding size for this fragment.
Definition: MCFragment.h:123
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
Definition: MCAsmBackend.h:130
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:119
.symbol_resolver (MachO)
Definition: MCDirectives.h:37
.type _foo,
Definition: MCDirectives.h:30
void FinishImpl() override
Streamer specific finalization.
MCAssemblerFlag
Definition: MCDirectives.h:48
.type _foo, STT_FUNC # aka
Definition: MCDirectives.h:23
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:260
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
bool isBundleGroupBeforeFirstInst() const
Definition: MCSection.h:130
MCSubtargetInfo - Generic base class for all target subtargets.
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:30
References to labels and assigned expressions.
Definition: MCExpr.h:39
void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
BundleLockStateType getBundleLockState() const
Definition: MCSection.h:126
.weak_definition (MachO)
Definition: MCDirectives.h:43
void setBundleGroupBeforeFirstInst(bool IsFirst)
Definition: MCSection.h:133
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:333
Fragment for data and encoded instructions.
Definition: MCFragment.h:218
virtual MCSection * getNonexecutableStackSection(MCContext &Ctx) const
Targets can implement this method to specify a section to switch to if the translation unit doesn't h...
Definition: MCAsmInfo.h:415
VariantKind getKind() const
Definition: MCExpr.h:313
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
.private_extern (MachO)
Definition: MCDirectives.h:39
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, ""relax all fixups in the emitted object file"))
bool PopSection()
Restore the current and previous section from the section stack.
Definition: MCStreamer.h:333
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:341
LLVM Value Representation.
Definition: Value.h:71
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:36
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:247
bool isBundleLocked() const
Definition: MCSection.h:128
Constant expressions.
Definition: MCExpr.h:38
Binary expressions.
Definition: MCExpr.h:37
void EndCOFFSymbolDef() override
Marks the end of the symbol definition.
void EmitAssemblerFlag(MCAssemblerFlag Flag) override
Note in the output the specified Flag.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
Target specific expression.
Definition: MCExpr.h:41
~MCELFStreamer() override
Represents a location in source code.
Definition: SMLoc.h:24
void FinishImpl() override
Streamer specific finalization.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:149
#define T1
MCDataFragment * getOrCreateDataFragment()
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment...
void EmitCOFFSymbolStorageClass(int StorageClass) override
Emit the storage class of the symbol.
void setBeginSymbol(MCSymbol *Sym)
Definition: MCSection.h:110