LLVM  6.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 
42 bool MCELFStreamer::isBundleLocked() const {
44 }
45 
46 void MCELFStreamer::mergeFragment(MCDataFragment *DF,
47  MCDataFragment *EF) {
48  MCAssembler &Assembler = getAssembler();
49 
50  if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
51  uint64_t FSize = EF->getContents().size();
52 
53  if (FSize > Assembler.getBundleAlignSize())
54  report_fatal_error("Fragment can't be larger than a bundle size");
55 
56  uint64_t RequiredBundlePadding = computeBundlePadding(
57  Assembler, EF, DF->getContents().size(), FSize);
58 
59  if (RequiredBundlePadding > UINT8_MAX)
60  report_fatal_error("Padding cannot exceed 255 bytes");
61 
62  if (RequiredBundlePadding > 0) {
64  raw_svector_ostream VecOS(Code);
65  MCObjectWriter *OW = Assembler.getBackend().createObjectWriter(VecOS);
66 
67  EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
68 
69  Assembler.writeFragmentPadding(*EF, FSize, OW);
70  delete OW;
71 
72  DF->getContents().append(Code.begin(), Code.end());
73  }
74  }
75 
76  flushPendingLabels(DF, DF->getContents().size());
77 
78  for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) {
79  EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() +
80  DF->getContents().size());
81  DF->getFixups().push_back(EF->getFixups()[i]);
82  }
83  DF->setHasInstructions(true);
84  DF->getContents().append(EF->getContents().begin(), EF->getContents().end());
85 }
86 
87 void MCELFStreamer::InitSections(bool NoExecStack) {
88  MCContext &Ctx = getContext();
91 
92  if (NoExecStack)
94 }
95 
97  auto *Symbol = cast<MCSymbolELF>(S);
99 
100  const MCSectionELF &Section =
101  static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
102  if (Section.getFlags() & ELF::SHF_TLS)
103  Symbol->setType(ELF::STT_TLS);
104 }
105 
107  auto *Symbol = cast<MCSymbolELF>(S);
109 
110  const MCSectionELF &Section =
111  static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
112  if (Section.getFlags() & ELF::SHF_TLS)
113  Symbol->setType(ELF::STT_TLS);
114 }
115 
117  // Let the target do whatever target specific stuff it needs to do.
119  // Do any generic stuff we need to do.
120  switch (Flag) {
121  case MCAF_SyntaxUnified: return; // no-op here.
122  case MCAF_Code16: return; // Change parsing mode; no-op here.
123  case MCAF_Code32: return; // Change parsing mode; no-op here.
124  case MCAF_Code64: return; // Change parsing mode; no-op here.
127  return;
128  }
129 
130  llvm_unreachable("invalid assembler flag!");
131 }
132 
133 // If bundle alignment is used and there are any instructions in the section, it
134 // needs to be aligned to at least the bundle size.
135 static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
136  MCSection *Section) {
137  if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions() &&
138  Section->getAlignment() < Assembler.getBundleAlignSize())
139  Section->setAlignment(Assembler.getBundleAlignSize());
140 }
141 
143  const MCExpr *Subsection) {
144  MCSection *CurSection = getCurrentSectionOnly();
145  if (CurSection && isBundleLocked())
146  report_fatal_error("Unterminated .bundle_lock when changing a section");
147 
149  // Ensure the previous section gets aligned if necessary.
150  setSectionAlignmentForBundling(Asm, CurSection);
151  auto *SectionELF = static_cast<const MCSectionELF *>(Section);
152  const MCSymbol *Grp = SectionELF->getGroup();
153  if (Grp)
154  Asm.registerSymbol(*Grp);
155 
156  changeSectionImpl(Section, Subsection);
157  Asm.registerSymbol(*Section->getBeginSymbol());
158 }
159 
161  getAssembler().registerSymbol(*Symbol);
164  Alias->setVariableValue(Value);
165 }
166 
167 // When GNU as encounters more than one .type declaration for an object it seems
168 // to use a mechanism similar to the one below to decide which type is actually
169 // used in the object file. The greater of T1 and T2 is selected based on the
170 // following ordering:
171 // STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
172 // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
173 // provided type).
174 static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
177  if (T1 == Type)
178  return T2;
179  if (T2 == Type)
180  return T1;
181  }
182 
183  return T2;
184 }
185 
187  auto *Symbol = cast<MCSymbolELF>(S);
188  // Indirect symbols are handled differently, to match how 'as' handles
189  // them. This makes writing matching .o files easier.
190  if (Attribute == MCSA_IndirectSymbol) {
191  // Note that we intentionally cannot use the symbol data here; this is
192  // important for matching the string table that 'as' generates.
193  IndirectSymbolData ISD;
194  ISD.Symbol = Symbol;
196  getAssembler().getIndirectSymbols().push_back(ISD);
197  return true;
198  }
199 
200  // Adding a symbol attribute always introduces the symbol, note that an
201  // important side effect of calling registerSymbol here is to register
202  // the symbol with the assembler.
204 
205  // The implementation of symbol attributes is designed to match 'as', but it
206  // leaves much to desired. It doesn't really make sense to arbitrarily add and
207  // remove flags, but 'as' allows this (in particular, see .desc).
208  //
209  // In the future it might be worth trying to make these operations more well
210  // defined.
211  switch (Attribute) {
212  case MCSA_LazyReference:
213  case MCSA_Reference:
214  case MCSA_SymbolResolver:
215  case MCSA_PrivateExtern:
216  case MCSA_WeakDefinition:
218  case MCSA_Invalid:
219  case MCSA_IndirectSymbol:
220  return false;
221 
222  case MCSA_NoDeadStrip:
223  // Ignore for now.
224  break;
225 
227  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
228  Symbol->setBinding(ELF::STB_GNU_UNIQUE);
229  Symbol->setExternal(true);
230  break;
231 
232  case MCSA_Global:
233  Symbol->setBinding(ELF::STB_GLOBAL);
234  Symbol->setExternal(true);
235  break;
236 
237  case MCSA_WeakReference:
238  case MCSA_Weak:
239  Symbol->setBinding(ELF::STB_WEAK);
240  Symbol->setExternal(true);
241  break;
242 
243  case MCSA_Local:
244  Symbol->setBinding(ELF::STB_LOCAL);
245  Symbol->setExternal(false);
246  break;
247 
249  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
250  break;
251 
253  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
254  break;
255 
256  case MCSA_ELF_TypeObject:
257  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
258  break;
259 
260  case MCSA_ELF_TypeTLS:
261  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
262  break;
263 
264  case MCSA_ELF_TypeCommon:
265  // TODO: Emit these as a common symbol.
266  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
267  break;
268 
269  case MCSA_ELF_TypeNoType:
270  Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
271  break;
272 
273  case MCSA_Protected:
274  Symbol->setVisibility(ELF::STV_PROTECTED);
275  break;
276 
277  case MCSA_Hidden:
278  Symbol->setVisibility(ELF::STV_HIDDEN);
279  break;
280 
281  case MCSA_Internal:
282  Symbol->setVisibility(ELF::STV_INTERNAL);
283  break;
284 
285  case MCSA_AltEntry:
286  llvm_unreachable("ELF doesn't support the .alt_entry attribute");
287  }
288 
289  return true;
290 }
291 
293  unsigned ByteAlignment) {
294  auto *Symbol = cast<MCSymbolELF>(S);
296 
297  if (!Symbol->isBindingSet()) {
298  Symbol->setBinding(ELF::STB_GLOBAL);
299  Symbol->setExternal(true);
300  }
301 
302  Symbol->setType(ELF::STT_OBJECT);
303 
304  if (Symbol->getBinding() == ELF::STB_LOCAL) {
308  SwitchSection(&Section);
309 
310  EmitValueToAlignment(ByteAlignment, 0, 1, 0);
311  EmitLabel(Symbol);
312  EmitZeros(Size);
313 
314  // Update the maximum alignment of the section if necessary.
315  if (ByteAlignment > Section.getAlignment())
316  Section.setAlignment(ByteAlignment);
317 
318  SwitchSection(P.first, P.second);
319  } else {
320  if(Symbol->declareCommon(Size, ByteAlignment))
321  report_fatal_error("Symbol: " + Symbol->getName() +
322  " redeclared as different type");
323  }
324 
325  cast<MCSymbolELF>(Symbol)
326  ->setSize(MCConstantExpr::create(Size, getContext()));
327 }
328 
330  cast<MCSymbolELF>(Symbol)->setSize(Value);
331 }
332 
334  unsigned ByteAlignment) {
335  auto *Symbol = cast<MCSymbolELF>(S);
336  // FIXME: Should this be caught and done earlier?
338  Symbol->setBinding(ELF::STB_LOCAL);
339  Symbol->setExternal(false);
340  EmitCommonSymbol(Symbol, Size, ByteAlignment);
341 }
342 
344  SMLoc Loc) {
345  if (isBundleLocked())
346  report_fatal_error("Emitting values inside a locked bundle is forbidden");
347  fixSymbolsInTLSFixups(Value);
348  MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
349 }
350 
352  int64_t Value,
353  unsigned ValueSize,
354  unsigned MaxBytesToEmit) {
355  if (isBundleLocked())
356  report_fatal_error("Emitting values inside a locked bundle is forbidden");
357  MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
358  ValueSize, MaxBytesToEmit);
359 }
360 
363  ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
364  PushSection();
365  SwitchSection(Comment);
366  if (!SeenIdent) {
367  EmitIntValue(0, 1);
368  SeenIdent = true;
369  }
370  EmitBytes(IdentString);
371  EmitIntValue(0, 1);
372  PopSection();
373 }
374 
375 void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
376  switch (expr->getKind()) {
377  case MCExpr::Target:
378  cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
379  break;
380  case MCExpr::Constant:
381  break;
382 
383  case MCExpr::Binary: {
384  const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
385  fixSymbolsInTLSFixups(be->getLHS());
386  fixSymbolsInTLSFixups(be->getRHS());
387  break;
388  }
389 
390  case MCExpr::SymbolRef: {
391  const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
392  switch (symRef.getKind()) {
393  default:
394  return;
440  break;
441  }
443  cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
444  break;
445  }
446 
447  case MCExpr::Unary:
448  fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
449  break;
450  }
451 }
452 
453 void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
454  const MCSubtargetInfo &STI) {
455  this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
456  MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
457 
458  for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
459  fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
460 }
461 
462 void MCELFStreamer::EmitInstToData(const MCInst &Inst,
463  const MCSubtargetInfo &STI) {
464  MCAssembler &Assembler = getAssembler();
466  SmallString<256> Code;
467  raw_svector_ostream VecOS(Code);
468  Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
469 
470  for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
471  fixSymbolsInTLSFixups(Fixups[i].getValue());
472 
473  // There are several possibilities here:
474  //
475  // If bundling is disabled, append the encoded instruction to the current data
476  // fragment (or create a new such fragment if the current fragment is not a
477  // data fragment).
478  //
479  // If bundling is enabled:
480  // - If we're not in a bundle-locked group, emit the instruction into a
481  // fragment of its own. If there are no fixups registered for the
482  // instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
483  // MCDataFragment.
484  // - If we're in a bundle-locked group, append the instruction to the current
485  // data fragment because we want all the instructions in a group to get into
486  // the same fragment. Be careful not to do that for the first instruction in
487  // the group, though.
488  MCDataFragment *DF;
489 
490  if (Assembler.isBundlingEnabled()) {
492  if (Assembler.getRelaxAll() && isBundleLocked())
493  // If the -mc-relax-all flag is used and we are bundle-locked, we re-use
494  // the current bundle group.
495  DF = BundleGroups.back();
496  else if (Assembler.getRelaxAll() && !isBundleLocked())
497  // When not in a bundle-locked group and the -mc-relax-all flag is used,
498  // we create a new temporary fragment which will be later merged into
499  // the current fragment.
500  DF = new MCDataFragment();
501  else if (isBundleLocked() && !Sec.isBundleGroupBeforeFirstInst())
502  // If we are bundle-locked, we re-use the current fragment.
503  // The bundle-locking directive ensures this is a new data fragment.
504  DF = cast<MCDataFragment>(getCurrentFragment());
505  else if (!isBundleLocked() && Fixups.size() == 0) {
506  // Optimize memory usage by emitting the instruction to a
507  // MCCompactEncodedInstFragment when not in a bundle-locked group and
508  // there are no fixups registered.
510  insert(CEIF);
511  CEIF->getContents().append(Code.begin(), Code.end());
512  return;
513  } else {
514  DF = new MCDataFragment();
515  insert(DF);
516  }
518  // If this fragment is for a group marked "align_to_end", set a flag
519  // in the fragment. This can happen after the fragment has already been
520  // created if there are nested bundle_align groups and an inner one
521  // is the one marked align_to_end.
522  DF->setAlignToBundleEnd(true);
523  }
524 
525  // We're now emitting an instruction in a bundle group, so this flag has
526  // to be turned off.
528  } else {
530  }
531 
532  // Add the fixups and data.
533  for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
534  Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
535  DF->getFixups().push_back(Fixups[i]);
536  }
537  DF->setHasInstructions(true);
538  DF->getContents().append(Code.begin(), Code.end());
539 
540  if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
541  if (!isBundleLocked()) {
542  mergeFragment(getOrCreateDataFragment(), DF);
543  delete DF;
544  }
545  }
546 }
547 
548 void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
549  assert(AlignPow2 <= 30 && "Invalid bundle alignment");
550  MCAssembler &Assembler = getAssembler();
551  if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 ||
552  Assembler.getBundleAlignSize() == 1U << AlignPow2))
553  Assembler.setBundleAlignSize(1U << AlignPow2);
554  else
555  report_fatal_error(".bundle_align_mode cannot be changed once set");
556 }
557 
558 void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
560 
561  // Sanity checks
562  //
563  if (!getAssembler().isBundlingEnabled())
564  report_fatal_error(".bundle_lock forbidden when bundling is disabled");
565 
566  if (!isBundleLocked())
568 
569  if (getAssembler().getRelaxAll() && !isBundleLocked()) {
570  // TODO: drop the lock state and set directly in the fragment
571  MCDataFragment *DF = new MCDataFragment();
572  BundleGroups.push_back(DF);
573  }
574 
577 }
578 
581 
582  // Sanity checks
583  if (!getAssembler().isBundlingEnabled())
584  report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
585  else if (!isBundleLocked())
586  report_fatal_error(".bundle_unlock without matching lock");
587  else if (Sec.isBundleGroupBeforeFirstInst())
588  report_fatal_error("Empty bundle-locked group is forbidden");
589 
590  // When the -mc-relax-all flag is used, we emit instructions to fragments
591  // stored on a stack. When the bundle unlock is emitted, we pop a fragment
592  // from the stack a merge it to the one below.
593  if (getAssembler().getRelaxAll()) {
594  assert(!BundleGroups.empty() && "There are no bundle groups");
595  MCDataFragment *DF = BundleGroups.back();
596 
597  // FIXME: Use BundleGroups to track the lock state instead.
599 
600  // FIXME: Use more separate fragments for nested groups.
601  if (!isBundleLocked()) {
602  mergeFragment(getOrCreateDataFragment(), DF);
603  BundleGroups.pop_back();
604  delete DF;
605  }
606 
609  } else
611 }
612 
614  // Ensure the last section gets aligned if necessary.
615  MCSection *CurSection = getCurrentSectionOnly();
617 
618  EmitFrames(nullptr);
619 
621 }
622 
624  llvm_unreachable("Generic ELF doesn't support this directive");
625 }
626 
627 void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
628  llvm_unreachable("ELF doesn't support this directive");
629 }
630 
632  uint64_t Size, unsigned ByteAlignment) {
633  llvm_unreachable("ELF doesn't support this directive");
634 }
635 
637  uint64_t Size, unsigned ByteAlignment) {
638  llvm_unreachable("ELF doesn't support this directive");
639 }
640 
643  bool RelaxAll) {
644  MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE);
645  if (RelaxAll)
646  S->getAssembler().setRelaxAll(true);
647  return S;
648 }
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:283
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
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.
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
bool hasInstructions() const
Definition: MCSection.h:137
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:305
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:103
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:320
Not a valid directive.
Definition: MCDirectives.h:20
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
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.
void setAlignment(unsigned Value)
Definition: MCSection.h:118
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:37
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:546
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:331
This is a compact (memory-size-wise) fragment for holding an encoded instruction (non-relaxable) that...
Definition: MCFragment.h:241
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
std::vector< IndirectSymbolData > & getIndirectSymbols()
Definition: MCAssembler.h:334
.type _foo, STT_NOTYPE # aka
Definition: MCDirectives.h:28
bool isBundlingEnabled() const
Definition: MCAssembler.h:290
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.
unsigned getBundleAlignSize() const
Definition: MCAssembler.h:292
unsigned getAlignment() const
Definition: MCSection.h:117
MCContext & getContext() const
Definition: MCAssembler.h:257
MCContext & getContext() const
Definition: MCStreamer.h:227
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:261
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:288
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
ExternalFunctions * EF
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:165
void setAlignToBundleEnd(bool V)
Definition: MCFragment.h:117
.local (ELF)
Definition: MCDirectives.h:35
.no_dead_strip (MachO)
Definition: MCDirectives.h:36
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:278
Context object for machine code objects.
Definition: MCContext.h:59
#define F(x, y, z)
Definition: MD5.cpp:55
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:229
.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:549
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, " "relax all fixups in the emitted object file"))
.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:294
BundleLockStateType getBundleLockState() const
Definition: MCSection.h:126
bool isBundleLocked() const
Definition: MCSection.h:128
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
.lazy_reference (MachO)
Definition: MCDirectives.h:34
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:181
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:93
.reference (MachO)
Definition: MCDirectives.h:41
MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter)
Definition: MCELFStreamer.h:26
Unary expressions.
Definition: MCExpr.h:42
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
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:255
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:414
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:181
Streaming machine code generation interface.
Definition: MCStreamer.h:168
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)
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:860
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:116
static void setSectionAlignmentForBundling(const MCAssembler &Assembler, MCSection *Section)
MCAssembler & getAssembler()
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:22
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:206
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:287
.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:399
#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&#39;s offset in its section and FSize is the fragment&#39;s size.
Definition: MCFragment.cpp:190
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition: MCStreamer.h:304
void writeFragmentPadding(const MCFragment &F, uint64_t FSize, MCObjectWriter *OW) const
Write the necessary bundle padding to the given object writer.
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
Definition: MCStreamer.h:52
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:259
const MCSymbol & getSymbol() const
Definition: MCExpr.h:318
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:864
.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:48
MCSymbolAttr
Definition: MCDirectives.h:19
bool getRelaxAll() const
Definition: MCAssembler.h:287
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.
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:309
.syntax (ARM/ELF)
Definition: MCDirectives.h:49
.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:398
.code32 (X86) / .code 32 (ARM)
Definition: MCDirectives.h:52
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
.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:128
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
Definition: MCAsmBackend.h:128
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:120
.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
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:28
References to labels and assigned expressions.
Definition: MCExpr.h:41
bool isBundleGroupBeforeFirstInst() const
Definition: MCSection.h:130
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:133
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
MCFragment * getCurrentFragment() const
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:224
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:340
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:379
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:35
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:159
#define T1
MCDataFragment * getOrCreateDataFragment()
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment...