LLVM 19.0.0git
MCContext.cpp
Go to the documentation of this file.
1//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
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/MC/MCContext.h"
12#include "llvm/ADT/StringMap.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/ADT/Twine.h"
19#include "llvm/MC/MCAsmInfo.h"
20#include "llvm/MC/MCCodeView.h"
21#include "llvm/MC/MCDwarf.h"
22#include "llvm/MC/MCExpr.h"
23#include "llvm/MC/MCFragment.h"
24#include "llvm/MC/MCInst.h"
25#include "llvm/MC/MCLabel.h"
34#include "llvm/MC/MCStreamer.h"
36#include "llvm/MC/MCSymbol.h"
38#include "llvm/MC/MCSymbolELF.h"
44#include "llvm/MC/SectionKind.h"
49#include "llvm/Support/Path.h"
50#include "llvm/Support/SMLoc.h"
53#include <cassert>
54#include <cstdlib>
55#include <optional>
56#include <tuple>
57#include <utility>
58
59using namespace llvm;
60
61static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &,
62 std::vector<const MDNode *> &) {
63 SMD.print(nullptr, errs());
64}
65
66MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai,
67 const MCRegisterInfo *mri, const MCSubtargetInfo *msti,
68 const SourceMgr *mgr, MCTargetOptions const *TargetOpts,
69 bool DoAutoReset, StringRef Swift5ReflSegmentName)
70 : Swift5ReflectionSegmentName(Swift5ReflSegmentName), TT(TheTriple),
71 SrcMgr(mgr), InlineSrcMgr(nullptr), DiagHandler(defaultDiagHandler),
72 MAI(mai), MRI(mri), MSTI(msti), Symbols(Allocator), UsedNames(Allocator),
73 InlineAsmUsedLabelNames(Allocator),
74 CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
75 AutoReset(DoAutoReset), TargetOptions(TargetOpts) {
76 SecureLogFile = TargetOptions ? TargetOptions->AsSecureLogFile : "";
77
78 if (SrcMgr && SrcMgr->getNumBuffers())
79 MainFileName = std::string(SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())
81
82 switch (TheTriple.getObjectFormat()) {
83 case Triple::MachO:
84 Env = IsMachO;
85 break;
86 case Triple::COFF:
87 if (!TheTriple.isOSWindows() && !TheTriple.isUEFI())
89 "Cannot initialize MC for non-Windows COFF object files.");
90
91 Env = IsCOFF;
92 break;
93 case Triple::ELF:
94 Env = IsELF;
95 break;
96 case Triple::Wasm:
97 Env = IsWasm;
98 break;
99 case Triple::XCOFF:
100 Env = IsXCOFF;
101 break;
102 case Triple::GOFF:
103 Env = IsGOFF;
104 break;
106 Env = IsDXContainer;
107 break;
108 case Triple::SPIRV:
109 Env = IsSPIRV;
110 break;
112 report_fatal_error("Cannot initialize MC for unknown object file format.");
113 break;
114 }
115}
116
118 if (AutoReset)
119 reset();
120
121 // NOTE: The symbols are all allocated out of a bump pointer allocator,
122 // we don't need to free them here.
123}
124
126 if (!InlineSrcMgr)
127 InlineSrcMgr.reset(new SourceMgr());
128}
129
130//===----------------------------------------------------------------------===//
131// Module Lifetime Management
132//===----------------------------------------------------------------------===//
133
135 SrcMgr = nullptr;
136 InlineSrcMgr.reset();
137 LocInfos.clear();
138 DiagHandler = defaultDiagHandler;
139
140 // Call the destructors so the fragments are freed
141 COFFAllocator.DestroyAll();
142 DXCAllocator.DestroyAll();
143 ELFAllocator.DestroyAll();
144 GOFFAllocator.DestroyAll();
145 MachOAllocator.DestroyAll();
146 WasmAllocator.DestroyAll();
147 XCOFFAllocator.DestroyAll();
148 MCInstAllocator.DestroyAll();
149 SPIRVAllocator.DestroyAll();
150 WasmSignatureAllocator.DestroyAll();
151
152 MCSubtargetAllocator.DestroyAll();
153 InlineAsmUsedLabelNames.clear();
154 UsedNames.clear();
155 Symbols.clear();
156 Allocator.Reset();
157 Instances.clear();
158 CompilationDir.clear();
159 MainFileName.clear();
160 MCDwarfLineTablesCUMap.clear();
161 SectionsForRanges.clear();
162 MCGenDwarfLabelEntries.clear();
163 DwarfDebugFlags = StringRef();
164 DwarfCompileUnitID = 0;
165 CurrentDwarfLoc = MCDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0);
166
167 CVContext.reset();
168
169 MachOUniquingMap.clear();
170 ELFUniquingMap.clear();
171 GOFFUniquingMap.clear();
172 COFFUniquingMap.clear();
173 WasmUniquingMap.clear();
174 XCOFFUniquingMap.clear();
175 DXCUniquingMap.clear();
176
177 ELFEntrySizeMap.clear();
178 ELFSeenGenericMergeableSections.clear();
179
180 NextID.clear();
181 AllowTemporaryLabels = true;
182 DwarfLocSeen = false;
183 GenDwarfForAssembly = false;
184 GenDwarfFileNumber = 0;
185
186 HadError = false;
187}
188
189//===----------------------------------------------------------------------===//
190// MCInst Management
191//===----------------------------------------------------------------------===//
192
194 return new (MCInstAllocator.Allocate()) MCInst;
195}
196
197//===----------------------------------------------------------------------===//
198// Symbol Manipulation
199//===----------------------------------------------------------------------===//
200
202 SmallString<128> NameSV;
203 StringRef NameRef = Name.toStringRef(NameSV);
204
205 assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
206
207 MCSymbol *&Sym = Symbols[NameRef];
208 if (!Sym)
209 Sym = createSymbol(NameRef, false, false);
210
211 return Sym;
212}
213
215 unsigned Idx) {
216 return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + FuncName +
217 "$frame_escape_" + Twine(Idx));
218}
219
221 return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + FuncName +
222 "$parent_frame_offset");
223}
224
226 return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + "__ehtable$" +
227 FuncName);
228}
229
230MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
231 bool IsTemporary) {
232 static_assert(std::is_trivially_destructible<MCSymbolCOFF>(),
233 "MCSymbol classes must be trivially destructible");
234 static_assert(std::is_trivially_destructible<MCSymbolELF>(),
235 "MCSymbol classes must be trivially destructible");
236 static_assert(std::is_trivially_destructible<MCSymbolMachO>(),
237 "MCSymbol classes must be trivially destructible");
238 static_assert(std::is_trivially_destructible<MCSymbolWasm>(),
239 "MCSymbol classes must be trivially destructible");
240 static_assert(std::is_trivially_destructible<MCSymbolXCOFF>(),
241 "MCSymbol classes must be trivially destructible");
242
243 switch (getObjectFileType()) {
245 return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
246 case MCContext::IsELF:
247 return new (Name, *this) MCSymbolELF(Name, IsTemporary);
249 return new (Name, *this) MCSymbolGOFF(Name, IsTemporary);
251 return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
253 return new (Name, *this) MCSymbolWasm(Name, IsTemporary);
255 return createXCOFFSymbolImpl(Name, IsTemporary);
257 break;
259 return new (Name, *this)
261 }
262 return new (Name, *this)
264}
265
266MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
267 bool CanBeUnnamed) {
268 if (CanBeUnnamed && !UseNamesOnTempLabels)
269 return createSymbolImpl(nullptr, true);
270
271 // Determine whether this is a user written assembler temporary or normal
272 // label, if used.
273 bool IsTemporary = CanBeUnnamed;
274 if (AllowTemporaryLabels && !IsTemporary)
275 IsTemporary = Name.starts_with(MAI->getPrivateGlobalPrefix());
276
277 SmallString<128> NewName = Name;
278 bool AddSuffix = AlwaysAddSuffix;
279 unsigned &NextUniqueID = NextID[Name];
280 while (true) {
281 if (AddSuffix) {
282 NewName.resize(Name.size());
283 raw_svector_ostream(NewName) << NextUniqueID++;
284 }
285 auto NameEntry = UsedNames.insert(std::make_pair(NewName.str(), true));
286 if (NameEntry.second || !NameEntry.first->second) {
287 // Ok, we found a name.
288 // Mark it as used for a non-section symbol.
289 NameEntry.first->second = true;
290 // Have the MCSymbol object itself refer to the copy of the string that is
291 // embedded in the UsedNames entry.
292 return createSymbolImpl(&*NameEntry.first, IsTemporary);
293 }
294 assert(IsTemporary && "Cannot rename non-temporary symbols");
295 AddSuffix = true;
296 }
297 llvm_unreachable("Infinite loop");
298}
299
300MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) {
301 SmallString<128> NameSV;
303 return createSymbol(NameSV, AlwaysAddSuffix, true);
304}
305
307 SmallString<128> NameSV;
309 return createSymbol(NameSV, true, false);
310}
311
313 return createLinkerPrivateSymbol("tmp");
314}
315
317 SmallString<128> NameSV;
319 return createSymbol(NameSV, true, false);
320}
321
323
325 return createNamedTempSymbol("tmp");
326}
327
328unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
329 MCLabel *&Label = Instances[LocalLabelVal];
330 if (!Label)
331 Label = new (*this) MCLabel(0);
332 return Label->incInstance();
333}
334
335unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
336 MCLabel *&Label = Instances[LocalLabelVal];
337 if (!Label)
338 Label = new (*this) MCLabel(0);
339 return Label->getInstance();
340}
341
342MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
343 unsigned Instance) {
344 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
345 if (!Sym)
347 return Sym;
348}
349
351 unsigned Instance = NextInstance(LocalLabelVal);
352 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
353}
354
356 bool Before) {
357 unsigned Instance = GetInstance(LocalLabelVal);
358 if (!Before)
359 ++Instance;
360 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
361}
362
364 SmallString<128> NameSV;
365 StringRef NameRef = Name.toStringRef(NameSV);
366 return Symbols.lookup(NameRef);
367}
368
370 uint64_t Val) {
371 auto Symbol = getOrCreateSymbol(Sym);
372 Streamer.emitAssignment(Symbol, MCConstantExpr::create(Val, *this));
373}
374
376 InlineAsmUsedLabelNames[Sym->getName()] = Sym;
377}
378
380 return new (WasmSignatureAllocator.Allocate()) wasm::WasmSignature;
381}
382
384MCContext::createXCOFFSymbolImpl(const StringMapEntry<bool> *Name,
385 bool IsTemporary) {
386 if (!Name)
387 return new (nullptr, *this) MCSymbolXCOFF(nullptr, IsTemporary);
388
389 StringRef OriginalName = Name->first();
390 if (OriginalName.starts_with("._Renamed..") ||
391 OriginalName.starts_with("_Renamed.."))
392 reportError(SMLoc(), "invalid symbol name from source");
393
394 if (MAI->isValidUnquotedName(OriginalName))
395 return new (Name, *this) MCSymbolXCOFF(Name, IsTemporary);
396
397 // Now we have a name that contains invalid character(s) for XCOFF symbol.
398 // Let's replace with something valid, but save the original name so that
399 // we could still use the original name in the symbol table.
400 SmallString<128> InvalidName(OriginalName);
401
402 // If it's an entry point symbol, we will keep the '.'
403 // in front for the convention purpose. Otherwise, add "_Renamed.."
404 // as prefix to signal this is an renamed symbol.
405 const bool IsEntryPoint = InvalidName.starts_with(".");
406 SmallString<128> ValidName =
407 StringRef(IsEntryPoint ? "._Renamed.." : "_Renamed..");
408
409 // Append the hex values of '_' and invalid characters with "_Renamed..";
410 // at the same time replace invalid characters with '_'.
411 for (size_t I = 0; I < InvalidName.size(); ++I) {
412 if (!MAI->isAcceptableChar(InvalidName[I]) || InvalidName[I] == '_') {
413 raw_svector_ostream(ValidName).write_hex(InvalidName[I]);
414 InvalidName[I] = '_';
415 }
416 }
417
418 // Skip entry point symbol's '.' as we already have a '.' in front of
419 // "_Renamed".
420 if (IsEntryPoint)
421 ValidName.append(InvalidName.substr(1, InvalidName.size() - 1));
422 else
423 ValidName.append(InvalidName);
424
425 auto NameEntry = UsedNames.insert(std::make_pair(ValidName.str(), true));
426 assert((NameEntry.second || !NameEntry.first->second) &&
427 "This name is used somewhere else.");
428 // Mark the name as used for a non-section symbol.
429 NameEntry.first->second = true;
430 // Have the MCSymbol object itself refer to the copy of the string
431 // that is embedded in the UsedNames entry.
432 MCSymbolXCOFF *XSym = new (&*NameEntry.first, *this)
433 MCSymbolXCOFF(&*NameEntry.first, IsTemporary);
435 return XSym;
436}
437
438//===----------------------------------------------------------------------===//
439// Section Management
440//===----------------------------------------------------------------------===//
441
443 unsigned TypeAndAttributes,
444 unsigned Reserved2, SectionKind Kind,
445 const char *BeginSymName) {
446 // We unique sections by their segment/section pair. The returned section
447 // may not have the same flags as the requested section, if so this should be
448 // diagnosed by the client as an error.
449
450 // Form the name to look up.
451 assert(Section.size() <= 16 && "section name is too long");
452 assert(!memchr(Section.data(), '\0', Section.size()) &&
453 "section name cannot contain NUL");
454
455 // Do the lookup, if we have a hit, return it.
456 auto R = MachOUniquingMap.try_emplace((Segment + Twine(',') + Section).str());
457 if (!R.second)
458 return R.first->second;
459
460 MCSymbol *Begin = nullptr;
461 if (BeginSymName)
462 Begin = createTempSymbol(BeginSymName, false);
463
464 // Otherwise, return a new section.
465 StringRef Name = R.first->first();
466 R.first->second = new (MachOAllocator.Allocate())
467 MCSectionMachO(Segment, Name.substr(Name.size() - Section.size()),
468 TypeAndAttributes, Reserved2, Kind, Begin);
469 return R.first->second;
470}
471
472MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
473 unsigned Flags, SectionKind K,
474 unsigned EntrySize,
475 const MCSymbolELF *Group,
476 bool Comdat, unsigned UniqueID,
477 const MCSymbolELF *LinkedToSym) {
478 MCSymbolELF *R;
479 MCSymbol *&Sym = Symbols[Section];
480 // A section symbol can not redefine regular symbols. There may be multiple
481 // sections with the same name, in which case the first such section wins.
482 if (Sym && Sym->isDefined() &&
483 (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
484 reportError(SMLoc(), "invalid symbol redefinition");
485 if (Sym && Sym->isUndefined()) {
486 R = cast<MCSymbolELF>(Sym);
487 } else {
488 auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first;
489 R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
490 if (!Sym)
491 Sym = R;
492 }
493 R->setBinding(ELF::STB_LOCAL);
494 R->setType(ELF::STT_SECTION);
495
496 auto *Ret = new (ELFAllocator.Allocate())
497 MCSectionELF(Section, Type, Flags, K, EntrySize, Group, Comdat, UniqueID,
498 R, LinkedToSym);
499
500 auto *F = new MCDataFragment();
501 Ret->getFragmentList().insert(Ret->begin(), F);
502 F->setParent(Ret);
503 R->setFragment(F);
504
505 return Ret;
506}
507
509MCContext::createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags,
510 unsigned EntrySize, const MCSymbolELF *Group,
511 const MCSectionELF *RelInfoSection) {
513 bool Inserted;
514 std::tie(I, Inserted) = RelSecNames.insert(std::make_pair(Name.str(), true));
515
516 return createELFSectionImpl(
517 I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
518 true, true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
519}
520
522 const Twine &Suffix, unsigned Type,
523 unsigned Flags,
524 unsigned EntrySize) {
525 return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix,
526 /*IsComdat=*/true);
527}
528
530 unsigned Flags, unsigned EntrySize,
531 const Twine &Group, bool IsComdat,
532 unsigned UniqueID,
533 const MCSymbolELF *LinkedToSym) {
534 MCSymbolELF *GroupSym = nullptr;
535 if (!Group.isTriviallyEmpty() && !Group.str().empty())
536 GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
537
538 return getELFSection(Section, Type, Flags, EntrySize, GroupSym, IsComdat,
539 UniqueID, LinkedToSym);
540}
541
543 unsigned Flags, unsigned EntrySize,
544 const MCSymbolELF *GroupSym,
545 bool IsComdat, unsigned UniqueID,
546 const MCSymbolELF *LinkedToSym) {
547 StringRef Group = "";
548 if (GroupSym)
549 Group = GroupSym->getName();
550 assert(!(LinkedToSym && LinkedToSym->getName().empty()));
551 // Do the lookup, if we have a hit, return it.
552 auto IterBool = ELFUniquingMap.insert(std::make_pair(
553 ELFSectionKey{Section.str(), Group,
554 LinkedToSym ? LinkedToSym->getName() : "", UniqueID},
555 nullptr));
556 auto &Entry = *IterBool.first;
557 if (!IterBool.second)
558 return Entry.second;
559
560 StringRef CachedName = Entry.first.SectionName;
561
562 SectionKind Kind;
563 if (Flags & ELF::SHF_ARM_PURECODE)
565 else if (Flags & ELF::SHF_EXECINSTR)
566 Kind = SectionKind::getText();
567 else if (~Flags & ELF::SHF_WRITE)
569 else if (Flags & ELF::SHF_TLS)
572 else
573 // Default to `SectionKind::getText()`. This is the default for gas as
574 // well. The condition that falls into this case is where we do not have any
575 // section flags and must infer a classification rather than where we have
576 // section flags (i.e. this is not that SHF_EXECINSTR is unset bur rather it
577 // is unknown).
578 Kind = llvm::StringSwitch<SectionKind>(CachedName)
579 .Case(".bss", SectionKind::getBSS())
581 .StartsWith(".gnu.linkonce.b.", SectionKind::getBSS())
582 .StartsWith(".llvm.linkonce.b.", SectionKind::getBSS())
583 .Case(".data", SectionKind::getData())
584 .Case(".data1", SectionKind::getData())
585 .Case(".data.rel.ro", SectionKind::getReadOnlyWithRel())
586 .StartsWith(".data.", SectionKind::getData())
587 .Case(".rodata", SectionKind::getReadOnly())
588 .Case(".rodata1", SectionKind::getReadOnly())
592 .StartsWith(".gnu.linkonce.tb.", SectionKind::getThreadData())
593 .StartsWith(".llvm.linkonce.tb.", SectionKind::getThreadData())
594 .Case(".tdata", SectionKind::getThreadData())
596 .StartsWith(".gnu.linkonce.td.", SectionKind::getThreadData())
597 .StartsWith(".llvm.linkonce.td.", SectionKind::getThreadData())
600
601 MCSectionELF *Result =
602 createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
603 IsComdat, UniqueID, LinkedToSym);
604 Entry.second = Result;
605
606 recordELFMergeableSectionInfo(Result->getName(), Result->getFlags(),
607 Result->getUniqueID(), Result->getEntrySize());
608
609 return Result;
610}
611
613 bool IsComdat) {
614 return createELFSectionImpl(".group", ELF::SHT_GROUP, 0,
615 SectionKind::getReadOnly(), 4, Group, IsComdat,
616 MCSection::NonUniqueID, nullptr);
617}
618
620 unsigned Flags, unsigned UniqueID,
621 unsigned EntrySize) {
622 bool IsMergeable = Flags & ELF::SHF_MERGE;
623 if (UniqueID == GenericSectionID) {
624 ELFSeenGenericMergeableSections.insert(SectionName);
625 // Minor performance optimization: avoid hash map lookup in
626 // isELFGenericMergeableSection, which will return true for SectionName.
627 IsMergeable = true;
628 }
629
630 // For mergeable sections or non-mergeable sections with a generic mergeable
631 // section name we enter their Unique ID into the ELFEntrySizeMap so that
632 // compatible globals can be assigned to the same section.
633
634 if (IsMergeable || isELFGenericMergeableSection(SectionName)) {
635 ELFEntrySizeMap.insert(std::make_pair(
636 std::make_tuple(SectionName, Flags, EntrySize), UniqueID));
637 }
638}
639
641 return SectionName.starts_with(".rodata.str") ||
642 SectionName.starts_with(".rodata.cst");
643}
644
647 ELFSeenGenericMergeableSections.count(SectionName);
648}
649
650std::optional<unsigned>
652 unsigned EntrySize) {
653 auto I = ELFEntrySizeMap.find(std::make_tuple(SectionName, Flags, EntrySize));
654 return (I != ELFEntrySizeMap.end()) ? std::optional<unsigned>(I->second)
655 : std::nullopt;
656}
657
659 MCSection *Parent,
660 const MCExpr *SubsectionId) {
661 // Do the lookup. If we don't have a hit, return a new section.
662 auto IterBool =
663 GOFFUniquingMap.insert(std::make_pair(Section.str(), nullptr));
664 auto Iter = IterBool.first;
665 if (!IterBool.second)
666 return Iter->second;
667
668 StringRef CachedName = Iter->first;
669 MCSectionGOFF *GOFFSection = new (GOFFAllocator.Allocate())
670 MCSectionGOFF(CachedName, Kind, Parent, SubsectionId);
671 Iter->second = GOFFSection;
672
673 return GOFFSection;
674}
675
677 unsigned Characteristics,
678 SectionKind Kind,
679 StringRef COMDATSymName, int Selection,
680 unsigned UniqueID,
681 const char *BeginSymName) {
682 MCSymbol *COMDATSymbol = nullptr;
683 if (!COMDATSymName.empty()) {
684 COMDATSymbol = getOrCreateSymbol(COMDATSymName);
685 COMDATSymName = COMDATSymbol->getName();
686 }
687
688 // Do the lookup, if we have a hit, return it.
689 COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
690 auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
691 auto Iter = IterBool.first;
692 if (!IterBool.second)
693 return Iter->second;
694
695 MCSymbol *Begin = nullptr;
696 if (BeginSymName)
697 Begin = createTempSymbol(BeginSymName, false);
698
699 StringRef CachedName = Iter->first.SectionName;
700 MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
701 CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
702
703 Iter->second = Result;
704 return Result;
705}
706
708 unsigned Characteristics,
709 SectionKind Kind,
710 const char *BeginSymName) {
711 return getCOFFSection(Section, Characteristics, Kind, "", 0, GenericSectionID,
712 BeginSymName);
713}
714
716 const MCSymbol *KeySym,
717 unsigned UniqueID) {
718 // Return the normal section if we don't have to be associative or unique.
719 if (!KeySym && UniqueID == GenericSectionID)
720 return Sec;
721
722 // If we have a key symbol, make an associative section with the same name and
723 // kind as the normal section.
724 unsigned Characteristics = Sec->getCharacteristics();
725 if (KeySym) {
727 return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(),
728 KeySym->getName(),
730 }
731
732 return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(), "", 0,
733 UniqueID);
734}
735
737 unsigned Flags, const Twine &Group,
738 unsigned UniqueID,
739 const char *BeginSymName) {
740 MCSymbolWasm *GroupSym = nullptr;
741 if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
742 GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
743 GroupSym->setComdat(true);
744 }
745
746 return getWasmSection(Section, K, Flags, GroupSym, UniqueID, BeginSymName);
747}
748
750 unsigned Flags,
751 const MCSymbolWasm *GroupSym,
752 unsigned UniqueID,
753 const char *BeginSymName) {
754 StringRef Group = "";
755 if (GroupSym)
756 Group = GroupSym->getName();
757 // Do the lookup, if we have a hit, return it.
758 auto IterBool = WasmUniquingMap.insert(
759 std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr));
760 auto &Entry = *IterBool.first;
761 if (!IterBool.second)
762 return Entry.second;
763
764 StringRef CachedName = Entry.first.SectionName;
765
766 MCSymbol *Begin = createSymbol(CachedName, true, false);
767 Symbols[Begin->getName()] = Begin;
768 cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
769
770 MCSectionWasm *Result = new (WasmAllocator.Allocate())
771 MCSectionWasm(CachedName, Kind, Flags, GroupSym, UniqueID, Begin);
772 Entry.second = Result;
773
774 auto *F = new MCDataFragment();
775 Result->getFragmentList().insert(Result->begin(), F);
776 F->setParent(Result);
777 Begin->setFragment(F);
778
779 return Result;
780}
781
783 XCOFF::CsectProperties CsectProp) const {
784 return XCOFFUniquingMap.count(
785 XCOFFSectionKey(Section.str(), CsectProp.MappingClass)) != 0;
786}
787
789 StringRef Section, SectionKind Kind,
790 std::optional<XCOFF::CsectProperties> CsectProp, bool MultiSymbolsAllowed,
791 const char *BeginSymName,
792 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSectionSubtypeFlags) {
793 bool IsDwarfSec = DwarfSectionSubtypeFlags.has_value();
794 assert((IsDwarfSec != CsectProp.has_value()) && "Invalid XCOFF section!");
795
796 // Do the lookup. If we have a hit, return it.
797 auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
798 IsDwarfSec ? XCOFFSectionKey(Section.str(), *DwarfSectionSubtypeFlags)
799 : XCOFFSectionKey(Section.str(), CsectProp->MappingClass),
800 nullptr));
801 auto &Entry = *IterBool.first;
802 if (!IterBool.second) {
803 MCSectionXCOFF *ExistedEntry = Entry.second;
804 if (ExistedEntry->isMultiSymbolsAllowed() != MultiSymbolsAllowed)
805 report_fatal_error("section's multiply symbols policy does not match");
806
807 return ExistedEntry;
808 }
809
810 // Otherwise, return a new section.
811 StringRef CachedName = Entry.first.SectionName;
812 MCSymbolXCOFF *QualName = nullptr;
813 // Debug section don't have storage class attribute.
814 if (IsDwarfSec)
815 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(CachedName));
816 else
817 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
818 CachedName + "[" +
819 XCOFF::getMappingClassString(CsectProp->MappingClass) + "]"));
820
821 MCSymbol *Begin = nullptr;
822 if (BeginSymName)
823 Begin = createTempSymbol(BeginSymName, false);
824
825 // QualName->getUnqualifiedName() and CachedName are the same except when
826 // CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
827 MCSectionXCOFF *Result = nullptr;
828 if (IsDwarfSec)
829 Result = new (XCOFFAllocator.Allocate()) MCSectionXCOFF(
830 QualName->getUnqualifiedName(), Kind, QualName,
831 *DwarfSectionSubtypeFlags, Begin, CachedName, MultiSymbolsAllowed);
832 else
833 Result = new (XCOFFAllocator.Allocate())
834 MCSectionXCOFF(QualName->getUnqualifiedName(), CsectProp->MappingClass,
835 CsectProp->Type, Kind, QualName, Begin, CachedName,
836 MultiSymbolsAllowed);
837
838 Entry.second = Result;
839
840 auto *F = new MCDataFragment();
841 Result->getFragmentList().insert(Result->begin(), F);
842 F->setParent(Result);
843
844 if (Begin)
845 Begin->setFragment(F);
846
847 // We might miss calculating the symbols difference as absolute value before
848 // adding fixups when symbol_A without the fragment set is the csect itself
849 // and symbol_B is in it.
850 // TODO: Currently we only set the fragment for XMC_PR csects because we don't
851 // have other cases that hit this problem yet.
852 if (!IsDwarfSec && CsectProp->MappingClass == XCOFF::XMC_PR)
853 QualName->setFragment(F);
854
855 return Result;
856}
857
859 MCSymbol *Begin = nullptr;
860 MCSectionSPIRV *Result = new (SPIRVAllocator.Allocate())
862
863 auto *F = new MCDataFragment();
864 Result->getFragmentList().insert(Result->begin(), F);
865 F->setParent(Result);
866
867 return Result;
868}
869
871 SectionKind K) {
872 // Do the lookup, if we have a hit, return it.
873 auto ItInsertedPair = DXCUniquingMap.try_emplace(Section);
874 if (!ItInsertedPair.second)
875 return ItInsertedPair.first->second;
876
877 auto MapIt = ItInsertedPair.first;
878 // Grab the name from the StringMap. Since the Section is going to keep a
879 // copy of this StringRef we need to make sure the underlying string stays
880 // alive as long as we need it.
881 StringRef Name = MapIt->first();
882 MapIt->second =
883 new (DXCAllocator.Allocate()) MCSectionDXContainer(Name, K, nullptr);
884
885 // The first fragment will store the header
886 auto *F = new MCDataFragment();
887 MapIt->second->getFragmentList().insert(MapIt->second->begin(), F);
888 F->setParent(MapIt->second);
889
890 return MapIt->second;
891}
892
894 return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
895}
896
898 const std::string &To) {
899 DebugPrefixMap.emplace_back(From, To);
900}
901
903 for (const auto &[From, To] : llvm::reverse(DebugPrefixMap))
905 break;
906}
907
909 const auto &DebugPrefixMap = this->DebugPrefixMap;
910 if (DebugPrefixMap.empty())
911 return;
912
913 // Remap compilation directory.
914 remapDebugPath(CompilationDir);
915
916 // Remap MCDwarfDirs and RootFile.Name in all compilation units.
918 for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
919 for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
920 P = Dir;
922 Dir = std::string(P);
923 }
924
925 // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
926 // DW_AT_decl_file for DWARF v5 generated for assembly source.
927 P = CUIDTablePair.second.getRootFile().Name;
929 CUIDTablePair.second.getRootFile().Name = std::string(P);
930 }
931}
932
933//===----------------------------------------------------------------------===//
934// Dwarf Management
935//===----------------------------------------------------------------------===//
936
938 if (!TargetOptions)
940 return TargetOptions->EmitDwarfUnwind;
941}
942
944 if (TargetOptions)
945 return TargetOptions->EmitCompactUnwindNonCanonical;
946 return false;
947}
948
950 // MCDwarf needs the root file as well as the compilation directory.
951 // If we find a '.file 0' directive that will supersede these values.
952 std::optional<MD5::MD5Result> Cksum;
953 if (getDwarfVersion() >= 5) {
954 MD5 Hash;
955 MD5::MD5Result Sum;
956 Hash.update(Buffer);
957 Hash.final(Sum);
958 Cksum = Sum;
959 }
960 // Canonicalize the root filename. It cannot be empty, and should not
961 // repeat the compilation dir.
962 // The MCContext ctor initializes MainFileName to the name associated with
963 // the SrcMgr's main file ID, which might be the same as InputFileName (and
964 // possibly include directory components).
965 // Or, MainFileName might have been overridden by a -main-file-name option,
966 // which is supposed to be just a base filename with no directory component.
967 // So, if the InputFileName and MainFileName are not equal, assume
968 // MainFileName is a substitute basename and replace the last component.
969 SmallString<1024> FileNameBuf = InputFileName;
970 if (FileNameBuf.empty() || FileNameBuf == "-")
971 FileNameBuf = "<stdin>";
972 if (!getMainFileName().empty() && FileNameBuf != getMainFileName()) {
975 }
976 StringRef FileName = FileNameBuf;
977 if (FileName.consume_front(getCompilationDir()))
978 if (llvm::sys::path::is_separator(FileName.front()))
979 FileName = FileName.drop_front();
980 assert(!FileName.empty());
982 /*CUID=*/0, getCompilationDir(), FileName, Cksum, std::nullopt);
983}
984
985/// getDwarfFile - takes a file name and number to place in the dwarf file and
986/// directory tables. If the file number has already been allocated it is an
987/// error and zero is returned and the client reports the error, else the
988/// allocated file number is returned. The file numbers may be in any order.
991 unsigned FileNumber,
992 std::optional<MD5::MD5Result> Checksum,
993 std::optional<StringRef> Source, unsigned CUID) {
994 MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
995 return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
996 FileNumber);
997}
998
999/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
1000/// currently is assigned and false otherwise.
1001bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
1002 const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
1003 if (FileNumber == 0)
1004 return getDwarfVersion() >= 5;
1005 if (FileNumber >= LineTable.getMCDwarfFiles().size())
1006 return false;
1007
1008 return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
1009}
1010
1011/// Remove empty sections from SectionsForRanges, to avoid generating
1012/// useless debug info for them.
1014 SectionsForRanges.remove_if(
1015 [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
1016}
1017
1019 if (!CVContext)
1020 CVContext.reset(new CodeViewContext);
1021 return *CVContext;
1022}
1023
1024//===----------------------------------------------------------------------===//
1025// Error Reporting
1026//===----------------------------------------------------------------------===//
1027
1029 assert(DiagHandler && "MCContext::DiagHandler is not set");
1030 bool UseInlineSrcMgr = false;
1031 const SourceMgr *SMP = nullptr;
1032 if (SrcMgr) {
1033 SMP = SrcMgr;
1034 } else if (InlineSrcMgr) {
1035 SMP = InlineSrcMgr.get();
1036 UseInlineSrcMgr = true;
1037 } else
1038 llvm_unreachable("Either SourceMgr should be available");
1039 DiagHandler(SMD, UseInlineSrcMgr, *SMP, LocInfos);
1040}
1041
1042void MCContext::reportCommon(
1043 SMLoc Loc,
1044 std::function<void(SMDiagnostic &, const SourceMgr *)> GetMessage) {
1045 // * MCContext::SrcMgr is null when the MC layer emits machine code for input
1046 // other than assembly file, say, for .c/.cpp/.ll/.bc.
1047 // * MCContext::InlineSrcMgr is null when the inline asm is not used.
1048 // * A default SourceMgr is needed for diagnosing when both MCContext::SrcMgr
1049 // and MCContext::InlineSrcMgr are null.
1050 SourceMgr SM;
1051 const SourceMgr *SMP = &SM;
1052 bool UseInlineSrcMgr = false;
1053
1054 // FIXME: Simplify these by combining InlineSrcMgr & SrcMgr.
1055 // For MC-only execution, only SrcMgr is used;
1056 // For non MC-only execution, InlineSrcMgr is only ctor'd if there is
1057 // inline asm in the IR.
1058 if (Loc.isValid()) {
1059 if (SrcMgr) {
1060 SMP = SrcMgr;
1061 } else if (InlineSrcMgr) {
1062 SMP = InlineSrcMgr.get();
1063 UseInlineSrcMgr = true;
1064 } else
1065 llvm_unreachable("Either SourceMgr should be available");
1066 }
1067
1069 GetMessage(D, SMP);
1070 DiagHandler(D, UseInlineSrcMgr, *SMP, LocInfos);
1071}
1072
1073void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
1074 HadError = true;
1075 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1076 D = SMP->GetMessage(Loc, SourceMgr::DK_Error, Msg);
1077 });
1078}
1079
1080void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
1081 if (TargetOptions && TargetOptions->MCNoWarn)
1082 return;
1083 if (TargetOptions && TargetOptions->MCFatalWarnings) {
1084 reportError(Loc, Msg);
1085 } else {
1086 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1087 D = SMP->GetMessage(Loc, SourceMgr::DK_Warning, Msg);
1088 });
1089 }
1090}
unsigned const MachineRegisterInfo * MRI
This file defines the StringMap class.
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
BlockVerifier::State From
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:331
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &, std::vector< const MDNode * > &)
Definition: MCContext.cpp:61
#define DWARF2_FLAG_IS_STMT
Definition: MCDwarf.h:117
This file declares the MCSectionGOFF class, which contains all of the necessary machine code sections...
This file contains the MCSymbolGOFF class.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define P(N)
Basic Register Allocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This file defines the SmallVector class.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
Definition: TextStub.cpp:1060
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
Definition: Allocator.h:123
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:144
Tagged union holding either a T or a Error.
Definition: Error.h:474
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:664
StringRef getLinkerPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:671
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
Definition: MCAsmInfo.cpp:105
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:112
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
void remapDebugPath(SmallVectorImpl< char > &Path)
Remap one path in-place as per the debug prefix map.
Definition: MCContext.cpp:902
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:893
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
Definition: MCContext.cpp:442
Environment getObjectFileType() const
Definition: MCContext.h:420
void setSymbolValue(MCStreamer &Streamer, const Twine &Sym, uint64_t Val)
Set value for a symbol.
Definition: MCContext.cpp:369
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
Definition: MCContext.h:710
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
Definition: MCContext.cpp:897
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:322
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
Definition: MCContext.h:693
void RemapDebugPaths()
Definition: MCContext.cpp:908
MCInst * createMCInst()
Create and return a new MC instruction.
Definition: MCContext.cpp:193
MCSymbol * getOrCreateFrameAllocSymbol(const Twine &FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen.
Definition: MCContext.cpp:214
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
Definition: MCContext.cpp:509
MCSymbol * createLinkerPrivateTempSymbol()
Create a new linker temporary symbol with the specified prefix (Name) or "tmp".
Definition: MCContext.cpp:312
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
Definition: MCContext.h:643
void recordELFMergeableSectionInfo(StringRef SectionName, unsigned Flags, unsigned UniqueID, unsigned EntrySize)
Definition: MCContext.cpp:619
Expected< unsigned > getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
Definition: MCContext.cpp:990
wasm::WasmSignature * createWasmSignature()
Allocates and returns a new WasmSignature instance (with empty parameter and return type lists).
Definition: MCContext.cpp:379
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
Definition: MCContext.cpp:521
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:562
void diagnose(const SMDiagnostic &SMD)
Definition: MCContext.cpp:1028
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
Definition: MCContext.cpp:1001
void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
Definition: MCContext.cpp:375
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:728
void initInlineSourceManager()
Definition: MCContext.cpp:125
MCSymbol * getOrCreateParentFrameOffsetSymbol(const Twine &FuncName)
Definition: MCContext.cpp:220
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
Definition: MCContext.cpp:363
bool emitCompactUnwindNonCanonical() const
Definition: MCContext.cpp:943
CodeViewContext & getCVContext()
Definition: MCContext.cpp:1018
void reset()
reset - return object to right after construction state to prepare to process a new module
Definition: MCContext.cpp:134
bool isELFGenericMergeableSection(StringRef Name)
Definition: MCContext.cpp:645
MCContext(const Triple &TheTriple, const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCSubtargetInfo *MSTI, const SourceMgr *Mgr=nullptr, MCTargetOptions const *TargetOpts=nullptr, bool DoAutoReset=true, StringRef Swift5ReflSegmentName={})
Definition: MCContext.cpp:66
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, const char *BeginSymName=nullptr, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
Definition: MCContext.cpp:788
std::optional< unsigned > getELFUniqueIDForEntsize(StringRef SectionName, unsigned Flags, unsigned EntrySize)
Return the unique ID of the section with the given name, flags and entry size, if it exists.
Definition: MCContext.cpp:651
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
Definition: MCContext.cpp:350
void reportWarning(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1080
uint16_t getDwarfVersion() const
Definition: MCContext.h:828
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
Definition: MCContext.cpp:1013
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1073
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:676
MCSymbol * getOrCreateLSDASymbol(const Twine &FuncName)
Definition: MCContext.cpp:225
MCSectionDXContainer * getDXContainerSection(StringRef Section, SectionKind K)
Get the section for the provided Section name.
Definition: MCContext.cpp:870
bool hasXCOFFSection(StringRef Section, XCOFF::CsectProperties CsectProp) const
Definition: MCContext.cpp:782
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:545
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:201
MCSymbol * createLinkerPrivateSymbol(const Twine &Name)
Definition: MCContext.cpp:316
MCSectionSPIRV * getSPIRVSection()
Definition: MCContext.cpp:858
EmitDwarfUnwindType emitDwarfUnwindInfo() const
Definition: MCContext.cpp:937
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Definition: MCContext.cpp:640
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
Definition: MCContext.cpp:612
void setGenDwarfRootFile(StringRef FileName, StringRef Buffer)
Specifies information about the "root file" for assembler clients (e.g., llvm-mc).
Definition: MCContext.cpp:949
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, const MCExpr *SubsectionId)
Definition: MCContext.cpp:658
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym.
Definition: MCContext.cpp:715
void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir, StringRef Filename, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source)
Specifies the "root" file and directory of the compilation unit.
Definition: MCContext.h:752
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references).
Definition: MCContext.cpp:355
MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
Definition: MCContext.cpp:324
Fragment for data and encoded instructions.
Definition: MCFragment.h:242
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
Definition: MCDwarf.cpp:574
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:418
Instances of this class represent the information from a dwarf .loc directive.
Definition: MCDwarf.h:105
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
Instances of this class represent a label name in the MC file, and MCLabel are created and uniqued by...
Definition: MCLabel.h:23
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:66
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:26
This represents a section on a Mach-O system (used by Mac OS X).
This represents a section on wasm.
Definition: MCSectionWasm.h:26
bool isMultiSymbolsAllowed() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
static constexpr unsigned NonUniqueID
Definition: MCSection.h:41
SectionKind getKind() const
Definition: MCSection.h:125
StringRef getName() const
Definition: MCSection.h:124
MCSymbol * getBeginSymbol()
Definition: MCSection.h:129
Streaming machine code generation interface.
Definition: MCStreamer.h:212
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual bool mayHaveInstructions(MCSection &Sec) const
Definition: MCStreamer.h:1134
Generic base class for all target subtargets.
void setComdat(bool isComdat)
Definition: MCSymbolWasm.h:81
static StringRef getUnqualifiedName(StringRef Name)
Definition: MCSymbolXCOFF.h:31
void setSymbolTableName(StringRef STN)
Definition: MCSymbolXCOFF.h:62
StringRef getUnqualifiedName() const
Definition: MCSymbolXCOFF.h:50
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:275
Definition: MD5.h:41
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:189
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition: MD5.cpp:234
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:76
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:281
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
Definition: SourceMgr.cpp:484
Represents a location in source code.
Definition: SMLoc.h:23
constexpr bool isValid() const
Definition: SMLoc.h:29
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
static SectionKind getThreadData()
Definition: SectionKind.h:207
static SectionKind getMetadata()
Definition: SectionKind.h:188
static SectionKind getText()
Definition: SectionKind.h:190
static SectionKind getReadOnlyWithRel()
Definition: SectionKind.h:214
static SectionKind getData()
Definition: SectionKind.h:213
static SectionKind getBSS()
Definition: SectionKind.h:209
static SectionKind getThreadBSS()
Definition: SectionKind.h:206
static SectionKind getExecuteOnly()
Definition: SectionKind.h:191
static SectionKind getReadOnly()
Definition: SectionKind.h:192
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
void append(StringRef RHS)
Append from a StringRef.
Definition: SmallString.h:68
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:254
bool empty() const
Definition: SmallVector.h:94
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:950
void resize(size_type N)
Definition: SmallVector.h:651
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
unsigned getMainFileID() const
Definition: SourceMgr.h:132
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:125
unsigned getNumBuffers() const
Definition: SourceMgr.h:130
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
Definition: SourceMgr.cpp:274
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: StringMap.h:253
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:308
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:257
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:601
char front() const
front - Get the first character in the string.
Definition: StringRef.h:140
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:627
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
StringSwitch & StartsWith(StringLiteral S, T Value)
Definition: StringSwitch.h:83
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
ObjectFormatType getObjectFormat() const
Get the object format for this triple.
Definition: Triple.h:399
bool isUEFI() const
Tests whether the OS is UEFI.
Definition: Triple.h:619
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:624
@ DXContainer
Definition: Triple.h:301
@ UnknownObjectFormat
Definition: Triple.h:298
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
Definition: Twine.h:429
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:690
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_SCN_LNK_COMDAT
Definition: COFF.h:308
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition: COFF.h:425
@ SHF_MERGE
Definition: ELF.h:1163
@ SHF_WRITE
Definition: ELF.h:1154
@ SHF_TLS
Definition: ELF.h:1182
@ SHF_ARM_PURECODE
Definition: ELF.h:1252
@ SHF_EXECINSTR
Definition: ELF.h:1160
@ SHT_GROUP
Definition: ELF.h:1077
@ SHT_NOBITS
Definition: ELF.h:1070
@ STB_LOCAL
Definition: ELF.h:1310
@ STT_SECTION
Definition: ELF.h:1325
DwarfSectionSubtypeFlags
Values for defining the section subtype of sections of type STYP_DWARF as they would appear in the (s...
Definition: XCOFF.h:154
StringRef getMappingClassString(XCOFF::StorageMappingClass SMC)
Definition: XCOFF.cpp:20
@ XMC_PR
Program Code.
Definition: XCOFF.h:105
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
Definition: Path.cpp:475
bool replace_path_prefix(SmallVectorImpl< char > &Path, StringRef OldPrefix, StringRef NewPrefix, Style style=Style::native)
Replace matching path prefix with another path.
Definition: Path.cpp:519
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:457
bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
Definition: Path.cpp:602
@ WASM_SYMBOL_TYPE_SECTION
Definition: Wasm.h:211
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
SourceMgr SrcMgr
Definition: Error.cpp:24
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:419
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:156
EmitDwarfUnwindType
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
StorageMappingClass MappingClass
Definition: XCOFF.h:475