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,
65 /// \brief Should this fragment be aligned to the end of a bundle?
66 bool AlignToBundleEnd;
68 uint8_t BundlePadding;
70 /// LayoutOrder - The layout order of this fragment.
73 /// The data for the section this fragment is in.
76 /// Atom - The atom this fragment is in, as represented by it's defining
80 /// \name Assembler Backend Data
83 // FIXME: This could all be kept private to the assembler implementation.
85 /// Offset - The offset of this fragment in its section. This is ~0 until
92 MCFragment(FragmentType Kind, bool HasInstructions,
93 uint8_t BundlePadding, MCSection *Parent = nullptr);
98 // This is a friend so that the sentinal can be created.
99 friend struct ilist_sentinel_traits<MCFragment>;
103 /// Destroys the current fragment.
105 /// This must be used instead of delete as MCFragment is non-virtual.
106 /// This method will dispatch to the appropriate subclass.
109 FragmentType getKind() const { return Kind; }
111 MCSection *getParent() const { return Parent; }
112 void setParent(MCSection *Value) { Parent = Value; }
114 const MCSymbol *getAtom() const { return Atom; }
115 void setAtom(const MCSymbol *Value) { Atom = Value; }
117 unsigned getLayoutOrder() const { return LayoutOrder; }
118 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
120 /// \brief Does this fragment have instructions emitted into it? By default
121 /// this is false, but specific fragment types may set it to true.
122 bool hasInstructions() const { return HasInstructions; }
124 /// \brief Should this fragment be placed at the end of an aligned bundle?
125 bool alignToBundleEnd() const { return AlignToBundleEnd; }
126 void setAlignToBundleEnd(bool V) { AlignToBundleEnd = V; }
128 /// \brief Get the padding size that must be inserted before this fragment.
129 /// Used for bundling. By default, no padding is inserted.
130 /// Note that padding size is restricted to 8 bits. This is an optimization
131 /// to reduce the amount of space used for each fragment. In practice, larger
132 /// padding should never be required.
133 uint8_t getBundlePadding() const { return BundlePadding; }
135 /// \brief Set the padding size for this fragment. By default it's a no-op,
136 /// and only some fragments have a meaningful implementation.
137 void setBundlePadding(uint8_t N) { BundlePadding = N; }
142 /// Interface implemented by fragments that contain encoded instructions and/or
145 class MCEncodedFragment : public MCFragment {
147 MCEncodedFragment(MCFragment::FragmentType FType, bool HasInstructions,
149 : MCFragment(FType, HasInstructions, 0, Sec) {}
152 static bool classof(const MCFragment *F) {
153 MCFragment::FragmentType Kind = F->getKind();
157 case MCFragment::FT_Relaxable:
158 case MCFragment::FT_CompactEncodedInst:
159 case MCFragment::FT_Data:
165 /// Interface implemented by fragments that contain encoded instructions and/or
168 template<unsigned ContentsSize>
169 class MCEncodedFragmentWithContents : public MCEncodedFragment {
170 SmallVector<char, ContentsSize> Contents;
173 MCEncodedFragmentWithContents(MCFragment::FragmentType FType,
174 bool HasInstructions,
176 : MCEncodedFragment(FType, HasInstructions, Sec) {}
179 SmallVectorImpl<char> &getContents() { return Contents; }
180 const SmallVectorImpl<char> &getContents() const { return Contents; }
183 /// Interface implemented by fragments that contain encoded instructions and/or
184 /// data and also have fixups registered.
186 template<unsigned ContentsSize, unsigned FixupsSize>
187 class MCEncodedFragmentWithFixups :
188 public MCEncodedFragmentWithContents<ContentsSize> {
190 /// Fixups - The list of fixups in this fragment.
191 SmallVector<MCFixup, FixupsSize> Fixups;
194 MCEncodedFragmentWithFixups(MCFragment::FragmentType FType,
195 bool HasInstructions,
197 : MCEncodedFragmentWithContents<ContentsSize>(FType, HasInstructions,
201 typedef SmallVectorImpl<MCFixup>::const_iterator const_fixup_iterator;
202 typedef SmallVectorImpl<MCFixup>::iterator fixup_iterator;
204 SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
205 const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
207 fixup_iterator fixup_begin() { return Fixups.begin(); }
208 const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
210 fixup_iterator fixup_end() { return Fixups.end(); }
211 const_fixup_iterator fixup_end() const { return Fixups.end(); }
213 static bool classof(const MCFragment *F) {
214 MCFragment::FragmentType Kind = F->getKind();
215 return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data;
219 /// Fragment for data and encoded instructions.
221 class MCDataFragment : public MCEncodedFragmentWithFixups<32, 4> {
223 MCDataFragment(MCSection *Sec = nullptr)
224 : MCEncodedFragmentWithFixups<32, 4>(FT_Data, false, Sec) {}
226 void setHasInstructions(bool V) { HasInstructions = V; }
228 static bool classof(const MCFragment *F) {
229 return F->getKind() == MCFragment::FT_Data;
233 /// This is a compact (memory-size-wise) fragment for holding an encoded
234 /// instruction (non-relaxable) that has no fixups registered. When applicable,
235 /// it can be used instead of MCDataFragment and lead to lower memory
238 class MCCompactEncodedInstFragment : public MCEncodedFragmentWithContents<4> {
240 MCCompactEncodedInstFragment(MCSection *Sec = nullptr)
241 : MCEncodedFragmentWithContents(FT_CompactEncodedInst, true, Sec) {
244 static bool classof(const MCFragment *F) {
245 return F->getKind() == MCFragment::FT_CompactEncodedInst;
249 /// A relaxable fragment holds on to its MCInst, since it may need to be
250 /// relaxed during the assembler layout and relaxation stage.
252 class MCRelaxableFragment : public MCEncodedFragmentWithFixups<8, 1> {
254 /// Inst - The instruction this is a fragment for.
257 /// STI - The MCSubtargetInfo in effect when the instruction was encoded.
258 /// Keep a copy instead of a reference to make sure that updates to STI
259 /// in the assembler are not seen here.
260 const MCSubtargetInfo STI;
263 MCRelaxableFragment(const MCInst &Inst, const MCSubtargetInfo &STI,
264 MCSection *Sec = nullptr)
265 : MCEncodedFragmentWithFixups(FT_Relaxable, true, Sec),
266 Inst(Inst), STI(STI) {}
268 const MCInst &getInst() const { return Inst; }
269 void setInst(const MCInst &Value) { Inst = Value; }
271 const MCSubtargetInfo &getSubtargetInfo() { return STI; }
273 static bool classof(const MCFragment *F) {
274 return F->getKind() == MCFragment::FT_Relaxable;
278 class MCAlignFragment : public MCFragment {
280 /// Alignment - The alignment to ensure, in bytes.
283 /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
284 /// of using the provided value. The exact interpretation of this flag is
285 /// target dependent.
288 /// Value - Value to use for filling padding bytes.
291 /// ValueSize - The size of the integer (in bytes) of \p Value.
294 /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
295 /// cannot be satisfied in this width then this fragment is ignored.
296 unsigned MaxBytesToEmit;
299 MCAlignFragment(unsigned Alignment, int64_t Value, unsigned ValueSize,
300 unsigned MaxBytesToEmit, MCSection *Sec = nullptr)
301 : MCFragment(FT_Align, false, 0, Sec), Alignment(Alignment),
302 EmitNops(false), Value(Value),
303 ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit) {}
308 unsigned getAlignment() const { return Alignment; }
310 int64_t getValue() const { return Value; }
312 unsigned getValueSize() const { return ValueSize; }
314 unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
316 bool hasEmitNops() const { return EmitNops; }
317 void setEmitNops(bool Value) { EmitNops = Value; }
321 static bool classof(const MCFragment *F) {
322 return F->getKind() == MCFragment::FT_Align;
326 class MCFillFragment : public MCFragment {
328 /// Value - Value to use for filling bytes.
331 /// ValueSize - The size (in bytes) of \p Value to use when filling, or 0 if
332 /// this is a virtual fill fragment.
335 /// Size - The number of bytes to insert.
339 MCFillFragment(int64_t Value, unsigned ValueSize, uint64_t Size,
340 MCSection *Sec = nullptr)
341 : MCFragment(FT_Fill, false, 0, Sec), Value(Value), ValueSize(ValueSize),
343 assert((!ValueSize || (Size % ValueSize) == 0) &&
344 "Fill size must be a multiple of the value size!");
350 int64_t getValue() const { return Value; }
352 unsigned getValueSize() const { return ValueSize; }
354 uint64_t getSize() const { return Size; }
358 static bool classof(const MCFragment *F) {
359 return F->getKind() == MCFragment::FT_Fill;
363 class MCOrgFragment : public MCFragment {
365 /// Offset - The offset this fragment should start at.
366 const MCExpr *Offset;
368 /// Value - Value to use for filling bytes.
372 MCOrgFragment(const MCExpr &Offset, int8_t Value, MCSection *Sec = nullptr)
373 : MCFragment(FT_Org, false, 0, Sec), Offset(&Offset), Value(Value) {}
378 const MCExpr &getOffset() const { return *Offset; }
380 uint8_t getValue() const { return Value; }
384 static bool classof(const MCFragment *F) {
385 return F->getKind() == MCFragment::FT_Org;
389 class MCLEBFragment : public MCFragment {
391 /// Value - The value this fragment should contain.
394 /// IsSigned - True if this is a sleb128, false if uleb128.
397 SmallString<8> Contents;
400 MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSection *Sec = nullptr)
401 : MCFragment(FT_LEB, false, 0, Sec), Value(&Value_), IsSigned(IsSigned_) {
402 Contents.push_back(0);
408 const MCExpr &getValue() const { return *Value; }
410 bool isSigned() const { return IsSigned; }
412 SmallString<8> &getContents() { return Contents; }
413 const SmallString<8> &getContents() const { return Contents; }
417 static bool classof(const MCFragment *F) {
418 return F->getKind() == MCFragment::FT_LEB;
422 class MCDwarfLineAddrFragment : public MCFragment {
424 /// LineDelta - the value of the difference between the two line numbers
425 /// between two .loc dwarf directives.
428 /// AddrDelta - The expression for the difference of the two symbols that
429 /// make up the address delta between two .loc dwarf directives.
430 const MCExpr *AddrDelta;
432 SmallString<8> Contents;
435 MCDwarfLineAddrFragment(int64_t LineDelta, const MCExpr &AddrDelta,
436 MCSection *Sec = nullptr)
437 : MCFragment(FT_Dwarf, false, 0, Sec), LineDelta(LineDelta),
438 AddrDelta(&AddrDelta) {
439 Contents.push_back(0);
445 int64_t getLineDelta() const { return LineDelta; }
447 const MCExpr &getAddrDelta() const { return *AddrDelta; }
449 SmallString<8> &getContents() { return Contents; }
450 const SmallString<8> &getContents() const { return Contents; }
454 static bool classof(const MCFragment *F) {
455 return F->getKind() == MCFragment::FT_Dwarf;
459 class MCDwarfCallFrameFragment : public MCFragment {
461 /// AddrDelta - The expression for the difference of the two symbols that
462 /// make up the address delta between two .cfi_* dwarf directives.
463 const MCExpr *AddrDelta;
465 SmallString<8> Contents;
468 MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSection *Sec = nullptr)
469 : MCFragment(FT_DwarfFrame, false, 0, Sec), AddrDelta(&AddrDelta) {
470 Contents.push_back(0);
476 const MCExpr &getAddrDelta() const { return *AddrDelta; }
478 SmallString<8> &getContents() { return Contents; }
479 const SmallString<8> &getContents() const { return Contents; }
483 static bool classof(const MCFragment *F) {
484 return F->getKind() == MCFragment::FT_DwarfFrame;
488 class MCSafeSEHFragment : public MCFragment {
492 MCSafeSEHFragment(const MCSymbol *Sym, MCSection *Sec = nullptr)
493 : MCFragment(FT_SafeSEH, false, 0, Sec), Sym(Sym) {}
498 const MCSymbol *getSymbol() { return Sym; }
499 const MCSymbol *getSymbol() const { return Sym; }
503 static bool classof(const MCFragment *F) {
504 return F->getKind() == MCFragment::FT_SafeSEH;
508 // FIXME: This really doesn't belong here. See comments below.
509 struct IndirectSymbolData {
514 // FIXME: Ditto this. Purely so the Streamer and the ObjectWriter can talk
516 struct DataRegionData {
517 // This enum should be kept in sync w/ the mach-o definition in
518 // llvm/Object/MachOFormat.h.
519 enum KindTy { Data = 1, JumpTable8, JumpTable16, JumpTable32 } Kind;
525 friend class MCAsmLayout;
528 typedef std::vector<MCSection *> SectionListType;
529 typedef std::vector<const MCSymbol *> SymbolDataListType;
531 typedef pointee_iterator<SectionListType::const_iterator> const_iterator;
532 typedef pointee_iterator<SectionListType::iterator> iterator;
534 typedef pointee_iterator<SymbolDataListType::const_iterator>
535 const_symbol_iterator;
536 typedef pointee_iterator<SymbolDataListType::iterator> symbol_iterator;
538 typedef iterator_range<symbol_iterator> symbol_range;
539 typedef iterator_range<const_symbol_iterator> const_symbol_range;
541 typedef std::vector<IndirectSymbolData>::const_iterator
542 const_indirect_symbol_iterator;
543 typedef std::vector<IndirectSymbolData>::iterator indirect_symbol_iterator;
545 typedef std::vector<DataRegionData>::const_iterator
546 const_data_region_iterator;
547 typedef std::vector<DataRegionData>::iterator data_region_iterator;
549 /// MachO specific deployment target version info.
550 // A Major version of 0 indicates that no version information was supplied
551 // and so the corresponding load command should not be emitted.
553 MCVersionMinType Kind;
557 } VersionMinInfoType;
560 MCAssembler(const MCAssembler &) = delete;
561 void operator=(const MCAssembler &) = delete;
565 MCAsmBackend &Backend;
567 MCCodeEmitter &Emitter;
569 MCObjectWriter &Writer;
571 SectionListType Sections;
573 SymbolDataListType Symbols;
575 std::vector<IndirectSymbolData> IndirectSymbols;
577 std::vector<DataRegionData> DataRegions;
579 /// The list of linker options to propagate into the object file.
580 std::vector<std::vector<std::string>> LinkerOptions;
582 /// List of declared file names
583 std::vector<std::string> FileNames;
585 MCDwarfLineTableParams LTParams;
587 /// The set of function symbols for which a .thumb_func directive has
590 // FIXME: We really would like this in target specific code rather than
591 // here. Maybe when the relocation stuff moves to target specific,
592 // this can go with it? The streamer would need some target specific
594 mutable SmallPtrSet<const MCSymbol *, 64> ThumbFuncs;
596 /// \brief The bundle alignment size currently set in the assembler.
598 /// By default it's 0, which means bundling is disabled.
599 unsigned BundleAlignSize;
601 unsigned RelaxAll : 1;
602 unsigned SubsectionsViaSymbols : 1;
604 /// ELF specific e_header flags
605 // It would be good if there were an MCELFAssembler class to hold this.
606 // ELF header flags are used both by the integrated and standalone assemblers.
607 // Access to the flags is necessary in cases where assembler directives affect
608 // which flags to be set.
609 unsigned ELFHeaderEFlags;
611 /// Used to communicate Linker Optimization Hint information between
612 /// the Streamer and the .o writer
613 MCLOHContainer LOHContainer;
615 VersionMinInfoType VersionMinInfo;
618 /// Evaluate a fixup to a relocatable expression and the value which should be
619 /// placed into the fixup.
621 /// \param Layout The layout to use for evaluation.
622 /// \param Fixup The fixup to evaluate.
623 /// \param DF The fragment the fixup is inside.
624 /// \param Target [out] On return, the relocatable expression the fixup
626 /// \param Value [out] On return, the value of the fixup as currently laid
628 /// \return Whether the fixup value was fully resolved. This is true if the
629 /// \p Value result is fixed, otherwise the value may change due to
631 bool evaluateFixup(const MCAsmLayout &Layout, const MCFixup &Fixup,
632 const MCFragment *DF, MCValue &Target,
633 uint64_t &Value) const;
635 /// Check whether a fixup can be satisfied, or whether it needs to be relaxed
636 /// (increased in size, in order to hold its value correctly).
637 bool fixupNeedsRelaxation(const MCFixup &Fixup, const MCRelaxableFragment *DF,
638 const MCAsmLayout &Layout) const;
640 /// Check whether the given fragment needs relaxation.
641 bool fragmentNeedsRelaxation(const MCRelaxableFragment *IF,
642 const MCAsmLayout &Layout) const;
644 /// \brief Perform one layout iteration and return true if any offsets
646 bool layoutOnce(MCAsmLayout &Layout);
648 /// \brief Perform one layout iteration of the given section and return true
649 /// if any offsets were adjusted.
650 bool layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec);
652 bool relaxInstruction(MCAsmLayout &Layout, MCRelaxableFragment &IF);
654 bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
656 bool relaxDwarfLineAddr(MCAsmLayout &Layout, MCDwarfLineAddrFragment &DF);
657 bool relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
658 MCDwarfCallFrameFragment &DF);
660 /// finishLayout - Finalize a layout, including fragment lowering.
661 void finishLayout(MCAsmLayout &Layout);
663 std::pair<uint64_t, bool> handleFixup(const MCAsmLayout &Layout,
664 MCFragment &F, const MCFixup &Fixup);
667 /// Compute the effective fragment size assuming it is laid out at the given
668 /// \p SectionAddress and \p FragmentOffset.
669 uint64_t computeFragmentSize(const MCAsmLayout &Layout,
670 const MCFragment &F) const;
672 /// Find the symbol which defines the atom containing the given symbol, or
673 /// null if there is no such symbol.
674 const MCSymbol *getAtom(const MCSymbol &S) const;
676 /// Check whether a particular symbol is visible to the linker and is required
677 /// in the symbol table, or whether it can be discarded by the assembler. This
678 /// also effects whether the assembler treats the label as potentially
679 /// defining a separate atom.
680 bool isSymbolLinkerVisible(const MCSymbol &SD) const;
682 /// Emit the section contents using the given object writer.
683 void writeSectionData(const MCSection *Section,
684 const MCAsmLayout &Layout) const;
686 /// Check whether a given symbol has been flagged with .thumb_func.
687 bool isThumbFunc(const MCSymbol *Func) const;
689 /// Flag a function symbol as the target of a .thumb_func directive.
690 void setIsThumbFunc(const MCSymbol *Func) { ThumbFuncs.insert(Func); }
692 /// ELF e_header flags
693 unsigned getELFHeaderEFlags() const { return ELFHeaderEFlags; }
694 void setELFHeaderEFlags(unsigned Flags) { ELFHeaderEFlags = Flags; }
696 /// MachO deployment target version information.
697 const VersionMinInfoType &getVersionMinInfo() const { return VersionMinInfo; }
698 void setVersionMinInfo(MCVersionMinType Kind, unsigned Major, unsigned Minor,
700 VersionMinInfo.Kind = Kind;
701 VersionMinInfo.Major = Major;
702 VersionMinInfo.Minor = Minor;
703 VersionMinInfo.Update = Update;
707 /// Construct a new assembler instance.
709 // FIXME: How are we going to parameterize this? Two obvious options are stay
710 // concrete and require clients to pass in a target like object. The other
711 // option is to make this abstract, and have targets provide concrete
712 // implementations as we do with AsmParser.
713 MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
714 MCCodeEmitter &Emitter_, MCObjectWriter &Writer_);
717 /// Reuse an assembler instance
721 MCContext &getContext() const { return Context; }
723 MCAsmBackend &getBackend() const { return Backend; }
725 MCCodeEmitter &getEmitter() const { return Emitter; }
727 MCObjectWriter &getWriter() const { return Writer; }
729 MCDwarfLineTableParams getDWARFLinetableParams() const { return LTParams; }
730 void setDWARFLinetableParams(MCDwarfLineTableParams P) { LTParams = P; }
732 /// Finish - Do final processing and write the object to the output stream.
733 /// \p Writer is used for custom object writer (as the MCJIT does),
734 /// if not specified it is automatically created from backend.
737 // Layout all section and prepare them for emission.
738 void layout(MCAsmLayout &Layout);
740 // FIXME: This does not belong here.
741 bool getSubsectionsViaSymbols() const { return SubsectionsViaSymbols; }
742 void setSubsectionsViaSymbols(bool Value) { SubsectionsViaSymbols = Value; }
744 bool getRelaxAll() const { return RelaxAll; }
745 void setRelaxAll(bool Value) { RelaxAll = Value; }
747 bool isBundlingEnabled() const { return BundleAlignSize != 0; }
749 unsigned getBundleAlignSize() const { return BundleAlignSize; }
751 void setBundleAlignSize(unsigned Size) {
752 assert((Size == 0 || !(Size & (Size - 1))) &&
753 "Expect a power-of-two bundle align size");
754 BundleAlignSize = Size;
757 /// \name Section List Access
760 iterator begin() { return Sections.begin(); }
761 const_iterator begin() const { return Sections.begin(); }
763 iterator end() { return Sections.end(); }
764 const_iterator end() const { return Sections.end(); }
766 size_t size() const { return Sections.size(); }
769 /// \name Symbol List Access
771 symbol_iterator symbol_begin() { return Symbols.begin(); }
772 const_symbol_iterator symbol_begin() const { return Symbols.begin(); }
774 symbol_iterator symbol_end() { return Symbols.end(); }
775 const_symbol_iterator symbol_end() const { return Symbols.end(); }
777 symbol_range symbols() { return make_range(symbol_begin(), symbol_end()); }
778 const_symbol_range symbols() const {
779 return make_range(symbol_begin(), symbol_end());
782 size_t symbol_size() const { return Symbols.size(); }
785 /// \name Indirect Symbol List Access
788 // FIXME: This is a total hack, this should not be here. Once things are
789 // factored so that the streamer has direct access to the .o writer, it can
791 std::vector<IndirectSymbolData> &getIndirectSymbols() {
792 return IndirectSymbols;
795 indirect_symbol_iterator indirect_symbol_begin() {
796 return IndirectSymbols.begin();
798 const_indirect_symbol_iterator indirect_symbol_begin() const {
799 return IndirectSymbols.begin();
802 indirect_symbol_iterator indirect_symbol_end() {
803 return IndirectSymbols.end();
805 const_indirect_symbol_iterator indirect_symbol_end() const {
806 return IndirectSymbols.end();
809 size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
812 /// \name Linker Option List Access
815 std::vector<std::vector<std::string>> &getLinkerOptions() {
816 return LinkerOptions;
820 /// \name Data Region List Access
823 // FIXME: This is a total hack, this should not be here. Once things are
824 // factored so that the streamer has direct access to the .o writer, it can
826 std::vector<DataRegionData> &getDataRegions() { return DataRegions; }
828 data_region_iterator data_region_begin() { return DataRegions.begin(); }
829 const_data_region_iterator data_region_begin() const {
830 return DataRegions.begin();
833 data_region_iterator data_region_end() { return DataRegions.end(); }
834 const_data_region_iterator data_region_end() const {
835 return DataRegions.end();
838 size_t data_region_size() const { return DataRegions.size(); }
841 /// \name Data Region List Access
844 // FIXME: This is a total hack, this should not be here. Once things are
845 // factored so that the streamer has direct access to the .o writer, it can
847 MCLOHContainer &getLOHContainer() { return LOHContainer; }
848 const MCLOHContainer &getLOHContainer() const {
849 return const_cast<MCAssembler *>(this)->getLOHContainer();
852 /// \name Backend Data Access
855 bool registerSection(MCSection &Section);
857 void registerSymbol(const MCSymbol &Symbol, bool *Created = nullptr);
859 ArrayRef<std::string> getFileNames() { return FileNames; }
861 void addFileName(StringRef FileName) {
862 if (std::find(FileNames.begin(), FileNames.end(), FileName) ==
864 FileNames.push_back(FileName);
867 /// \brief Write the necessary bundle padding to the given object writer.
868 /// Expects a fragment \p F containing instructions and its size \p FSize.
869 void writeFragmentPadding(const MCFragment &F, uint64_t FSize,
870 MCObjectWriter *OW) const;
877 /// \brief Compute the amount of padding required before the fragment \p F to
878 /// obey bundling restrictions, where \p FOffset is the fragment's offset in
879 /// its section and \p FSize is the fragment's size.
880 uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCFragment *F,
881 uint64_t FOffset, uint64_t FSize);
883 } // end namespace llvm