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