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 const MCSection *getOrCreateSection(const char *Name,
90 virtual ~TargetLoweringObjectFile();
92 /// Initialize - this method must be called before any actual lowering is
93 /// done. This specifies the current context for codegen, and gives the
94 /// lowering implementations a chance to set up their default sections.
95 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
100 const MCSection *getTextSection() const { return TextSection; }
101 const MCSection *getDataSection() const { return DataSection; }
102 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
103 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
104 const MCSection *getLSDASection() const { return LSDASection; }
105 const MCSection *getEHFrameSection() const { return EHFrameSection; }
106 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
107 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
108 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
109 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
110 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
111 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
112 const MCSection *getDwarfDebugInlineSection() const {
113 return DwarfDebugInlineSection;
115 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
116 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
117 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
118 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
119 const MCSection *getDwarfMacroInfoSection() const {
120 return DwarfMacroInfoSection;
123 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
124 /// decide not to emit the UsedDirective for some symbols in llvm.used.
125 /// FIXME: REMOVE this (rdar://7071300)
126 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
131 /// getSectionForConstant - Given a constant with the SectionKind, return a
132 /// section that it should be placed in.
133 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
135 /// getKindForNamedSection - If this target wants to be able to override
136 /// section flags based on the name of the section specified for a global
137 /// variable, it can implement this. This is used on ELF systems so that
138 /// ".tbss" gets the TLS bit set etc.
139 virtual SectionKind getKindForNamedSection(const char *Section,
140 SectionKind K) const {
144 /// getKindForGlobal - Classify the specified global variable into a set of
145 /// target independent categories embodied in SectionKind.
146 static SectionKind getKindForGlobal(const GlobalValue *GV,
147 const TargetMachine &TM);
149 /// SectionForGlobal - This method computes the appropriate section to emit
150 /// the specified global variable or function definition. This should not
151 /// be passed external (or available externally) globals.
152 const MCSection *SectionForGlobal(const GlobalValue *GV,
153 SectionKind Kind, Mangler *Mang,
154 const TargetMachine &TM) const;
156 /// SectionForGlobal - This method computes the appropriate section to emit
157 /// the specified global variable or function definition. This should not
158 /// be passed external (or available externally) globals.
159 const MCSection *SectionForGlobal(const GlobalValue *GV,
161 const TargetMachine &TM) const {
162 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
165 /// getSpecialCasedSectionGlobals - Allow the target to completely override
166 /// section assignment of a global.
167 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
168 /// getFlagsForNamedSection.
169 virtual const MCSection *
170 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
171 SectionKind Kind) const {
175 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
176 /// into a string that can be printed to the assembly file after the
177 /// ".section foo" part of a section directive.
178 virtual void getSectionFlagsAsString(SectionKind Kind,
179 SmallVectorImpl<char> &Str) const {
183 virtual const MCSection *
184 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
185 Mangler *Mang, const TargetMachine &TM) const;
191 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
192 bool AtIsCommentChar; // True if @ is the comment character on this target.
195 /// TLSDataSection - Section directive for Thread Local data.
197 const MCSection *TLSDataSection; // Defaults to ".tdata".
199 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
200 /// Null if this target doesn't support a BSS section.
202 const MCSection *TLSBSSSection; // Defaults to ".tbss".
204 const MCSection *DataRelSection;
205 const MCSection *DataRelLocalSection;
206 const MCSection *DataRelROSection;
207 const MCSection *DataRelROLocalSection;
209 const MCSection *MergeableConst4Section;
210 const MCSection *MergeableConst8Section;
211 const MCSection *MergeableConst16Section;
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);
223 /// getSectionForConstant - Given a constant with the SectionKind, return a
224 /// section that it should be placed in.
225 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
227 virtual SectionKind getKindForNamedSection(const char *Section,
228 SectionKind K) const;
229 void getSectionFlagsAsString(SectionKind Kind,
230 SmallVectorImpl<char> &Str) const;
232 virtual const MCSection *
233 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
234 Mangler *Mang, const TargetMachine &TM) const;
239 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
240 const MCSection *CStringSection;
241 const MCSection *UStringSection;
242 const MCSection *TextCoalSection;
243 const MCSection *ConstTextCoalSection;
244 const MCSection *ConstDataCoalSection;
245 const MCSection *ConstDataSection;
246 const MCSection *DataCoalSection;
247 const MCSection *FourByteConstantSection;
248 const MCSection *EightByteConstantSection;
249 const MCSection *SixteenByteConstantSection;
252 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
254 virtual const MCSection *
255 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
256 Mangler *Mang, const TargetMachine &TM) const;
258 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
260 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
261 /// decide not to emit the UsedDirective for some symbols in llvm.used.
262 /// FIXME: REMOVE this (rdar://7071300)
263 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
266 /// getMachOSection - Return the MCSection for the specified mach-o section.
267 /// FIXME: Switch this to a semantic view eventually.
268 const MCSection *getMachOSection(const char *Name, bool isDirective,
274 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
276 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
278 virtual void getSectionFlagsAsString(SectionKind Kind,
279 SmallVectorImpl<char> &Str) const;
281 virtual const MCSection *
282 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
283 Mangler *Mang, const TargetMachine &TM) const;
285 /// getCOFFSection - Return the MCSection for the specified COFF section.
286 /// FIXME: Switch this to a semantic view eventually.
287 const MCSection *getCOFFSection(const char *Name, bool isDirective,
291 } // end namespace llvm