LLVM 17.0.0git
MCObjectStreamer.cpp
Go to the documentation of this file.
1//===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===//
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
11#include "llvm/MC/MCAsmInfo.h"
12#include "llvm/MC/MCAssembler.h"
14#include "llvm/MC/MCCodeView.h"
15#include "llvm/MC/MCContext.h"
16#include "llvm/MC/MCDwarf.h"
17#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCSection.h"
21#include "llvm/MC/MCSymbol.h"
22#include "llvm/MC/MCValue.h"
25using namespace llvm;
26
28 std::unique_ptr<MCAsmBackend> TAB,
29 std::unique_ptr<MCObjectWriter> OW,
30 std::unique_ptr<MCCodeEmitter> Emitter)
32 Assembler(std::make_unique<MCAssembler>(
33 Context, std::move(TAB), std::move(Emitter), std::move(OW))),
34 EmitEHFrame(true), EmitDebugFrame(false) {
35 if (Assembler->getBackendPtr())
36 setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
37}
38
40
41// AssemblerPtr is used for evaluation of expressions and causes
42// difference between asm and object outputs. Return nullptr to in
43// inline asm mode to limit divergence to assembly inputs.
46 return Assembler.get();
47 return nullptr;
48}
49
51 MCSection *CurSection = getCurrentSectionOnly();
52 if (CurSection) {
53 // Register labels that have not yet been assigned to a Section.
54 if (!PendingLabels.empty()) {
55 for (MCSymbol* Sym : PendingLabels)
56 CurSection->addPendingLabel(Sym);
57 PendingLabels.clear();
58 }
59
60 // Add this label to the current Section / Subsection.
61 CurSection->addPendingLabel(S, CurSubsectionIdx);
62
63 // Add this Section to the list of PendingLabelSections.
64 PendingLabelSections.insert(CurSection);
65 } else
66 // There is no Section / Subsection for this label yet.
67 PendingLabels.push_back(S);
68}
69
71 MCSection *CurSection = getCurrentSectionOnly();
72 if (!CurSection) {
73 assert(PendingLabels.empty());
74 return;
75 }
76 // Register labels that have not yet been assigned to a Section.
77 if (!PendingLabels.empty()) {
78 for (MCSymbol* Sym : PendingLabels)
79 CurSection->addPendingLabel(Sym, CurSubsectionIdx);
80 PendingLabels.clear();
81 }
82
83 // Associate a fragment with this label, either the supplied fragment
84 // or an empty data fragment.
85 if (F)
86 CurSection->flushPendingLabels(F, FOffset, CurSubsectionIdx);
87 else
88 CurSection->flushPendingLabels(nullptr, 0, CurSubsectionIdx);
89}
90
92 // Register labels that have not yet been assigned to a Section.
93 if (!PendingLabels.empty()) {
94 MCSection *CurSection = getCurrentSectionOnly();
95 assert(CurSection);
96 for (MCSymbol* Sym : PendingLabels)
97 CurSection->addPendingLabel(Sym, CurSubsectionIdx);
98 PendingLabels.clear();
99 }
100
101 // Assign an empty data fragment to all remaining pending labels.
102 for (MCSection* Section : PendingLabelSections)
103 Section->flushPendingLabels();
104}
105
106// When fixup's offset is a forward declared label, e.g.:
107//
108// .reloc 1f, R_MIPS_JALR, foo
109// 1: nop
110//
111// postpone adding it to Fixups vector until the label is defined and its offset
112// is known.
113void MCObjectStreamer::resolvePendingFixups() {
114 for (PendingMCFixup &PendingFixup : PendingFixups) {
115 if (!PendingFixup.Sym || PendingFixup.Sym->isUndefined ()) {
116 getContext().reportError(PendingFixup.Fixup.getLoc(),
117 "unresolved relocation offset");
118 continue;
119 }
120 flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size());
121 PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset() +
122 PendingFixup.Fixup.getOffset());
123
124 // If the location symbol to relocate is in MCEncodedFragmentWithFixups,
125 // put the Fixup into location symbol's fragment. Otherwise
126 // put into PendingFixup.DF
127 MCFragment *SymFragment = PendingFixup.Sym->getFragment();
128 switch (SymFragment->getKind()) {
132 cast<MCEncodedFragmentWithFixups<8, 1>>(SymFragment)
133 ->getFixups()
134 .push_back(PendingFixup.Fixup);
135 break;
138 cast<MCEncodedFragmentWithFixups<32, 4>>(SymFragment)
139 ->getFixups()
140 .push_back(PendingFixup.Fixup);
141 break;
142 default:
143 PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
144 break;
145 }
146 }
147 PendingFixups.clear();
148}
149
150// As a compile-time optimization, avoid allocating and evaluating an MCExpr
151// tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
152static std::optional<uint64_t> absoluteSymbolDiff(const MCSymbol *Hi,
153 const MCSymbol *Lo) {
154 assert(Hi && Lo);
155 if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
156 Hi->isVariable() || Lo->isVariable())
157 return std::nullopt;
158
159 return Hi->getOffset() - Lo->getOffset();
160}
161
163 const MCSymbol *Lo,
164 unsigned Size) {
165 if (!getAssembler().getContext().getTargetTriple().isRISCV())
166 if (std::optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo))
167 return emitIntValue(*Diff, Size);
169}
170
172 const MCSymbol *Lo) {
173 if (!getAssembler().getContext().getTargetTriple().isRISCV())
174 if (std::optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo)) {
175 emitULEB128IntValue(*Diff);
176 return;
177 }
179}
180
182 if (Assembler)
183 Assembler->reset();
184 CurInsertionPoint = MCSection::iterator();
185 EmitEHFrame = true;
186 EmitDebugFrame = false;
187 PendingLabels.clear();
188 PendingLabelSections.clear();
190}
191
193 if (!getNumFrameInfos())
194 return;
195
196 if (EmitEHFrame)
197 MCDwarfFrameEmitter::Emit(*this, MAB, true);
198
199 if (EmitDebugFrame)
200 MCDwarfFrameEmitter::Emit(*this, MAB, false);
201}
202
204 assert(getCurrentSectionOnly() && "No current section!");
205
206 if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
207 return &*std::prev(CurInsertionPoint);
208
209 return nullptr;
210}
211
213 const MCAssembler &Assembler,
214 const MCSubtargetInfo *STI) {
215 if (!F.hasInstructions())
216 return true;
217 // When bundling is enabled, we don't want to add data to a fragment that
218 // already has instructions (see MCELFStreamer::emitInstToData for details)
219 if (Assembler.isBundlingEnabled())
220 return Assembler.getRelaxAll();
221 // If the subtarget is changed mid fragment we start a new fragment to record
222 // the new STI.
223 return !STI || F.getSubtargetInfo() == STI;
224}
225
228 MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
229 if (!F || !canReuseDataFragment(*F, *Assembler, STI)) {
230 F = new MCDataFragment();
231 insert(F);
232 }
233 return F;
234}
235
237 Assembler->registerSymbol(Sym);
238}
239
242 EmitEHFrame = EH;
243 EmitDebugFrame = Debug;
244}
245
247 SMLoc Loc) {
250 flushPendingLabels(DF, DF->getContents().size());
251
253
254 // Avoid fixups when possible.
255 int64_t AbsValue;
256 if (Value->evaluateAsAbsolute(AbsValue, getAssemblerPtr())) {
257 if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
259 Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
260 return;
261 }
262 emitIntValue(AbsValue, Size);
263 return;
264 }
265 DF->getFixups().push_back(
266 MCFixup::create(DF->getContents().size(), Value,
267 MCFixup::getKindForSize(Size, false), Loc));
268 DF->getContents().resize(DF->getContents().size() + Size, 0);
269}
270
271MCSymbol *MCObjectStreamer::emitCFILabel() {
272 MCSymbol *Label = getContext().createTempSymbol("cfi");
273 emitLabel(Label);
274 return Label;
275}
276
277void MCObjectStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
278 // We need to create a local symbol to avoid relocations.
280 emitLabel(Frame.Begin);
281}
282
283void MCObjectStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
284 Frame.End = getContext().createTempSymbol();
285 emitLabel(Frame.End);
286}
287
289 MCStreamer::emitLabel(Symbol, Loc);
290
291 getAssembler().registerSymbol(*Symbol);
292
293 // If there is a current fragment, mark the symbol as pointing into it.
294 // Otherwise queue the label and set its fragment pointer when we emit the
295 // next fragment.
296 auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
297 if (F && !(getAssembler().isBundlingEnabled() &&
298 getAssembler().getRelaxAll())) {
299 Symbol->setFragment(F);
300 Symbol->setOffset(F->getContents().size());
301 } else {
302 // Assign all pending labels to offset 0 within the dummy "pending"
303 // fragment. (They will all be reassigned to a real fragment in
304 // flushPendingLabels())
305 Symbol->setOffset(0);
306 addPendingLabel(Symbol);
307 }
308
310}
311
313 auto Assignments = pendingAssignments.find(Symbol);
314 if (Assignments != pendingAssignments.end()) {
315 for (const PendingAssignment &A : Assignments->second)
316 emitAssignment(A.Symbol, A.Value);
317
318 pendingAssignments.erase(Assignments);
319 }
320}
321
322// Emit a label at a previously emitted fragment/offset position. This must be
323// within the currently-active section.
326 assert(F->getParent() == getCurrentSectionOnly());
327
328 MCStreamer::emitLabel(Symbol, Loc);
329 getAssembler().registerSymbol(*Symbol);
330 auto *DF = dyn_cast_or_null<MCDataFragment>(F);
331 Symbol->setOffset(Offset);
332 if (DF) {
333 Symbol->setFragment(F);
334 } else {
335 assert(isa<MCDummyFragment>(F) &&
336 "F must either be an MCDataFragment or the pending MCDummyFragment");
337 assert(Offset == 0);
338 addPendingLabel(Symbol);
339 }
340}
341
343 int64_t IntValue;
344 if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
345 emitULEB128IntValue(IntValue);
346 return;
347 }
348 insert(new MCLEBFragment(*Value, false));
349}
350
352 int64_t IntValue;
353 if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
354 emitSLEB128IntValue(IntValue);
355 return;
356 }
357 insert(new MCLEBFragment(*Value, true));
358}
359
361 const MCSymbol *Symbol) {
362 report_fatal_error("This file format doesn't support weak aliases.");
363}
364
366 const MCExpr *Subsection) {
367 changeSectionImpl(Section, Subsection);
368}
369
371 const MCExpr *Subsection) {
372 assert(Section && "Cannot switch to a null section!");
374
375 bool Created = getAssembler().registerSection(*Section);
376
377 int64_t IntSubsection = 0;
378 if (Subsection &&
379 !Subsection->evaluateAsAbsolute(IntSubsection, getAssemblerPtr()))
380 report_fatal_error("Cannot evaluate subsection number");
381 if (IntSubsection < 0 || IntSubsection > 8192)
382 report_fatal_error("Subsection number out of range");
383 CurSubsectionIdx = unsigned(IntSubsection);
384 CurInsertionPoint =
385 Section->getSubsectionInsertionPoint(CurSubsectionIdx);
386 return Created;
387}
388
390 getAssembler().registerSymbol(*Symbol);
393}
394
396 const MCExpr *Value) {
397 const MCSymbol *Target = &cast<MCSymbolRefExpr>(*Value).getSymbol();
398
399 // If the symbol already exists, emit the assignment. Otherwise, emit it
400 // later only if the symbol is also emitted.
401 if (Target->isRegistered())
402 emitAssignment(Symbol, Value);
403 else
404 pendingAssignments[Target].push_back({Symbol, Value});
405}
406
408 return Sec.hasInstructions();
409}
410
412 const MCSubtargetInfo &STI) {
413 const MCSection &Sec = *getCurrentSectionOnly();
414 if (Sec.isVirtualSection()) {
416 " section '" + Sec.getName() +
417 "' cannot have instructions");
418 return;
419 }
420 getAssembler().getBackend().emitInstructionBegin(*this, Inst, STI);
421 emitInstructionImpl(Inst, STI);
423}
424
425void MCObjectStreamer::emitInstructionImpl(const MCInst &Inst,
426 const MCSubtargetInfo &STI) {
428
430 Sec->setHasInstructions(true);
431
432 // Now that a machine instruction has been assembled into this section, make
433 // a line entry for any .loc directive that has been seen.
435
436 // If this instruction doesn't need relaxation, just emit it as data.
437 MCAssembler &Assembler = getAssembler();
438 MCAsmBackend &Backend = Assembler.getBackend();
439 if (!(Backend.mayNeedRelaxation(Inst, STI) ||
440 Backend.allowEnhancedRelaxation())) {
441 emitInstToData(Inst, STI);
442 return;
443 }
444
445 // Otherwise, relax and emit it as data if either:
446 // - The RelaxAll flag was passed
447 // - Bundling is enabled and this instruction is inside a bundle-locked
448 // group. We want to emit all such instructions into the same data
449 // fragment.
450 if (Assembler.getRelaxAll() ||
451 (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
452 MCInst Relaxed = Inst;
453 while (Backend.mayNeedRelaxation(Relaxed, STI))
454 Backend.relaxInstruction(Relaxed, STI);
455 emitInstToData(Relaxed, STI);
456 return;
457 }
458
459 // Otherwise emit to a separate fragment.
460 emitInstToFragment(Inst, STI);
461}
462
464 const MCSubtargetInfo &STI) {
465 if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
466 llvm_unreachable("All instructions should have already been relaxed");
467
468 // Always create a new, separate fragment here, because its size can change
469 // during relaxation.
470 MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
471 insert(IF);
472
473 SmallString<128> Code;
474 getAssembler().getEmitter().encodeInstruction(Inst, Code, IF->getFixups(),
475 STI);
476 IF->getContents().append(Code.begin(), Code.end());
477}
478
479#ifndef NDEBUG
480static const char *const BundlingNotImplementedMsg =
481 "Aligned bundling is not implemented for this object format";
482#endif
483
486}
487
488void MCObjectStreamer::emitBundleLock(bool AlignToEnd) {
490}
491
494}
495
496void MCObjectStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
497 unsigned Column, unsigned Flags,
498 unsigned Isa,
499 unsigned Discriminator,
500 StringRef FileName) {
501 // In case we see two .loc directives in a row, make sure the
502 // first one gets a line entry.
504
505 this->MCStreamer::emitDwarfLocDirective(FileNo, Line, Column, Flags, Isa,
506 Discriminator, FileName);
507}
508
510 const MCSymbol *B) {
511 MCContext &Context = OS.getContext();
513 const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
514 const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
515 const MCExpr *AddrDelta =
517 return AddrDelta;
518}
519
522 int64_t LineDelta, const MCSymbol *Label,
523 int PointerSize) {
524 // emit the sequence to set the address
525 OS.emitIntValue(dwarf::DW_LNS_extended_op, 1);
526 OS.emitULEB128IntValue(PointerSize + 1);
527 OS.emitIntValue(dwarf::DW_LNE_set_address, 1);
528 OS.emitSymbolValue(Label, PointerSize);
529
530 // emit the sequence for the LineDelta (from 1) and a zero address delta.
531 MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
532}
533
535 const MCSymbol *LastLabel,
536 const MCSymbol *Label,
537 unsigned PointerSize) {
538 if (!LastLabel) {
539 emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
540 Label, PointerSize);
541 return;
542 }
543 const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
544 insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
545}
546
548 MCSymbol *LastLabel) {
549 // Emit a DW_LNE_end_sequence for the end of the section.
550 // Use the section end label to compute the address delta and use INT64_MAX
551 // as the line delta which is the signal that this is actually a
552 // DW_LNE_end_sequence.
553 MCSymbol *SectionEnd = endSection(Section);
554
555 // Switch back the dwarf line section, in case endSection had to switch the
556 // section.
557 MCContext &Ctx = getContext();
559
560 const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
561 emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
562 AsmInfo->getCodePointerSize());
563}
564
566 const MCSymbol *Label) {
567 const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
568 insert(new MCDwarfCallFrameFragment(*AddrDelta));
569}
570
571void MCObjectStreamer::emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
572 unsigned Line, unsigned Column,
573 bool PrologueEnd, bool IsStmt,
574 StringRef FileName, SMLoc Loc) {
575 // Validate the directive.
576 if (!checkCVLocSection(FunctionId, FileNo, Loc))
577 return;
578
579 // Emit a label at the current position and record it in the CodeViewContext.
580 MCSymbol *LineSym = getContext().createTempSymbol();
581 emitLabel(LineSym);
582 getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId,
583 FileNo, Line, Column, PrologueEnd,
584 IsStmt);
585}
586
588 const MCSymbol *Begin,
589 const MCSymbol *End) {
590 getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
591 End);
592 this->MCStreamer::emitCVLinetableDirective(FunctionId, Begin, End);
593}
594
596 unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
597 const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
599 *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
600 FnEndSym);
602 PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
603}
604
606 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
607 StringRef FixedSizePortion) {
608 MCFragment *Frag =
609 getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
610 // Attach labels that were pending before we created the defrange fragment to
611 // the beginning of the new fragment.
612 flushPendingLabels(Frag, 0);
613 this->MCStreamer::emitCVDefRangeDirective(Ranges, FixedSizePortion);
614}
615
618}
621}
622
625}
626
630 flushPendingLabels(DF, DF->getContents().size());
631 DF->getContents().append(Data.begin(), Data.end());
632}
633
635 unsigned ValueSize,
636 unsigned MaxBytesToEmit) {
637 if (MaxBytesToEmit == 0)
638 MaxBytesToEmit = Alignment.value();
639 insert(new MCAlignFragment(Alignment, Value, ValueSize, MaxBytesToEmit));
640
641 // Update the maximum alignment on the current section if necessary.
643 CurSec->ensureMinAlignment(Alignment);
644}
645
647 const MCSubtargetInfo *STI,
648 unsigned MaxBytesToEmit) {
649 emitValueToAlignment(Alignment, 0, 1, MaxBytesToEmit);
650 cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true, STI);
651}
652
654 unsigned char Value,
655 SMLoc Loc) {
656 insert(new MCOrgFragment(*Offset, Value, Loc));
657}
658
659// Associate DTPRel32 fixup with data and resize data area
662 flushPendingLabels(DF, DF->getContents().size());
663
664 DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
666 DF->getContents().resize(DF->getContents().size() + 4, 0);
667}
668
669// Associate DTPRel64 fixup with data and resize data area
672 flushPendingLabels(DF, DF->getContents().size());
673
674 DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
676 DF->getContents().resize(DF->getContents().size() + 8, 0);
677}
678
679// Associate TPRel32 fixup with data and resize data area
682 flushPendingLabels(DF, DF->getContents().size());
683
684 DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
685 Value, FK_TPRel_4));
686 DF->getContents().resize(DF->getContents().size() + 4, 0);
687}
688
689// Associate TPRel64 fixup with data and resize data area
692 flushPendingLabels(DF, DF->getContents().size());
693
694 DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
695 Value, FK_TPRel_8));
696 DF->getContents().resize(DF->getContents().size() + 8, 0);
697}
698
699// Associate GPRel32 fixup with data and resize data area
702 flushPendingLabels(DF, DF->getContents().size());
703
704 DF->getFixups().push_back(
705 MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
706 DF->getContents().resize(DF->getContents().size() + 4, 0);
707}
708
709// Associate GPRel64 fixup with data and resize data area
712 flushPendingLabels(DF, DF->getContents().size());
713
714 DF->getFixups().push_back(
715 MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
716 DF->getContents().resize(DF->getContents().size() + 8, 0);
717}
718
719static std::optional<std::pair<bool, std::string>>
720getOffsetAndDataFragment(const MCSymbol &Symbol, uint32_t &RelocOffset,
721 MCDataFragment *&DF) {
722 if (Symbol.isVariable()) {
723 const MCExpr *SymbolExpr = Symbol.getVariableValue();
724 MCValue OffsetVal;
725 if(!SymbolExpr->evaluateAsRelocatable(OffsetVal, nullptr, nullptr))
726 return std::make_pair(false,
727 std::string("symbol in .reloc offset is not "
728 "relocatable"));
729 if (OffsetVal.isAbsolute()) {
730 RelocOffset = OffsetVal.getConstant();
731 MCFragment *Fragment = Symbol.getFragment();
732 // FIXME Support symbols with no DF. For example:
733 // .reloc .data, ENUM_VALUE, <some expr>
734 if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
735 return std::make_pair(false,
736 std::string("symbol in offset has no data "
737 "fragment"));
738 DF = cast<MCDataFragment>(Fragment);
739 return std::nullopt;
740 }
741
742 if (OffsetVal.getSymB())
743 return std::make_pair(false,
744 std::string(".reloc symbol offset is not "
745 "representable"));
746
747 const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*OffsetVal.getSymA());
748 if (!SRE.getSymbol().isDefined())
749 return std::make_pair(false,
750 std::string("symbol used in the .reloc offset is "
751 "not defined"));
752
753 if (SRE.getSymbol().isVariable())
754 return std::make_pair(false,
755 std::string("symbol used in the .reloc offset is "
756 "variable"));
757
758 MCFragment *Fragment = SRE.getSymbol().getFragment();
759 // FIXME Support symbols with no DF. For example:
760 // .reloc .data, ENUM_VALUE, <some expr>
761 if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
762 return std::make_pair(false,
763 std::string("symbol in offset has no data "
764 "fragment"));
765 RelocOffset = SRE.getSymbol().getOffset() + OffsetVal.getConstant();
766 DF = cast<MCDataFragment>(Fragment);
767 } else {
768 RelocOffset = Symbol.getOffset();
769 MCFragment *Fragment = Symbol.getFragment();
770 // FIXME Support symbols with no DF. For example:
771 // .reloc .data, ENUM_VALUE, <some expr>
772 if (!Fragment || Fragment->getKind() != MCFragment::FT_Data)
773 return std::make_pair(false,
774 std::string("symbol in offset has no data "
775 "fragment"));
776 DF = cast<MCDataFragment>(Fragment);
777 }
778 return std::nullopt;
779}
780
781std::optional<std::pair<bool, std::string>>
783 const MCExpr *Expr, SMLoc Loc,
784 const MCSubtargetInfo &STI) {
785 std::optional<MCFixupKind> MaybeKind =
786 Assembler->getBackend().getFixupKind(Name);
787 if (!MaybeKind)
788 return std::make_pair(true, std::string("unknown relocation name"));
789
790 MCFixupKind Kind = *MaybeKind;
791
792 if (Expr == nullptr)
793 Expr =
794 MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
795
797 flushPendingLabels(DF, DF->getContents().size());
798
799 MCValue OffsetVal;
800 if (!Offset.evaluateAsRelocatable(OffsetVal, nullptr, nullptr))
801 return std::make_pair(false,
802 std::string(".reloc offset is not relocatable"));
803 if (OffsetVal.isAbsolute()) {
804 if (OffsetVal.getConstant() < 0)
805 return std::make_pair(false, std::string(".reloc offset is negative"));
806 DF->getFixups().push_back(
807 MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
808 return std::nullopt;
809 }
810 if (OffsetVal.getSymB())
811 return std::make_pair(false,
812 std::string(".reloc offset is not representable"));
813
814 const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*OffsetVal.getSymA());
815 const MCSymbol &Symbol = SRE.getSymbol();
816 if (Symbol.isDefined()) {
817 uint32_t SymbolOffset = 0;
818 std::optional<std::pair<bool, std::string>> Error =
819 getOffsetAndDataFragment(Symbol, SymbolOffset, DF);
820
821 if (Error != std::nullopt)
822 return Error;
823
824 DF->getFixups().push_back(
825 MCFixup::create(SymbolOffset + OffsetVal.getConstant(),
826 Expr, Kind, Loc));
827 return std::nullopt;
828 }
829
830 PendingFixups.emplace_back(
831 &SRE.getSymbol(), DF,
832 MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
833 return std::nullopt;
834}
835
836void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
837 SMLoc Loc) {
839 flushPendingLabels(DF, DF->getContents().size());
840
841 assert(getCurrentSectionOnly() && "need a section");
842 insert(new MCFillFragment(FillValue, 1, NumBytes, Loc));
843}
844
845void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
846 int64_t Expr, SMLoc Loc) {
847 int64_t IntNumValues;
848 // Do additional checking now if we can resolve the value.
849 if (NumValues.evaluateAsAbsolute(IntNumValues, getAssemblerPtr())) {
850 if (IntNumValues < 0) {
853 "'.fill' directive with negative repeat count has no effect");
854 return;
855 }
856 // Emit now if we can for better errors.
857 int64_t NonZeroSize = Size > 4 ? 4 : Size;
858 Expr &= ~0ULL >> (64 - NonZeroSize * 8);
859 for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
860 emitIntValue(Expr, NonZeroSize);
861 if (NonZeroSize < Size)
862 emitIntValue(0, Size - NonZeroSize);
863 }
864 return;
865 }
866
867 // Otherwise emit as fragment.
869 flushPendingLabels(DF, DF->getContents().size());
870
871 assert(getCurrentSectionOnly() && "need a section");
872 insert(new MCFillFragment(Expr, Size, NumValues, Loc));
873}
874
875void MCObjectStreamer::emitNops(int64_t NumBytes, int64_t ControlledNopLength,
876 SMLoc Loc, const MCSubtargetInfo &STI) {
877 // Emit an NOP fragment.
879 flushPendingLabels(DF, DF->getContents().size());
880
881 assert(getCurrentSectionOnly() && "need a section");
882
883 insert(new MCNopsFragment(NumBytes, ControlledNopLength, Loc, STI));
884}
885
887 getAssembler().addFileName(Filename);
888}
889
891 StringRef CompilerVerion,
892 StringRef TimeStamp,
893 StringRef Description) {
894 getAssembler().addFileName(Filename);
895 // TODO: add additional info to integrated assembler.
896}
897
900}
901
904}
905
908
909 // If we are generating dwarf for assembly source files dump out the sections.
910 if (getContext().getGenDwarfForAssembly())
912
913 // Dump out the dwarf file & directory tables and line tables.
914 MCDwarfLineTable::emit(this, getAssembler().getDWARFLinetableParams());
915
916 // Emit pseudo probes for the current module.
918
919 // Update any remaining pending labels with empty data fragments.
921
922 resolvePendingFixups();
924}
basic Basic Alias true
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
dxil DXContainer Global Emitter
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
std::string Name
uint64_t Size
bool End
Definition: ELF_riscv.cpp:464
Symbol * Sym
Definition: ELF_riscv.cpp:463
static const char *const BundlingNotImplementedMsg
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B)
static std::optional< std::pair< bool, std::string > > getOffsetAndDataFragment(const MCSymbol &Symbol, uint32_t &RelocOffset, MCDataFragment *&DF)
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, MCDwarfLineTableParams Params, int64_t LineDelta, const MCSymbol *Label, int PointerSize)
static std::optional< uint64_t > absoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo)
static bool canReuseDataFragment(const MCDataFragment &F, const MCAssembler &Assembler, const MCSubtargetInfo *STI)
#define F(x, y, z)
Definition: MD5.cpp:55
LLVMContext & Context
bool Debug
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
@ Flags
Definition: TextStubV5.cpp:93
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
Definition: MCCodeView.cpp:327
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
Definition: MCCodeView.cpp:193
void recordCVLoc(MCContext &Ctx, const MCSymbol *Label, unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt)
Saves the information from the currently parsed .cv_loc directive and sets CVLocSeen.
Definition: MCCodeView.cpp:131
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
Definition: MCCodeView.cpp:248
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
Definition: MCCodeView.cpp:422
void emitStringTable(MCObjectStreamer &OS)
Emits the string table substream.
Definition: MCCodeView.cpp:171
MCFragment * emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > Ranges, StringRef FixedSizePortion)
Definition: MCCodeView.cpp:435
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
virtual bool allowEnhancedRelaxation() const
Return true if this target allows an unrelaxable instruction to be emitted into RelaxableFragment and...
Definition: MCAsmBackend.h:59
virtual void relaxInstruction(MCInst &Inst, const MCSubtargetInfo &STI) const
Relax the instruction in the given fragment to the next wider instruction.
Definition: MCAsmBackend.h:172
virtual bool mayNeedRelaxation(const MCInst &Inst, const MCSubtargetInfo &STI) const
Check whether the given instruction may need relaxation.
Definition: MCAsmBackend.h:149
virtual void emitInstructionEnd(MCObjectStreamer &OS, const MCInst &Inst)
Definition: MCAsmBackend.h:66
virtual void emitInstructionBegin(MCObjectStreamer &OS, const MCInst &Inst, const MCSubtargetInfo &STI)
Give the target a chance to manipulate state related to instruction alignment (e.g.
Definition: MCAsmBackend.h:64
virtual std::optional< MCFixupKind > getFixupKind(StringRef Name) const
Map a relocation name used in .reloc to a fixup kind.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:550
void Finish()
Finish - Do final processing and write the object to the output stream.
bool isBundlingEnabled() const
Definition: MCAssembler.h:360
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:333
bool getRelaxAll() const
Definition: MCAssembler.h:357
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:331
void addFileName(StringRef FileName)
Definition: MCAssembler.h:482
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:329
bool registerSection(MCSection &Section)
bool registerSymbol(const MCSymbol &Symbol)
MCDwarfLineTableParams getDWARFLinetableParams() const
Definition: MCAssembler.h:335
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:183
@ Sub
Subtraction.
Definition: MCExpr.h:506
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
Definition: MCCodeEmitter.h:28
Context object for machine code objects.
Definition: MCContext.h:76
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:450
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:318
void RemapDebugPaths()
Definition: MCContext.cpp:890
void clearDwarfLocSeen()
Definition: MCContext.h:782
CodeViewContext & getCVContext()
Definition: MCContext.cpp:1000
const SourceMgr * getSourceManager() const
Definition: MCContext.h:435
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:446
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1055
Fragment for data and encoded instructions.
Definition: MCFragment.h:241
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1855
static void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
Definition: MCDwarf.cpp:669
static void make(MCStreamer *MCOS, MCSection *Section)
Definition: MCDwarf.cpp:94
static void emit(MCStreamer *MCOS, MCDwarfLineTableParams Params)
Definition: MCDwarf.cpp:259
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:749
static MCFixupKind getKindForSize(unsigned Size, bool IsPCRel)
Return the generic fixup kind for a value with the given size.
Definition: MCFixup.h:109
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Definition: MCFixup.h:87
FragmentType getKind() const
Definition: MCFragment.h:93
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1138
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
SMLoc getLoc() const
Definition: MCInst.h:204
MCSection * getDwarfLineSection() const
Streaming object file generation interface.
void reset() override
state management
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel) override
Emit the debug line end entry.
void emitValueToAlignment(Align Alignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
void emitULEB128Value(const MCExpr *Value) override
void emitSLEB128Value(const MCExpr *Value) override
void emitNops(int64_t NumBytes, int64_t ControlledNopLength, SMLoc Loc, const MCSubtargetInfo &STI) override
MCDataFragment * getOrCreateDataFragment(const MCSubtargetInfo *STI=nullptr)
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment.
void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) override
This implements the CodeView '.cv_inline_linetable' assembler directive.
void emitCVStringTableDirective() override
This implements the CodeView '.cv_stringtable' assembler directive.
void emitBundleAlignMode(Align Alignment) override
Set the bundle alignment mode from now on in the section.
MCAssembler & getAssembler()
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
void emitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize) override
If targets does not support representing debug line section by .loc/.file directives in assembly outp...
void emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label)
void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc) override
This implements the CodeView '.cv_loc' assembler directive.
void emitDTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (32-bit DTP relative) value.
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
void emitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
void emitPendingAssignments(MCSymbol *Symbol)
Emits pending conditional assignments that depend on Symbol being emitted.
void emitFileDirective(StringRef Filename) override
Switch to a new logical file.
void emitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > Ranges, StringRef FixedSizePortion) override
This implements the CodeView '.cv_def_range' assembler directive.
void emitGPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel64 (64-bit GP relative) value.
MCAssembler * getAssemblerPtr() override
void flushPendingLabels()
Create a data fragment for any pending labels across all Sections and Subsections.
virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F, uint64_t Offset)
std::optional< std::pair< bool, std::string > > emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc, const MCSubtargetInfo &STI) override
Record a relocation described by the .reloc directive.
void emitAddrsigSym(const MCSymbol *Sym) override
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
void visitUsedSymbol(const MCSymbol &Sym) override
void emitGPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel32 (32-bit GP relative) value.
void insert(MCFragment *F)
virtual void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void finishImpl() override
Streamer specific finalization.
void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo) override
Emit the absolute difference between two symbols encoded with ULEB128.
void emitBundleUnlock() override
Ends a bundle-locked group.
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
void emitCFISections(bool EH, bool Debug) override
void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName) override
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
void addPendingLabel(MCSymbol *label)
Assign a label to the current Section and Subsection even though a fragment is not yet present.
bool mayHaveInstructions(MCSection &Sec) const override
MCFragment * getCurrentFragment() const
void emitCodeAlignment(Align ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
void emitFrames(MCAsmBackend *MAB)
void changeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
void emitTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (64-bit TP relative) value.
void emitCVFileChecksumOffsetDirective(unsigned FileNo) override
This implements the CodeView '.cv_filechecksumoffset' assembler directive.
void emitTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (32-bit TP relative) value.
void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol, but only if Value is also emitted.
void emitCVFileChecksumsDirective() override
This implements the CodeView '.cv_filechecksums' assembler directive.
void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *Begin, const MCSymbol *End) override
This implements the CodeView '.cv_linetable' assembler directive.
void emitDTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (64-bit DTP relative) value.
void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc) override
Emit some number of copies of Value until the byte offset Offset is reached.
void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) override
Emit the absolute difference between two symbols if possible.
void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
static void emit(MCObjectStreamer *MCOS)
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:270
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
void addPendingLabel(MCSymbol *label, unsigned Subsection=0)
Add a pending label for the requested subsection.
Definition: MCSection.cpp:91
virtual StringRef getVirtualSectionKind() const
Definition: MCSection.cpp:89
void ensureMinAlignment(Align MinAlignment)
Makes sure that Alignment is at least MinAlignment.
Definition: MCSection.h:144
void flushPendingLabels(MCFragment *F, uint64_t FOffset=0, unsigned Subsection=0)
Associate all pending labels in a subsection with a fragment.
Definition: MCSection.cpp:95
bool hasInstructions() const
Definition: MCSection.h:166
void setHasInstructions(bool Value)
Definition: MCSection.h:167
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
bool isBundleLocked() const
Definition: MCSection.h:157
StringRef getName() const
Definition: MCSection.h:124
FragmentListType::iterator iterator
Definition: MCSection.h:64
Streaming machine code generation interface.
Definition: MCStreamer.h:212
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName)
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
Definition: MCStreamer.cpp:263
virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo)
Emit the absolute difference between two symbols encoded with ULEB128.
bool getUseAssemblerInfoForParsing()
Definition: MCStreamer.h:302
MCContext & getContext() const
Definition: MCStreamer.h:297
bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc)
Returns true if the the .cv_loc directive is in the right section.
Definition: MCStreamer.cpp:325
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:424
void setAllowAutoPadding(bool v)
Definition: MCStreamer.h:308
virtual void reset()
State management.
Definition: MCStreamer.cpp:102
virtual void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView '.cv_linetable' assembler directive.
Definition: MCStreamer.cpp:347
virtual void emitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:446
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
Definition: MCStreamer.cpp:134
unsigned getNumFrameInfos()
Definition: MCStreamer.cpp:116
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:162
MCSymbol * endSection(MCSection *Section)
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
virtual void emitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > Ranges, StringRef FixedSizePortion)
This implements the CodeView '.cv_def_range' assembler directive.
Definition: MCStreamer.cpp:369
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:393
virtual void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Emit the expression Value into the output as a native integer of the given Size bytes.
unsigned emitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:172
virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
This implements the CodeView '.cv_inline_linetable' assembler directive.
Definition: MCStreamer.cpp:351
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
const MCSymbol & getSymbol() const
Definition: MCExpr.h:399
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:386
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:251
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:301
uint64_t getOffset() const
Definition: MCSymbol.h:328
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:398
This represents an "assembler immediate".
Definition: MCValue.h:36
int64_t getConstant() const
Definition: MCValue.h:43
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:45
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:44
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:49
Represents a location in source code.
Definition: SMLoc.h:23
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Definition: SourceMgr.cpp:352
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
#define INT64_MAX
Definition: DataTypes.h:71
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:440
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:256
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:21
@ FK_DTPRel_4
A four-byte dtp relative fixup.
Definition: MCFixup.h:36
@ FK_DTPRel_8
A eight-byte dtp relative fixup.
Definition: MCFixup.h:37
@ FK_TPRel_4
A four-byte tp relative fixup.
Definition: MCFixup.h:38
@ FK_GPRel_4
A four-byte gp relative fixup.
Definition: MCFixup.h:34
@ FK_TPRel_8
A eight-byte tp relative fixup.
Definition: MCFixup.h:39
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:261
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1946
Definition: BitVector.h:858
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
MCSymbol * Begin
Definition: MCDwarf.h:685