LLVM  15.0.0git
MCMachOStreamer.cpp
Go to the documentation of this file.
1 //===- MCMachOStreamer.cpp - MachO Streamer -------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ADT/DenseMap.h"
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/ADT/SmallVector.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/MC/MCAsmBackend.h"
14 #include "llvm/MC/MCAssembler.h"
15 #include "llvm/MC/MCCodeEmitter.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCDirectives.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCFixup.h"
20 #include "llvm/MC/MCFragment.h"
24 #include "llvm/MC/MCObjectWriter.h"
25 #include "llvm/MC/MCSection.h"
26 #include "llvm/MC/MCSectionMachO.h"
27 #include "llvm/MC/MCSymbol.h"
28 #include "llvm/MC/MCSymbolMachO.h"
29 #include "llvm/MC/MCValue.h"
30 #include "llvm/MC/SectionKind.h"
31 #include "llvm/MC/TargetRegistry.h"
32 #include "llvm/Support/Casting.h"
35 #include <cassert>
36 #include <vector>
37 
38 namespace llvm {
39 class MCInst;
40 class MCStreamer;
41 class MCSubtargetInfo;
42 class Triple;
43 } // namespace llvm
44 
45 using namespace llvm;
46 
47 namespace {
48 
49 class MCMachOStreamer : public MCObjectStreamer {
50 private:
51  /// LabelSections - true if each section change should emit a linker local
52  /// label for use in relocations for assembler local references. Obviates the
53  /// need for local relocations. False by default.
54  bool LabelSections;
55 
56  bool DWARFMustBeAtTheEnd;
57  bool CreatedADWARFSection;
58 
59  /// HasSectionLabel - map of which sections have already had a non-local
60  /// label emitted to them. Used so we don't emit extraneous linker local
61  /// labels in the middle of the section.
62  DenseMap<const MCSection*, bool> HasSectionLabel;
63 
64  void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) override;
65 
66  void emitDataRegion(DataRegionData::KindTy Kind);
67  void emitDataRegionEnd();
68 
69 public:
70  MCMachOStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
71  std::unique_ptr<MCObjectWriter> OW,
72  std::unique_ptr<MCCodeEmitter> Emitter,
73  bool DWARFMustBeAtTheEnd, bool label)
74  : MCObjectStreamer(Context, std::move(MAB), std::move(OW),
75  std::move(Emitter)),
76  LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd),
77  CreatedADWARFSection(false) {}
78 
79  /// state management
80  void reset() override {
81  CreatedADWARFSection = false;
82  HasSectionLabel.clear();
84  }
85 
86  /// @name MCStreamer Interface
87  /// @{
88 
89  void changeSection(MCSection *Sect, const MCExpr *Subsect) override;
90  void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
91  void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
92  void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
93  void emitAssemblerFlag(MCAssemblerFlag Flag) override;
94  void emitLinkerOptions(ArrayRef<std::string> Options) override;
95  void emitDataRegion(MCDataRegionType Kind) override;
96  void emitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
97  unsigned Update, VersionTuple SDKVersion) override;
98  void emitBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
99  unsigned Update, VersionTuple SDKVersion) override;
100  void emitDarwinTargetVariantBuildVersion(unsigned Platform, unsigned Major,
101  unsigned Minor, unsigned Update,
102  VersionTuple SDKVersion) override;
103  void emitThumbFunc(MCSymbol *Func) override;
104  bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
105  void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
106  void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
107  unsigned ByteAlignment) override;
108 
109  void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
110  unsigned ByteAlignment) override;
111  void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
112  uint64_t Size = 0, unsigned ByteAlignment = 0,
113  SMLoc Loc = SMLoc()) override;
114  void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
115  unsigned ByteAlignment = 0) override;
116 
117  void emitIdent(StringRef IdentString) override {
118  llvm_unreachable("macho doesn't support this directive");
119  }
120 
121  void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override {
122  getAssembler().getLOHContainer().addDirective(Kind, Args);
123  }
124  void emitCGProfileEntry(const MCSymbolRefExpr *From,
125  const MCSymbolRefExpr *To, uint64_t Count) override {
126  if (!From->getSymbol().isTemporary() && !To->getSymbol().isTemporary())
127  getAssembler().CGProfile.push_back({From, To, Count});
128  }
129 
130  void finishImpl() override;
131 
132  void finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE);
133  void finalizeCGProfile();
134  void createAddrSigSection();
135 };
136 
137 } // end anonymous namespace.
138 
139 static bool canGoAfterDWARF(const MCSectionMachO &MSec) {
140  // These sections are created by the assembler itself after the end of
141  // the .s file.
142  StringRef SegName = MSec.getSegmentName();
143  StringRef SecName = MSec.getName();
144 
145  if (SegName == "__LD" && SecName == "__compact_unwind")
146  return true;
147 
148  if (SegName == "__IMPORT") {
149  if (SecName == "__jump_table")
150  return true;
151 
152  if (SecName == "__pointers")
153  return true;
154  }
155 
156  if (SegName == "__TEXT" && SecName == "__eh_frame")
157  return true;
158 
159  if (SegName == "__DATA" && (SecName == "__nl_symbol_ptr" ||
160  SecName == "__thread_ptr"))
161  return true;
162  if (SegName == "__LLVM" && SecName == "__cg_profile")
163  return true;
164  return false;
165 }
166 
167 void MCMachOStreamer::changeSection(MCSection *Section,
168  const MCExpr *Subsection) {
169  // Change the section normally.
170  bool Created = changeSectionImpl(Section, Subsection);
171  const MCSectionMachO &MSec = *cast<MCSectionMachO>(Section);
172  StringRef SegName = MSec.getSegmentName();
173  if (SegName == "__DWARF")
174  CreatedADWARFSection = true;
175  else if (Created && DWARFMustBeAtTheEnd && !canGoAfterDWARF(MSec))
176  assert((!CreatedADWARFSection ||
177  Section == getContext().getObjectFileInfo()->getStackMapSection())
178  && "Creating regular section after DWARF");
179 
180  // Output a linker-local symbol so we don't need section-relative local
181  // relocations. The linker hates us when we do that.
182  if (LabelSections && !HasSectionLabel[Section] &&
183  !Section->getBeginSymbol()) {
184  MCSymbol *Label = getContext().createLinkerPrivateTempSymbol();
185  Section->setBeginSymbol(Label);
186  HasSectionLabel[Section] = true;
187  }
188 }
189 
190 void MCMachOStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
191  MCSymbol *EHSymbol) {
192  getAssembler().registerSymbol(*Symbol);
193  if (Symbol->isExternal())
194  emitSymbolAttribute(EHSymbol, MCSA_Global);
195  if (cast<MCSymbolMachO>(Symbol)->isWeakDefinition())
196  emitSymbolAttribute(EHSymbol, MCSA_WeakDefinition);
197  if (Symbol->isPrivateExtern())
198  emitSymbolAttribute(EHSymbol, MCSA_PrivateExtern);
199 }
200 
201 void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
202  // We have to create a new fragment if this is an atom defining symbol,
203  // fragments cannot span atoms.
204  if (getAssembler().isSymbolLinkerVisible(*Symbol))
205  insert(new MCDataFragment());
206 
208 
209  // This causes the reference type flag to be cleared. Darwin 'as' was "trying"
210  // to clear the weak reference and weak definition bits too, but the
211  // implementation was buggy. For now we just try to match 'as', for
212  // diffability.
213  //
214  // FIXME: Cleanup this code, these bits should be emitted based on semantic
215  // properties, not on the order of definition, etc.
216  cast<MCSymbolMachO>(Symbol)->clearReferenceType();
217 }
218 
219 void MCMachOStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
220  MCValue Res;
221 
222  if (Value->evaluateAsRelocatable(Res, nullptr, nullptr)) {
223  if (const MCSymbolRefExpr *SymAExpr = Res.getSymA()) {
224  const MCSymbol &SymA = SymAExpr->getSymbol();
225  if (!Res.getSymB() && (SymA.getName() == "" || Res.getConstant() != 0))
226  cast<MCSymbolMachO>(Symbol)->setAltEntry();
227  }
228  }
230 }
231 
232 void MCMachOStreamer::emitDataRegion(DataRegionData::KindTy Kind) {
233  // Create a temporary label to mark the start of the data region.
234  MCSymbol *Start = getContext().createTempSymbol();
235  emitLabel(Start);
236  // Record the region for the object writer to use.
237  DataRegionData Data = { Kind, Start, nullptr };
238  std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
239  Regions.push_back(Data);
240 }
241 
242 void MCMachOStreamer::emitDataRegionEnd() {
243  std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
244  assert(!Regions.empty() && "Mismatched .end_data_region!");
245  DataRegionData &Data = Regions.back();
246  assert(!Data.End && "Mismatched .end_data_region!");
247  // Create a temporary label to mark the end of the data region.
248  Data.End = getContext().createTempSymbol();
249  emitLabel(Data.End);
250 }
251 
252 void MCMachOStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
253  // Let the target do whatever target specific stuff it needs to do.
254  getAssembler().getBackend().handleAssemblerFlag(Flag);
255  // Do any generic stuff we need to do.
256  switch (Flag) {
257  case MCAF_SyntaxUnified: return; // no-op here.
258  case MCAF_Code16: return; // Change parsing mode; no-op here.
259  case MCAF_Code32: return; // Change parsing mode; no-op here.
260  case MCAF_Code64: return; // Change parsing mode; no-op here.
262  getAssembler().setSubsectionsViaSymbols(true);
263  return;
264  }
265 }
266 
267 void MCMachOStreamer::emitLinkerOptions(ArrayRef<std::string> Options) {
268  getAssembler().getLinkerOptions().push_back(Options);
269 }
270 
271 void MCMachOStreamer::emitDataRegion(MCDataRegionType Kind) {
272  switch (Kind) {
273  case MCDR_DataRegion:
274  emitDataRegion(DataRegionData::Data);
275  return;
276  case MCDR_DataRegionJT8:
277  emitDataRegion(DataRegionData::JumpTable8);
278  return;
279  case MCDR_DataRegionJT16:
280  emitDataRegion(DataRegionData::JumpTable16);
281  return;
282  case MCDR_DataRegionJT32:
283  emitDataRegion(DataRegionData::JumpTable32);
284  return;
285  case MCDR_DataRegionEnd:
286  emitDataRegionEnd();
287  return;
288  }
289 }
290 
291 void MCMachOStreamer::emitVersionMin(MCVersionMinType Kind, unsigned Major,
292  unsigned Minor, unsigned Update,
293  VersionTuple SDKVersion) {
294  getAssembler().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
295 }
296 
297 void MCMachOStreamer::emitBuildVersion(unsigned Platform, unsigned Major,
298  unsigned Minor, unsigned Update,
299  VersionTuple SDKVersion) {
300  getAssembler().setBuildVersion((MachO::PlatformType)Platform, Major, Minor,
301  Update, SDKVersion);
302 }
303 
304 void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
305  unsigned Platform, unsigned Major, unsigned Minor, unsigned Update,
306  VersionTuple SDKVersion) {
307  getAssembler().setDarwinTargetVariantBuildVersion(
308  (MachO::PlatformType)Platform, Major, Minor, Update, SDKVersion);
309 }
310 
311 void MCMachOStreamer::emitThumbFunc(MCSymbol *Symbol) {
312  // Remember that the function is a thumb function. Fixup and relocation
313  // values will need adjusted.
314  getAssembler().setIsThumbFunc(Symbol);
315  cast<MCSymbolMachO>(Symbol)->setThumbFunc();
316 }
317 
318 bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
320  MCSymbolMachO *Symbol = cast<MCSymbolMachO>(Sym);
321 
322  // Indirect symbols are handled differently, to match how 'as' handles
323  // them. This makes writing matching .o files easier.
325  // Note that we intentionally cannot use the symbol data here; this is
326  // important for matching the string table that 'as' generates.
327  IndirectSymbolData ISD;
328  ISD.Symbol = Symbol;
329  ISD.Section = getCurrentSectionOnly();
330  getAssembler().getIndirectSymbols().push_back(ISD);
331  return true;
332  }
333 
334  // Adding a symbol attribute always introduces the symbol, note that an
335  // important side effect of calling registerSymbol here is to register
336  // the symbol with the assembler.
337  getAssembler().registerSymbol(*Symbol);
338 
339  // The implementation of symbol attributes is designed to match 'as', but it
340  // leaves much to desired. It doesn't really make sense to arbitrarily add and
341  // remove flags, but 'as' allows this (in particular, see .desc).
342  //
343  // In the future it might be worth trying to make these operations more well
344  // defined.
345  switch (Attribute) {
346  case MCSA_Invalid:
349  case MCSA_ELF_TypeObject:
350  case MCSA_ELF_TypeTLS:
351  case MCSA_ELF_TypeCommon:
352  case MCSA_ELF_TypeNoType:
354  case MCSA_Extern:
355  case MCSA_Hidden:
356  case MCSA_IndirectSymbol:
357  case MCSA_Internal:
358  case MCSA_Protected:
359  case MCSA_Weak:
360  case MCSA_Local:
361  case MCSA_LGlobal:
362  case MCSA_Exported:
363  return false;
364 
365  case MCSA_Global:
366  Symbol->setExternal(true);
367  // This effectively clears the undefined lazy bit, in Darwin 'as', although
368  // it isn't very consistent because it implements this as part of symbol
369  // lookup.
370  //
371  // FIXME: Cleanup this code, these bits should be emitted based on semantic
372  // properties, not on the order of definition, etc.
373  Symbol->setReferenceTypeUndefinedLazy(false);
374  break;
375 
376  case MCSA_LazyReference:
377  // FIXME: This requires -dynamic.
378  Symbol->setNoDeadStrip();
379  if (Symbol->isUndefined())
380  Symbol->setReferenceTypeUndefinedLazy(true);
381  break;
382 
383  // Since .reference sets the no dead strip bit, it is equivalent to
384  // .no_dead_strip in practice.
385  case MCSA_Reference:
386  case MCSA_NoDeadStrip:
387  Symbol->setNoDeadStrip();
388  break;
389 
390  case MCSA_SymbolResolver:
391  Symbol->setSymbolResolver();
392  break;
393 
394  case MCSA_AltEntry:
395  Symbol->setAltEntry();
396  break;
397 
398  case MCSA_PrivateExtern:
399  Symbol->setExternal(true);
400  Symbol->setPrivateExtern(true);
401  break;
402 
403  case MCSA_WeakReference:
404  // FIXME: This requires -dynamic.
405  if (Symbol->isUndefined())
406  Symbol->setWeakReference();
407  break;
408 
409  case MCSA_WeakDefinition:
410  // FIXME: 'as' enforces that this is defined and global. The manual claims
411  // it has to be in a coalesced section, but this isn't enforced.
412  Symbol->setWeakDefinition();
413  break;
414 
416  Symbol->setWeakDefinition();
417  Symbol->setWeakReference();
418  break;
419 
420  case MCSA_Cold:
421  Symbol->setCold();
422  break;
423  }
424 
425  return true;
426 }
427 
428 void MCMachOStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
429  // Encode the 'desc' value into the lowest implementation defined bits.
430  getAssembler().registerSymbol(*Symbol);
431  cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
432 }
433 
434 void MCMachOStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
435  unsigned ByteAlignment) {
436  // FIXME: Darwin 'as' does appear to allow redef of a .comm by itself.
437  assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
438 
439  getAssembler().registerSymbol(*Symbol);
440  Symbol->setExternal(true);
441  Symbol->setCommon(Size, ByteAlignment);
442 }
443 
444 void MCMachOStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
445  unsigned ByteAlignment) {
446  // '.lcomm' is equivalent to '.zerofill'.
447  return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
448  Symbol, Size, ByteAlignment);
449 }
450 
451 void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
452  uint64_t Size, unsigned ByteAlignment,
453  SMLoc Loc) {
454  // On darwin all virtual sections have zerofill type. Disallow the usage of
455  // .zerofill in non-virtual functions. If something similar is needed, use
456  // .space or .zero.
457  if (!Section->isVirtualSection()) {
458  getContext().reportError(
459  Loc, "The usage of .zerofill is restricted to sections of "
460  "ZEROFILL type. Use .zero or .space instead.");
461  return; // Early returning here shouldn't harm. EmitZeros should work on any
462  // section.
463  }
464 
465  PushSection();
466  SwitchSection(Section);
467 
468  // The symbol may not be present, which only creates the section.
469  if (Symbol) {
470  emitValueToAlignment(ByteAlignment, 0, 1, 0);
471  emitLabel(Symbol);
472  emitZeros(Size);
473  }
474  PopSection();
475 }
476 
477 // This should always be called with the thread local bss section. Like the
478 // .zerofill directive this doesn't actually switch sections on us.
479 void MCMachOStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
480  uint64_t Size, unsigned ByteAlignment) {
481  emitZerofill(Section, Symbol, Size, ByteAlignment);
482 }
483 
484 void MCMachOStreamer::emitInstToData(const MCInst &Inst,
485  const MCSubtargetInfo &STI) {
486  MCDataFragment *DF = getOrCreateDataFragment();
487 
490  raw_svector_ostream VecOS(Code);
491  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
492 
493  // Add the fixups and data.
494  for (MCFixup &Fixup : Fixups) {
495  Fixup.setOffset(Fixup.getOffset() + DF->getContents().size());
496  DF->getFixups().push_back(Fixup);
497  }
498  DF->setHasInstructions(STI);
499  DF->getContents().append(Code.begin(), Code.end());
500 }
501 
502 void MCMachOStreamer::finishImpl() {
503  emitFrames(&getAssembler().getBackend());
504 
505  // We have to set the fragment atom associations so we can relax properly for
506  // Mach-O.
507 
508  // First, scan the symbol table to build a lookup table from fragments to
509  // defining symbols.
511  for (const MCSymbol &Symbol : getAssembler().symbols()) {
512  if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() &&
513  !Symbol.isVariable()) {
514  // An atom defining symbol should never be internal to a fragment.
515  assert(Symbol.getOffset() == 0 &&
516  "Invalid offset in atom defining symbol!");
517  DefiningSymbolMap[Symbol.getFragment()] = &Symbol;
518  }
519  }
520 
521  // Set the fragment atom associations by tracking the last seen atom defining
522  // symbol.
523  for (MCSection &Sec : getAssembler()) {
524  const MCSymbol *CurrentAtom = nullptr;
525  for (MCFragment &Frag : Sec) {
526  if (const MCSymbol *Symbol = DefiningSymbolMap.lookup(&Frag))
527  CurrentAtom = Symbol;
528  Frag.setAtom(CurrentAtom);
529  }
530  }
531 
532  finalizeCGProfile();
533 
534  createAddrSigSection();
536 }
537 
538 void MCMachOStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE) {
539  const MCSymbol *S = &SRE->getSymbol();
540  bool Created;
541  getAssembler().registerSymbol(*S, &Created);
542  if (Created)
543  S->setExternal(true);
544 }
545 
546 void MCMachOStreamer::finalizeCGProfile() {
547  MCAssembler &Asm = getAssembler();
548  if (Asm.CGProfile.empty())
549  return;
550  for (MCAssembler::CGProfileEntry &E : Asm.CGProfile) {
551  finalizeCGProfileEntry(E.From);
552  finalizeCGProfileEntry(E.To);
553  }
554  // We can't write the section out until symbol indices are finalized which
555  // doesn't happen until after section layout. We need to create the section
556  // and set its size now so that it's accounted for in layout.
557  MCSection *CGProfileSection = Asm.getContext().getMachOSection(
558  "__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
559  Asm.registerSection(*CGProfileSection);
560  auto *Frag = new MCDataFragment(CGProfileSection);
561  // For each entry, reserve space for 2 32-bit indices and a 64-bit count.
562  size_t SectionBytes =
563  Asm.CGProfile.size() * (2 * sizeof(uint32_t) + sizeof(uint64_t));
564  Frag->getContents().resize(SectionBytes);
565 }
566 
568  std::unique_ptr<MCAsmBackend> &&MAB,
569  std::unique_ptr<MCObjectWriter> &&OW,
570  std::unique_ptr<MCCodeEmitter> &&CE,
571  bool RelaxAll, bool DWARFMustBeAtTheEnd,
572  bool LabelSections) {
573  MCMachOStreamer *S =
574  new MCMachOStreamer(Context, std::move(MAB), std::move(OW), std::move(CE),
575  DWARFMustBeAtTheEnd, LabelSections);
576  const Triple &Target = Context.getTargetTriple();
577  S->emitVersionForTarget(
578  Target, Context.getObjectFileInfo()->getSDKVersion(),
579  Context.getObjectFileInfo()->getDarwinTargetVariantTriple(),
580  Context.getObjectFileInfo()->getDarwinTargetVariantSDKVersion());
581  if (RelaxAll)
582  S->getAssembler().setRelaxAll(true);
583  return S;
584 }
585 
586 // Create the AddrSig section and first data fragment here as its layout needs
587 // to be computed immediately after in order for it to be exported correctly.
588 void MCMachOStreamer::createAddrSigSection() {
589  MCAssembler &Asm = getAssembler();
590  MCObjectWriter &writer = Asm.getWriter();
591  if (!writer.getEmitAddrsigSection())
592  return;
593  MCSection *AddrSigSection =
594  Asm.getContext().getObjectFileInfo()->getAddrSigSection();
595  Asm.registerSection(*AddrSigSection);
596  new MCDataFragment(AddrSigSection);
597 }
llvm::DataRegionData::Data
@ Data
Definition: MCAssembler.h:68
llvm::MCVersionMinType
MCVersionMinType
Definition: MCDirectives.h:67
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::MCDataRegionType
MCDataRegionType
Definition: MCDirectives.h:59
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::SectionKind::getMetadata
static SectionKind getMetadata()
Definition: SectionKind.h:188
llvm::MCObjectStreamer::emitLabel
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Definition: MCObjectStreamer.cpp:286
llvm::MCSymbol::isTemporary
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:215
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:74
llvm::Attribute
Definition: Attributes.h:52
llvm::MCLOHType
MCLOHType
Linker Optimization Hint Type.
Definition: MCLinkerOptimizationHint.h:33
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::lookup
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:199
StringRef.h
llvm::MCSA_ELF_TypeObject
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
Definition: MCDirectives.h:25
MCCodeEmitter.h
MCDirectives.h
llvm::MCSA_Invalid
@ MCSA_Invalid
Not a valid directive.
Definition: MCDirectives.h:19
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:140
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::tgtok::Code
@ Code
Definition: TGLexer.h:50
llvm::DataRegionData::JumpTable32
@ JumpTable32
Definition: MCAssembler.h:68
ErrorHandling.h
MCFragment.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
MCAssembler.h
llvm::DataRegionData::JumpTable8
@ JumpTable8
Definition: MCAssembler.h:68
MCObjectFileInfo.h
DenseMap.h
llvm::createMachOStreamer
MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
Definition: MCMachOStreamer.cpp:567
llvm::DataRegionData::KindTy
KindTy
Definition: MCAssembler.h:68
llvm::MCSA_ELF_TypeNoType
@ MCSA_ELF_TypeNoType
.type _foo, STT_NOTYPE # aka @notype
Definition: MCDirectives.h:28
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MCAssemblerFlag
MCAssemblerFlag
Definition: MCDirectives.h:51
llvm::MCObjectStreamer::reset
void reset() override
state management
Definition: MCObjectStreamer.cpp:179
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MCSymbolAttr
MCSymbolAttr
Definition: MCDirectives.h:18
llvm::MCSA_Cold
@ MCSA_Cold
.cold (MachO)
Definition: MCDirectives.h:22
llvm::MCDR_DataRegionJT16
@ MCDR_DataRegionJT16
.data_region jt16
Definition: MCDirectives.h:62
llvm::MCSA_Local
@ MCSA_Local
.local (ELF)
Definition: MCDirectives.h:38
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
llvm::MCSA_NoDeadStrip
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
Definition: MCDirectives.h:39
MCObjectStreamer.h
llvm::MCFragment
Definition: MCFragment.h:30
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:201
llvm::MCDR_DataRegion
@ MCDR_DataRegion
.data_region
Definition: MCDirectives.h:60
MCAsmBackend.h
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
SmallString.h
canGoAfterDWARF
static bool canGoAfterDWARF(const MCSectionMachO &MSec)
Definition: MCMachOStreamer.cpp:139
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MCSA_Extern
@ MCSA_Extern
.extern (XCOFF)
Definition: MCDirectives.h:32
llvm::MCSA_AltEntry
@ MCSA_AltEntry
.alt_entry (MachO)
Definition: MCDirectives.h:41
llvm::MCSA_Protected
@ MCSA_Protected
.protected (ELF)
Definition: MCDirectives.h:43
MCContext.h
MCSectionMachO.h
MCSymbol.h
llvm::MCSA_LazyReference
@ MCSA_LazyReference
.lazy_reference (MachO)
Definition: MCDirectives.h:37
llvm::MCSA_LGlobal
@ MCSA_LGlobal
.lglobl (XCOFF)
Definition: MCDirectives.h:31
llvm::MCAF_Code16
@ MCAF_Code16
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:54
false
Definition: StackSlotColoring.cpp:141
llvm::MCObjectStreamer
Streaming object file generation interface.
Definition: MCObjectStreamer.h:42
llvm::DataRegionData
Definition: MCAssembler.h:65
llvm::MCSA_ELF_TypeIndFunction
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
Definition: MCDirectives.h:24
llvm::AArch64::Fixups
Fixups
Definition: AArch64FixupKinds.h:17
llvm::MCSA_Reference
@ MCSA_Reference
.reference (MachO)
Definition: MCDirectives.h:44
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:147
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
llvm::MachO::PlatformType
PlatformType
Definition: MachO.h:492
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:399
llvm::MCValue::getConstant
int64_t getConstant() const
Definition: MCValue.h:43
llvm::VersionTuple
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:31
llvm::MCSA_Hidden
@ MCSA_Hidden
.hidden (ELF)
Definition: MCDirectives.h:33
llvm::MCSymbol::getName
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:198
llvm::MCValue::getSymA
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:44
llvm::MCSA_ELF_TypeGnuUniqueObject
@ MCSA_ELF_TypeGnuUniqueObject
Definition: MCDirectives.h:29
llvm::MCObjectStreamer::emitAssignment
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
Definition: MCObjectStreamer.cpp:387
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
DF
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
llvm::SmallString< 256 >
llvm::MCSA_Exported
@ MCSA_Exported
.globl _foo, exported (XCOFF)
Definition: MCDirectives.h:34
llvm::MCDR_DataRegionJT32
@ MCDR_DataRegionJT32
.data_region jt32
Definition: MCDirectives.h:63
llvm::MCSA_WeakDefAutoPrivate
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
Definition: MCDirectives.h:48
llvm::IndirectSymbolData::Symbol
MCSymbol * Symbol
Definition: MCAssembler.h:59
llvm::MCAssembler
Definition: MCAssembler.h:73
llvm::MCAF_SubsectionsViaSymbols
@ MCAF_SubsectionsViaSymbols
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:53
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::clear
void clear()
Definition: DenseMap.h:112
uint64_t
llvm::MCSA_WeakReference
@ MCSA_WeakReference
.weak_reference (MachO)
Definition: MCDirectives.h:47
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
symbols
Itanium Name Demangler i e convert the string _Z1fv into and both[sub] projects need to demangle symbols
Definition: README.txt:20
llvm::DenseMap
Definition: DenseMap.h:716
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1665
MCSymbolMachO.h
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
MCSection.h
llvm::ArrayRef< std::string >
llvm::IndirectSymbolData
Definition: MCAssembler.h:58
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:233
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
uint32_t
MCFixup.h
llvm::MCObjectWriter
Defines the object file and target independent interfaces used by the assembler backend to write nati...
Definition: MCObjectWriter.h:34
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCSA_ELF_TypeTLS
@ MCSA_ELF_TypeTLS
.type _foo, STT_TLS # aka @tls_object
Definition: MCDirectives.h:26
llvm::MCSA_IndirectSymbol
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
Definition: MCDirectives.h:35
writer
we should consider alternate ways to model stack dependencies Lots of things could be done in WebAssemblyTargetTransformInfo cpp there are numerous optimization related hooks that can be overridden in WebAssemblyTargetLowering Instead of the OptimizeReturned which should consider preserving the returned attribute through to MachineInstrs and extending the MemIntrinsicResults pass to do this optimization on calls too That would also let the WebAssemblyPeephole pass clean up dead defs for such as it does for stores Consider implementing and or getMachineCombinerPatterns Find a clean way to fix the problem which leads to the Shrink Wrapping pass being run after the WebAssembly PEI pass When setting multiple variables to the same we currently get code like const It could be done with a smaller encoding like local tee $pop5 local $pop6 WebAssembly registers are implicitly initialized to zero Explicit zeroing is therefore often redundant and could be optimized away Small indices may use smaller encodings than large indices WebAssemblyRegColoring and or WebAssemblyRegRenumbering should sort registers according to their usage frequency to maximize the usage of smaller encodings Many cases of irreducible control flow could be transformed more optimally than via the transform in WebAssemblyFixIrreducibleControlFlow cpp It may also be worthwhile to do transforms before register particularly when duplicating to allow register coloring to be aware of the duplication WebAssemblyRegStackify could use AliasAnalysis to reorder loads and stores more aggressively WebAssemblyRegStackify is currently a greedy algorithm This means for a binary however wasm doesn t actually require this WebAssemblyRegStackify could be or possibly to take full advantage of what WebAssembly permits Add support for mergeable sections in the Wasm writer
Definition: README.txt:154
llvm::MCSA_Internal
@ MCSA_Internal
.internal (ELF)
Definition: MCDirectives.h:36
llvm::MCSection::getName
StringRef getName() const
Definition: MCSection.h:123
llvm::MCAF_Code32
@ MCAF_Code32
.code32 (X86) / .code 32 (ARM)
Definition: MCDirectives.h:55
llvm::MCSA_ELF_TypeCommon
@ MCSA_ELF_TypeCommon
.type _foo, STT_COMMON # aka @common
Definition: MCDirectives.h:27
llvm::DataRegionData::JumpTable16
@ JumpTable16
Definition: MCAssembler.h:68
llvm::MCAF_Code64
@ MCAF_Code64
.code64 (X86)
Definition: MCDirectives.h:56
MCObjectWriter.h
llvm::MCAF_SyntaxUnified
@ MCAF_SyntaxUnified
.syntax (ARM/ELF)
Definition: MCDirectives.h:52
llvm::pdb::PDB_SymType::Label
@ Label
std
Definition: BitVector.h:851
llvm::MCSA_SymbolResolver
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
Definition: MCDirectives.h:40
llvm::MCSectionMachO
This represents a section on a Mach-O system (used by Mac OS X).
Definition: MCSectionMachO.h:24
Casting.h
llvm::MCSectionMachO::getSegmentName
StringRef getSegmentName() const
Definition: MCSectionMachO.h:40
llvm::MCSA_Global
@ MCSA_Global
.type _foo, @gnu_unique_object
Definition: MCDirectives.h:30
MCValue.h
llvm::MCSA_WeakDefinition
@ MCSA_WeakDefinition
.weak_definition (MachO)
Definition: MCDirectives.h:46
llvm::LCOMM::ByteAlignment
@ ByteAlignment
Definition: MCAsmInfo.h:50
SectionKind.h
llvm::MCSA_ELF_TypeFunction
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
Definition: MCDirectives.h:23
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
MCLinkerOptimizationHint.h
llvm::MCSA_Weak
@ MCSA_Weak
.weak
Definition: MCDirectives.h:45
llvm::MCDR_DataRegionJT8
@ MCDR_DataRegionJT8
.data_region jt8
Definition: MCDirectives.h:61
SmallVector.h
llvm::IndirectSymbolData::Section
MCSection * Section
Definition: MCAssembler.h:60
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:662
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::MCSA_PrivateExtern
@ MCSA_PrivateExtern
.private_extern (MachO)
Definition: MCDirectives.h:42
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:36
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::MCSymbolMachO
Definition: MCSymbolMachO.h:15
llvm::MCObjectStreamer::finishImpl
void finishImpl() override
Streamer specific finalization.
Definition: MCObjectStreamer.cpp:918
raw_ostream.h
llvm::MCDataFragment
Fragment for data and encoded instructions.
Definition: MCFragment.h:241
llvm::MCDR_DataRegionEnd
@ MCDR_DataRegionEnd
.end_data_region
Definition: MCDirectives.h:64
TargetRegistry.h
MCExpr.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::MCValue::getSymB
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:45
llvm::MCAssembler::CGProfileEntry
Definition: MCAssembler.h:465