LLVM  8.0.0svn
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/SmallString.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/BinaryFormat/ELF.h"
18 #include "llvm/MC/MCAsmBackend.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/MCFixup.h"
25 #include "llvm/MC/MCFragment.h"
27 #include "llvm/MC/MCObjectWriter.h"
28 #include "llvm/MC/MCSection.h"
29 #include "llvm/MC/MCSectionELF.h"
30 #include "llvm/MC/MCStreamer.h"
31 #include "llvm/MC/MCSymbol.h"
32 #include "llvm/MC/MCSymbolELF.h"
33 #include "llvm/Support/Casting.h"
37 #include <cassert>
38 #include <cstdint>
39 
40 using namespace llvm;
41 
43  std::unique_ptr<MCAsmBackend> TAB,
44  std::unique_ptr<MCObjectWriter> OW,
45  std::unique_ptr<MCCodeEmitter> Emitter)
46  : MCObjectStreamer(Context, std::move(TAB), std::move(OW),
47  std::move(Emitter)) {}
48 
49 bool MCELFStreamer::isBundleLocked() const {
51 }
52 
53 void MCELFStreamer::mergeFragment(MCDataFragment *DF,
54  MCDataFragment *EF) {
55  MCAssembler &Assembler = getAssembler();
56 
57  if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
58  uint64_t FSize = EF->getContents().size();
59 
60  if (FSize > Assembler.getBundleAlignSize())
61  report_fatal_error("Fragment can't be larger than a bundle size");
62 
63  uint64_t RequiredBundlePadding = computeBundlePadding(
64  Assembler, EF, DF->getContents().size(), FSize);
65 
66  if (RequiredBundlePadding > UINT8_MAX)
67  report_fatal_error("Padding cannot exceed 255 bytes");
68 
69  if (RequiredBundlePadding > 0) {
70  SmallString<256> Code;
71  raw_svector_ostream VecOS(Code);
72  EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
73  Assembler.writeFragmentPadding(VecOS, *EF, FSize);
74 
75  DF->getContents().append(Code.begin(), Code.end());
76  }
77  }
78 
79  flushPendingLabels(DF, DF->getContents().size());
80 
81  for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) {
82  EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() +
83  DF->getContents().size());
84  DF->getFixups().push_back(EF->getFixups()[i]);
85  }
86  if (DF->getSubtargetInfo() == nullptr && EF->getSubtargetInfo())
88  DF->getContents().append(EF->getContents().begin(), EF->getContents().end());
89 }
90 
91 void MCELFStreamer::InitSections(bool NoExecStack) {
92  MCContext &Ctx = getContext();
95 
96  if (NoExecStack)
98 }
99 
101  auto *Symbol = cast<MCSymbolELF>(S);
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  auto *Symbol = cast<MCSymbolELF>(S);
113 
114  const MCSectionELF &Section =
115  static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
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 alignment 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  changeSectionImpl(Section, Subsection);
161  Asm.registerSymbol(*Section->getBeginSymbol());
162 }
163 
165  getAssembler().registerSymbol(*Symbol);
168  Alias->setVariableValue(Value);
169 }
170 
171 // When GNU as encounters more than one .type declaration for an object it seems
172 // to use a mechanism similar to the one below to decide which type is actually
173 // used in the object file. The greater of T1 and T2 is selected based on the
174 // following ordering:
175 // STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
176 // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
177 // provided type).
178 static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
181  if (T1 == Type)
182  return T2;
183  if (T2 == Type)
184  return T1;
185  }
186 
187  return T2;
188 }
189 
191  auto *Symbol = cast<MCSymbolELF>(S);
192 
193  // Adding a symbol attribute always introduces the symbol, note that an
194  // important side effect of calling registerSymbol here is to register
195  // the symbol with the assembler.
197 
198  // The implementation of symbol attributes is designed to match 'as', but it
199  // leaves much to desired. It doesn't really make sense to arbitrarily add and
200  // remove flags, but 'as' allows this (in particular, see .desc).
201  //
202  // In the future it might be worth trying to make these operations more well
203  // defined.
204  switch (Attribute) {
205  case MCSA_LazyReference:
206  case MCSA_Reference:
207  case MCSA_SymbolResolver:
208  case MCSA_PrivateExtern:
209  case MCSA_WeakDefinition:
211  case MCSA_Invalid:
212  case MCSA_IndirectSymbol:
213  return false;
214 
215  case MCSA_NoDeadStrip:
216  // Ignore for now.
217  break;
218 
220  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
221  Symbol->setBinding(ELF::STB_GNU_UNIQUE);
222  Symbol->setExternal(true);
223  break;
224 
225  case MCSA_Global:
226  Symbol->setBinding(ELF::STB_GLOBAL);
227  Symbol->setExternal(true);
228  break;
229 
230  case MCSA_WeakReference:
231  case MCSA_Weak:
232  Symbol->setBinding(ELF::STB_WEAK);
233  Symbol->setExternal(true);
234  break;
235 
236  case MCSA_Local:
237  Symbol->setBinding(ELF::STB_LOCAL);
238  Symbol->setExternal(false);
239  break;
240 
242  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
243  break;
244 
246  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
247  break;
248 
249  case MCSA_ELF_TypeObject:
250  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
251  break;
252 
253  case MCSA_ELF_TypeTLS:
254  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
255  break;
256 
257  case MCSA_ELF_TypeCommon:
258  // TODO: Emit these as a common symbol.
259  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
260  break;
261 
262  case MCSA_ELF_TypeNoType:
263  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
264  break;
265 
266  case MCSA_Protected:
267  Symbol->setVisibility(ELF::STV_PROTECTED);
268  break;
269 
270  case MCSA_Hidden:
271  Symbol->setVisibility(ELF::STV_HIDDEN);
272  break;
273 
274  case MCSA_Internal:
275  Symbol->setVisibility(ELF::STV_INTERNAL);
276  break;
277 
278  case MCSA_AltEntry:
279  llvm_unreachable("ELF doesn't support the .alt_entry attribute");
280  }
281 
282  return true;
283 }
284 
286  unsigned ByteAlignment) {
287  auto *Symbol = cast<MCSymbolELF>(S);
289 
290  if (!Symbol->isBindingSet()) {
291  Symbol->setBinding(ELF::STB_GLOBAL);
292  Symbol->setExternal(true);
293  }
294 
295  Symbol->setType(ELF::STT_OBJECT);
296 
297  if (Symbol->getBinding() == ELF::STB_LOCAL) {
301  SwitchSection(&Section);
302 
303  EmitValueToAlignment(ByteAlignment, 0, 1, 0);
304  EmitLabel(Symbol);
305  EmitZeros(Size);
306 
307  // Update the maximum alignment of the section if necessary.
308  if (ByteAlignment > Section.getAlignment())
309  Section.setAlignment(ByteAlignment);
310 
311  SwitchSection(P.first, P.second);
312  } else {
313  if(Symbol->declareCommon(Size, ByteAlignment))
314  report_fatal_error("Symbol: " + Symbol->getName() +
315  " redeclared as different type");
316  }
317 
318  cast<MCSymbolELF>(Symbol)
319  ->setSize(MCConstantExpr::create(Size, getContext()));
320 }
321 
323  cast<MCSymbolELF>(Symbol)->setSize(Value);
324 }
325 
327  const MCSymbol *Aliasee) {
328  getAssembler().Symvers.push_back({AliasName, Aliasee});
329 }
330 
332  unsigned ByteAlignment) {
333  auto *Symbol = cast<MCSymbolELF>(S);
334  // FIXME: Should this be caught and done earlier?
336  Symbol->setBinding(ELF::STB_LOCAL);
337  Symbol->setExternal(false);
338  EmitCommonSymbol(Symbol, Size, ByteAlignment);
339 }
340 
342  SMLoc Loc) {
343  if (isBundleLocked())
344  report_fatal_error("Emitting values inside a locked bundle is forbidden");
345  fixSymbolsInTLSFixups(Value);
346  MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
347 }
348 
350  int64_t Value,
351  unsigned ValueSize,
352  unsigned MaxBytesToEmit) {
353  if (isBundleLocked())
354  report_fatal_error("Emitting values inside a locked bundle is forbidden");
355  MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
356  ValueSize, MaxBytesToEmit);
357 }
358 
360  const MCSymbolRefExpr *To,
361  uint64_t Count) {
362  getAssembler().CGProfile.push_back({From, To, Count});
363 }
364 
367  ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
368  PushSection();
369  SwitchSection(Comment);
370  if (!SeenIdent) {
371  EmitIntValue(0, 1);
372  SeenIdent = true;
373  }
374  EmitBytes(IdentString);
375  EmitIntValue(0, 1);
376  PopSection();
377 }
378 
379 void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
380  switch (expr->getKind()) {
381  case MCExpr::Target:
382  cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
383  break;
384  case MCExpr::Constant:
385  break;
386 
387  case MCExpr::Binary: {
388  const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
389  fixSymbolsInTLSFixups(be->getLHS());
390  fixSymbolsInTLSFixups(be->getRHS());
391  break;
392  }
393 
394  case MCExpr::SymbolRef: {
395  const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
396  switch (symRef.getKind()) {
397  default:
398  return;
448  break;
449  }
451  cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
452  break;
453  }
454 
455  case MCExpr::Unary:
456  fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
457  break;
458  }
459 }
460 
461 void MCELFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE) {
462  const MCSymbol *S = &SRE->getSymbol();
463  if (S->isTemporary()) {
464  if (!S->isInSection()) {
466  SRE->getLoc(), Twine("Reference to undefined temporary symbol ") +
467  "`" + S->getName() + "`");
468  return;
469  }
470  S = S->getSection().getBeginSymbol();
471  S->setUsedInReloc();
472  SRE =
473  MCSymbolRefExpr::create(S, SRE->getKind(), getContext(), SRE->getLoc());
474  return;
475  }
476  // Not a temporary, referece it as a weak undefined.
477  bool Created;
478  getAssembler().registerSymbol(*S, &Created);
479  if (Created) {
480  cast<MCSymbolELF>(S)->setBinding(ELF::STB_WEAK);
481  cast<MCSymbolELF>(S)->setExternal(true);
482  }
483 }
484 
485 void MCELFStreamer::finalizeCGProfile() {
486  for (MCAssembler::CGProfileEntry &E : getAssembler().CGProfile) {
487  finalizeCGProfileEntry(E.From);
488  finalizeCGProfileEntry(E.To);
489  }
490 }
491 
492 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
493  const MCSubtargetInfo &STI) {
494  this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
495  MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
496 
497  for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
498  fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
499 }
500 
501 // A fragment can only have one Subtarget, and when bundling is enabled we
502 // sometimes need to use the same fragment. We give an error if there
503 // are conflicting Subtargets.
504 static void CheckBundleSubtargets(const MCSubtargetInfo *OldSTI,
505  const MCSubtargetInfo *NewSTI) {
506  if (OldSTI && NewSTI && OldSTI != NewSTI)
507  report_fatal_error("A Bundle can only have one Subtarget.");
508 }
509 
510 void MCELFStreamer::EmitInstToData(const MCInst &Inst,
511  const MCSubtargetInfo &STI) {
512  MCAssembler &Assembler = getAssembler();
514  SmallString<256> Code;
515  raw_svector_ostream VecOS(Code);
516  Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
517 
518  for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
519  fixSymbolsInTLSFixups(Fixups[i].getValue());
520 
521  // There are several possibilities here:
522  //
523  // If bundling is disabled, append the encoded instruction to the current data
524  // fragment (or create a new such fragment if the current fragment is not a
525  // data fragment, or the Subtarget has changed).
526  //
527  // If bundling is enabled:
528  // - If we're not in a bundle-locked group, emit the instruction into a
529  // fragment of its own. If there are no fixups registered for the
530  // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
531  // MCDataFragment.
532  // - If we're in a bundle-locked group, append the instruction to the current
533  // data fragment because we want all the instructions in a group to get into
534  // the same fragment. Be careful not to do that for the first instruction in
535  // the group, though.
536  MCDataFragment *DF;
537 
538  if (Assembler.isBundlingEnabled()) {
540  if (Assembler.getRelaxAll() && isBundleLocked()) {
541  // If the -mc-relax-all flag is used and we are bundle-locked, we re-use
542  // the current bundle group.
543  DF = BundleGroups.back();
545  }
546  else if (Assembler.getRelaxAll() && !isBundleLocked())
547  // When not in a bundle-locked group and the -mc-relax-all flag is used,
548  // we create a new temporary fragment which will be later merged into
549  // the current fragment.
550  DF = new MCDataFragment();
551  else if (isBundleLocked() && !Sec.isBundleGroupBeforeFirstInst()) {
552  // If we are bundle-locked, we re-use the current fragment.
553  // The bundle-locking directive ensures this is a new data fragment.
554  DF = cast<MCDataFragment>(getCurrentFragment());
556  }
557  else if (!isBundleLocked() && Fixups.size() == 0) {
558  // Optimize memory usage by emitting the instruction to a
559  // MCCompactEncodedInstFragment when not in a bundle-locked group and
560  // there are no fixups registered.
562  insert(CEIF);
563  CEIF->getContents().append(Code.begin(), Code.end());
564  CEIF->setHasInstructions(STI);
565  return;
566  } else {
567  DF = new MCDataFragment();
568  insert(DF);
569  }
571  // If this fragment is for a group marked "align_to_end", set a flag
572  // in the fragment. This can happen after the fragment has already been
573  // created if there are nested bundle_align groups and an inner one
574  // is the one marked align_to_end.
575  DF->setAlignToBundleEnd(true);
576  }
577 
578  // We're now emitting an instruction in a bundle group, so this flag has
579  // to be turned off.
581  } else {
582  DF = getOrCreateDataFragment(&STI);
583  }
584 
585  // Add the fixups and data.
586  for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
587  Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
588  DF->getFixups().push_back(Fixups[i]);
589  }
590  DF->setHasInstructions(STI);
591  DF->getContents().append(Code.begin(), Code.end());
592 
593  if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
594  if (!isBundleLocked()) {
595  mergeFragment(getOrCreateDataFragment(&STI), DF);
596  delete DF;
597  }
598  }
599 }
600 
601 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
602  assert(AlignPow2 <= 30 && "Invalid bundle alignment");
603  MCAssembler &Assembler = getAssembler();
604  if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 ||
605  Assembler.getBundleAlignSize() == 1U << AlignPow2))
606  Assembler.setBundleAlignSize(1U << AlignPow2);
607  else
608  report_fatal_error(".bundle_align_mode cannot be changed once set");
609 }
610 
611 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
613 
614  // Sanity checks
615  //
616  if (!getAssembler().isBundlingEnabled())
617  report_fatal_error(".bundle_lock forbidden when bundling is disabled");
618 
619  if (!isBundleLocked())
621 
622  if (getAssembler().getRelaxAll() && !isBundleLocked()) {
623  // TODO: drop the lock state and set directly in the fragment
624  MCDataFragment *DF = new MCDataFragment();
625  BundleGroups.push_back(DF);
626  }
627 
630 }
631 
634 
635  // Sanity checks
636  if (!getAssembler().isBundlingEnabled())
637  report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
638  else if (!isBundleLocked())
639  report_fatal_error(".bundle_unlock without matching lock");
640  else if (Sec.isBundleGroupBeforeFirstInst())
641  report_fatal_error("Empty bundle-locked group is forbidden");
642 
643  // When the -mc-relax-all flag is used, we emit instructions to fragments
644  // stored on a stack. When the bundle unlock is emitted, we pop a fragment
645  // from the stack a merge it to the one below.
646  if (getAssembler().getRelaxAll()) {
647  assert(!BundleGroups.empty() && "There are no bundle groups");
648  MCDataFragment *DF = BundleGroups.back();
649 
650  // FIXME: Use BundleGroups to track the lock state instead.
652 
653  // FIXME: Use more separate fragments for nested groups.
654  if (!isBundleLocked()) {
655  mergeFragment(getOrCreateDataFragment(DF->getSubtargetInfo()), DF);
656  BundleGroups.pop_back();
657  delete DF;
658  }
659 
662  } else
664 }
665 
667  // Ensure the last section gets aligned if necessary.
668  MCSection *CurSection = getCurrentSectionOnly();
670 
671  finalizeCGProfile();
672  EmitFrames(nullptr);
673 
675 }
676 
678  llvm_unreachable("Generic ELF doesn't support this directive");
679 }
680 
681 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
682  llvm_unreachable("ELF doesn't support this directive");
683 }
684 
686  uint64_t Size, unsigned ByteAlignment,
687  SMLoc Loc) {
688  llvm_unreachable("ELF doesn't support this directive");
689 }
690 
692  uint64_t Size, unsigned ByteAlignment) {
693  llvm_unreachable("ELF doesn't support this directive");
694 }
695 
697  std::unique_ptr<MCAsmBackend> &&MAB,
698  std::unique_ptr<MCObjectWriter> &&OW,
699  std::unique_ptr<MCCodeEmitter> &&CE,
700  bool RelaxAll) {
701  MCELFStreamer *S =
702  new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
703  if (RelaxAll)
704  S->getAssembler().setRelaxAll(true);
705  return S;
706 }
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count) override
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:293
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
void setUsedInReloc() const
Definition: MCSymbol.h:213
LLVMContext & Context
bool hasInstructions() const
Definition: MCSection.h:141
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:322
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:139
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
.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:42
VariantKind getKind() const
Definition: MCExpr.h:337
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 setAlignment(unsigned Value)
Definition: MCSection.h:122
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:39
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:563
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:510
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
void PushSection()
Save the current and previous section on the section stack.
Definition: MCStreamer.h:362
This is a compact (memory-size-wise) fragment for holding an encoded instruction (non-relaxable) that...
Definition: MCFragment.h:257
F(f)
void EmitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, unsigned ByteAlignment=0, SMLoc L=SMLoc()) override
Emit the zerofill section and an optional symbol.
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
.type _foo, STT_NOTYPE # aka
Definition: MCDirectives.h:28
bool isBundlingEnabled() const
Definition: MCAssembler.h:317
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2)
void EmitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
SMLoc getLoc() const
Definition: MCExpr.h:74
unsigned getBundleAlignSize() const
Definition: MCAssembler.h:319
unsigned getAlignment() const
Definition: MCSection.h:121
MCContext & getContext() const
Definition: MCAssembler.h:278
MCContext & getContext() const
Definition: MCStreamer.h:253
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
Definition: BitVector.h:938
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:288
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:315
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
Definition: MCSymbol.h:252
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
.local (ELF)
Definition: MCDirectives.h:35
.no_dead_strip (MachO)
Definition: MCDirectives.h:36
void flushPendingLabels()
Create a dummy fragment to assign any pending labels.
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:305
Context object for machine code objects.
Definition: MCContext.h:63
void EmitThumbFunc(MCSymbol *Func) override
Note in the output that the specified Func is a Thumb mode function (ARM target only).
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:51
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:566
Streaming object file generation interface.
.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.
.protected (ELF)
Definition: MCDirectives.h:40
void setBundleAlignSize(unsigned Size)
Definition: MCAssembler.h:321
BundleLockStateType getBundleLockState() const
Definition: MCSection.h:130
bool isBundleLocked() const
Definition: MCSection.h:132
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
.lazy_reference (MachO)
Definition: MCDirectives.h:34
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:198
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:112
.reference (MachO)
Definition: MCDirectives.h:41
Unary expressions.
Definition: MCExpr.h:42
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:118
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:271
virtual MCSection * getNonexecutableStackSection(MCContext &Ctx) const
Targets can implement this method to specify a section to switch to if the translation unit doesn&#39;t h...
Definition: MCAsmInfo.h:428
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
.hidden (ELF)
Definition: MCDirectives.h:31
#define P(N)
void EmitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Definition: MCStreamer.cpp:189
Streaming machine code generation interface.
Definition: MCStreamer.h:183
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
.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:46
void insert(MCFragment *F)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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:999
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:129
static void setSectionAlignmentForBundling(const MCAssembler &Assembler, MCSection *Section)
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
MCAssembler & getAssembler()
void setHasInstructions(const MCSubtargetInfo &STI)
Record that the fragment contains instructions with the MCSubtargetInfo in effect when the instructio...
Definition: MCFragment.h:178
void emitELFSymverDirective(StringRef AliasName, const MCSymbol *Aliasee) override
Emit an ELF .symver directive.
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:224
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:220
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:297
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:612
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:50
void EmitFrames(MCAsmBackend *MAB)
.weak_reference (MachO)
Definition: MCDirectives.h:44
Binary assembler expressions.
Definition: MCExpr.h:416
size_t size() const
Definition: SmallVector.h:53
#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.
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition: MCStreamer.h:335
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
Definition: MCStreamer.h:56
BlockVerifier::State From
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F, uint64_t FSize) const
Write the necessary bundle padding to OS.
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:286
const MCSymbol & getSymbol() const
Definition: MCExpr.h:335
ExprKind getKind() const
Definition: MCExpr.h:73
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
static void CheckBundleSubtargets(const MCSubtargetInfo *OldSTI, const MCSubtargetInfo *NewSTI)
.indirect_symbol (MachO)
Definition: MCDirectives.h:32
.type _foo, STT_TLS # aka
Definition: MCDirectives.h:26
MCSymbol * getBeginSymbol()
Definition: MCSection.h:110
void setVariableValue(const MCExpr *Value)
Definition: MCSymbol.cpp:49
MCSymbolAttr
Definition: MCDirectives.h:19
void setBundlePadding(uint8_t N)
Set the padding size for this fragment.
Definition: MCFragment.h:170
uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCEncodedFragment *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&#39;s offset in its section and FSize is the fragment&#39;s size.
Definition: MCFragment.cpp:191
bool getRelaxAll() const
Definition: MCAssembler.h:314
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:340
.syntax (ARM/ELF)
Definition: MCDirectives.h:49
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
Definition: MCFragment.h:174
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:267
.internal (ELF)
Definition: MCDirectives.h:33
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:394
.code32 (X86) / .code 32 (ARM)
Definition: MCDirectives.h:52
.type _foo, STT_COMMON # aka
Definition: MCDirectives.h:27
.code64 (X86)
Definition: MCDirectives.h:53
MCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
std::vector< CGProfileEntry > CGProfile
Definition: MCAssembler.h:427
MCDataFragment * getOrCreateDataFragment(const MCSubtargetInfo *STI=nullptr)
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment...
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
Definition: MCAsmBackend.h:160
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:133
.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
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:28
References to labels and assigned expressions.
Definition: MCExpr.h:41
uint32_t Size
Definition: Profile.cpp:47
bool isBundleGroupBeforeFirstInst() const
Definition: MCSection.h:134
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.
.weak_definition (MachO)
Definition: MCDirectives.h:43
void setBundleGroupBeforeFirstInst(bool IsFirst)
Definition: MCSection.h:137
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
MCFragment * getCurrentFragment() const
void setAlignToBundleEnd(bool V)
Definition: MCFragment.h:159
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
Fragment for data and encoded instructions.
Definition: MCFragment.h:242
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
MCSection * getTextSection() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
.private_extern (MachO)
Definition: MCDirectives.h:39
bool PopSection()
Restore the current and previous section from the section stack.
Definition: MCStreamer.h:371
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:389
LLVM Value Representation.
Definition: Value.h:73
Constant expressions.
Definition: MCExpr.h:40
Binary expressions.
Definition: MCExpr.h:39
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:49
Target specific expression.
Definition: MCExpr.h:43
unsigned getFlags() const
Definition: MCSectionELF.h:75
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:164
std::vector< std::pair< StringRef, const MCSymbol * > > Symvers
Definition: MCAssembler.h:211
#define T1