LLVM  3.7.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/MCSection.h"
28 #include "llvm/MC/MCSectionELF.h"
29 #include "llvm/MC/MCSymbolELF.h"
30 #include "llvm/MC/MCSymbol.h"
31 #include "llvm/MC/MCValue.h"
32 #include "llvm/Support/Debug.h"
33 #include "llvm/Support/ELF.h"
37 
38 using namespace llvm;
39 
40 bool MCELFStreamer::isBundleLocked() const {
42 }
43 
45 }
46 
47 void MCELFStreamer::mergeFragment(MCDataFragment *DF,
48  MCDataFragment *EF) {
49  MCAssembler &Assembler = getAssembler();
50 
51  if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
52  uint64_t FSize = EF->getContents().size();
53 
54  if (FSize > Assembler.getBundleAlignSize())
55  report_fatal_error("Fragment can't be larger than a bundle size");
56 
57  uint64_t RequiredBundlePadding = computeBundlePadding(
58  Assembler, EF, DF->getContents().size(), FSize);
59 
60  if (RequiredBundlePadding > UINT8_MAX)
61  report_fatal_error("Padding cannot exceed 255 bytes");
62 
63  if (RequiredBundlePadding > 0) {
65  raw_svector_ostream VecOS(Code);
66  MCObjectWriter *OW = Assembler.getBackend().createObjectWriter(VecOS);
67 
68  EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
69 
70  Assembler.writeFragmentPadding(*EF, FSize, OW);
71  VecOS.flush();
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  // This emulates the same behavior of GNU as. This makes it easier
91  // to compare the output as the major sections are in the same order.
92  MCContext &Ctx = getContext();
95 
98 
101 
103 
104  if (NoExecStack)
106 }
107 
109  auto *Symbol = cast<MCSymbolELF>(S);
110  assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
111 
113 
114  const MCSectionELF &Section =
115  static_cast<const MCSectionELF&>(Symbol->getSection());
116  if (Section.getFlags() & ELF::SHF_TLS)
117  Symbol->setType(ELF::STT_TLS);
118 }
119 
121  // Let the target do whatever target specific stuff it needs to do.
123  // Do any generic stuff we need to do.
124  switch (Flag) {
125  case MCAF_SyntaxUnified: return; // no-op here.
126  case MCAF_Code16: return; // Change parsing mode; no-op here.
127  case MCAF_Code32: return; // Change parsing mode; no-op here.
128  case MCAF_Code64: return; // Change parsing mode; no-op here.
131  return;
132  }
133 
134  llvm_unreachable("invalid assembler flag!");
135 }
136 
137 // If bundle aligment is used and there are any instructions in the section, it
138 // needs to be aligned to at least the bundle size.
139 static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
140  MCSection *Section) {
141  if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions() &&
142  Section->getAlignment() < Assembler.getBundleAlignSize())
143  Section->setAlignment(Assembler.getBundleAlignSize());
144 }
145 
147  const MCExpr *Subsection) {
148  MCSection *CurSection = getCurrentSectionOnly();
149  if (CurSection && isBundleLocked())
150  report_fatal_error("Unterminated .bundle_lock when changing a section");
151 
153  // Ensure the previous section gets aligned if necessary.
154  setSectionAlignmentForBundling(Asm, CurSection);
155  auto *SectionELF = static_cast<const MCSectionELF *>(Section);
156  const MCSymbol *Grp = SectionELF->getGroup();
157  if (Grp)
158  Asm.registerSymbol(*Grp);
159 
160  this->MCObjectStreamer::ChangeSection(Section, Subsection);
161  MCContext &Ctx = getContext();
162  auto *Begin = cast_or_null<MCSymbolELF>(Section->getBeginSymbol());
163  if (!Begin) {
164  Begin = Ctx.getOrCreateSectionSymbol(*SectionELF);
165  Section->setBeginSymbol(Begin);
166  }
167  if (Begin->isUndefined()) {
168  Asm.registerSymbol(*Begin);
169  Begin->setType(ELF::STT_SECTION);
170  }
171 }
172 
174  getAssembler().registerSymbol(*Symbol);
177  Alias->setVariableValue(Value);
178 }
179 
180 // When GNU as encounters more than one .type declaration for an object it seems
181 // to use a mechanism similar to the one below to decide which type is actually
182 // used in the object file. The greater of T1 and T2 is selected based on the
183 // following ordering:
184 // STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
185 // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
186 // provided type).
187 static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
190  if (T1 == Type)
191  return T2;
192  if (T2 == Type)
193  return T1;
194  }
195 
196  return T2;
197 }
198 
200  auto *Symbol = cast<MCSymbolELF>(S);
201  // Indirect symbols are handled differently, to match how 'as' handles
202  // them. This makes writing matching .o files easier.
203  if (Attribute == MCSA_IndirectSymbol) {
204  // Note that we intentionally cannot use the symbol data here; this is
205  // important for matching the string table that 'as' generates.
206  IndirectSymbolData ISD;
207  ISD.Symbol = Symbol;
209  getAssembler().getIndirectSymbols().push_back(ISD);
210  return true;
211  }
212 
213  // Adding a symbol attribute always introduces the symbol, note that an
214  // important side effect of calling registerSymbol here is to register
215  // the symbol with the assembler.
217 
218  // The implementation of symbol attributes is designed to match 'as', but it
219  // leaves much to desired. It doesn't really make sense to arbitrarily add and
220  // remove flags, but 'as' allows this (in particular, see .desc).
221  //
222  // In the future it might be worth trying to make these operations more well
223  // defined.
224  switch (Attribute) {
225  case MCSA_LazyReference:
226  case MCSA_Reference:
227  case MCSA_SymbolResolver:
228  case MCSA_PrivateExtern:
229  case MCSA_WeakDefinition:
231  case MCSA_Invalid:
232  case MCSA_IndirectSymbol:
233  return false;
234 
235  case MCSA_NoDeadStrip:
236  // Ignore for now.
237  break;
238 
240  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
241  Symbol->setBinding(ELF::STB_GNU_UNIQUE);
242  Symbol->setExternal(true);
243  break;
244 
245  case MCSA_Global:
246  Symbol->setBinding(ELF::STB_GLOBAL);
247  Symbol->setExternal(true);
248  break;
249 
250  case MCSA_WeakReference:
251  case MCSA_Weak:
252  Symbol->setBinding(ELF::STB_WEAK);
253  Symbol->setExternal(true);
254  break;
255 
256  case MCSA_Local:
257  Symbol->setBinding(ELF::STB_LOCAL);
258  Symbol->setExternal(false);
259  break;
260 
262  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
263  break;
264 
266  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
267  break;
268 
269  case MCSA_ELF_TypeObject:
270  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
271  break;
272 
273  case MCSA_ELF_TypeTLS:
274  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
275  break;
276 
277  case MCSA_ELF_TypeCommon:
278  // TODO: Emit these as a common symbol.
279  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
280  break;
281 
282  case MCSA_ELF_TypeNoType:
283  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
284  break;
285 
286  case MCSA_Protected:
287  Symbol->setVisibility(ELF::STV_PROTECTED);
288  break;
289 
290  case MCSA_Hidden:
291  Symbol->setVisibility(ELF::STV_HIDDEN);
292  break;
293 
294  case MCSA_Internal:
295  Symbol->setVisibility(ELF::STV_INTERNAL);
296  break;
297  }
298 
299  return true;
300 }
301 
303  unsigned ByteAlignment) {
304  auto *Symbol = cast<MCSymbolELF>(S);
306 
307  if (!Symbol->isBindingSet()) {
308  Symbol->setBinding(ELF::STB_GLOBAL);
309  Symbol->setExternal(true);
310  }
311 
312  Symbol->setType(ELF::STT_OBJECT);
313 
314  if (Symbol->getBinding() == ELF::STB_LOCAL) {
317 
318  AssignSection(Symbol, Section);
319 
320  struct LocalCommon L = {Symbol, Size, ByteAlignment};
321  LocalCommons.push_back(L);
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  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  const 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;
454  break;
455  }
457  cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
458  break;
459  }
460 
461  case MCExpr::Unary:
462  fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
463  break;
464  }
465 }
466 
467 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
468  const MCSubtargetInfo &STI) {
469  this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
470  MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
471 
472  for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
473  fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
474 }
475 
476 void MCELFStreamer::EmitInstToData(const MCInst &Inst,
477  const MCSubtargetInfo &STI) {
478  MCAssembler &Assembler = getAssembler();
481  raw_svector_ostream VecOS(Code);
482  Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
483  VecOS.flush();
484 
485  for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
486  fixSymbolsInTLSFixups(Fixups[i].getValue());
487 
488  // There are several possibilities here:
489  //
490  // If bundling is disabled, append the encoded instruction to the current data
491  // fragment (or create a new such fragment if the current fragment is not a
492  // data fragment).
493  //
494  // If bundling is enabled:
495  // - If we're not in a bundle-locked group, emit the instruction into a
496  // fragment of its own. If there are no fixups registered for the
497  // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
498  // MCDataFragment.
499  // - If we're in a bundle-locked group, append the instruction to the current
500  // data fragment because we want all the instructions in a group to get into
501  // the same fragment. Be careful not to do that for the first instruction in
502  // the group, though.
503  MCDataFragment *DF;
504 
505  if (Assembler.isBundlingEnabled()) {
507  if (Assembler.getRelaxAll() && isBundleLocked())
508  // If the -mc-relax-all flag is used and we are bundle-locked, we re-use
509  // the current bundle group.
510  DF = BundleGroups.back();
511  else if (Assembler.getRelaxAll() && !isBundleLocked())
512  // When not in a bundle-locked group and the -mc-relax-all flag is used,
513  // we create a new temporary fragment which will be later merged into
514  // the current fragment.
515  DF = new MCDataFragment();
516  else if (isBundleLocked() && !Sec.isBundleGroupBeforeFirstInst())
517  // If we are bundle-locked, we re-use the current fragment.
518  // The bundle-locking directive ensures this is a new data fragment.
519  DF = cast<MCDataFragment>(getCurrentFragment());
520  else if (!isBundleLocked() && Fixups.size() == 0) {
521  // Optimize memory usage by emitting the instruction to a
522  // MCCompactEncodedInstFragment when not in a bundle-locked group and
523  // there are no fixups registered.
525  insert(CEIF);
526  CEIF->getContents().append(Code.begin(), Code.end());
527  return;
528  } else {
529  DF = new MCDataFragment();
530  insert(DF);
531  }
533  // If this fragment is for a group marked "align_to_end", set a flag
534  // in the fragment. This can happen after the fragment has already been
535  // created if there are nested bundle_align groups and an inner one
536  // is the one marked align_to_end.
537  DF->setAlignToBundleEnd(true);
538  }
539 
540  // We're now emitting an instruction in a bundle group, so this flag has
541  // to be turned off.
543  } else {
545  }
546 
547  // Add the fixups and data.
548  for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
549  Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
550  DF->getFixups().push_back(Fixups[i]);
551  }
552  DF->setHasInstructions(true);
553  DF->getContents().append(Code.begin(), Code.end());
554 
555  if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
556  if (!isBundleLocked()) {
557  mergeFragment(getOrCreateDataFragment(), DF);
558  delete DF;
559  }
560  }
561 }
562 
563 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
564  assert(AlignPow2 <= 30 && "Invalid bundle alignment");
565  MCAssembler &Assembler = getAssembler();
566  if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 ||
567  Assembler.getBundleAlignSize() == 1U << AlignPow2))
568  Assembler.setBundleAlignSize(1U << AlignPow2);
569  else
570  report_fatal_error(".bundle_align_mode cannot be changed once set");
571 }
572 
573 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
575 
576  // Sanity checks
577  //
578  if (!getAssembler().isBundlingEnabled())
579  report_fatal_error(".bundle_lock forbidden when bundling is disabled");
580 
581  if (!isBundleLocked())
583 
584  if (getAssembler().getRelaxAll() && !isBundleLocked()) {
585  // TODO: drop the lock state and set directly in the fragment
586  MCDataFragment *DF = new MCDataFragment();
587  BundleGroups.push_back(DF);
588  }
589 
592 }
593 
596 
597  // Sanity checks
598  if (!getAssembler().isBundlingEnabled())
599  report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
600  else if (!isBundleLocked())
601  report_fatal_error(".bundle_unlock without matching lock");
602  else if (Sec.isBundleGroupBeforeFirstInst())
603  report_fatal_error("Empty bundle-locked group is forbidden");
604 
605  // When the -mc-relax-all flag is used, we emit instructions to fragments
606  // stored on a stack. When the bundle unlock is emited, we pop a fragment
607  // from the stack a merge it to the one below.
608  if (getAssembler().getRelaxAll()) {
609  assert(!BundleGroups.empty() && "There are no bundle groups");
610  MCDataFragment *DF = BundleGroups.back();
611 
612  // FIXME: Use BundleGroups to track the lock state instead.
614 
615  // FIXME: Use more separate fragments for nested groups.
616  if (!isBundleLocked()) {
617  mergeFragment(getOrCreateDataFragment(), DF);
618  BundleGroups.pop_back();
619  delete DF;
620  }
621 
624  } else
626 }
627 
629  for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
630  e = LocalCommons.end();
631  i != e; ++i) {
632  const MCSymbol &Symbol = *i->Symbol;
633  uint64_t Size = i->Size;
634  unsigned ByteAlignment = i->ByteAlignment;
635  MCSection &Section = Symbol.getSection();
636 
637  getAssembler().registerSection(Section);
638  new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &Section);
639 
640  MCFragment *F = new MCFillFragment(0, 0, Size, &Section);
641  Symbol.setFragment(F);
642 
643  // Update the maximum alignment of the section if necessary.
644  if (ByteAlignment > Section.getAlignment())
645  Section.setAlignment(ByteAlignment);
646  }
647 
648  LocalCommons.clear();
649 }
650 
652  // Ensure the last section gets aligned if necessary.
653  MCSection *CurSection = getCurrentSectionOnly();
655 
656  EmitFrames(nullptr);
657 
658  Flush();
659 
661 }
662 
665  bool RelaxAll) {
666  MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE);
667  if (RelaxAll)
668  S->getAssembler().setRelaxAll(true);
669  return S;
670 }
671 
673  llvm_unreachable("Generic ELF doesn't support this directive");
674 }
675 
676 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
677  llvm_unreachable("ELF doesn't support this directive");
678 }
679 
681  llvm_unreachable("ELF doesn't support this directive");
682 }
683 
685  llvm_unreachable("ELF doesn't support this directive");
686 }
687 
689  llvm_unreachable("ELF doesn't support this directive");
690 }
691 
693  llvm_unreachable("ELF doesn't support this directive");
694 }
695 
697  uint64_t Size, unsigned ByteAlignment) {
698  llvm_unreachable("ELF doesn't support this directive");
699 }
700 
702  uint64_t Size, unsigned ByteAlignment) {
703  llvm_unreachable("ELF doesn't support this directive");
704 }
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
void AssignSection(MCSymbol *Symbol, MCSection *Section)
Sets the symbol's section.
Definition: MCStreamer.cpp:192
MCSymbolELF * getOrCreateSectionSymbol(const MCSectionELF &Section)
Definition: MCContext.cpp:124
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
void Flush() override
Causes any cached state to be written out.
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:225
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
const MCSymbol & getSymbol() const
Definition: MCExpr.h:328
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:315
bool hasInstructions() const
Definition: MCSection.h:144
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.
MCSectionELF * getELFSection(StringRef Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:311
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:753
void setAlignment(unsigned Value)
Definition: MCSection.h:125
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:69
unsigned getFlags() const
Definition: MCSectionELF.h:77
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:37
void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:735
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:488
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
void PushSection()
Save the current and previous section on the section stack.
Definition: MCStreamer.h:301
MCSection * getDataSection() const
This is a compact (memory-size-wise) fragment for holding an encoded instruction (non-relaxable) that...
Definition: MCAssembler.h:245
F(f)
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:795
bool registerSection(MCSection &Section)
Definition: MCAssembler.h:859
.type _foo, STT_NOTYPE # aka
Definition: MCDirectives.h:28
unsigned getAlignment() const
Definition: MCSection.h:124
static std::error_code getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:294
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override
Start emitting COFF symbol definition.
MCContext & getContext() const
Definition: MCAssembler.h:731
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.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
MCFragment * getCurrentFragment() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
void EmitFileDirective(StringRef Filename) override
Switch to a new logical file.
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:749
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:279
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
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:159
void setAlignToBundleEnd(bool V)
Definition: MCAssembler.h:133
.local (ELF)
Definition: MCDirectives.h:35
.no_dead_strip (MachO)
Definition: MCDirectives.h:36
MCContext & getContext() const
Definition: MCStreamer.h:210
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:746
Context object for machine code objects.
Definition: MCContext.h:48
MCSection * getBSSSection() const
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: MCAssembler.h:233
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:50
.type _foo, STT_GNU_IFUNC
Definition: MCDirectives.h:24
.protected (ELF)
Definition: MCDirectives.h:39
void setBundleAlignSize(unsigned Size)
Definition: MCAssembler.h:755
.lazy_reference (MachO)
Definition: MCDirectives.h:34
SmallVectorImpl< char > & getContents()
Definition: MCAssembler.h:186
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:79
.reference (MachO)
Definition: MCDirectives.h:40
Unary expressions.
Definition: MCExpr.h:39
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:97
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCAssembler.h:259
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:531
Streaming machine code generation interface.
Definition: MCStreamer.h:157
.weak_def_can_be_hidden (MachO)
Definition: MCDirectives.h:44
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 setSize(const MCExpr *SS)
Definition: MCSymbolELF.h:23
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:701
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:748
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCAssembler.h:211
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:49
void EmitValueImpl(const MCExpr *Value, unsigned Size, const SMLoc &Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
MCSection * getTextSection() const
void EmitFrames(MCAsmBackend *MAB)
.weak_reference (MachO)
Definition: MCDirectives.h:43
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:416
Binary assembler expressions.
Definition: MCExpr.h:405
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.
void setFragment(MCFragment *Value) const
Definition: MCSymbol.h:385
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:861
bool isBundlingEnabled() const
Definition: MCAssembler.h:751
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:264
.indirect_symbol (MachO)
Definition: MCDirectives.h:32
.type _foo, STT_TLS # aka
Definition: MCDirectives.h:26
MCSymbol * getBeginSymbol()
Definition: MCSection.h:113
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:40
MCSymbolAttr
Definition: MCDirectives.h:19
void addFileName(StringRef FileName)
Definition: MCAssembler.h:871
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:48
.internal (ELF)
Definition: MCDirectives.h:33
.code32 (X86) / .code 32 (ARM)
Definition: MCDirectives.h:51
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:534
.type _foo, STT_COMMON # aka
Definition: MCDirectives.h:27
.code64 (X86)
Definition: MCDirectives.h:52
void setBundlePadding(uint8_t N)
Set the padding size for this fragment.
Definition: MCAssembler.h:144
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
Definition: MCAsmBackend.h:132
.symbol_resolver (MachO)
Definition: MCDirectives.h:37
void EmitValueImpl(const MCExpr *Value, unsigned Size, const SMLoc &Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
.type _foo,
Definition: MCDirectives.h:30
void FinishImpl() override
Streamer specific finalization.
MCAssemblerFlag
Definition: MCDirectives.h:47
.type _foo, STT_FUNC # aka
Definition: MCDirectives.h:23
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:733
bool isBundleGroupBeforeFirstInst() const
Definition: MCSection.h:137
MCSubtargetInfo - Generic base class for all target subtargets.
MCSectionELF - 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:38
BundleLockStateType getBundleLockState() const
Definition: MCSection.h:133
.weak_definition (MachO)
Definition: MCDirectives.h:42
void setBundleGroupBeforeFirstInst(bool IsFirst)
Definition: MCSection.h:140
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:321
Fragment for data and encoded instructions.
Definition: MCAssembler.h:228
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:395
VariantKind getKind() const
Definition: MCExpr.h:330
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
.private_extern (MachO)
Definition: MCDirectives.h:38
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:310
LLVM Value Representation.
Definition: Value.h:69
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:229
bool isBundleLocked() const
Definition: MCSection.h:135
Constant expressions.
Definition: MCExpr.h:37
Binary expressions.
Definition: MCExpr.h:36
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:40
Target specific expression.
Definition: MCExpr.h:40
~MCELFStreamer() override
Represents a location in source code.
Definition: SMLoc.h:23
void FinishImpl() override
Streamer specific finalization.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:150
#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:117