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