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"
29 class TargetLoweringObjectFile {
33 TargetLoweringObjectFile();
35 /// TextSection - Section directive for standard text.
37 const MCSection *TextSection;
39 /// DataSection - Section directive for standard data.
41 const MCSection *DataSection;
43 /// BSSSection - Section that is default initialized to zero.
44 const MCSection *BSSSection;
46 /// ReadOnlySection - Section that is readonly and can contain arbitrary
47 /// initialized data. Targets are not required to have a readonly section.
48 /// If they don't, various bits of code will fall back to using the data
49 /// section for constants.
50 const MCSection *ReadOnlySection;
52 /// StaticCtorSection - This section contains the static constructor pointer
54 const MCSection *StaticCtorSection;
56 /// StaticDtorSection - This section contains the static destructor pointer
58 const MCSection *StaticDtorSection;
60 /// LSDASection - If exception handling is supported by the target, this is
61 /// the section the Language Specific Data Area information is emitted to.
62 const MCSection *LSDASection;
64 /// EHFrameSection - If exception handling is supported by the target, this is
65 /// the section the EH Frame is emitted to.
66 const MCSection *EHFrameSection;
68 // Dwarf sections for debug info. If a target supports debug info, these must
70 const MCSection *DwarfAbbrevSection;
71 const MCSection *DwarfInfoSection;
72 const MCSection *DwarfLineSection;
73 const MCSection *DwarfFrameSection;
74 const MCSection *DwarfPubNamesSection;
75 const MCSection *DwarfPubTypesSection;
76 const MCSection *DwarfDebugInlineSection;
77 const MCSection *DwarfStrSection;
78 const MCSection *DwarfLocSection;
79 const MCSection *DwarfARangesSection;
80 const MCSection *DwarfRangesSection;
81 const MCSection *DwarfMacroInfoSection;
85 MCContext &getContext() const { return *Ctx; }
88 virtual ~TargetLoweringObjectFile();
90 /// Initialize - this method must be called before any actual lowering is
91 /// done. This specifies the current context for codegen, and gives the
92 /// lowering implementations a chance to set up their default sections.
93 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
98 const MCSection *getTextSection() const { return TextSection; }
99 const MCSection *getDataSection() const { return DataSection; }
100 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
101 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
102 const MCSection *getLSDASection() const { return LSDASection; }
103 const MCSection *getEHFrameSection() const { return EHFrameSection; }
104 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
105 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
106 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
107 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
108 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
109 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
110 const MCSection *getDwarfDebugInlineSection() const {
111 return DwarfDebugInlineSection;
113 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
114 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
115 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
116 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
117 const MCSection *getDwarfMacroInfoSection() const {
118 return DwarfMacroInfoSection;
121 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
122 /// decide not to emit the UsedDirective for some symbols in llvm.used.
123 /// FIXME: REMOVE this (rdar://7071300)
124 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
129 /// getSectionForConstant - Given a constant with the SectionKind, return a
130 /// section that it should be placed in.
131 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
133 /// getKindForGlobal - Classify the specified global variable into a set of
134 /// target independent categories embodied in SectionKind.
135 static SectionKind getKindForGlobal(const GlobalValue *GV,
136 const TargetMachine &TM);
138 /// SectionForGlobal - This method computes the appropriate section to emit
139 /// the specified global variable or function definition. This should not
140 /// be passed external (or available externally) globals.
141 const MCSection *SectionForGlobal(const GlobalValue *GV,
142 SectionKind Kind, Mangler *Mang,
143 const TargetMachine &TM) const;
145 /// SectionForGlobal - This method computes the appropriate section to emit
146 /// the specified global variable or function definition. This should not
147 /// be passed external (or available externally) globals.
148 const MCSection *SectionForGlobal(const GlobalValue *GV,
150 const TargetMachine &TM) const {
151 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
156 /// getExplicitSectionGlobal - Targets should implement this method to assign
157 /// a section to globals with an explicit section specfied. The
158 /// implementation of this method can assume that GV->hasSection() is true.
159 virtual const MCSection *
160 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
161 Mangler *Mang, const TargetMachine &TM) const = 0;
163 /// getSpecialCasedSectionGlobals - Allow the target to completely override
164 /// section assignment of a global.
165 virtual const MCSection *
166 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
167 SectionKind Kind) const {
171 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
172 /// into a string that can be printed to the assembly file after the
173 /// ".section foo" part of a section directive.
174 virtual void getSectionFlagsAsString(SectionKind Kind,
175 SmallVectorImpl<char> &Str) const {
179 virtual const MCSection *
180 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
181 Mangler *Mang, const TargetMachine &TM) const;
187 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
188 bool AtIsCommentChar; // True if @ is the comment character on this target.
191 /// TLSDataSection - Section directive for Thread Local data.
193 const MCSection *TLSDataSection; // Defaults to ".tdata".
195 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
196 /// Null if this target doesn't support a BSS section.
198 const MCSection *TLSBSSSection; // Defaults to ".tbss".
200 const MCSection *DataRelSection;
201 const MCSection *DataRelLocalSection;
202 const MCSection *DataRelROSection;
203 const MCSection *DataRelROLocalSection;
205 const MCSection *MergeableConst4Section;
206 const MCSection *MergeableConst8Section;
207 const MCSection *MergeableConst16Section;
210 const MCSection *getELFSection(const char *Name, bool isDirective,
211 SectionKind Kind) const;
213 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
215 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
216 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
217 bool hasCrazyBSS = false)
218 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
220 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
222 /// getSectionForConstant - Given a constant with the SectionKind, return a
223 /// section that it should be placed in.
224 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
227 virtual const MCSection *
228 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
229 Mangler *Mang, const TargetMachine &TM) const;
231 void getSectionFlagsAsString(SectionKind Kind,
232 SmallVectorImpl<char> &Str) const;
234 virtual const MCSection *
235 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
236 Mangler *Mang, const TargetMachine &TM) const;
241 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
242 const MCSection *CStringSection;
243 const MCSection *UStringSection;
244 const MCSection *TextCoalSection;
245 const MCSection *ConstTextCoalSection;
246 const MCSection *ConstDataCoalSection;
247 const MCSection *ConstDataSection;
248 const MCSection *DataCoalSection;
249 const MCSection *FourByteConstantSection;
250 const MCSection *EightByteConstantSection;
251 const MCSection *SixteenByteConstantSection;
254 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
256 virtual const MCSection *
257 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
258 Mangler *Mang, const TargetMachine &TM) const;
260 virtual const MCSection *
261 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
262 Mangler *Mang, const TargetMachine &TM) const;
264 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
266 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
267 /// decide not to emit the UsedDirective for some symbols in llvm.used.
268 /// FIXME: REMOVE this (rdar://7071300)
269 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
272 /// getMachOSection - Return the MCSection for the specified mach-o section.
273 /// FIXME: Switch this to a semantic view eventually.
274 const MCSection *getMachOSection(const char *Name, bool isDirective,
275 SectionKind K) const;
280 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
282 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
284 virtual const MCSection *
285 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
286 Mangler *Mang, const TargetMachine &TM) const;
288 virtual void getSectionFlagsAsString(SectionKind Kind,
289 SmallVectorImpl<char> &Str) const;
291 virtual const MCSection *
292 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
293 Mangler *Mang, const TargetMachine &TM) const;
295 /// getCOFFSection - Return the MCSection for the specified COFF section.
296 /// FIXME: Switch this to a semantic view eventually.
297 const MCSection *getCOFFSection(const char *Name, bool isDirective,
298 SectionKind K) const;
301 } // end namespace llvm