LLVM 23.0.0git
MCAssembler.cpp
Go to the documentation of this file.
1//===- lib/MC/MCAssembler.cpp - Assembler Backend Implementation ----------===//
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
10#include "llvm/ADT/ArrayRef.h"
12#include "llvm/ADT/Statistic.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/ADT/Twine.h"
16#include "llvm/MC/MCAsmInfo.h"
18#include "llvm/MC/MCCodeView.h"
19#include "llvm/MC/MCContext.h"
20#include "llvm/MC/MCDwarf.h"
21#include "llvm/MC/MCExpr.h"
22#include "llvm/MC/MCFixup.h"
23#include "llvm/MC/MCInst.h"
25#include "llvm/MC/MCSFrame.h"
26#include "llvm/MC/MCSection.h"
27#include "llvm/MC/MCSymbol.h"
28#include "llvm/MC/MCValue.h"
31#include "llvm/Support/Debug.h"
34#include "llvm/Support/LEB128.h"
36#include <cassert>
37#include <cstdint>
38#include <tuple>
39#include <utility>
40
41using namespace llvm;
42
43namespace llvm {
44class MCSubtargetInfo;
45}
46
47#define DEBUG_TYPE "assembler"
48
49namespace {
50namespace stats {
51
52STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total");
53STATISTIC(EmittedRelaxableFragments,
54 "Number of emitted assembler fragments - relaxable");
55STATISTIC(EmittedDataFragments,
56 "Number of emitted assembler fragments - data");
57STATISTIC(EmittedAlignFragments,
58 "Number of emitted assembler fragments - align");
59STATISTIC(EmittedFillFragments,
60 "Number of emitted assembler fragments - fill");
61STATISTIC(EmittedNopsFragments, "Number of emitted assembler fragments - nops");
62STATISTIC(EmittedOrgFragments, "Number of emitted assembler fragments - org");
63STATISTIC(Fixups, "Number of fixups");
64STATISTIC(FixupEvalForRelax, "Number of fixup evaluations for relaxation");
65STATISTIC(ObjectBytes, "Number of emitted object file bytes");
66STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
67STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
68
69} // end namespace stats
70} // end anonymous namespace
71
72// FIXME FIXME FIXME: There are number of places in this file where we convert
73// what is a 64-bit assembler value used for computation into a value in the
74// object file, which may truncate it. We should detect that truncation where
75// invalid and report errors back.
76
77/* *** */
78
80 std::unique_ptr<MCAsmBackend> Backend,
81 std::unique_ptr<MCCodeEmitter> Emitter,
82 std::unique_ptr<MCObjectWriter> Writer)
83 : Context(Context), Backend(std::move(Backend)),
84 Emitter(std::move(Emitter)), Writer(std::move(Writer)) {
85 if (this->Backend)
86 this->Backend->setAssembler(this);
87 if (this->Writer)
88 this->Writer->setAssembler(this);
89}
90
92 HasLayout = false;
93 HasFinalLayout = false;
94 RelaxAll = false;
95 Sections.clear();
96 Symbols.clear();
97 ThumbFuncs.clear();
98
99 // reset objects owned by us
100 if (getBackendPtr())
101 getBackendPtr()->reset();
102 if (getEmitterPtr())
103 getEmitterPtr()->reset();
104 if (Writer)
105 Writer->reset();
106}
107
109 if (Section.isRegistered())
110 return false;
111 Sections.push_back(&Section);
112 Section.setIsRegistered(true);
113 return true;
114}
115
116bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
117 if (ThumbFuncs.count(Symbol))
118 return true;
119
120 if (!Symbol->isVariable())
121 return false;
122
123 const MCExpr *Expr = Symbol->getVariableValue();
124
125 MCValue V;
126 if (!Expr->evaluateAsRelocatable(V, nullptr))
127 return false;
128
129 if (V.getSubSym() || V.getSpecifier())
130 return false;
131
132 auto *Sym = V.getAddSym();
133 if (!Sym || V.getSpecifier())
134 return false;
135
136 if (!isThumbFunc(Sym))
137 return false;
138
139 ThumbFuncs.insert(Symbol); // Cache it.
140 return true;
141}
142
143bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
145 bool RecordReloc, uint8_t *Data) const {
146 if (RecordReloc)
147 ++stats::Fixups;
148
149 // FIXME: This code has some duplication with recordRelocation. We should
150 // probably merge the two into a single callback that tries to evaluate a
151 // fixup and records a relocation if one is needed.
152
153 // On error claim to have completely evaluated the fixup, to prevent any
154 // further processing from being done.
155 const MCExpr *Expr = Fixup.getValue();
156 Value = 0;
157 if (!Expr->evaluateAsRelocatable(Target, this)) {
158 reportError(Fixup.getLoc(), "expected relocatable expression");
159 return true;
160 }
161
162 bool IsResolved = false;
163 if (auto State = getBackend().evaluateFixup(F, Fixup, Target, Value)) {
164 IsResolved = *State;
165 } else {
166 const MCSymbol *Add = Target.getAddSym();
167 const MCSymbol *Sub = Target.getSubSym();
168 Value += Target.getConstant();
169 if (Add && Add->isDefined())
171 if (Sub && Sub->isDefined())
173
174 if (Fixup.isPCRel()) {
175 Value -= getFragmentOffset(F) + Fixup.getOffset();
176 // During relaxation, F's offset is already updated but forward reference
177 // targets are stale. Add Stretch so that the displacement equals
178 // target_old - source_old, preventing premature relaxation.
179 if (Stretch) {
180 assert(!RecordReloc &&
181 "Stretch should only be applied during relaxation");
182 MCFragment *AF = Add ? Add->getFragment() : nullptr;
183 if (AF && AF->getLayoutOrder() > F.getLayoutOrder())
184 Value += Stretch;
185 MCFragment *SF = Sub ? Sub->getFragment() : nullptr;
186 if (SF && SF->getLayoutOrder() > F.getLayoutOrder())
187 Value -= Stretch;
188 }
189 if (Add && !Sub && !Add->isUndefined() && !Add->isAbsolute()) {
191 *Add, F, false, true);
192 }
193 } else {
194 IsResolved = Target.isAbsolute();
195 }
196 }
197
198 if (!RecordReloc)
199 return IsResolved;
200
201 if (IsResolved && mc::isRelocRelocation(Fixup.getKind()))
202 IsResolved = false;
203 getBackend().applyFixup(F, Fixup, Target, Data, Value, IsResolved);
204 return true;
205}
206
208 assert(getBackendPtr() && "Requires assembler backend");
209 switch (F.getKind()) {
219 return F.getSize();
220 case MCFragment::FT_Fill: {
221 auto &FF = static_cast<const MCFillFragment &>(F);
222 int64_t NumValues = 0;
223 if (!FF.getNumValues().evaluateKnownAbsolute(NumValues, *this)) {
224 recordError(FF.getLoc(), "expected assembly-time absolute expression");
225 return 0;
226 }
227 int64_t Size = NumValues * FF.getValueSize();
228 if (Size < 0) {
229 recordError(FF.getLoc(), "invalid number of bytes");
230 return 0;
231 }
232 return Size;
233 }
234
236 return F.getSize();
237
239 return cast<MCNopsFragment>(F).getNumBytes();
240
242 return cast<MCBoundaryAlignFragment>(F).getSize();
243
245 return 4;
246
247 case MCFragment::FT_Org: {
250 if (!OF.getOffset().evaluateAsValue(Value, *this)) {
251 recordError(OF.getLoc(), "expected assembly-time absolute expression");
252 return 0;
253 }
254
255 uint64_t FragmentOffset = getFragmentOffset(OF);
256 int64_t TargetLocation = Value.getConstant();
257 if (const auto *SA = Value.getAddSym()) {
258 uint64_t Val;
259 if (!getSymbolOffset(*SA, Val)) {
260 recordError(OF.getLoc(), "expected absolute expression");
261 return 0;
262 }
263 TargetLocation += Val;
264 }
265 int64_t Size = TargetLocation - FragmentOffset;
266 if (Size < 0 || Size >= 0x40000000) {
267 recordError(OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
268 "' (at offset '" + Twine(FragmentOffset) +
269 "')");
270 return 0;
271 }
272 return Size;
273 }
274 }
275
276 llvm_unreachable("invalid fragment kind");
277}
278
279// Simple getSymbolOffset helper for the non-variable case.
280static bool getLabelOffset(const MCAssembler &Asm, const MCSymbol &S,
281 bool ReportError, uint64_t &Val) {
282 if (!S.getFragment()) {
283 if (ReportError)
284 reportFatalUsageError("cannot evaluate undefined symbol '" + S.getName() +
285 "'");
286 return false;
287 }
288 Val = Asm.getFragmentOffset(*S.getFragment()) + S.getOffset();
289 return true;
290}
291
292static bool getSymbolOffsetImpl(const MCAssembler &Asm, const MCSymbol &S,
293 bool ReportError, uint64_t &Val) {
294 if (!S.isVariable())
295 return getLabelOffset(Asm, S, ReportError, Val);
296
297 // If SD is a variable, evaluate it.
300 reportFatalUsageError("cannot evaluate equated symbol '" + S.getName() +
301 "'");
302
303 uint64_t Offset = Target.getConstant();
304
305 const MCSymbol *A = Target.getAddSym();
306 if (A) {
307 uint64_t ValA;
308 // FIXME: On most platforms, `Target`'s component symbols are labels from
309 // having been simplified during evaluation, but on Mach-O they can be
310 // variables due to PR19203. This, and the line below for `B` can be
311 // restored to call `getLabelOffset` when PR19203 is fixed.
312 if (!getSymbolOffsetImpl(Asm, *A, ReportError, ValA))
313 return false;
314 Offset += ValA;
315 }
316
317 const MCSymbol *B = Target.getSubSym();
318 if (B) {
319 uint64_t ValB;
320 if (!getSymbolOffsetImpl(Asm, *B, ReportError, ValB))
321 return false;
322 Offset -= ValB;
323 }
324
325 Val = Offset;
326 return true;
327}
328
330 return getSymbolOffsetImpl(*this, S, false, Val);
331}
332
334 uint64_t Val;
335 getSymbolOffsetImpl(*this, S, true, Val);
336 return Val;
337}
338
339const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
340 assert(HasLayout);
341 if (!Symbol.isVariable())
342 return &Symbol;
343
344 const MCExpr *Expr = Symbol.getVariableValue();
346 if (!Expr->evaluateAsValue(Value, *this)) {
347 reportError(Expr->getLoc(), "expression could not be evaluated");
348 return nullptr;
349 }
350
351 const MCSymbol *SymB = Value.getSubSym();
352 if (SymB) {
353 reportError(Expr->getLoc(),
354 Twine("symbol '") + SymB->getName() +
355 "' could not be evaluated in a subtraction expression");
356 return nullptr;
357 }
358
359 const MCSymbol *A = Value.getAddSym();
360 if (!A)
361 return nullptr;
362
363 const MCSymbol &ASym = *A;
364 if (ASym.isCommon()) {
365 reportError(Expr->getLoc(), "Common symbol '" + ASym.getName() +
366 "' cannot be used in assignment expr");
367 return nullptr;
368 }
369
370 return &ASym;
371}
372
374 const MCFragment &F = *Sec.curFragList()->Tail;
375 assert(HasLayout && F.getKind() == MCFragment::FT_Data);
376 return getFragmentOffset(F) + F.getSize();
377}
378
380 // Virtual sections have no file size.
381 if (Sec.isBssSection())
382 return 0;
383 return getSectionAddressSize(Sec);
384}
385
387 bool Changed = !Symbol.isRegistered();
388 if (Changed) {
389 Symbol.setIsRegistered(true);
390 Symbols.push_back(&Symbol);
391 }
392 return Changed;
393}
394
395void MCAssembler::addRelocDirective(RelocDirective RD) {
396 relocDirectives.push_back(RD);
397}
398
399/// Write the fragment \p F to the output file.
400static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
401 const MCFragment &F) {
402 // FIXME: Embed in fragments instead?
403 uint64_t FragmentSize = Asm.computeFragmentSize(F);
404
405 llvm::endianness Endian = Asm.getBackend().Endian;
406
407 // This variable (and its dummy usage) is to participate in the assert at
408 // the end of the function.
409 uint64_t Start = OS.tell();
410 (void) Start;
411
412 ++stats::EmittedFragments;
413
414 switch (F.getKind()) {
423 if (F.getKind() == MCFragment::FT_Data)
424 ++stats::EmittedDataFragments;
425 else if (F.getKind() == MCFragment::FT_Relaxable)
426 ++stats::EmittedRelaxableFragments;
427 const auto &EF = cast<MCFragment>(F);
428 OS << StringRef(EF.getContents().data(), EF.getContents().size());
429 OS << StringRef(EF.getVarContents().data(), EF.getVarContents().size());
430 } break;
431
433 ++stats::EmittedAlignFragments;
434 OS << StringRef(F.getContents().data(), F.getContents().size());
435 assert(F.getAlignFillLen() &&
436 "Invalid virtual align in concrete fragment!");
437
438 uint64_t Count = (FragmentSize - F.getFixedSize()) / F.getAlignFillLen();
439 assert((FragmentSize - F.getFixedSize()) % F.getAlignFillLen() == 0 &&
440 "computeFragmentSize computed size is incorrect");
441
442 // In the nops mode, call the backend hook to write `Count` nops.
443 if (F.hasAlignEmitNops()) {
444 if (!Asm.getBackend().writeNopData(OS, Count, F.getSubtargetInfo()))
445 reportFatalInternalError("unable to write nop sequence of " +
446 Twine(Count) + " bytes");
447 } else {
448 // Otherwise, write out in multiples of the value size.
449 for (uint64_t i = 0; i != Count; ++i) {
450 switch (F.getAlignFillLen()) {
451 default:
452 llvm_unreachable("Invalid size!");
453 case 1:
454 OS << char(F.getAlignFill());
455 break;
456 case 2:
457 support::endian::write<uint16_t>(OS, F.getAlignFill(), Endian);
458 break;
459 case 4:
460 support::endian::write<uint32_t>(OS, F.getAlignFill(), Endian);
461 break;
462 case 8:
463 support::endian::write<uint64_t>(OS, F.getAlignFill(), Endian);
464 break;
465 }
466 }
467 }
468 } break;
469
471 OS << StringRef(F.getContents().data(), F.getContents().size());
472 uint64_t PadSize = FragmentSize - F.getContents().size();
473 if (F.getPrefAlignEmitNops()) {
474 if (!Asm.getBackend().writeNopData(OS, PadSize, F.getSubtargetInfo()))
475 reportFatalInternalError("unable to write nop sequence of " +
476 Twine(PadSize) + " bytes");
477 } else if (F.getPrefAlignFill() == 0) {
478 OS.write_zeros(PadSize);
479 } else {
480 char B = char(F.getPrefAlignFill());
481 for (uint64_t I = 0; I < PadSize; ++I)
482 OS << B;
483 }
484 break;
485 }
486
487 case MCFragment::FT_Fill: {
488 ++stats::EmittedFillFragments;
490 uint64_t V = FF.getValue();
491 unsigned VSize = FF.getValueSize();
492 const unsigned MaxChunkSize = 16;
493 char Data[MaxChunkSize];
494 assert(0 < VSize && VSize <= MaxChunkSize && "Illegal fragment fill size");
495 // Duplicate V into Data as byte vector to reduce number of
496 // writes done. As such, do endian conversion here.
497 for (unsigned I = 0; I != VSize; ++I) {
498 unsigned index = Endian == llvm::endianness::little ? I : (VSize - I - 1);
499 Data[I] = uint8_t(V >> (index * 8));
500 }
501 for (unsigned I = VSize; I < MaxChunkSize; ++I)
502 Data[I] = Data[I - VSize];
503
504 // Set to largest multiple of VSize in Data.
505 const unsigned NumPerChunk = MaxChunkSize / VSize;
506 // Set ChunkSize to largest multiple of VSize in Data
507 const unsigned ChunkSize = VSize * NumPerChunk;
508
509 // Do copies by chunk.
510 StringRef Ref(Data, ChunkSize);
511 for (uint64_t I = 0, E = FragmentSize / ChunkSize; I != E; ++I)
512 OS << Ref;
513
514 // do remainder if needed.
515 unsigned TrailingCount = FragmentSize % ChunkSize;
516 if (TrailingCount)
517 OS.write(Data, TrailingCount);
518 break;
519 }
520
521 case MCFragment::FT_Nops: {
522 ++stats::EmittedNopsFragments;
524
525 int64_t NumBytes = NF.getNumBytes();
526 int64_t ControlledNopLength = NF.getControlledNopLength();
527 int64_t MaximumNopLength =
528 Asm.getBackend().getMaximumNopSize(*NF.getSubtargetInfo());
529
530 assert(NumBytes > 0 && "Expected positive NOPs fragment size");
531 assert(ControlledNopLength >= 0 && "Expected non-negative NOP size");
532
533 if (ControlledNopLength > MaximumNopLength) {
534 Asm.reportError(NF.getLoc(), "illegal NOP size " +
535 std::to_string(ControlledNopLength) +
536 ". (expected within [0, " +
537 std::to_string(MaximumNopLength) + "])");
538 // Clamp the NOP length as reportError does not stop the execution
539 // immediately.
540 ControlledNopLength = MaximumNopLength;
541 }
542
543 // Use maximum value if the size of each NOP is not specified
544 if (!ControlledNopLength)
545 ControlledNopLength = MaximumNopLength;
546
547 while (NumBytes) {
548 uint64_t NumBytesToEmit =
549 (uint64_t)std::min(NumBytes, ControlledNopLength);
550 assert(NumBytesToEmit && "try to emit empty NOP instruction");
551 if (!Asm.getBackend().writeNopData(OS, NumBytesToEmit,
552 NF.getSubtargetInfo())) {
553 report_fatal_error("unable to write nop sequence of the remaining " +
554 Twine(NumBytesToEmit) + " bytes");
555 break;
556 }
557 NumBytes -= NumBytesToEmit;
558 }
559 break;
560 }
561
564 if (!Asm.getBackend().writeNopData(OS, FragmentSize, BF.getSubtargetInfo()))
565 report_fatal_error("unable to write nop sequence of " +
566 Twine(FragmentSize) + " bytes");
567 break;
568 }
569
573 break;
574 }
575
576 case MCFragment::FT_Org: {
577 ++stats::EmittedOrgFragments;
579
580 for (uint64_t i = 0, e = FragmentSize; i != e; ++i)
581 OS << char(OF.getValue());
582
583 break;
584 }
585
586 }
587
588 assert(OS.tell() - Start == FragmentSize &&
589 "The stream should advance by fragment size");
590}
591
593 const MCSection *Sec) const {
594 assert(getBackendPtr() && "Expected assembler backend");
595
596 if (Sec->isBssSection()) {
597 assert(getSectionFileSize(*Sec) == 0 && "Invalid size for section!");
598
599 // Ensure no fixups or non-zero bytes are written to BSS sections, catching
600 // errors in both input assembly code and MCStreamer API usage. Location is
601 // not tracked for efficiency.
602 auto Fn = [](char c) { return c != 0; };
603 for (const MCFragment &F : *Sec) {
604 bool HasNonZero = false;
605 switch (F.getKind()) {
606 default:
607 reportFatalInternalError("BSS section '" + Sec->getName() +
608 "' contains invalid fragment");
609 break;
612 HasNonZero =
613 any_of(F.getContents(), Fn) || any_of(F.getVarContents(), Fn);
614 break;
616 // Disallowed for API usage. AsmParser changes non-zero fill values to
617 // 0.
618 assert(F.getAlignFill() == 0 && "Invalid align in virtual section!");
619 break;
621 assert(!F.getPrefAlignEmitNops() && F.getPrefAlignFill() == 0 &&
622 "Invalid align in BSS");
623 break;
625 HasNonZero = cast<MCFillFragment>(F).getValue() != 0;
626 break;
628 HasNonZero = cast<MCOrgFragment>(F).getValue() != 0;
629 break;
630 }
631 if (HasNonZero) {
632 reportError(SMLoc(), "BSS section '" + Sec->getName() +
633 "' cannot have non-zero bytes");
634 break;
635 }
636 if (F.getFixups().size() || F.getVarFixups().size()) {
638 "BSS section '" + Sec->getName() + "' cannot have fixups");
639 break;
640 }
641 }
642
643 return;
644 }
645
646 uint64_t Start = OS.tell();
647 (void)Start;
648
649 for (const MCFragment &F : *Sec)
650 writeFragment(OS, *this, F);
651
653 assert(getContext().hadError() ||
654 OS.tell() - Start == getSectionAddressSize(*Sec));
655}
656
658 assert(getBackendPtr() && "Expected assembler backend");
659 DEBUG_WITH_TYPE("mc-dump-pre", {
660 errs() << "assembler backend - pre-layout\n--\n";
661 dump();
662 });
663
664 // Assign section ordinals.
665 unsigned SectionIndex = 0;
666 for (MCSection &Sec : *this) {
667 Sec.setOrdinal(SectionIndex++);
668
669 // Chain together fragments from all subsections.
670 if (Sec.Subsections.size() > 1) {
671 MCFragment Dummy;
672 MCFragment *Tail = &Dummy;
673 for (auto &[_, List] : Sec.Subsections) {
674 assert(List.Head);
675 Tail->Next = List.Head;
676 Tail = List.Tail;
677 }
678 Sec.Subsections.clear();
679 Sec.Subsections.push_back({0u, {Dummy.getNext(), Tail}});
680 Sec.CurFragList = &Sec.Subsections[0].second;
681
682 unsigned FragmentIndex = 0;
683 for (MCFragment &Frag : Sec)
684 Frag.setLayoutOrder(FragmentIndex++);
685 }
686 }
687
688 // Layout until everything fits.
689 this->HasLayout = true;
690 for (MCSection &Sec : *this)
691 layoutSection(Sec);
692 unsigned FirstStable = Sections.size();
693 while ((FirstStable = relaxOnce(FirstStable)) > 0)
694 if (getContext().hadError())
695 return;
696
697 // Some targets might want to adjust fragment offsets. If so, perform another
698 // layout iteration.
699 if (getBackend().finishLayout())
700 for (MCSection &Sec : *this)
701 layoutSection(Sec);
702
704
705 DEBUG_WITH_TYPE("mc-dump", {
706 errs() << "assembler backend - final-layout\n--\n";
707 dump(); });
708
709 // Allow the object writer a chance to perform post-layout binding (for
710 // example, to set the index fields in the symbol data).
712
713 // Fragment sizes are finalized. For RISC-V linker relaxation, this flag
714 // helps check whether a PC-relative fixup is fully resolved.
715 this->HasFinalLayout = true;
716
717 // Resolve .reloc offsets and add fixups.
718 for (auto &PF : relocDirectives) {
719 MCValue Res;
720 auto &O = PF.Offset;
721 if (!O.evaluateAsValue(Res, *this)) {
722 getContext().reportError(O.getLoc(), ".reloc offset is not relocatable");
723 continue;
724 }
725 auto *Sym = Res.getAddSym();
726 auto *F = Sym ? Sym->getFragment() : nullptr;
727 auto *Sec = F ? F->getParent() : nullptr;
728 if (Res.getSubSym() || !Sec) {
729 getContext().reportError(O.getLoc(),
730 ".reloc offset is not relative to a section");
731 continue;
732 }
733
734 uint64_t Offset = Sym ? Sym->getOffset() + Res.getConstant() : 0;
735 F->addFixup(MCFixup::create(Offset, PF.Expr, PF.Kind));
736 }
737
738 // Evaluate and apply the fixups, generating relocation entries as necessary.
739 for (MCSection &Sec : *this) {
740 for (MCFragment &F : Sec) {
741 // Process fragments with fixups here.
742 auto Contents = F.getContents();
743 for (MCFixup &Fixup : F.getFixups()) {
744 uint64_t FixedValue;
747 Fixup.getOffset() <= F.getFixedSize());
748 auto *Data =
749 reinterpret_cast<uint8_t *>(Contents.data() + Fixup.getOffset());
750 evaluateFixup(F, Fixup, Target, FixedValue,
751 /*RecordReloc=*/true, Data);
752 }
753 // In the variable part, fixup offsets are relative to the fixed part's
754 // start.
755 for (MCFixup &Fixup : F.getVarFixups()) {
756 uint64_t FixedValue;
759 (Fixup.getOffset() >= F.getFixedSize() &&
760 Fixup.getOffset() <= F.getSize()));
761 auto *Data = reinterpret_cast<uint8_t *>(
762 F.getVarContents().data() + (Fixup.getOffset() - F.getFixedSize()));
763 evaluateFixup(F, Fixup, Target, FixedValue,
764 /*RecordReloc=*/true, Data);
765 }
766 }
767 }
768}
769
771 layout();
772
773 // Write the object file if there is no error. The output would be discarded
774 // anyway, and this avoids wasting time writing large files (e.g. when testing
775 // fixup overflow with `.space 0x80000000`).
776 if (!getContext().hadError())
777 stats::ObjectBytes += getWriter().writeObject();
778
779 HasLayout = false;
780 assert(PendingErrors.empty());
781}
782
783void MCAssembler::relaxAlign(MCFragment &F) {
784 uint64_t Offset = F.Offset + F.getFixedSize();
785 unsigned Size = offsetToAlignment(Offset, F.getAlignment());
786 bool AlignFixup = false;
787 if (F.hasAlignEmitNops()) {
788 AlignFixup = getBackend().relaxAlign(F, Size);
789 if (!AlignFixup)
790 while (Size % getBackend().getMinimumNopSize())
791 Size += F.getAlignment().value();
792 }
793 if (!AlignFixup && Size > F.getAlignMaxBytesToEmit())
794 Size = 0;
795 F.VarContentStart = F.getFixedSize();
796 F.VarContentEnd = F.VarContentStart + Size;
797 if (F.VarContentEnd > F.getParent()->ContentStorage.size())
798 F.getParent()->ContentStorage.resize(F.VarContentEnd);
799}
800
801// Compute the body size by walking forward from F to the End symbol and
802// summing fragment sizes. This avoids depending on stale layout offsets.
803void MCAssembler::relaxPrefAlign(MCFragment &F) {
804 uint64_t RawStart = F.Offset + F.getFixedSize();
805 const MCSymbol &End = F.getPrefAlignEnd();
806 if (!End.getFragment() || End.getFragment()->getParent() != F.getParent()) {
807 recordError(SMLoc(), ".prefalign end symbol '" + End.getName() +
808 "' must be in the current section");
809 return;
810 }
811 const MCFragment *EndFrag = End.getFragment();
812 if (EndFrag->getLayoutOrder() <= F.getLayoutOrder())
813 return;
814 uint64_t BodySize = 0;
815 for (const MCFragment *Cur = F.getNext();; Cur = Cur->getNext()) {
816 if (Cur == EndFrag) {
817 BodySize += End.getOffset();
818 break;
819 }
820 BodySize += computeFragmentSize(*Cur);
821 }
822 Align NewAlign =
823 std::min(Align(llvm::bit_ceil(BodySize)), F.getPrefAlignPreferred());
824 F.setPrefAlignComputed(NewAlign);
825 uint64_t NewPadSize = offsetToAlignment(RawStart, NewAlign);
826 F.VarContentStart = F.getFixedSize();
827 F.VarContentEnd = F.VarContentStart + NewPadSize;
828 if (F.VarContentEnd > F.getParent()->ContentStorage.size())
829 F.getParent()->ContentStorage.resize(F.VarContentEnd);
830 // Update the maximum alignment on the current section if necessary, similar
831 // to MCObjectStreamer::emitValueToAlignment.
832 F.getParent()->ensureMinAlignment(NewAlign);
833}
834
835bool MCAssembler::fixupNeedsRelaxation(const MCFragment &F,
836 const MCFixup &Fixup) const {
837 ++stats::FixupEvalForRelax;
838 MCValue Target;
839 uint64_t Value;
840 bool Resolved = evaluateFixup(F, const_cast<MCFixup &>(Fixup), Target, Value,
841 /*RecordReloc=*/false, {});
843 Resolved);
844}
845
846void MCAssembler::relaxInstruction(MCFragment &F) {
848 "Expected CodeEmitter defined for relaxInstruction");
849 // If this inst doesn't ever need relaxation, ignore it. This occurs when we
850 // are intentionally pushing out inst fragments, or because we relaxed a
851 // previous instruction to one that doesn't need relaxation.
852 if (!getBackend().mayNeedRelaxation(F.getOpcode(), F.getOperands(),
853 *F.getSubtargetInfo()))
854 return;
855
856 bool DoRelax = false;
857 for (const MCFixup &Fixup : F.getVarFixups())
858 if ((DoRelax = fixupNeedsRelaxation(F, Fixup)))
859 break;
860 if (!DoRelax)
861 return;
862
863 ++stats::RelaxedInstructions;
864
865 // TODO Refactor relaxInstruction to accept MCFragment and remove
866 // `setInst`.
867 MCInst Relaxed = F.getInst();
868 getBackend().relaxInstruction(Relaxed, *F.getSubtargetInfo());
869
870 // Encode the new instruction.
871 F.setInst(Relaxed);
874 getEmitter().encodeInstruction(Relaxed, Data, Fixups, *F.getSubtargetInfo());
875 F.setVarContents(Data);
876 F.setVarFixups(Fixups);
877}
878
879void MCAssembler::relaxLEB(MCFragment &F) {
880 unsigned PadTo = F.getVarSize();
881 int64_t Value;
882 F.clearVarFixups();
883 // Use evaluateKnownAbsolute for Mach-O as a hack: .subsections_via_symbols
884 // requires that .uleb128 A-B is foldable where A and B reside in different
885 // fragments. This is used by __gcc_except_table.
887 ? F.getLEBValue().evaluateKnownAbsolute(Value, *this)
888 : F.getLEBValue().evaluateAsAbsolute(Value, *this);
889 if (!Abs) {
890 bool Relaxed, UseZeroPad;
891 std::tie(Relaxed, UseZeroPad) = getBackend().relaxLEB128(F, Value);
892 if (!Relaxed) {
893 reportError(F.getLEBValue().getLoc(),
894 Twine(F.isLEBSigned() ? ".s" : ".u") +
895 "leb128 expression is not absolute");
896 F.setLEBValue(MCConstantExpr::create(0, Context));
897 }
898 uint8_t Tmp[10]; // maximum size: ceil(64/7)
899 PadTo = std::max(PadTo, encodeULEB128(uint64_t(Value), Tmp));
900 if (UseZeroPad)
901 Value = 0;
902 }
903 uint8_t Data[16];
904 size_t Size = 0;
905 // The compiler can generate EH table assembly that is impossible to assemble
906 // without either adding padding to an LEB fragment or adding extra padding
907 // to a later alignment fragment. To accommodate such tables, relaxation can
908 // only increase an LEB fragment size here, not decrease it. See PR35809.
909 if (F.isLEBSigned())
910 Size = encodeSLEB128(Value, Data, PadTo);
911 else
912 Size = encodeULEB128(Value, Data, PadTo);
913 F.setVarContents({reinterpret_cast<char *>(Data), Size});
914}
915
916/// Check if the branch crosses the boundary.
917///
918/// \param StartAddr start address of the fused/unfused branch.
919/// \param Size size of the fused/unfused branch.
920/// \param BoundaryAlignment alignment requirement of the branch.
921/// \returns true if the branch cross the boundary.
922static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size,
923 Align BoundaryAlignment) {
924 uint64_t EndAddr = StartAddr + Size;
925 return (StartAddr >> Log2(BoundaryAlignment)) !=
926 ((EndAddr - 1) >> Log2(BoundaryAlignment));
927}
928
929/// Check if the branch is against the boundary.
930///
931/// \param StartAddr start address of the fused/unfused branch.
932/// \param Size size of the fused/unfused branch.
933/// \param BoundaryAlignment alignment requirement of the branch.
934/// \returns true if the branch is against the boundary.
936 Align BoundaryAlignment) {
937 uint64_t EndAddr = StartAddr + Size;
938 return (EndAddr & (BoundaryAlignment.value() - 1)) == 0;
939}
940
941/// Check if the branch needs padding.
942///
943/// \param StartAddr start address of the fused/unfused branch.
944/// \param Size size of the fused/unfused branch.
945/// \param BoundaryAlignment alignment requirement of the branch.
946/// \returns true if the branch needs padding.
947static bool needPadding(uint64_t StartAddr, uint64_t Size,
948 Align BoundaryAlignment) {
949 return mayCrossBoundary(StartAddr, Size, BoundaryAlignment) ||
950 isAgainstBoundary(StartAddr, Size, BoundaryAlignment);
951}
952
953void MCAssembler::relaxBoundaryAlign(MCBoundaryAlignFragment &BF) {
954 // BoundaryAlignFragment that doesn't need to align any fragment should not be
955 // relaxed.
956 if (!BF.getLastFragment())
957 return;
958
959 uint64_t AlignedOffset = getFragmentOffset(BF);
960 uint64_t AlignedSize = 0;
961 for (const MCFragment *F = BF.getNext();; F = F->getNext()) {
962 AlignedSize += computeFragmentSize(*F);
963 if (F == BF.getLastFragment())
964 break;
965 }
966
967 Align BoundaryAlignment = BF.getAlignment();
968 uint64_t NewSize = needPadding(AlignedOffset, AlignedSize, BoundaryAlignment)
969 ? offsetToAlignment(AlignedOffset, BoundaryAlignment)
970 : 0U;
971 if (NewSize == BF.getSize())
972 return;
973 BF.setSize(NewSize);
974}
975
976void MCAssembler::relaxDwarfLineAddr(MCFragment &F) {
977 if (getBackend().relaxDwarfLineAddr(F))
978 return;
979
980 MCContext &Context = getContext();
981 int64_t AddrDelta;
982 bool Abs = F.getDwarfAddrDelta().evaluateKnownAbsolute(AddrDelta, *this);
983 assert(Abs && "We created a line delta with an invalid expression");
984 (void)Abs;
985 SmallVector<char, 8> Data;
987 F.getDwarfLineDelta(), AddrDelta, Data);
988 F.setVarContents(Data);
989 F.clearVarFixups();
990}
991
992void MCAssembler::relaxDwarfCallFrameFragment(MCFragment &F) {
993 if (getBackend().relaxDwarfCFA(F))
994 return;
995
996 MCContext &Context = getContext();
997 int64_t Value;
998 bool Abs = F.getDwarfAddrDelta().evaluateAsAbsolute(Value, *this);
999 if (!Abs) {
1000 reportError(F.getDwarfAddrDelta().getLoc(),
1001 "invalid CFI advance_loc expression");
1002 F.setDwarfAddrDelta(MCConstantExpr::create(0, Context));
1003 return;
1004 }
1005
1006 SmallVector<char, 8> Data;
1008 F.setVarContents(Data);
1009 F.clearVarFixups();
1010}
1011
1012void MCAssembler::relaxSFrameFragment(MCFragment &F) {
1013 assert(F.getKind() == MCFragment::FT_SFrame);
1014 MCContext &C = getContext();
1015 int64_t Value;
1016 bool Abs = F.getSFrameAddrDelta().evaluateAsAbsolute(Value, *this);
1017 if (!Abs) {
1018 C.reportError(F.getSFrameAddrDelta().getLoc(),
1019 "invalid CFI advance_loc expression in sframe");
1020 F.setSFrameAddrDelta(MCConstantExpr::create(0, C));
1021 return;
1022 }
1023
1025 MCSFrameEmitter::encodeFuncOffset(Context, Value, Data, F.getSFrameFDE());
1026 F.setVarContents(Data);
1027 F.clearVarFixups();
1028}
1029
1030void MCAssembler::relaxFragment(MCFragment &F) {
1031 switch (F.getKind()) {
1032 default:
1033 return;
1035 relaxAlign(F);
1036 break;
1038 assert(!getRelaxAll() && "Did not expect a FT_Relaxable in RelaxAll mode");
1039 relaxInstruction(F);
1040 break;
1041 case MCFragment::FT_LEB:
1042 relaxLEB(F);
1043 break;
1045 relaxDwarfLineAddr(F);
1046 break;
1048 relaxDwarfCallFrameFragment(F);
1049 break;
1051 relaxSFrameFragment(F);
1052 break;
1054 relaxBoundaryAlign(static_cast<MCBoundaryAlignFragment &>(F));
1055 break;
1057 relaxPrefAlign(F);
1058 break;
1061 *this, static_cast<MCCVInlineLineTableFragment &>(F));
1062 break;
1065 *this, static_cast<MCCVDefRangeFragment &>(F));
1066 break;
1067 }
1068}
1069
1070void MCAssembler::layoutSection(MCSection &Sec) {
1071 uint64_t Offset = 0;
1072 for (MCFragment &F : Sec) {
1073 F.Offset = Offset;
1074 if (F.getKind() == MCFragment::FT_Align)
1075 relaxAlign(F);
1077 }
1078}
1079
1080// Fused relaxation and layout: a single forward pass that updates each
1081// fragment's offset before processing it, so upstream size changes are
1082// immediately visible.
1083unsigned MCAssembler::relaxOnce(unsigned FirstStable) {
1084 uint64_t MaxIterations = 0;
1085 PendingErrors.clear();
1086 unsigned Res = 0;
1087 for (unsigned I = 0; I != FirstStable; ++I) {
1088 auto &Sec = *Sections[I];
1089 uint64_t Iters = 0;
1090 for (;;) {
1091 bool Changed = false;
1092 uint64_t Offset = 0;
1093 for (MCFragment &F : Sec) {
1094 if (F.Offset != Offset)
1095 Changed = true;
1096 Stretch = Offset - F.Offset;
1097 F.Offset = Offset;
1098 if (F.getKind() != MCFragment::FT_Data)
1099 relaxFragment(F);
1101 }
1102 ++Iters;
1103
1104 if (!Changed)
1105 break;
1106 // If any fragment changed size, it might impact the layout of subsequent
1107 // sections. Therefore, we must re-evaluate all sections.
1108 FirstStable = Sections.size();
1109 Res = I;
1110 // Assume each iteration finalizes at least one extra fragment. If the
1111 // layout does not converge after N+1 iterations, bail out.
1112 if (Iters > Sec.curFragList()->Tail->getLayoutOrder())
1113 break;
1114 }
1115 MaxIterations = std::max(MaxIterations, Iters);
1116 }
1117 stats::RelaxationSteps += MaxIterations;
1118 Stretch = 0;
1119 // The subsequent relaxOnce call only needs to visit Sections [0,Res) if no
1120 // change occurred.
1121 return Res;
1122}
1123
1124void MCAssembler::reportError(SMLoc L, const Twine &Msg) const {
1125 getContext().reportError(L, Msg);
1126}
1127
1128void MCAssembler::recordError(SMLoc Loc, const Twine &Msg) const {
1129 PendingErrors.emplace_back(Loc, Msg.str());
1130}
1131
1133 for (auto &Err : PendingErrors)
1134 reportError(Err.first, Err.second);
1135 PendingErrors.clear();
1136}
1137
1138#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1140 raw_ostream &OS = errs();
1142 // Scan symbols and build a map of fragments to their corresponding symbols.
1143 // For variable symbols, we don't want to call their getFragment, which might
1144 // modify `Fragment`.
1145 for (const MCSymbol &Sym : symbols())
1146 if (!Sym.isVariable())
1147 if (auto *F = Sym.getFragment())
1148 FragToSyms.try_emplace(F).first->second.push_back(&Sym);
1149
1150 OS << "Sections:[";
1151 for (const MCSection &Sec : *this) {
1152 OS << '\n';
1153 Sec.dump(&FragToSyms);
1154 }
1155 OS << "\n]\n";
1156}
1157#endif
1158
1160 if (auto *E = getValue())
1161 return E->getLoc();
1162 return {};
1163}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
#define _
static bool getSymbolOffsetImpl(const MCAssembler &Asm, const MCSymbol &S, bool ReportError, uint64_t &Val)
static bool needPadding(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch needs padding.
static void writeFragment(raw_ostream &OS, const MCAssembler &Asm, const MCFragment &F)
Write the fragment F to the output file.
static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch crosses the boundary.
static bool isAgainstBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch is against the boundary.
static bool getLabelOffset(const MCAssembler &Asm, const MCSymbol &S, bool ReportError, uint64_t &Val)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
PowerPC TLS Dynamic Call Fixup
if(PassOpts->AAPipeline)
This file defines the SmallVector class.
static Split data
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition Debug.h:72
void encodeInlineLineTable(const MCAssembler &Asm, MCCVInlineLineTableFragment &F)
Encodes the binary annotations once we have a layout.
void encodeDefRange(const MCAssembler &Asm, MCCVDefRangeFragment &F)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition DenseMap.h:256
virtual void relaxInstruction(MCInst &Inst, const MCSubtargetInfo &STI) const
Relax the instruction in the given fragment to the next wider instruction.
virtual bool relaxAlign(MCFragment &F, unsigned &Size)
virtual std::pair< bool, bool > relaxLEB128(MCFragment &, int64_t &Value) const
virtual bool fixupNeedsRelaxationAdvanced(const MCFragment &, const MCFixup &, const MCValue &, uint64_t, bool Resolved) const
Target specific predicate for whether a given fixup requires the associated instruction to be relaxed...
virtual void reset()
lifetime management
virtual void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target, uint8_t *Data, uint64_t Value, bool IsResolved)=0
MCContext & getContext() const
LLVM_ABI bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
LLVM_ABI uint64_t getSectionAddressSize(const MCSection &Sec) const
LLVM_ABI void Finish()
Finish - Do final processing and write the object to the output stream.
LLVM_ABI void reportError(SMLoc L, const Twine &Msg) const
LLVM_ABI void writeSectionData(raw_ostream &OS, const MCSection *Section) const
Emit the section contents to OS.
iterator_range< pointee_iterator< SmallVector< const MCSymbol *, 0 >::const_iterator > > symbols() const
LLVM_ABI void dump() const
LLVM_ABI void layout()
MCObjectWriter & getWriter() const
MCCodeEmitter * getEmitterPtr() const
LLVM_ABI void addRelocDirective(RelocDirective RD)
bool getRelaxAll() const
MCCodeEmitter & getEmitter() const
LLVM_ABI void recordError(SMLoc L, const Twine &Msg) const
LLVM_ABI MCAssembler(MCContext &Context, std::unique_ptr< MCAsmBackend > Backend, std::unique_ptr< MCCodeEmitter > Emitter, std::unique_ptr< MCObjectWriter > Writer)
Construct a new assembler instance.
LLVM_ABI bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
MCAsmBackend & getBackend() const
LLVM_ABI bool registerSection(MCSection &Section)
LLVM_ABI void flushPendingErrors() const
LLVM_ABI uint64_t computeFragmentSize(const MCFragment &F) const
Compute the effective fragment size.
LLVM_ABI const MCSymbol * getBaseSymbol(const MCSymbol &Symbol) const
MCAsmBackend * getBackendPtr() const
LLVM_ABI uint64_t getSectionFileSize(const MCSection &Sec) const
LLVM_ABI void reset()
Reuse an assembler instance.
LLVM_ABI bool registerSymbol(const MCSymbol &Symbol)
uint64_t getFragmentOffset(const MCFragment &F) const
MCDwarfLineTableParams getDWARFLinetableParams() const
Represents required padding such that a particular other set of fragments does not cross a particular...
Definition MCSection.h:535
void setSize(uint64_t Value)
Definition MCSection.h:551
const MCFragment * getLastFragment() const
Definition MCSection.h:556
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
Encode the given Inst to bytes and append to CB.
virtual void reset()
Lifetime management.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:83
LLVM_ABI CodeViewContext & getCVContext()
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
static LLVM_ABI void encodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Definition MCDwarf.cpp:1991
static LLVM_ABI void encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Definition MCDwarf.cpp:745
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
LLVM_ABI bool evaluateAsValue(MCValue &Res, const MCAssembler &Asm) const
Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables.
Definition MCExpr.cpp:453
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
Definition MCExpr.cpp:450
SMLoc getLoc() const
Definition MCExpr.h:86
uint8_t getValueSize() const
Definition MCSection.h:401
uint64_t getValue() const
Definition MCSection.h:400
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition MCFixup.h:61
const MCExpr * getValue() const
Definition MCFixup.h:101
LLVM_ABI SMLoc getLoc() const
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
Definition MCFixup.h:86
unsigned getLayoutOrder() const
Definition MCSection.h:186
MCSection * getParent() const
Definition MCSection.h:181
MCFragment * getNext() const
Definition MCSection.h:177
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
Definition MCSection.h:197
int64_t getControlledNopLength() const
Definition MCSection.h:429
int64_t getNumBytes() const
Definition MCSection.h:428
SMLoc getLoc() const
Definition MCSection.h:431
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const
bool getSubsectionsViaSymbols() const
virtual void executePostLayoutBinding()
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
virtual uint64_t writeObject()=0
Write the object file and returns the number of bytes written.
static void encodeFuncOffset(MCContext &C, uint64_t Offset, SmallVectorImpl< char > &Out, MCFragment *FDEFrag)
Definition MCSFrame.cpp:617
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:569
bool isBssSection() const
Check whether this section is "virtual", that is has no actual object file contents.
Definition MCSection.h:686
void dump(DenseMap< const MCFragment *, SmallVector< const MCSymbol *, 0 > > *FragToSyms=nullptr) const
Definition MCSection.cpp:36
void setOrdinal(unsigned Value)
Definition MCSection.h:663
FragList * curFragList() const
Definition MCSection.h:677
Generic base class for all target subtargets.
Represents a symbol table index fragment.
Definition MCSection.h:463
const MCSymbol * getSymbol() const
Definition MCSection.h:469
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
bool isCommon() const
Is this a 'common' symbol.
Definition MCSymbol.h:343
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition MCSymbol.h:267
uint32_t getIndex() const
Get the (implementation defined) index.
Definition MCSymbol.h:280
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
Definition MCSymbol.h:270
MCFragment * getFragment() const
Definition MCSymbol.h:345
uint64_t getOffset() const
Definition MCSymbol.h:289
const MCSymbol * getAddSym() const
Definition MCValue.h:49
int64_t getConstant() const
Definition MCValue.h:44
const MCSymbol * getSubSym() const
Definition MCValue.h:51
Represents a location in source code.
Definition SMLoc.h:22
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Definition Twine.cpp:17
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
uint64_t tell() const
tell - Return the current offset with the file.
raw_ostream & write(unsigned char C)
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition CallingConv.h:76
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
bool isRelocRelocation(MCFixupKind FixupKind)
Definition MCFixup.h:135
@ Resolved
Queried, materialization begun.
Definition Core.h:793
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition Endian.h:96
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
Definition bit.h:360
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
Definition Error.cpp:173
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1746
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
Definition Alignment.h:186
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
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:1917
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition LEB128.h:24
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition LEB128.h:79
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:197
endianness
Definition bit.h:71
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77