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())
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(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
217 "$frame_escape_" + Twine(Idx));
218}
219
221 return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
222 "$parent_frame_offset");
223}
224
226 return getOrCreateSymbol(Twine(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) MCSymbol(MCSymbol::SymbolKindUnset, Name,
263 IsTemporary);
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)
342 Sym = createNamedTempSymbol();
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 StringRef Sym,
367 uint64_t Val) {
368 auto Symbol = getOrCreateSymbol(Sym);
369 Streamer.emitAssignment(Symbol, MCConstantExpr::create(Val, *this));
370}
371
373 InlineAsmUsedLabelNames[Sym->getName()] = Sym;
374}
375
377MCContext::createXCOFFSymbolImpl(const StringMapEntry<bool> *Name,
378 bool IsTemporary) {
379 if (!Name)
380 return new (nullptr, *this) MCSymbolXCOFF(nullptr, IsTemporary);
381
382 StringRef OriginalName = Name->first();
383 if (OriginalName.startswith("._Renamed..") ||
384 OriginalName.startswith("_Renamed.."))
385 reportError(SMLoc(), "invalid symbol name from source");
386
387 if (MAI->isValidUnquotedName(OriginalName))
388 return new (Name, *this) MCSymbolXCOFF(Name, IsTemporary);
389
390 // Now we have a name that contains invalid character(s) for XCOFF symbol.
391 // Let's replace with something valid, but save the original name so that
392 // we could still use the original name in the symbol table.
393 SmallString<128> InvalidName(OriginalName);
394
395 // If it's an entry point symbol, we will keep the '.'
396 // in front for the convention purpose. Otherwise, add "_Renamed.."
397 // as prefix to signal this is an renamed symbol.
398 const bool IsEntryPoint = !InvalidName.empty() && InvalidName[0] == '.';
399 SmallString<128> ValidName =
400 StringRef(IsEntryPoint ? "._Renamed.." : "_Renamed..");
401
402 // Append the hex values of '_' and invalid characters with "_Renamed..";
403 // at the same time replace invalid characters with '_'.
404 for (size_t I = 0; I < InvalidName.size(); ++I) {
405 if (!MAI->isAcceptableChar(InvalidName[I]) || InvalidName[I] == '_') {
406 raw_svector_ostream(ValidName).write_hex(InvalidName[I]);
407 InvalidName[I] = '_';
408 }
409 }
410
411 // Skip entry point symbol's '.' as we already have a '.' in front of
412 // "_Renamed".
413 if (IsEntryPoint)
414 ValidName.append(InvalidName.substr(1, InvalidName.size() - 1));
415 else
416 ValidName.append(InvalidName);
417
418 auto NameEntry = UsedNames.insert(std::make_pair(ValidName.str(), true));
419 assert((NameEntry.second || !NameEntry.first->second) &&
420 "This name is used somewhere else.");
421 // Mark the name as used for a non-section symbol.
422 NameEntry.first->second = true;
423 // Have the MCSymbol object itself refer to the copy of the string
424 // that is embedded in the UsedNames entry.
425 MCSymbolXCOFF *XSym = new (&*NameEntry.first, *this)
426 MCSymbolXCOFF(&*NameEntry.first, IsTemporary);
428 return XSym;
429}
430
431//===----------------------------------------------------------------------===//
432// Section Management
433//===----------------------------------------------------------------------===//
434
436 unsigned TypeAndAttributes,
437 unsigned Reserved2, SectionKind Kind,
438 const char *BeginSymName) {
439 // We unique sections by their segment/section pair. The returned section
440 // may not have the same flags as the requested section, if so this should be
441 // diagnosed by the client as an error.
442
443 // Form the name to look up.
444 assert(Section.size() <= 16 && "section name is too long");
445 assert(!memchr(Section.data(), '\0', Section.size()) &&
446 "section name cannot contain NUL");
447
448 // Do the lookup, if we have a hit, return it.
449 auto R = MachOUniquingMap.try_emplace((Segment + Twine(',') + Section).str());
450 if (!R.second)
451 return R.first->second;
452
453 MCSymbol *Begin = nullptr;
454 if (BeginSymName)
455 Begin = createTempSymbol(BeginSymName, false);
456
457 // Otherwise, return a new section.
458 StringRef Name = R.first->first();
459 R.first->second = new (MachOAllocator.Allocate())
460 MCSectionMachO(Segment, Name.substr(Name.size() - Section.size()),
461 TypeAndAttributes, Reserved2, Kind, Begin);
462 return R.first->second;
463}
464
465MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
466 unsigned Flags, SectionKind K,
467 unsigned EntrySize,
468 const MCSymbolELF *Group,
469 bool Comdat, unsigned UniqueID,
470 const MCSymbolELF *LinkedToSym) {
471 MCSymbolELF *R;
472 MCSymbol *&Sym = Symbols[Section];
473 // A section symbol can not redefine regular symbols. There may be multiple
474 // sections with the same name, in which case the first such section wins.
475 if (Sym && Sym->isDefined() &&
476 (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
477 reportError(SMLoc(), "invalid symbol redefinition");
478 if (Sym && Sym->isUndefined()) {
479 R = cast<MCSymbolELF>(Sym);
480 } else {
481 auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first;
482 R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
483 if (!Sym)
484 Sym = R;
485 }
486 R->setBinding(ELF::STB_LOCAL);
487 R->setType(ELF::STT_SECTION);
488
489 auto *Ret = new (ELFAllocator.Allocate())
490 MCSectionELF(Section, Type, Flags, K, EntrySize, Group, Comdat, UniqueID,
491 R, LinkedToSym);
492
493 auto *F = new MCDataFragment();
494 Ret->getFragmentList().insert(Ret->begin(), F);
495 F->setParent(Ret);
496 R->setFragment(F);
497
498 return Ret;
499}
500
502 unsigned Flags, unsigned EntrySize,
503 const MCSymbolELF *Group,
504 const MCSectionELF *RelInfoSection) {
506 bool Inserted;
507 std::tie(I, Inserted) =
508 RelSecNames.insert(std::make_pair(Name.str(), true));
509
510 return createELFSectionImpl(
511 I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
512 true, true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
513}
514
516 const Twine &Suffix, unsigned Type,
517 unsigned Flags,
518 unsigned EntrySize) {
519 return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix,
520 /*IsComdat=*/true);
521}
522
524 unsigned Flags, unsigned EntrySize,
525 const Twine &Group, bool IsComdat,
526 unsigned UniqueID,
527 const MCSymbolELF *LinkedToSym) {
528 MCSymbolELF *GroupSym = nullptr;
529 if (!Group.isTriviallyEmpty() && !Group.str().empty())
530 GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
531
532 return getELFSection(Section, Type, Flags, EntrySize, GroupSym, IsComdat,
533 UniqueID, LinkedToSym);
534}
535
537 unsigned Flags, unsigned EntrySize,
538 const MCSymbolELF *GroupSym,
539 bool IsComdat, unsigned UniqueID,
540 const MCSymbolELF *LinkedToSym) {
541 StringRef Group = "";
542 if (GroupSym)
543 Group = GroupSym->getName();
544 assert(!(LinkedToSym && LinkedToSym->getName().empty()));
545 // Do the lookup, if we have a hit, return it.
546 auto IterBool = ELFUniquingMap.insert(std::make_pair(
547 ELFSectionKey{Section.str(), Group,
548 LinkedToSym ? LinkedToSym->getName() : "", UniqueID},
549 nullptr));
550 auto &Entry = *IterBool.first;
551 if (!IterBool.second)
552 return Entry.second;
553
554 StringRef CachedName = Entry.first.SectionName;
555
556 SectionKind Kind;
557 if (Flags & ELF::SHF_ARM_PURECODE)
559 else if (Flags & ELF::SHF_EXECINSTR)
560 Kind = SectionKind::getText();
561 else if (~Flags & ELF::SHF_WRITE)
563 else if (Flags & ELF::SHF_TLS)
566 else
567 // Default to `SectionKind::getText()`. This is the default for gas as
568 // well. The condition that falls into this case is where we do not have any
569 // section flags and must infer a classification rather than where we have
570 // section flags (i.e. this is not that SHF_EXECINSTR is unset bur rather it
571 // is unknown).
572 Kind = llvm::StringSwitch<SectionKind>(CachedName)
573 .Case(".bss", SectionKind::getBSS())
575 .StartsWith(".gnu.linkonce.b.", SectionKind::getBSS())
576 .StartsWith(".llvm.linkonce.b.", SectionKind::getBSS())
577 .Case(".data", SectionKind::getData())
578 .Case(".data1", SectionKind::getData())
579 .Case(".data.rel.ro", SectionKind::getReadOnlyWithRel())
580 .StartsWith(".data.", SectionKind::getData())
581 .Case(".rodata", SectionKind::getReadOnly())
582 .Case(".rodata1", SectionKind::getReadOnly())
586 .StartsWith(".gnu.linkonce.tb.", SectionKind::getThreadData())
587 .StartsWith(".llvm.linkonce.tb.", SectionKind::getThreadData())
588 .Case(".tdata", SectionKind::getThreadData())
590 .StartsWith(".gnu.linkonce.td.", SectionKind::getThreadData())
591 .StartsWith(".llvm.linkonce.td.", SectionKind::getThreadData())
594
595 MCSectionELF *Result =
596 createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
597 IsComdat, UniqueID, LinkedToSym);
598 Entry.second = Result;
599
600 recordELFMergeableSectionInfo(Result->getName(), Result->getFlags(),
601 Result->getUniqueID(), Result->getEntrySize());
602
603 return Result;
604}
605
607 bool IsComdat) {
608 return createELFSectionImpl(".group", ELF::SHT_GROUP, 0,
609 SectionKind::getReadOnly(), 4, Group, IsComdat,
610 MCSection::NonUniqueID, nullptr);
611}
612
614 unsigned Flags, unsigned UniqueID,
615 unsigned EntrySize) {
616 bool IsMergeable = Flags & ELF::SHF_MERGE;
617 if (UniqueID == GenericSectionID)
618 ELFSeenGenericMergeableSections.insert(SectionName);
619
620 // For mergeable sections or non-mergeable sections with a generic mergeable
621 // section name we enter their Unique ID into the ELFEntrySizeMap so that
622 // compatible globals can be assigned to the same section.
623 if (IsMergeable || isELFGenericMergeableSection(SectionName)) {
624 ELFEntrySizeMap.insert(std::make_pair(
625 ELFEntrySizeKey{SectionName, Flags, EntrySize}, UniqueID));
626 }
627}
628
630 return SectionName.startswith(".rodata.str") ||
631 SectionName.startswith(".rodata.cst");
632}
633
636 ELFSeenGenericMergeableSections.count(SectionName);
637}
638
639std::optional<unsigned>
641 unsigned EntrySize) {
642 auto I = ELFEntrySizeMap.find(
643 MCContext::ELFEntrySizeKey{SectionName, Flags, EntrySize});
644 return (I != ELFEntrySizeMap.end()) ? std::optional<unsigned>(I->second)
645 : std::nullopt;
646}
647
649 MCSection *Parent,
650 const MCExpr *SubsectionId) {
651 // Do the lookup. If we don't have a hit, return a new section.
652 auto &GOFFSection = GOFFUniquingMap[Section.str()];
653 if (!GOFFSection)
654 GOFFSection = new (GOFFAllocator.Allocate())
655 MCSectionGOFF(Section, Kind, Parent, SubsectionId);
656
657 return GOFFSection;
658}
659
661 unsigned Characteristics,
662 SectionKind Kind,
663 StringRef COMDATSymName, int Selection,
664 unsigned UniqueID,
665 const char *BeginSymName) {
666 MCSymbol *COMDATSymbol = nullptr;
667 if (!COMDATSymName.empty()) {
668 COMDATSymbol = getOrCreateSymbol(COMDATSymName);
669 COMDATSymName = COMDATSymbol->getName();
670 }
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 if (Begin)
853 Begin->setFragment(F);
854
855 return Result;
856}
857
859 SectionKind K) {
860 // Do the lookup, if we have a hit, return it.
861 auto ItInsertedPair = DXCUniquingMap.try_emplace(Section);
862 if (!ItInsertedPair.second)
863 return ItInsertedPair.first->second;
864
865 auto MapIt = ItInsertedPair.first;
866 // Grab the name from the StringMap. Since the Section is going to keep a
867 // copy of this StringRef we need to make sure the underlying string stays
868 // alive as long as we need it.
869 StringRef Name = MapIt->first();
870 MapIt->second =
871 new (DXCAllocator.Allocate()) MCSectionDXContainer(Name, K, nullptr);
872
873 // The first fragment will store the header
874 auto *F = new MCDataFragment();
875 MapIt->second->getFragmentList().insert(MapIt->second->begin(), F);
876 F->setParent(MapIt->second);
877
878 return MapIt->second;
879}
880
882 return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
883}
884
886 const std::string &To) {
887 DebugPrefixMap.insert(std::make_pair(From, To));
888}
889
891 for (const auto &[From, To] : DebugPrefixMap)
893 break;
894}
895
897 const auto &DebugPrefixMap = this->DebugPrefixMap;
898 if (DebugPrefixMap.empty())
899 return;
900
901 // Remap compilation directory.
902 remapDebugPath(CompilationDir);
903
904 // Remap MCDwarfDirs and RootFile.Name in all compilation units.
906 for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
907 for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
908 P = Dir;
910 Dir = std::string(P);
911 }
912
913 // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
914 // DW_AT_decl_file for DWARF v5 generated for assembly source.
915 P = CUIDTablePair.second.getRootFile().Name;
917 CUIDTablePair.second.getRootFile().Name = std::string(P);
918 }
919}
920
921//===----------------------------------------------------------------------===//
922// Dwarf Management
923//===----------------------------------------------------------------------===//
924
926 if (!TargetOptions)
928 return TargetOptions->EmitDwarfUnwind;
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:330
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
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.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
Definition: TextStub.cpp:1094
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:890
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:881
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:435
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
Definition: MCContext.cpp:225
Environment getObjectFileType() const
Definition: MCContext.h:429
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:885
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:896
MCInst * createMCInst()
Create and return a new MC instruction.
Definition: MCContext.cpp:193
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:613
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:515
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:372
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
Definition: MCContext.cpp:365
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:729
void initInlineSourceManager()
Definition: MCContext.cpp:126
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
Definition: MCContext.cpp:359
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:634
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: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:640
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:828
@ 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:660
MCSectionDXContainer * getDXContainerSection(StringRef Section, SectionKind K)
Get the section for the provided Section name.
Definition: MCContext.cpp:858
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:201
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
Definition: MCContext.cpp:220
MCSectionSPIRV * getSPIRVSection()
Definition: MCContext.cpp:843
EmitDwarfUnwindType emitDwarfUnwindInfo() const
Definition: MCContext.cpp:925
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Definition: MCContext.cpp:629
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
Definition: MCContext.cpp:606
MCSymbol * getOrCreateFrameAllocSymbol(StringRef 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
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:648
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: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:562
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
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:248
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
Definition: MCSymbol.h:252
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:273
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:257
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:267
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
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:275
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:597
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:623
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:381
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:583
@ DXContainer
Definition: Triple.h:283
@ UnknownObjectFormat
Definition: Triple.h:280
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:294
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition: COFF.h:411
@ SHF_MERGE
Definition: ELF.h:1089
@ SHF_WRITE
Definition: ELF.h:1080
@ SHF_TLS
Definition: ELF.h:1108
@ SHF_ARM_PURECODE
Definition: ELF.h:1178
@ SHF_EXECINSTR
Definition: ELF.h:1086
@ SHT_GROUP
Definition: ELF.h:1009
@ SHT_NOBITS
Definition: ELF.h:1002
@ STB_LOCAL
Definition: ELF.h:1236
@ STT_SECTION
Definition: ELF.h:1251
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:474
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:518
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:456
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:601
@ 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
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