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
626 // For mergeable sections or non-mergeable sections with a generic mergeable
627 // section name we enter their Unique ID into the ELFEntrySizeMap so that
628 // compatible globals can be assigned to the same section.
629 if (IsMergeable || isELFGenericMergeableSection(SectionName)) {
630 ELFEntrySizeMap.insert(std::make_pair(
631 ELFEntrySizeKey{SectionName, Flags, EntrySize}, UniqueID));
632 }
633}
634
636 return SectionName.starts_with(".rodata.str") ||
637 SectionName.starts_with(".rodata.cst");
638}
639
642 ELFSeenGenericMergeableSections.count(SectionName);
643}
644
645std::optional<unsigned>
647 unsigned EntrySize) {
648 auto I = ELFEntrySizeMap.find(
649 MCContext::ELFEntrySizeKey{SectionName, Flags, EntrySize});
650 return (I != ELFEntrySizeMap.end()) ? std::optional<unsigned>(I->second)
651 : std::nullopt;
652}
653
655 MCSection *Parent,
656 const MCExpr *SubsectionId) {
657 // Do the lookup. If we don't have a hit, return a new section.
658 auto IterBool =
659 GOFFUniquingMap.insert(std::make_pair(Section.str(), nullptr));
660 auto Iter = IterBool.first;
661 if (!IterBool.second)
662 return Iter->second;
663
664 StringRef CachedName = Iter->first;
665 MCSectionGOFF *GOFFSection = new (GOFFAllocator.Allocate())
666 MCSectionGOFF(CachedName, Kind, Parent, SubsectionId);
667 Iter->second = GOFFSection;
668
669 return GOFFSection;
670}
671
673 unsigned Characteristics,
674 SectionKind Kind,
675 StringRef COMDATSymName, int Selection,
676 unsigned UniqueID,
677 const char *BeginSymName) {
678 MCSymbol *COMDATSymbol = nullptr;
679 if (!COMDATSymName.empty()) {
680 COMDATSymbol = getOrCreateSymbol(COMDATSymName);
681 COMDATSymName = COMDATSymbol->getName();
682 }
683
684 // Do the lookup, if we have a hit, return it.
685 COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
686 auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
687 auto Iter = IterBool.first;
688 if (!IterBool.second)
689 return Iter->second;
690
691 MCSymbol *Begin = nullptr;
692 if (BeginSymName)
693 Begin = createTempSymbol(BeginSymName, false);
694
695 StringRef CachedName = Iter->first.SectionName;
696 MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
697 CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
698
699 Iter->second = Result;
700 return Result;
701}
702
704 unsigned Characteristics,
705 SectionKind Kind,
706 const char *BeginSymName) {
707 return getCOFFSection(Section, Characteristics, Kind, "", 0, GenericSectionID,
708 BeginSymName);
709}
710
712 const MCSymbol *KeySym,
713 unsigned UniqueID) {
714 // Return the normal section if we don't have to be associative or unique.
715 if (!KeySym && UniqueID == GenericSectionID)
716 return Sec;
717
718 // If we have a key symbol, make an associative section with the same name and
719 // kind as the normal section.
720 unsigned Characteristics = Sec->getCharacteristics();
721 if (KeySym) {
723 return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(),
724 KeySym->getName(),
726 }
727
728 return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(), "", 0,
729 UniqueID);
730}
731
733 unsigned Flags, const Twine &Group,
734 unsigned UniqueID,
735 const char *BeginSymName) {
736 MCSymbolWasm *GroupSym = nullptr;
737 if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
738 GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
739 GroupSym->setComdat(true);
740 }
741
742 return getWasmSection(Section, K, Flags, GroupSym, UniqueID, BeginSymName);
743}
744
746 unsigned Flags,
747 const MCSymbolWasm *GroupSym,
748 unsigned UniqueID,
749 const char *BeginSymName) {
750 StringRef Group = "";
751 if (GroupSym)
752 Group = GroupSym->getName();
753 // Do the lookup, if we have a hit, return it.
754 auto IterBool = WasmUniquingMap.insert(
755 std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr));
756 auto &Entry = *IterBool.first;
757 if (!IterBool.second)
758 return Entry.second;
759
760 StringRef CachedName = Entry.first.SectionName;
761
762 MCSymbol *Begin = createSymbol(CachedName, true, false);
763 Symbols[Begin->getName()] = Begin;
764 cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
765
766 MCSectionWasm *Result = new (WasmAllocator.Allocate())
767 MCSectionWasm(CachedName, Kind, Flags, GroupSym, UniqueID, Begin);
768 Entry.second = Result;
769
770 auto *F = new MCDataFragment();
771 Result->getFragmentList().insert(Result->begin(), F);
772 F->setParent(Result);
773 Begin->setFragment(F);
774
775 return Result;
776}
777
779 XCOFF::CsectProperties CsectProp) const {
780 return XCOFFUniquingMap.count(
781 XCOFFSectionKey(Section.str(), CsectProp.MappingClass)) != 0;
782}
783
785 StringRef Section, SectionKind Kind,
786 std::optional<XCOFF::CsectProperties> CsectProp, bool MultiSymbolsAllowed,
787 const char *BeginSymName,
788 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSectionSubtypeFlags) {
789 bool IsDwarfSec = DwarfSectionSubtypeFlags.has_value();
790 assert((IsDwarfSec != CsectProp.has_value()) && "Invalid XCOFF section!");
791
792 // Do the lookup. If we have a hit, return it.
793 auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
794 IsDwarfSec ? XCOFFSectionKey(Section.str(), *DwarfSectionSubtypeFlags)
795 : XCOFFSectionKey(Section.str(), CsectProp->MappingClass),
796 nullptr));
797 auto &Entry = *IterBool.first;
798 if (!IterBool.second) {
799 MCSectionXCOFF *ExistedEntry = Entry.second;
800 if (ExistedEntry->isMultiSymbolsAllowed() != MultiSymbolsAllowed)
801 report_fatal_error("section's multiply symbols policy does not match");
802
803 return ExistedEntry;
804 }
805
806 // Otherwise, return a new section.
807 StringRef CachedName = Entry.first.SectionName;
808 MCSymbolXCOFF *QualName = nullptr;
809 // Debug section don't have storage class attribute.
810 if (IsDwarfSec)
811 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(CachedName));
812 else
813 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
814 CachedName + "[" +
815 XCOFF::getMappingClassString(CsectProp->MappingClass) + "]"));
816
817 MCSymbol *Begin = nullptr;
818 if (BeginSymName)
819 Begin = createTempSymbol(BeginSymName, false);
820
821 // QualName->getUnqualifiedName() and CachedName are the same except when
822 // CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
823 MCSectionXCOFF *Result = nullptr;
824 if (IsDwarfSec)
825 Result = new (XCOFFAllocator.Allocate()) MCSectionXCOFF(
826 QualName->getUnqualifiedName(), Kind, QualName,
827 *DwarfSectionSubtypeFlags, Begin, CachedName, MultiSymbolsAllowed);
828 else
829 Result = new (XCOFFAllocator.Allocate())
830 MCSectionXCOFF(QualName->getUnqualifiedName(), CsectProp->MappingClass,
831 CsectProp->Type, Kind, QualName, Begin, CachedName,
832 MultiSymbolsAllowed);
833
834 Entry.second = Result;
835
836 auto *F = new MCDataFragment();
837 Result->getFragmentList().insert(Result->begin(), F);
838 F->setParent(Result);
839
840 if (Begin)
841 Begin->setFragment(F);
842
843 // We might miss calculating the symbols difference as absolute value before
844 // adding fixups when symbol_A without the fragment set is the csect itself
845 // and symbol_B is in it.
846 // TODO: Currently we only set the fragment for XMC_PR csects because we don't
847 // have other cases that hit this problem yet.
848 if (!IsDwarfSec && CsectProp->MappingClass == XCOFF::XMC_PR)
849 QualName->setFragment(F);
850
851 return Result;
852}
853
855 MCSymbol *Begin = nullptr;
856 MCSectionSPIRV *Result = new (SPIRVAllocator.Allocate())
858
859 auto *F = new MCDataFragment();
860 Result->getFragmentList().insert(Result->begin(), F);
861 F->setParent(Result);
862
863 return Result;
864}
865
867 SectionKind K) {
868 // Do the lookup, if we have a hit, return it.
869 auto ItInsertedPair = DXCUniquingMap.try_emplace(Section);
870 if (!ItInsertedPair.second)
871 return ItInsertedPair.first->second;
872
873 auto MapIt = ItInsertedPair.first;
874 // Grab the name from the StringMap. Since the Section is going to keep a
875 // copy of this StringRef we need to make sure the underlying string stays
876 // alive as long as we need it.
877 StringRef Name = MapIt->first();
878 MapIt->second =
879 new (DXCAllocator.Allocate()) MCSectionDXContainer(Name, K, nullptr);
880
881 // The first fragment will store the header
882 auto *F = new MCDataFragment();
883 MapIt->second->getFragmentList().insert(MapIt->second->begin(), F);
884 F->setParent(MapIt->second);
885
886 return MapIt->second;
887}
888
890 return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
891}
892
894 const std::string &To) {
895 DebugPrefixMap.emplace_back(From, To);
896}
897
899 for (const auto &[From, To] : llvm::reverse(DebugPrefixMap))
901 break;
902}
903
905 const auto &DebugPrefixMap = this->DebugPrefixMap;
906 if (DebugPrefixMap.empty())
907 return;
908
909 // Remap compilation directory.
910 remapDebugPath(CompilationDir);
911
912 // Remap MCDwarfDirs and RootFile.Name in all compilation units.
914 for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
915 for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
916 P = Dir;
918 Dir = std::string(P);
919 }
920
921 // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
922 // DW_AT_decl_file for DWARF v5 generated for assembly source.
923 P = CUIDTablePair.second.getRootFile().Name;
925 CUIDTablePair.second.getRootFile().Name = std::string(P);
926 }
927}
928
929//===----------------------------------------------------------------------===//
930// Dwarf Management
931//===----------------------------------------------------------------------===//
932
934 if (!TargetOptions)
936 return TargetOptions->EmitDwarfUnwind;
937}
938
940 if (TargetOptions)
941 return TargetOptions->EmitCompactUnwindNonCanonical;
942 return false;
943}
944
946 // MCDwarf needs the root file as well as the compilation directory.
947 // If we find a '.file 0' directive that will supersede these values.
948 std::optional<MD5::MD5Result> Cksum;
949 if (getDwarfVersion() >= 5) {
950 MD5 Hash;
951 MD5::MD5Result Sum;
952 Hash.update(Buffer);
953 Hash.final(Sum);
954 Cksum = Sum;
955 }
956 // Canonicalize the root filename. It cannot be empty, and should not
957 // repeat the compilation dir.
958 // The MCContext ctor initializes MainFileName to the name associated with
959 // the SrcMgr's main file ID, which might be the same as InputFileName (and
960 // possibly include directory components).
961 // Or, MainFileName might have been overridden by a -main-file-name option,
962 // which is supposed to be just a base filename with no directory component.
963 // So, if the InputFileName and MainFileName are not equal, assume
964 // MainFileName is a substitute basename and replace the last component.
965 SmallString<1024> FileNameBuf = InputFileName;
966 if (FileNameBuf.empty() || FileNameBuf == "-")
967 FileNameBuf = "<stdin>";
968 if (!getMainFileName().empty() && FileNameBuf != getMainFileName()) {
971 }
972 StringRef FileName = FileNameBuf;
973 if (FileName.consume_front(getCompilationDir()))
974 if (llvm::sys::path::is_separator(FileName.front()))
975 FileName = FileName.drop_front();
976 assert(!FileName.empty());
978 /*CUID=*/0, getCompilationDir(), FileName, Cksum, std::nullopt);
979}
980
981/// getDwarfFile - takes a file name and number to place in the dwarf file and
982/// directory tables. If the file number has already been allocated it is an
983/// error and zero is returned and the client reports the error, else the
984/// allocated file number is returned. The file numbers may be in any order.
987 unsigned FileNumber,
988 std::optional<MD5::MD5Result> Checksum,
989 std::optional<StringRef> Source, unsigned CUID) {
990 MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
991 return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
992 FileNumber);
993}
994
995/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
996/// currently is assigned and false otherwise.
997bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
998 const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
999 if (FileNumber == 0)
1000 return getDwarfVersion() >= 5;
1001 if (FileNumber >= LineTable.getMCDwarfFiles().size())
1002 return false;
1003
1004 return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
1005}
1006
1007/// Remove empty sections from SectionsForRanges, to avoid generating
1008/// useless debug info for them.
1010 SectionsForRanges.remove_if(
1011 [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
1012}
1013
1015 if (!CVContext)
1016 CVContext.reset(new CodeViewContext);
1017 return *CVContext;
1018}
1019
1020//===----------------------------------------------------------------------===//
1021// Error Reporting
1022//===----------------------------------------------------------------------===//
1023
1025 assert(DiagHandler && "MCContext::DiagHandler is not set");
1026 bool UseInlineSrcMgr = false;
1027 const SourceMgr *SMP = nullptr;
1028 if (SrcMgr) {
1029 SMP = SrcMgr;
1030 } else if (InlineSrcMgr) {
1031 SMP = InlineSrcMgr.get();
1032 UseInlineSrcMgr = true;
1033 } else
1034 llvm_unreachable("Either SourceMgr should be available");
1035 DiagHandler(SMD, UseInlineSrcMgr, *SMP, LocInfos);
1036}
1037
1038void MCContext::reportCommon(
1039 SMLoc Loc,
1040 std::function<void(SMDiagnostic &, const SourceMgr *)> GetMessage) {
1041 // * MCContext::SrcMgr is null when the MC layer emits machine code for input
1042 // other than assembly file, say, for .c/.cpp/.ll/.bc.
1043 // * MCContext::InlineSrcMgr is null when the inline asm is not used.
1044 // * A default SourceMgr is needed for diagnosing when both MCContext::SrcMgr
1045 // and MCContext::InlineSrcMgr are null.
1046 SourceMgr SM;
1047 const SourceMgr *SMP = &SM;
1048 bool UseInlineSrcMgr = false;
1049
1050 // FIXME: Simplify these by combining InlineSrcMgr & SrcMgr.
1051 // For MC-only execution, only SrcMgr is used;
1052 // For non MC-only execution, InlineSrcMgr is only ctor'd if there is
1053 // inline asm in the IR.
1054 if (Loc.isValid()) {
1055 if (SrcMgr) {
1056 SMP = SrcMgr;
1057 } else if (InlineSrcMgr) {
1058 SMP = InlineSrcMgr.get();
1059 UseInlineSrcMgr = true;
1060 } else
1061 llvm_unreachable("Either SourceMgr should be available");
1062 }
1063
1065 GetMessage(D, SMP);
1066 DiagHandler(D, UseInlineSrcMgr, *SMP, LocInfos);
1067}
1068
1069void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
1070 HadError = true;
1071 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1072 D = SMP->GetMessage(Loc, SourceMgr::DK_Error, Msg);
1073 });
1074}
1075
1076void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
1077 if (TargetOptions && TargetOptions->MCNoWarn)
1078 return;
1079 if (TargetOptions && TargetOptions->MCFatalWarnings) {
1080 reportError(Loc, Msg);
1081 } else {
1082 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1083 D = SMP->GetMessage(Loc, SourceMgr::DK_Warning, Msg);
1084 });
1085 }
1086}
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:898
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:889
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:436
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:726
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
Definition: MCContext.cpp:893
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:709
void RemapDebugPaths()
Definition: MCContext.cpp:904
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:659
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:986
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:578
void diagnose(const SMDiagnostic &SMD)
Definition: MCContext.cpp:1024
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:997
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:744
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:939
CodeViewContext & getCVContext()
Definition: MCContext.cpp:1014
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:640
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:784
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:646
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:1076
uint16_t getDwarfVersion() const
Definition: MCContext.h:844
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
Definition: MCContext.cpp:1009
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1069
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:672
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:866
bool hasXCOFFSection(StringRef Section, XCOFF::CsectProperties CsectProp) const
Definition: MCContext.cpp:778
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:561
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:854
EmitDwarfUnwindType emitDwarfUnwindInfo() const
Definition: MCContext.cpp:933
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Definition: MCContext.cpp:635
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:945
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, const MCExpr *SubsectionId)
Definition: MCContext.cpp:654
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:711
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:768
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:1137
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) 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:306
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:605
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:631
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:387
bool isUEFI() const
Tests whether the OS is UEFI.
Definition: Triple.h:603
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:608
@ DXContainer
Definition: Triple.h:289
@ UnknownObjectFormat
Definition: Triple.h:286
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