llvm.org GIT mirror llvm / 7521964
Move alignment from MCSectionData to MCSection. This starts merging MCSection and MCSectionData. There are a few issues with the current split between MCSection and MCSectionData. * It optimizes the the not as important case. We want the production of .o files to be really fast, but the split puts the information used for .o emission in a separate data structure. * The ELF/COFF/MachO hierarchy is not represented in MCSectionData, leading to some ad-hoc ways to represent the various flags. * It makes it harder to remember where each item is. The attached patch starts merging the two by moving the alignment from MCSectionData to MCSection. Most of the patch is actually just dropping 'const', since MCSectionData is mutable, but MCSection was not. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237936 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
85 changed file(s) with 647 addition(s) and 714 deletion(s). Raw diff Collapse all Expand all
4545
4646 /// Given a constant with the SectionKind, return a section that it should be
4747 /// placed in.
48 const MCSection *getSectionForConstant(SectionKind Kind,
49 const Constant *C) const override;
48 MCSection *getSectionForConstant(SectionKind Kind,
49 const Constant *C) const override;
5050
51 const MCSection *getExplicitSectionGlobal(const GlobalValue *GV,
52 SectionKind Kind, Mangler &Mang,
53 const TargetMachine &TM) const override;
51 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
52 Mangler &Mang,
53 const TargetMachine &TM) const override;
5454
55 const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
56 SectionKind Kind, Mangler &Mang,
57 const TargetMachine &TM) const override;
55 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
56 Mangler &Mang,
57 const TargetMachine &TM) const override;
5858
59 const MCSection *
60 getSectionForJumpTable(const Function &F, Mangler &Mang,
61 const TargetMachine &TM) const override;
59 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
60 const TargetMachine &TM) const override;
6261
6362 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
6463 const Function &F) const override;
7776 MachineModuleInfo *MMI) const override;
7877
7978 void InitializeELF(bool UseInitArray_);
80 const MCSection *getStaticCtorSection(unsigned Priority,
81 const MCSymbol *KeySym) const override;
82 const MCSection *getStaticDtorSection(unsigned Priority,
83 const MCSymbol *KeySym) const override;
79 MCSection *getStaticCtorSection(unsigned Priority,
80 const MCSymbol *KeySym) const override;
81 MCSection *getStaticDtorSection(unsigned Priority,
82 const MCSymbol *KeySym) const override;
8483 };
8584
8685
9998 ArrayRef ModuleFlags,
10099 Mangler &Mang, const TargetMachine &TM) const override;
101100
102 const MCSection *
103 SelectSectionForGlobal(const GlobalValue *GV,
104 SectionKind Kind, Mangler &Mang,
105 const TargetMachine &TM) const override;
101 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
102 Mangler &Mang,
103 const TargetMachine &TM) const override;
106104
107 const MCSection *
108 getExplicitSectionGlobal(const GlobalValue *GV,
109 SectionKind Kind, Mangler &Mang,
110 const TargetMachine &TM) const override;
105 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
106 Mangler &Mang,
107 const TargetMachine &TM) const override;
111108
112 const MCSection *getSectionForConstant(SectionKind Kind,
113 const Constant *C) const override;
109 MCSection *getSectionForConstant(SectionKind Kind,
110 const Constant *C) const override;
114111
115112 /// The mach-o version of this method defaults to returning a stub reference.
116113 const MCExpr *
137134 public:
138135 ~TargetLoweringObjectFileCOFF() override {}
139136
140 const MCSection *
141 getExplicitSectionGlobal(const GlobalValue *GV,
142 SectionKind Kind, Mangler &Mang,
143 const TargetMachine &TM) const override;
137 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
138 Mangler &Mang,
139 const TargetMachine &TM) const override;
144140
145 const MCSection *
146 SelectSectionForGlobal(const GlobalValue *GV,
147 SectionKind Kind, Mangler &Mang,
148 const TargetMachine &TM) const override;
141 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
142 Mangler &Mang,
143 const TargetMachine &TM) const override;
149144
150145 void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV,
151146 bool CannotUsePrivateLabel, Mangler &Mang,
152147 const TargetMachine &TM) const override;
153148
154 const MCSection *
155 getSectionForJumpTable(const Function &F, Mangler &Mang,
156 const TargetMachine &TM) const override;
149 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
150 const TargetMachine &TM) const override;
157151
158152 /// Extract the dependent library name from a linker option string. Returns
159153 /// StringRef() if the option does not specify a library.
165159 ArrayRef ModuleFlags,
166160 Mangler &Mang, const TargetMachine &TM) const override;
167161
168 const MCSection *getStaticCtorSection(unsigned Priority,
169 const MCSymbol *KeySym) const override;
170 const MCSection *getStaticDtorSection(unsigned Priority,
171 const MCSymbol *KeySym) const override;
162 MCSection *getStaticCtorSection(unsigned Priority,
163 const MCSymbol *KeySym) const override;
164 MCSection *getStaticDtorSection(unsigned Priority,
165 const MCSymbol *KeySym) const override;
172166 };
173167
174168 } // end namespace llvm
7272 // sections in a stable order to ensure that we have print the
7373 // constant pools in a deterministic order when printing an assembly
7474 // file.
75 typedef MapVector<const MCSection *, ConstantPool> ConstantPoolMapTy;
75 typedef MapVector<MCSection *, ConstantPool> ConstantPoolMapTy;
7676 ConstantPoolMapTy ConstantPools;
7777
7878 public:
8282 unsigned Size);
8383
8484 private:
85 ConstantPool *getConstantPool(const MCSection *Section);
86 ConstantPool &getOrCreateConstantPool(const MCSection *Section);
85 ConstantPool *getConstantPool(MCSection *Section);
86 ConstantPool &getOrCreateConstantPool(MCSection *Section);
8787 };
8888 } // end namespace llvm
8989
387387 /// Targets can implement this method to specify a section to switch to if the
388388 /// translation unit doesn't have any trampolines that require an executable
389389 /// stack.
390 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
390 virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
391391 return nullptr;
392392 }
393393
1414 namespace llvm {
1515 class MCAsmInfoELF : public MCAsmInfo {
1616 virtual void anchor();
17 const MCSection *getNonexecutableStackSection(MCContext &Ctx) const final;
17 MCSection *getNonexecutableStackSection(MCContext &Ctx) const final;
1818
1919 protected:
2020 MCAsmInfoELF();
556556
557557 private:
558558 FragmentListType Fragments;
559 const MCSection *Section;
559 MCSection *Section;
560560
561561 /// Ordinal - The section index in the assemblers section list.
562562 unsigned Ordinal;
563563
564564 /// LayoutOrder - The index of this section in the layout order.
565565 unsigned LayoutOrder;
566
567 /// Alignment - The maximum alignment seen in this section.
568 unsigned Alignment;
569566
570567 /// \brief Keeping track of bundle-locked state.
571568 BundleLockStateType BundleLockState;
595592 public:
596593 // Only for use as sentinel.
597594 MCSectionData();
598 MCSectionData(const MCSection &Section, MCAssembler *A = nullptr);
599
600 const MCSection &getSection() const { return *Section; }
601
602 unsigned getAlignment() const { return Alignment; }
603 void setAlignment(unsigned Value) { Alignment = Value; }
595 MCSectionData(MCSection &Section, MCAssembler *A = nullptr);
596
597 MCSection &getSection() const { return *Section; }
598
599 unsigned getAlignment() const;
600 void setAlignment(unsigned Value);
604601
605602 bool hasInstructions() const { return HasInstructions; }
606603 void setHasInstructions(bool Value) { HasInstructions = Value; }
10201017 return *Entry;
10211018 }
10221019
1023 MCSectionData &getOrCreateSectionData(const MCSection &Section,
1020 MCSectionData &getOrCreateSectionData(MCSection &Section,
10241021 bool *Created = nullptr) {
10251022 MCSectionData *&Entry = SectionMap[&Section];
10261023
136136 unsigned GenDwarfFileNumber;
137137
138138 /// Sections for generating the .debug_ranges and .debug_aranges sections.
139 SetVector<const MCSection *> SectionsForRanges;
139 SetVector<MCSection *> SectionsForRanges;
140140
141141 /// The information gathered from labels that will have dwarf label
142142 /// entries when generating dwarf assembly source files.
196196 }
197197 };
198198
199 StringMap MachOUniquingMap;
200 std::map ELFUniquingMap;
201 std::map COFFUniquingMap;
199 StringMap MachOUniquingMap;
200 std::map ELFUniquingMap;
201 std::map COFFUniquingMap;
202202 StringMap ELFRelSecNames;
203203
204204 /// Do automatic reset in destructor
290290
291291 /// Return the MCSection for the specified mach-o section. This requires
292292 /// the operands to be valid.
293 const MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
294 unsigned TypeAndAttributes,
295 unsigned Reserved2, SectionKind K,
296 const char *BeginSymName = nullptr);
297
298 const MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
299 unsigned TypeAndAttributes,
300 SectionKind K,
301 const char *BeginSymName = nullptr) {
293 MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
294 unsigned TypeAndAttributes,
295 unsigned Reserved2, SectionKind K,
296 const char *BeginSymName = nullptr);
297
298 MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
299 unsigned TypeAndAttributes, SectionKind K,
300 const char *BeginSymName = nullptr) {
302301 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K,
303302 BeginSymName);
304303 }
305304
306 const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
307 unsigned Flags) {
305 MCSectionELF *getELFSection(StringRef Section, unsigned Type,
306 unsigned Flags) {
308307 return getELFSection(Section, Type, Flags, nullptr);
309308 }
310309
311 const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
312 unsigned Flags,
313 const char *BeginSymName) {
310 MCSectionELF *getELFSection(StringRef Section, unsigned Type,
311 unsigned Flags, const char *BeginSymName) {
314312 return getELFSection(Section, Type, Flags, 0, "", BeginSymName);
315313 }
316314
317 const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
318 unsigned Flags, unsigned EntrySize,
319 StringRef Group) {
315 MCSectionELF *getELFSection(StringRef Section, unsigned Type,
316 unsigned Flags, unsigned EntrySize,
317 StringRef Group) {
320318 return getELFSection(Section, Type, Flags, EntrySize, Group, nullptr);
321319 }
322320
323 const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
324 unsigned Flags, unsigned EntrySize,
325 StringRef Group,
326 const char *BeginSymName) {
321 MCSectionELF *getELFSection(StringRef Section, unsigned Type,
322 unsigned Flags, unsigned EntrySize,
323 StringRef Group, const char *BeginSymName) {
327324 return getELFSection(Section, Type, Flags, EntrySize, Group, ~0,
328325 BeginSymName);
329326 }
330327
331 const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
332 unsigned Flags, unsigned EntrySize,
333 StringRef Group, unsigned UniqueID) {
328 MCSectionELF *getELFSection(StringRef Section, unsigned Type,
329 unsigned Flags, unsigned EntrySize,
330 StringRef Group, unsigned UniqueID) {
334331 return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
335332 nullptr);
336333 }
337334
338 const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
335 MCSectionELF *getELFSection(StringRef Section, unsigned Type,
336 unsigned Flags, unsigned EntrySize,
337 StringRef Group, unsigned UniqueID,
338 const char *BeginSymName);
339
340 MCSectionELF *getELFSection(StringRef Section, unsigned Type,
341 unsigned Flags, unsigned EntrySize,
342 const MCSymbol *Group, unsigned UniqueID,
343 const char *BeginSymName,
344 const MCSectionELF *Associated);
345
346 MCSectionELF *createELFRelSection(StringRef Name, unsigned Type,
339347 unsigned Flags, unsigned EntrySize,
340 StringRef Group, unsigned UniqueID,
341 const char *BeginSymName);
342
343 const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
344 unsigned Flags, unsigned EntrySize,
345 const MCSymbol *Group, unsigned UniqueID,
346 const char *BeginSymName,
348 const MCSymbol *Group,
347349 const MCSectionELF *Associated);
348350
349 const MCSectionELF *createELFRelSection(StringRef Name, unsigned Type,
350 unsigned Flags, unsigned EntrySize,
351 const MCSymbol *Group,
352 const MCSectionELF *Associated);
353
354 void renameELFSection(const MCSectionELF *Section, StringRef Name);
355
356 const MCSectionELF *createELFGroupSection(const MCSymbol *Group);
357
358 const MCSectionCOFF *getCOFFSection(StringRef Section,
359 unsigned Characteristics,
360 SectionKind Kind,
361 StringRef COMDATSymName, int Selection,
362 const char *BeginSymName = nullptr);
363
364 const MCSectionCOFF *getCOFFSection(StringRef Section,
365 unsigned Characteristics,
366 SectionKind Kind,
367 const char *BeginSymName = nullptr);
368
369 const MCSectionCOFF *getCOFFSection(StringRef Section);
351 void renameELFSection(MCSectionELF *Section, StringRef Name);
352
353 MCSectionELF *createELFGroupSection(const MCSymbol *Group);
354
355 MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
356 SectionKind Kind, StringRef COMDATSymName,
357 int Selection,
358 const char *BeginSymName = nullptr);
359
360 MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
361 SectionKind Kind,
362 const char *BeginSymName = nullptr);
363
364 MCSectionCOFF *getCOFFSection(StringRef Section);
370365
371366 /// Gets or creates a section equivalent to Sec that is associated with the
372367 /// section containing KeySym. For example, to create a debug info section
373368 /// associated with an inline function, pass the normal debug info section
374369 /// as Sec and the function symbol as KeySym.
375 const MCSectionCOFF *getAssociativeCOFFSection(const MCSectionCOFF *Sec,
376 const MCSymbol *KeySym);
370 MCSectionCOFF *getAssociativeCOFFSection(MCSectionCOFF *Sec,
371 const MCSymbol *KeySym);
377372
378373 /// @}
379374
466461 void setGenDwarfFileNumber(unsigned FileNumber) {
467462 GenDwarfFileNumber = FileNumber;
468463 }
469 const SetVector<const MCSection *> &getGenDwarfSectionSyms() {
464 const SetVector<MCSection *> &getGenDwarfSectionSyms() {
470465 return SectionsForRanges;
471466 }
472 bool addGenDwarfSection(const MCSection *Sec) {
467 bool addGenDwarfSection(MCSection *Sec) {
473468 return SectionsForRanges.insert(Sec);
474469 }
475470
142142 // This is called when an instruction is assembled into the specified
143143 // section and if there is information from the last .loc directive that
144144 // has yet to have a line entry made for it is made.
145 static void Make(MCObjectStreamer *MCOS, const MCSection *Section);
145 static void Make(MCObjectStreamer *MCOS, MCSection *Section);
146146 };
147147
148148 /// \brief Instances of this class represent the line information for a compile
152152 class MCLineSection {
153153 public:
154154 // \brief Add an entry to this MCLineSection's line entries.
155 void addLineEntry(const MCLineEntry &LineEntry, const MCSection *Sec) {
155 void addLineEntry(const MCLineEntry &LineEntry, MCSection *Sec) {
156156 MCLineDivisions[Sec].push_back(LineEntry);
157157 }
158158
159159 typedef std::vector MCLineEntryCollection;
160160 typedef MCLineEntryCollection::iterator iterator;
161161 typedef MCLineEntryCollection::const_iterator const_iterator;
162 typedef MapVector<const MCSection *, MCLineEntryCollection> MCLineDivisionMap;
162 typedef MapVector<MCSection *, MCLineEntryCollection> MCLineDivisionMap;
163163
164164 private:
165165 // A collection of MCLineEntry for each section.
4747 /// @{
4848
4949 void InitSections(bool NoExecStack) override;
50 void ChangeSection(const MCSection *Section,
51 const MCExpr *Subsection) override;
50 void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
5251 void EmitLabel(MCSymbol *Symbol) override;
5352 void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
5453 void EmitThumbFunc(MCSymbol *Func) override;
6766 void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
6867 unsigned ByteAlignment) override;
6968
70 void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = nullptr,
69 void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
7170 uint64_t Size = 0, unsigned ByteAlignment = 0) override;
72 void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
73 uint64_t Size, unsigned ByteAlignment = 0) override;
71 void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
72 unsigned ByteAlignment = 0) override;
7473 void EmitValueImpl(const MCExpr *Value, unsigned Size,
7574 const SMLoc &Loc = SMLoc()) override;
7675
115115 /// currently defined as the absolute section for constants, or
116116 /// otherwise the section associated with the first defined symbol in the
117117 /// expression.
118 const MCSection *FindAssociatedSection() const;
118 MCSection *FindAssociatedSection() const;
119119
120120 /// @}
121121 };
557557 const MCAsmLayout *Layout,
558558 const MCFixup *Fixup) const = 0;
559559 virtual void visitUsedExpr(MCStreamer& Streamer) const = 0;
560 virtual const MCSection *FindAssociatedSection() const = 0;
560 virtual MCSection *FindAssociatedSection() const = 0;
561561
562562 virtual void fixELFSymbolsInTLSFixups(MCAssembler &) const = 0;
563563
5252 /// should emit only an EH frame.
5353 unsigned CompactUnwindDwarfEHFrameOnly;
5454
55 /// TextSection - Section directive for standard text.
56 ///
57 const MCSection *TextSection;
58
59 /// DataSection - Section directive for standard data.
60 ///
61 const MCSection *DataSection;
62
63 /// BSSSection - Section that is default initialized to zero.
64 const MCSection *BSSSection;
65
66 /// ReadOnlySection - Section that is readonly and can contain arbitrary
67 /// initialized data. Targets are not required to have a readonly section.
68 /// If they don't, various bits of code will fall back to using the data
69 /// section for constants.
70 const MCSection *ReadOnlySection;
71
72 /// StaticCtorSection - This section contains the static constructor pointer
73 /// list.
74 const MCSection *StaticCtorSection;
75
76 /// StaticDtorSection - This section contains the static destructor pointer
77 /// list.
78 const MCSection *StaticDtorSection;
79
80 /// LSDASection - If exception handling is supported by the target, this is
81 /// the section the Language Specific Data Area information is emitted to.
82 const MCSection *LSDASection;
83
84 /// CompactUnwindSection - If exception handling is supported by the target
85 /// and the target can support a compact representation of the CIE and FDE,
86 /// this is the section to emit them into.
87 const MCSection *CompactUnwindSection;
55 /// Section directive for standard text.
56 ///
57 MCSection *TextSection;
58
59 /// Section directive for standard data.
60 ///
61 MCSection *DataSection;
62
63 /// Section that is default initialized to zero.
64 MCSection *BSSSection;
65
66 /// Section that is readonly and can contain arbitrary initialized data.
67 /// Targets are not required to have a readonly section. If they don't,
68 /// various bits of code will fall back to using the data section for
69 /// constants.
70 MCSection *ReadOnlySection;
71
72 /// This section contains the static constructor pointer list.
73 MCSection *StaticCtorSection;
74
75 /// This section contains the static destructor pointer list.
76 MCSection *StaticDtorSection;
77
78 /// If exception handling is supported by the target, this is the section the
79 /// Language Specific Data Area information is emitted to.
80 MCSection *LSDASection;
81
82 /// If exception handling is supported by the target and the target can
83 /// support a compact representation of the CIE and FDE, this is the section
84 /// to emit them into.
85 MCSection *CompactUnwindSection;
8886
8987 // Dwarf sections for debug info. If a target supports debug info, these must
9088 // be set.
91 const MCSection *DwarfAbbrevSection;
92 const MCSection *DwarfInfoSection;
93 const MCSection *DwarfLineSection;
94 const MCSection *DwarfFrameSection;
95 const MCSection *DwarfPubTypesSection;
89 MCSection *DwarfAbbrevSection;
90 MCSection *DwarfInfoSection;
91 MCSection *DwarfLineSection;
92 MCSection *DwarfFrameSection;
93 MCSection *DwarfPubTypesSection;
9694 const MCSection *DwarfDebugInlineSection;
97 const MCSection *DwarfStrSection;
98 const MCSection *DwarfLocSection;
99 const MCSection *DwarfARangesSection;
100 const MCSection *DwarfRangesSection;
95 MCSection *DwarfStrSection;
96 MCSection *DwarfLocSection;
97 MCSection *DwarfARangesSection;
98 MCSection *DwarfRangesSection;
10199 // The pubnames section is no longer generated by default. The generation
102100 // can be enabled by a compiler flag.
103 const MCSection *DwarfPubNamesSection;
101 MCSection *DwarfPubNamesSection;
104102
105103 // DWARF5 Experimental Debug Info Sections
106104 /// DwarfAccelNamesSection, DwarfAccelObjCSection,
107105 /// DwarfAccelNamespaceSection, DwarfAccelTypesSection -
108106 /// If we use the DWARF accelerated hash tables then we want to emit these
109107 /// sections.
110 const MCSection *DwarfAccelNamesSection;
111 const MCSection *DwarfAccelObjCSection;
112 const MCSection *DwarfAccelNamespaceSection;
113 const MCSection *DwarfAccelTypesSection;
108 MCSection *DwarfAccelNamesSection;
109 MCSection *DwarfAccelObjCSection;
110 MCSection *DwarfAccelNamespaceSection;
111 MCSection *DwarfAccelTypesSection;
114112
115113 /// These are used for the Fission separate debug information files.
116 const MCSection *DwarfInfoDWOSection;
117 const MCSection *DwarfTypesDWOSection;
118 const MCSection *DwarfAbbrevDWOSection;
119 const MCSection *DwarfStrDWOSection;
120 const MCSection *DwarfLineDWOSection;
121 const MCSection *DwarfLocDWOSection;
122 const MCSection *DwarfStrOffDWOSection;
123 const MCSection *DwarfAddrSection;
114 MCSection *DwarfInfoDWOSection;
115 MCSection *DwarfTypesDWOSection;
116 MCSection *DwarfAbbrevDWOSection;
117 MCSection *DwarfStrDWOSection;
118 MCSection *DwarfLineDWOSection;
119 MCSection *DwarfLocDWOSection;
120 MCSection *DwarfStrOffDWOSection;
121 MCSection *DwarfAddrSection;
124122
125123 /// Sections for newer gnu pubnames and pubtypes.
126 const MCSection *DwarfGnuPubNamesSection;
127 const MCSection *DwarfGnuPubTypesSection;
128
129 const MCSection *COFFDebugSymbolsSection;
124 MCSection *DwarfGnuPubNamesSection;
125 MCSection *DwarfGnuPubTypesSection;
126
127 MCSection *COFFDebugSymbolsSection;
130128
131129 // Extra TLS Variable Data section. If the target needs to put additional
132130 // information for a TLS variable, it'll go here.
133 const MCSection *TLSExtraDataSection;
134
135 /// TLSDataSection - Section directive for Thread Local data.
136 /// ELF, MachO and COFF.
137 const MCSection *TLSDataSection; // Defaults to ".tdata".
138
139 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
140 /// Null if this target doesn't support a BSS section.
141 /// ELF and MachO only.
142 const MCSection *TLSBSSSection; // Defaults to ".tbss".
131 MCSection *TLSExtraDataSection;
132
133 /// Section directive for Thread Local data. ELF, MachO and COFF.
134 MCSection *TLSDataSection; // Defaults to ".tdata".
135
136 /// Section directive for Thread Local uninitialized data. Null if this target
137 /// doesn't support a BSS section. ELF and MachO only.
138 MCSection *TLSBSSSection; // Defaults to ".tbss".
143139
144140 /// StackMap section.
145 const MCSection *StackMapSection;
146
147 /// EHFrameSection - EH frame section. It is initialized on demand so it
148 /// can be overwritten (with uniquing).
149 const MCSection *EHFrameSection;
141 MCSection *StackMapSection;
142
143 /// EH frame section. It is initialized on demand so it can be overwritten
144 /// (with uniquing).
145 MCSection *EHFrameSection;
150146
151147 /// ELF specific sections.
152148 ///
153 const MCSection *DataRelSection;
149 MCSection *DataRelSection;
154150 const MCSection *DataRelLocalSection;
155 const MCSection *DataRelROSection;
156 const MCSection *DataRelROLocalSection;
157 const MCSection *MergeableConst4Section;
158 const MCSection *MergeableConst8Section;
159 const MCSection *MergeableConst16Section;
151 MCSection *DataRelROSection;
152 MCSection *DataRelROLocalSection;
153 MCSection *MergeableConst4Section;
154 MCSection *MergeableConst8Section;
155 MCSection *MergeableConst16Section;
160156
161157 /// MachO specific sections.
162158 ///
163159
164 /// TLSTLVSection - Section for thread local structure information.
165 /// Contains the source code name of the variable, visibility and a pointer
166 /// to the initial value (.tdata or .tbss).
167 const MCSection *TLSTLVSection; // Defaults to ".tlv".
160 /// Section for thread local structure information. Contains the source code
161 /// name of the variable, visibility and a pointer to the initial value
162 /// (.tdata or .tbss).
163 MCSection *TLSTLVSection; // Defaults to ".tlv".
168164
169165 /// TLSThreadInitSection - Section for thread local data initialization
170166 /// functions.
171167 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
172168
173 const MCSection *CStringSection;
174 const MCSection *UStringSection;
175 const MCSection *TextCoalSection;
176 const MCSection *ConstTextCoalSection;
177 const MCSection *ConstDataSection;
178 const MCSection *DataCoalSection;
179 const MCSection *DataCommonSection;
180 const MCSection *DataBSSSection;
181 const MCSection *FourByteConstantSection;
182 const MCSection *EightByteConstantSection;
183 const MCSection *SixteenByteConstantSection;
184 const MCSection *LazySymbolPointerSection;
185 const MCSection *NonLazySymbolPointerSection;
169 MCSection *CStringSection;
170 MCSection *UStringSection;
171 MCSection *TextCoalSection;
172 MCSection *ConstTextCoalSection;
173 MCSection *ConstDataSection;
174 MCSection *DataCoalSection;
175 MCSection *DataCommonSection;
176 MCSection *DataBSSSection;
177 MCSection *FourByteConstantSection;
178 MCSection *EightByteConstantSection;
179 MCSection *SixteenByteConstantSection;
180 MCSection *LazySymbolPointerSection;
181 MCSection *NonLazySymbolPointerSection;
186182
187183 /// COFF specific sections.
188184 ///
189 const MCSection *DrectveSection;
190 const MCSection *PDataSection;
191 const MCSection *XDataSection;
185 MCSection *DrectveSection;
186 MCSection *PDataSection;
187 MCSection *XDataSection;
192188
193189 public:
194190 void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
213209 return CompactUnwindDwarfEHFrameOnly;
214210 }
215211
216 const MCSection *getTextSection() const { return TextSection; }
217 const MCSection *getDataSection() const { return DataSection; }
218 const MCSection *getBSSSection() const { return BSSSection; }
219 const MCSection *getLSDASection() const { return LSDASection; }
220 const MCSection *getCompactUnwindSection() const{
221 return CompactUnwindSection;
222 }
223 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
224 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
225 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
226 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
227 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
228 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
229 const MCSection *getDwarfGnuPubNamesSection() const {
212 MCSection *getTextSection() const { return TextSection; }
213 MCSection *getDataSection() const { return DataSection; }
214 MCSection *getBSSSection() const { return BSSSection; }
215 MCSection *getLSDASection() const { return LSDASection; }
216 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
217 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
218 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
219 MCSection *getDwarfLineSection() const { return DwarfLineSection; }
220 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
221 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
222 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
223 MCSection *getDwarfGnuPubNamesSection() const {
230224 return DwarfGnuPubNamesSection;
231225 }
232 const MCSection *getDwarfGnuPubTypesSection() const {
226 MCSection *getDwarfGnuPubTypesSection() const {
233227 return DwarfGnuPubTypesSection;
234228 }
235229 const MCSection *getDwarfDebugInlineSection() const {
236230 return DwarfDebugInlineSection;
237231 }
238 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
239 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
240 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
241 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
232 MCSection *getDwarfStrSection() const { return DwarfStrSection; }
233 MCSection *getDwarfLocSection() const { return DwarfLocSection; }
234 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
235 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
242236
243237 // DWARF5 Experimental Debug Info Sections
244 const MCSection *getDwarfAccelNamesSection() const {
238 MCSection *getDwarfAccelNamesSection() const {
245239 return DwarfAccelNamesSection;
246240 }
247 const MCSection *getDwarfAccelObjCSection() const {
248 return DwarfAccelObjCSection;
249 }
250 const MCSection *getDwarfAccelNamespaceSection() const {
241 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
242 MCSection *getDwarfAccelNamespaceSection() const {
251243 return DwarfAccelNamespaceSection;
252244 }
253 const MCSection *getDwarfAccelTypesSection() const {
245 MCSection *getDwarfAccelTypesSection() const {
254246 return DwarfAccelTypesSection;
255247 }
256 const MCSection *getDwarfInfoDWOSection() const {
257 return DwarfInfoDWOSection;
258 }
259 const MCSection *getDwarfTypesSection(uint64_t Hash) const;
260 const MCSection *getDwarfTypesDWOSection() const {
261 return DwarfTypesDWOSection;
262 }
263 const MCSection *getDwarfAbbrevDWOSection() const {
264 return DwarfAbbrevDWOSection;
265 }
266 const MCSection *getDwarfStrDWOSection() const {
267 return DwarfStrDWOSection;
268 }
269 const MCSection *getDwarfLineDWOSection() const {
270 return DwarfLineDWOSection;
271 }
272 const MCSection *getDwarfLocDWOSection() const {
273 return DwarfLocDWOSection;
274 }
275 const MCSection *getDwarfStrOffDWOSection() const {
276 return DwarfStrOffDWOSection;
277 }
278 const MCSection *getDwarfAddrSection() const {
279 return DwarfAddrSection;
280 }
281
282 const MCSection *getCOFFDebugSymbolsSection() const {
248 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
249 MCSection *getDwarfTypesSection(uint64_t Hash) const;
250 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
251 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
252 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
253 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
254 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
255 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
256 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
257
258 MCSection *getCOFFDebugSymbolsSection() const {
283259 return COFFDebugSymbolsSection;
284260 }
285261
286 const MCSection *getTLSExtraDataSection() const {
287 return TLSExtraDataSection;
288 }
262 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
289263 const MCSection *getTLSDataSection() const { return TLSDataSection; }
290 const MCSection *getTLSBSSSection() const { return TLSBSSSection; }
291
292 const MCSection *getStackMapSection() const { return StackMapSection; }
264 MCSection *getTLSBSSSection() const { return TLSBSSSection; }
265
266 MCSection *getStackMapSection() const { return StackMapSection; }
293267
294268 /// ELF specific sections.
295269 ///
296 const MCSection *getDataRelSection() const { return DataRelSection; }
270 MCSection *getDataRelSection() const { return DataRelSection; }
297271 const MCSection *getDataRelLocalSection() const {
298272 return DataRelLocalSection;
299273 }
300 const MCSection *getDataRelROSection() const { return DataRelROSection; }
301 const MCSection *getDataRelROLocalSection() const {
302 return DataRelROLocalSection;
303 }
274 MCSection *getDataRelROSection() const { return DataRelROSection; }
275 MCSection *getDataRelROLocalSection() const { return DataRelROLocalSection; }
304276 const MCSection *getMergeableConst4Section() const {
305277 return MergeableConst4Section;
306278 }
319291 }
320292 const MCSection *getCStringSection() const { return CStringSection; }
321293 const MCSection *getUStringSection() const { return UStringSection; }
322 const MCSection *getTextCoalSection() const { return TextCoalSection; }
294 MCSection *getTextCoalSection() const { return TextCoalSection; }
323295 const MCSection *getConstTextCoalSection() const {
324296 return ConstTextCoalSection;
325297 }
326298 const MCSection *getConstDataSection() const { return ConstDataSection; }
327299 const MCSection *getDataCoalSection() const { return DataCoalSection; }
328300 const MCSection *getDataCommonSection() const { return DataCommonSection; }
329 const MCSection *getDataBSSSection() const { return DataBSSSection; }
301 MCSection *getDataBSSSection() const { return DataBSSSection; }
330302 const MCSection *getFourByteConstantSection() const {
331303 return FourByteConstantSection;
332304 }
336308 const MCSection *getSixteenByteConstantSection() const {
337309 return SixteenByteConstantSection;
338310 }
339 const MCSection *getLazySymbolPointerSection() const {
311 MCSection *getLazySymbolPointerSection() const {
340312 return LazySymbolPointerSection;
341313 }
342 const MCSection *getNonLazySymbolPointerSection() const {
314 MCSection *getNonLazySymbolPointerSection() const {
343315 return NonLazySymbolPointerSection;
344316 }
345317
346318 /// COFF specific sections.
347319 ///
348 const MCSection *getDrectveSection() const { return DrectveSection; }
349 const MCSection *getPDataSection() const { return PDataSection; }
350 const MCSection *getXDataSection() const { return XDataSection; }
351
352 const MCSection *getEHFrameSection() {
320 MCSection *getDrectveSection() const { return DrectveSection; }
321 MCSection *getPDataSection() const { return PDataSection; }
322 MCSection *getXDataSection() const { return XDataSection; }
323
324 MCSection *getEHFrameSection() {
353325 if (!EHFrameSection)
354326 InitEHFrameSection();
355327 return EHFrameSection;
7979 /// fragment is not a data fragment.
8080 MCDataFragment *getOrCreateDataFragment();
8181
82 bool changeSectionImpl(const MCSection *Section, const MCExpr *Subsection);
82 bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection);
8383
8484 /// If any labels have been emitted but not assigned fragments, ensure that
8585 /// they get assigned, either to F if possible or to a new data fragment.
102102 void EmitULEB128Value(const MCExpr *Value) override;
103103 void EmitSLEB128Value(const MCExpr *Value) override;
104104 void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
105 void ChangeSection(const MCSection *Section,
106 const MCExpr *Subsection) override;
105 void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
107106 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo& STI) override;
108107
109108 /// \brief Emit an instruction to a special fragment, because this instruction
146145 bool emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
147146 unsigned Size) override;
148147
149 bool mayHaveInstructions(const MCSection &Sec) const override {
148 bool mayHaveInstructions(MCSection &Sec) const override {
150149 return Assembler->getOrCreateSectionData(Sec).hasInstructions();
151150 }
152151 };
3434 MCSection(const MCSection &) = delete;
3535 void operator=(const MCSection &) = delete;
3636
37 mutable MCSymbol *Begin;
38 mutable MCSymbol *End;
37 MCSymbol *Begin;
38 MCSymbol *End;
39 /// The alignment requirement of this section.
40 unsigned Alignment;
3941
4042 protected:
4143 MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
42 : Begin(Begin), End(nullptr), Variant(V), Kind(K) {}
44 : Begin(Begin), End(nullptr), Alignment(1), Variant(V), Kind(K) {}
4345 SectionVariant Variant;
4446 SectionKind Kind;
4547
5052
5153 SectionVariant getVariant() const { return Variant; }
5254
53 MCSymbol *getBeginSymbol() const { return Begin; }
54 void setBeginSymbol(MCSymbol *Sym) const {
55 MCSymbol *getBeginSymbol() { return Begin; }
56 const MCSymbol *getBeginSymbol() const {
57 return const_cast(this)->getBeginSymbol();
58 }
59 void setBeginSymbol(MCSymbol *Sym) {
5560 assert(!Begin);
5661 Begin = Sym;
5762 }
58 MCSymbol *getEndSymbol(MCContext &Ctx) const;
63 MCSymbol *getEndSymbol(MCContext &Ctx);
5964 bool hasEnded() const;
65
66 unsigned getAlignment() const { return Alignment; }
67 void setAlignment(unsigned Value) { Alignment = Value; }
6068
6169 virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
6270 const MCExpr *Subsection) const = 0;
4141 class formatted_raw_ostream;
4242 class AssemblerConstantPools;
4343
44 typedef std::pair<const MCSection *, const MCExpr *> MCSectionSubPair;
44 typedef std::pair<MCSection *, const MCExpr *> MCSectionSubPair;
4545
4646 /// Target specific streamer interface. This is used so that targets can
4747 /// implement support for target specific assembly directives.
312312 ///
313313 /// This is called by PopSection and SwitchSection, if the current
314314 /// section changes.
315 virtual void ChangeSection(const MCSection *, const MCExpr *);
315 virtual void ChangeSection(MCSection *, const MCExpr *);
316316
317317 /// \brief Save the current and previous section on the section stack.
318318 void PushSection() {
347347 /// is required to update CurSection.
348348 ///
349349 /// This corresponds to assembler directives like .section, .text, etc.
350 virtual void SwitchSection(const MCSection *Section,
350 virtual void SwitchSection(MCSection *Section,
351351 const MCExpr *Subsection = nullptr);
352352
353353 /// \brief Set the current section where code is being emitted to \p Section.
354354 /// This is required to update CurSection. This version does not call
355355 /// ChangeSection.
356 void SwitchSectionNoChange(const MCSection *Section,
356 void SwitchSectionNoChange(MCSection *Section,
357357 const MCExpr *Subsection = nullptr) {
358358 assert(Section && "Cannot switch to a null section!");
359359 MCSectionSubPair curSection = SectionStack.back().first;
365365 /// \brief Create the default sections and set the initial one.
366366 virtual void InitSections(bool NoExecStack);
367367
368 MCSymbol *endSection(const MCSection *Section);
368 MCSymbol *endSection(MCSection *Section);
369369
370370 /// \brief Sets the symbol's section.
371371 ///
372372 /// Each emitted symbol will be tracked in the ordering table,
373373 /// so we can sort on them later.
374 void AssignSection(MCSymbol *Symbol, const MCSection *Section);
374 void AssignSection(MCSymbol *Symbol, MCSection *Section);
375375
376376 /// \brief Emit a label for \p Symbol into the current section.
377377 ///
499499 /// \param Size - The size of the zerofill symbol.
500500 /// \param ByteAlignment - The alignment of the zerofill symbol if
501501 /// non-zero. This must be a power of 2 on some targets.
502 virtual void EmitZerofill(const MCSection *Section,
503 MCSymbol *Symbol = nullptr, uint64_t Size = 0,
504 unsigned ByteAlignment = 0) = 0;
502 virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
503 uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
505504
506505 /// \brief Emit a thread local bss (.tbss) symbol.
507506 ///
510509 /// \param Size - The size of the symbol.
511510 /// \param ByteAlignment - The alignment of the thread local common symbol
512511 /// if non-zero. This must be a power of 2 on some targets.
513 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
512 virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
514513 uint64_t Size, unsigned ByteAlignment = 0);
515514
516515 /// @}
727726 /// \brief Finish emission of machine code.
728727 void Finish();
729728
730 virtual bool mayHaveInstructions(const MCSection &Sec) const { return true; }
729 virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
731730 };
732731
733732 /// Create a dummy machine code streamer, which does nothing. This is useful for
149149 // Special sentinal value for the absolute pseudo section.
150150 //
151151 // FIXME: Use a PointerInt wrapper for this?
152 static const MCSection *AbsolutePseudoSection;
152 static MCSection *AbsolutePseudoSection;
153153
154154 /// Name - The name of the symbol. The referred-to string data is actually
155155 /// held by the StringMap that lives in MCContext.
156156 StringRef Name;
157157
158 /// Section - The section the symbol is defined in. This is null for
159 /// undefined symbols, and the special AbsolutePseudoSection value for
160 /// absolute symbols. If this is a variable symbol, this caches the
161 /// variable value's section.
162 mutable const MCSection *Section;
158 /// The section the symbol is defined in. This is null for undefined symbols,
159 /// and the special AbsolutePseudoSection value for absolute symbols. If this
160 /// is a variable symbol, this caches the variable value's section.
161 mutable MCSection *Section;
163162
164163 /// Value - If non-null, the value for a variable symbol.
165164 const MCExpr *Value;
187186
188187 MCSymbol(const MCSymbol &) = delete;
189188 void operator=(const MCSymbol &) = delete;
190 const MCSection *getSectionPtr() const {
189 MCSection *getSectionPtr() const {
191190 if (Section || !Value)
192191 return Section;
193192 return Section = Value->FindAssociatedSection();
254253 /// isAbsolute - Check if this is an absolute symbol.
255254 bool isAbsolute() const { return getSectionPtr() == AbsolutePseudoSection; }
256255
257 /// getSection - Get the section associated with a defined, non-absolute
258 /// symbol.
259 const MCSection &getSection() const {
256 /// Get the section associated with a defined, non-absolute symbol.
257 MCSection &getSection() const {
260258 assert(isInSection() && "Invalid accessor!");
261259 return *getSectionPtr();
262260 }
263261
264 /// setSection - Mark the symbol as defined in the section \p S.
265 void setSection(const MCSection &S) {
262 /// Mark the symbol as defined in the section \p S.
263 void setSection(MCSection &S) {
266264 assert(!isVariable() && "Cannot set section of variable");
267265 Section = &S;
268266 }
5656 unsigned ByteAlignment) override;
5757 void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
5858 unsigned ByteAlignment) override;
59 void EmitZerofill(const MCSection *Section, MCSymbol *Symbol, uint64_t Size,
59 void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
6060 unsigned ByteAlignment) override;
61 void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, uint64_t Size,
61 void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
6262 unsigned ByteAlignment) override;
6363 void EmitFileDirective(StringRef Filename) override;
6464 void EmitIdent(StringRef IdentString) override;
6464
6565 class UnwindEmitter {
6666 public:
67 static const MCSection *getPDataSection(const MCSymbol *Function,
68 MCContext &Context);
69 static const MCSection *getXDataSection(const MCSymbol *Function,
70 MCContext &Context);
67 static MCSection *getPDataSection(const MCSymbol *Function,
68 MCContext &Context);
69 static MCSection *getXDataSection(const MCSymbol *Function,
70 MCContext &Context);
7171
7272 virtual ~UnwindEmitter() { }
7373
7676
7777 /// Given a constant with the SectionKind, return a section that it should be
7878 /// placed in.
79 virtual const MCSection *getSectionForConstant(SectionKind Kind,
80 const Constant *C) const;
79 virtual MCSection *getSectionForConstant(SectionKind Kind,
80 const Constant *C) const;
8181
8282 /// Classify the specified global variable into a set of target independent
8383 /// categories embodied in SectionKind.
8787 /// This method computes the appropriate section to emit the specified global
8888 /// variable or function definition. This should not be passed external (or
8989 /// available externally) globals.
90 const MCSection *SectionForGlobal(const GlobalValue *GV,
91 SectionKind Kind, Mangler &Mang,
92 const TargetMachine &TM) const;
90 MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind,
91 Mangler &Mang, const TargetMachine &TM) const;
9392
9493 /// This method computes the appropriate section to emit the specified global
9594 /// variable or function definition. This should not be passed external (or
9695 /// available externally) globals.
97 const MCSection *SectionForGlobal(const GlobalValue *GV,
98 Mangler &Mang,
99 const TargetMachine &TM) const {
96 MCSection *SectionForGlobal(const GlobalValue *GV, Mangler &Mang,
97 const TargetMachine &TM) const {
10098 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
10199 }
102100
105103 bool CannotUsePrivateLabel, Mangler &Mang,
106104 const TargetMachine &TM) const;
107105
108 virtual const MCSection *
109 getSectionForJumpTable(const Function &F, Mangler &Mang,
110 const TargetMachine &TM) const;
106 virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
107 const TargetMachine &TM) const;
111108
112109 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
113110 const Function &F) const;
115112 /// Targets should implement this method to assign a section to globals with
116113 /// an explicit section specfied. The implementation of this method can
117114 /// assume that GV->hasSection() is true.
118 virtual const MCSection *
115 virtual MCSection *
119116 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
120117 Mangler &Mang, const TargetMachine &TM) const = 0;
121118
149146 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
150147 MCStreamer &Streamer) const;
151148
152 virtual const MCSection *getStaticCtorSection(unsigned Priority,
153 const MCSymbol *KeySym) const {
149 virtual MCSection *getStaticCtorSection(unsigned Priority,
150 const MCSymbol *KeySym) const {
154151 return StaticCtorSection;
155152 }
156153
157 virtual const MCSection *getStaticDtorSection(unsigned Priority,
158 const MCSymbol *KeySym) const {
154 virtual MCSection *getStaticDtorSection(unsigned Priority,
155 const MCSymbol *KeySym) const {
159156 return StaticDtorSection;
160157 }
161158
191188 }
192189
193190 protected:
194 virtual const MCSection *
195 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
196 Mangler &Mang, const TargetMachine &TM) const = 0;
191 virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
192 SectionKind Kind, Mangler &Mang,
193 const TargetMachine &TM) const = 0;
197194 };
198195
199196 } // end namespace llvm
2323 }
2424
2525 // Emit addresses into the section given.
26 void AddressPool::emit(AsmPrinter &Asm, const MCSection *AddrSection) {
26 void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
2727 if (Pool.empty())
2828 return;
2929
3939 /// label/symbol.
4040 unsigned getIndex(const MCSymbol *Sym, bool TLS = false);
4141
42 void emit(AsmPrinter &Asm, const MCSection *AddrSection);
42 void emit(AsmPrinter &Asm, MCSection *AddrSection);
4343
4444 bool isEmpty() { return Pool.empty(); }
4545
404404
405405 // Handle local BSS symbols.
406406 if (MAI->hasMachoZeroFillDirective()) {
407 const MCSection *TheSection =
408 getObjFileLowering().SectionForGlobal(GV, GVKind, *Mang, TM);
407 MCSection *TheSection =
408 getObjFileLowering().SectionForGlobal(GV, GVKind, *Mang, TM);
409409 // .zerofill __DATA, __bss, _foo, 400, 5
410410 OutStreamer->EmitZerofill(TheSection, GVSym, Size, Align);
411411 return;
433433 return;
434434 }
435435
436 const MCSection *TheSection =
437 getObjFileLowering().SectionForGlobal(GV, GVKind, *Mang, TM);
436 MCSection *TheSection =
437 getObjFileLowering().SectionForGlobal(GV, GVKind, *Mang, TM);
438438
439439 // Handle the zerofill directive on darwin, which is a special form of BSS
440440 // emission.
478478 OutStreamer->AddBlankLine();
479479
480480 // Emit the variable struct for the runtime.
481 const MCSection *TLVSect
482 = getObjFileLowering().getTLSExtraDataSection();
481 MCSection *TLVSect = getObjFileLowering().getTLSExtraDataSection();
483482
484483 OutStreamer->SwitchSection(TLVSect);
485484 // Emit the linkage here.
11211120
11221121 // Emit __morestack address if needed for indirect calls.
11231122 if (MMI->usesMorestackAddr()) {
1124 const MCSection *ReadOnlySection =
1123 MCSection *ReadOnlySection =
11251124 getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly(),
11261125 /*C=*/nullptr);
11271126 OutStreamer->SwitchSection(ReadOnlySection);
11391138 // to be executable. Some targets have a directive to declare this.
11401139 Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
11411140 if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
1142 if (const MCSection *S = MAI->getNonexecutableStackSection(OutContext))
1141 if (MCSection *S = MAI->getNonexecutableStackSection(OutContext))
11431142 OutStreamer->SwitchSection(S);
11441143
11451144 // Allow the target to emit any magic that it wants at the end of the file,
11811180 }
11821181
11831182 namespace {
1184 // SectionCPs - Keep track the alignment, constpool entries per Section.
1183 // Keep track the alignment, constpool entries per Section.
11851184 struct SectionCPs {
1186 const MCSection *S;
1185 MCSection *S;
11871186 unsigned Alignment;
11881187 SmallVector CPEs;
1189 SectionCPs(const MCSection *s, unsigned a) : S(s), Alignment(a) {}
1188 SectionCPs(MCSection *s, unsigned a) : S(s), Alignment(a) {}
11901189 };
11911190 }
11921191
12141213 if (!CPE.isMachineConstantPoolEntry())
12151214 C = CPE.Val.ConstVal;
12161215
1217 const MCSection *S = getObjFileLowering().getSectionForConstant(Kind, C);
1216 MCSection *S = getObjFileLowering().getSectionForConstant(Kind, C);
12181217
12191218 // The number of sections are small, just do a linear search from the
12201219 // last section to the first.
12931292 *F);
12941293 if (JTInDiffSection) {
12951294 // Drop it in the readonly section.
1296 const MCSection *ReadOnlySection =
1297 TLOF.getSectionForJumpTable(*F, *Mang, TM);
1295 MCSection *ReadOnlySection = TLOF.getSectionForJumpTable(*F, *Mang, TM);
12981296 OutStreamer->SwitchSection(ReadOnlySection);
12991297 }
13001298
15381536
15391537 KeySym = getSymbol(GV);
15401538 }
1541 const MCSection *OutputSection =
1539 MCSection *OutputSection =
15421540 (isCtor ? Obj.getStaticCtorSection(S.Priority, KeySym)
15431541 : Obj.getStaticDtorSection(S.Priority, KeySym));
15441542 OutStreamer->SwitchSection(OutputSection);
12841284 Holder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection());
12851285 }
12861286
1287 void DwarfDebug::emitAccel(DwarfAccelTable &Accel, const MCSection *Section,
1287 void DwarfDebug::emitAccel(DwarfAccelTable &Accel, MCSection *Section,
12881288 StringRef TableName) {
12891289 Accel.FinalizeTable(Asm, TableName);
12901290 Asm->OutStreamer->SwitchSection(Section);
13781378 /// emitDebugPubNames - Emit visible names into a debug pubnames section.
13791379 ///
13801380 void DwarfDebug::emitDebugPubNames(bool GnuStyle) {
1381 const MCSection *PSec =
1382 GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
1383 : Asm->getObjFileLowering().getDwarfPubNamesSection();
1381 MCSection *PSec = GnuStyle
1382 ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
1383 : Asm->getObjFileLowering().getDwarfPubNamesSection();
13841384
13851385 emitDebugPubSection(GnuStyle, PSec, "Names",
13861386 &DwarfCompileUnit::getGlobalNames);
13871387 }
13881388
13891389 void DwarfDebug::emitDebugPubSection(
1390 bool GnuStyle, const MCSection *PSec, StringRef Name,
1390 bool GnuStyle, MCSection *PSec, StringRef Name,
13911391 const StringMap &(DwarfCompileUnit::*Accessor)() const) {
13921392 for (const auto &NU : CUMap) {
13931393 DwarfCompileUnit *TheU = NU.second;
14471447 }
14481448
14491449 void DwarfDebug::emitDebugPubTypes(bool GnuStyle) {
1450 const MCSection *PSec =
1451 GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
1452 : Asm->getObjFileLowering().getDwarfPubTypesSection();
1450 MCSection *PSec = GnuStyle
1451 ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
1452 : Asm->getObjFileLowering().getDwarfPubTypesSection();
14531453
14541454 emitDebugPubSection(GnuStyle, PSec, "Types",
14551455 &DwarfCompileUnit::getGlobalTypes);
16101610 // address we can tie back to a CU.
16111611 void DwarfDebug::emitDebugARanges() {
16121612 // Provides a unique id per text section.
1613 MapVector<const MCSection *, SmallVector> SectionMap;
1613 MapVector<MCSection *, SmallVector> SectionMap;
16141614
16151615 // Filter labels by section.
16161616 for (const SymbolCU &SCU : ArangeLabels) {
16171617 if (SCU.Sym->isInSection()) {
16181618 // Make a note of this symbol and it's section.
1619 const MCSection *Section = &SCU.Sym->getSection();
1619 MCSection *Section = &SCU.Sym->getSection();
16201620 if (!Section->getKind().isMetadata())
16211621 SectionMap[Section].push_back(SCU);
16221622 } else {
16291629
16301630 // Add terminating symbols for each section.
16311631 for (const auto &I : SectionMap) {
1632 const MCSection *Section = I.first;
1632 MCSection *Section = I.first;
16331633 MCSymbol *Sym = nullptr;
16341634
16351635 if (Section)
18721872 // sections.
18731873 void DwarfDebug::emitDebugStrDWO() {
18741874 assert(useSplitDwarf() && "No split dwarf?");
1875 const MCSection *OffSec =
1876 Asm->getObjFileLowering().getDwarfStrOffDWOSection();
1875 MCSection *OffSec = Asm->getObjFileLowering().getDwarfStrOffDWOSection();
18771876 InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(),
18781877 OffSec);
18791878 }
370370 void emitAbbreviations();
371371
372372 /// \brief Emit a specified accelerator table.
373 void emitAccel(DwarfAccelTable &Accel, const MCSection *Section,
373 void emitAccel(DwarfAccelTable &Accel, MCSection *Section,
374374 StringRef TableName);
375375
376376 /// \brief Emit visible names into a hashed accelerator table section.
399399 void emitDebugPubTypes(bool GnuStyle = false);
400400
401401 void emitDebugPubSection(
402 bool GnuStyle, const MCSection *PSec, StringRef Name,
402 bool GnuStyle, MCSection *PSec, StringRef Name,
403403 const StringMap &(DwarfCompileUnit::*Accessor)() const);
404404
405405 /// \brief Emit visible names into a debug str section.
4949 void DwarfFile::emitUnits(bool UseOffsets) {
5050 for (const auto &TheU : CUs) {
5151 DIE &Die = TheU->getUnitDie();
52 const MCSection *USection = TheU->getSection();
52 MCSection *USection = TheU->getSection();
5353 Asm->OutStreamer->SwitchSection(USection);
5454
5555 TheU->emitHeader(UseOffsets);
119119 return Offset;
120120 }
121121
122 void DwarfFile::emitAbbrevs(const MCSection *Section) {
122 void DwarfFile::emitAbbrevs(MCSection *Section) {
123123 // Check to see if it is worth the effort.
124124 if (!Abbreviations.empty()) {
125125 // Start the debug abbrev section.
129129 }
130130
131131 // Emit strings into a string section.
132 void DwarfFile::emitStrings(const MCSection *StrSection,
133 const MCSection *OffsetSection) {
132 void DwarfFile::emitStrings(MCSection *StrSection, MCSection *OffsetSection) {
134133 StrPool.emit(*Asm, StrSection, OffsetSection);
135134 }
136135
8181 void emitUnits(bool UseOffsets);
8282
8383 /// \brief Emit a set of abbreviations to the specific section.
84 void emitAbbrevs(const MCSection *);
84 void emitAbbrevs(MCSection *);
8585
8686 /// \brief Emit all of the strings to the section given.
87 void emitStrings(const MCSection *StrSection,
88 const MCSection *OffsetSection = nullptr);
87 void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr);
8988
9089 /// \brief Returns the string pool.
9190 DwarfStringPool &getStringPool() { return StrPool; }
3131 return getEntry(Asm, Pool, Prefix, Str).second;
3232 }
3333
34 void DwarfStringPool::emit(AsmPrinter &Asm, const MCSection *StrSection,
35 const MCSection *OffsetSection) {
34 void DwarfStringPool::emit(AsmPrinter &Asm, MCSection *StrSection,
35 MCSection *OffsetSection) {
3636 if (Pool.empty())
3737 return;
3838
3131 DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix)
3232 : Pool(A), Prefix(Prefix) {}
3333
34 void emit(AsmPrinter &Asm, const MCSection *StrSection,
35 const MCSection *OffsetSection = nullptr);
34 void emit(AsmPrinter &Asm, MCSection *StrSection,
35 MCSection *OffsetSection = nullptr);
3636
3737 /// \brief Returns an entry into the string pool with the given
3838 /// string text.
15121512 Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
15131513 }
15141514
1515 void DwarfUnit::initSection(const MCSection *Section) {
1515 void DwarfUnit::initSection(MCSection *Section) {
15161516 assert(!this->Section);
15171517 this->Section = Section;
15181518 }
114114 DIEInteger *DIEIntegerOne;
115115
116116 /// The section this unit will be emitted in.
117 const MCSection *Section;
117 MCSection *Section;
118118
119119 DwarfUnit(unsigned UID, dwarf::Tag, const DICompileUnit *CU, AsmPrinter *A,
120120 DwarfDebug *DW, DwarfFile *DWU);
131131 public:
132132 virtual ~DwarfUnit();
133133
134 void initSection(const MCSection *Section);
135
136 const MCSection *getSection() const {
134 void initSection(MCSection *Section);
135
136 MCSection *getSection() const {
137137 assert(Section);
138138 return Section;
139139 }
387387 }
388388
389389 // Type infos.
390 const MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection();
390 MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection();
391391 unsigned TTypeEncoding;
392392 unsigned TypeFormatSize;
393393
523523 MCStreamer &OS = *AP.OutStreamer;
524524
525525 // Create the section.
526 const MCSection *StackMapSection =
527 OutContext.getObjectFileInfo()->getStackMapSection();
526 MCSection *StackMapSection =
527 OutContext.getObjectFileInfo()->getStackMapSection();
528528 OS.SwitchSection(StackMapSection);
529529
530530 // Emit a dummy symbol to force section inclusion.
6868 StringRef Prefix = ".data.";
6969 NameData.insert(NameData.begin(), Prefix.begin(), Prefix.end());
7070 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_GROUP;
71 const MCSection *Sec = getContext().getELFSection(NameData,
72 ELF::SHT_PROGBITS,
73 Flags,
74 0, Label->getName());
71 MCSection *Sec = getContext().getELFSection(NameData, ELF::SHT_PROGBITS,
72 Flags, 0, Label->getName());
7573 unsigned Size = TM.getDataLayout()->getPointerSize();
7674 Streamer.SwitchSection(Sec);
7775 Streamer.EmitValueToAlignment(TM.getDataLayout()->getPointerABIAlignment());
200198 return C;
201199 }
202200
203 const MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
201 MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
204202 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
205203 const TargetMachine &TM) const {
206204 StringRef SectionName = GV->getSection();
244242 return ".data.rel.ro";
245243 }
246244
247 static const MCSectionELF *
245 static MCSectionELF *
248246 selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV,
249247 SectionKind Kind, Mangler &Mang,
250248 const TargetMachine &TM, bool EmitUniqueSection,
307305 EntrySize, Group, UniqueID);
308306 }
309307
310 const MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
308 MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
311309 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
312310 const TargetMachine &TM) const {
313311 unsigned Flags = getELFSectionFlags(Kind);
327325 EmitUniqueSection, Flags, &NextUniqueID);
328326 }
329327
330 const MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
328 MCSection *TargetLoweringObjectFileELF::getSectionForJumpTable(
331329 const Function &F, Mangler &Mang, const TargetMachine &TM) const {
332330 // If the function can be removed, produce a unique section so that
333331 // the table doesn't prevent the removal.
348346 return false;
349347 }
350348
351 /// getSectionForConstant - Given a mergeable constant with the
352 /// specified size and relocation information, return a section that it
353 /// should be placed in.
354 const MCSection *
349 /// Given a mergeable constant with the specified size and relocation
350 /// information, return a section that it should be placed in.
351 MCSection *
355352 TargetLoweringObjectFileELF::getSectionForConstant(SectionKind Kind,
356353 const Constant *C) const {
357354 if (Kind.isMergeableConst4() && MergeableConst4Section)
368365 return DataRelROSection;
369366 }
370367
371 static const MCSectionELF *getStaticStructorSection(MCContext &Ctx,
372 bool UseInitArray,
373 bool IsCtor,
374 unsigned Priority,
375 const MCSymbol *KeySym) {
368 static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
369 bool IsCtor, unsigned Priority,
370 const MCSymbol *KeySym) {
376371 std::string Name;
377372 unsigned Type;
378373 unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
410405 return Ctx.getELFSection(Name, Type, Flags, 0, COMDAT);
411406 }
412407
413 const MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
408 MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
414409 unsigned Priority, const MCSymbol *KeySym) const {
415410 return getStaticStructorSection(getContext(), UseInitArray, true, Priority,
416411 KeySym);
417412 }
418413
419 const MCSection *TargetLoweringObjectFileELF::getStaticDtorSection(
414 MCSection *TargetLoweringObjectFileELF::getStaticDtorSection(
420415 unsigned Priority, const MCSymbol *KeySym) const {
421416 return getStaticStructorSection(getContext(), UseInitArray, false, Priority,
422417 KeySym);
519514 ErrorCode + ".");
520515
521516 // Get the section.
522 const MCSectionMachO *S =
523 getContext().getMachOSection(Segment, Section, TAA, StubSize,
524 SectionKind::getDataNoRel());
517 MCSectionMachO *S = getContext().getMachOSection(
518 Segment, Section, TAA, StubSize, SectionKind::getDataNoRel());
525519 Streamer.SwitchSection(S);
526520 Streamer.EmitLabel(getContext().
527521 getOrCreateSymbol(StringRef("L_OBJC_IMAGE_INFO")));
539533 "' cannot be lowered.");
540534 }
541535
542 const MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
536 MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
543537 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
544538 const TargetMachine &TM) const {
545539 // Parse the section specifier and create it if valid.
560554 }
561555
562556 // Get the section.
563 const MCSectionMachO *S =
564 getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
557 MCSectionMachO *S =
558 getContext().getMachOSection(Segment, Section, TAA, StubSize, Kind);
565559
566560 // If TAA wasn't set by ParseSectionSpecifier() above,
567561 // use the value returned by getMachOSection() as a default.
581575 return S;
582576 }
583577
584 const MCSection *TargetLoweringObjectFileMachO::
585 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
586 Mangler &Mang, const TargetMachine &TM) const {
578 MCSection *TargetLoweringObjectFileMachO::SelectSectionForGlobal(
579 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
580 const TargetMachine &TM) const {
587581 checkMachOComdat(GV);
588582
589583 // Handle thread local data.
648642 return DataSection;
649643 }
650644
651 const MCSection *
645 MCSection *
652646 TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind,
653647 const Constant *C) const {
654648 // If this constant requires a relocation, we have to put it in the data
860854 return 0;
861855 }
862856
863 const MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
857 MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
864858 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
865859 const TargetMachine &TM) const {
866860 int Selection = 0;
902896 return ".data";
903897 }
904898
905
906 const MCSection *TargetLoweringObjectFileCOFF::
907 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
908 Mangler &Mang, const TargetMachine &TM) const {
899 MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
900 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
901 const TargetMachine &TM) const {
909902 // If we have -ffunction-sections then we should emit the global value to a
910903 // uniqued section specifically for it.
911904 bool EmitUniquedSection;
970963 Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
971964 }
972965
973 const MCSection *TargetLoweringObjectFileCOFF::getSectionForJumpTable(
966 MCSection *TargetLoweringObjectFileCOFF::getSectionForJumpTable(
974967 const Function &F, Mangler &Mang, const TargetMachine &TM) const {
975968 // If the function can be removed, produce a unique section so that
976969 // the table doesn't prevent the removal.
10251018
10261019 // Emit the linker options to the linker .drectve section. According to the
10271020 // spec, this section is a space-separated string containing flags for linker.
1028 const MCSection *Sec = getDrectveSection();
1021 MCSection *Sec = getDrectveSection();
10291022 Streamer.SwitchSection(Sec);
10301023 for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
10311024 MDNode *MDOptions = cast(LinkerOptions->getOperand(i));
10391032 }
10401033 }
10411034
1042 const MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection(
1035 MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection(
10431036 unsigned Priority, const MCSymbol *KeySym) const {
10441037 return getContext().getAssociativeCOFFSection(
10451038 cast(StaticCtorSection), KeySym);
10461039 }
10471040
1048 const MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection(
1041 MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection(
10491042 unsigned Priority, const MCSymbol *KeySym) const {
10501043 return getContext().getAssociativeCOFFSection(
10511044 cast(StaticDtorSection), KeySym);
4747 //
4848 // AssemblerConstantPools implementation
4949 //
50 ConstantPool *
51 AssemblerConstantPools::getConstantPool(const MCSection *Section) {
50 ConstantPool *AssemblerConstantPools::getConstantPool(MCSection *Section) {
5251 ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
5352 if (CP == ConstantPools.end())
5453 return nullptr;
5756 }
5857
5958 ConstantPool &
60 AssemblerConstantPools::getOrCreateConstantPool(const MCSection *Section) {
59 AssemblerConstantPools::getOrCreateConstantPool(MCSection *Section) {
6160 return ConstantPools[Section];
6261 }
6362
64 static void emitConstantPool(MCStreamer &Streamer, const MCSection *Section,
63 static void emitConstantPool(MCStreamer &Streamer, MCSection *Section,
6564 ConstantPool &CP) {
6665 if (!CP.empty()) {
6766 Streamer.SwitchSection(Section);
7473 for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
7574 CPE = ConstantPools.end();
7675 CPI != CPE; ++CPI) {
77 const MCSection *Section = CPI->first;
76 MCSection *Section = CPI->first;
7877 ConstantPool &CP = CPI->second;
7978
8079 emitConstantPool(Streamer, Section, CP);
8281 }
8382
8483 void AssemblerConstantPools::emitForCurrentSection(MCStreamer &Streamer) {
85 const MCSection *Section = Streamer.getCurrentSection().first;
84 MCSection *Section = Streamer.getCurrentSection().first;
8685 if (ConstantPool *CP = getConstantPool(Section)) {
8786 emitConstantPool(Streamer, Section, *CP);
8887 }
9190 const MCExpr *AssemblerConstantPools::addEntry(MCStreamer &Streamer,
9291 const MCExpr *Expr,
9392 unsigned Size) {
94 const MCSection *Section = Streamer.getCurrentSection().first;
93 MCSection *Section = Streamer.getCurrentSection().first;
9594 return getOrCreateConstantPool(Section).addEntry(Expr, Streamer.getContext(),
9695 Size);
9796 }
132132 unsigned ShstrtabIndex;
133133
134134 // Sections in the order they are to be output in the section table.
135 std::vector SectionTable;
136 unsigned addToSectionTable(const MCSectionELF *Sec);
135 std::vector SectionTable;
136 unsigned addToSectionTable(MCSectionELF *Sec);
137137
138138 // TargetObjectWriter wrappers.
139139 bool is64Bit() const { return TargetObjectWriter->is64Bit(); }
220220 const SectionIndexMapTy &SectionIndexMap,
221221 const RevGroupMapTy &RevGroupMap);
222222
223 const MCSectionELF *createRelocationSection(MCAssembler &Asm,
224 const MCSectionELF &Sec);
223 MCSectionELF *createRelocationSection(MCAssembler &Asm,
224 const MCSectionELF &Sec);
225225
226226 const MCSectionELF *createSectionHeaderStringTable();
227227 const MCSectionELF *createStringTable(MCContext &Ctx);
260260 };
261261 }
262262
263 unsigned ELFObjectWriter::addToSectionTable(const MCSectionELF *Sec) {
263 unsigned ELFObjectWriter::addToSectionTable(MCSectionELF *Sec) {
264264 SectionTable.push_back(Sec);
265265 ShStrTabBuilder.add(Sec->getSectionName());
266266 return SectionTable.size();
548548 unsigned EntrySize = is64Bit() ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
549549
550550 // Symbol table
551 const MCSectionELF *SymtabSection =
551 MCSectionELF *SymtabSection =
552552 Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0, EntrySize, "");
553553 MCSectionData &SymtabSD = Asm.getOrCreateSectionData(*SymtabSection);
554554 SymtabSD.setAlignment(is64Bit() ? 8 : 4);
607607 return;
608608
609609 SecStart = OS.tell();
610 const MCSectionELF *SymtabShndxSection =
610 MCSectionELF *SymtabShndxSection =
611611 Ctx.getELFSection(".symtab_shndxr", ELF::SHT_SYMTAB_SHNDX, 0, 4, "");
612612 addToSectionTable(SymtabShndxSection);
613613 MCSectionData *SymtabShndxSD =
10631063 UndefinedSymbolData[i].Symbol->getData().setIndex(Index++);
10641064 }
10651065
1066 const MCSectionELF *
1066 MCSectionELF *
10671067 ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
10681068 const MCSectionELF &Sec) {
10691069 if (Relocations[&Sec].empty())
10841084 if (Sec.getFlags() & ELF::SHF_GROUP)
10851085 Flags = ELF::SHF_GROUP;
10861086
1087 const MCSectionELF *RelaSection = Ctx.createELFRelSection(
1087 MCSectionELF *RelaSection = Ctx.createELFRelSection(
10881088 RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
10891089 Flags, EntrySize, Sec.getGroup(), &Sec);
10901090 MCSectionData &RelSD = Asm.getOrCreateSectionData(*RelaSection);
11401140 void ELFObjectWriter::writeSectionData(const MCAssembler &Asm,
11411141 const MCSectionData &SD,
11421142 const MCAsmLayout &Layout) {
1143 const MCSectionELF &Section =
1144 static_castMCSectionELF &>(SD.getSection());
1143 MCSectionELF &Section = static_cast<MCSectionELF &>(SD.getSection());
11451144 StringRef SectionName = Section.getSectionName();
11461145
11471146 // Compressing debug_frame requires handling alignment fragments which is
12441243 }
12451244
12461245 const MCSectionELF *ELFObjectWriter::createStringTable(MCContext &Ctx) {
1247 const MCSectionELF *StrtabSection =
1246 MCSectionELF *StrtabSection =
12481247 Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0);
12491248 StringTableIndex = addToSectionTable(StrtabSection);
12501249 OS << StrTabBuilder.data();
13141313 (NumSections + 1) >= ELF::SHN_LORESERVE ? NumSections + 1 : 0;
13151314 WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, 0, 0);
13161315
1317 for (const MCSectionELF *Section : SectionTable) {
1316 for (MCSectionELF *Section : SectionTable) {
13181317 const MCSectionData &SD = Asm.getOrCreateSectionData(*Section);
13191318 uint32_t GroupSymbolIndex;
13201319 unsigned Type = Section->getType();
13361335 void ELFObjectWriter::WriteObject(MCAssembler &Asm,
13371336 const MCAsmLayout &Layout) {
13381337 MCContext &Ctx = Asm.getContext();
1339 const MCSectionELF *ShstrtabSection =
1338 MCSectionELF *ShstrtabSection =
13401339 Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0);
13411340 ShstrtabIndex = addToSectionTable(ShstrtabSection);
13421341
13521351 SectionOffsetsTy SectionOffsets;
13531352 bool ComputedSymtab = false;
13541353 for (const MCSectionData &SD : Asm) {
1355 const MCSectionELF &Section =
1356 static_castMCSectionELF &>(SD.getSection());
1354 MCSectionELF &Section = static_cast<MCSectionELF &>(SD.getSection());
13571355
13581356 uint64_t Padding = OffsetToAlignment(OS.tell(), SD.getAlignment());
13591357 WriteZeros(Padding);
13871385 if (Type == ELF::SHT_GROUP || Type == ELF::SHT_REL || Type == ELF::SHT_RELA)
13881386 continue;
13891387
1390 const MCSectionELF *RelSection = createRelocationSection(Asm, Section);
1388 MCSectionELF *RelSection = createRelocationSection(Asm, Section);
13911389
13921390 if (SignatureSymbol) {
13931391 Asm.getOrCreateSymbolData(*SignatureSymbol);
13941392 unsigned &GroupIdx = RevGroupMap[SignatureSymbol];
13951393 if (!GroupIdx) {
1396 const MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol);
1394 MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol);
13971395 GroupIdx = addToSectionTable(Group);
13981396 MCSectionData *GroupD = &Asm.getOrCreateSectionData(*Group);
13991397 GroupD->setAlignment(4);
1919
2020 void MCAsmInfoELF::anchor() { }
2121
22 const MCSection *
23 MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const {
22 MCSection *MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const {
2423 return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS, 0);
2524 }
2625
113113 /// @name MCStreamer Interface
114114 /// @{
115115
116 void ChangeSection(const MCSection *Section,
117 const MCExpr *Subsection) override;
116 void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
118117
119118 void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override;
120119 void EmitLabel(MCSymbol *Symbol) override;
149148 void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
150149 unsigned ByteAlignment) override;
151150
152 void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = nullptr,
151 void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
153152 uint64_t Size = 0, unsigned ByteAlignment = 0) override;
154153
155 void EmitTBSSSymbol (const MCSection *Section, MCSymbol *Symbol,
156 uint64_t Size, unsigned ByteAlignment = 0) override;
154 void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
155 unsigned ByteAlignment = 0) override;
157156
158157 void EmitBytes(StringRef Data) override;
159158
296295 EmitEOL();
297296 }
298297
299 void MCAsmStreamer::ChangeSection(const MCSection *Section,
298 void MCAsmStreamer::ChangeSection(MCSection *Section,
300299 const MCExpr *Subsection) {
301300 assert(Section && "Cannot switch to a null section!");
302301 Section->PrintSwitchToSection(*MAI, OS, Subsection);
541540 EmitEOL();
542541 }
543542
544 void MCAsmStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
543 void MCAsmStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
545544 uint64_t Size, unsigned ByteAlignment) {
546545 if (Symbol)
547546 AssignSection(Symbol, Section);
564563 // .tbss sym, size, align
565564 // This depends that the symbol has already been mangled from the original,
566565 // e.g. _a.
567 void MCAsmStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
566 void MCAsmStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
568567 uint64_t Size, unsigned ByteAlignment) {
569568 AssignSection(Symbol, Section);
570569
11011100 // We only do this so the section switch that terminates the handler
11021101 // data block is visible.
11031102 WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
1104 if (const MCSection *XData = WinEH::UnwindEmitter::getXDataSection(
1103 if (MCSection *XData = WinEH::UnwindEmitter::getXDataSection(
11051104 CurFrame->Function, getContext()))
11061105 SwitchSectionNoChange(XData);
11071106
291291
292292 MCSectionData::MCSectionData() : Section(nullptr) {}
293293
294 MCSectionData::MCSectionData(const MCSection &Section, MCAssembler *A)
295 : Section(&Section), Ordinal(~UINT32_C(0)), Alignment(1),
294 MCSectionData::MCSectionData(MCSection &Section, MCAssembler *A)
295 : Section(&Section), Ordinal(~UINT32_C(0)),
296296 BundleLockState(NotBundleLocked), BundleLockNestingDepth(0),
297297 BundleGroupBeforeFirstInst(false), HasInstructions(false) {
298298 if (A)
299299 A->getSectionList().push_back(this);
300 }
301
302 unsigned MCSectionData::getAlignment() const { return Section->getAlignment(); }
303
304 void MCSectionData::setAlignment(unsigned Value) {
305 Section->setAlignment(Value);
300306 }
301307
302308 MCSectionData::iterator
240240 // Section Management
241241 //===----------------------------------------------------------------------===//
242242
243 const MCSectionMachO *
244 MCContext::getMachOSection(StringRef Segment, StringRef Section,
245 unsigned TypeAndAttributes, unsigned Reserved2,
246 SectionKind Kind, const char *BeginSymName) {
243 MCSectionMachO *MCContext::getMachOSection(StringRef Segment, StringRef Section,
244 unsigned TypeAndAttributes,
245 unsigned Reserved2, SectionKind Kind,
246 const char *BeginSymName) {
247247
248248 // We unique sections by their segment/section pair. The returned section
249249 // may not have the same flags as the requested section, if so this should be
256256 Name += Section;
257257
258258 // Do the lookup, if we have a hit, return it.
259 const MCSectionMachO *&Entry = MachOUniquingMap[Name];
259 MCSectionMachO *&Entry = MachOUniquingMap[Name];
260260 if (Entry)
261261 return Entry;
262262
269269 Reserved2, Kind, Begin);
270270 }
271271
272 void MCContext::renameELFSection(const MCSectionELF *Section, StringRef Name) {
272 void MCContext::renameELFSection(MCSectionELF *Section, StringRef Name) {
273273 StringRef GroupName;
274274 if (const MCSymbol *Group = Section->getGroup())
275275 GroupName = Group->getName();
285285 const_cast(Section)->setSectionName(CachedName);
286286 }
287287
288 const MCSectionELF *
289 MCContext::createELFRelSection(StringRef Name, unsigned Type, unsigned Flags,
290 unsigned EntrySize, const MCSymbol *Group,
291 const MCSectionELF *Associated) {
288 MCSectionELF *MCContext::createELFRelSection(StringRef Name, unsigned Type,
289 unsigned Flags, unsigned EntrySize,
290 const MCSymbol *Group,
291 const MCSectionELF *Associated) {
292292 StringMap::iterator I;
293293 bool Inserted;
294294 std::tie(I, Inserted) = ELFRelSecNames.insert(std::make_pair(Name, true));
298298 EntrySize, Group, true, nullptr, Associated);
299299 }
300300
301 const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
302 unsigned Flags, unsigned EntrySize,
303 StringRef Group, unsigned UniqueID,
304 const char *BeginSymName) {
301 MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
302 unsigned Flags, unsigned EntrySize,
303 StringRef Group, unsigned UniqueID,
304 const char *BeginSymName) {
305305 MCSymbol *GroupSym = nullptr;
306306 if (!Group.empty())
307307 GroupSym = getOrCreateSymbol(Group);
310310 BeginSymName, nullptr);
311311 }
312312
313 const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
314 unsigned Flags, unsigned EntrySize,
315 const MCSymbol *GroupSym,
316 unsigned UniqueID,
317 const char *BeginSymName,
318 const MCSectionELF *Associated) {
313 MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
314 unsigned Flags, unsigned EntrySize,
315 const MCSymbol *GroupSym,
316 unsigned UniqueID,
317 const char *BeginSymName,
318 const MCSectionELF *Associated) {
319319 StringRef Group = "";
320320 if (GroupSym)
321321 Group = GroupSym->getName();
345345 return Result;
346346 }
347347
348 const MCSectionELF *MCContext::createELFGroupSection(const MCSymbol *Group) {
348 MCSectionELF *MCContext::createELFGroupSection(const MCSymbol *Group) {
349349 MCSectionELF *Result = new (*this)
350350 MCSectionELF(".group", ELF::SHT_GROUP, 0, SectionKind::getReadOnly(), 4,
351351 Group, ~0, nullptr, nullptr);
352352 return Result;
353353 }
354354
355 const MCSectionCOFF *
356 MCContext::getCOFFSection(StringRef Section, unsigned Characteristics,
357 SectionKind Kind, StringRef COMDATSymName,
358 int Selection, const char *BeginSymName) {
355 MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
356 unsigned Characteristics,
357 SectionKind Kind,
358 StringRef COMDATSymName, int Selection,
359 const char *BeginSymName) {
359360 MCSymbol *COMDATSymbol = nullptr;
360361 if (!COMDATSymName.empty()) {
361362 COMDATSymbol = getOrCreateSymbol(COMDATSymName);
381382 return Result;
382383 }
383384
384 const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
385 unsigned Characteristics,
386 SectionKind Kind,
387 const char *BeginSymName) {
385 MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
386 unsigned Characteristics,
387 SectionKind Kind,
388 const char *BeginSymName) {
388389 return getCOFFSection(Section, Characteristics, Kind, "", 0, BeginSymName);
389390 }
390391
391 const MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
392 MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
392393 COFFSectionKey T{Section, "", 0};
393394 auto Iter = COFFUniquingMap.find(T);
394395 if (Iter == COFFUniquingMap.end())
396397 return Iter->second;
397398 }
398399
399 const MCSectionCOFF *
400 MCContext::getAssociativeCOFFSection(const MCSectionCOFF *Sec,
401 const MCSymbol *KeySym) {
400 MCSectionCOFF *MCContext::getAssociativeCOFFSection(MCSectionCOFF *Sec,
401 const MCSymbol *KeySym) {
402402 // Return the normal section if we don't have to be associative.
403403 if (!KeySym)
404404 return Sec;
439439 /// Remove empty sections from SectionStartEndSyms, to avoid generating
440440 /// useless debug info for them.
441441 void MCContext::finalizeDwarfSections(MCStreamer &MCOS) {
442 std::vector Keep;
443 for (const MCSection *Sec : SectionsForRanges) {
442 std::vector Keep;
443 for (MCSection *Sec : SectionsForRanges) {
444444 if (MCOS.mayHaveInstructions(*Sec))
445445 Keep.push_back(Sec);
446446 }
6363 // and if there is information from the last .loc directive that has yet to have
6464 // a line entry made for it is made.
6565 //
66 void MCLineEntry::Make(MCObjectStreamer *MCOS, const MCSection *Section) {
66 void MCLineEntry::Make(MCObjectStreamer *MCOS, MCSection *Section) {
6767 if (!MCOS->getContext().getDwarfLocSeen())
6868 return;
6969
114114 // in the LineSection.
115115 //
116116 static inline void
117 EmitDwarfLineTable(MCObjectStreamer *MCOS, const MCSection *Section,
117 EmitDwarfLineTable(MCObjectStreamer *MCOS, MCSection *Section,
118118 const MCLineSection::MCLineEntryCollection &LineEntries) {
119119 unsigned FileNum = 1;
120120 unsigned LastLine = 1;
609609
610610 // Now emit the table of pairs of PointerSize'ed values for the section
611611 // addresses and sizes.
612 for (const MCSection *Sec : Sections) {
613 MCSymbol *StartSymbol = Sec->getBeginSymbol();
612 for (MCSection *Sec : Sections) {
613 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
614614 MCSymbol *EndSymbol = Sec->getEndSymbol(context);
615615 assert(StartSymbol && "StartSymbol must not be NULL");
616616 assert(EndSymbol && "EndSymbol must not be NULL");
804804
805805 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfRangesSection());
806806
807 for (const MCSection *Sec : Sections) {
808 MCSymbol *StartSymbol = Sec->getBeginSymbol();
807 for (MCSection *Sec : Sections) {
808 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
809809 MCSymbol *EndSymbol = Sec->getEndSymbol(context);
810810 assert(StartSymbol && "StartSymbol must not be NULL");
811811 assert(EndSymbol && "EndSymbol must not be NULL");
15191519
15201520 if (!NeedsEHFrameSection) return;
15211521
1522 const MCSection &Section =
1523 IsEH ? *const_cast(MOFI)->getEHFrameSection() :
1524 *MOFI->getDwarfFrameSection();
1522 MCSection &Section =
1523 IsEH ? *const_cast(MOFI)->getEHFrameSection()
1524 : *MOFI->getDwarfFrameSection();
15251525
15261526 Streamer.SwitchSection(&Section);
15271527 MCSymbol *SectionStart = Context.createTempSymbol();
140140 Section->setAlignment(Assembler.getBundleAlignSize());
141141 }
142142
143 void MCELFStreamer::ChangeSection(const MCSection *Section,
143 void MCELFStreamer::ChangeSection(MCSection *Section,
144144 const MCExpr *Subsection) {
145145 MCSectionData *CurSection = getCurrentSectionData();
146146 if (CurSection && CurSection->isBundleLocked())
313313 MCELF::SetType(SD, ELF::STT_OBJECT);
314314
315315 if (MCELF::GetBinding(SD) == ELF_STB_Local) {
316 const MCSection *Section = getAssembler().getContext().getELFSection(
316 MCSection *Section = getAssembler().getContext().getELFSection(
317317 ".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
318318
319319 AssignSection(Symbol, Section);
368368 }
369369
370370 void MCELFStreamer::EmitIdent(StringRef IdentString) {
371 const MCSection *Comment = getAssembler().getContext().getELFSection(
371 MCSection *Comment = getAssembler().getContext().getELFSection(
372372 ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
373373 PushSection();
374374 SwitchSection(Comment);
632632 const MCSymbol &Symbol = *i->Symbol;
633633 uint64_t Size = i->Size;
634634 unsigned ByteAlignment = i->ByteAlignment;
635 const MCSection &Section = Symbol.getSection();
635 MCSection &Section = Symbol.getSection();
636636
637637 MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section);
638638 new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData);
692692 llvm_unreachable("ELF doesn't support this directive");
693693 }
694694
695 void MCELFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
695 void MCELFStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
696696 uint64_t Size, unsigned ByteAlignment) {
697697 llvm_unreachable("ELF doesn't support this directive");
698698 }
699699
700 void MCELFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
700 void MCELFStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
701701 uint64_t Size, unsigned ByteAlignment) {
702702 llvm_unreachable("ELF doesn't support this directive");
703703 }
754754 llvm_unreachable("Invalid assembly expression kind!");
755755 }
756756
757 const MCSection *MCExpr::FindAssociatedSection() const {
757 MCSection *MCExpr::FindAssociatedSection() const {
758758 switch (getKind()) {
759759 case Target:
760760 // We never look through target specific expressions.
778778
779779 case Binary: {
780780 const MCBinaryExpr *BE = cast(this);
781 const MCSection *LHS_S = BE->getLHS()->FindAssociatedSection();
782 const MCSection *RHS_S = BE->getRHS()->FindAssociatedSection();
781 MCSection *LHS_S = BE->getLHS()->FindAssociatedSection();
782 MCSection *RHS_S = BE->getRHS()->FindAssociatedSection();
783783
784784 // If either section is absolute, return the other.
785785 if (LHS_S == MCSymbol::AbsolutePseudoSection)
6767 /// @name MCStreamer Interface
6868 /// @{
6969
70 void ChangeSection(const MCSection *Sect, const MCExpr *Subsect) override;
70 void ChangeSection(MCSection *Sect, const MCExpr *Subsect) override;
7171 void EmitLabel(MCSymbol *Symbol) override;
7272 void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
7373 void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
9797 }
9898 void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
9999 unsigned ByteAlignment) override;
100 void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = nullptr,
100 void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
101101 uint64_t Size = 0, unsigned ByteAlignment = 0) override;
102 void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, uint64_t Size,
102 void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
103103 unsigned ByteAlignment = 0) override;
104104
105105 void EmitFileDirective(StringRef Filename) override {
148148 return false;
149149 }
150150
151 void MCMachOStreamer::ChangeSection(const MCSection *Section,
151 void MCMachOStreamer::ChangeSection(MCSection *Section,
152152 const MCExpr *Subsection) {
153153 // Change the section normally.
154154 bool Created = MCObjectStreamer::changeSectionImpl(Section, Subsection);
400400 Symbol, Size, ByteAlignment);
401401 }
402402
403 void MCMachOStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
403 void MCMachOStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
404404 uint64_t Size, unsigned ByteAlignment) {
405405 MCSectionData &SectData = getAssembler().getOrCreateSectionData(*Section);
406406
431431
432432 // This should always be called with the thread local bss section. Like the
433433 // .zerofill directive this doesn't actually switch sections on us.
434 void MCMachOStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
434 void MCMachOStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
435435 uint64_t Size, unsigned ByteAlignment) {
436436 EmitZerofill(Section, Symbol, Size, ByteAlignment);
437437 return;
3030
3131 void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
3232 unsigned ByteAlignment) override {}
33 void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = nullptr,
33 void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
3434 uint64_t Size = 0, unsigned ByteAlignment = 0) override {}
3535 void EmitGPRel32Value(const MCExpr *Value) override {}
3636 };
767767 }
768768 }
769769
770 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
770 MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
771771 return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
772772 0, utostr(Hash));
773773 }
200200 report_fatal_error("This file format doesn't support weak aliases.");
201201 }
202202
203 void MCObjectStreamer::ChangeSection(const MCSection *Section,
203 void MCObjectStreamer::ChangeSection(MCSection *Section,
204204 const MCExpr *Subsection) {
205205 changeSectionImpl(Section, Subsection);
206206 }
207207
208 bool MCObjectStreamer::changeSectionImpl(const MCSection *Section,
208 bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
209209 const MCExpr *Subsection) {
210210 assert(Section && "Cannot switch to a null section!");
211211 flushPendingLabels(nullptr);
631631 if (getContext().getGenDwarfForAssembly()) {
632632 MCSymbol *SectionStartSym = getContext().createTempSymbol();
633633 getStreamer().EmitLabel(SectionStartSym);
634 const MCSection *Sec = getStreamer().getCurrentSection().first;
634 MCSection *Sec = getStreamer().getCurrentSection().first;
635635 bool InsertResult = getContext().addGenDwarfSection(Sec);
636636 assert(InsertResult && ".text section should not have debug info yet");
637637 (void)InsertResult;
526526 }
527527 }
528528
529 const MCSection *ELFSection = getContext().getELFSection(
530 SectionName, Type, Flags, Size, GroupName, UniqueID);
529 MCSection *ELFSection = getContext().getELFSection(SectionName, Type, Flags,
530 Size, GroupName, UniqueID);
531531 getStreamer().SwitchSection(ELFSection, Subsection);
532532
533533 if (getContext().getGenDwarfForAssembly()) {
676676
677677 Lex();
678678
679 const MCSection *Note = getContext().getELFSection(".note", ELF::SHT_NOTE, 0);
679 MCSection *Note = getContext().getELFSection(".note", ELF::SHT_NOTE, 0);
680680
681681 getStreamer().PushSection();
682682 getStreamer().SwitchSection(Note);
1717 // MCSection
1818 //===----------------------------------------------------------------------===//
1919
20 MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) const {
20 MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
2121 if (!End)
2222 End = Ctx.createTempSymbol("sec_end", true);
2323 return End;
187187 SwitchSection(getContext().getObjectFileInfo()->getTextSection());
188188 }
189189
190 void MCStreamer::AssignSection(MCSymbol *Symbol, const MCSection *Section) {
190 void MCStreamer::AssignSection(MCSymbol *Symbol, MCSection *Section) {
191191 if (Section)
192192 Symbol->setSection(*Section);
193193 else
639639 void MCStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
640640 void MCStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
641641 unsigned ByteAlignment) {}
642 void MCStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
642 void MCStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
643643 uint64_t Size, unsigned ByteAlignment) {}
644 void MCStreamer::ChangeSection(const MCSection *, const MCExpr *) {}
644 void MCStreamer::ChangeSection(MCSection *, const MCExpr *) {}
645645 void MCStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
646646 void MCStreamer::EmitBytes(StringRef Data) {}
647647 void MCStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
663663 void MCStreamer::FinishImpl() {}
664664 void MCStreamer::EmitBundleUnlock() {}
665665
666 void MCStreamer::SwitchSection(const MCSection *Section,
667 const MCExpr *Subsection) {
666 void MCStreamer::SwitchSection(MCSection *Section, const MCExpr *Subsection) {
668667 assert(Section && "Cannot switch to a null section!");
669668 MCSectionSubPair curSection = SectionStack.back().first;
670669 SectionStack.back().second = curSection;
678677 }
679678 }
680679
681 MCSymbol *MCStreamer::endSection(const MCSection *Section) {
680 MCSymbol *MCStreamer::endSection(MCSection *Section) {
682681 // TODO: keep track of the last subsection so that this symbol appears in the
683682 // correct place.
684683 MCSymbol *Sym = Section->getEndSymbol(Context);
1313 using namespace llvm;
1414
1515 // Sentinel value for the absolute pseudo section.
16 const MCSection *MCSymbol::AbsolutePseudoSection =
17 reinterpret_castMCSection *>(1);
16 MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1);
1817
1918 static bool isAcceptableChar(char C) {
2019 if ((C < 'a' || C > 'z') &&
223223
224224 // Emit the unwind info structs first.
225225 for (const auto &CFI : Streamer.getWinFrameInfos()) {
226 const MCSection *XData =
227 getXDataSection(CFI->Function, Context);
226 MCSection *XData = getXDataSection(CFI->Function, Context);
228227 Streamer.SwitchSection(XData);
229228 EmitUnwindInfo(Streamer, CFI);
230229 }
231230
232231 // Now emit RUNTIME_FUNCTION entries.
233232 for (const auto &CFI : Streamer.getWinFrameInfos()) {
234 const MCSection *PData =
235 getPDataSection(CFI->Function, Context);
233 MCSection *PData = getPDataSection(CFI->Function, Context);
236234 Streamer.SwitchSection(PData);
237235 EmitRuntimeFunction(Streamer, CFI);
238236 }
243241 // Switch sections (the static function above is meant to be called from
244242 // here and from Emit().
245243 MCContext &context = Streamer.getContext();
246 const MCSection *xdataSect =
247 getXDataSection(info->Function, context);
244 MCSection *xdataSect = getXDataSection(info->Function, context);
248245 Streamer.SwitchSection(xdataSect);
249246
250247 llvm::EmitUnwindInfo(Streamer, info);
2424 /// associated with that comdat. If the code described is not in the main .text
2525 /// section, make a new section for it. Otherwise use the main unwind info
2626 /// section.
27 static const MCSection *getUnwindInfoSection(
28 StringRef SecName, const MCSectionCOFF *UnwindSec, const MCSymbol *Function,
29 MCContext &Context) {
27 static MCSection *getUnwindInfoSection(StringRef SecName,
28 MCSectionCOFF *UnwindSec,
29 const MCSymbol *Function,
30 MCContext &Context) {
3031 if (Function && Function->isInSection()) {
3132 // If Function is in a COMDAT, get or create an unwind info section in that
3233 // COMDAT group.
5859
5960 }
6061
61 const MCSection *UnwindEmitter::getPDataSection(const MCSymbol *Function,
62 MCContext &Context) {
63 const MCSectionCOFF *PData =
62 MCSection *UnwindEmitter::getPDataSection(const MCSymbol *Function,
63 MCContext &Context) {
64 MCSectionCOFF *PData =
6465 cast(Context.getObjectFileInfo()->getPDataSection());
6566 return getUnwindInfoSection(".pdata", PData, Function, Context);
6667 }
6768
68 const MCSection *UnwindEmitter::getXDataSection(const MCSymbol *Function,
69 MCContext &Context) {
70 const MCSectionCOFF *XData =
69 MCSection *UnwindEmitter::getXDataSection(const MCSymbol *Function,
70 MCContext &Context) {
71 MCSectionCOFF *XData =
7172 cast(Context.getObjectFileInfo()->getXDataSection());
7273 return getUnwindInfoSection(".xdata", XData, Function, Context);
7374 }
218218 unsigned ByteAlignment) {
219219 assert(!Symbol->isInSection() && "Symbol must not already have a section!");
220220
221 const MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
221 MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
222222 MCSectionData &SectionData = getAssembler().getOrCreateSectionData(*Section);
223223 if (SectionData.getAlignment() < ByteAlignment)
224224 SectionData.setAlignment(ByteAlignment);
237237 SD.setFragment(Fragment);
238238 }
239239
240 void MCWinCOFFStreamer::EmitZerofill(const MCSection *Section,
241 MCSymbol *Symbol, uint64_t Size,
242 unsigned ByteAlignment) {
243 llvm_unreachable("not implemented");
244 }
245
246 void MCWinCOFFStreamer::EmitTBSSSymbol(const MCSection *Section,
247 MCSymbol *Symbol, uint64_t Size,
248 unsigned ByteAlignment) {
240 void MCWinCOFFStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
241 uint64_t Size, unsigned ByteAlignment) {
242 llvm_unreachable("not implemented");
243 }
244
245 void MCWinCOFFStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
246 uint64_t Size, unsigned ByteAlignment) {
249247 llvm_unreachable("not implemented");
250248 }
251249
8888 return true;
8989 }
9090
91 void RecordStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
91 void RecordStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
9292 uint64_t Size, unsigned ByteAlignment) {
9393 markDefined(*Symbol);
9494 }
3232 void EmitLabel(MCSymbol *Symbol) override;
3333 void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
3434 bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
35 void EmitZerofill(const MCSection *Section, MCSymbol *Symbol, uint64_t Size,
35 void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
3636 unsigned ByteAlignment) override;
3737 void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
3838 unsigned ByteAlignment) override;
9595
9696 ~AArch64ELFStreamer() override {}
9797
98 void ChangeSection(const MCSection *Section,
99 const MCExpr *Subsection) override {
98 void ChangeSection(MCSection *Section, const MCExpr *Subsection) override {
10099 // We have to keep track of the mapping symbol state of any sections we
101100 // use. Each one should start off as EMS_None, which is provided as the
102101 // default constructor by DenseMap::lookup.
8585 Streamer.visitUsedExpr(*getSubExpr());
8686 }
8787
88 const MCSection *AArch64MCExpr::FindAssociatedSection() const {
88 MCSection *AArch64MCExpr::FindAssociatedSection() const {
8989 llvm_unreachable("FIXME: what goes here?");
9090 }
9191
148148
149149 void visitUsedExpr(MCStreamer &Streamer) const override;
150150
151 const MCSection *FindAssociatedSection() const override;
151 MCSection *FindAssociatedSection() const override;
152152
153153 bool EvaluateAsRelocatableImpl(MCValue &Res,
154154 const MCAsmLayout *Layout,
274274 unsigned EmittedArch;
275275 SmallVector Contents;
276276
277 const MCSection *AttributeSection;
277 MCSection *AttributeSection;
278278
279279 AttributeItem *getAttributeItem(unsigned Attribute) {
280280 for (size_t i = 0; i < Contents.size(); ++i)
430430 void emitRegSave(const SmallVectorImpl &RegList, bool isVector);
431431 void emitUnwindRaw(int64_t Offset, const SmallVectorImpl &Opcodes);
432432
433 void ChangeSection(const MCSection *Section,
434 const MCExpr *Subsection) override {
433 void ChangeSection(MCSection *Section, const MCExpr *Subsection) override {
435434 // We have to keep track of the mapping symbol state of any sections we
436435 // use. Each one should start off as EMS_None, which is provided as the
437436 // default constructor by DenseMap::lookup.
10271026 const MCSymbol *Group = FnSection.getGroup();
10281027 if (Group)
10291028 Flags |= ELF::SHF_GROUP;
1030 const MCSectionELF *EHSection =
1029 MCSectionELF *EHSection =
10311030 getContext().getELFSection(EHSecName, Type, Flags, 0, Group,
10321031 FnSection.getUniqueID(), nullptr, &FnSection);
10331032
6161 const MCFixup *Fixup) const override {
6262 return false;
6363 }
64 void visitUsedExpr(MCStreamer &Streamer) const override;
65 const MCSection *FindAssociatedSection() const override {
64 void visitUsedExpr(MCStreamer &Streamer) const override;
65 MCSection *FindAssociatedSection() const override {
6666 return getSubExpr()->FindAssociatedSection();
6767 }
6868
8080 return false;
8181 }
8282
83 const MCSection *
83 MCSection *
8484 HexagonTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
8585 SectionKind Kind, Mangler &Mang,
8686 const TargetMachine &TM) const {
1515 namespace llvm {
1616
1717 class HexagonTargetObjectFile : public TargetLoweringObjectFileELF {
18 const MCSectionELF *SmallDataSection;
19 const MCSectionELF *SmallBSSSection;
18 MCSectionELF *SmallDataSection;
19 MCSectionELF *SmallBSSSection;
20
2021 public:
2122 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
2223
2930 const TargetMachine &TM) const;
3031
3132 bool IsSmallDataEnabled () const;
32 const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
33 SectionKind Kind, Mangler &Mang,
34 const TargetMachine &TM) const override;
33 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
34 Mangler &Mang,
35 const TargetMachine &TM) const override;
3536 };
3637
3738 } // namespace llvm
5757 Labels.push_back(Symbol);
5858 }
5959
60 void MipsELFStreamer::SwitchSection(const MCSection * Section,
60 void MipsELFStreamer::SwitchSection(MCSection *Section,
6161 const MCExpr *Subsection) {
6262 MCELFStreamer::SwitchSection(Section, Subsection);
6363 Labels.clear();
5454
5555 /// Overriding this function allows us to dismiss all labels that are
5656 /// candidates for marking as microMIPS when .section directive is processed.
57 void SwitchSection(const MCSection *Section,
57 void SwitchSection(MCSection *Section,
5858 const MCExpr *Subsection = nullptr) override;
5959
6060 /// Overriding this function allows us to dismiss all labels that are
5050 const MCAsmLayout *Layout,
5151 const MCFixup *Fixup) const override;
5252 void visitUsedExpr(MCStreamer &Streamer) const override;
53 const MCSection *FindAssociatedSection() const override {
53 MCSection *FindAssociatedSection() const override {
5454 return getSubExpr()->FindAssociatedSection();
5555 }
5656
2727 if (MTS->getABI().IsN64()) {
2828 // The EntrySize value of 1 seems strange since the records are neither
2929 // 1-byte long nor fixed length but it matches the value GAS emits.
30 const MCSectionELF *Sec =
30 MCSectionELF *Sec =
3131 Context.getELFSection(".MIPS.options", ELF::SHT_MIPS_OPTIONS,
3232 ELF::SHF_ALLOC | ELF::SHF_MIPS_NOSTRIP, 1, "");
3333 MCA.getOrCreateSectionData(*Sec).setAlignment(8);
4545 Streamer->EmitIntValue(ri_cprmask[3], 4);
4646 Streamer->EmitIntValue(ri_gp_value, 8);
4747 } else {
48 const MCSectionELF *Sec = Context.getELFSection(
49 ".reginfo", ELF::SHT_MIPS_REGINFO, ELF::SHF_ALLOC, 24, "");
48 MCSectionELF *Sec = Context.getELFSection(".reginfo", ELF::SHT_MIPS_REGINFO,
49 ELF::SHF_ALLOC, 24, "");
5050 MCA.getOrCreateSectionData(*Sec)
5151 .setAlignment(MTS->getABI().IsN32() ? 8 : 4);
5252 Streamer->SwitchSection(Sec);
563563 MCContext &Context = MCA.getContext();
564564 MCStreamer &OS = getStreamer();
565565
566 const MCSectionELF *Sec = Context.getELFSection(
567 ".pdr", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHT_REL);
566 MCSectionELF *Sec = Context.getELFSection(".pdr", ELF::SHT_PROGBITS,
567 ELF::SHF_ALLOC | ELF::SHT_REL);
568568
569569 const MCSymbolRefExpr *ExprRef =
570570 MCSymbolRefExpr::Create(Name, MCSymbolRefExpr::VK_None, Context);
785785 MCAssembler &MCA = getStreamer().getAssembler();
786786 MCContext &Context = MCA.getContext();
787787 MCStreamer &OS = getStreamer();
788 const MCSectionELF *Sec = Context.getELFSection(
788 MCSectionELF *Sec = Context.getELFSection(
789789 ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
790790 MCSectionData &ABIShndxSD = MCA.getOrCreateSectionData(*Sec);
791791 ABIShndxSD.setAlignment(8);
962962 //
963963 // .section mips16.call.fpxxxx,"ax",@progbits
964964 //
965 const MCSectionELF *M = OutContext.getELFSection(
965 MCSectionELF *M = OutContext.getELFSection(
966966 ".mips16.call.fp." + std::string(Symbol), ELF::SHT_PROGBITS,
967967 ELF::SHF_ALLOC | ELF::SHF_EXECINSTR);
968968 OutStreamer->SwitchSection(M, nullptr);
109109 return IsInSmallSection(TM.getDataLayout()->getTypeAllocSize(Ty));
110110 }
111111
112 const MCSection *MipsTargetObjectFile::
113 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
114 Mangler &Mang, const TargetMachine &TM) const {
112 MCSection *
113 MipsTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
114 SectionKind Kind, Mangler &Mang,
115 const TargetMachine &TM) const {
115116 // TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*"
116117 // sections?
117118
135136 CN->getType())));
136137 }
137138
138 const MCSection *MipsTargetObjectFile::
139 getSectionForConstant(SectionKind Kind, const Constant *C) const {
139 MCSection *
140 MipsTargetObjectFile::getSectionForConstant(SectionKind Kind,
141 const Constant *C) const {
140142 if (IsConstantInSmallSection(C, *TM))
141143 return SmallDataSection;
142144
1414 namespace llvm {
1515 class MipsTargetMachine;
1616 class MipsTargetObjectFile : public TargetLoweringObjectFileELF {
17 const MCSection *SmallDataSection;
18 const MCSection *SmallBSSSection;
17 MCSection *SmallDataSection;
18 MCSection *SmallBSSSection;
1919 const MipsTargetMachine *TM;
2020 public:
2121
3030 bool IsGlobalInSmallSectionImpl(const GlobalValue *GV,
3131 const TargetMachine &TM) const;
3232
33 const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
34 SectionKind Kind, Mangler &Mang,
35 const TargetMachine &TM) const override;
33 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
34 Mangler &Mang,
35 const TargetMachine &TM) const override;
3636
3737 /// Return true if this constant should be placed into small data section.
3838 bool IsConstantInSmallSection(const Constant *CN,
3939 const TargetMachine &TM) const;
4040
41 const MCSection *getSectionForConstant(SectionKind Kind,
42 const Constant *C) const override;
41 MCSection *getSectionForConstant(SectionKind Kind,
42 const Constant *C) const override;
4343 };
4444 } // end namespace llvm
4545
45194519 delete DwarfRangesSection;
45204520 }
45214521
4522 const MCSection *
4522 MCSection *
45234523 NVPTXTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
45244524 SectionKind Kind, Mangler &Mang,
45254525 const TargetMachine &TM) const {
6767 return false;
6868 }
6969 void visitUsedExpr(MCStreamer &Streamer) const override {};
70 const MCSection *FindAssociatedSection() const override {
71 return nullptr;
72 }
70 MCSection *FindAssociatedSection() const override { return nullptr; }
7371
7472 // There are no TLS NVPTXMCExprs at the moment.
7573 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
111109 return false;
112110 }
113111 void visitUsedExpr(MCStreamer &Streamer) const override {};
114 const MCSection *FindAssociatedSection() const override {
115 return nullptr;
116 }
112 MCSection *FindAssociatedSection() const override { return nullptr; }
117113
118114 // There are no TLS NVPTXMCExprs at the moment.
119115 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
8383 new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
8484 }
8585
86 const MCSection *getSectionForConstant(SectionKind Kind,
87 const Constant *C) const override {
86 MCSection *getSectionForConstant(SectionKind Kind,
87 const Constant *C) const override {
8888 return ReadOnlySection;
8989 }
9090
91 const MCSection *getExplicitSectionGlobal(const GlobalValue *GV,
92 SectionKind Kind, Mangler &Mang,
93 const TargetMachine &TM) const override {
91 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
92 Mangler &Mang,
93 const TargetMachine &TM) const override {
9494 return DataSection;
9595 }
9696
97 const MCSection *
98 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
99 const TargetMachine &TM) const override;
97 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
98 Mangler &Mang,
99 const TargetMachine &TM) const override;
100100 };
101101
102102 } // end namespace llvm
8181 const MCAsmLayout *Layout,
8282 const MCFixup *Fixup) const override;
8383 void visitUsedExpr(MCStreamer &Streamer) const override;
84 const MCSection *FindAssociatedSection() const override {
84 MCSection *FindAssociatedSection() const override {
8585 return getSubExpr()->FindAssociatedSection();
8686 }
8787
10531053
10541054 // Emit an official procedure descriptor.
10551055 MCSectionSubPair Current = OutStreamer->getCurrentSection();
1056 const MCSectionELF *Section = OutStreamer->getContext().getELFSection(
1056 MCSectionELF *Section = OutStreamer->getContext().getELFSection(
10571057 ".opd", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
10581058 OutStreamer->SwitchSection(Section);
10591059 OutStreamer->EmitLabel(CurrentFnSym);
10831083 static_cast(*OutStreamer->getTargetStreamer());
10841084
10851085 if (!TOC.empty()) {
1086 const MCSectionELF *Section;
1087
1086 MCSectionELF *Section;
1087
10881088 if (isPPC64)
10891089 Section = OutStreamer->getContext().getELFSection(
10901090 ".toc", ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
12841284 static_cast(getObjFileLowering());
12851285
12861286 // .lazy_symbol_pointer
1287 const MCSection *LSPSection = TLOFMacho.getLazySymbolPointerSection();
1288
1287 MCSection *LSPSection = TLOFMacho.getLazySymbolPointerSection();
1288
12891289 // Output stubs for dynamically-linked functions
12901290 if (TM.getRelocationModel() == Reloc::PIC_) {
1291 const MCSection *StubSection =
1292 OutContext.getMachOSection("__TEXT", "__picsymbolstub1",
1293 MachO::S_SYMBOL_STUBS |
1294 MachO::S_ATTR_PURE_INSTRUCTIONS,
1295 32, SectionKind::getText());
1291 MCSection *StubSection = OutContext.getMachOSection(
1292 "__TEXT", "__picsymbolstub1",
1293 MachO::S_SYMBOL_STUBS | MachO::S_ATTR_PURE_INSTRUCTIONS, 32,
1294 SectionKind::getText());
12961295 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
12971296 OutStreamer->SwitchSection(StubSection);
12981297 EmitAlignment(4);
13551354 OutStreamer->AddBlankLine();
13561355 return;
13571356 }
1358
1359 const MCSection *StubSection =
1360 OutContext.getMachOSection("__TEXT","__symbol_stub1",
1361 MachO::S_SYMBOL_STUBS |
1362 MachO::S_ATTR_PURE_INSTRUCTIONS,
1363 16, SectionKind::getText());
1357
1358 MCSection *StubSection = OutContext.getMachOSection(
1359 "__TEXT", "__symbol_stub1",
1360 MachO::S_SYMBOL_STUBS | MachO::S_ATTR_PURE_INSTRUCTIONS, 16,
1361 SectionKind::getText());
13641362 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
13651363 MCSymbol *Stub = Stubs[i].first;
13661364 MCSymbol *RawSym = Stubs[i].second.getPointer();
2121 InitializeELF(TM.Options.UseInitArray);
2222 }
2323
24 const MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
24 MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
2525 const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
2626 const TargetMachine &TM) const {
2727 // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
2121
2222 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
2323
24 const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
25 SectionKind Kind, Mangler &Mang,
26 const TargetMachine &TM) const override;
24 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
25 Mangler &Mang,
26 const TargetMachine &TM) const override;
2727
2828 /// \brief Describe a TLS variable address within debug info.
2929 const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const override;
106106 SetupMachineFunction(MF);
107107
108108 MCContext &Context = getObjFileLowering().getContext();
109 const MCSectionELF *ConfigSection =
109 MCSectionELF *ConfigSection =
110110 Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0);
111111 OutStreamer->SwitchSection(ConfigSection);
112112
130130 EmitFunctionBody();
131131
132132 if (isVerbose()) {
133 const MCSectionELF *CommentSection =
133 MCSectionELF *CommentSection =
134134 Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0);
135135 OutStreamer->SwitchSection(CommentSection);
136136
508508
509509 header.wavefront_size = STM.getWavefrontSize();
510510
511 const MCSectionELF *VersionSection =
511 MCSectionELF *VersionSection =
512512 OutContext.getELFSection(".hsa.version", ELF::SHT_PROGBITS, 0);
513513 OutStreamer->SwitchSection(VersionSection);
514514 OutStreamer->EmitBytes(Twine("HSA Code Unit:" +
8989 const MCAsmLayout *Layout,
9090 const MCFixup *Fixup) const override;
9191 void visitUsedExpr(MCStreamer &Streamer) const override;
92 const MCSection *FindAssociatedSection() const override {
92 MCSection *FindAssociatedSection() const override {
9393 return getSubExpr()->FindAssociatedSection();
9494 }
9595
254254 llvm_unreachable("Invalid relocation");
255255 }
256256
257 /// SectionForGlobal - This method computes the appropriate section to emit
258 /// the specified global variable or function definition. This should not
259 /// be passed external (or available externally) globals.
260 const MCSection *TargetLoweringObjectFile::
261 SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
262 const TargetMachine &TM) const {
257 /// This method computes the appropriate section to emit the specified global
258 /// variable or function definition. This should not be passed external (or
259 /// available externally) globals.
260 MCSection *
261 TargetLoweringObjectFile::SectionForGlobal(const GlobalValue *GV,
262 SectionKind Kind, Mangler &Mang,
263 const TargetMachine &TM) const {
263264 // Select section name.
264265 if (GV->hasSection())
265266 return getExplicitSectionGlobal(GV, Kind, Mang, TM);
269270 return SelectSectionForGlobal(GV, Kind, Mang, TM);
270271 }
271272
272 const MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
273 MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
273274 const Function &F, Mangler &Mang, const TargetMachine &TM) const {
274275 return getSectionForConstant(SectionKind::getReadOnly(), /*C=*/nullptr);
275276 }
292293 return false;
293294 }
294295
295 /// getSectionForConstant - Given a mergable constant with the
296 /// specified size and relocation information, return a section that it
297 /// should be placed in.
298 const MCSection *
296 /// Given a mergable constant with the specified size and relocation
297 /// information, return a section that it should be placed in.
298 MCSection *
299299 TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind,
300300 const Constant *C) const {
301301 if (Kind.isReadOnly() && ReadOnlySection != nullptr)
614614
615615 Stubs = MMIMacho.GetFnStubList();
616616 if (!Stubs.empty()) {
617 const MCSection *TheSection =
618 OutContext.getMachOSection("__IMPORT", "__jump_table",
619 MachO::S_SYMBOL_STUBS |
620 MachO::S_ATTR_SELF_MODIFYING_CODE |
621 MachO::S_ATTR_PURE_INSTRUCTIONS,
622 5, SectionKind::getMetadata());
617 MCSection *TheSection = OutContext.getMachOSection(
618 "__IMPORT", "__jump_table",
619 MachO::S_SYMBOL_STUBS | MachO::S_ATTR_SELF_MODIFYING_CODE |
620 MachO::S_ATTR_PURE_INSTRUCTIONS,
621 5, SectionKind::getMetadata());
623622 OutStreamer->SwitchSection(TheSection);
624623
625624 for (const auto &Stub : Stubs) {
640639 // Output stubs for external and common global variables.
641640 Stubs = MMIMacho.GetGVStubList();
642641 if (!Stubs.empty()) {
643 const MCSection *TheSection =
644 OutContext.getMachOSection("__IMPORT", "__pointers",
645 MachO::S_NON_LAZY_SYMBOL_POINTERS,
646 SectionKind::getMetadata());
642 MCSection *TheSection = OutContext.getMachOSection(
643 "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
644 SectionKind::getMetadata());
647645 OutStreamer->SwitchSection(TheSection);
648646
649647 for (auto &Stub : Stubs)
655653
656654 Stubs = MMIMacho.GetHiddenGVStubList();
657655 if (!Stubs.empty()) {
658 const MCSection *TheSection =
659 OutContext.getMachOSection("__IMPORT", "__pointers",
660 MachO::S_NON_LAZY_SYMBOL_POINTERS,
661 SectionKind::getMetadata());
656 MCSection *TheSection = OutContext.getMachOSection(
657 "__IMPORT", "__pointers", MachO::S_NON_LAZY_SYMBOL_POINTERS,
658 SectionKind::getMetadata());
662659 OutStreamer->SwitchSection(TheSection);
663660
664661 for (auto &Stub : Stubs)
148148 return APIntToHexString(AI);
149149 }
150150
151 const MCSection *
151 MCSection *
152152 X86WindowsTargetObjectFile::getSectionForConstant(SectionKind Kind,
153153 const Constant *C) const {
154154 if (Kind.isReadOnly()) {
5757
5858 /// \brief Given a mergeable constant with the specified size and relocation
5959 /// information, return a section that it should be placed in.
60 const MCSection *getSectionForConstant(SectionKind Kind,
61 const Constant *C) const override;
60 MCSection *getSectionForConstant(SectionKind Kind,
61 const Constant *C) const override;
6262 };
6363
6464 } // end namespace llvm
9494 return Flags;
9595 }
9696
97 const MCSection *
97 MCSection *
9898 XCoreTargetObjectFile::getExplicitSectionGlobal(const GlobalValue *GV,
9999 SectionKind Kind, Mangler &Mang,
100100 const TargetMachine &TM) const {
107107 getXCoreSectionFlags(Kind, IsCPRel));
108108 }
109109
110 const MCSection *XCoreTargetObjectFile::
111 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
112 const TargetMachine &TM) const{
110 MCSection *
111 XCoreTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
112 SectionKind Kind, Mangler &Mang,
113 const TargetMachine &TM) const {
113114
114115 bool UseCPRel = GV->isLocalLinkage(GV->getLinkage());
115116
140141 report_fatal_error("Target does not support TLS or Common sections");
141142 }
142143
143 const MCSection *
144 MCSection *
144145 XCoreTargetObjectFile::getSectionForConstant(SectionKind Kind,
145146 const Constant *C) const {
146147 if (Kind.isMergeableConst4()) return MergeableConst4Section;
1616 static const unsigned CodeModelLargeSize = 256;
1717
1818 class XCoreTargetObjectFile : public TargetLoweringObjectFileELF {
19 const MCSection *BSSSectionLarge;
20 const MCSection *DataSectionLarge;
21 const MCSection *ReadOnlySectionLarge;
22 const MCSection *DataRelROSectionLarge;
19 MCSection *BSSSectionLarge;
20 MCSection *DataSectionLarge;
21 MCSection *ReadOnlySectionLarge;
22 MCSection *DataRelROSectionLarge;
23
2324 public:
2425 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
2526
26 const MCSection *
27 getExplicitSectionGlobal(const GlobalValue *GV,
28 SectionKind Kind, Mangler &Mang,
29 const TargetMachine &TM) const override;
27 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
28 Mangler &Mang,
29 const TargetMach