1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/MC/SectionKind.h"
30 class TargetLoweringObjectFile {
34 TargetLoweringObjectFile();
36 /// TextSection - Section directive for standard text.
38 const MCSection *TextSection;
40 /// DataSection - Section directive for standard data.
42 const MCSection *DataSection;
44 /// BSSSection - Section that is default initialized to zero.
45 const MCSection *BSSSection;
47 /// ReadOnlySection - Section that is readonly and can contain arbitrary
48 /// initialized data. Targets are not required to have a readonly section.
49 /// If they don't, various bits of code will fall back to using the data
50 /// section for constants.
51 const MCSection *ReadOnlySection;
53 /// StaticCtorSection - This section contains the static constructor pointer
55 const MCSection *StaticCtorSection;
57 /// StaticDtorSection - This section contains the static destructor pointer
59 const MCSection *StaticDtorSection;
61 /// LSDASection - If exception handling is supported by the target, this is
62 /// the section the Language Specific Data Area information is emitted to.
63 const MCSection *LSDASection;
65 /// EHFrameSection - If exception handling is supported by the target, this is
66 /// the section the EH Frame is emitted to.
67 const MCSection *EHFrameSection;
69 // Dwarf sections for debug info. If a target supports debug info, these must
71 const MCSection *DwarfAbbrevSection;
72 const MCSection *DwarfInfoSection;
73 const MCSection *DwarfLineSection;
74 const MCSection *DwarfFrameSection;
75 const MCSection *DwarfPubNamesSection;
76 const MCSection *DwarfPubTypesSection;
77 const MCSection *DwarfDebugInlineSection;
78 const MCSection *DwarfStrSection;
79 const MCSection *DwarfLocSection;
80 const MCSection *DwarfARangesSection;
81 const MCSection *DwarfRangesSection;
82 const MCSection *DwarfMacroInfoSection;
86 MCContext &getContext() const { return *Ctx; }
89 virtual ~TargetLoweringObjectFile();
91 /// Initialize - this method must be called before any actual lowering is
92 /// done. This specifies the current context for codegen, and gives the
93 /// lowering implementations a chance to set up their default sections.
94 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
99 const MCSection *getTextSection() const { return TextSection; }
100 const MCSection *getDataSection() const { return DataSection; }
101 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
102 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
103 const MCSection *getLSDASection() const { return LSDASection; }
104 const MCSection *getEHFrameSection() const { return EHFrameSection; }
105 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
106 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
107 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
108 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
109 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
110 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
111 const MCSection *getDwarfDebugInlineSection() const {
112 return DwarfDebugInlineSection;
114 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
115 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
116 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
117 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
118 const MCSection *getDwarfMacroInfoSection() const {
119 return DwarfMacroInfoSection;
122 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
123 /// decide not to emit the UsedDirective for some symbols in llvm.used.
124 /// FIXME: REMOVE this (rdar://7071300)
125 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
130 /// getSectionForConstant - Given a constant with the SectionKind, return a
131 /// section that it should be placed in.
132 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
134 /// getKindForGlobal - Classify the specified global variable into a set of
135 /// target independent categories embodied in SectionKind.
136 static SectionKind getKindForGlobal(const GlobalValue *GV,
137 const TargetMachine &TM);
139 /// SectionForGlobal - This method computes the appropriate section to emit
140 /// the specified global variable or function definition. This should not
141 /// be passed external (or available externally) globals.
142 const MCSection *SectionForGlobal(const GlobalValue *GV,
143 SectionKind Kind, Mangler *Mang,
144 const TargetMachine &TM) const;
146 /// SectionForGlobal - This method computes the appropriate section to emit
147 /// the specified global variable or function definition. This should not
148 /// be passed external (or available externally) globals.
149 const MCSection *SectionForGlobal(const GlobalValue *GV,
151 const TargetMachine &TM) const {
152 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
157 /// getExplicitSectionGlobal - Targets should implement this method to assign
158 /// a section to globals with an explicit section specfied. The
159 /// implementation of this method can assume that GV->hasSection() is true.
160 virtual const MCSection *
161 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
162 Mangler *Mang, const TargetMachine &TM) const = 0;
164 /// getSpecialCasedSectionGlobals - Allow the target to completely override
165 /// section assignment of a global.
166 virtual const MCSection *
167 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
168 SectionKind Kind) const {
172 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
173 /// into a string that can be printed to the assembly file after the
174 /// ".section foo" part of a section directive.
175 virtual void getSectionFlagsAsString(SectionKind Kind,
176 SmallVectorImpl<char> &Str,
177 const TargetAsmInfo &TAI) const {
181 virtual const MCSection *
182 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
183 Mangler *Mang, const TargetMachine &TM) const;
189 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
190 bool AtIsCommentChar; // True if @ is the comment character on this target.
193 /// TLSDataSection - Section directive for Thread Local data.
195 const MCSection *TLSDataSection; // Defaults to ".tdata".
197 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
198 /// Null if this target doesn't support a BSS section.
200 const MCSection *TLSBSSSection; // Defaults to ".tbss".
202 const MCSection *DataRelSection;
203 const MCSection *DataRelLocalSection;
204 const MCSection *DataRelROSection;
205 const MCSection *DataRelROLocalSection;
207 const MCSection *MergeableConst4Section;
208 const MCSection *MergeableConst8Section;
209 const MCSection *MergeableConst16Section;
212 const MCSection *getELFSection(const char *Name, bool isDirective,
213 SectionKind Kind) const;
215 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
217 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
218 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
219 bool hasCrazyBSS = false)
220 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
222 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
224 /// getSectionForConstant - Given a constant with the SectionKind, return a
225 /// section that it should be placed in.
226 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
229 virtual const MCSection *
230 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
231 Mangler *Mang, const TargetMachine &TM) const;
233 void getSectionFlagsAsString(SectionKind Kind,
234 SmallVectorImpl<char> &Str,
235 const TargetAsmInfo &TAI) const;
237 virtual const MCSection *
238 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
239 Mangler *Mang, const TargetMachine &TM) const;
244 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
245 const MCSection *CStringSection;
246 const MCSection *UStringSection;
247 const MCSection *TextCoalSection;
248 const MCSection *ConstTextCoalSection;
249 const MCSection *ConstDataCoalSection;
250 const MCSection *ConstDataSection;
251 const MCSection *DataCoalSection;
252 const MCSection *FourByteConstantSection;
253 const MCSection *EightByteConstantSection;
254 const MCSection *SixteenByteConstantSection;
257 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
259 virtual const MCSection *
260 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
261 Mangler *Mang, const TargetMachine &TM) const;
263 virtual const MCSection *
264 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
265 Mangler *Mang, const TargetMachine &TM) const;
267 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
269 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
270 /// decide not to emit the UsedDirective for some symbols in llvm.used.
271 /// FIXME: REMOVE this (rdar://7071300)
272 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
275 /// getMachOSection - Return the MCSection for the specified mach-o section.
276 /// FIXME: Switch this to a semantic view eventually.
277 const MCSection *getMachOSection(const char *Name, bool isDirective,
278 SectionKind K) const;
283 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
285 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
287 virtual const MCSection *
288 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
289 Mangler *Mang, const TargetMachine &TM) const;
291 virtual void getSectionFlagsAsString(SectionKind Kind,
292 SmallVectorImpl<char> &Str,
293 const TargetAsmInfo &TAI) const;
295 virtual const MCSection *
296 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
297 Mangler *Mang, const TargetMachine &TM) const;
299 /// getCOFFSection - Return the MCSection for the specified COFF section.
300 /// FIXME: Switch this to a semantic view eventually.
301 const MCSection *getCOFFSection(const char *Name, bool isDirective,
302 SectionKind K) const;
305 } // end namespace llvm