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