1 //===- MCAssembler.h - Object File Generation -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCASSEMBLER_H
11 #define LLVM_MC_MCASSEMBLER_H
13 #include "llvm/ADT/SmallPtrSet.h"
14 #include "llvm/ADT/ilist.h"
15 #include "llvm/ADT/ilist_node.h"
16 #include "llvm/ADT/iterator.h"
17 #include "llvm/MC/MCDirectives.h"
18 #include "llvm/MC/MCDwarf.h"
19 #include "llvm/MC/MCFixup.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCLinkerOptimizationHint.h"
22 #include "llvm/MC/MCSubtargetInfo.h"
34 class MCSubtargetInfo;
38 class MCFragment : public ilist_node<MCFragment> {
39 friend class MCAsmLayout;
41 MCFragment(const MCFragment &) = delete;
42 void operator=(const MCFragment &) = delete;
45 enum FragmentType : uint8_t {
48 FT_CompactEncodedInst,
66 /// \brief Should this fragment be aligned to the end of a bundle?
67 bool AlignToBundleEnd;
69 uint8_t BundlePadding;
71 /// LayoutOrder - The layout order of this fragment.
74 /// The data for the section this fragment is in.
77 /// Atom - The atom this fragment is in, as represented by it's defining
81 /// \name Assembler Backend Data
84 // FIXME: This could all be kept private to the assembler implementation.
86 /// Offset - The offset of this fragment in its section. This is ~0 until
93 MCFragment(FragmentType Kind, bool HasInstructions,
94 uint8_t BundlePadding, MCSection *Parent = nullptr);
99 // This is a friend so that the sentinal can be created.
100 friend struct ilist_sentinel_traits<MCFragment>;
104 /// Destroys the current fragment.
106 /// This must be used instead of delete as MCFragment is non-virtual.
107 /// This method will dispatch to the appropriate subclass.
110 FragmentType getKind() const { return Kind; }
112 MCSection *getParent() const { return Parent; }
113 void setParent(MCSection *Value) { Parent = Value; }
115 const MCSymbol *getAtom() const { return Atom; }
116 void setAtom(const MCSymbol *Value) { Atom = Value; }
118 unsigned getLayoutOrder() const { return LayoutOrder; }
119 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
121 /// \brief Does this fragment have instructions emitted into it? By default
122 /// this is false, but specific fragment types may set it to true.
123 bool hasInstructions() const { return HasInstructions; }
125 /// \brief Should this fragment be placed at the end of an aligned bundle?
126 bool alignToBundleEnd() const { return AlignToBundleEnd; }
127 void setAlignToBundleEnd(bool V) { AlignToBundleEnd = V; }
129 /// \brief Get the padding size that must be inserted before this fragment.
130 /// Used for bundling. By default, no padding is inserted.
131 /// Note that padding size is restricted to 8 bits. This is an optimization
132 /// to reduce the amount of space used for each fragment. In practice, larger
133 /// padding should never be required.
134 uint8_t getBundlePadding() const { return BundlePadding; }
136 /// \brief Set the padding size for this fragment. By default it's a no-op,
137 /// and only some fragments have a meaningful implementation.
138 void setBundlePadding(uint8_t N) { BundlePadding = N; }
140 /// \brief Return true if given frgment has FT_Dummy type.
141 bool isDummy() const { return Kind == FT_Dummy; }
146 class MCDummyFragment : public MCFragment {
148 explicit MCDummyFragment(MCSection *Sec)
149 : MCFragment(FT_Dummy, false, 0, Sec){};
150 static bool classof(const MCFragment *F) { return F->getKind() == FT_Dummy; }
153 /// Interface implemented by fragments that contain encoded instructions and/or
156 class MCEncodedFragment : public MCFragment {
158 MCEncodedFragment(MCFragment::FragmentType FType, bool HasInstructions,
160 : MCFragment(FType, HasInstructions, 0, Sec) {}
163 static bool classof(const MCFragment *F) {
164 MCFragment::FragmentType Kind = F->getKind();
168 case MCFragment::FT_Relaxable:
169 case MCFragment::FT_CompactEncodedInst:
170 case MCFragment::FT_Data:
176 /// Interface implemented by fragments that contain encoded instructions and/or
179 template<unsigned ContentsSize>
180 class MCEncodedFragmentWithContents : public MCEncodedFragment {
181 SmallVector<char, ContentsSize> Contents;
184 MCEncodedFragmentWithContents(MCFragment::FragmentType FType,
185 bool HasInstructions,
187 : MCEncodedFragment(FType, HasInstructions, Sec) {}
190 SmallVectorImpl<char> &getContents() { return Contents; }
191 const SmallVectorImpl<char> &getContents() const { return Contents; }
194 /// Interface implemented by fragments that contain encoded instructions and/or
195 /// data and also have fixups registered.
197 template<unsigned ContentsSize, unsigned FixupsSize>
198 class MCEncodedFragmentWithFixups :
199 public MCEncodedFragmentWithContents<ContentsSize> {
201 /// Fixups - The list of fixups in this fragment.
202 SmallVector<MCFixup, FixupsSize> Fixups;
205 MCEncodedFragmentWithFixups(MCFragment::FragmentType FType,
206 bool HasInstructions,
208 : MCEncodedFragmentWithContents<ContentsSize>(FType, HasInstructions,
212 typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
213 typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
215 SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
216 const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
218 fixup_iterator fixup_begin() { return Fixups.begin(); }
219 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
221 fixup_iterator fixup_end() { return Fixups.end(); }
222 const_fixup_iterator fixup_end() const { return Fixups.end(); }
224 static bool classof(const MCFragment *F) {
225 MCFragment::FragmentType Kind = F->getKind();
226 return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data;
230 /// Fragment for data and encoded instructions.
232 class MCDataFragment : public MCEncodedFragmentWithFixups<32, 4> {
234 MCDataFragment(MCSection *Sec = nullptr)
235 : MCEncodedFragmentWithFixups<32, 4>(FT_Data, false, Sec) {}
237 void setHasInstructions(bool V) { HasInstructions = V; }
239 static bool classof(const MCFragment *F) {
240 return F->getKind() == MCFragment::FT_Data;
244 /// This is a compact (memory-size-wise) fragment for holding an encoded
245 /// instruction (non-relaxable) that has no fixups registered. When applicable,
246 /// it can be used instead of MCDataFragment and lead to lower memory
249 class MCCompactEncodedInstFragment : public MCEncodedFragmentWithContents<4> {
251 MCCompactEncodedInstFragment(MCSection *Sec = nullptr)
252 : MCEncodedFragmentWithContents(FT_CompactEncodedInst, true, Sec) {
255 static bool classof(const MCFragment *F) {
256 return F->getKind() == MCFragment::FT_CompactEncodedInst;
260 /// A relaxable fragment holds on to its MCInst, since it may need to be
261 /// relaxed during the assembler layout and relaxation stage.
263 class MCRelaxableFragment : public MCEncodedFragmentWithFixups<8, 1> {
265 /// Inst - The instruction this is a fragment for.
268 /// STI - The MCSubtargetInfo in effect when the instruction was encoded.
269 /// Keep a copy instead of a reference to make sure that updates to STI
270 /// in the assembler are not seen here.
271 const MCSubtargetInfo STI;
274 MCRelaxableFragment(const MCInst &Inst, const MCSubtargetInfo &STI,
275 MCSection *Sec = nullptr)
276 : MCEncodedFragmentWithFixups(FT_Relaxable, true, Sec),
277 Inst(Inst), STI(STI) {}
279 const MCInst &getInst() const { return Inst; }
280 void setInst(const MCInst &Value) { Inst = Value; }
282 const MCSubtargetInfo &getSubtargetInfo() { return STI; }
284 static bool classof(const MCFragment *F) {
285 return F->getKind() == MCFragment::FT_Relaxable;
289 class MCAlignFragment : public MCFragment {
291 /// Alignment - The alignment to ensure, in bytes.
294 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
295 /// of using the provided value. The exact interpretation of this flag is
296 /// target dependent.
299 /// Value - Value to use for filling padding bytes.
302 /// ValueSize - The size of the integer (in bytes) of \p Value.
305 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
306 /// cannot be satisfied in this width then this fragment is ignored.
307 unsigned MaxBytesToEmit;
310 MCAlignFragment(unsigned Alignment, int64_t Value, unsigned ValueSize,
311 unsigned MaxBytesToEmit, MCSection *Sec = nullptr)
312 : MCFragment(FT_Align, false, 0, Sec), Alignment(Alignment),
313 EmitNops(false), Value(Value),
314 ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit) {}
319 unsigned getAlignment() const { return Alignment; }
321 int64_t getValue() const { return Value; }
323 unsigned getValueSize() const { return ValueSize; }
325 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
327 bool hasEmitNops() const { return EmitNops; }
328 void setEmitNops(bool Value) { EmitNops = Value; }
332 static bool classof(const MCFragment *F) {
333 return F->getKind() == MCFragment::FT_Align;
337 class MCFillFragment : public MCFragment {
339 /// Value - Value to use for filling bytes.
342 /// ValueSize - The size (in bytes) of \p Value to use when filling, or 0 if
343 /// this is a virtual fill fragment.
346 /// Size - The number of bytes to insert.
350 MCFillFragment(int64_t Value, unsigned ValueSize, uint64_t Size,
351 MCSection *Sec = nullptr)
352 : MCFragment(FT_Fill, false, 0, Sec), Value(Value), ValueSize(ValueSize),
354 assert((!ValueSize || (Size % ValueSize) == 0) &&
355 "Fill size must be a multiple of the value size!");
361 int64_t getValue() const { return Value; }
363 unsigned getValueSize() const { return ValueSize; }
365 uint64_t getSize() const { return Size; }
369 static bool classof(const MCFragment *F) {
370 return F->getKind() == MCFragment::FT_Fill;
374 class MCOrgFragment : public MCFragment {
376 /// Offset - The offset this fragment should start at.
377 const MCExpr *Offset;
379 /// Value - Value to use for filling bytes.
383 MCOrgFragment(const MCExpr &Offset, int8_t Value, MCSection *Sec = nullptr)
384 : MCFragment(FT_Org, false, 0, Sec), Offset(&Offset), Value(Value) {}
389 const MCExpr &getOffset() const { return *Offset; }
391 uint8_t getValue() const { return Value; }
395 static bool classof(const MCFragment *F) {
396 return F->getKind() == MCFragment::FT_Org;
400 class MCLEBFragment : public MCFragment {
402 /// Value - The value this fragment should contain.
405 /// IsSigned - True if this is a sleb128, false if uleb128.
408 SmallString<8> Contents;
411 MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSection *Sec = nullptr)
412 : MCFragment(FT_LEB, false, 0, Sec), Value(&Value_), IsSigned(IsSigned_) {
413 Contents.push_back(0);
419 const MCExpr &getValue() const { return *Value; }
421 bool isSigned() const { return IsSigned; }
423 SmallString<8> &getContents() { return Contents; }
424 const SmallString<8> &getContents() const { return Contents; }
428 static bool classof(const MCFragment *F) {
429 return F->getKind() == MCFragment::FT_LEB;
433 class MCDwarfLineAddrFragment : public MCFragment {
435 /// LineDelta - the value of the difference between the two line numbers
436 /// between two .loc dwarf directives.
439 /// AddrDelta - The expression for the difference of the two symbols that
440 /// make up the address delta between two .loc dwarf directives.
441 const MCExpr *AddrDelta;
443 SmallString<8> Contents;
446 MCDwarfLineAddrFragment(int64_t LineDelta, const MCExpr &AddrDelta,
447 MCSection *Sec = nullptr)
448 : MCFragment(FT_Dwarf, false, 0, Sec), LineDelta(LineDelta),
449 AddrDelta(&AddrDelta) {
450 Contents.push_back(0);
456 int64_t getLineDelta() const { return LineDelta; }
458 const MCExpr &getAddrDelta() const { return *AddrDelta; }
460 SmallString<8> &getContents() { return Contents; }
461 const SmallString<8> &getContents() const { return Contents; }
465 static bool classof(const MCFragment *F) {
466 return F->getKind() == MCFragment::FT_Dwarf;
470 class MCDwarfCallFrameFragment : public MCFragment {
472 /// AddrDelta - The expression for the difference of the two symbols that
473 /// make up the address delta between two .cfi_* dwarf directives.
474 const MCExpr *AddrDelta;
476 SmallString<8> Contents;
479 MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSection *Sec = nullptr)
480 : MCFragment(FT_DwarfFrame, false, 0, Sec), AddrDelta(&AddrDelta) {
481 Contents.push_back(0);
487 const MCExpr &getAddrDelta() const { return *AddrDelta; }
489 SmallString<8> &getContents() { return Contents; }
490 const SmallString<8> &getContents() const { return Contents; }
494 static bool classof(const MCFragment *F) {
495 return F->getKind() == MCFragment::FT_DwarfFrame;
499 class MCSafeSEHFragment : public MCFragment {
503 MCSafeSEHFragment(const MCSymbol *Sym, MCSection *Sec = nullptr)
504 : MCFragment(FT_SafeSEH, false, 0, Sec), Sym(Sym) {}
509 const MCSymbol *getSymbol() { return Sym; }
510 const MCSymbol *getSymbol() const { return Sym; }
514 static bool classof(const MCFragment *F) {
515 return F->getKind() == MCFragment::FT_SafeSEH;
519 // FIXME: This really doesn't belong here. See comments below.
520 struct IndirectSymbolData {
525 // FIXME: Ditto this. Purely so the Streamer and the ObjectWriter can talk
527 struct DataRegionData {
528 // This enum should be kept in sync w/ the mach-o definition in
529 // llvm/Object/MachOFormat.h.
530 enum KindTy { Data = 1, JumpTable8, JumpTable16, JumpTable32 } Kind;
536 friend class MCAsmLayout;
539 typedef std::vector<MCSection *> SectionListType;
540 typedef std::vector<const MCSymbol *> SymbolDataListType;
542 typedef pointee_iterator<SectionListType::const_iterator> const_iterator;
543 typedef pointee_iterator<SectionListType::iterator> iterator;
545 typedef pointee_iterator<SymbolDataListType::const_iterator>
546 const_symbol_iterator;
547 typedef pointee_iterator<SymbolDataListType::iterator> symbol_iterator;
549 typedef iterator_range<symbol_iterator> symbol_range;
550 typedef iterator_range<const_symbol_iterator> const_symbol_range;
552 typedef std::vector<IndirectSymbolData>::const_iterator
553 const_indirect_symbol_iterator;
554 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
556 typedef std::vector<DataRegionData>::const_iterator
557 const_data_region_iterator;
558 typedef std::vector<DataRegionData>::iterator data_region_iterator;
560 /// MachO specific deployment target version info.
561 // A Major version of 0 indicates that no version information was supplied
562 // and so the corresponding load command should not be emitted.
564 MCVersionMinType Kind;
568 } VersionMinInfoType;
571 MCAssembler(const MCAssembler &) = delete;
572 void operator=(const MCAssembler &) = delete;
576 MCAsmBackend &Backend;
578 MCCodeEmitter &Emitter;
580 MCObjectWriter &Writer;
582 SectionListType Sections;
584 SymbolDataListType Symbols;
586 std::vector<IndirectSymbolData> IndirectSymbols;
588 std::vector<DataRegionData> DataRegions;
590 /// The list of linker options to propagate into the object file.
591 std::vector<std::vector<std::string>> LinkerOptions;
593 /// List of declared file names
594 std::vector<std::string> FileNames;
596 MCDwarfLineTableParams LTParams;
598 /// The set of function symbols for which a .thumb_func directive has
601 // FIXME: We really would like this in target specific code rather than
602 // here. Maybe when the relocation stuff moves to target specific,
603 // this can go with it? The streamer would need some target specific
605 mutable SmallPtrSet<const MCSymbol *, 64> ThumbFuncs;
607 /// \brief The bundle alignment size currently set in the assembler.
609 /// By default it's 0, which means bundling is disabled.
610 unsigned BundleAlignSize;
612 unsigned RelaxAll : 1;
613 unsigned SubsectionsViaSymbols : 1;
615 /// ELF specific e_header flags
616 // It would be good if there were an MCELFAssembler class to hold this.
617 // ELF header flags are used both by the integrated and standalone assemblers.
618 // Access to the flags is necessary in cases where assembler directives affect
619 // which flags to be set.
620 unsigned ELFHeaderEFlags;
622 /// Used to communicate Linker Optimization Hint information between
623 /// the Streamer and the .o writer
624 MCLOHContainer LOHContainer;
626 VersionMinInfoType VersionMinInfo;
629 /// Evaluate a fixup to a relocatable expression and the value which should be
630 /// placed into the fixup.
632 /// \param Layout The layout to use for evaluation.
633 /// \param Fixup The fixup to evaluate.
634 /// \param DF The fragment the fixup is inside.
635 /// \param Target [out] On return, the relocatable expression the fixup
637 /// \param Value [out] On return, the value of the fixup as currently laid
639 /// \return Whether the fixup value was fully resolved. This is true if the
640 /// \p Value result is fixed, otherwise the value may change due to
642 bool evaluateFixup(const MCAsmLayout &Layout, const MCFixup &Fixup,
643 const MCFragment *DF, MCValue &Target,
644 uint64_t &Value) const;
646 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
647 /// (increased in size, in order to hold its value correctly).
648 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCRelaxableFragment *DF,
649 const MCAsmLayout &Layout) const;
651 /// Check whether the given fragment needs relaxation.
652 bool fragmentNeedsRelaxation(const MCRelaxableFragment *IF,
653 const MCAsmLayout &Layout) const;
655 /// \brief Perform one layout iteration and return true if any offsets
657 bool layoutOnce(MCAsmLayout &Layout);
659 /// \brief Perform one layout iteration of the given section and return true
660 /// if any offsets were adjusted.
661 bool layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec);
663 bool relaxInstruction(MCAsmLayout &Layout, MCRelaxableFragment &IF);
665 bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
667 bool relaxDwarfLineAddr(MCAsmLayout &Layout, MCDwarfLineAddrFragment &DF);
668 bool relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
669 MCDwarfCallFrameFragment &DF);
671 /// finishLayout - Finalize a layout, including fragment lowering.
672 void finishLayout(MCAsmLayout &Layout);
674 std::pair<uint64_t, bool> handleFixup(const MCAsmLayout &Layout,
675 MCFragment &F, const MCFixup &Fixup);
678 /// Compute the effective fragment size assuming it is laid out at the given
679 /// \p SectionAddress and \p FragmentOffset.
680 uint64_t computeFragmentSize(const MCAsmLayout &Layout,
681 const MCFragment &F) const;
683 /// Find the symbol which defines the atom containing the given symbol, or
684 /// null if there is no such symbol.
685 const MCSymbol *getAtom(const MCSymbol &S) const;
687 /// Check whether a particular symbol is visible to the linker and is required
688 /// in the symbol table, or whether it can be discarded by the assembler. This
689 /// also effects whether the assembler treats the label as potentially
690 /// defining a separate atom.
691 bool isSymbolLinkerVisible(const MCSymbol &SD) const;
693 /// Emit the section contents using the given object writer.
694 void writeSectionData(const MCSection *Section,
695 const MCAsmLayout &Layout) const;
697 /// Check whether a given symbol has been flagged with .thumb_func.
698 bool isThumbFunc(const MCSymbol *Func) const;
700 /// Flag a function symbol as the target of a .thumb_func directive.
701 void setIsThumbFunc(const MCSymbol *Func) { ThumbFuncs.insert(Func); }
703 /// ELF e_header flags
704 unsigned getELFHeaderEFlags() const { return ELFHeaderEFlags; }
705 void setELFHeaderEFlags(unsigned Flags) { ELFHeaderEFlags = Flags; }
707 /// MachO deployment target version information.
708 const VersionMinInfoType &getVersionMinInfo() const { return VersionMinInfo; }
709 void setVersionMinInfo(MCVersionMinType Kind, unsigned Major, unsigned Minor,
711 VersionMinInfo.Kind = Kind;
712 VersionMinInfo.Major = Major;
713 VersionMinInfo.Minor = Minor;
714 VersionMinInfo.Update = Update;
718 /// Construct a new assembler instance.
720 // FIXME: How are we going to parameterize this? Two obvious options are stay
721 // concrete and require clients to pass in a target like object. The other
722 // option is to make this abstract, and have targets provide concrete
723 // implementations as we do with AsmParser.
724 MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
725 MCCodeEmitter &Emitter_, MCObjectWriter &Writer_);
728 /// Reuse an assembler instance
732 MCContext &getContext() const { return Context; }
734 MCAsmBackend &getBackend() const { return Backend; }
736 MCCodeEmitter &getEmitter() const { return Emitter; }
738 MCObjectWriter &getWriter() const { return Writer; }
740 MCDwarfLineTableParams getDWARFLinetableParams() const { return LTParams; }
741 void setDWARFLinetableParams(MCDwarfLineTableParams P) { LTParams = P; }
743 /// Finish - Do final processing and write the object to the output stream.
744 /// \p Writer is used for custom object writer (as the MCJIT does),
745 /// if not specified it is automatically created from backend.
748 // Layout all section and prepare them for emission.
749 void layout(MCAsmLayout &Layout);
751 // FIXME: This does not belong here.
752 bool getSubsectionsViaSymbols() const { return SubsectionsViaSymbols; }
753 void setSubsectionsViaSymbols(bool Value) { SubsectionsViaSymbols = Value; }
755 bool getRelaxAll() const { return RelaxAll; }
756 void setRelaxAll(bool Value) { RelaxAll = Value; }
758 bool isBundlingEnabled() const { return BundleAlignSize != 0; }
760 unsigned getBundleAlignSize() const { return BundleAlignSize; }
762 void setBundleAlignSize(unsigned Size) {
763 assert((Size == 0 || !(Size & (Size - 1))) &&
764 "Expect a power-of-two bundle align size");
765 BundleAlignSize = Size;
768 /// \name Section List Access
771 iterator begin() { return Sections.begin(); }
772 const_iterator begin() const { return Sections.begin(); }
774 iterator end() { return Sections.end(); }
775 const_iterator end() const { return Sections.end(); }
777 size_t size() const { return Sections.size(); }
780 /// \name Symbol List Access
782 symbol_iterator symbol_begin() { return Symbols.begin(); }
783 const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
785 symbol_iterator symbol_end() { return Symbols.end(); }
786 const_symbol_iterator symbol_end() const { return Symbols.end(); }
788 symbol_range symbols() { return make_range(symbol_begin(), symbol_end()); }
789 const_symbol_range symbols() const {
790 return make_range(symbol_begin(), symbol_end());
793 size_t symbol_size() const { return Symbols.size(); }
796 /// \name Indirect Symbol List Access
799 // FIXME: This is a total hack, this should not be here. Once things are
800 // factored so that the streamer has direct access to the .o writer, it can
802 std::vector<IndirectSymbolData> &getIndirectSymbols() {
803 return IndirectSymbols;
806 indirect_symbol_iterator indirect_symbol_begin() {
807 return IndirectSymbols.begin();
809 const_indirect_symbol_iterator indirect_symbol_begin() const {
810 return IndirectSymbols.begin();
813 indirect_symbol_iterator indirect_symbol_end() {
814 return IndirectSymbols.end();
816 const_indirect_symbol_iterator indirect_symbol_end() const {
817 return IndirectSymbols.end();
820 size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
823 /// \name Linker Option List Access
826 std::vector<std::vector<std::string>> &getLinkerOptions() {
827 return LinkerOptions;
831 /// \name Data Region List Access
834 // FIXME: This is a total hack, this should not be here. Once things are
835 // factored so that the streamer has direct access to the .o writer, it can
837 std::vector<DataRegionData> &getDataRegions() { return DataRegions; }
839 data_region_iterator data_region_begin() { return DataRegions.begin(); }
840 const_data_region_iterator data_region_begin() const {
841 return DataRegions.begin();
844 data_region_iterator data_region_end() { return DataRegions.end(); }
845 const_data_region_iterator data_region_end() const {
846 return DataRegions.end();
849 size_t data_region_size() const { return DataRegions.size(); }
852 /// \name Data Region List Access
855 // FIXME: This is a total hack, this should not be here. Once things are
856 // factored so that the streamer has direct access to the .o writer, it can
858 MCLOHContainer &getLOHContainer() { return LOHContainer; }
859 const MCLOHContainer &getLOHContainer() const {
860 return const_cast<MCAssembler *>(this)->getLOHContainer();
863 /// \name Backend Data Access
866 bool registerSection(MCSection &Section);
868 void registerSymbol(const MCSymbol &Symbol, bool *Created = nullptr);
870 ArrayRef<std::string> getFileNames() { return FileNames; }
872 void addFileName(StringRef FileName) {
873 if (std::find(FileNames.begin(), FileNames.end(), FileName) ==
875 FileNames.push_back(FileName);
878 /// \brief Write the necessary bundle padding to the given object writer.
879 /// Expects a fragment \p F containing instructions and its size \p FSize.
880 void writeFragmentPadding(const MCFragment &F, uint64_t FSize,
881 MCObjectWriter *OW) const;
888 /// \brief Compute the amount of padding required before the fragment \p F to
889 /// obey bundling restrictions, where \p FOffset is the fragment's offset in
890 /// its section and \p FSize is the fragment's size.
891 uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCFragment *F,
892 uint64_t FOffset, uint64_t FSize);
894 } // end namespace llvm