LLVM 22.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/MCSection.h"
26#include "llvm/MC/MCSymbol.h"
27#include "llvm/MC/MCValue.h"
30#include "llvm/Support/Debug.h"
33#include "llvm/Support/LEB128.h"
35#include <cassert>
36#include <cstdint>
37#include <tuple>
38#include <utility>
39
40using namespace llvm;
41
42namespace llvm {
43class MCSubtargetInfo;
44}
45
46#define DEBUG_TYPE "assembler"
47
48namespace {
49namespace stats {
50
51STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total");
52STATISTIC(EmittedRelaxableFragments,
53 "Number of emitted assembler fragments - relaxable");
54STATISTIC(EmittedDataFragments,
55 "Number of emitted assembler fragments - data");
56STATISTIC(EmittedAlignFragments,
57 "Number of emitted assembler fragments - align");
58STATISTIC(EmittedFillFragments,
59 "Number of emitted assembler fragments - fill");
60STATISTIC(EmittedNopsFragments, "Number of emitted assembler fragments - nops");
61STATISTIC(EmittedOrgFragments, "Number of emitted assembler fragments - org");
62STATISTIC(Fixups, "Number of fixups");
63STATISTIC(FixupEvalForRelax, "Number of fixup evaluations for relaxation");
64STATISTIC(ObjectBytes, "Number of emitted object file bytes");
65STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
66STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
67
68} // end namespace stats
69} // end anonymous namespace
70
71// FIXME FIXME FIXME: There are number of places in this file where we convert
72// what is a 64-bit assembler value used for computation into a value in the
73// object file, which may truncate it. We should detect that truncation where
74// invalid and report errors back.
75
76/* *** */
77
79 std::unique_ptr<MCAsmBackend> Backend,
80 std::unique_ptr<MCCodeEmitter> Emitter,
81 std::unique_ptr<MCObjectWriter> Writer)
82 : Context(Context), Backend(std::move(Backend)),
83 Emitter(std::move(Emitter)), Writer(std::move(Writer)) {
84 if (this->Backend)
85 this->Backend->setAssembler(this);
86 if (this->Writer)
87 this->Writer->setAssembler(this);
88}
89
91 HasLayout = false;
92 HasFinalLayout = false;
93 RelaxAll = false;
94 Sections.clear();
95 Symbols.clear();
96 ThumbFuncs.clear();
97
98 // reset objects owned by us
99 if (getBackendPtr())
100 getBackendPtr()->reset();
101 if (getEmitterPtr())
102 getEmitterPtr()->reset();
103 if (Writer)
104 Writer->reset();
105}
106
108 if (Section.isRegistered())
109 return false;
110 Sections.push_back(&Section);
111 Section.setIsRegistered(true);
112 return true;
113}
114
115bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
116 if (ThumbFuncs.count(Symbol))
117 return true;
118
119 if (!Symbol->isVariable())
120 return false;
121
122 const MCExpr *Expr = Symbol->getVariableValue();
123
124 MCValue V;
125 if (!Expr->evaluateAsRelocatable(V, nullptr))
126 return false;
127
128 if (V.getSubSym() || V.getSpecifier())
129 return false;
130
131 auto *Sym = V.getAddSym();
132 if (!Sym || V.getSpecifier())
133 return false;
134
135 if (!isThumbFunc(Sym))
136 return false;
137
138 ThumbFuncs.insert(Symbol); // Cache it.
139 return true;
140}
141
142bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
144 bool RecordReloc, uint8_t *Data) const {
145 if (RecordReloc)
146 ++stats::Fixups;
147
148 // FIXME: This code has some duplication with recordRelocation. We should
149 // probably merge the two into a single callback that tries to evaluate a
150 // fixup and records a relocation if one is needed.
151
152 // On error claim to have completely evaluated the fixup, to prevent any
153 // further processing from being done.
154 const MCExpr *Expr = Fixup.getValue();
155 Value = 0;
156 if (!Expr->evaluateAsRelocatable(Target, this)) {
157 reportError(Fixup.getLoc(), "expected relocatable expression");
158 return true;
159 }
160
161 bool IsResolved = false;
162 if (auto State = getBackend().evaluateFixup(F, Fixup, Target, Value)) {
163 IsResolved = *State;
164 } else {
165 const MCSymbol *Add = Target.getAddSym();
166 const MCSymbol *Sub = Target.getSubSym();
167 Value += Target.getConstant();
168 if (Add && Add->isDefined())
170 if (Sub && Sub->isDefined())
172
173 if (Fixup.isPCRel()) {
174 Value -= getFragmentOffset(F) + Fixup.getOffset();
175 if (Add && !Sub && !Add->isUndefined() && !Add->isAbsolute()) {
177 *Add, F, false, true);
178 }
179 } else {
180 IsResolved = Target.isAbsolute();
181 }
182 }
183
184 if (!RecordReloc)
185 return IsResolved;
186
187 if (IsResolved && mc::isRelocRelocation(Fixup.getKind()))
188 IsResolved = false;
189 getBackend().applyFixup(F, Fixup, Target, Data, Value, IsResolved);
190 return true;
191}
192
194 assert(getBackendPtr() && "Requires assembler backend");
195 switch (F.getKind()) {
204 return F.getSize();
205 case MCFragment::FT_Fill: {
206 auto &FF = static_cast<const MCFillFragment &>(F);
207 int64_t NumValues = 0;
208 if (!FF.getNumValues().evaluateKnownAbsolute(NumValues, *this)) {
209 recordError(FF.getLoc(), "expected assembly-time absolute expression");
210 return 0;
211 }
212 int64_t Size = NumValues * FF.getValueSize();
213 if (Size < 0) {
214 recordError(FF.getLoc(), "invalid number of bytes");
215 return 0;
216 }
217 return Size;
218 }
219
221 return cast<MCNopsFragment>(F).getNumBytes();
222
224 return cast<MCBoundaryAlignFragment>(F).getSize();
225
227 return 4;
228
229 case MCFragment::FT_Org: {
230 const MCOrgFragment &OF = cast<MCOrgFragment>(F);
232 if (!OF.getOffset().evaluateAsValue(Value, *this)) {
233 recordError(OF.getLoc(), "expected assembly-time absolute expression");
234 return 0;
235 }
236
237 uint64_t FragmentOffset = getFragmentOffset(OF);
238 int64_t TargetLocation = Value.getConstant();
239 if (const auto *SA = Value.getAddSym()) {
240 uint64_t Val;
241 if (!getSymbolOffset(*SA, Val)) {
242 recordError(OF.getLoc(), "expected absolute expression");
243 return 0;
244 }
245 TargetLocation += Val;
246 }
247 int64_t Size = TargetLocation - FragmentOffset;
248 if (Size < 0 || Size >= 0x40000000) {
249 recordError(OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
250 "' (at offset '" + Twine(FragmentOffset) +
251 "')");
252 return 0;
253 }
254 return Size;
255 }
256 }
257
258 llvm_unreachable("invalid fragment kind");
259}
260
261// Simple getSymbolOffset helper for the non-variable case.
262static bool getLabelOffset(const MCAssembler &Asm, const MCSymbol &S,
263 bool ReportError, uint64_t &Val) {
264 if (!S.getFragment()) {
265 if (ReportError)
266 reportFatalUsageError("cannot evaluate undefined symbol '" + S.getName() +
267 "'");
268 return false;
269 }
270 Val = Asm.getFragmentOffset(*S.getFragment()) + S.getOffset();
271 return true;
272}
273
274static bool getSymbolOffsetImpl(const MCAssembler &Asm, const MCSymbol &S,
275 bool ReportError, uint64_t &Val) {
276 if (!S.isVariable())
277 return getLabelOffset(Asm, S, ReportError, Val);
278
279 // If SD is a variable, evaluate it.
282 reportFatalUsageError("cannot evaluate equated symbol '" + S.getName() +
283 "'");
284
285 uint64_t Offset = Target.getConstant();
286
287 const MCSymbol *A = Target.getAddSym();
288 if (A) {
289 uint64_t ValA;
290 // FIXME: On most platforms, `Target`'s component symbols are labels from
291 // having been simplified during evaluation, but on Mach-O they can be
292 // variables due to PR19203. This, and the line below for `B` can be
293 // restored to call `getLabelOffset` when PR19203 is fixed.
294 if (!getSymbolOffsetImpl(Asm, *A, ReportError, ValA))
295 return false;
296 Offset += ValA;
297 }
298
299 const MCSymbol *B = Target.getSubSym();
300 if (B) {
301 uint64_t ValB;
302 if (!getSymbolOffsetImpl(Asm, *B, ReportError, ValB))
303 return false;
304 Offset -= ValB;
305 }
306
307 Val = Offset;
308 return true;
309}
310
312 return getSymbolOffsetImpl(*this, S, false, Val);
313}
314
316 uint64_t Val;
317 getSymbolOffsetImpl(*this, S, true, Val);
318 return Val;
319}
320
321const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
322 assert(HasLayout);
323 if (!Symbol.isVariable())
324 return &Symbol;
325
326 const MCExpr *Expr = Symbol.getVariableValue();
328 if (!Expr->evaluateAsValue(Value, *this)) {
329 reportError(Expr->getLoc(), "expression could not be evaluated");
330 return nullptr;
331 }
332
333 const MCSymbol *SymB = Value.getSubSym();
334 if (SymB) {
335 reportError(Expr->getLoc(),
336 Twine("symbol '") + SymB->getName() +
337 "' could not be evaluated in a subtraction expression");
338 return nullptr;
339 }
340
341 const MCSymbol *A = Value.getAddSym();
342 if (!A)
343 return nullptr;
344
345 const MCSymbol &ASym = *A;
346 if (ASym.isCommon()) {
347 reportError(Expr->getLoc(), "Common symbol '" + ASym.getName() +
348 "' cannot be used in assignment expr");
349 return nullptr;
350 }
351
352 return &ASym;
353}
354
356 const MCFragment &F = *Sec.curFragList()->Tail;
357 assert(HasLayout && F.getKind() == MCFragment::FT_Data);
358 return getFragmentOffset(F) + F.getSize();
359}
360
362 // Virtual sections have no file size.
363 if (Sec.isBssSection())
364 return 0;
365 return getSectionAddressSize(Sec);
366}
367
369 bool Changed = !Symbol.isRegistered();
370 if (Changed) {
371 Symbol.setIsRegistered(true);
372 Symbols.push_back(&Symbol);
373 }
374 return Changed;
375}
376
377void MCAssembler::addRelocDirective(RelocDirective RD) {
378 relocDirectives.push_back(RD);
379}
380
381/// Write the fragment \p F to the output file.
382static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
383 const MCFragment &F) {
384 // FIXME: Embed in fragments instead?
385 uint64_t FragmentSize = Asm.computeFragmentSize(F);
386
387 llvm::endianness Endian = Asm.getBackend().Endian;
388
389 // This variable (and its dummy usage) is to participate in the assert at
390 // the end of the function.
391 uint64_t Start = OS.tell();
392 (void) Start;
393
394 ++stats::EmittedFragments;
395
396 switch (F.getKind()) {
404 if (F.getKind() == MCFragment::FT_Data)
405 ++stats::EmittedDataFragments;
406 else if (F.getKind() == MCFragment::FT_Relaxable)
407 ++stats::EmittedRelaxableFragments;
408 const auto &EF = cast<MCFragment>(F);
409 OS << StringRef(EF.getContents().data(), EF.getContents().size());
410 OS << StringRef(EF.getVarContents().data(), EF.getVarContents().size());
411 } break;
412
414 ++stats::EmittedAlignFragments;
415 OS << StringRef(F.getContents().data(), F.getContents().size());
416 assert(F.getAlignFillLen() &&
417 "Invalid virtual align in concrete fragment!");
418
419 uint64_t Count = (FragmentSize - F.getFixedSize()) / F.getAlignFillLen();
420 assert((FragmentSize - F.getFixedSize()) % F.getAlignFillLen() == 0 &&
421 "computeFragmentSize computed size is incorrect");
422
423 // In the nops mode, call the backend hook to write `Count` nops.
424 if (F.hasAlignEmitNops()) {
425 if (!Asm.getBackend().writeNopData(OS, Count, F.getSubtargetInfo()))
426 reportFatalInternalError("unable to write nop sequence of " +
427 Twine(Count) + " bytes");
428 } else {
429 // Otherwise, write out in multiples of the value size.
430 for (uint64_t i = 0; i != Count; ++i) {
431 switch (F.getAlignFillLen()) {
432 default:
433 llvm_unreachable("Invalid size!");
434 case 1:
435 OS << char(F.getAlignFill());
436 break;
437 case 2:
438 support::endian::write<uint16_t>(OS, F.getAlignFill(), Endian);
439 break;
440 case 4:
441 support::endian::write<uint32_t>(OS, F.getAlignFill(), Endian);
442 break;
443 case 8:
444 support::endian::write<uint64_t>(OS, F.getAlignFill(), Endian);
445 break;
446 }
447 }
448 }
449 } break;
450
451 case MCFragment::FT_Fill: {
452 ++stats::EmittedFillFragments;
453 const MCFillFragment &FF = cast<MCFillFragment>(F);
454 uint64_t V = FF.getValue();
455 unsigned VSize = FF.getValueSize();
456 const unsigned MaxChunkSize = 16;
457 char Data[MaxChunkSize];
458 assert(0 < VSize && VSize <= MaxChunkSize && "Illegal fragment fill size");
459 // Duplicate V into Data as byte vector to reduce number of
460 // writes done. As such, do endian conversion here.
461 for (unsigned I = 0; I != VSize; ++I) {
462 unsigned index = Endian == llvm::endianness::little ? I : (VSize - I - 1);
463 Data[I] = uint8_t(V >> (index * 8));
464 }
465 for (unsigned I = VSize; I < MaxChunkSize; ++I)
466 Data[I] = Data[I - VSize];
467
468 // Set to largest multiple of VSize in Data.
469 const unsigned NumPerChunk = MaxChunkSize / VSize;
470 // Set ChunkSize to largest multiple of VSize in Data
471 const unsigned ChunkSize = VSize * NumPerChunk;
472
473 // Do copies by chunk.
474 StringRef Ref(Data, ChunkSize);
475 for (uint64_t I = 0, E = FragmentSize / ChunkSize; I != E; ++I)
476 OS << Ref;
477
478 // do remainder if needed.
479 unsigned TrailingCount = FragmentSize % ChunkSize;
480 if (TrailingCount)
481 OS.write(Data, TrailingCount);
482 break;
483 }
484
485 case MCFragment::FT_Nops: {
486 ++stats::EmittedNopsFragments;
487 const MCNopsFragment &NF = cast<MCNopsFragment>(F);
488
489 int64_t NumBytes = NF.getNumBytes();
490 int64_t ControlledNopLength = NF.getControlledNopLength();
491 int64_t MaximumNopLength =
492 Asm.getBackend().getMaximumNopSize(*NF.getSubtargetInfo());
493
494 assert(NumBytes > 0 && "Expected positive NOPs fragment size");
495 assert(ControlledNopLength >= 0 && "Expected non-negative NOP size");
496
497 if (ControlledNopLength > MaximumNopLength) {
498 Asm.reportError(NF.getLoc(), "illegal NOP size " +
499 std::to_string(ControlledNopLength) +
500 ". (expected within [0, " +
501 std::to_string(MaximumNopLength) + "])");
502 // Clamp the NOP length as reportError does not stop the execution
503 // immediately.
504 ControlledNopLength = MaximumNopLength;
505 }
506
507 // Use maximum value if the size of each NOP is not specified
508 if (!ControlledNopLength)
509 ControlledNopLength = MaximumNopLength;
510
511 while (NumBytes) {
512 uint64_t NumBytesToEmit =
513 (uint64_t)std::min(NumBytes, ControlledNopLength);
514 assert(NumBytesToEmit && "try to emit empty NOP instruction");
515 if (!Asm.getBackend().writeNopData(OS, NumBytesToEmit,
516 NF.getSubtargetInfo())) {
517 report_fatal_error("unable to write nop sequence of the remaining " +
518 Twine(NumBytesToEmit) + " bytes");
519 break;
520 }
521 NumBytes -= NumBytesToEmit;
522 }
523 break;
524 }
525
527 const MCBoundaryAlignFragment &BF = cast<MCBoundaryAlignFragment>(F);
528 if (!Asm.getBackend().writeNopData(OS, FragmentSize, BF.getSubtargetInfo()))
529 report_fatal_error("unable to write nop sequence of " +
530 Twine(FragmentSize) + " bytes");
531 break;
532 }
533
535 const MCSymbolIdFragment &SF = cast<MCSymbolIdFragment>(F);
536 support::endian::write<uint32_t>(OS, SF.getSymbol()->getIndex(), Endian);
537 break;
538 }
539
540 case MCFragment::FT_Org: {
541 ++stats::EmittedOrgFragments;
542 const MCOrgFragment &OF = cast<MCOrgFragment>(F);
543
544 for (uint64_t i = 0, e = FragmentSize; i != e; ++i)
545 OS << char(OF.getValue());
546
547 break;
548 }
549
550 }
551
552 assert(OS.tell() - Start == FragmentSize &&
553 "The stream should advance by fragment size");
554}
555
557 const MCSection *Sec) const {
558 assert(getBackendPtr() && "Expected assembler backend");
559
560 if (Sec->isBssSection()) {
561 assert(getSectionFileSize(*Sec) == 0 && "Invalid size for section!");
562
563 // Ensure no fixups or non-zero bytes are written to BSS sections, catching
564 // errors in both input assembly code and MCStreamer API usage. Location is
565 // not tracked for efficiency.
566 auto Fn = [](char c) { return c != 0; };
567 for (const MCFragment &F : *Sec) {
568 bool HasNonZero = false;
569 switch (F.getKind()) {
570 default:
571 reportFatalInternalError("BSS section '" + Sec->getName() +
572 "' contains invalid fragment");
573 break;
576 HasNonZero =
577 any_of(F.getContents(), Fn) || any_of(F.getVarContents(), Fn);
578 break;
580 // Disallowed for API usage. AsmParser changes non-zero fill values to
581 // 0.
582 assert(F.getAlignFill() == 0 && "Invalid align in virtual section!");
583 break;
585 HasNonZero = cast<MCFillFragment>(F).getValue() != 0;
586 break;
588 HasNonZero = cast<MCOrgFragment>(F).getValue() != 0;
589 break;
590 }
591 if (HasNonZero) {
592 reportError(SMLoc(), "BSS section '" + Sec->getName() +
593 "' cannot have non-zero bytes");
594 break;
595 }
596 if (F.getFixups().size() || F.getVarFixups().size()) {
598 "BSS section '" + Sec->getName() + "' cannot have fixups");
599 break;
600 }
601 }
602
603 return;
604 }
605
606 uint64_t Start = OS.tell();
607 (void)Start;
608
609 for (const MCFragment &F : *Sec)
610 writeFragment(OS, *this, F);
611
613 assert(getContext().hadError() ||
614 OS.tell() - Start == getSectionAddressSize(*Sec));
615}
616
618 assert(getBackendPtr() && "Expected assembler backend");
619 DEBUG_WITH_TYPE("mc-dump-pre", {
620 errs() << "assembler backend - pre-layout\n--\n";
621 dump();
622 });
623
624 // Assign section ordinals.
625 unsigned SectionIndex = 0;
626 for (MCSection &Sec : *this) {
627 Sec.setOrdinal(SectionIndex++);
628
629 // Chain together fragments from all subsections.
630 if (Sec.Subsections.size() > 1) {
631 MCFragment Dummy;
632 MCFragment *Tail = &Dummy;
633 for (auto &[_, List] : Sec.Subsections) {
634 assert(List.Head);
635 Tail->Next = List.Head;
636 Tail = List.Tail;
637 }
638 Sec.Subsections.clear();
639 Sec.Subsections.push_back({0u, {Dummy.getNext(), Tail}});
640 Sec.CurFragList = &Sec.Subsections[0].second;
641
642 unsigned FragmentIndex = 0;
643 for (MCFragment &Frag : Sec)
644 Frag.setLayoutOrder(FragmentIndex++);
645 }
646 }
647
648 // Layout until everything fits.
649 this->HasLayout = true;
650 for (MCSection &Sec : *this)
651 layoutSection(Sec);
652 unsigned FirstStable = Sections.size();
653 while ((FirstStable = relaxOnce(FirstStable)) > 0)
654 if (getContext().hadError())
655 return;
656
657 // Some targets might want to adjust fragment offsets. If so, perform another
658 // layout iteration.
659 if (getBackend().finishLayout(*this))
660 for (MCSection &Sec : *this)
661 layoutSection(Sec);
662
664
665 DEBUG_WITH_TYPE("mc-dump", {
666 errs() << "assembler backend - final-layout\n--\n";
667 dump(); });
668
669 // Allow the object writer a chance to perform post-layout binding (for
670 // example, to set the index fields in the symbol data).
672
673 // Fragment sizes are finalized. For RISC-V linker relaxation, this flag
674 // helps check whether a PC-relative fixup is fully resolved.
675 this->HasFinalLayout = true;
676
677 // Resolve .reloc offsets and add fixups.
678 for (auto &PF : relocDirectives) {
679 MCValue Res;
680 auto &O = PF.Offset;
681 if (!O.evaluateAsValue(Res, *this)) {
682 getContext().reportError(O.getLoc(), ".reloc offset is not relocatable");
683 continue;
684 }
685 auto *Sym = Res.getAddSym();
686 auto *F = Sym ? Sym->getFragment() : nullptr;
687 auto *Sec = F ? F->getParent() : nullptr;
688 if (Res.getSubSym() || !Sec) {
689 getContext().reportError(O.getLoc(),
690 ".reloc offset is not relative to a section");
691 continue;
692 }
693
694 uint64_t Offset = Sym ? Sym->getOffset() + Res.getConstant() : 0;
695 F->addFixup(MCFixup::create(Offset, PF.Expr, PF.Kind));
696 }
697
698 // Evaluate and apply the fixups, generating relocation entries as necessary.
699 for (MCSection &Sec : *this) {
700 for (MCFragment &F : Sec) {
701 // Process fragments with fixups here.
702 auto Contents = F.getContents();
703 for (MCFixup &Fixup : F.getFixups()) {
704 uint64_t FixedValue;
707 Fixup.getOffset() <= F.getFixedSize());
708 auto *Data =
709 reinterpret_cast<uint8_t *>(Contents.data() + Fixup.getOffset());
710 evaluateFixup(F, Fixup, Target, FixedValue,
711 /*RecordReloc=*/true, Data);
712 }
713 // In the variable part, fixup offsets are relative to the fixed part's
714 // start.
715 for (MCFixup &Fixup : F.getVarFixups()) {
716 uint64_t FixedValue;
719 (Fixup.getOffset() >= F.getFixedSize() &&
720 Fixup.getOffset() <= F.getSize()));
721 auto *Data = reinterpret_cast<uint8_t *>(
722 F.getVarContents().data() + (Fixup.getOffset() - F.getFixedSize()));
723 evaluateFixup(F, Fixup, Target, FixedValue,
724 /*RecordReloc=*/true, Data);
725 }
726 }
727 }
728}
729
731 layout();
732
733 // Write the object file.
734 stats::ObjectBytes += getWriter().writeObject();
735
736 HasLayout = false;
737 assert(PendingErrors.empty());
738}
739
740bool MCAssembler::fixupNeedsRelaxation(const MCFragment &F,
741 const MCFixup &Fixup) const {
742 ++stats::FixupEvalForRelax;
745 bool Resolved = evaluateFixup(F, const_cast<MCFixup &>(Fixup), Target, Value,
746 /*RecordReloc=*/false, {});
748 Resolved);
749}
750
751void MCAssembler::relaxInstruction(MCFragment &F) {
753 "Expected CodeEmitter defined for relaxInstruction");
754 // If this inst doesn't ever need relaxation, ignore it. This occurs when we
755 // are intentionally pushing out inst fragments, or because we relaxed a
756 // previous instruction to one that doesn't need relaxation.
757 if (!getBackend().mayNeedRelaxation(F.getOpcode(), F.getOperands(),
758 *F.getSubtargetInfo()))
759 return;
760
761 bool DoRelax = false;
762 for (const MCFixup &Fixup : F.getVarFixups())
763 if ((DoRelax = fixupNeedsRelaxation(F, Fixup)))
764 break;
765 if (!DoRelax)
766 return;
767
768 ++stats::RelaxedInstructions;
769
770 // TODO Refactor relaxInstruction to accept MCFragment and remove
771 // `setInst`.
772 MCInst Relaxed = F.getInst();
773 getBackend().relaxInstruction(Relaxed, *F.getSubtargetInfo());
774
775 // Encode the new instruction.
776 F.setInst(Relaxed);
779 getEmitter().encodeInstruction(Relaxed, Data, Fixups, *F.getSubtargetInfo());
780 F.setVarContents(Data);
781 F.setVarFixups(Fixups);
782}
783
784void MCAssembler::relaxLEB(MCFragment &F) {
785 unsigned PadTo = F.getVarSize();
786 int64_t Value;
787 F.clearVarFixups();
788 // Use evaluateKnownAbsolute for Mach-O as a hack: .subsections_via_symbols
789 // requires that .uleb128 A-B is foldable where A and B reside in different
790 // fragments. This is used by __gcc_except_table.
792 ? F.getLEBValue().evaluateKnownAbsolute(Value, *this)
793 : F.getLEBValue().evaluateAsAbsolute(Value, *this);
794 if (!Abs) {
795 bool Relaxed, UseZeroPad;
796 std::tie(Relaxed, UseZeroPad) = getBackend().relaxLEB128(F, Value);
797 if (!Relaxed) {
798 reportError(F.getLEBValue().getLoc(),
799 Twine(F.isLEBSigned() ? ".s" : ".u") +
800 "leb128 expression is not absolute");
801 F.setLEBValue(MCConstantExpr::create(0, Context));
802 }
803 uint8_t Tmp[10]; // maximum size: ceil(64/7)
804 PadTo = std::max(PadTo, encodeULEB128(uint64_t(Value), Tmp));
805 if (UseZeroPad)
806 Value = 0;
807 }
808 uint8_t Data[16];
809 size_t Size = 0;
810 // The compiler can generate EH table assembly that is impossible to assemble
811 // without either adding padding to an LEB fragment or adding extra padding
812 // to a later alignment fragment. To accommodate such tables, relaxation can
813 // only increase an LEB fragment size here, not decrease it. See PR35809.
814 if (F.isLEBSigned())
815 Size = encodeSLEB128(Value, Data, PadTo);
816 else
817 Size = encodeULEB128(Value, Data, PadTo);
818 F.setVarContents({reinterpret_cast<char *>(Data), Size});
819}
820
821/// Check if the branch crosses the boundary.
822///
823/// \param StartAddr start address of the fused/unfused branch.
824/// \param Size size of the fused/unfused branch.
825/// \param BoundaryAlignment alignment requirement of the branch.
826/// \returns true if the branch cross the boundary.
827static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size,
828 Align BoundaryAlignment) {
829 uint64_t EndAddr = StartAddr + Size;
830 return (StartAddr >> Log2(BoundaryAlignment)) !=
831 ((EndAddr - 1) >> Log2(BoundaryAlignment));
832}
833
834/// Check if the branch is against the boundary.
835///
836/// \param StartAddr start address of the fused/unfused branch.
837/// \param Size size of the fused/unfused branch.
838/// \param BoundaryAlignment alignment requirement of the branch.
839/// \returns true if the branch is against the boundary.
841 Align BoundaryAlignment) {
842 uint64_t EndAddr = StartAddr + Size;
843 return (EndAddr & (BoundaryAlignment.value() - 1)) == 0;
844}
845
846/// Check if the branch needs padding.
847///
848/// \param StartAddr start address of the fused/unfused branch.
849/// \param Size size of the fused/unfused branch.
850/// \param BoundaryAlignment alignment requirement of the branch.
851/// \returns true if the branch needs padding.
852static bool needPadding(uint64_t StartAddr, uint64_t Size,
853 Align BoundaryAlignment) {
854 return mayCrossBoundary(StartAddr, Size, BoundaryAlignment) ||
855 isAgainstBoundary(StartAddr, Size, BoundaryAlignment);
856}
857
858void MCAssembler::relaxBoundaryAlign(MCBoundaryAlignFragment &BF) {
859 // BoundaryAlignFragment that doesn't need to align any fragment should not be
860 // relaxed.
861 if (!BF.getLastFragment())
862 return;
863
864 uint64_t AlignedOffset = getFragmentOffset(BF);
865 uint64_t AlignedSize = 0;
866 for (const MCFragment *F = BF.getNext();; F = F->getNext()) {
867 AlignedSize += computeFragmentSize(*F);
868 if (F == BF.getLastFragment())
869 break;
870 }
871
872 Align BoundaryAlignment = BF.getAlignment();
873 uint64_t NewSize = needPadding(AlignedOffset, AlignedSize, BoundaryAlignment)
874 ? offsetToAlignment(AlignedOffset, BoundaryAlignment)
875 : 0U;
876 if (NewSize == BF.getSize())
877 return;
878 BF.setSize(NewSize);
879}
880
881void MCAssembler::relaxDwarfLineAddr(MCFragment &F) {
882 if (getBackend().relaxDwarfLineAddr(F))
883 return;
884
885 MCContext &Context = getContext();
886 int64_t AddrDelta;
887 bool Abs = F.getDwarfAddrDelta().evaluateKnownAbsolute(AddrDelta, *this);
888 assert(Abs && "We created a line delta with an invalid expression");
889 (void)Abs;
892 F.getDwarfLineDelta(), AddrDelta, Data);
893 F.setVarContents(Data);
894 F.clearVarFixups();
895}
896
897void MCAssembler::relaxDwarfCallFrameFragment(MCFragment &F) {
898 if (getBackend().relaxDwarfCFA(F))
899 return;
900
902 int64_t Value;
903 bool Abs = F.getDwarfAddrDelta().evaluateAsAbsolute(Value, *this);
904 if (!Abs) {
905 reportError(F.getDwarfAddrDelta().getLoc(),
906 "invalid CFI advance_loc expression");
907 F.setDwarfAddrDelta(MCConstantExpr::create(0, Context));
908 return;
909 }
910
913 F.setVarContents(Data);
914 F.clearVarFixups();
915}
916
917bool MCAssembler::relaxFragment(MCFragment &F) {
918 auto Size = computeFragmentSize(F);
919 switch (F.getKind()) {
920 default:
921 return false;
923 assert(!getRelaxAll() && "Did not expect a FT_Relaxable in RelaxAll mode");
924 relaxInstruction(F);
925 break;
927 relaxLEB(F);
928 break;
930 relaxDwarfLineAddr(F);
931 break;
933 relaxDwarfCallFrameFragment(F);
934 break;
936 relaxBoundaryAlign(static_cast<MCBoundaryAlignFragment &>(F));
937 break;
940 *this, static_cast<MCCVInlineLineTableFragment &>(F));
941 break;
944 *this, static_cast<MCCVDefRangeFragment &>(F));
945 break;
948 return F.getNext()->Offset - F.Offset != Size;
949 }
950 return computeFragmentSize(F) != Size;
951}
952
953void MCAssembler::layoutSection(MCSection &Sec) {
954 uint64_t Offset = 0;
955 for (MCFragment &F : Sec) {
956 F.Offset = Offset;
957 if (F.getKind() == MCFragment::FT_Align) {
958 Offset += F.getFixedSize();
959 unsigned Size = offsetToAlignment(Offset, F.getAlignment());
960 // In the nops mode, RISC-V style linker relaxation might adjust the size
961 // and add a fixup, even if `Size` is originally 0.
962 bool AlignFixup = false;
963 if (F.hasAlignEmitNops()) {
964 AlignFixup = getBackend().relaxAlign(F, Size);
965 // If the backend does not handle the fragment specially, pad with nops,
966 // but ensure that the padding is larger than the minimum nop size.
967 if (!AlignFixup)
968 while (Size % getBackend().getMinimumNopSize())
969 Size += F.getAlignment().value();
970 }
971 if (!AlignFixup && Size > F.getAlignMaxBytesToEmit())
972 Size = 0;
973 // Update the variable tail size, offset by FixedSize to prevent ubsan
974 // pointer-overflow in evaluateFixup. The content is ignored.
975 F.VarContentStart = F.getFixedSize();
976 F.VarContentEnd = F.VarContentStart + Size;
977 if (F.VarContentEnd > F.getParent()->ContentStorage.size())
978 F.getParent()->ContentStorage.resize(F.VarContentEnd);
979 Offset += Size;
980 } else {
982 }
983 }
984}
985
986unsigned MCAssembler::relaxOnce(unsigned FirstStable) {
987 ++stats::RelaxationSteps;
988 PendingErrors.clear();
989
990 unsigned Res = 0;
991 for (unsigned I = 0; I != FirstStable; ++I) {
992 // Assume each iteration finalizes at least one extra fragment. If the
993 // layout does not converge after N+1 iterations, bail out.
994 auto &Sec = *Sections[I];
995 auto MaxIter = Sec.curFragList()->Tail->getLayoutOrder() + 1;
996 for (;;) {
997 bool Changed = false;
998 for (MCFragment &F : Sec)
999 if (F.getKind() != MCFragment::FT_Data && relaxFragment(F))
1000 Changed = true;
1001
1002 if (!Changed)
1003 break;
1004 // If any fragment changed size, it might impact the layout of subsequent
1005 // sections. Therefore, we must re-evaluate all sections.
1006 FirstStable = Sections.size();
1007 Res = I;
1008 if (--MaxIter == 0)
1009 break;
1010 layoutSection(Sec);
1011 }
1012 }
1013 // The subsequent relaxOnce call only needs to visit Sections [0,Res) if no
1014 // change occurred.
1015 return Res;
1016}
1017
1018void MCAssembler::reportError(SMLoc L, const Twine &Msg) const {
1019 getContext().reportError(L, Msg);
1020}
1021
1022void MCAssembler::recordError(SMLoc Loc, const Twine &Msg) const {
1023 PendingErrors.emplace_back(Loc, Msg.str());
1024}
1025
1027 for (auto &Err : PendingErrors)
1028 reportError(Err.first, Err.second);
1029 PendingErrors.clear();
1030}
1031
1032#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1034 raw_ostream &OS = errs();
1036 // Scan symbols and build a map of fragments to their corresponding symbols.
1037 // For variable symbols, we don't want to call their getFragment, which might
1038 // modify `Fragment`.
1039 for (const MCSymbol &Sym : symbols())
1040 if (!Sym.isVariable())
1041 if (auto *F = Sym.getFragment())
1042 FragToSyms.try_emplace(F).first->second.push_back(&Sym);
1043
1044 OS << "Sections:[";
1045 for (const MCSection &Sec : *this) {
1046 OS << '\n';
1047 Sec.dump(&FragToSyms);
1048 }
1049 OS << "\n]\n";
1050}
1051#endif
1052
1054 if (auto *E = getValue())
1055 return E->getLoc();
1056 return {};
1057}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:638
dxil DXContainer Global Emitter
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
#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:55
#define I(x, y, z)
Definition: MD5.cpp:58
PowerPC TLS Dynamic Call Fixup
endianness Endian
raw_pwrite_stream & OS
This file defines the SmallVector class.
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:167
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition: Debug.h:77
void encodeInlineLineTable(const MCAssembler &Asm, MCCVInlineLineTableFragment &F)
Encodes the binary annotations once we have a layout.
Definition: MCCodeView.cpp:472
void encodeDefRange(const MCAssembler &Asm, MCCVDefRangeFragment &F)
Definition: MCCodeView.cpp:609
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition: DenseMap.h:245
virtual void relaxInstruction(MCInst &Inst, const MCSubtargetInfo &STI) const
Relax the instruction in the given fragment to the next wider instruction.
Definition: MCAsmBackend.h:157
virtual bool relaxAlign(MCFragment &F, unsigned &Size)
Definition: MCAsmBackend.h:168
virtual std::pair< bool, bool > relaxLEB128(MCFragment &, int64_t &Value) const
Definition: MCAsmBackend.h:174
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
Definition: MCAsmBackend.h:84
virtual void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target, uint8_t *Data, uint64_t Value, bool IsResolved)=0
MCContext & getContext() const
Definition: MCAssembler.h:169
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.
LLVM_ABI void dump() const
LLVM_ABI void layout()
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:179
MCCodeEmitter * getEmitterPtr() const
Definition: MCAssembler.h:173
LLVM_ABI void addRelocDirective(RelocDirective RD)
bool getRelaxAll() const
Definition: MCAssembler.h:193
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:177
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.
Definition: MCAssembler.cpp:78
LLVM_ABI bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:175
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
Definition: MCAssembler.h:171
iterator_range< pointee_iterator< typename SmallVector< const MCSymbol *, 0 >::const_iterator > > symbols() const
Definition: MCAssembler.h:202
LLVM_ABI uint64_t getSectionFileSize(const MCSection &Sec) const
LLVM_ABI void reset()
Reuse an assembler instance.
Definition: MCAssembler.cpp:90
LLVM_ABI bool registerSymbol(const MCSymbol &Symbol)
uint64_t getFragmentOffset(const MCFragment &F) const
Definition: MCAssembler.h:139
MCDwarfLineTableParams getDWARFLinetableParams() const
Definition: MCAssembler.h:181
Represents required padding such that a particular other set of fragments does not cross a particular...
Definition: MCSection.h:459
uint64_t getSize() const
Definition: MCSection.h:475
void setSize(uint64_t Value)
Definition: MCSection.h:476
const MCFragment * getLastFragment() const
Definition: MCSection.h:481
const MCSubtargetInfo * getSubtargetInfo() const
Definition: MCSection.h:487
Fragment representing the .cv_def_range directive.
Definition: MCSection.h:430
Fragment representing the binary annotations produced by the .cv_inline_linetable directive.
Definition: MCSection.h:402
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.
Definition: MCCodeEmitter.h:33
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()
Definition: MCContext.cpp:1060
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1115
static LLVM_ABI void encodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Definition: MCDwarf.cpp:1972
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:735
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:321
uint64_t getValue() const
Definition: MCSection.h:320
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
MCFragment * getNext() const
Definition: MCSection.h:154
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:188
int64_t getControlledNopLength() const
Definition: MCSection.h:350
int64_t getNumBytes() const
Definition: MCSection.h:349
const MCSubtargetInfo * getSubtargetInfo() const
Definition: MCSection.h:354
SMLoc getLoc() const
Definition: MCSection.h:352
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.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
bool isBssSection() const
Check whether this section is "virtual", that is has no actual object file contents.
Definition: MCSection.h:612
void dump(DenseMap< const MCFragment *, SmallVector< const MCSymbol *, 0 > > *FragToSyms=nullptr) const
Definition: MCSection.cpp:36
void setOrdinal(unsigned Value)
Definition: MCSection.h:589
FragList * curFragList() const
Definition: MCSection.h:603
Generic base class for all target subtargets.
Represents a symbol table index fragment.
Definition: MCSection.h:386
const MCSymbol * getSymbol()
Definition: MCSection.h:392
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:344
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:346
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:23
size_t size() const
Definition: SmallVector.h:79
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
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
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:148
raw_ostream & write(unsigned char C)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition: CallingConv.h:76
@ Relaxed
Definition: NVPTX.h:158
bool isRelocRelocation(MCFixupKind FixupKind)
Definition: MCFixup.h:135
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
Definition: Error.cpp:177
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:1751
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
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:197
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.
@ 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:1886
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
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:81
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:208
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:180
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
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