LLVM 18.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
151 MCSubtargetAllocator.DestroyAll();
152 InlineAsmUsedLabelNames.clear();
153 UsedNames.clear();
154 Symbols.clear();
155 Allocator.Reset();
156 Instances.clear();
157 CompilationDir.clear();
158 MainFileName.clear();
159 MCDwarfLineTablesCUMap.clear();
160 SectionsForRanges.clear();
161 MCGenDwarfLabelEntries.clear();
162 DwarfDebugFlags = StringRef();
163 DwarfCompileUnitID = 0;
164 CurrentDwarfLoc = MCDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0);
165
166 CVContext.reset();
167
168 MachOUniquingMap.clear();
169 ELFUniquingMap.clear();
170 GOFFUniquingMap.clear();
171 COFFUniquingMap.clear();
172 WasmUniquingMap.clear();
173 XCOFFUniquingMap.clear();
174 DXCUniquingMap.clear();
175
176 ELFEntrySizeMap.clear();
177 ELFSeenGenericMergeableSections.clear();
178
179 NextID.clear();
180 AllowTemporaryLabels = true;
181 DwarfLocSeen = false;
182 GenDwarfForAssembly = false;
183 GenDwarfFileNumber = 0;
184
185 HadError = false;
186}
187
188//===----------------------------------------------------------------------===//
189// MCInst Management
190//===----------------------------------------------------------------------===//
191
193 return new (MCInstAllocator.Allocate()) MCInst;
194}
195
196//===----------------------------------------------------------------------===//
197// Symbol Manipulation
198//===----------------------------------------------------------------------===//
199
201 SmallString<128> NameSV;
202 StringRef NameRef = Name.toStringRef(NameSV);
203
204 assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
205
206 MCSymbol *&Sym = Symbols[NameRef];
207 if (!Sym)
208 Sym = createSymbol(NameRef, false, false);
209
210 return Sym;
211}
212
214 unsigned Idx) {
215 return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + FuncName +
216 "$frame_escape_" + Twine(Idx));
217}
218
220 return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + FuncName +
221 "$parent_frame_offset");
222}
223
225 return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + "__ehtable$" +
226 FuncName);
227}
228
229MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
230 bool IsTemporary) {
231 static_assert(std::is_trivially_destructible<MCSymbolCOFF>(),
232 "MCSymbol classes must be trivially destructible");
233 static_assert(std::is_trivially_destructible<MCSymbolELF>(),
234 "MCSymbol classes must be trivially destructible");
235 static_assert(std::is_trivially_destructible<MCSymbolMachO>(),
236 "MCSymbol classes must be trivially destructible");
237 static_assert(std::is_trivially_destructible<MCSymbolWasm>(),
238 "MCSymbol classes must be trivially destructible");
239 static_assert(std::is_trivially_destructible<MCSymbolXCOFF>(),
240 "MCSymbol classes must be trivially destructible");
241
242 switch (getObjectFileType()) {
244 return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
245 case MCContext::IsELF:
246 return new (Name, *this) MCSymbolELF(Name, IsTemporary);
248 return new (Name, *this) MCSymbolGOFF(Name, IsTemporary);
250 return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
252 return new (Name, *this) MCSymbolWasm(Name, IsTemporary);
254 return createXCOFFSymbolImpl(Name, IsTemporary);
256 break;
258 return new (Name, *this)
260 }
261 return new (Name, *this)
263}
264
265MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
266 bool CanBeUnnamed) {
267 if (CanBeUnnamed && !UseNamesOnTempLabels)
268 return createSymbolImpl(nullptr, true);
269
270 // Determine whether this is a user written assembler temporary or normal
271 // label, if used.
272 bool IsTemporary = CanBeUnnamed;
273 if (AllowTemporaryLabels && !IsTemporary)
274 IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
275
276 SmallString<128> NewName = Name;
277 bool AddSuffix = AlwaysAddSuffix;
278 unsigned &NextUniqueID = NextID[Name];
279 while (true) {
280 if (AddSuffix) {
281 NewName.resize(Name.size());
282 raw_svector_ostream(NewName) << NextUniqueID++;
283 }
284 auto NameEntry = UsedNames.insert(std::make_pair(NewName.str(), true));
285 if (NameEntry.second || !NameEntry.first->second) {
286 // Ok, we found a name.
287 // Mark it as used for a non-section symbol.
288 NameEntry.first->second = true;
289 // Have the MCSymbol object itself refer to the copy of the string that is
290 // embedded in the UsedNames entry.
291 return createSymbolImpl(&*NameEntry.first, IsTemporary);
292 }
293 assert(IsTemporary && "Cannot rename non-temporary symbols");
294 AddSuffix = true;
295 }
296 llvm_unreachable("Infinite loop");
297}
298
299MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) {
300 SmallString<128> NameSV;
302 return createSymbol(NameSV, AlwaysAddSuffix, true);
303}
304
306 SmallString<128> NameSV;
308 return createSymbol(NameSV, true, false);
309}
310
312 return createLinkerPrivateSymbol("tmp");
313}
314
316 SmallString<128> NameSV;
318 return createSymbol(NameSV, true, false);
319}
320
322
324 return createNamedTempSymbol("tmp");
325}
326
327unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
328 MCLabel *&Label = Instances[LocalLabelVal];
329 if (!Label)
330 Label = new (*this) MCLabel(0);
331 return Label->incInstance();
332}
333
334unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
335 MCLabel *&Label = Instances[LocalLabelVal];
336 if (!Label)
337 Label = new (*this) MCLabel(0);
338 return Label->getInstance();
339}
340
341MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
342 unsigned Instance) {
343 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
344 if (!Sym)
346 return Sym;
347}
348
350 unsigned Instance = NextInstance(LocalLabelVal);
351 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
352}
353
355 bool Before) {
356 unsigned Instance = GetInstance(LocalLabelVal);
357 if (!Before)
358 ++Instance;
359 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
360}
361
363 SmallString<128> NameSV;
364 StringRef NameRef = Name.toStringRef(NameSV);
365 return Symbols.lookup(NameRef);
366}
367
369 uint64_t Val) {
370 auto Symbol = getOrCreateSymbol(Sym);
371 Streamer.emitAssignment(Symbol, MCConstantExpr::create(Val, *this));
372}
373
375 InlineAsmUsedLabelNames[Sym->getName()] = Sym;
376}
377
379MCContext::createXCOFFSymbolImpl(const StringMapEntry<bool> *Name,
380 bool IsTemporary) {
381 if (!Name)
382 return new (nullptr, *this) MCSymbolXCOFF(nullptr, IsTemporary);
383
384 StringRef OriginalName = Name->first();
385 if (OriginalName.startswith("._Renamed..") ||
386 OriginalName.startswith("_Renamed.."))
387 reportError(SMLoc(), "invalid symbol name from source");
388
389 if (MAI->isValidUnquotedName(OriginalName))
390 return new (Name, *this) MCSymbolXCOFF(Name, IsTemporary);
391
392 // Now we have a name that contains invalid character(s) for XCOFF symbol.
393 // Let's replace with something valid, but save the original name so that
394 // we could still use the original name in the symbol table.
395 SmallString<128> InvalidName(OriginalName);
396
397 // If it's an entry point symbol, we will keep the '.'
398 // in front for the convention purpose. Otherwise, add "_Renamed.."
399 // as prefix to signal this is an renamed symbol.
400 const bool IsEntryPoint = !InvalidName.empty() && InvalidName[0] == '.';
401 SmallString<128> ValidName =
402 StringRef(IsEntryPoint ? "._Renamed.." : "_Renamed..");
403
404 // Append the hex values of '_' and invalid characters with "_Renamed..";
405 // at the same time replace invalid characters with '_'.
406 for (size_t I = 0; I < InvalidName.size(); ++I) {
407 if (!MAI->isAcceptableChar(InvalidName[I]) || InvalidName[I] == '_') {
408 raw_svector_ostream(ValidName).write_hex(InvalidName[I]);
409 InvalidName[I] = '_';
410 }
411 }
412
413 // Skip entry point symbol's '.' as we already have a '.' in front of
414 // "_Renamed".
415 if (IsEntryPoint)
416 ValidName.append(InvalidName.substr(1, InvalidName.size() - 1));
417 else
418 ValidName.append(InvalidName);
419
420 auto NameEntry = UsedNames.insert(std::make_pair(ValidName.str(), true));
421 assert((NameEntry.second || !NameEntry.first->second) &&
422 "This name is used somewhere else.");
423 // Mark the name as used for a non-section symbol.
424 NameEntry.first->second = true;
425 // Have the MCSymbol object itself refer to the copy of the string
426 // that is embedded in the UsedNames entry.
427 MCSymbolXCOFF *XSym = new (&*NameEntry.first, *this)
428 MCSymbolXCOFF(&*NameEntry.first, IsTemporary);
430 return XSym;
431}
432
433//===----------------------------------------------------------------------===//
434// Section Management
435//===----------------------------------------------------------------------===//
436
438 unsigned TypeAndAttributes,
439 unsigned Reserved2, SectionKind Kind,
440 const char *BeginSymName) {
441 // We unique sections by their segment/section pair. The returned section
442 // may not have the same flags as the requested section, if so this should be
443 // diagnosed by the client as an error.
444
445 // Form the name to look up.
446 assert(Section.size() <= 16 && "section name is too long");
447 assert(!memchr(Section.data(), '\0', Section.size()) &&
448 "section name cannot contain NUL");
449
450 // Do the lookup, if we have a hit, return it.
451 auto R = MachOUniquingMap.try_emplace((Segment + Twine(',') + Section).str());
452 if (!R.second)
453 return R.first->second;
454
455 MCSymbol *Begin = nullptr;
456 if (BeginSymName)
457 Begin = createTempSymbol(BeginSymName, false);
458
459 // Otherwise, return a new section.
460 StringRef Name = R.first->first();
461 R.first->second = new (MachOAllocator.Allocate())
462 MCSectionMachO(Segment, Name.substr(Name.size() - Section.size()),
463 TypeAndAttributes, Reserved2, Kind, Begin);
464 return R.first->second;
465}
466
467MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
468 unsigned Flags, SectionKind K,
469 unsigned EntrySize,
470 const MCSymbolELF *Group,
471 bool Comdat, unsigned UniqueID,
472 const MCSymbolELF *LinkedToSym) {
473 MCSymbolELF *R;
474 MCSymbol *&Sym = Symbols[Section];
475 // A section symbol can not redefine regular symbols. There may be multiple
476 // sections with the same name, in which case the first such section wins.
477 if (Sym && Sym->isDefined() &&
478 (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
479 reportError(SMLoc(), "invalid symbol redefinition");
480 if (Sym && Sym->isUndefined()) {
481 R = cast<MCSymbolELF>(Sym);
482 } else {
483 auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first;
484 R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
485 if (!Sym)
486 Sym = R;
487 }
488 R->setBinding(ELF::STB_LOCAL);
489 R->setType(ELF::STT_SECTION);
490
491 auto *Ret = new (ELFAllocator.Allocate())
492 MCSectionELF(Section, Type, Flags, K, EntrySize, Group, Comdat, UniqueID,
493 R, LinkedToSym);
494
495 auto *F = new MCDataFragment();
496 Ret->getFragmentList().insert(Ret->begin(), F);
497 F->setParent(Ret);
498 R->setFragment(F);
499
500 return Ret;
501}
502
504MCContext::createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags,
505 unsigned EntrySize, const MCSymbolELF *Group,
506 const MCSectionELF *RelInfoSection) {
508 bool Inserted;
509 std::tie(I, Inserted) = RelSecNames.insert(std::make_pair(Name.str(), true));
510
511 return createELFSectionImpl(
512 I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
513 true, true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
514}
515
517 const Twine &Suffix, unsigned Type,
518 unsigned Flags,
519 unsigned EntrySize) {
520 return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix,
521 /*IsComdat=*/true);
522}
523
525 unsigned Flags, unsigned EntrySize,
526 const Twine &Group, bool IsComdat,
527 unsigned UniqueID,
528 const MCSymbolELF *LinkedToSym) {
529 MCSymbolELF *GroupSym = nullptr;
530 if (!Group.isTriviallyEmpty() && !Group.str().empty())
531 GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
532
533 return getELFSection(Section, Type, Flags, EntrySize, GroupSym, IsComdat,
534 UniqueID, LinkedToSym);
535}
536
538 unsigned Flags, unsigned EntrySize,
539 const MCSymbolELF *GroupSym,
540 bool IsComdat, unsigned UniqueID,
541 const MCSymbolELF *LinkedToSym) {
542 StringRef Group = "";
543 if (GroupSym)
544 Group = GroupSym->getName();
545 assert(!(LinkedToSym && LinkedToSym->getName().empty()));
546 // Do the lookup, if we have a hit, return it.
547 auto IterBool = ELFUniquingMap.insert(std::make_pair(
548 ELFSectionKey{Section.str(), Group,
549 LinkedToSym ? LinkedToSym->getName() : "", UniqueID},
550 nullptr));
551 auto &Entry = *IterBool.first;
552 if (!IterBool.second)
553 return Entry.second;
554
555 StringRef CachedName = Entry.first.SectionName;
556
557 SectionKind Kind;
558 if (Flags & ELF::SHF_ARM_PURECODE)
560 else if (Flags & ELF::SHF_EXECINSTR)
561 Kind = SectionKind::getText();
562 else if (~Flags & ELF::SHF_WRITE)
564 else if (Flags & ELF::SHF_TLS)
567 else
568 // Default to `SectionKind::getText()`. This is the default for gas as
569 // well. The condition that falls into this case is where we do not have any
570 // section flags and must infer a classification rather than where we have
571 // section flags (i.e. this is not that SHF_EXECINSTR is unset bur rather it
572 // is unknown).
573 Kind = llvm::StringSwitch<SectionKind>(CachedName)
574 .Case(".bss", SectionKind::getBSS())
576 .StartsWith(".gnu.linkonce.b.", SectionKind::getBSS())
577 .StartsWith(".llvm.linkonce.b.", SectionKind::getBSS())
578 .Case(".data", SectionKind::getData())
579 .Case(".data1", SectionKind::getData())
580 .Case(".data.rel.ro", SectionKind::getReadOnlyWithRel())
581 .StartsWith(".data.", SectionKind::getData())
582 .Case(".rodata", SectionKind::getReadOnly())
583 .Case(".rodata1", SectionKind::getReadOnly())
587 .StartsWith(".gnu.linkonce.tb.", SectionKind::getThreadData())
588 .StartsWith(".llvm.linkonce.tb.", SectionKind::getThreadData())
589 .Case(".tdata", SectionKind::getThreadData())
591 .StartsWith(".gnu.linkonce.td.", SectionKind::getThreadData())
592 .StartsWith(".llvm.linkonce.td.", SectionKind::getThreadData())
595
596 MCSectionELF *Result =
597 createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
598 IsComdat, UniqueID, LinkedToSym);
599 Entry.second = Result;
600
601 recordELFMergeableSectionInfo(Result->getName(), Result->getFlags(),
602 Result->getUniqueID(), Result->getEntrySize());
603
604 return Result;
605}
606
608 bool IsComdat) {
609 return createELFSectionImpl(".group", ELF::SHT_GROUP, 0,
610 SectionKind::getReadOnly(), 4, Group, IsComdat,
611 MCSection::NonUniqueID, nullptr);
612}
613
615 unsigned Flags, unsigned UniqueID,
616 unsigned EntrySize) {
617 bool IsMergeable = Flags & ELF::SHF_MERGE;
618 if (UniqueID == GenericSectionID)
619 ELFSeenGenericMergeableSections.insert(SectionName);
620
621 // For mergeable sections or non-mergeable sections with a generic mergeable
622 // section name we enter their Unique ID into the ELFEntrySizeMap so that
623 // compatible globals can be assigned to the same section.
624 if (IsMergeable || isELFGenericMergeableSection(SectionName)) {
625 ELFEntrySizeMap.insert(std::make_pair(
626 ELFEntrySizeKey{SectionName, Flags, EntrySize}, UniqueID));
627 }
628}
629
631 return SectionName.startswith(".rodata.str") ||
632 SectionName.startswith(".rodata.cst");
633}
634
637 ELFSeenGenericMergeableSections.count(SectionName);
638}
639
640std::optional<unsigned>
642 unsigned EntrySize) {
643 auto I = ELFEntrySizeMap.find(
644 MCContext::ELFEntrySizeKey{SectionName, Flags, EntrySize});
645 return (I != ELFEntrySizeMap.end()) ? std::optional<unsigned>(I->second)
646 : std::nullopt;
647}
648
650 MCSection *Parent,
651 const MCExpr *SubsectionId) {
652 // Do the lookup. If we don't have a hit, return a new section.
653 auto &GOFFSection = GOFFUniquingMap[Section.str()];
654 if (!GOFFSection)
655 GOFFSection = new (GOFFAllocator.Allocate())
656 MCSectionGOFF(Section, Kind, Parent, SubsectionId);
657
658 return GOFFSection;
659}
660
662 unsigned Characteristics,
663 SectionKind Kind,
664 StringRef COMDATSymName, int Selection,
665 unsigned UniqueID,
666 const char *BeginSymName) {
667 MCSymbol *COMDATSymbol = nullptr;
668 if (!COMDATSymName.empty()) {
669 COMDATSymbol = getOrCreateSymbol(COMDATSymName);
670 COMDATSymName = COMDATSymbol->getName();
671 }
672
673 // Do the lookup, if we have a hit, return it.
674 COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
675 auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
676 auto Iter = IterBool.first;
677 if (!IterBool.second)
678 return Iter->second;
679
680 MCSymbol *Begin = nullptr;
681 if (BeginSymName)
682 Begin = createTempSymbol(BeginSymName, false);
683
684 StringRef CachedName = Iter->first.SectionName;
685 MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
686 CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
687
688 Iter->second = Result;
689 return Result;
690}
691
693 unsigned Characteristics,
694 SectionKind Kind,
695 const char *BeginSymName) {
696 return getCOFFSection(Section, Characteristics, Kind, "", 0, GenericSectionID,
697 BeginSymName);
698}
699
701 const MCSymbol *KeySym,
702 unsigned UniqueID) {
703 // Return the normal section if we don't have to be associative or unique.
704 if (!KeySym && UniqueID == GenericSectionID)
705 return Sec;
706
707 // If we have a key symbol, make an associative section with the same name and
708 // kind as the normal section.
709 unsigned Characteristics = Sec->getCharacteristics();
710 if (KeySym) {
712 return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(),
713 KeySym->getName(),
715 }
716
717 return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(), "", 0,
718 UniqueID);
719}
720
722 unsigned Flags, const Twine &Group,
723 unsigned UniqueID,
724 const char *BeginSymName) {
725 MCSymbolWasm *GroupSym = nullptr;
726 if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
727 GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
728 GroupSym->setComdat(true);
729 }
730
731 return getWasmSection(Section, K, Flags, GroupSym, UniqueID, BeginSymName);
732}
733
735 unsigned Flags,
736 const MCSymbolWasm *GroupSym,
737 unsigned UniqueID,
738 const char *BeginSymName) {
739 StringRef Group = "";
740 if (GroupSym)
741 Group = GroupSym->getName();
742 // Do the lookup, if we have a hit, return it.
743 auto IterBool = WasmUniquingMap.insert(
744 std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr));
745 auto &Entry = *IterBool.first;
746 if (!IterBool.second)
747 return Entry.second;
748
749 StringRef CachedName = Entry.first.SectionName;
750
751 MCSymbol *Begin = createSymbol(CachedName, true, false);
752 Symbols[Begin->getName()] = Begin;
753 cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
754
755 MCSectionWasm *Result = new (WasmAllocator.Allocate())
756 MCSectionWasm(CachedName, Kind, Flags, GroupSym, UniqueID, Begin);
757 Entry.second = Result;
758
759 auto *F = new MCDataFragment();
760 Result->getFragmentList().insert(Result->begin(), F);
761 F->setParent(Result);
762 Begin->setFragment(F);
763
764 return Result;
765}
766
768 XCOFF::CsectProperties CsectProp) const {
769 return XCOFFUniquingMap.count(
770 XCOFFSectionKey(Section.str(), CsectProp.MappingClass)) != 0;
771}
772
774 StringRef Section, SectionKind Kind,
775 std::optional<XCOFF::CsectProperties> CsectProp, bool MultiSymbolsAllowed,
776 const char *BeginSymName,
777 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSectionSubtypeFlags) {
778 bool IsDwarfSec = DwarfSectionSubtypeFlags.has_value();
779 assert((IsDwarfSec != CsectProp.has_value()) && "Invalid XCOFF section!");
780
781 // Do the lookup. If we have a hit, return it.
782 auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
783 IsDwarfSec ? XCOFFSectionKey(Section.str(), *DwarfSectionSubtypeFlags)
784 : XCOFFSectionKey(Section.str(), CsectProp->MappingClass),
785 nullptr));
786 auto &Entry = *IterBool.first;
787 if (!IterBool.second) {
788 MCSectionXCOFF *ExistedEntry = Entry.second;
789 if (ExistedEntry->isMultiSymbolsAllowed() != MultiSymbolsAllowed)
790 report_fatal_error("section's multiply symbols policy does not match");
791
792 return ExistedEntry;
793 }
794
795 // Otherwise, return a new section.
796 StringRef CachedName = Entry.first.SectionName;
797 MCSymbolXCOFF *QualName = nullptr;
798 // Debug section don't have storage class attribute.
799 if (IsDwarfSec)
800 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(CachedName));
801 else
802 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
803 CachedName + "[" +
804 XCOFF::getMappingClassString(CsectProp->MappingClass) + "]"));
805
806 MCSymbol *Begin = nullptr;
807 if (BeginSymName)
808 Begin = createTempSymbol(BeginSymName, false);
809
810 // QualName->getUnqualifiedName() and CachedName are the same except when
811 // CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
812 MCSectionXCOFF *Result = nullptr;
813 if (IsDwarfSec)
814 Result = new (XCOFFAllocator.Allocate()) MCSectionXCOFF(
815 QualName->getUnqualifiedName(), Kind, QualName,
816 *DwarfSectionSubtypeFlags, Begin, CachedName, MultiSymbolsAllowed);
817 else
818 Result = new (XCOFFAllocator.Allocate())
819 MCSectionXCOFF(QualName->getUnqualifiedName(), CsectProp->MappingClass,
820 CsectProp->Type, Kind, QualName, Begin, CachedName,
821 MultiSymbolsAllowed);
822
823 Entry.second = Result;
824
825 auto *F = new MCDataFragment();
826 Result->getFragmentList().insert(Result->begin(), F);
827 F->setParent(Result);
828
829 if (Begin)
830 Begin->setFragment(F);
831
832 // We might miss calculating the symbols difference as absolute value before
833 // adding fixups when symbol_A without the fragment set is the csect itself
834 // and symbol_B is in it.
835 // TODO: Currently we only set the fragment for XMC_PR csects because we don't
836 // have other cases that hit this problem yet.
837 if (!IsDwarfSec && CsectProp->MappingClass == XCOFF::XMC_PR)
838 QualName->setFragment(F);
839
840 return Result;
841}
842
844 MCSymbol *Begin = nullptr;
845 MCSectionSPIRV *Result = new (SPIRVAllocator.Allocate())
847
848 auto *F = new MCDataFragment();
849 Result->getFragmentList().insert(Result->begin(), F);
850 F->setParent(Result);
851
852 return Result;
853}
854
856 SectionKind K) {
857 // Do the lookup, if we have a hit, return it.
858 auto ItInsertedPair = DXCUniquingMap.try_emplace(Section);
859 if (!ItInsertedPair.second)
860 return ItInsertedPair.first->second;
861
862 auto MapIt = ItInsertedPair.first;
863 // Grab the name from the StringMap. Since the Section is going to keep a
864 // copy of this StringRef we need to make sure the underlying string stays
865 // alive as long as we need it.
866 StringRef Name = MapIt->first();
867 MapIt->second =
868 new (DXCAllocator.Allocate()) MCSectionDXContainer(Name, K, nullptr);
869
870 // The first fragment will store the header
871 auto *F = new MCDataFragment();
872 MapIt->second->getFragmentList().insert(MapIt->second->begin(), F);
873 F->setParent(MapIt->second);
874
875 return MapIt->second;
876}
877
879 return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
880}
881
883 const std::string &To) {
884 DebugPrefixMap.emplace_back(From, To);
885}
886
888 for (const auto &[From, To] : llvm::reverse(DebugPrefixMap))
890 break;
891}
892
894 const auto &DebugPrefixMap = this->DebugPrefixMap;
895 if (DebugPrefixMap.empty())
896 return;
897
898 // Remap compilation directory.
899 remapDebugPath(CompilationDir);
900
901 // Remap MCDwarfDirs and RootFile.Name in all compilation units.
903 for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
904 for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
905 P = Dir;
907 Dir = std::string(P);
908 }
909
910 // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
911 // DW_AT_decl_file for DWARF v5 generated for assembly source.
912 P = CUIDTablePair.second.getRootFile().Name;
914 CUIDTablePair.second.getRootFile().Name = std::string(P);
915 }
916}
917
918//===----------------------------------------------------------------------===//
919// Dwarf Management
920//===----------------------------------------------------------------------===//
921
923 if (!TargetOptions)
925 return TargetOptions->EmitDwarfUnwind;
926}
927
929 if (TargetOptions)
930 return TargetOptions->EmitCompactUnwindNonCanonical;
931 return false;
932}
933
935 // MCDwarf needs the root file as well as the compilation directory.
936 // If we find a '.file 0' directive that will supersede these values.
937 std::optional<MD5::MD5Result> Cksum;
938 if (getDwarfVersion() >= 5) {
939 MD5 Hash;
940 MD5::MD5Result Sum;
941 Hash.update(Buffer);
942 Hash.final(Sum);
943 Cksum = Sum;
944 }
945 // Canonicalize the root filename. It cannot be empty, and should not
946 // repeat the compilation dir.
947 // The MCContext ctor initializes MainFileName to the name associated with
948 // the SrcMgr's main file ID, which might be the same as InputFileName (and
949 // possibly include directory components).
950 // Or, MainFileName might have been overridden by a -main-file-name option,
951 // which is supposed to be just a base filename with no directory component.
952 // So, if the InputFileName and MainFileName are not equal, assume
953 // MainFileName is a substitute basename and replace the last component.
954 SmallString<1024> FileNameBuf = InputFileName;
955 if (FileNameBuf.empty() || FileNameBuf == "-")
956 FileNameBuf = "<stdin>";
957 if (!getMainFileName().empty() && FileNameBuf != getMainFileName()) {
960 }
961 StringRef FileName = FileNameBuf;
962 if (FileName.consume_front(getCompilationDir()))
963 if (llvm::sys::path::is_separator(FileName.front()))
964 FileName = FileName.drop_front();
965 assert(!FileName.empty());
967 /*CUID=*/0, getCompilationDir(), FileName, Cksum, std::nullopt);
968}
969
970/// getDwarfFile - takes a file name and number to place in the dwarf file and
971/// directory tables. If the file number has already been allocated it is an
972/// error and zero is returned and the client reports the error, else the
973/// allocated file number is returned. The file numbers may be in any order.
976 unsigned FileNumber,
977 std::optional<MD5::MD5Result> Checksum,
978 std::optional<StringRef> Source, unsigned CUID) {
979 MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
980 return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
981 FileNumber);
982}
983
984/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
985/// currently is assigned and false otherwise.
986bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
987 const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
988 if (FileNumber == 0)
989 return getDwarfVersion() >= 5;
990 if (FileNumber >= LineTable.getMCDwarfFiles().size())
991 return false;
992
993 return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
994}
995
996/// Remove empty sections from SectionsForRanges, to avoid generating
997/// useless debug info for them.
999 SectionsForRanges.remove_if(
1000 [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
1001}
1002
1004 if (!CVContext)
1005 CVContext.reset(new CodeViewContext);
1006 return *CVContext;
1007}
1008
1009//===----------------------------------------------------------------------===//
1010// Error Reporting
1011//===----------------------------------------------------------------------===//
1012
1014 assert(DiagHandler && "MCContext::DiagHandler is not set");
1015 bool UseInlineSrcMgr = false;
1016 const SourceMgr *SMP = nullptr;
1017 if (SrcMgr) {
1018 SMP = SrcMgr;
1019 } else if (InlineSrcMgr) {
1020 SMP = InlineSrcMgr.get();
1021 UseInlineSrcMgr = true;
1022 } else
1023 llvm_unreachable("Either SourceMgr should be available");
1024 DiagHandler(SMD, UseInlineSrcMgr, *SMP, LocInfos);
1025}
1026
1027void MCContext::reportCommon(
1028 SMLoc Loc,
1029 std::function<void(SMDiagnostic &, const SourceMgr *)> GetMessage) {
1030 // * MCContext::SrcMgr is null when the MC layer emits machine code for input
1031 // other than assembly file, say, for .c/.cpp/.ll/.bc.
1032 // * MCContext::InlineSrcMgr is null when the inline asm is not used.
1033 // * A default SourceMgr is needed for diagnosing when both MCContext::SrcMgr
1034 // and MCContext::InlineSrcMgr are null.
1035 SourceMgr SM;
1036 const SourceMgr *SMP = &SM;
1037 bool UseInlineSrcMgr = false;
1038
1039 // FIXME: Simplify these by combining InlineSrcMgr & SrcMgr.
1040 // For MC-only execution, only SrcMgr is used;
1041 // For non MC-only execution, InlineSrcMgr is only ctor'd if there is
1042 // inline asm in the IR.
1043 if (Loc.isValid()) {
1044 if (SrcMgr) {
1045 SMP = SrcMgr;
1046 } else if (InlineSrcMgr) {
1047 SMP = InlineSrcMgr.get();
1048 UseInlineSrcMgr = true;
1049 } else
1050 llvm_unreachable("Either SourceMgr should be available");
1051 }
1052
1054 GetMessage(D, SMP);
1055 DiagHandler(D, UseInlineSrcMgr, *SMP, LocInfos);
1056}
1057
1058void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
1059 HadError = true;
1060 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1061 D = SMP->GetMessage(Loc, SourceMgr::DK_Error, Msg);
1062 });
1063}
1064
1065void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
1066 if (TargetOptions && TargetOptions->MCNoWarn)
1067 return;
1068 if (TargetOptions && TargetOptions->MCFatalWarnings) {
1069 reportError(Loc, Msg);
1070 } else {
1071 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1072 D = SMP->GetMessage(Loc, SourceMgr::DK_Warning, Msg);
1073 });
1074 }
1075}
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:477
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:671
StringRef getLinkerPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:678
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:887
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:878
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:437
Environment getObjectFileType() const
Definition: MCContext.h:429
void setSymbolValue(MCStreamer &Streamer, const Twine &Sym, uint64_t Val)
Set value for a symbol.
Definition: MCContext.cpp:368
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
Definition: MCContext.h:713
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
Definition: MCContext.cpp:882
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:321
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
Definition: MCContext.h:696
void RemapDebugPaths()
Definition: MCContext.cpp:893
MCInst * createMCInst()
Create and return a new MC instruction.
Definition: MCContext.cpp:192
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:213
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
Definition: MCContext.cpp:504
MCSymbol * createLinkerPrivateTempSymbol()
Create a new linker temporary symbol with the specified prefix (Name) or "tmp".
Definition: MCContext.cpp:311
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
Definition: MCContext.h:646
void recordELFMergeableSectionInfo(StringRef SectionName, unsigned Flags, unsigned UniqueID, unsigned EntrySize)
Definition: MCContext.cpp:614
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:975
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:516
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:565
void diagnose(const SMDiagnostic &SMD)
Definition: MCContext.cpp:1013
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:986
void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
Definition: MCContext.cpp:374
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:731
void initInlineSourceManager()
Definition: MCContext.cpp:125
MCSymbol * getOrCreateParentFrameOffsetSymbol(const Twine &FuncName)
Definition: MCContext.cpp:219
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
Definition: MCContext.cpp:362
bool emitCompactUnwindNonCanonical() const
Definition: MCContext.cpp:928
CodeViewContext & getCVContext()
Definition: MCContext.cpp:1003
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:635
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
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:548
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:773
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:641
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
Definition: MCContext.cpp:349
void reportWarning(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1065
uint16_t getDwarfVersion() const
Definition: MCContext.h:831
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
Definition: MCContext.cpp:998
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1058
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:661
MCSymbol * getOrCreateLSDASymbol(const Twine &FuncName)
Definition: MCContext.cpp:224
MCSectionDXContainer * getDXContainerSection(StringRef Section, SectionKind K)
Get the section for the provided Section name.
Definition: MCContext.cpp:855
bool hasXCOFFSection(StringRef Section, XCOFF::CsectProperties CsectProp) const
Definition: MCContext.cpp:767
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:200
MCSymbol * createLinkerPrivateSymbol(const Twine &Name)
Definition: MCContext.cpp:315
MCSectionSPIRV * getSPIRVSection()
Definition: MCContext.cpp:843
EmitDwarfUnwindType emitDwarfUnwindInfo() const
Definition: MCContext.cpp:922
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Definition: MCContext.cpp:630
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
Definition: MCContext.cpp:607
void setGenDwarfRootFile(StringRef FileName, StringRef Buffer)
Specifies information about the "root file" for assembler clients (e.g., llvm-mc).
Definition: MCContext.cpp:934
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, const MCExpr *SubsectionId)
Definition: MCContext.cpp:649
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:700
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:755
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:354
MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
Definition: MCContext.cpp:323
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:569
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:26
void setSymbolTableName(StringRef STN)
Definition: MCSymbolXCOFF.h:57
StringRef getUnqualifiedName() const
Definition: MCSymbolXCOFF.h:45
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:261
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:577
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:941
void resize(size_type N)
Definition: SmallVector.h:642
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:234
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:287
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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:613
char front() const
front - Get the first character in the string.
Definition: StringRef.h:140
bool startswith(StringRef Prefix) const
Definition: StringRef.h:261
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:639
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:383
bool isUEFI() const
Tests whether the OS is UEFI.
Definition: Triple.h:578
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:583
@ DXContainer
Definition: Triple.h:285
@ UnknownObjectFormat
Definition: Triple.h:282
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:672
#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
@ STB_LOCAL
Definition: ELF.h:1246
@ SHT_GROUP
Definition: ELF.h:1018
@ SHT_NOBITS
Definition: ELF.h:1011
@ SHF_MERGE
Definition: ELF.h:1099
@ SHF_WRITE
Definition: ELF.h:1090
@ SHF_TLS
Definition: ELF.h:1118
@ SHF_ARM_PURECODE
Definition: ELF.h:1188
@ SHF_EXECINSTR
Definition: ELF.h:1096
@ STT_SECTION
Definition: ELF.h:1261
DwarfSectionSubtypeFlags
Values for defining the section subtype of sections of type STYP_DWARF as they would appear in the (s...
Definition: XCOFF.h:153
StringRef getMappingClassString(XCOFF::StorageMappingClass SMC)
Definition: XCOFF.cpp:20
@ XMC_PR
Program Code.
Definition: XCOFF.h:104
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:476
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:520
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:458
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:603
@ WASM_SYMBOL_TYPE_SECTION
Definition: Wasm.h:387
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:428
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:474