LLVM 19.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.addFragment(*F);
205 return F;
206}
207
208//===----------------------------------------------------------------------===//
209// Symbol Manipulation
210//===----------------------------------------------------------------------===//
211
213 SmallString<128> NameSV;
214 StringRef NameRef = Name.toStringRef(NameSV);
215
216 assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
217
218 MCSymbolTableEntry &Entry = getSymbolTableEntry(NameRef);
219 if (!Entry.second.Symbol) {
220 bool IsRenamable = NameRef.starts_with(MAI->getPrivateGlobalPrefix());
221 bool IsTemporary = IsRenamable && !SaveTempLabels;
222 if (!Entry.second.Used) {
223 Entry.second.Used = true;
224 Entry.second.Symbol = createSymbolImpl(&Entry, IsTemporary);
225 } else {
226 assert(IsRenamable && "cannot rename non-private symbol");
227 // Slow path: we need to rename a temp symbol from the user.
228 Entry.second.Symbol = createRenamableSymbol(NameRef, false, IsTemporary);
229 }
230 }
231
232 return Entry.second.Symbol;
233}
234
236 unsigned Idx) {
237 return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + FuncName +
238 "$frame_escape_" + Twine(Idx));
239}
240
242 return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + FuncName +
243 "$parent_frame_offset");
244}
245
247 return getOrCreateSymbol(MAI->getPrivateGlobalPrefix() + "__ehtable$" +
248 FuncName);
249}
250
251MCSymbolTableEntry &MCContext::getSymbolTableEntry(StringRef Name) {
252 return *Symbols.try_emplace(Name, MCSymbolTableValue{}).first;
253}
254
255MCSymbol *MCContext::createSymbolImpl(const MCSymbolTableEntry *Name,
256 bool IsTemporary) {
257 static_assert(std::is_trivially_destructible<MCSymbolCOFF>(),
258 "MCSymbol classes must be trivially destructible");
259 static_assert(std::is_trivially_destructible<MCSymbolELF>(),
260 "MCSymbol classes must be trivially destructible");
261 static_assert(std::is_trivially_destructible<MCSymbolMachO>(),
262 "MCSymbol classes must be trivially destructible");
263 static_assert(std::is_trivially_destructible<MCSymbolWasm>(),
264 "MCSymbol classes must be trivially destructible");
265 static_assert(std::is_trivially_destructible<MCSymbolXCOFF>(),
266 "MCSymbol classes must be trivially destructible");
267
268 switch (getObjectFileType()) {
270 return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
271 case MCContext::IsELF:
272 return new (Name, *this) MCSymbolELF(Name, IsTemporary);
274 return new (Name, *this) MCSymbolGOFF(Name, IsTemporary);
276 return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
278 return new (Name, *this) MCSymbolWasm(Name, IsTemporary);
280 return createXCOFFSymbolImpl(Name, IsTemporary);
282 break;
284 return new (Name, *this)
286 }
287 return new (Name, *this)
289}
290
291MCSymbol *MCContext::createRenamableSymbol(const Twine &Name,
292 bool AlwaysAddSuffix,
293 bool IsTemporary) {
294 SmallString<128> NewName;
295 Name.toVector(NewName);
296 size_t NameLen = NewName.size();
297
298 MCSymbolTableEntry &NameEntry = getSymbolTableEntry(NewName.str());
299 MCSymbolTableEntry *EntryPtr = &NameEntry;
300 while (AlwaysAddSuffix || EntryPtr->second.Used) {
301 AlwaysAddSuffix = false;
302
303 NewName.resize(NameLen);
304 raw_svector_ostream(NewName) << NameEntry.second.NextUniqueID++;
305 EntryPtr = &getSymbolTableEntry(NewName.str());
306 }
307
308 EntryPtr->second.Used = true;
309 return createSymbolImpl(EntryPtr, IsTemporary);
310}
311
312MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix) {
313 if (!UseNamesOnTempLabels)
314 return createSymbolImpl(nullptr, /*IsTemporary=*/true);
315 return createRenamableSymbol(MAI->getPrivateGlobalPrefix() + Name,
316 AlwaysAddSuffix, /*IsTemporary=*/true);
317}
318
320 return createRenamableSymbol(MAI->getPrivateGlobalPrefix() + Name, true,
321 /*IsTemporary=*/!SaveTempLabels);
322}
323
325 if (AlwaysEmit)
327
328 bool IsTemporary = !SaveTempLabels;
329 if (IsTemporary && !UseNamesOnTempLabels)
330 return createSymbolImpl(nullptr, IsTemporary);
331 return createRenamableSymbol(MAI->getPrivateLabelPrefix() + Name,
332 /*AlwaysAddSuffix=*/false, IsTemporary);
333}
334
336 return createLinkerPrivateSymbol("tmp");
337}
338
340 return createRenamableSymbol(MAI->getLinkerPrivateGlobalPrefix() + Name,
341 /*AlwaysAddSuffix=*/true,
342 /*IsTemporary=*/false);
343}
344
346
348 return createNamedTempSymbol("tmp");
349}
350
351unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
352 MCLabel *&Label = Instances[LocalLabelVal];
353 if (!Label)
354 Label = new (*this) MCLabel(0);
355 return Label->incInstance();
356}
357
358unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
359 MCLabel *&Label = Instances[LocalLabelVal];
360 if (!Label)
361 Label = new (*this) MCLabel(0);
362 return Label->getInstance();
363}
364
365MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
366 unsigned Instance) {
367 MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
368 if (!Sym)
370 return Sym;
371}
372
374 unsigned Instance = NextInstance(LocalLabelVal);
375 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
376}
377
379 bool Before) {
380 unsigned Instance = GetInstance(LocalLabelVal);
381 if (!Before)
382 ++Instance;
383 return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
384}
385
386template <typename Symbol>
387Symbol *MCContext::getOrCreateSectionSymbol(StringRef Section) {
388 Symbol *R;
389 auto &SymEntry = getSymbolTableEntry(Section);
390 MCSymbol *Sym = SymEntry.second.Symbol;
391 // A section symbol can not redefine regular symbols. There may be multiple
392 // sections with the same name, in which case the first such section wins.
393 if (Sym && Sym->isDefined() &&
394 (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
395 reportError(SMLoc(), "invalid symbol redefinition");
396 if (Sym && Sym->isUndefined()) {
397 R = cast<Symbol>(Sym);
398 } else {
399 SymEntry.second.Used = true;
400 R = new (&SymEntry, *this) Symbol(&SymEntry, /*isTemporary=*/false);
401 if (!Sym)
402 SymEntry.second.Symbol = R;
403 }
404 return R;
405}
406
408 SmallString<128> NameSV;
409 StringRef NameRef = Name.toStringRef(NameSV);
410 return Symbols.lookup(NameRef).Symbol;
411}
412
414 uint64_t Val) {
415 auto Symbol = getOrCreateSymbol(Sym);
416 Streamer.emitAssignment(Symbol, MCConstantExpr::create(Val, *this));
417}
418
420 InlineAsmUsedLabelNames[Sym->getName()] = Sym;
421}
422
424 return new (WasmSignatureAllocator.Allocate()) wasm::WasmSignature;
425}
426
427MCSymbolXCOFF *MCContext::createXCOFFSymbolImpl(const MCSymbolTableEntry *Name,
428 bool IsTemporary) {
429 if (!Name)
430 return new (nullptr, *this) MCSymbolXCOFF(nullptr, IsTemporary);
431
432 StringRef OriginalName = Name->first();
433 if (OriginalName.starts_with("._Renamed..") ||
434 OriginalName.starts_with("_Renamed.."))
435 reportError(SMLoc(), "invalid symbol name from source");
436
437 if (MAI->isValidUnquotedName(OriginalName))
438 return new (Name, *this) MCSymbolXCOFF(Name, IsTemporary);
439
440 // Now we have a name that contains invalid character(s) for XCOFF symbol.
441 // Let's replace with something valid, but save the original name so that
442 // we could still use the original name in the symbol table.
443 SmallString<128> InvalidName(OriginalName);
444
445 // If it's an entry point symbol, we will keep the '.'
446 // in front for the convention purpose. Otherwise, add "_Renamed.."
447 // as prefix to signal this is an renamed symbol.
448 const bool IsEntryPoint = InvalidName.starts_with(".");
449 SmallString<128> ValidName =
450 StringRef(IsEntryPoint ? "._Renamed.." : "_Renamed..");
451
452 // Append the hex values of '_' and invalid characters with "_Renamed..";
453 // at the same time replace invalid characters with '_'.
454 for (size_t I = 0; I < InvalidName.size(); ++I) {
455 if (!MAI->isAcceptableChar(InvalidName[I]) || InvalidName[I] == '_') {
456 raw_svector_ostream(ValidName).write_hex(InvalidName[I]);
457 InvalidName[I] = '_';
458 }
459 }
460
461 // Skip entry point symbol's '.' as we already have a '.' in front of
462 // "_Renamed".
463 if (IsEntryPoint)
464 ValidName.append(InvalidName.substr(1, InvalidName.size() - 1));
465 else
466 ValidName.append(InvalidName);
467
468 MCSymbolTableEntry &NameEntry = getSymbolTableEntry(ValidName.str());
469 assert(!NameEntry.second.Used && "This name is used somewhere else.");
470 NameEntry.second.Used = true;
471 // Have the MCSymbol object itself refer to the copy of the string
472 // that is embedded in the symbol table entry.
473 MCSymbolXCOFF *XSym =
474 new (&NameEntry, *this) MCSymbolXCOFF(&NameEntry, IsTemporary);
476 return XSym;
477}
478
479//===----------------------------------------------------------------------===//
480// Section Management
481//===----------------------------------------------------------------------===//
482
484 unsigned TypeAndAttributes,
485 unsigned Reserved2, SectionKind Kind,
486 const char *BeginSymName) {
487 // We unique sections by their segment/section pair. The returned section
488 // may not have the same flags as the requested section, if so this should be
489 // diagnosed by the client as an error.
490
491 // Form the name to look up.
492 assert(Section.size() <= 16 && "section name is too long");
493 assert(!memchr(Section.data(), '\0', Section.size()) &&
494 "section name cannot contain NUL");
495
496 // Do the lookup, if we have a hit, return it.
497 auto R = MachOUniquingMap.try_emplace((Segment + Twine(',') + Section).str());
498 if (!R.second)
499 return R.first->second;
500
501 MCSymbol *Begin = nullptr;
502 if (BeginSymName)
503 Begin = createTempSymbol(BeginSymName, false);
504
505 // Otherwise, return a new section.
506 StringRef Name = R.first->first();
507 auto *Ret = new (MachOAllocator.Allocate())
508 MCSectionMachO(Segment, Name.substr(Name.size() - Section.size()),
509 TypeAndAttributes, Reserved2, Kind, Begin);
510 R.first->second = Ret;
511 allocInitialFragment(*Ret);
512 return Ret;
513}
514
515MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
516 unsigned Flags,
517 unsigned EntrySize,
518 const MCSymbolELF *Group,
519 bool Comdat, unsigned UniqueID,
520 const MCSymbolELF *LinkedToSym) {
521 auto *R = getOrCreateSectionSymbol<MCSymbolELF>(Section);
522 R->setBinding(ELF::STB_LOCAL);
523 R->setType(ELF::STT_SECTION);
524
525 auto *Ret = new (ELFAllocator.Allocate()) MCSectionELF(
526 Section, Type, Flags, EntrySize, Group, Comdat, UniqueID, R, LinkedToSym);
527
528 auto *F = allocInitialFragment(*Ret);
529 R->setFragment(F);
530 return Ret;
531}
532
534MCContext::createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags,
535 unsigned EntrySize, const MCSymbolELF *Group,
536 const MCSectionELF *RelInfoSection) {
538 bool Inserted;
539 std::tie(I, Inserted) = RelSecNames.insert(std::make_pair(Name.str(), true));
540
541 return createELFSectionImpl(
542 I->getKey(), Type, Flags, EntrySize, Group, true, true,
543 cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
544}
545
547 const Twine &Suffix, unsigned Type,
548 unsigned Flags,
549 unsigned EntrySize) {
550 return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix,
551 /*IsComdat=*/true);
552}
553
555 unsigned Flags, unsigned EntrySize,
556 const Twine &Group, bool IsComdat,
557 unsigned UniqueID,
558 const MCSymbolELF *LinkedToSym) {
559 MCSymbolELF *GroupSym = nullptr;
560 if (!Group.isTriviallyEmpty() && !Group.str().empty())
561 GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
562
563 return getELFSection(Section, Type, Flags, EntrySize, GroupSym, IsComdat,
564 UniqueID, LinkedToSym);
565}
566
568 unsigned Flags, unsigned EntrySize,
569 const MCSymbolELF *GroupSym,
570 bool IsComdat, unsigned UniqueID,
571 const MCSymbolELF *LinkedToSym) {
572 StringRef Group = "";
573 if (GroupSym)
574 Group = GroupSym->getName();
575 assert(!(LinkedToSym && LinkedToSym->getName().empty()));
576
577 // Sections are differentiated by the quadruple (section_name, group_name,
578 // unique_id, link_to_symbol_name). Sections sharing the same quadruple are
579 // combined into one section. As an optimization, non-unique sections without
580 // group or linked-to symbol have a shorter unique-ing key.
581 std::pair<StringMap<MCSectionELF *>::iterator, bool> EntryNewPair;
582 // Length of the section name, which are the first SectionLen bytes of the key
583 unsigned SectionLen;
584 if (GroupSym || LinkedToSym || UniqueID != MCSection::NonUniqueID) {
585 SmallString<128> Buffer;
586 Section.toVector(Buffer);
587 SectionLen = Buffer.size();
588 Buffer.push_back(0); // separator which cannot occur in the name
589 if (GroupSym)
590 Buffer.append(GroupSym->getName());
591 Buffer.push_back(0); // separator which cannot occur in the name
592 if (LinkedToSym)
593 Buffer.append(LinkedToSym->getName());
595 StringRef UniqueMapKey = StringRef(Buffer);
596 EntryNewPair = ELFUniquingMap.insert(std::make_pair(UniqueMapKey, nullptr));
597 } else if (!Section.isSingleStringRef()) {
598 SmallString<128> Buffer;
599 StringRef UniqueMapKey = Section.toStringRef(Buffer);
600 SectionLen = UniqueMapKey.size();
601 EntryNewPair = ELFUniquingMap.insert(std::make_pair(UniqueMapKey, nullptr));
602 } else {
603 StringRef UniqueMapKey = Section.getSingleStringRef();
604 SectionLen = UniqueMapKey.size();
605 EntryNewPair = ELFUniquingMap.insert(std::make_pair(UniqueMapKey, nullptr));
606 }
607
608 if (!EntryNewPair.second)
609 return EntryNewPair.first->second;
610
611 StringRef CachedName = EntryNewPair.first->getKey().take_front(SectionLen);
612
613 MCSectionELF *Result =
614 createELFSectionImpl(CachedName, Type, Flags, EntrySize, GroupSym,
615 IsComdat, UniqueID, LinkedToSym);
616 EntryNewPair.first->second = Result;
617
618 recordELFMergeableSectionInfo(Result->getName(), Result->getFlags(),
619 Result->getUniqueID(), Result->getEntrySize());
620
621 return Result;
622}
623
625 bool IsComdat) {
626 return createELFSectionImpl(".group", ELF::SHT_GROUP, 0, 4, Group, IsComdat,
627 MCSection::NonUniqueID, nullptr);
628}
629
631 unsigned Flags, unsigned UniqueID,
632 unsigned EntrySize) {
633 bool IsMergeable = Flags & ELF::SHF_MERGE;
634 if (UniqueID == GenericSectionID) {
635 ELFSeenGenericMergeableSections.insert(SectionName);
636 // Minor performance optimization: avoid hash map lookup in
637 // isELFGenericMergeableSection, which will return true for SectionName.
638 IsMergeable = true;
639 }
640
641 // For mergeable sections or non-mergeable sections with a generic mergeable
642 // section name we enter their Unique ID into the ELFEntrySizeMap so that
643 // compatible globals can be assigned to the same section.
644
645 if (IsMergeable || isELFGenericMergeableSection(SectionName)) {
646 ELFEntrySizeMap.insert(std::make_pair(
647 std::make_tuple(SectionName, Flags, EntrySize), UniqueID));
648 }
649}
650
652 return SectionName.starts_with(".rodata.str") ||
653 SectionName.starts_with(".rodata.cst");
654}
655
658 ELFSeenGenericMergeableSections.count(SectionName);
659}
660
661std::optional<unsigned>
663 unsigned EntrySize) {
664 auto I = ELFEntrySizeMap.find(std::make_tuple(SectionName, Flags, EntrySize));
665 return (I != ELFEntrySizeMap.end()) ? std::optional<unsigned>(I->second)
666 : std::nullopt;
667}
668
670 MCSection *Parent,
671 uint32_t Subsection) {
672 // Do the lookup. If we don't have a hit, return a new section.
673 auto IterBool =
674 GOFFUniquingMap.insert(std::make_pair(Section.str(), nullptr));
675 auto Iter = IterBool.first;
676 if (!IterBool.second)
677 return Iter->second;
678
679 StringRef CachedName = Iter->first;
680 MCSectionGOFF *GOFFSection = new (GOFFAllocator.Allocate())
681 MCSectionGOFF(CachedName, Kind, Parent, Subsection);
682 Iter->second = GOFFSection;
683 allocInitialFragment(*GOFFSection);
684 return GOFFSection;
685}
686
688 unsigned Characteristics,
689 StringRef COMDATSymName, int Selection,
690 unsigned UniqueID) {
691 MCSymbol *COMDATSymbol = nullptr;
692 if (!COMDATSymName.empty()) {
693 COMDATSymbol = getOrCreateSymbol(COMDATSymName);
694 COMDATSymName = COMDATSymbol->getName();
695 // A non-associative COMDAT is considered to define the COMDAT symbol. Check
696 // the redefinition error.
697 if (Selection != COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE && COMDATSymbol &&
698 COMDATSymbol->isDefined() &&
699 (!COMDATSymbol->isInSection() ||
700 cast<MCSectionCOFF>(COMDATSymbol->getSection()).getCOMDATSymbol() !=
701 COMDATSymbol))
702 reportError(SMLoc(), "invalid symbol redefinition");
703 }
704
705 // Do the lookup, if we have a hit, return it.
706 COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
707 auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
708 auto Iter = IterBool.first;
709 if (!IterBool.second)
710 return Iter->second;
711
712 StringRef CachedName = Iter->first.SectionName;
713 MCSymbol *Begin = getOrCreateSectionSymbol<MCSymbolCOFF>(Section);
714 MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
715 CachedName, Characteristics, COMDATSymbol, Selection, Begin);
716 Iter->second = Result;
717 auto *F = allocInitialFragment(*Result);
718 Begin->setFragment(F);
719 return Result;
720}
721
723 unsigned Characteristics) {
724 return getCOFFSection(Section, Characteristics, "", 0, GenericSectionID);
725}
726
728 const MCSymbol *KeySym,
729 unsigned UniqueID) {
730 // Return the normal section if we don't have to be associative or unique.
731 if (!KeySym && UniqueID == GenericSectionID)
732 return Sec;
733
734 // If we have a key symbol, make an associative section with the same name and
735 // kind as the normal section.
736 unsigned Characteristics = Sec->getCharacteristics();
737 if (KeySym) {
739 return getCOFFSection(Sec->getName(), Characteristics, KeySym->getName(),
741 }
742
743 return getCOFFSection(Sec->getName(), Characteristics, "", 0, UniqueID);
744}
745
747 unsigned Flags, const Twine &Group,
748 unsigned UniqueID,
749 const char *BeginSymName) {
750 MCSymbolWasm *GroupSym = nullptr;
751 if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
752 GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
753 GroupSym->setComdat(true);
754 }
755
756 return getWasmSection(Section, K, Flags, GroupSym, UniqueID, BeginSymName);
757}
758
760 unsigned Flags,
761 const MCSymbolWasm *GroupSym,
762 unsigned UniqueID,
763 const char *BeginSymName) {
764 StringRef Group = "";
765 if (GroupSym)
766 Group = GroupSym->getName();
767 // Do the lookup, if we have a hit, return it.
768 auto IterBool = WasmUniquingMap.insert(
769 std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr));
770 auto &Entry = *IterBool.first;
771 if (!IterBool.second)
772 return Entry.second;
773
774 StringRef CachedName = Entry.first.SectionName;
775
776 MCSymbol *Begin = createRenamableSymbol(CachedName, true, false);
777 // Begin always has a different name than CachedName... see #48596.
778 getSymbolTableEntry(Begin->getName()).second.Symbol = Begin;
779 cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
780
781 MCSectionWasm *Result = new (WasmAllocator.Allocate())
782 MCSectionWasm(CachedName, Kind, Flags, GroupSym, UniqueID, Begin);
783 Entry.second = Result;
784
785 auto *F = allocInitialFragment(*Result);
786 Begin->setFragment(F);
787 return Result;
788}
789
791 XCOFF::CsectProperties CsectProp) const {
792 return XCOFFUniquingMap.count(
793 XCOFFSectionKey(Section.str(), CsectProp.MappingClass)) != 0;
794}
795
797 StringRef Section, SectionKind Kind,
798 std::optional<XCOFF::CsectProperties> CsectProp, bool MultiSymbolsAllowed,
799 const char *BeginSymName,
800 std::optional<XCOFF::DwarfSectionSubtypeFlags> DwarfSectionSubtypeFlags) {
801 bool IsDwarfSec = DwarfSectionSubtypeFlags.has_value();
802 assert((IsDwarfSec != CsectProp.has_value()) && "Invalid XCOFF section!");
803
804 // Do the lookup. If we have a hit, return it.
805 auto IterBool = XCOFFUniquingMap.insert(std::make_pair(
806 IsDwarfSec ? XCOFFSectionKey(Section.str(), *DwarfSectionSubtypeFlags)
807 : XCOFFSectionKey(Section.str(), CsectProp->MappingClass),
808 nullptr));
809 auto &Entry = *IterBool.first;
810 if (!IterBool.second) {
811 MCSectionXCOFF *ExistedEntry = Entry.second;
812 if (ExistedEntry->isMultiSymbolsAllowed() != MultiSymbolsAllowed)
813 report_fatal_error("section's multiply symbols policy does not match");
814
815 return ExistedEntry;
816 }
817
818 // Otherwise, return a new section.
819 StringRef CachedName = Entry.first.SectionName;
820 MCSymbolXCOFF *QualName = nullptr;
821 // Debug section don't have storage class attribute.
822 if (IsDwarfSec)
823 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(CachedName));
824 else
825 QualName = cast<MCSymbolXCOFF>(getOrCreateSymbol(
826 CachedName + "[" +
827 XCOFF::getMappingClassString(CsectProp->MappingClass) + "]"));
828
829 MCSymbol *Begin = nullptr;
830 if (BeginSymName)
831 Begin = createTempSymbol(BeginSymName, false);
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, Begin, CachedName, MultiSymbolsAllowed);
840 else
841 Result = new (XCOFFAllocator.Allocate())
842 MCSectionXCOFF(QualName->getUnqualifiedName(), CsectProp->MappingClass,
843 CsectProp->Type, Kind, QualName, Begin, CachedName,
844 MultiSymbolsAllowed);
845
846 Entry.second = Result;
847
848 auto *F = allocInitialFragment(*Result);
849 if (Begin)
850 Begin->setFragment(F);
851
852 // We might miss calculating the symbols difference as absolute value before
853 // adding fixups when symbol_A without the fragment set is the csect itself
854 // and symbol_B is in it.
855 // TODO: Currently we only set the fragment for XMC_PR csects because we don't
856 // have other cases that hit this problem yet.
857 if (!IsDwarfSec && CsectProp->MappingClass == XCOFF::XMC_PR)
858 QualName->setFragment(F);
859
860 return Result;
861}
862
864 MCSectionSPIRV *Result = new (SPIRVAllocator.Allocate()) MCSectionSPIRV();
865
866 allocInitialFragment(*Result);
867 return Result;
868}
869
871 SectionKind K) {
872 // Do the lookup, if we have a hit, return it.
873 auto ItInsertedPair = DXCUniquingMap.try_emplace(Section);
874 if (!ItInsertedPair.second)
875 return ItInsertedPair.first->second;
876
877 auto MapIt = ItInsertedPair.first;
878 // Grab the name from the StringMap. Since the Section is going to keep a
879 // copy of this StringRef we need to make sure the underlying string stays
880 // alive as long as we need it.
881 StringRef Name = MapIt->first();
882 MapIt->second =
883 new (DXCAllocator.Allocate()) MCSectionDXContainer(Name, K, nullptr);
884
885 // The first fragment will store the header
886 allocInitialFragment(*MapIt->second);
887 return MapIt->second;
888}
889
891 return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
892}
893
895 const std::string &To) {
896 DebugPrefixMap.emplace_back(From, To);
897}
898
900 for (const auto &[From, To] : llvm::reverse(DebugPrefixMap))
902 break;
903}
904
906 const auto &DebugPrefixMap = this->DebugPrefixMap;
907 if (DebugPrefixMap.empty())
908 return;
909
910 // Remap compilation directory.
911 remapDebugPath(CompilationDir);
912
913 // Remap MCDwarfDirs and RootFile.Name in all compilation units.
915 for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
916 for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
917 P = Dir;
919 Dir = std::string(P);
920 }
921
922 // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
923 // DW_AT_decl_file for DWARF v5 generated for assembly source.
924 P = CUIDTablePair.second.getRootFile().Name;
926 CUIDTablePair.second.getRootFile().Name = std::string(P);
927 }
928}
929
930//===----------------------------------------------------------------------===//
931// Dwarf Management
932//===----------------------------------------------------------------------===//
933
935 if (!TargetOptions)
937 return TargetOptions->EmitDwarfUnwind;
938}
939
941 if (TargetOptions)
942 return TargetOptions->EmitCompactUnwindNonCanonical;
943 return false;
944}
945
947 // MCDwarf needs the root file as well as the compilation directory.
948 // If we find a '.file 0' directive that will supersede these values.
949 std::optional<MD5::MD5Result> Cksum;
950 if (getDwarfVersion() >= 5) {
951 MD5 Hash;
952 MD5::MD5Result Sum;
953 Hash.update(Buffer);
954 Hash.final(Sum);
955 Cksum = Sum;
956 }
957 // Canonicalize the root filename. It cannot be empty, and should not
958 // repeat the compilation dir.
959 // The MCContext ctor initializes MainFileName to the name associated with
960 // the SrcMgr's main file ID, which might be the same as InputFileName (and
961 // possibly include directory components).
962 // Or, MainFileName might have been overridden by a -main-file-name option,
963 // which is supposed to be just a base filename with no directory component.
964 // So, if the InputFileName and MainFileName are not equal, assume
965 // MainFileName is a substitute basename and replace the last component.
966 SmallString<1024> FileNameBuf = InputFileName;
967 if (FileNameBuf.empty() || FileNameBuf == "-")
968 FileNameBuf = "<stdin>";
969 if (!getMainFileName().empty() && FileNameBuf != getMainFileName()) {
972 }
973 StringRef FileName = FileNameBuf;
974 if (FileName.consume_front(getCompilationDir()))
975 if (llvm::sys::path::is_separator(FileName.front()))
976 FileName = FileName.drop_front();
977 assert(!FileName.empty());
979 /*CUID=*/0, getCompilationDir(), FileName, Cksum, std::nullopt);
980}
981
982/// getDwarfFile - takes a file name and number to place in the dwarf file and
983/// directory tables. If the file number has already been allocated it is an
984/// error and zero is returned and the client reports the error, else the
985/// allocated file number is returned. The file numbers may be in any order.
988 unsigned FileNumber,
989 std::optional<MD5::MD5Result> Checksum,
990 std::optional<StringRef> Source, unsigned CUID) {
991 MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
992 return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
993 FileNumber);
994}
995
996/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
997/// currently is assigned and false otherwise.
998bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
999 const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
1000 if (FileNumber == 0)
1001 return getDwarfVersion() >= 5;
1002 if (FileNumber >= LineTable.getMCDwarfFiles().size())
1003 return false;
1004
1005 return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
1006}
1007
1008/// Remove empty sections from SectionsForRanges, to avoid generating
1009/// useless debug info for them.
1011 SectionsForRanges.remove_if(
1012 [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
1013}
1014
1016 if (!CVContext)
1017 CVContext.reset(new CodeViewContext(this));
1018 return *CVContext;
1019}
1020
1021//===----------------------------------------------------------------------===//
1022// Error Reporting
1023//===----------------------------------------------------------------------===//
1024
1026 assert(DiagHandler && "MCContext::DiagHandler is not set");
1027 bool UseInlineSrcMgr = false;
1028 const SourceMgr *SMP = nullptr;
1029 if (SrcMgr) {
1030 SMP = SrcMgr;
1031 } else if (InlineSrcMgr) {
1032 SMP = InlineSrcMgr.get();
1033 UseInlineSrcMgr = true;
1034 } else
1035 llvm_unreachable("Either SourceMgr should be available");
1036 DiagHandler(SMD, UseInlineSrcMgr, *SMP, LocInfos);
1037}
1038
1039void MCContext::reportCommon(
1040 SMLoc Loc,
1041 std::function<void(SMDiagnostic &, const SourceMgr *)> GetMessage) {
1042 // * MCContext::SrcMgr is null when the MC layer emits machine code for input
1043 // other than assembly file, say, for .c/.cpp/.ll/.bc.
1044 // * MCContext::InlineSrcMgr is null when the inline asm is not used.
1045 // * A default SourceMgr is needed for diagnosing when both MCContext::SrcMgr
1046 // and MCContext::InlineSrcMgr are null.
1047 SourceMgr SM;
1048 const SourceMgr *SMP = &SM;
1049 bool UseInlineSrcMgr = false;
1050
1051 // FIXME: Simplify these by combining InlineSrcMgr & SrcMgr.
1052 // For MC-only execution, only SrcMgr is used;
1053 // For non MC-only execution, InlineSrcMgr is only ctor'd if there is
1054 // inline asm in the IR.
1055 if (Loc.isValid()) {
1056 if (SrcMgr) {
1057 SMP = SrcMgr;
1058 } else if (InlineSrcMgr) {
1059 SMP = InlineSrcMgr.get();
1060 UseInlineSrcMgr = true;
1061 } else
1062 llvm_unreachable("Either SourceMgr should be available");
1063 }
1064
1066 GetMessage(D, SMP);
1067 DiagHandler(D, UseInlineSrcMgr, *SMP, LocInfos);
1068}
1069
1070void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
1071 HadError = true;
1072 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1073 D = SMP->GetMessage(Loc, SourceMgr::DK_Error, Msg);
1074 });
1075}
1076
1077void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
1078 if (TargetOptions && TargetOptions->MCNoWarn)
1079 return;
1080 if (TargetOptions && TargetOptions->MCFatalWarnings) {
1081 reportError(Loc, Msg);
1082 } else {
1083 reportCommon(Loc, [&](SMDiagnostic &D, const SourceMgr *SMP) {
1084 D = SMP->GetMessage(Loc, SourceMgr::DK_Warning, Msg);
1085 });
1086 }
1087}
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:664
StringRef getLinkerPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:671
StringRef getPrivateLabelPrefix() const
Definition: MCAsmInfo.h:665
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
Definition: MCAsmInfo.cpp:105
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition: MCAsmInfo.cpp:112
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
void remapDebugPath(SmallVectorImpl< char > &Path)
Remap one path in-place as per the debug prefix map.
Definition: MCContext.cpp:899
MCSymbol * createBlockSymbol(const Twine &Name, bool AlwaysEmit=false)
Get or create a symbol for a basic block.
Definition: MCContext.cpp:324
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:890
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:483
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:413
const std::string & getMainFileName() const
Get the main file name for use in error messages and debug info.
Definition: MCContext.h:691
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
Definition: MCContext.cpp:894
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:345
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
Definition: MCContext.h:674
void RemapDebugPaths()
Definition: MCContext.cpp:905
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:235
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
Definition: MCContext.cpp:534
MCSymbol * createLinkerPrivateTempSymbol()
Create a new linker temporary symbol with the specified prefix (Name) or "tmp".
Definition: MCContext.cpp:335
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)
Definition: MCContext.h:624
void recordELFMergeableSectionInfo(StringRef SectionName, unsigned Flags, unsigned UniqueID, unsigned EntrySize)
Definition: MCContext.cpp:630
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:987
wasm::WasmSignature * createWasmSignature()
Allocates and returns a new WasmSignature instance (with empty parameter and return type lists).
Definition: MCContext.cpp:423
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:546
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:547
void diagnose(const SMDiagnostic &SMD)
Definition: MCContext.cpp:1025
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:998
void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
Definition: MCContext.cpp:419
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:709
void initInlineSourceManager()
Definition: MCContext.cpp:127
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID)
Definition: MCContext.cpp:687
MCSymbol * getOrCreateParentFrameOffsetSymbol(const Twine &FuncName)
Definition: MCContext.cpp:241
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
Definition: MCContext.cpp:407
bool emitCompactUnwindNonCanonical() const
Definition: MCContext.cpp:940
CodeViewContext & getCVContext()
Definition: MCContext.cpp:1015
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:669
bool isELFGenericMergeableSection(StringRef Name)
Definition: MCContext.cpp:656
MCContext(const Triple &TheTriple, const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCSubtargetInfo *MSTI, const SourceMgr *Mgr=nullptr, MCTargetOptions const *TargetOpts=nullptr, bool DoAutoReset=true, StringRef Swift5ReflSegmentName={})
Definition: MCContext.cpp:67
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, const char *BeginSymName=nullptr, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
Definition: MCContext.cpp:796
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:662
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions).
Definition: MCContext.cpp:373
void reportWarning(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1077
uint16_t getDwarfVersion() const
Definition: MCContext.h:809
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
Definition: MCContext.cpp:1010
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1070
@ GenericSectionID
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:530
MCSymbol * getOrCreateLSDASymbol(const Twine &FuncName)
Definition: MCContext.cpp:246
MCSectionDXContainer * getDXContainerSection(StringRef Section, SectionKind K)
Get the section for the provided Section name.
Definition: MCContext.cpp:870
bool hasXCOFFSection(StringRef Section, XCOFF::CsectProperties CsectProp) const
Definition: MCContext.cpp:790
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:212
MCSymbol * createLinkerPrivateSymbol(const Twine &Name)
Definition: MCContext.cpp:339
MCSectionSPIRV * getSPIRVSection()
Definition: MCContext.cpp:863
EmitDwarfUnwindType emitDwarfUnwindInfo() const
Definition: MCContext.cpp:934
bool isELFImplicitMergeableSectionNamePrefix(StringRef Name)
Definition: MCContext.cpp:651
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group, bool IsComdat)
Definition: MCContext.cpp:624
void setGenDwarfRootFile(StringRef FileName, StringRef Buffer)
Specifies information about the "root file" for assembler clients (e.g., llvm-mc).
Definition: MCContext.cpp:946
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:727
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:733
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:378
MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
Definition: MCContext.cpp:347
Fragment for data and encoded instructions.
Definition: MCFragment.h:232
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
void addFragment(MCFragment &F)
Definition: MCSection.h:201
StringRef getName() const
Definition: MCSection.h:142
FragList * curFragList() const
Definition: MCSection.h:196
MCSymbol * getBeginSymbol()
Definition: MCSection.h:147
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:1118
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:258
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:602
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:628
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:573
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:425
@ STB_LOCAL
Definition: ELF.h:1314
@ SHT_GROUP
Definition: ELF.h:1081
@ SHF_MERGE
Definition: ELF.h:1167
@ STT_SECTION
Definition: ELF.h:1329
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