llvm.org GIT mirror llvm / e76a33b
Add MCObjectFileInfo and sink the MCSections initialization code from TargetLoweringObjectFileImpl down to MCObjectFileInfo. TargetAsmInfo is done to one last method. It's *almost* gone! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135569 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 8 years ago
27 changed file(s) with 901 addition(s) and 841 deletion(s). Raw diff Collapse all Expand all
174174 MachineModuleInfo(); // DUMMY CONSTRUCTOR, DO NOT CALL.
175175 // Real constructor.
176176 MachineModuleInfo(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
177 const MCObjectFileInfo *MOFI,
177178 const TargetAsmInfo *TAI);
178179 ~MachineModuleInfo();
179180
3232
3333
3434 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
35 protected:
36 /// TLSDataSection - Section directive for Thread Local data.
37 ///
38 const MCSection *TLSDataSection; // Defaults to ".tdata".
39
40 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
41 /// Null if this target doesn't support a BSS section.
42 ///
43 const MCSection *TLSBSSSection; // Defaults to ".tbss".
44
45 const MCSection *DataRelSection;
46 const MCSection *DataRelLocalSection;
47 const MCSection *DataRelROSection;
48 const MCSection *DataRelROLocalSection;
49
50 const MCSection *MergeableConst4Section;
51 const MCSection *MergeableConst8Section;
52 const MCSection *MergeableConst16Section;
5335 public:
54 TargetLoweringObjectFileELF();
55 ~TargetLoweringObjectFileELF() {}
56
57 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
58
59 virtual const MCSection *getEHFrameSection() const;
60 virtual const MCSection *getWin64EHFuncTableSection(StringRef) const {
61 return NULL;
62 }
63 virtual const MCSection *getWin64EHTableSection(StringRef) const{return NULL;}
36 virtual ~TargetLoweringObjectFileELF() {}
6437
6538 virtual void emitPersonalityValue(MCStreamer &Streamer,
6639 const TargetMachine &TM,
6740 const MCSymbol *Sym) const;
68
69 const MCSection *getDataRelSection() const { return DataRelSection; }
7041
7142 /// getSectionForConstant - Given a constant with the SectionKind, return a
7243 /// section that it should be placed in.
9869
9970
10071 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
101 /// TLSDataSection - Section for thread local data.
102 ///
103 const MCSection *TLSDataSection; // Defaults to ".tdata".
104
105 /// TLSBSSSection - Section for thread local uninitialized data.
106 ///
107 const MCSection *TLSBSSSection; // Defaults to ".tbss".
108
109 /// TLSTLVSection - Section for thread local structure information.
110 /// Contains the source code name of the variable, visibility and a pointer
111 /// to the initial value (.tdata or .tbss).
112 const MCSection *TLSTLVSection; // Defaults to ".tlv".
113
114 /// TLSThreadInitSection - Section for thread local data initialization
115 /// functions.
116 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
117
118 const MCSection *CStringSection;
119 const MCSection *UStringSection;
120 const MCSection *TextCoalSection;
121 const MCSection *ConstTextCoalSection;
122 const MCSection *ConstDataSection;
123 const MCSection *DataCoalSection;
124 const MCSection *DataCommonSection;
125 const MCSection *DataBSSSection;
126 const MCSection *FourByteConstantSection;
127 const MCSection *EightByteConstantSection;
128 const MCSection *SixteenByteConstantSection;
129
130 const MCSection *LazySymbolPointerSection;
131 const MCSection *NonLazySymbolPointerSection;
13272 public:
133 TargetLoweringObjectFileMachO();
134 ~TargetLoweringObjectFileMachO() {}
135
136 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
137
138 virtual const MCSection *getEHFrameSection() const;
139 virtual const MCSection *getWin64EHFuncTableSection(StringRef) const {
140 return NULL;
141 }
142 virtual const MCSection *getWin64EHTableSection(StringRef) const{return NULL;}
73 virtual ~TargetLoweringObjectFileMachO() {}
14374
14475 virtual const MCSection *
14576 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
15687 /// FIXME: REMOVE this (rdar://7071300)
15788 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
15889 Mangler *) const;
159
160 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
161 /// text symbols into.
162 const MCSection *getTextCoalSection() const {
163 return TextCoalSection;
164 }
165
166 /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
167 /// we put weak read-only symbols into.
168 const MCSection *getConstTextCoalSection() const {
169 return ConstTextCoalSection;
170 }
171
172 /// getLazySymbolPointerSection - Return the section corresponding to
173 /// the .lazy_symbol_pointer directive.
174 const MCSection *getLazySymbolPointerSection() const {
175 return LazySymbolPointerSection;
176 }
177
178 /// getNonLazySymbolPointerSection - Return the section corresponding to
179 /// the .non_lazy_symbol_pointer directive.
180 const MCSection *getNonLazySymbolPointerSection() const {
181 return NonLazySymbolPointerSection;
182 }
18390
18491 /// getExprForDwarfGlobalReference - The mach-o version of this method
18592 /// defaults to returning a stub reference.
202109
203110
204111 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
205 const MCSection *DrectveSection;
206 const MCSection *PDataSection;
207 const MCSection *XDataSection;
208112 public:
209 TargetLoweringObjectFileCOFF();
210 ~TargetLoweringObjectFileCOFF() {}
211
212 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
213
214 virtual const MCSection *getEHFrameSection() const;
215 virtual const MCSection *getWin64EHFuncTableSection(StringRef) const;
216 virtual const MCSection *getWin64EHTableSection(StringRef) const;
217
218 virtual const MCSection *getDrectveSection() const { return DrectveSection; }
113 virtual ~TargetLoweringObjectFileCOFF() {}
219114
220115 virtual const MCSection *
221116 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
2525 class MCLabel;
2626 class MCDwarfFile;
2727 class MCDwarfLoc;
28 class MCObjectFileInfo;
2829 class MCRegisterInfo;
2930 class MCLineSection;
3031 class StringRef;
4849
4950 /// The MCRegisterInfo for this target.
5051 const MCRegisterInfo &MRI;
52
53 /// The MCObjectFileInfo for this target.
54 const MCObjectFileInfo *MOFI;
5155
5256 const TargetAsmInfo *TAI;
5357
114118
115119 public:
116120 explicit MCContext(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
117 const TargetAsmInfo *TAI);
121 const MCObjectFileInfo *MOFI, const TargetAsmInfo *TAI);
118122 ~MCContext();
119123
120124 const MCAsmInfo &getAsmInfo() const { return MAI; }
121125
122126 const MCRegisterInfo &getRegisterInfo() const { return MRI; }
127
128 const MCObjectFileInfo *getObjectFileInfo() const { return MOFI; }
123129
124130 const TargetAsmInfo &getTargetAsmInfo() const { return *TAI; }
125131
0 //===-- llvm/MC/MCObjectFileInfo.h - Object File Info -----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file describes common object file formats.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_MC_MCBJECTFILEINFO_H
14 #define LLVM_MC_MCBJECTFILEINFO_H
15
16 #include "llvm/MC/MCCodeGenInfo.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/MC/SectionKind.h"
19
20 namespace llvm {
21 class MCContext;
22 class MCSection;
23 class Triple;
24
25 class MCObjectFileInfo {
26 protected:
27 /// CommDirectiveSupportsAlignment - True if .comm supports alignment. This
28 /// is a hack for as long as we support 10.4 Tiger, whose assembler doesn't
29 /// support alignment on comm.
30 bool CommDirectiveSupportsAlignment;
31
32 /// SupportsWeakEmptyEHFrame - True if target object file supports a
33 /// weak_definition of constant 0 for an omitted EH frame.
34 bool SupportsWeakOmittedEHFrame;
35
36 /// IsFunctionEHFrameSymbolPrivate - This flag is set to true if the
37 /// "EH_frame" symbol for EH information should be an assembler temporary (aka
38 /// private linkage, aka an L or .L label) or false if it should be a normal
39 /// non-.globl label. This defaults to true.
40 bool IsFunctionEHFrameSymbolPrivate;
41
42
43 /// TextSection - Section directive for standard text.
44 ///
45 const MCSection *TextSection;
46
47 /// DataSection - Section directive for standard data.
48 ///
49 const MCSection *DataSection;
50
51 /// BSSSection - Section that is default initialized to zero.
52 const MCSection *BSSSection;
53
54 /// ReadOnlySection - Section that is readonly and can contain arbitrary
55 /// initialized data. Targets are not required to have a readonly section.
56 /// If they don't, various bits of code will fall back to using the data
57 /// section for constants.
58 const MCSection *ReadOnlySection;
59
60 /// StaticCtorSection - This section contains the static constructor pointer
61 /// list.
62 const MCSection *StaticCtorSection;
63
64 /// StaticDtorSection - This section contains the static destructor pointer
65 /// list.
66 const MCSection *StaticDtorSection;
67
68 /// LSDASection - If exception handling is supported by the target, this is
69 /// the section the Language Specific Data Area information is emitted to.
70 const MCSection *LSDASection;
71
72 /// CompactUnwindSection - If exception handling is supported by the target
73 /// and the target can support a compact representation of the CIE and FDE,
74 /// this is the section to emit them into.
75 const MCSection *CompactUnwindSection;
76
77 // Dwarf sections for debug info. If a target supports debug info, these must
78 // be set.
79 const MCSection *DwarfAbbrevSection;
80 const MCSection *DwarfInfoSection;
81 const MCSection *DwarfLineSection;
82 const MCSection *DwarfFrameSection;
83 const MCSection *DwarfPubNamesSection;
84 const MCSection *DwarfPubTypesSection;
85 const MCSection *DwarfDebugInlineSection;
86 const MCSection *DwarfStrSection;
87 const MCSection *DwarfLocSection;
88 const MCSection *DwarfARangesSection;
89 const MCSection *DwarfRangesSection;
90 const MCSection *DwarfMacroInfoSection;
91
92 // Extra TLS Variable Data section. If the target needs to put additional
93 // information for a TLS variable, it'll go here.
94 const MCSection *TLSExtraDataSection;
95
96 /// TLSDataSection - Section directive for Thread Local data.
97 /// ELF and MachO only.
98 const MCSection *TLSDataSection; // Defaults to ".tdata".
99
100 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
101 /// Null if this target doesn't support a BSS section.
102 /// ELF and MachO only.
103 const MCSection *TLSBSSSection; // Defaults to ".tbss".
104
105
106 /// EHFrameSection - EH frame section. It is initialized on demand so it
107 /// can be overwritten (with uniquing).
108 const MCSection *EHFrameSection;
109
110 /// ELF specific sections.
111 ///
112 const MCSection *DataRelSection;
113 const MCSection *DataRelLocalSection;
114 const MCSection *DataRelROSection;
115 const MCSection *DataRelROLocalSection;
116 const MCSection *MergeableConst4Section;
117 const MCSection *MergeableConst8Section;
118 const MCSection *MergeableConst16Section;
119
120 /// MachO specific sections.
121 ///
122
123 /// TLSTLVSection - Section for thread local structure information.
124 /// Contains the source code name of the variable, visibility and a pointer
125 /// to the initial value (.tdata or .tbss).
126 const MCSection *TLSTLVSection; // Defaults to ".tlv".
127
128 /// TLSThreadInitSection - Section for thread local data initialization
129 /// functions.
130 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
131
132 const MCSection *CStringSection;
133 const MCSection *UStringSection;
134 const MCSection *TextCoalSection;
135 const MCSection *ConstTextCoalSection;
136 const MCSection *ConstDataSection;
137 const MCSection *DataCoalSection;
138 const MCSection *DataCommonSection;
139 const MCSection *DataBSSSection;
140 const MCSection *FourByteConstantSection;
141 const MCSection *EightByteConstantSection;
142 const MCSection *SixteenByteConstantSection;
143 const MCSection *LazySymbolPointerSection;
144 const MCSection *NonLazySymbolPointerSection;
145
146 /// COFF specific sections.
147 ///
148 const MCSection *DrectveSection;
149 const MCSection *PDataSection;
150 const MCSection *XDataSection;
151
152 public:
153 void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, MCContext &ctx);
154
155 bool isFunctionEHFrameSymbolPrivate() const {
156 return IsFunctionEHFrameSymbolPrivate;
157 }
158 bool getSupportsWeakOmittedEHFrame() const {
159 return SupportsWeakOmittedEHFrame;
160 }
161 bool getCommDirectiveSupportsAlignment() const {
162 return CommDirectiveSupportsAlignment;
163 }
164
165 const MCSection *getTextSection() const { return TextSection; }
166 const MCSection *getDataSection() const { return DataSection; }
167 const MCSection *getBSSSection() const { return BSSSection; }
168 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
169 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
170 const MCSection *getLSDASection() const { return LSDASection; }
171 const MCSection *getCompactUnwindSection() const{
172 return CompactUnwindSection;
173 }
174 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
175 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
176 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
177 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
178 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
179 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
180 const MCSection *getDwarfDebugInlineSection() const {
181 return DwarfDebugInlineSection;
182 }
183 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
184 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
185 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
186 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
187 const MCSection *getDwarfMacroInfoSection() const {
188 return DwarfMacroInfoSection;
189 }
190 const MCSection *getTLSExtraDataSection() const {
191 return TLSExtraDataSection;
192 }
193 const MCSection *getTLSDataSection() const { return TLSDataSection; }
194 const MCSection *getTLSBSSSection() const { return TLSBSSSection; }
195
196 /// ELF specific sections.
197 ///
198 const MCSection *getDataRelSection() const { return DataRelSection; }
199 const MCSection *getDataRelLocalSection() const {
200 return DataRelLocalSection;
201 }
202 const MCSection *getDataRelROSection() const { return DataRelROSection; }
203 const MCSection *getDataRelROLocalSection() const {
204 return DataRelROLocalSection;
205 }
206 const MCSection *getMergeableConst4Section() const {
207 return MergeableConst4Section;
208 }
209 const MCSection *getMergeableConst8Section() const {
210 return MergeableConst8Section;
211 }
212 const MCSection *getMergeableConst16Section() const {
213 return MergeableConst16Section;
214 }
215
216 /// MachO specific sections.
217 ///
218 const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
219 const MCSection *getTLSThreadInitSection() const {
220 return TLSThreadInitSection;
221 }
222 const MCSection *getCStringSection() const { return CStringSection; }
223 const MCSection *getUStringSection() const { return UStringSection; }
224 const MCSection *getTextCoalSection() const { return TextCoalSection; }
225 const MCSection *getConstTextCoalSection() const {
226 return ConstTextCoalSection;
227 }
228 const MCSection *getConstDataSection() const { return ConstDataSection; }
229 const MCSection *getDataCoalSection() const { return DataCoalSection; }
230 const MCSection *getDataCommonSection() const { return DataCommonSection; }
231 const MCSection *getDataBSSSection() const { return DataBSSSection; }
232 const MCSection *getFourByteConstantSection() const {
233 return FourByteConstantSection;
234 }
235 const MCSection *getEightByteConstantSection() const {
236 return EightByteConstantSection;
237 }
238 const MCSection *getSixteenByteConstantSection() const {
239 return SixteenByteConstantSection;
240 }
241 const MCSection *getLazySymbolPointerSection() const {
242 return LazySymbolPointerSection;
243 }
244 const MCSection *getNonLazySymbolPointerSection() const {
245 return NonLazySymbolPointerSection;
246 }
247
248 /// COFF specific sections.
249 ///
250 const MCSection *getDrectveSection() const { return DrectveSection; }
251 const MCSection *getPDataSection() const { return PDataSection; }
252 const MCSection *getXDataSection() const { return XDataSection; }
253
254 const MCSection *getEHFrameSection() {
255 if (!EHFrameSection)
256 InitEHFrameSection();
257 return EHFrameSection;
258 }
259
260 private:
261 enum Environment { IsMachO, IsELF, IsCOFF };
262 Environment Env;
263 Reloc::Model RelocM;
264 MCContext *Ctx;
265
266 void InitMachOMCObjectFileInfo(Triple T);
267 void InitELFMCObjectFileInfo(Triple T);
268 void InitCOFFMCObjectFileInfo(Triple T);
269
270 /// InitEHFrameSection - Initialize EHFrameSection on demand.
271 ///
272 void InitEHFrameSection();
273 };
274
275 } // end namespace llvm
276
277 #endif
1414 #define LLVM_TARGET_TARGETASMINFO_H
1515
1616 #include "llvm/Target/TargetLoweringObjectFile.h"
17 #include "llvm/Target/TargetRegisterInfo.h"
1817
1918 namespace llvm {
20 template class ArrayRef;
21 class MCSection;
2219 class TargetMachine;
2320 class TargetLoweringObjectFile;
2421
2825 public:
2926 explicit TargetAsmInfo(const TargetMachine &TM);
3027
31 const MCSection *getDwarfLineSection() const {
32 return TLOF->getDwarfLineSection();
33 }
34
35 const MCSection *getEHFrameSection() const {
36 return TLOF->getEHFrameSection();
37 }
38
39 const MCSection *getCompactUnwindSection() const {
40 return TLOF->getCompactUnwindSection();
41 }
42
43 const MCSection *getDwarfFrameSection() const {
44 return TLOF->getDwarfFrameSection();
45 }
46
47 const MCSection *getWin64EHFuncTableSection(StringRef Suffix) const {
48 return TLOF->getWin64EHFuncTableSection(Suffix);
49 }
50
51 const MCSection *getWin64EHTableSection(StringRef Suffix) const {
52 return TLOF->getWin64EHTableSection(Suffix);
53 }
54
5528 unsigned getFDEEncoding(bool CFI) const {
5629 return TLOF->getFDEEncoding(CFI);
57 }
58
59 bool isFunctionEHFrameSymbolPrivate() const {
60 return TLOF->isFunctionEHFrameSymbolPrivate();
6130 }
6231 };
6332
1515 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
1616
1717 #include "llvm/ADT/StringRef.h"
18 #include "llvm/MC/MCObjectFileInfo.h"
1819 #include "llvm/MC/SectionKind.h"
1920
2021 namespace llvm {
3031 class GlobalValue;
3132 class TargetMachine;
3233
33 class TargetLoweringObjectFile {
34 class TargetLoweringObjectFile : public MCObjectFileInfo {
3435 MCContext *Ctx;
3536
3637 TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
3738 void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
38 protected:
3939
40 TargetLoweringObjectFile();
41
42 /// TextSection - Section directive for standard text.
43 ///
44 const MCSection *TextSection;
45
46 /// DataSection - Section directive for standard data.
47 ///
48 const MCSection *DataSection;
49
50 /// BSSSection - Section that is default initialized to zero.
51 const MCSection *BSSSection;
52
53 /// ReadOnlySection - Section that is readonly and can contain arbitrary
54 /// initialized data. Targets are not required to have a readonly section.
55 /// If they don't, various bits of code will fall back to using the data
56 /// section for constants.
57 const MCSection *ReadOnlySection;
58
59 /// StaticCtorSection - This section contains the static constructor pointer
60 /// list.
61 const MCSection *StaticCtorSection;
62
63 /// StaticDtorSection - This section contains the static destructor pointer
64 /// list.
65 const MCSection *StaticDtorSection;
66
67 /// LSDASection - If exception handling is supported by the target, this is
68 /// the section the Language Specific Data Area information is emitted to.
69 const MCSection *LSDASection;
70
71 /// CompactUnwindSection - If exception handling is supported by the target
72 /// and the target can support a compact representation of the CIE and FDE,
73 /// this is the section to emit them into.
74 const MCSection *CompactUnwindSection;
75
76 // Dwarf sections for debug info. If a target supports debug info, these must
77 // be set.
78 const MCSection *DwarfAbbrevSection;
79 const MCSection *DwarfInfoSection;
80 const MCSection *DwarfLineSection;
81 const MCSection *DwarfFrameSection;
82 const MCSection *DwarfPubNamesSection;
83 const MCSection *DwarfPubTypesSection;
84 const MCSection *DwarfDebugInlineSection;
85 const MCSection *DwarfStrSection;
86 const MCSection *DwarfLocSection;
87 const MCSection *DwarfARangesSection;
88 const MCSection *DwarfRangesSection;
89 const MCSection *DwarfMacroInfoSection;
90
91 // Extra TLS Variable Data section. If the target needs to put additional
92 // information for a TLS variable, it'll go here.
93 const MCSection *TLSExtraDataSection;
94
95 /// CommDirectiveSupportsAlignment - True if .comm supports alignment. This
96 /// is a hack for as long as we support 10.4 Tiger, whose assembler doesn't
97 /// support alignment on comm.
98 bool CommDirectiveSupportsAlignment;
99
100 /// SupportsWeakEmptyEHFrame - True if target object file supports a
101 /// weak_definition of constant 0 for an omitted EH frame.
102 bool SupportsWeakOmittedEHFrame;
103
104 /// IsFunctionEHFrameSymbolPrivate - This flag is set to true if the
105 /// "EH_frame" symbol for EH information should be an assembler temporary (aka
106 /// private linkage, aka an L or .L label) or false if it should be a normal
107 /// non-.globl label. This defaults to true.
108 bool IsFunctionEHFrameSymbolPrivate;
109
11040 public:
11141 MCContext &getContext() const { return *Ctx; }
42
43 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0) {}
11244
11345 virtual ~TargetLoweringObjectFile();
11446
11547 /// Initialize - this method must be called before any actual lowering is
11648 /// done. This specifies the current context for codegen, and gives the
11749 /// lowering implementations a chance to set up their default sections.
118 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
119 Ctx = &ctx;
120 }
50 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
12151
122 bool isFunctionEHFrameSymbolPrivate() const {
123 return IsFunctionEHFrameSymbolPrivate;
124 }
125 bool getSupportsWeakOmittedEHFrame() const {
126 return SupportsWeakOmittedEHFrame;
127 }
128 bool getCommDirectiveSupportsAlignment() const {
129 return CommDirectiveSupportsAlignment;
130 }
131
132 const MCSection *getTextSection() const { return TextSection; }
133 const MCSection *getDataSection() const { return DataSection; }
134 const MCSection *getBSSSection() const { return BSSSection; }
135 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
136 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
137 const MCSection *getLSDASection() const { return LSDASection; }
138 const MCSection *getCompactUnwindSection() const{return CompactUnwindSection;}
139 virtual const MCSection *getEHFrameSection() const = 0;
14052 virtual void emitPersonalityValue(MCStreamer &Streamer,
14153 const TargetMachine &TM,
14254 const MCSymbol *Sym) const;
143 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
144 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
145 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
146 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
147 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
148 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
149 const MCSection *getDwarfDebugInlineSection() const {
150 return DwarfDebugInlineSection;
151 }
152 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
153 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
154 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
155 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
156 const MCSection *getDwarfMacroInfoSection() const {
157 return DwarfMacroInfoSection;
158 }
159 const MCSection *getTLSExtraDataSection() const {
160 return TLSExtraDataSection;
161 }
162 virtual const MCSection *getWin64EHFuncTableSection(StringRef suffix)const=0;
163 virtual const MCSection *getWin64EHTableSection(StringRef suffix) const = 0;
16455
16556 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
16657 /// decide not to emit the UsedDirective for some symbols in llvm.used.
2525 #include "llvm/Target/Mangler.h"
2626 #include "llvm/Target/TargetData.h"
2727 #include "llvm/Target/TargetFrameLowering.h"
28 #include "llvm/Target/TargetLoweringObjectFile.h"
2928 #include "llvm/Target/TargetMachine.h"
3029 #include "llvm/Target/TargetOptions.h"
3130 #include "llvm/Target/TargetRegisterInfo.h"
7676 // This is a temporary hack to keep sections in the same order they
7777 // were before. This lets us produce bit identical outputs while
7878 // transitioning to CFI.
79 Asm->OutStreamer.SwitchSection(TLOF.getEHFrameSection());
79 Asm->OutStreamer.SwitchSection(
80 const_cast(TLOF).getEHFrameSection());
8081 }
8182 }
8283
6666 ELFWriter::ELFWriter(raw_ostream &o, TargetMachine &tm)
6767 : MachineFunctionPass(ID), O(o), TM(tm),
6868 OutContext(*new MCContext(*TM.getMCAsmInfo(), *TM.getRegisterInfo(),
69 &TM.getTargetLowering()->getObjFileLowering(),
6970 new TargetAsmInfo(tm))),
7071 TLOF(TM.getTargetLowering()->getObjFileLowering()),
7172 is64Bit(TM.getTargetData()->getPointerSizeInBits() == 64),
2929 #include "llvm/Target/TargetAsmInfo.h"
3030 #include "llvm/Target/TargetData.h"
3131 #include "llvm/Target/TargetInstrInfo.h"
32 #include "llvm/Target/TargetRegisterInfo.h"
3233 #include "llvm/Target/TargetRegistry.h"
3334 #include "llvm/Target/TargetSubtargetInfo.h"
3435 #include "llvm/Transforms/Scalar.h"
372373 // all the per-module stuff we're generating, including MCContext.
373374 TargetAsmInfo *TAI = new TargetAsmInfo(*this);
374375 MachineModuleInfo *MMI = new MachineModuleInfo(*getMCAsmInfo(),
375 *getRegisterInfo(), TAI);
376 *getRegisterInfo(),
377 &getTargetLowering()->getObjFileLowering(),
378 TAI);
376379 PM.add(MMI);
377380 OutContext = &MMI->getContext(); // Return the MCContext specifically by-ref.
378381
1616 #include "llvm/CodeGen/MachineFunctionPass.h"
1717 #include "llvm/CodeGen/MachineFunction.h"
1818 #include "llvm/CodeGen/Passes.h"
19 #include "llvm/Target/TargetInstrInfo.h"
20 #include "llvm/Target/TargetMachine.h"
21 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/Target/TargetAsmInfo.h"
20 #include "llvm/MC/MCObjectFileInfo.h"
2221 #include "llvm/MC/MCSymbol.h"
2322 #include "llvm/ADT/PointerUnion.h"
2423 #include "llvm/Support/Dwarf.h"
254253
255254 MachineModuleInfo::MachineModuleInfo(const MCAsmInfo &MAI,
256255 const MCRegisterInfo &MRI,
256 const MCObjectFileInfo *MOFI,
257257 const TargetAsmInfo *TAI)
258 : ImmutablePass(ID), Context(MAI, MRI, TAI),
258 : ImmutablePass(ID), Context(MAI, MRI, MOFI, TAI),
259259 ObjFileMMI(0), CompactUnwindEncoding(0), CurCallSite(0), CallsEHReturn(0),
260260 CallsUnwindInit(0), DbgInfoAvailable(false),
261261 CallsExternalVAFunctionWithFloatingPointArguments(false) {
267267 }
268268
269269 MachineModuleInfo::MachineModuleInfo()
270 : ImmutablePass(ID), Context(*(MCAsmInfo*)0, *(MCRegisterInfo*)0, NULL) {
270 : ImmutablePass(ID),
271 Context(*(MCAsmInfo*)0, *(MCRegisterInfo*)0, (MCObjectFileInfo*)0, NULL) {
271272 assert(0 && "This MachineModuleInfo constructor should never be called, MMI "
272273 "should always be explicitly constructed by LLVMTargetMachine");
273274 abort();
4242 // ELF
4343 //===----------------------------------------------------------------------===//
4444
45 TargetLoweringObjectFileELF::TargetLoweringObjectFileELF()
46 : TargetLoweringObjectFile(),
47 TLSDataSection(0),
48 TLSBSSSection(0),
49 DataRelSection(0),
50 DataRelLocalSection(0),
51 DataRelROSection(0),
52 DataRelROLocalSection(0),
53 MergeableConst4Section(0),
54 MergeableConst8Section(0),
55 MergeableConst16Section(0) {
56 }
57
58 void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
59 const TargetMachine &TM) {
60 TargetLoweringObjectFile::Initialize(Ctx, TM);
61
62 BSSSection =
63 getContext().getELFSection(".bss", ELF::SHT_NOBITS,
64 ELF::SHF_WRITE |ELF::SHF_ALLOC,
65 SectionKind::getBSS());
66
67 TextSection =
68 getContext().getELFSection(".text", ELF::SHT_PROGBITS,
69 ELF::SHF_EXECINSTR |
70 ELF::SHF_ALLOC,
71 SectionKind::getText());
72
73 DataSection =
74 getContext().getELFSection(".data", ELF::SHT_PROGBITS,
75 ELF::SHF_WRITE |ELF::SHF_ALLOC,
76 SectionKind::getDataRel());
77
78 ReadOnlySection =
79 getContext().getELFSection(".rodata", ELF::SHT_PROGBITS,
80 ELF::SHF_ALLOC,
81 SectionKind::getReadOnly());
82
83 TLSDataSection =
84 getContext().getELFSection(".tdata", ELF::SHT_PROGBITS,
85 ELF::SHF_ALLOC | ELF::SHF_TLS |
86 ELF::SHF_WRITE,
87 SectionKind::getThreadData());
88
89 TLSBSSSection =
90 getContext().getELFSection(".tbss", ELF::SHT_NOBITS,
91 ELF::SHF_ALLOC | ELF::SHF_TLS |
92 ELF::SHF_WRITE,
93 SectionKind::getThreadBSS());
94
95 DataRelSection =
96 getContext().getELFSection(".data.rel", ELF::SHT_PROGBITS,
97 ELF::SHF_ALLOC |ELF::SHF_WRITE,
98 SectionKind::getDataRel());
99
100 DataRelLocalSection =
101 getContext().getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
102 ELF::SHF_ALLOC |ELF::SHF_WRITE,
103 SectionKind::getDataRelLocal());
104
105 DataRelROSection =
106 getContext().getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
107 ELF::SHF_ALLOC |ELF::SHF_WRITE,
108 SectionKind::getReadOnlyWithRel());
109
110 DataRelROLocalSection =
111 getContext().getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
112 ELF::SHF_ALLOC |ELF::SHF_WRITE,
113 SectionKind::getReadOnlyWithRelLocal());
114
115 MergeableConst4Section =
116 getContext().getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
117 ELF::SHF_ALLOC |ELF::SHF_MERGE,
118 SectionKind::getMergeableConst4());
119
120 MergeableConst8Section =
121 getContext().getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
122 ELF::SHF_ALLOC |ELF::SHF_MERGE,
123 SectionKind::getMergeableConst8());
124
125 MergeableConst16Section =
126 getContext().getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
127 ELF::SHF_ALLOC |ELF::SHF_MERGE,
128 SectionKind::getMergeableConst16());
129
130 StaticCtorSection =
131 getContext().getELFSection(".ctors", ELF::SHT_PROGBITS,
132 ELF::SHF_ALLOC |ELF::SHF_WRITE,
133 SectionKind::getDataRel());
134
135 StaticDtorSection =
136 getContext().getELFSection(".dtors", ELF::SHT_PROGBITS,
137 ELF::SHF_ALLOC |ELF::SHF_WRITE,
138 SectionKind::getDataRel());
139
140 // Exception Handling Sections.
141
142 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
143 // it contains relocatable pointers. In PIC mode, this is probably a big
144 // runtime hit for C++ apps. Either the contents of the LSDA need to be
145 // adjusted or this should be a data section.
146 LSDASection =
147 getContext().getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
148 ELF::SHF_ALLOC,
149 SectionKind::getReadOnly());
150 // Debug Info Sections.
151 DwarfAbbrevSection =
152 getContext().getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
153 SectionKind::getMetadata());
154 DwarfInfoSection =
155 getContext().getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
156 SectionKind::getMetadata());
157 DwarfLineSection =
158 getContext().getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
159 SectionKind::getMetadata());
160 DwarfFrameSection =
161 getContext().getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
162 SectionKind::getMetadata());
163 DwarfPubNamesSection =
164 getContext().getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
165 SectionKind::getMetadata());
166 DwarfPubTypesSection =
167 getContext().getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
168 SectionKind::getMetadata());
169 DwarfStrSection =
170 getContext().getELFSection(".debug_str", ELF::SHT_PROGBITS, 0,
171 SectionKind::getMetadata());
172 DwarfLocSection =
173 getContext().getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
174 SectionKind::getMetadata());
175 DwarfARangesSection =
176 getContext().getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
177 SectionKind::getMetadata());
178 DwarfRangesSection =
179 getContext().getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
180 SectionKind::getMetadata());
181 DwarfMacroInfoSection =
182 getContext().getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
183 SectionKind::getMetadata());
184 }
185
186 const MCSection *TargetLoweringObjectFileELF::getEHFrameSection() const {
187 return getContext().getELFSection(".eh_frame", ELF::SHT_PROGBITS,
188 ELF::SHF_ALLOC,
189 SectionKind::getDataRel());
190 }
191
19245 MCSymbol *
19346 TargetLoweringObjectFileELF::getCFIPersonalitySymbol(const GlobalValue *GV,
19447 Mangler *Mang,
492345 // MachO
493346 //===----------------------------------------------------------------------===//
494347
495 TargetLoweringObjectFileMachO::TargetLoweringObjectFileMachO()
496 : TargetLoweringObjectFile(),
497 TLSDataSection(0),
498 TLSBSSSection(0),
499 TLSTLVSection(0),
500 TLSThreadInitSection(0),
501 CStringSection(0),
502 UStringSection(0),
503 TextCoalSection(0),
504 ConstTextCoalSection(0),
505 ConstDataSection(0),
506 DataCoalSection(0),
507 DataCommonSection(0),
508 DataBSSSection(0),
509 FourByteConstantSection(0),
510 EightByteConstantSection(0),
511 SixteenByteConstantSection(0),
512 LazySymbolPointerSection(0),
513 NonLazySymbolPointerSection(0) {
514 }
515
516 void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
517 const TargetMachine &TM) {
518 IsFunctionEHFrameSymbolPrivate = false;
519 SupportsWeakOmittedEHFrame = false;
520
521 // .comm doesn't support alignment before Leopard.
522 Triple T(((LLVMTargetMachine&)TM).getTargetTriple());
523 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
524 CommDirectiveSupportsAlignment = false;
525
526 TargetLoweringObjectFile::Initialize(Ctx, TM);
527
528 TextSection // .text
529 = getContext().getMachOSection("__TEXT", "__text",
530 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
531 SectionKind::getText());
532 DataSection // .data
533 = getContext().getMachOSection("__DATA", "__data", 0,
534 SectionKind::getDataRel());
535
536 TLSDataSection // .tdata
537 = getContext().getMachOSection("__DATA", "__thread_data",
538 MCSectionMachO::S_THREAD_LOCAL_REGULAR,
539 SectionKind::getDataRel());
540 TLSBSSSection // .tbss
541 = getContext().getMachOSection("__DATA", "__thread_bss",
542 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
543 SectionKind::getThreadBSS());
544
545 // TODO: Verify datarel below.
546 TLSTLVSection // .tlv
547 = getContext().getMachOSection("__DATA", "__thread_vars",
548 MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
549 SectionKind::getDataRel());
550
551 TLSThreadInitSection
552 = getContext().getMachOSection("__DATA", "__thread_init",
553 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
554 SectionKind::getDataRel());
555
556 CStringSection // .cstring
557 = getContext().getMachOSection("__TEXT", "__cstring",
558 MCSectionMachO::S_CSTRING_LITERALS,
559 SectionKind::getMergeable1ByteCString());
560 UStringSection
561 = getContext().getMachOSection("__TEXT","__ustring", 0,
562 SectionKind::getMergeable2ByteCString());
563 FourByteConstantSection // .literal4
564 = getContext().getMachOSection("__TEXT", "__literal4",
565 MCSectionMachO::S_4BYTE_LITERALS,
566 SectionKind::getMergeableConst4());
567 EightByteConstantSection // .literal8
568 = getContext().getMachOSection("__TEXT", "__literal8",
569 MCSectionMachO::S_8BYTE_LITERALS,
570 SectionKind::getMergeableConst8());
571
572 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
573 // to using it in -static mode.
574 SixteenByteConstantSection = 0;
575 if (TM.getRelocationModel() != Reloc::Static &&
576 TM.getTargetData()->getPointerSizeInBits() == 32)
577 SixteenByteConstantSection = // .literal16
578 getContext().getMachOSection("__TEXT", "__literal16",
579 MCSectionMachO::S_16BYTE_LITERALS,
580 SectionKind::getMergeableConst16());
581
582 ReadOnlySection // .const
583 = getContext().getMachOSection("__TEXT", "__const", 0,
584 SectionKind::getReadOnly());
585
586 TextCoalSection
587 = getContext().getMachOSection("__TEXT", "__textcoal_nt",
588 MCSectionMachO::S_COALESCED |
589 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
590 SectionKind::getText());
591 ConstTextCoalSection
592 = getContext().getMachOSection("__TEXT", "__const_coal",
593 MCSectionMachO::S_COALESCED,
594 SectionKind::getReadOnly());
595 ConstDataSection // .const_data
596 = getContext().getMachOSection("__DATA", "__const", 0,
597 SectionKind::getReadOnlyWithRel());
598 DataCoalSection
599 = getContext().getMachOSection("__DATA","__datacoal_nt",
600 MCSectionMachO::S_COALESCED,
601 SectionKind::getDataRel());
602 DataCommonSection
603 = getContext().getMachOSection("__DATA","__common",
604 MCSectionMachO::S_ZEROFILL,
605 SectionKind::getBSS());
606 DataBSSSection
607 = getContext().getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
608 SectionKind::getBSS());
609
610
611 LazySymbolPointerSection
612 = getContext().getMachOSection("__DATA", "__la_symbol_ptr",
613 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
614 SectionKind::getMetadata());
615 NonLazySymbolPointerSection
616 = getContext().getMachOSection("__DATA", "__nl_symbol_ptr",
617 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
618 SectionKind::getMetadata());
619
620 if (TM.getRelocationModel() == Reloc::Static) {
621 StaticCtorSection
622 = getContext().getMachOSection("__TEXT", "__constructor", 0,
623 SectionKind::getDataRel());
624 StaticDtorSection
625 = getContext().getMachOSection("__TEXT", "__destructor", 0,
626 SectionKind::getDataRel());
627 } else {
628 StaticCtorSection
629 = getContext().getMachOSection("__DATA", "__mod_init_func",
630 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
631 SectionKind::getDataRel());
632 StaticDtorSection
633 = getContext().getMachOSection("__DATA", "__mod_term_func",
634 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
635 SectionKind::getDataRel());
636 }
637
638 // Exception Handling.
639 LSDASection = getContext().getMachOSection("__TEXT", "__gcc_except_tab", 0,
640 SectionKind::getReadOnlyWithRel());
641
642 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
643 CompactUnwindSection =
644 getContext().getMachOSection("__LD", "__compact_unwind",
645 MCSectionMachO::S_ATTR_DEBUG,
646 SectionKind::getReadOnly());
647
648 // Debug Information.
649 DwarfAbbrevSection =
650 getContext().getMachOSection("__DWARF", "__debug_abbrev",
651 MCSectionMachO::S_ATTR_DEBUG,
652 SectionKind::getMetadata());
653 DwarfInfoSection =
654 getContext().getMachOSection("__DWARF", "__debug_info",
655 MCSectionMachO::S_ATTR_DEBUG,
656 SectionKind::getMetadata());
657 DwarfLineSection =
658 getContext().getMachOSection("__DWARF", "__debug_line",
659 MCSectionMachO::S_ATTR_DEBUG,
660 SectionKind::getMetadata());
661 DwarfFrameSection =
662 getContext().getMachOSection("__DWARF", "__debug_frame",
663 MCSectionMachO::S_ATTR_DEBUG,
664 SectionKind::getMetadata());
665 DwarfPubNamesSection =
666 getContext().getMachOSection("__DWARF", "__debug_pubnames",
667 MCSectionMachO::S_ATTR_DEBUG,
668 SectionKind::getMetadata());
669 DwarfPubTypesSection =
670 getContext().getMachOSection("__DWARF", "__debug_pubtypes",
671 MCSectionMachO::S_ATTR_DEBUG,
672 SectionKind::getMetadata());
673 DwarfStrSection =
674 getContext().getMachOSection("__DWARF", "__debug_str",
675 MCSectionMachO::S_ATTR_DEBUG,
676 SectionKind::getMetadata());
677 DwarfLocSection =
678 getContext().getMachOSection("__DWARF", "__debug_loc",
679 MCSectionMachO::S_ATTR_DEBUG,
680 SectionKind::getMetadata());
681 DwarfARangesSection =
682 getContext().getMachOSection("__DWARF", "__debug_aranges",
683 MCSectionMachO::S_ATTR_DEBUG,
684 SectionKind::getMetadata());
685 DwarfRangesSection =
686 getContext().getMachOSection("__DWARF", "__debug_ranges",
687 MCSectionMachO::S_ATTR_DEBUG,
688 SectionKind::getMetadata());
689 DwarfMacroInfoSection =
690 getContext().getMachOSection("__DWARF", "__debug_macinfo",
691 MCSectionMachO::S_ATTR_DEBUG,
692 SectionKind::getMetadata());
693 DwarfDebugInlineSection =
694 getContext().getMachOSection("__DWARF", "__debug_inlined",
695 MCSectionMachO::S_ATTR_DEBUG,
696 SectionKind::getMetadata());
697
698 TLSExtraDataSection = TLSTLVSection;
699 }
700
701 const MCSection *TargetLoweringObjectFileMachO::getEHFrameSection() const {
702 return getContext().getMachOSection("__TEXT", "__eh_frame",
703 MCSectionMachO::S_COALESCED |
704 MCSectionMachO::S_ATTR_NO_TOC |
705 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
706 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
707 SectionKind::getReadOnly());
708 }
709
710348 const MCSection *TargetLoweringObjectFileMachO::
711349 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
712350 Mangler *Mang, const TargetMachine &TM) const {
923561 //===----------------------------------------------------------------------===//
924562 // COFF
925563 //===----------------------------------------------------------------------===//
926
927 TargetLoweringObjectFileCOFF::TargetLoweringObjectFileCOFF()
928 : TargetLoweringObjectFile(),
929 DrectveSection(0),
930 PDataSection(0),
931 XDataSection(0) {
932 }
933
934 void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
935 const TargetMachine &TM) {
936 TargetLoweringObjectFile::Initialize(Ctx, TM);
937 TextSection =
938 getContext().getCOFFSection(".text",
939 COFF::IMAGE_SCN_CNT_CODE |
940 COFF::IMAGE_SCN_MEM_EXECUTE |
941 COFF::IMAGE_SCN_MEM_READ,
942 SectionKind::getText());
943 DataSection =
944 getContext().getCOFFSection(".data",
945 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
946 COFF::IMAGE_SCN_MEM_READ |
947 COFF::IMAGE_SCN_MEM_WRITE,
948 SectionKind::getDataRel());
949 ReadOnlySection =
950 getContext().getCOFFSection(".rdata",
951 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
952 COFF::IMAGE_SCN_MEM_READ,
953 SectionKind::getReadOnly());
954 StaticCtorSection =
955 getContext().getCOFFSection(".ctors",
956 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
957 COFF::IMAGE_SCN_MEM_READ |
958 COFF::IMAGE_SCN_MEM_WRITE,
959 SectionKind::getDataRel());
960 StaticDtorSection =
961 getContext().getCOFFSection(".dtors",
962 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
963 COFF::IMAGE_SCN_MEM_READ |
964 COFF::IMAGE_SCN_MEM_WRITE,
965 SectionKind::getDataRel());
966
967 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
968 // though it contains relocatable pointers. In PIC mode, this is probably a
969 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
970 // adjusted or this should be a data section.
971 LSDASection =
972 getContext().getCOFFSection(".gcc_except_table",
973 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
974 COFF::IMAGE_SCN_MEM_READ,
975 SectionKind::getReadOnly());
976 // Debug info.
977 DwarfAbbrevSection =
978 getContext().getCOFFSection(".debug_abbrev",
979 COFF::IMAGE_SCN_MEM_DISCARDABLE |
980 COFF::IMAGE_SCN_MEM_READ,
981 SectionKind::getMetadata());
982 DwarfInfoSection =
983 getContext().getCOFFSection(".debug_info",
984 COFF::IMAGE_SCN_MEM_DISCARDABLE |
985 COFF::IMAGE_SCN_MEM_READ,
986 SectionKind::getMetadata());
987 DwarfLineSection =
988 getContext().getCOFFSection(".debug_line",
989 COFF::IMAGE_SCN_MEM_DISCARDABLE |
990 COFF::IMAGE_SCN_MEM_READ,
991 SectionKind::getMetadata());
992 DwarfFrameSection =
993 getContext().getCOFFSection(".debug_frame",
994 COFF::IMAGE_SCN_MEM_DISCARDABLE |
995 COFF::IMAGE_SCN_MEM_READ,
996 SectionKind::getMetadata());
997 DwarfPubNamesSection =
998 getContext().getCOFFSection(".debug_pubnames",
999 COFF::IMAGE_SCN_MEM_DISCARDABLE |
1000 COFF::IMAGE_SCN_MEM_READ,
1001 SectionKind::getMetadata());
1002 DwarfPubTypesSection =
1003 getContext().getCOFFSection(".debug_pubtypes",
1004 COFF::IMAGE_SCN_MEM_DISCARDABLE |
1005 COFF::IMAGE_SCN_MEM_READ,
1006 SectionKind::getMetadata());
1007 DwarfStrSection =
1008 getContext().getCOFFSection(".debug_str",
1009 COFF::IMAGE_SCN_MEM_DISCARDABLE |
1010 COFF::IMAGE_SCN_MEM_READ,
1011 SectionKind::getMetadata());
1012 DwarfLocSection =
1013 getContext().getCOFFSection(".debug_loc",
1014 COFF::IMAGE_SCN_MEM_DISCARDABLE |
1015 COFF::IMAGE_SCN_MEM_READ,
1016 SectionKind::getMetadata());
1017 DwarfARangesSection =
1018 getContext().getCOFFSection(".debug_aranges",
1019 COFF::IMAGE_SCN_MEM_DISCARDABLE |
1020 COFF::IMAGE_SCN_MEM_READ,
1021 SectionKind::getMetadata());
1022 DwarfRangesSection =
1023 getContext().getCOFFSection(".debug_ranges",
1024 COFF::IMAGE_SCN_MEM_DISCARDABLE |
1025 COFF::IMAGE_SCN_MEM_READ,
1026 SectionKind::getMetadata());
1027 DwarfMacroInfoSection =
1028 getContext().getCOFFSection(".debug_macinfo",
1029 COFF::IMAGE_SCN_MEM_DISCARDABLE |
1030 COFF::IMAGE_SCN_MEM_READ,
1031 SectionKind::getMetadata());
1032
1033 DrectveSection =
1034 getContext().getCOFFSection(".drectve",
1035 COFF::IMAGE_SCN_LNK_INFO,
1036 SectionKind::getMetadata());
1037
1038 PDataSection =
1039 getContext().getCOFFSection(".pdata",
1040 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1041 COFF::IMAGE_SCN_MEM_READ |
1042 COFF::IMAGE_SCN_MEM_WRITE,
1043 SectionKind::getDataRel());
1044
1045 XDataSection =
1046 getContext().getCOFFSection(".xdata",
1047 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1048 COFF::IMAGE_SCN_MEM_READ |
1049 COFF::IMAGE_SCN_MEM_WRITE,
1050 SectionKind::getDataRel());
1051 }
1052
1053 const MCSection *TargetLoweringObjectFileCOFF::getEHFrameSection() const {
1054 return getContext().getCOFFSection(".eh_frame",
1055 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1056 COFF::IMAGE_SCN_MEM_READ |
1057 COFF::IMAGE_SCN_MEM_WRITE,
1058 SectionKind::getDataRel());
1059 }
1060
1061 const MCSection *TargetLoweringObjectFileCOFF::getWin64EHFuncTableSection(
1062 StringRef suffix) const {
1063 if (suffix == "")
1064 return PDataSection;
1065 return getContext().getCOFFSection((".pdata"+suffix).str(),
1066 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1067 COFF::IMAGE_SCN_MEM_READ |
1068 COFF::IMAGE_SCN_MEM_WRITE,
1069 SectionKind::getDataRel());
1070 }
1071
1072 const MCSection *TargetLoweringObjectFileCOFF::getWin64EHTableSection(
1073 StringRef suffix) const {
1074 if (suffix == "")
1075 return XDataSection;
1076 return getContext().getCOFFSection((".xdata"+suffix).str(),
1077 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1078 COFF::IMAGE_SCN_MEM_READ |
1079 COFF::IMAGE_SCN_MEM_WRITE,
1080 SectionKind::getDataRel());
1081 }
1082
1083564
1084565 static unsigned
1085566 getCOFFSectionFlags(SectionKind K) {
1515 #include "llvm/MC/MCInst.h"
1616 #include "llvm/MC/MCInstPrinter.h"
1717 #include "llvm/MC/MCRegisterInfo.h"
18 #include "llvm/MC/MCSectionCOFF.h"
1819 #include "llvm/MC/MCSectionMachO.h"
1920 #include "llvm/MC/MCSymbol.h"
2021 #include "llvm/ADT/OwningPtr.h"
994995 EmitEOL();
995996 }
996997
998 static const MCSection *getWin64EHTableSection(StringRef suffix,
999 MCContext &context) {
1000 // FIXME: This doesn't belong in MCObjectFileInfo. However,
1001 /// this duplicate code in MCWin64EH.cpp.
1002 if (suffix == "")
1003 return context.getObjectFileInfo()->getXDataSection();
1004 return context.getCOFFSection((".xdata"+suffix).str(),
1005 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
1006 COFF::IMAGE_SCN_MEM_READ |
1007 COFF::IMAGE_SCN_MEM_WRITE,
1008 SectionKind::getDataRel());
1009 }
1010
9971011 void MCAsmStreamer::EmitWin64EHHandlerData() {
9981012 MCStreamer::EmitWin64EHHandlerData();
9991013
10031017 // data block is visible.
10041018 MCWin64EHUnwindInfo *CurFrame = getCurrentW64UnwindInfo();
10051019 StringRef suffix=MCWin64EHUnwindEmitter::GetSectionSuffix(CurFrame->Function);
1006 const MCSection *xdataSect =
1007 getContext().getTargetAsmInfo().getWin64EHTableSection(suffix);
1020 const MCSection *xdataSect = getWin64EHTableSection(suffix, getContext());
10081021 if (xdataSect)
10091022 SwitchSectionNoChange(xdataSect);
10101023
88
99 #include "llvm/MC/MCContext.h"
1010 #include "llvm/MC/MCAsmInfo.h"
11 #include "llvm/MC/MCObjectFileInfo.h"
1112 #include "llvm/MC/MCRegisterInfo.h"
1213 #include "llvm/MC/MCSectionMachO.h"
1314 #include "llvm/MC/MCSectionELF.h"
2728
2829
2930 MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
30 const TargetAsmInfo *tai) :
31 MAI(mai), MRI(mri), TAI(tai),
31 const MCObjectFileInfo *mofi, const TargetAsmInfo *tai) :
32 MAI(mai), MRI(mri), MOFI(mofi), TAI(tai),
3233 Allocator(), Symbols(Allocator), UsedNames(Allocator),
3334 NextUniqueID(0),
3435 CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0),
7474 assert(tai && "Unable to create target assembler!");
7575
7676 // Set up the MCContext for creating symbols and MCExpr's.
77 MCContext *Ctx = new MCContext(*MAI, *MRI, tai);
77 MCContext *Ctx = new MCContext(*MAI, *MRI, 0, tai);
7878 assert(Ctx && "Unable to create MCContext!");
7979
8080 // Set up disassembler.
376376 SourceMgr sourceMgr;
377377 sourceMgr.setDiagHandler(diag_handler, static_cast(this));
378378 sourceMgr.AddNewSourceBuffer(buf, SMLoc()); // ownership of buf handed over
379 MCContext context(*AsmInfo, *MRI, NULL);
379 MCContext context(*AsmInfo, *MRI, NULL, NULL);
380380 OwningPtr streamer(createNullStreamer(context));
381381 OwningPtr genericParser(createMCAsmParser(*Tgt, sourceMgr,
382382 context, *streamer,
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include "llvm/MC/MCDwarf.h"
910 #include "llvm/MC/MCAsmInfo.h"
10 #include "llvm/MC/MCDwarf.h"
11 #include "llvm/MC/MCContext.h"
12 #include "llvm/MC/MCObjectFileInfo.h"
13 #include "llvm/MC/MCObjectWriter.h"
14 #include "llvm/MC/MCRegisterInfo.h"
1115 #include "llvm/MC/MCStreamer.h"
1216 #include "llvm/MC/MCSymbol.h"
1317 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCContext.h"
15 #include "llvm/MC/MCObjectWriter.h"
1618 #include "llvm/Support/Debug.h"
1719 #include "llvm/Support/ErrorHandling.h"
1820 #include "llvm/Support/raw_ostream.h"
195197 MCOS->EmitLabel(SectionEnd);
196198
197199 // Switch back the the dwarf line section.
198 MCOS->SwitchSection(context.getTargetAsmInfo().getDwarfLineSection());
200 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection());
199201
200202 const MCAsmInfo &asmInfo = MCOS->getContext().getAsmInfo();
201203 MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
208210 void MCDwarfFileTable::Emit(MCStreamer *MCOS) {
209211 MCContext &context = MCOS->getContext();
210212 // Switch to the section where the table will be emitted into.
211 MCOS->SwitchSection(context.getTargetAsmInfo().getDwarfLineSection());
213 MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection());
212214
213215 // Create a symbol at the beginning of this section.
214216 MCSymbol *LineStartSym = context.CreateTempSymbol();
687689 bool FrameEmitterImpl::EmitCompactUnwind(MCStreamer &Streamer,
688690 const MCDwarfFrameInfo &Frame) {
689691 MCContext &Context = Streamer.getContext();
692 const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
690693 const TargetAsmInfo &TAI = Context.getTargetAsmInfo();
691694 bool VerboseAsm = Streamer.isVerboseAsm();
692695
719722 if (Frame.Lsda)
720723 Encoding |= 0x40000000;
721724
722 Streamer.SwitchSection(TAI.getCompactUnwindSection());
725 Streamer.SwitchSection(MOFI->getCompactUnwindSection());
723726
724727 // Range Start
725728 unsigned FDEEncoding = TAI.getFDEEncoding(UsingCFI);
766769 unsigned lsdaEncoding) {
767770 MCContext &context = streamer.getContext();
768771 const MCRegisterInfo &MRI = context.getRegisterInfo();
772 const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
769773 const TargetAsmInfo &TAI = context.getTargetAsmInfo();
770774 bool verboseAsm = streamer.isVerboseAsm();
771775
772776 MCSymbol *sectionStart;
773 if (TAI.isFunctionEHFrameSymbolPrivate() || !IsEH)
777 if (MOFI->isFunctionEHFrameSymbolPrivate() || !IsEH)
774778 sectionStart = context.CreateTempSymbol();
775779 else
776780 sectionStart = context.GetOrCreateSymbol(Twine("EH_frame") + Twine(CIENum));
889893 MCContext &context = streamer.getContext();
890894 MCSymbol *fdeStart = context.CreateTempSymbol();
891895 MCSymbol *fdeEnd = context.CreateTempSymbol();
896 const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
892897 const TargetAsmInfo &TAI = context.getTargetAsmInfo();
893898 bool verboseAsm = streamer.isVerboseAsm();
894899
895 if (!TAI.isFunctionEHFrameSymbolPrivate() && IsEH) {
900 if (!MOFI->isFunctionEHFrameSymbolPrivate() && IsEH) {
896901 MCSymbol *EHSym =
897902 context.GetOrCreateSymbol(frame.Function->getName() + Twine(".eh"));
898903 streamer.EmitEHSymAttributes(frame.Function, EHSym);
10071012 bool UsingCFI,
10081013 bool IsEH) {
10091014 MCContext &Context = Streamer.getContext();
1010 const TargetAsmInfo &TAI = Context.getTargetAsmInfo();
1011 const MCSection &Section = IsEH ? *TAI.getEHFrameSection() :
1012 *TAI.getDwarfFrameSection();
1015 MCObjectFileInfo *MOFI =
1016 const_cast(Context.getObjectFileInfo());
1017 const MCSection &Section = IsEH ? *MOFI->getEHFrameSection() :
1018 *MOFI->getDwarfFrameSection();
10131019 Streamer.SwitchSection(&Section);
10141020 MCSymbol *SectionStart = Context.CreateTempSymbol();
10151021 Streamer.EmitLabel(SectionStart);
10211027 const MCSymbol *DummyDebugKey = NULL;
10221028 for (unsigned i = 0, n = Streamer.getNumFrameInfos(); i < n; ++i) {
10231029 const MCDwarfFrameInfo &Frame = Streamer.getFrameInfo(i);
1024 if (IsEH && TAI.getCompactUnwindSection() && Frame.CompactUnwindEncoding &&
1030 if (IsEH && MOFI->getCompactUnwindSection() &&
1031 Frame.CompactUnwindEncoding &&
10251032 Emitter.EmitCompactUnwind(Streamer, Frame)) {
10261033 FDEEnd = NULL;
10271034 continue;
0 //===-- MObjectFileInfo.cpp - Object File Information ---------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/MC/MCObjectFileInfo.h"
10 #include "llvm/MC/MCContext.h"
11 #include "llvm/MC/MCSection.h"
12 #include "llvm/MC/MCSectionCOFF.h"
13 #include "llvm/MC/MCSectionELF.h"
14 #include "llvm/MC/MCSectionMachO.h"
15 #include "llvm/ADT/Triple.h"
16 using namespace llvm;
17
18 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
19 // MachO
20 IsFunctionEHFrameSymbolPrivate = false;
21 SupportsWeakOmittedEHFrame = false;
22
23 // .comm doesn't support alignment before Leopard.
24 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
25 CommDirectiveSupportsAlignment = false;
26
27 TextSection // .text
28 = Ctx->getMachOSection("__TEXT", "__text",
29 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
30 SectionKind::getText());
31 DataSection // .data
32 = Ctx->getMachOSection("__DATA", "__data", 0,
33 SectionKind::getDataRel());
34
35 TLSDataSection // .tdata
36 = Ctx->getMachOSection("__DATA", "__thread_data",
37 MCSectionMachO::S_THREAD_LOCAL_REGULAR,
38 SectionKind::getDataRel());
39 TLSBSSSection // .tbss
40 = Ctx->getMachOSection("__DATA", "__thread_bss",
41 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
42 SectionKind::getThreadBSS());
43
44 // TODO: Verify datarel below.
45 TLSTLVSection // .tlv
46 = Ctx->getMachOSection("__DATA", "__thread_vars",
47 MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
48 SectionKind::getDataRel());
49
50 TLSThreadInitSection
51 = Ctx->getMachOSection("__DATA", "__thread_init",
52 MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
53 SectionKind::getDataRel());
54
55 CStringSection // .cstring
56 = Ctx->getMachOSection("__TEXT", "__cstring",
57 MCSectionMachO::S_CSTRING_LITERALS,
58 SectionKind::getMergeable1ByteCString());
59 UStringSection
60 = Ctx->getMachOSection("__TEXT","__ustring", 0,
61 SectionKind::getMergeable2ByteCString());
62 FourByteConstantSection // .literal4
63 = Ctx->getMachOSection("__TEXT", "__literal4",
64 MCSectionMachO::S_4BYTE_LITERALS,
65 SectionKind::getMergeableConst4());
66 EightByteConstantSection // .literal8
67 = Ctx->getMachOSection("__TEXT", "__literal8",
68 MCSectionMachO::S_8BYTE_LITERALS,
69 SectionKind::getMergeableConst8());
70
71 // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
72 // to using it in -static mode.
73 SixteenByteConstantSection = 0;
74 if (RelocM != Reloc::Static &&
75 T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64)
76 SixteenByteConstantSection = // .literal16
77 Ctx->getMachOSection("__TEXT", "__literal16",
78 MCSectionMachO::S_16BYTE_LITERALS,
79 SectionKind::getMergeableConst16());
80
81 ReadOnlySection // .const
82 = Ctx->getMachOSection("__TEXT", "__const", 0,
83 SectionKind::getReadOnly());
84
85 TextCoalSection
86 = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
87 MCSectionMachO::S_COALESCED |
88 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
89 SectionKind::getText());
90 ConstTextCoalSection
91 = Ctx->getMachOSection("__TEXT", "__const_coal",
92 MCSectionMachO::S_COALESCED,
93 SectionKind::getReadOnly());
94 ConstDataSection // .const_data
95 = Ctx->getMachOSection("__DATA", "__const", 0,
96 SectionKind::getReadOnlyWithRel());
97 DataCoalSection
98 = Ctx->getMachOSection("__DATA","__datacoal_nt",
99 MCSectionMachO::S_COALESCED,
100 SectionKind::getDataRel());
101 DataCommonSection
102 = Ctx->getMachOSection("__DATA","__common",
103 MCSectionMachO::S_ZEROFILL,
104 SectionKind::getBSS());
105 DataBSSSection
106 = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
107 SectionKind::getBSS());
108
109
110 LazySymbolPointerSection
111 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
112 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
113 SectionKind::getMetadata());
114 NonLazySymbolPointerSection
115 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
116 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
117 SectionKind::getMetadata());
118
119 if (RelocM == Reloc::Static) {
120 StaticCtorSection
121 = Ctx->getMachOSection("__TEXT", "__constructor", 0,
122 SectionKind::getDataRel());
123 StaticDtorSection
124 = Ctx->getMachOSection("__TEXT", "__destructor", 0,
125 SectionKind::getDataRel());
126 } else {
127 StaticCtorSection
128 = Ctx->getMachOSection("__DATA", "__mod_init_func",
129 MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
130 SectionKind::getDataRel());
131 StaticDtorSection
132 = Ctx->getMachOSection("__DATA", "__mod_term_func",
133 MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
134 SectionKind::getDataRel());
135 }
136
137 // Exception Handling.
138 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
139 SectionKind::getReadOnlyWithRel());
140
141 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
142 CompactUnwindSection =
143 Ctx->getMachOSection("__LD", "__compact_unwind",
144 MCSectionMachO::S_ATTR_DEBUG,
145 SectionKind::getReadOnly());
146
147 // Debug Information.
148 DwarfAbbrevSection =
149 Ctx->getMachOSection("__DWARF", "__debug_abbrev",
150 MCSectionMachO::S_ATTR_DEBUG,
151 SectionKind::getMetadata());
152 DwarfInfoSection =
153 Ctx->getMachOSection("__DWARF", "__debug_info",
154 MCSectionMachO::S_ATTR_DEBUG,
155 SectionKind::getMetadata());
156 DwarfLineSection =
157 Ctx->getMachOSection("__DWARF", "__debug_line",
158 MCSectionMachO::S_ATTR_DEBUG,
159 SectionKind::getMetadata());
160 DwarfFrameSection =
161 Ctx->getMachOSection("__DWARF", "__debug_frame",
162 MCSectionMachO::S_ATTR_DEBUG,
163 SectionKind::getMetadata());
164 DwarfPubNamesSection =
165 Ctx->getMachOSection("__DWARF", "__debug_pubnames",
166 MCSectionMachO::S_ATTR_DEBUG,
167 SectionKind::getMetadata());
168 DwarfPubTypesSection =
169 Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
170 MCSectionMachO::S_ATTR_DEBUG,
171 SectionKind::getMetadata());
172 DwarfStrSection =
173 Ctx->getMachOSection("__DWARF", "__debug_str",
174 MCSectionMachO::S_ATTR_DEBUG,
175 SectionKind::getMetadata());
176 DwarfLocSection =
177 Ctx->getMachOSection("__DWARF", "__debug_loc",
178 MCSectionMachO::S_ATTR_DEBUG,
179 SectionKind::getMetadata());
180 DwarfARangesSection =
181 Ctx->getMachOSection("__DWARF", "__debug_aranges",
182 MCSectionMachO::S_ATTR_DEBUG,
183 SectionKind::getMetadata());
184 DwarfRangesSection =
185 Ctx->getMachOSection("__DWARF", "__debug_ranges",
186 MCSectionMachO::S_ATTR_DEBUG,
187 SectionKind::getMetadata());
188 DwarfMacroInfoSection =
189 Ctx->getMachOSection("__DWARF", "__debug_macinfo",
190 MCSectionMachO::S_ATTR_DEBUG,
191 SectionKind::getMetadata());
192 DwarfDebugInlineSection =
193 Ctx->getMachOSection("__DWARF", "__debug_inlined",
194 MCSectionMachO::S_ATTR_DEBUG,
195 SectionKind::getMetadata());
196
197 TLSExtraDataSection = TLSTLVSection;
198 }
199
200 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
201 // ELF
202 BSSSection =
203 Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
204 ELF::SHF_WRITE |ELF::SHF_ALLOC,
205 SectionKind::getBSS());
206
207 TextSection =
208 Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
209 ELF::SHF_EXECINSTR |
210 ELF::SHF_ALLOC,
211 SectionKind::getText());
212
213 DataSection =
214 Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
215 ELF::SHF_WRITE |ELF::SHF_ALLOC,
216 SectionKind::getDataRel());
217
218 ReadOnlySection =
219 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
220 ELF::SHF_ALLOC,
221 SectionKind::getReadOnly());
222
223 TLSDataSection =
224 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
225 ELF::SHF_ALLOC | ELF::SHF_TLS |
226 ELF::SHF_WRITE,
227 SectionKind::getThreadData());
228
229 TLSBSSSection =
230 Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
231 ELF::SHF_ALLOC | ELF::SHF_TLS |
232 ELF::SHF_WRITE,
233 SectionKind::getThreadBSS());
234
235 DataRelSection =
236 Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
237 ELF::SHF_ALLOC |ELF::SHF_WRITE,
238 SectionKind::getDataRel());
239
240 DataRelLocalSection =
241 Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
242 ELF::SHF_ALLOC |ELF::SHF_WRITE,
243 SectionKind::getDataRelLocal());
244
245 DataRelROSection =
246 Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
247 ELF::SHF_ALLOC |ELF::SHF_WRITE,
248 SectionKind::getReadOnlyWithRel());
249
250 DataRelROLocalSection =
251 Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
252 ELF::SHF_ALLOC |ELF::SHF_WRITE,
253 SectionKind::getReadOnlyWithRelLocal());
254
255 MergeableConst4Section =
256 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
257 ELF::SHF_ALLOC |ELF::SHF_MERGE,
258 SectionKind::getMergeableConst4());
259
260 MergeableConst8Section =
261 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
262 ELF::SHF_ALLOC |ELF::SHF_MERGE,
263 SectionKind::getMergeableConst8());
264
265 MergeableConst16Section =
266 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
267 ELF::SHF_ALLOC |ELF::SHF_MERGE,
268 SectionKind::getMergeableConst16());
269
270 StaticCtorSection =
271 Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
272 ELF::SHF_ALLOC |ELF::SHF_WRITE,
273 SectionKind::getDataRel());
274
275 StaticDtorSection =
276 Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
277 ELF::SHF_ALLOC |ELF::SHF_WRITE,
278 SectionKind::getDataRel());
279
280 // Exception Handling Sections.
281
282 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
283 // it contains relocatable pointers. In PIC mode, this is probably a big
284 // runtime hit for C++ apps. Either the contents of the LSDA need to be
285 // adjusted or this should be a data section.
286 LSDASection =
287 Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
288 ELF::SHF_ALLOC,
289 SectionKind::getReadOnly());
290
291 // Debug Info Sections.
292 DwarfAbbrevSection =
293 Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
294 SectionKind::getMetadata());
295 DwarfInfoSection =
296 Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
297 SectionKind::getMetadata());
298 DwarfLineSection =
299 Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
300 SectionKind::getMetadata());
301 DwarfFrameSection =
302 Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
303 SectionKind::getMetadata());
304 DwarfPubNamesSection =
305 Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
306 SectionKind::getMetadata());
307 DwarfPubTypesSection =
308 Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
309 SectionKind::getMetadata());
310 DwarfStrSection =
311 Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS, 0,
312 SectionKind::getMetadata());
313 DwarfLocSection =
314 Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
315 SectionKind::getMetadata());
316 DwarfARangesSection =
317 Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
318 SectionKind::getMetadata());
319 DwarfRangesSection =
320 Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
321 SectionKind::getMetadata());
322 DwarfMacroInfoSection =
323 Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
324 SectionKind::getMetadata());
325 }
326
327
328 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
329 // COFF
330 TextSection =
331 Ctx->getCOFFSection(".text",
332 COFF::IMAGE_SCN_CNT_CODE |
333 COFF::IMAGE_SCN_MEM_EXECUTE |
334 COFF::IMAGE_SCN_MEM_READ,
335 SectionKind::getText());
336 DataSection =
337 Ctx->getCOFFSection(".data",
338 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
339 COFF::IMAGE_SCN_MEM_READ |
340 COFF::IMAGE_SCN_MEM_WRITE,
341 SectionKind::getDataRel());
342 ReadOnlySection =
343 Ctx->getCOFFSection(".rdata",
344 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
345 COFF::IMAGE_SCN_MEM_READ,
346 SectionKind::getReadOnly());
347 StaticCtorSection =
348 Ctx->getCOFFSection(".ctors",
349 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
350 COFF::IMAGE_SCN_MEM_READ |
351 COFF::IMAGE_SCN_MEM_WRITE,
352 SectionKind::getDataRel());
353 StaticDtorSection =
354 Ctx->getCOFFSection(".dtors",
355 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
356 COFF::IMAGE_SCN_MEM_READ |
357 COFF::IMAGE_SCN_MEM_WRITE,
358 SectionKind::getDataRel());
359
360 // FIXME: We're emitting LSDA info into a readonly section on COFF, even
361 // though it contains relocatable pointers. In PIC mode, this is probably a
362 // big runtime hit for C++ apps. Either the contents of the LSDA need to be
363 // adjusted or this should be a data section.
364 LSDASection =
365 Ctx->getCOFFSection(".gcc_except_table",
366 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
367 COFF::IMAGE_SCN_MEM_READ,
368 SectionKind::getReadOnly());
369
370 // Debug info.
371 DwarfAbbrevSection =
372 Ctx->getCOFFSection(".debug_abbrev",
373 COFF::IMAGE_SCN_MEM_DISCARDABLE |
374 COFF::IMAGE_SCN_MEM_READ,
375 SectionKind::getMetadata());
376 DwarfInfoSection =
377 Ctx->getCOFFSection(".debug_info",
378 COFF::IMAGE_SCN_MEM_DISCARDABLE |
379 COFF::IMAGE_SCN_MEM_READ,
380 SectionKind::getMetadata());
381 DwarfLineSection =
382 Ctx->getCOFFSection(".debug_line",
383 COFF::IMAGE_SCN_MEM_DISCARDABLE |
384 COFF::IMAGE_SCN_MEM_READ,
385 SectionKind::getMetadata());
386 DwarfFrameSection =
387 Ctx->getCOFFSection(".debug_frame",
388 COFF::IMAGE_SCN_MEM_DISCARDABLE |
389 COFF::IMAGE_SCN_MEM_READ,
390 SectionKind::getMetadata());
391 DwarfPubNamesSection =
392 Ctx->getCOFFSection(".debug_pubnames",
393 COFF::IMAGE_SCN_MEM_DISCARDABLE |
394 COFF::IMAGE_SCN_MEM_READ,
395 SectionKind::getMetadata());
396 DwarfPubTypesSection =
397 Ctx->getCOFFSection(".debug_pubtypes",
398 COFF::IMAGE_SCN_MEM_DISCARDABLE |
399 COFF::IMAGE_SCN_MEM_READ,
400 SectionKind::getMetadata());
401 DwarfStrSection =
402 Ctx->getCOFFSection(".debug_str",
403 COFF::IMAGE_SCN_MEM_DISCARDABLE |
404 COFF::IMAGE_SCN_MEM_READ,
405 SectionKind::getMetadata());
406 DwarfLocSection =
407 Ctx->getCOFFSection(".debug_loc",
408 COFF::IMAGE_SCN_MEM_DISCARDABLE |
409 COFF::IMAGE_SCN_MEM_READ,
410 SectionKind::getMetadata());
411 DwarfARangesSection =
412 Ctx->getCOFFSection(".debug_aranges",
413 COFF::IMAGE_SCN_MEM_DISCARDABLE |
414 COFF::IMAGE_SCN_MEM_READ,
415 SectionKind::getMetadata());
416 DwarfRangesSection =
417 Ctx->getCOFFSection(".debug_ranges",
418 COFF::IMAGE_SCN_MEM_DISCARDABLE |
419 COFF::IMAGE_SCN_MEM_READ,
420 SectionKind::getMetadata());
421 DwarfMacroInfoSection =
422 Ctx->getCOFFSection(".debug_macinfo",
423 COFF::IMAGE_SCN_MEM_DISCARDABLE |
424 COFF::IMAGE_SCN_MEM_READ,
425 SectionKind::getMetadata());
426
427 DrectveSection =
428 Ctx->getCOFFSection(".drectve",
429 COFF::IMAGE_SCN_LNK_INFO,
430 SectionKind::getMetadata());
431
432 PDataSection =
433 Ctx->getCOFFSection(".pdata",
434 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
435 COFF::IMAGE_SCN_MEM_READ |
436 COFF::IMAGE_SCN_MEM_WRITE,
437 SectionKind::getDataRel());
438
439 XDataSection =
440 Ctx->getCOFFSection(".xdata",
441 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
442 COFF::IMAGE_SCN_MEM_READ |
443 COFF::IMAGE_SCN_MEM_WRITE,
444 SectionKind::getDataRel());
445 }
446
447 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
448 MCContext &ctx) {
449 RelocM = relocm;
450 Ctx = &ctx;
451
452 // Common.
453 CommDirectiveSupportsAlignment = true;
454 SupportsWeakOmittedEHFrame = true;
455 IsFunctionEHFrameSymbolPrivate = true;
456
457 Triple T(TT);
458 Triple::ArchType Arch = T.getArch();
459 // FIXME: Checking for Arch here to filter out bogus triples such as
460 // cellspu-apple-darwin. Perhaps we should fix in Triple?
461 if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
462 Arch == Triple::arm || Arch == Triple::thumb ||
463 Arch == Triple::ppc || Arch == Triple::ppc64 ||
464 Arch == Triple::UnknownArch) &&
465 (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
466 Env = IsMachO;
467 InitMachOMCObjectFileInfo(T);
468 } else if (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
469 T.getOS() == Triple::Win32) {
470 Env = IsCOFF;
471 InitCOFFMCObjectFileInfo(T);
472 } else {
473 Env = IsELF;
474 InitELFMCObjectFileInfo(T);
475 }
476 }
477
478 void MCObjectFileInfo::InitEHFrameSection() {
479 if (Env == IsMachO)
480 EHFrameSection =
481 Ctx->getMachOSection("__TEXT", "__eh_frame",
482 MCSectionMachO::S_COALESCED |
483 MCSectionMachO::S_ATTR_NO_TOC |
484 MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
485 MCSectionMachO::S_ATTR_LIVE_SUPPORT,
486 SectionKind::getReadOnly());
487 else if (Env == IsELF)
488 EHFrameSection =
489 Ctx->getELFSection(".eh_frame", ELF::SHT_PROGBITS,
490 ELF::SHF_ALLOC,
491 SectionKind::getDataRel());
492 else
493 EHFrameSection =
494 Ctx->getCOFFSection(".eh_frame",
495 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
496 COFF::IMAGE_SCN_MEM_READ |
497 COFF::IMAGE_SCN_MEM_WRITE,
498 SectionKind::getDataRel());
499 }
2222 #include "llvm/MC/MCParser/AsmLexer.h"
2323 #include "llvm/MC/MCParser/MCAsmParser.h"
2424 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
25 #include "llvm/MC/MCRegisterInfo.h"
2526 #include "llvm/MC/MCSectionMachO.h"
2627 #include "llvm/MC/MCStreamer.h"
2728 #include "llvm/MC/MCSymbol.h"
99 #include "llvm/MC/MCWin64EH.h"
1010 #include "llvm/MC/MCStreamer.h"
1111 #include "llvm/MC/MCContext.h"
12 #include "llvm/MC/MCObjectFileInfo.h"
1213 #include "llvm/MC/MCSymbol.h"
1314 #include "llvm/MC/MCSectionCOFF.h"
1415 #include "llvm/MC/MCExpr.h"
15 #include "llvm/Target/TargetAsmInfo.h"
16 #include "llvm/ADT/Twine.h"
1617
1718 namespace llvm {
1819
219220 return "";
220221 }
221222
223 static const MCSection *getWin64EHTableSection(StringRef suffix,
224 MCContext &context) {
225 if (suffix == "")
226 return context.getObjectFileInfo()->getXDataSection();
227
228 return context.getCOFFSection((".xdata"+suffix).str(),
229 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
230 COFF::IMAGE_SCN_MEM_READ |
231 COFF::IMAGE_SCN_MEM_WRITE,
232 SectionKind::getDataRel());
233 }
234
235 static const MCSection *getWin64EHFuncTableSection(StringRef suffix,
236 MCContext &context) {
237 if (suffix == "")
238 return context.getObjectFileInfo()->getPDataSection();
239 return context.getCOFFSection((".pdata"+suffix).str(),
240 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
241 COFF::IMAGE_SCN_MEM_READ |
242 COFF::IMAGE_SCN_MEM_WRITE,
243 SectionKind::getDataRel());
244 }
245
222246 void MCWin64EHUnwindEmitter::EmitUnwindInfo(MCStreamer &streamer,
223247 MCWin64EHUnwindInfo *info) {
224248 // Switch sections (the static function above is meant to be called from
225249 // here and from Emit().
226250 MCContext &context = streamer.getContext();
227 const TargetAsmInfo &TAI = context.getTargetAsmInfo();
228251 const MCSection *xdataSect =
229 TAI.getWin64EHTableSection(GetSectionSuffix(info->Function));
252 getWin64EHTableSection(GetSectionSuffix(info->Function), context);
230253 streamer.SwitchSection(xdataSect);
231254
232255 llvm::EmitUnwindInfo(streamer, info);
235258 void MCWin64EHUnwindEmitter::Emit(MCStreamer &streamer) {
236259 MCContext &context = streamer.getContext();
237260 // Emit the unwind info structs first.
238 const TargetAsmInfo &TAI = context.getTargetAsmInfo();
239261 for (unsigned i = 0; i < streamer.getNumW64UnwindInfos(); ++i) {
240262 MCWin64EHUnwindInfo &info = streamer.getW64UnwindInfo(i);
241263 const MCSection *xdataSect =
242 TAI.getWin64EHTableSection(GetSectionSuffix(info.Function));
264 getWin64EHTableSection(GetSectionSuffix(info.Function), context);
243265 streamer.SwitchSection(xdataSect);
244266 llvm::EmitUnwindInfo(streamer, &info);
245267 }
247269 for (unsigned i = 0; i < streamer.getNumW64UnwindInfos(); ++i) {
248270 MCWin64EHUnwindInfo &info = streamer.getW64UnwindInfo(i);
249271 const MCSection *pdataSect =
250 TAI.getWin64EHFuncTableSection(GetSectionSuffix(info.Function));
272 getWin64EHFuncTableSection(GetSectionSuffix(info.Function), context);
251273 streamer.SwitchSection(pdataSect);
252274 EmitRuntimeFunction(streamer, &info);
253275 }
154154 TargetRegistry::RegisterMCCodeGenInfo(TheARMTarget, createARMMCCodeGenInfo);
155155 TargetRegistry::RegisterMCCodeGenInfo(TheThumbTarget, createARMMCCodeGenInfo);
156156 }
157
3636 #include "llvm/MC/MCAsmInfo.h"
3737 #include "llvm/MC/MCContext.h"
3838 #include "llvm/MC/MCInstrInfo.h"
39 #include "llvm/MC/MCObjectFileInfo.h"
3940 #include "llvm/MC/MCRegisterInfo.h"
4041 #include "llvm/MC/MCSubtargetInfo.h"
4142 #include "llvm/MC/MCSymbol.h"
9192 const Module *TheModule;
9293 const MCAsmInfo* TAsm;
9394 const MCRegisterInfo *MRI;
95 const MCObjectFileInfo *MOFI;
9496 MCContext *TCtx;
9597 const TargetData* TD;
9698
110112 static char ID;
111113 explicit CWriter(formatted_raw_ostream &o)
112114 : FunctionPass(ID), Out(o), IL(0), Mang(0), LI(0),
113 TheModule(0), TAsm(0), MRI(0), TCtx(0), TD(0), OpaqueCounter(0),
114 NextAnonValueNumber(0) {
115 TheModule(0), TAsm(0), MRI(0), MOFI(0), TCtx(0), TD(0),
116 OpaqueCounter(0), NextAnonValueNumber(0) {
115117 initializeLoopInfoPass(*PassRegistry::getPassRegistry());
116118 FPCounter = 0;
117119 }
151153 delete TCtx;
152154 delete TAsm;
153155 delete MRI;
156 delete MOFI;
154157 FPConstantMap.clear();
155158 ByValParams.clear();
156159 intrinsicPrototypesAlreadyGenerated.clear();
16721675 #endif
16731676 TAsm = new CBEMCAsmInfo();
16741677 MRI = new MCRegisterInfo();
1675 TCtx = new MCContext(*TAsm, *MRI, NULL);
1678 TCtx = new MCContext(*TAsm, *MRI, NULL, NULL);
16761679 Mang = new Mangler(*TCtx, *TD);
16771680
16781681 // Keep track of which functions are static ctors/dtors so they can have
3434 // Generic Code
3535 //===----------------------------------------------------------------------===//
3636
37 TargetLoweringObjectFile::TargetLoweringObjectFile() :
38 Ctx(0),
39 TextSection(0),
40 DataSection(0),
41 BSSSection(0),
42 ReadOnlySection(0),
43 StaticCtorSection(0),
44 StaticDtorSection(0),
45 LSDASection(0),
46 CompactUnwindSection(0),
47 DwarfAbbrevSection(0),
48 DwarfInfoSection(0),
49 DwarfLineSection(0),
50 DwarfFrameSection(0),
51 DwarfPubNamesSection(0),
52 DwarfPubTypesSection(0),
53 DwarfDebugInlineSection(0),
54 DwarfStrSection(0),
55 DwarfLocSection(0),
56 DwarfARangesSection(0),
57 DwarfRangesSection(0),
58 DwarfMacroInfoSection(0),
59 TLSExtraDataSection(0),
60 CommDirectiveSupportsAlignment(true),
61 SupportsWeakOmittedEHFrame(true),
62 IsFunctionEHFrameSymbolPrivate(true) {
63 }
64
37 /// Initialize - this method must be called before any actual lowering is
38 /// done. This specifies the current context for codegen, and gives the
39 /// lowering implementations a chance to set up their default sections.
40 void TargetLoweringObjectFile::Initialize(MCContext &ctx,
41 const TargetMachine &TM) {
42 Ctx = &ctx;
43 InitMCObjectFileInfo(TM.getTargetTriple(), TM.getRelocationModel(), *Ctx);
44 }
45
6546 TargetLoweringObjectFile::~TargetLoweringObjectFile() {
6647 }
6748
None ; RUN: llc < %s -march=ppc32 -mtriple=ppc-apple-darwin | FileCheck %s
0 ; RUN: llc < %s -march=ppc32 -mtriple=powerpc-apple-darwin | FileCheck %s
11
22 ; ModuleID = '/Volumes/MacOS9/tests/WebKit/JavaScriptCore/profiler/ProfilerServer.mm'
33
1717 #include "llvm/MC/MCCodeEmitter.h"
1818 #include "llvm/MC/MCInstPrinter.h"
1919 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCObjectFileInfo.h"
21 #include "llvm/MC/MCRegisterInfo.h"
2022 #include "llvm/MC/MCSectionMachO.h"
2123 #include "llvm/MC/MCStreamer.h"
2224 #include "llvm/MC/MCSubtargetInfo.h"
345347 }
346348
347349 const TargetAsmInfo *tai = new TargetAsmInfo(*TM);
348 MCContext Ctx(*MAI, *MRI, tai);
350 // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
351 // MCObjectFileInfo needs a MCContext reference in order to initialize itself.
352 OwningPtr MOFI(new MCObjectFileInfo());
353 MCContext Ctx(*MAI, *MRI, MOFI.get(), tai);
354 MOFI->InitMCObjectFileInfo(TripleName, RelocModel, Ctx);
355
349356 if (SaveTempLabels)
350357 Ctx.setAllowTemporaryLabels(false);
351358
313313
314314 // mark which symbols can not be internalized
315315 MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),
316 NULL);
316 NULL, NULL);
317317 Mangler mangler(Context, *_target->getTargetData());
318318 std::vector mustPreserveList;
319319 SmallPtrSet asmUsed;
664664 bool LTOModule::ParseSymbols() {
665665 // Use mangler to add GlobalPrefix to names to match linker names.
666666 MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),
667 NULL);
667 NULL, NULL);
668668 Mangler mangler(Context, *_target->getTargetData());
669669
670670 // add functions