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 const MCSection *getOrCreateSection(const char *Name,
91 virtual ~TargetLoweringObjectFile();
93 /// Initialize - this method must be called before any actual lowering is
94 /// done. This specifies the current context for codegen, and gives the
95 /// lowering implementations a chance to set up their default sections.
96 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
101 const MCSection *getTextSection() const { return TextSection; }
102 const MCSection *getDataSection() const { return DataSection; }
103 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
104 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
105 const MCSection *getLSDASection() const { return LSDASection; }
106 const MCSection *getEHFrameSection() const { return EHFrameSection; }
107 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
108 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
109 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
110 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
111 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
112 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
113 const MCSection *getDwarfDebugInlineSection() const {
114 return DwarfDebugInlineSection;
116 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
117 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
118 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
119 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
120 const MCSection *getDwarfMacroInfoSection() const {
121 return DwarfMacroInfoSection;
124 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
125 /// decide not to emit the UsedDirective for some symbols in llvm.used.
126 /// FIXME: REMOVE this (rdar://7071300)
127 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
132 /// getSectionForConstant - Given a constant with the SectionKind, return a
133 /// section that it should be placed in.
134 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
136 /// getKindForNamedSection - If this target wants to be able to override
137 /// section flags based on the name of the section specified for a global
138 /// variable, it can implement this. This is used on ELF systems so that
139 /// ".tbss" gets the TLS bit set etc.
140 virtual SectionKind getKindForNamedSection(const char *Section,
141 SectionKind K) 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;
152 /// getSpecialCasedSectionGlobals - Allow the target to completely override
153 /// section assignment of a global.
154 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
155 /// getFlagsForNamedSection.
156 virtual const MCSection *
157 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
158 SectionKind Kind) const {
162 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
163 /// into a string that can be printed to the assembly file after the
164 /// ".section foo" part of a section directive.
165 virtual void getSectionFlagsAsString(SectionKind Kind,
166 SmallVectorImpl<char> &Str) const {
170 virtual const MCSection *
171 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
172 Mangler *Mang, const TargetMachine &TM) const;
178 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
179 bool AtIsCommentChar; // True if @ is the comment character on this target.
182 /// TLSDataSection - Section directive for Thread Local data.
184 const MCSection *TLSDataSection; // Defaults to ".tdata".
186 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
187 /// Null if this target doesn't support a BSS section.
189 const MCSection *TLSBSSSection; // Defaults to ".tbss".
191 const MCSection *CStringSection;
193 const MCSection *DataRelSection;
194 const MCSection *DataRelLocalSection;
195 const MCSection *DataRelROSection;
196 const MCSection *DataRelROLocalSection;
198 const MCSection *MergeableConst4Section;
199 const MCSection *MergeableConst8Section;
200 const MCSection *MergeableConst16Section;
202 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
204 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
205 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
206 bool hasCrazyBSS = false)
207 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
209 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
212 /// getSectionForConstant - Given a constant with the SectionKind, return a
213 /// section that it should be placed in.
214 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
216 virtual SectionKind getKindForNamedSection(const char *Section,
217 SectionKind K) const;
218 void getSectionFlagsAsString(SectionKind Kind,
219 SmallVectorImpl<char> &Str) const;
221 virtual const MCSection *
222 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
223 Mangler *Mang, const TargetMachine &TM) const;
228 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
229 const MCSection *CStringSection;
230 const MCSection *TextCoalSection;
231 const MCSection *ConstTextCoalSection;
232 const MCSection *ConstDataCoalSection;
233 const MCSection *ConstDataSection;
234 const MCSection *DataCoalSection;
235 const MCSection *FourByteConstantSection;
236 const MCSection *EightByteConstantSection;
237 const MCSection *SixteenByteConstantSection;
240 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
242 virtual const MCSection *
243 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
244 Mangler *Mang, const TargetMachine &TM) const;
246 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
248 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
249 /// decide not to emit the UsedDirective for some symbols in llvm.used.
250 /// FIXME: REMOVE this (rdar://7071300)
251 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
257 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
259 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
261 virtual void getSectionFlagsAsString(SectionKind Kind,
262 SmallVectorImpl<char> &Str) const;
264 virtual const MCSection *
265 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
266 Mangler *Mang, const TargetMachine &TM) const;
269 } // end namespace llvm