LLVM 17.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"
13#include "llvm/ADT/StringMap.h"
14#include "llvm/ADT/StringRef.h"
15#include "llvm/ADT/Twine.h"
20#include "llvm/MC/MCAsmInfo.h"
21#include "llvm/MC/MCCodeView.h"
22#include "llvm/MC/MCDwarf.h"
23#include "llvm/MC/MCExpr.h"
24#include "llvm/MC/MCFragment.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCLabel.h"
35#include "llvm/MC/MCStreamer.h"
37#include "llvm/MC/MCSymbol.h"
39#include "llvm/MC/MCSymbolELF.h"
45#include "llvm/MC/SectionKind.h"
50#include "llvm/Support/Path.h"
51#include "llvm/Support/SMLoc.h"
54#include <cassert>
55#include <cstdlib>
56#include <optional>
57#include <tuple>
58#include <utility>
59
60using namespace llvm;
61
62static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &,
63 std::vector<const MDNode *> &) {
64 SMD.print(nullptr, errs());
65}
66
67MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai,
68 const MCRegisterInfo *mri, const MCSubtargetInfo *msti,
69 const SourceMgr *mgr, MCTargetOptions const *TargetOpts,
70 bool DoAutoReset, StringRef Swift5ReflSegmentName)
71 : Swift5ReflectionSegmentName(Swift5ReflSegmentName), TT(TheTriple),
72 SrcMgr(mgr), InlineSrcMgr(nullptr), DiagHandler(defaultDiagHandler),
73 MAI(mai), MRI(mri), MSTI(msti), Symbols(Allocator), UsedNames(Allocator),
74 InlineAsmUsedLabelNames(Allocator),
75 CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
76 AutoReset(DoAutoReset), TargetOptions(TargetOpts) {
77 SecureLogFile = TargetOptions ? TargetOptions->AsSecureLogFile : "";
78
79 if (SrcMgr && SrcMgr->getNumBuffers())
80 MainFileName = std::string(SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())
82
83 switch (TheTriple.getObjectFormat()) {
84 case Triple::MachO:
85 Env = IsMachO;
86 break;
87 case Triple::COFF:
88 if (!TheTriple.isOSWindows() && !TheTriple.isUEFI())
90 "Cannot initialize MC for non-Windows COFF object files.");
91
92 Env = IsCOFF;
93 break;
94 case Triple::ELF:
95 Env = IsELF;
96 break;
97 case Triple::Wasm:
98 Env = IsWasm;
99 break;
100 case Triple::XCOFF:
101 Env = IsXCOFF;
102 break;
103 case Triple::GOFF:
104 Env = IsGOFF;
105 break;
107 Env = IsDXContainer;
108 break;
109 case Triple::SPIRV:
110 Env = IsSPIRV;
111 break;
113 report_fatal_error("Cannot initialize MC for unknown object file format.");
114 break;
115 }
116}
117
119 if (AutoReset)
120 reset();
121
122 // NOTE: The symbols are all allocated out of a bump pointer allocator,
123 // we don't need to free them here.
124}
125
127 if (!InlineSrcMgr)
128 InlineSrcMgr.reset(new SourceMgr());
129}
130
131//===----------------------------------------------------------------------===//
132// Module Lifetime Management
133//===----------------------------------------------------------------------===//
134
136 SrcMgr = nullptr;
137 InlineSrcMgr.reset();
138 LocInfos.clear();
139 DiagHandler = defaultDiagHandler;
140
141 // Call the destructors so the fragments are freed
142 COFFAllocator.DestroyAll();
143 DXCAllocator.DestroyAll();
144 ELFAllocator.DestroyAll();
145 GOFFAllocator.DestroyAll();
146 MachOAllocator.DestroyAll();
147 WasmAllocator.DestroyAll();
148 XCOFFAllocator.DestroyAll();
149 MCInstAllocator.DestroyAll();
150 SPIRVAllocator.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.startswith(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 SmallString<128> NameSV;
314 raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << "tmp";
315 return createSymbol(NameSV, true, false);
316}
317
319
321 return createNamedTempSymbol("tmp");
322}
323
324unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
325 MCLabel *&Label = Instances[LocalLabelVal];
326 if (!Label)
327 Label = new (*this) MCLabel(0);
328 return Label->incInstance();
329}
330
331unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
332 MCLabel *&Label = Instances[LocalLabelVal];
333 if (!Label)
334 Label = new (*this) MCLabel(0);
335 return Label->getInstance();
336}
337
338MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
339 unsigned Instance) {
340 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
341 if (!Sym)
343 return Sym;
344}
345
347 unsigned Instance = NextInstance(LocalLabelVal);
348 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
349}
350
352 bool Before) {
353 unsigned Instance = GetInstance(LocalLabelVal);
354 if (!Before)
355 ++Instance;
356 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
357}
358
360 SmallString<128> NameSV;
361 StringRef NameRef = Name.toStringRef(NameSV);
362 return Symbols.lookup(NameRef);
363}
364
366 uint64_t Val) {
367 auto Symbol = getOrCreateSymbol(Sym);
368 Streamer.emitAssignment(Symbol, MCConstantExpr::create(Val, *this));
369}
370
372 InlineAsmUsedLabelNames[Sym->getName()] = Sym;
373}
374
376MCContext::createXCOFFSymbolImpl(const StringMapEntry<bool> *Name,
377 bool IsTemporary) {
378 if (!Name)
379 return new (nullptr, *this) MCSymbolXCOFF(nullptr, IsTemporary);
380
381 StringRef OriginalName = Name->first();
382 if (OriginalName.startswith("._Renamed..") ||
383 OriginalName.startswith("_Renamed.."))
384 reportError(SMLoc(), "invalid symbol name from source");
385
386 if (MAI->isValidUnquotedName(OriginalName))
387 return new (Name, *this) MCSymbolXCOFF(Name, IsTemporary);
388
389 // Now we have a name that contains invalid character(s) for XCOFF symbol.
390 // Let's replace with something valid, but save the original name so that
391 // we could still use the original name in the symbol table.
392 SmallString<128> InvalidName(OriginalName);
393
394 // If it's an entry point symbol, we will keep the '.'
395 // in front for the convention purpose. Otherwise, add "_Renamed.."
396 // as prefix to signal this is an renamed symbol.
397 const bool IsEntryPoint = !InvalidName.empty() && InvalidName[0] == '.';
398 SmallString<128> ValidName =
399 StringRef(IsEntryPoint ? "._Renamed.." : "_Renamed..");
400
401 // Append the hex values of '_' and invalid characters with "_Renamed..";
402 // at the same time replace invalid characters with '_'.
403 for (size_t I = 0; I < InvalidName.size(); ++I) {
404 if (!MAI->isAcceptableChar(InvalidName[I]) || InvalidName[I] == '_') {
405 raw_svector_ostream(ValidName).write_hex(InvalidName[I]);
406 InvalidName[I] = '_';
407 }
408 }
409
410 // Skip entry point symbol's '.' as we already have a '.' in front of
411 // "_Renamed".
412 if (IsEntryPoint)
413 ValidName.append(InvalidName.substr(1, InvalidName.size() - 1));
414 else
415 ValidName.append(InvalidName);
416
417 auto NameEntry = UsedNames.insert(std::make_pair(ValidName.str(), true));
418 assert((NameEntry.second || !NameEntry.first->second) &&
419 "This name is used somewhere else.");
420 // Mark the name as used for a non-section symbol.
421 NameEntry.first->second = true;
422 // Have the MCSymbol object itself refer to the copy of the string
423 // that is embedded in the UsedNames entry.
424 MCSymbolXCOFF *XSym = new (&*NameEntry.first, *this)
425 MCSymbolXCOFF(&*NameEntry.first, IsTemporary);
427 return XSym;
428}
429
430//===----------------------------------------------------------------------===//
431// Section Management
432//===----------------------------------------------------------------------===//
433
435 unsigned TypeAndAttributes,
436 unsigned Reserved2, SectionKind Kind,
437 const char *BeginSymName) {
438 // We unique sections by their segment/section pair. The returned section
439 // may not have the same flags as the requested section, if so this should be
440 // diagnosed by the client as an error.
441
442 // Form the name to look up.
443 assert(Section.size() <= 16 && "section name is too long");
444 assert(!memchr(Section.data(), '\0', Section.size()) &&
445 "section name cannot contain NUL");
446
447 // Do the lookup, if we have a hit, return it.
448 auto R = MachOUniquingMap.try_emplace((Segment + Twine(',') + Section).str());
449 if (!R.second)
450 return R.first->second;
451
452 MCSymbol *Begin = nullptr;
453 if (BeginSymName)
454 Begin = createTempSymbol(BeginSymName, false);
455
456 // Otherwise, return a new section.
457 StringRef Name = R.first->first();
458 R.first->second = new (MachOAllocator.Allocate())
459 MCSectionMachO(Segment, Name.substr(Name.size() - Section.size()),
460 TypeAndAttributes, Reserved2, Kind, Begin);
461 return R.first->second;
462}
463
464MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
465 unsigned Flags, SectionKind K,
466 unsigned EntrySize,
467 const MCSymbolELF *Group,
468 bool Comdat, unsigned UniqueID,
469 const MCSymbolELF *LinkedToSym) {
470 MCSymbolELF *R;
471 MCSymbol *&Sym = Symbols[Section];
472 // A section symbol can not redefine regular symbols. There may be multiple
473 // sections with the same name, in which case the first such section wins.
474 if (Sym && Sym->isDefined() &&
475 (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
476 reportError(SMLoc(), "invalid symbol redefinition");
477 if (Sym && Sym->isUndefined()) {
478 R = cast<MCSymbolELF>(Sym);
479 } else {
480 auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first;
481 R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
482 if (!Sym)
483 Sym = R;
484 }
485 R->setBinding(ELF::STB_LOCAL);
486 R->setType(ELF::STT_SECTION);
487
488 auto *Ret = new (ELFAllocator.Allocate())
489 MCSectionELF(Section, Type, Flags, K, EntrySize, Group, Comdat, UniqueID,
490 R, LinkedToSym);
491
492 auto *F = new MCDataFragment();
493 Ret->getFragmentList().insert(Ret->begin(), F);
494 F->setParent(Ret);
495 R->setFragment(F);
496
497 return Ret;
498}
499
501MCContext::createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags,
502 unsigned EntrySize, const MCSymbolELF *Group,
503 const MCSectionELF *RelInfoSection) {
505 bool Inserted;
506 std::tie(I, Inserted) = RelSecNames.insert(std::make_pair(Name.str(), true));
507
508 return createELFSectionImpl(
509 I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
510 true, true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
511}
512
514 const Twine &Suffix, unsigned Type,
515 unsigned Flags,
516 unsigned EntrySize) {
517 return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix,
518 /*IsComdat=*/true);
519}
520
522 unsigned Flags, unsigned EntrySize,
523 const Twine &Group, bool IsComdat,
524 unsigned UniqueID,
525 const MCSymbolELF *LinkedToSym) {
526 MCSymbolELF *GroupSym = nullptr;
527 if (!Group.isTriviallyEmpty() && !Group.str().empty())
528 GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
529
530 return getELFSection(Section, Type, Flags, EntrySize, GroupSym, IsComdat,
531 UniqueID, LinkedToSym);
532}
533
535 unsigned Flags, unsigned EntrySize,
536 const MCSymbolELF *GroupSym,
537 bool IsComdat, unsigned UniqueID,
538 const MCSymbolELF *LinkedToSym) {
539 StringRef Group = "";
540 if (GroupSym)
541 Group = GroupSym->getName();
542 assert(!(LinkedToSym && LinkedToSym->getName().empty()));
543 // Do the lookup, if we have a hit, return it.
544 auto IterBool = ELFUniquingMap.insert(std::make_pair(
545 ELFSectionKey{Section.str(), Group,
546 LinkedToSym ? LinkedToSym->getName() : "", UniqueID},
547 nullptr));
548 auto &Entry = *IterBool.first;
549 if (!IterBool.second)
550 return Entry.second;
551
552 StringRef CachedName = Entry.first.SectionName;
553
554 SectionKind Kind;
557 else if (Flags & ELF::SHF_EXECINSTR)
558 Kind = SectionKind::getText();
559 else if (~Flags & ELF::SHF_WRITE)
561 else if (Flags & ELF::SHF_TLS)
564 else
565 // Default to `SectionKind::getText()`. This is the default for gas as
566 // well. The condition that falls into this case is where we do not have any
567 // section flags and must infer a classification rather than where we have
568 // section flags (i.e. this is not that SHF_EXECINSTR is unset bur rather it
569 // is unknown).
570 Kind = llvm::StringSwitch<SectionKind>(CachedName)
571 .Case(".bss", SectionKind::getBSS())
573 .StartsWith(".gnu.linkonce.b.", SectionKind::getBSS())
574 .StartsWith(".llvm.linkonce.b.", SectionKind::getBSS())
575 .Case(".data", SectionKind::getData())
576 .Case(".data1", SectionKind::getData())
577 .Case(".data.rel.ro", SectionKind::getReadOnlyWithRel())
578 .StartsWith(".data.", SectionKind::getData())
579 .Case(".rodata", SectionKind::getReadOnly())
580 .Case(".rodata1", SectionKind::getReadOnly())
584 .StartsWith(".gnu.linkonce.tb.", SectionKind::getThreadData())
585 .StartsWith(".llvm.linkonce.tb.", SectionKind::getThreadData())
586 .Case(".tdata", SectionKind::getThreadData())
588 .StartsWith(".gnu.linkonce.td.", SectionKind::getThreadData())
589 .StartsWith(".llvm.linkonce.td.", SectionKind::getThreadData())
592
593 MCSectionELF *Result =
594 createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
595 IsComdat, UniqueID, LinkedToSym);
596 Entry.second = Result;
597
598 recordELFMergeableSectionInfo(Result->getName(), Result->getFlags(),
599 Result->getUniqueID(), Result->getEntrySize());
600
601 return Result;
602}
603
605 bool IsComdat) {
606 return createELFSectionImpl(".group", ELF::SHT_GROUP, 0,
607 SectionKind::getReadOnly(), 4, Group, IsComdat,
608 MCSection::NonUniqueID, nullptr);
609}
610
612 unsigned Flags, unsigned UniqueID,
613 unsigned EntrySize) {
614 bool IsMergeable = Flags & ELF::SHF_MERGE;
615 if (UniqueID == GenericSectionID)
616 ELFSeenGenericMergeableSections.insert(SectionName);
617
618 // For mergeable sections or non-mergeable sections with a generic mergeable
619 // section name we enter their Unique ID into the ELFEntrySizeMap so that
620 // compatible globals can be assigned to the same section.
621 if (IsMergeable || isELFGenericMergeableSection(SectionName)) {
622 ELFEntrySizeMap.insert(std::make_pair(
623 ELFEntrySizeKey{SectionName, Flags, EntrySize}, UniqueID));
624 }
625}
626
628 return SectionName.startswith(".rodata.str") ||
629 SectionName.startswith(".rodata.cst");
630}
631
634 ELFSeenGenericMergeableSections.count(SectionName);
635}
636
637std::optional<unsigned>
639 unsigned EntrySize) {
640 auto I = ELFEntrySizeMap.find(
641 MCContext::ELFEntrySizeKey{SectionName, Flags, EntrySize});
642 return (I != ELFEntrySizeMap.end()) ? std::optional<unsigned>(I->second)
643 : std::nullopt;
644}
645
647 MCSection *Parent,
648 const MCExpr *SubsectionId) {
649 // Do the lookup. If we don't have a hit, return a new section.
650 auto &GOFFSection = GOFFUniquingMap[Section.str()];
651 if (!GOFFSection)
652 GOFFSection = new (GOFFAllocator.Allocate())
653 MCSectionGOFF(Section, Kind, Parent, SubsectionId);
654
655 return GOFFSection;
656}
657
659 unsigned Characteristics,
660 SectionKind Kind,
661 StringRef COMDATSymName, int Selection,
662 unsigned UniqueID,
663 const char *BeginSymName) {
664 MCSymbol *COMDATSymbol = nullptr;
665 if (!COMDATSymName.empty()) {
666 COMDATSymbol = getOrCreateSymbol(COMDATSymName);
667 COMDATSymName = COMDATSymbol->getName();
668 }
669
670 // Do the lookup, if we have a hit, return it.
671 COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
672 auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
673 auto Iter = IterBool.first;
674 if (!IterBool.second)
675 return Iter->second;
676
677 MCSymbol *Begin = nullptr;
678 if (BeginSymName)
679 Begin = createTempSymbol(BeginSymName, false);
680
681 StringRef CachedName = Iter->first.SectionName;
682 MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
683 CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
684
685 Iter->second = Result;
686 return Result;
687}
688
690 unsigned Characteristics,
691 SectionKind Kind,
692 const char *BeginSymName) {
693 return getCOFFSection(Section, Characteristics, Kind, "", 0, GenericSectionID,
694 BeginSymName);
695}
696
698 const MCSymbol *KeySym,
699 unsigned UniqueID) {
700 // Return the normal section if we don't have to be associative or unique.
701 if (!KeySym && UniqueID == GenericSectionID)
702 return Sec;
703
704 // If we have a key symbol, make an associative section with the same name and
705 // kind as the normal section.
706 unsigned Characteristics = Sec->getCharacteristics();
707 if (KeySym) {
709 return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(),
710 KeySym->getName(),
712 }
713
714 return getCOFFSection(Sec->getName(), Characteristics, Sec->getKind(), "", 0,
715 UniqueID);
716}
717
719 unsigned Flags, const Twine &Group,
720 unsigned UniqueID,
721 const char *BeginSymName) {
722 MCSymbolWasm *GroupSym = nullptr;
723 if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
724 GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
725 GroupSym->setComdat(true);
726 }
727
728 return getWasmSection(Section, K, Flags, GroupSym, UniqueID, BeginSymName);
729}
730
732 unsigned Flags,
733 const MCSymbolWasm *GroupSym,
734 unsigned UniqueID,
735 const char *BeginSymName) {
736 StringRef Group = "";
737 if (GroupSym)
738 Group = GroupSym->getName();
739 // Do the lookup, if we have a hit, return it.
740 auto IterBool = WasmUniquingMap.insert(
741 std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr));
742 auto &Entry = *IterBool.first;
743 if (!IterBool.second)
744 return Entry.second;
745
746 StringRef CachedName = Entry.first.SectionName;
747
748 MCSymbol *Begin = createSymbol(CachedName, true, false);
749 Symbols[Begin->getName()] = Begin;
750 cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
751
752 MCSectionWasm *Result = new (WasmAllocator.Allocate())
753 MCSectionWasm(CachedName, Kind, Flags, GroupSym, UniqueID, Begin);
754 Entry.second = Result;
755
756 auto *F = new MCDataFragment();
757 Result->getFragmentList().insert(Result->begin(), F);
758 F->setParent(Result);
759 Begin->setFragment(F);
760
761 return Result;
762}
763
765 XCOFF::CsectProperties CsectProp) const {
766 return XCOFFUniquingMap.count(
767 XCOFFSectionKey(Section.str(), CsectProp.MappingClass)) != 0;
768}
769
771 StringRef Section, SectionKind Kind,
772 std::optional<XCOFF::CsectProperties> CsectProp, bool MultiSymbolsAllowed,
773 const char *BeginSymName,
774 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSectionSubtypeFlags) {
775 bool IsDwarfSec = DwarfSectionSubtypeFlags.has_value();
776 assert((IsDwarfSec != CsectProp.has_value()) && "Invalid XCOFF section!");
777
778 // Do the lookup. If we have a hit, return it.
779 auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
780 IsDwarfSec ? XCOFFSectionKey(Section.str(), *DwarfSectionSubtypeFlags)
781 : XCOFFSectionKey(Section.str(), CsectProp->MappingClass),
782 nullptr));
783 auto &Entry = *IterBool.first;
784 if (!IterBool.second) {
785 MCSectionXCOFF *ExistedEntry = Entry.second;
786 if (ExistedEntry->isMultiSymbolsAllowed() != MultiSymbolsAllowed)
787 report_fatal_error("section's multiply symbols policy does not match");
788
789 return ExistedEntry;
790 }
791
792 // Otherwise, return a new section.
793 StringRef CachedName = Entry.first.SectionName;
794 MCSymbolXCOFF *QualName = nullptr;
795 // Debug section don't have storage class attribute.
796 if (IsDwarfSec)
797 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(CachedName));
798 else
799 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
800 CachedName + "[" +
801 XCOFF::getMappingClassString(CsectProp->MappingClass) + "]"));
802
803 MCSymbol *Begin = nullptr;
804 if (BeginSymName)
805 Begin = createTempSymbol(BeginSymName, false);
806
807 // QualName->getUnqualifiedName() and CachedName are the same except when
808 // CachedName contains invalid character(s) such as '$' for an XCOFF symbol.
809 MCSectionXCOFF *Result = nullptr;
810 if (IsDwarfSec)
811 Result = new (XCOFFAllocator.Allocate()) MCSectionXCOFF(
812 QualName->getUnqualifiedName(), Kind, QualName,
813 *DwarfSectionSubtypeFlags, Begin, CachedName, MultiSymbolsAllowed);
814 else
815 Result = new (XCOFFAllocator.Allocate())
816 MCSectionXCOFF(QualName->getUnqualifiedName(), CsectProp->MappingClass,
817 CsectProp->Type, Kind, QualName, Begin, CachedName,
818 MultiSymbolsAllowed);
819
820 Entry.second = Result;
821
822 auto *F = new MCDataFragment();
823 Result->getFragmentList().insert(Result->begin(), F);
824 F->setParent(Result);
825
826 if (Begin)
827 Begin->setFragment(F);
828
829 // We might miss calculating the symbols difference as absolute value before
830 // adding fixups when symbol_A without the fragment set is the csect itself
831 // and symbol_B is in it.
832 // TODO: Currently we only set the fragment for XMC_PR csects because we don't
833 // have other cases that hit this problem yet.
834 if (!IsDwarfSec && CsectProp->MappingClass == XCOFF::XMC_PR)
835 QualName->setFragment(F);
836
837 return Result;
838}
839
841 MCSymbol *Begin = nullptr;
842 MCSectionSPIRV *Result = new (SPIRVAllocator.Allocate())
844
845 auto *F = new MCDataFragment();
846 Result->getFragmentList().insert(Result->begin(), F);
847 F->setParent(Result);
848
849 return Result;
850}
851
853 SectionKind K) {
854 // Do the lookup, if we have a hit, return it.
855 auto ItInsertedPair = DXCUniquingMap.try_emplace(Section);
856 if (!ItInsertedPair.second)
857 return ItInsertedPair.first->second;
858
859 auto MapIt = ItInsertedPair.first;
860 // Grab the name from the StringMap. Since the Section is going to keep a
861 // copy of this StringRef we need to make sure the underlying string stays
862 // alive as long as we need it.
863 StringRef Name = MapIt->first();
864 MapIt->second =
865 new (DXCAllocator.Allocate()) MCSectionDXContainer(Name, K, nullptr);
866
867 // The first fragment will store the header
868 auto *F = new MCDataFragment();
869 MapIt->second->getFragmentList().insert(MapIt->second->begin(), F);
870 F->setParent(MapIt->second);
871
872 return MapIt->second;
873}
874
876 return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
877}
878
880 const std::string &To) {
881 DebugPrefixMap.emplace_back(From, To);
882}
883
885 for (const auto &[From, To] : llvm::reverse(DebugPrefixMap))
887 break;
888}
889
891 const auto &DebugPrefixMap = this->DebugPrefixMap;
892 if (DebugPrefixMap.empty())
893 return;
894
895 // Remap compilation directory.
896 remapDebugPath(CompilationDir);
897
898 // Remap MCDwarfDirs and RootFile.Name in all compilation units.
900 for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
901 for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
902 P = Dir;
904 Dir = std::string(P);
905 }
906
907 // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
908 // DW_AT_decl_file for DWARF v5 generated for assembly source.
909 P = CUIDTablePair.second.getRootFile().Name;
911 CUIDTablePair.second.getRootFile().Name = std::string(P);
912 }
913}
914
915//===----------------------------------------------------------------------===//
916// Dwarf Management
917//===----------------------------------------------------------------------===//
918
920 if (!TargetOptions)
922 return TargetOptions->EmitDwarfUnwind;
923}
924
926 if (TargetOptions)
927 return TargetOptions->EmitCompactUnwindNonCanonical;
928 return false;
929}
930
932 // MCDwarf needs the root file as well as the compilation directory.
933 // If we find a '.file 0' directive that will supersede these values.
934 std::optional<MD5::MD5Result> Cksum;
935 if (getDwarfVersion() >= 5) {
936 MD5 Hash;
937 MD5::MD5Result Sum;
938 Hash.update(Buffer);
939 Hash.final(Sum);
940 Cksum = Sum;
941 }
942 // Canonicalize the root filename. It cannot be empty, and should not
943 // repeat the compilation dir.
944 // The MCContext ctor initializes MainFileName to the name associated with
945 // the SrcMgr's main file ID, which might be the same as InputFileName (and
946 // possibly include directory components).
947 // Or, MainFileName might have been overridden by a -main-file-name option,
948 // which is supposed to be just a base filename with no directory component.
949 // So, if the InputFileName and MainFileName are not equal, assume
950 // MainFileName is a substitute basename and replace the last component.
951 SmallString<1024> FileNameBuf = InputFileName;
952 if (FileNameBuf.empty() || FileNameBuf == "-")
953 FileNameBuf = "<stdin>";
954 if (!getMainFileName().empty() && FileNameBuf != getMainFileName()) {
957 }
958 StringRef FileName = FileNameBuf;
959 if (FileName.consume_front(getCompilationDir()))
960 if (llvm::sys::path::is_separator(FileName.front()))
961 FileName = FileName.drop_front();
962 assert(!FileName.empty());
964 /*CUID=*/0, getCompilationDir(), FileName, Cksum, std::nullopt);
965}
966
967/// getDwarfFile - takes a file name and number to place in the dwarf file and
968/// directory tables. If the file number has already been allocated it is an
969/// error and zero is returned and the client reports the error, else the
970/// allocated file number is returned. The file numbers may be in any order.
973 unsigned FileNumber,
974 std::optional<MD5::MD5Result> Checksum,
975 std::optional<StringRef> Source, unsigned CUID) {
976 MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
977 return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
978 FileNumber);
979}
980
981/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
982/// currently is assigned and false otherwise.
983bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
984 const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
985 if (FileNumber == 0)
986 return getDwarfVersion() >= 5;
987 if (FileNumber >= LineTable.getMCDwarfFiles().size())
988 return false;
989
990 return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
991}
992
993/// Remove empty sections from SectionsForRanges, to avoid generating
994/// useless debug info for them.
996 SectionsForRanges.remove_if(
997 [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
998}
999
1001 if (!CVContext)
1002 CVContext.reset(new CodeViewContext);
1003 return *CVContext;
1004}
1005
1006//===----------------------------------------------------------------------===//
1007// Error Reporting
1008//===----------------------------------------------------------------------===//
1009
1011 assert(DiagHandler && "MCContext::DiagHandler is not set");
1012 bool UseInlineSrcMgr = false;
1013 const SourceMgr *SMP = nullptr;
1014 if (SrcMgr) {
1015 SMP = SrcMgr;
1016 } else if (InlineSrcMgr) {
1017 SMP = InlineSrcMgr.get();
1018 UseInlineSrcMgr = true;
1019 } else
1020 llvm_unreachable("Either SourceMgr should be available");
1021 DiagHandler(SMD, UseInlineSrcMgr, *SMP, LocInfos);
1022}
1023
1024void MCContext::reportCommon(
1025 SMLoc Loc,
1026 std::function<void(SMDiagnostic &, const SourceMgr *)> GetMessage) {
1027 // * MCContext::SrcMgr is null when the MC layer emits machine code for input
1028 // other than assembly file, say, for .c/.cpp/.ll/.bc.
1029 // * MCContext::InlineSrcMgr is null when the inline asm is not used.
1030 // * A default SourceMgr is needed for diagnosing when both MCContext::SrcMgr
1031 // and MCContext::InlineSrcMgr are null.
1032 SourceMgr SM;
1033 const SourceMgr *SMP = &SM;
1034 bool UseInlineSrcMgr = false;
1035
1036 // FIXME: Simplify these by combining InlineSrcMgr & SrcMgr.
1037 // For MC-only execution, only SrcMgr is used;
1038 // For non MC-only execution, InlineSrcMgr is only ctor'd if there is
1039 // inline asm in the IR.
1040 if (Loc.isValid()) {
1041 if (SrcMgr) {
1042 SMP = SrcMgr;
1043 } else if (InlineSrcMgr) {
1044 SMP = InlineSrcMgr.get();
1045 UseInlineSrcMgr = true;
1046 } else
1047 llvm_unreachable("Either SourceMgr should be available");
1048 }
1049
1051 GetMessage(D, SMP);
1052 DiagHandler(D, UseInlineSrcMgr, *SMP, LocInfos);
1053}
1054
1055void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
1056 HadError = true;
1057 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1058 D = SMP->GetMessage(Loc, SourceMgr::DK_Error, Msg);
1059 });
1060}
1061
1062void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
1063 if (TargetOptions && TargetOptions->MCNoWarn)
1064 return;
1065 if (TargetOptions && TargetOptions->MCFatalWarnings) {
1066 reportError(Loc, Msg);
1067 } else {
1068 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1069 D = SMP->GetMessage(Loc, SourceMgr::DK_Warning, Msg);
1070 });
1071 }
1072}
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
This file defines DenseMapInfo traits for DenseMap.
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:463
static void defaultDiagHandler(const SMDiagnostic &SMD, bool, const SourceMgr &, std::vector< const MDNode * > &)
Definition: MCContext.cpp:62
#define DWARF2_FLAG_IS_STMT
Definition: MCDwarf.h:113
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.
@ Flags
Definition: TextStubV5.cpp:93
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
Definition: TextStub.cpp:1080
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:470
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:668
StringRef getLinkerPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:675
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
Definition: MCAsmInfo.cpp:116
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:123
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:884
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:875
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:434
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:365
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
Definition: MCContext.h:711
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
Definition: MCContext.cpp:879
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:318
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
Definition: MCContext.h:694
void RemapDebugPaths()
Definition: MCContext.cpp:890
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:501
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:312
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
Definition: MCContext.h:644
void recordELFMergeableSectionInfo(StringRef SectionName, unsigned Flags, unsigned UniqueID, unsigned EntrySize)
Definition: MCContext.cpp:611
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:972
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:513
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:563
void diagnose(const SMDiagnostic &SMD)
Definition: MCContext.cpp:1010
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:983
void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
Definition: MCContext.cpp:371
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:729
void initInlineSourceManager()
Definition: MCContext.cpp:126
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:359
bool emitCompactUnwindNonCanonical() const
Definition: MCContext.cpp:925
CodeViewContext & getCVContext()
Definition: MCContext.cpp:1000
void reset()
reset - return object to right after construction state to prepare to process a new module
Definition: MCContext.cpp:135
bool isELFGenericMergeableSection(StringRef Name)
Definition: MCContext.cpp:632
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:67
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:770
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:638
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
Definition: MCContext.cpp:346
void reportWarning(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1062
uint16_t getDwarfVersion() const
Definition: MCContext.h:829
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:546
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
Definition: MCContext.cpp:995
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1055
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:658
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:852
bool hasXCOFFSection(StringRef Section, XCOFF::CsectProperties CsectProp) const
Definition: MCContext.cpp:764
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:201
MCSectionSPIRV * getSPIRVSection()
Definition: MCContext.cpp:840
EmitDwarfUnwindType emitDwarfUnwindInfo() const
Definition: MCContext.cpp:919
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Definition: MCContext.cpp:627
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
Definition: MCContext.cpp:604
void setGenDwarfRootFile(StringRef FileName, StringRef Buffer)
Specifies information about the "root file" for assembler clients (e.g., llvm-mc).
Definition: MCContext.cpp:931
MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, const MCExpr *SubsectionId)
Definition: MCContext.cpp:646
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:697
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:753
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:351
MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
Definition: MCContext.cpp:320
Fragment for data and encoded instructions.
Definition: MCFragment.h:241
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:565
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:413
Instances of this class represent the information from a dwarf .loc directive.
Definition: MCDwarf.h:101
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:1130
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:41
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:206
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:276
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
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:233
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:286
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:585
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:590
@ 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:417
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:304
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition: COFF.h:421
@ SHF_MERGE
Definition: ELF.h:1094
@ SHF_WRITE
Definition: ELF.h:1085
@ SHF_TLS
Definition: ELF.h:1113
@ SHF_ARM_PURECODE
Definition: ELF.h:1183
@ SHF_EXECINSTR
Definition: ELF.h:1091
@ SHT_GROUP
Definition: ELF.h:1014
@ SHT_NOBITS
Definition: ELF.h:1007
@ STB_LOCAL
Definition: ELF.h:1241
@ STT_SECTION
Definition: ELF.h:1256
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: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:386
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:511
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
EmitDwarfUnwindType
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
StorageMappingClass MappingClass
Definition: XCOFF.h:473