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;
72 const MCSection *getOrCreateSection(const char *Name,
77 virtual ~TargetLoweringObjectFile();
79 /// Initialize - this method must be called before any actual lowering is
80 /// done. This specifies the current context for codegen, and gives the
81 /// lowering implementations a chance to set up their default sections.
82 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
87 const MCSection *getTextSection() const { return TextSection; }
88 const MCSection *getDataSection() const { return DataSection; }
89 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
90 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
91 const MCSection *getLSDASection() const { return LSDASection; }
92 const MCSection *getEHFrameSection() const { return EHFrameSection; }
94 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
95 /// decide not to emit the UsedDirective for some symbols in llvm.used.
96 /// FIXME: REMOVE this (rdar://7071300)
97 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
102 /// getSectionForConstant - Given a constant with the SectionKind, return a
103 /// section that it should be placed in.
104 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
106 /// getKindForNamedSection - If this target wants to be able to override
107 /// section flags based on the name of the section specified for a global
108 /// variable, it can implement this. This is used on ELF systems so that
109 /// ".tbss" gets the TLS bit set etc.
110 virtual SectionKind getKindForNamedSection(const char *Section,
111 SectionKind K) const {
115 /// SectionForGlobal - This method computes the appropriate section to emit
116 /// the specified global variable or function definition. This should not
117 /// be passed external (or available externally) globals.
118 const MCSection *SectionForGlobal(const GlobalValue *GV,
120 const TargetMachine &TM) const;
122 /// getSpecialCasedSectionGlobals - Allow the target to completely override
123 /// section assignment of a global.
124 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
125 /// getFlagsForNamedSection.
126 virtual const MCSection *
127 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
128 SectionKind Kind) const {
132 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
133 /// into a string that can be printed to the assembly file after the
134 /// ".section foo" part of a section directive.
135 virtual void getSectionFlagsAsString(SectionKind Kind,
136 SmallVectorImpl<char> &Str) const {
140 virtual const MCSection *
141 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
142 Mangler *Mang, const TargetMachine &TM) const;
148 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
149 bool AtIsCommentChar; // True if @ is the comment character on this target.
152 /// TLSDataSection - Section directive for Thread Local data.
154 const MCSection *TLSDataSection; // Defaults to ".tdata".
156 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
157 /// Null if this target doesn't support a BSS section.
159 const MCSection *TLSBSSSection; // Defaults to ".tbss".
161 const MCSection *CStringSection;
163 const MCSection *DataRelSection;
164 const MCSection *DataRelLocalSection;
165 const MCSection *DataRelROSection;
166 const MCSection *DataRelROLocalSection;
168 const MCSection *MergeableConst4Section;
169 const MCSection *MergeableConst8Section;
170 const MCSection *MergeableConst16Section;
172 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
174 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
175 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
176 bool hasCrazyBSS = false)
177 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
179 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
182 /// getSectionForConstant - Given a constant with the SectionKind, return a
183 /// section that it should be placed in.
184 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
186 virtual SectionKind getKindForNamedSection(const char *Section,
187 SectionKind K) const;
188 void getSectionFlagsAsString(SectionKind Kind,
189 SmallVectorImpl<char> &Str) const;
191 virtual const MCSection *
192 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
193 Mangler *Mang, const TargetMachine &TM) const;
198 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
199 const MCSection *CStringSection;
200 const MCSection *TextCoalSection;
201 const MCSection *ConstTextCoalSection;
202 const MCSection *ConstDataCoalSection;
203 const MCSection *ConstDataSection;
204 const MCSection *DataCoalSection;
205 const MCSection *FourByteConstantSection;
206 const MCSection *EightByteConstantSection;
207 const MCSection *SixteenByteConstantSection;
210 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
212 virtual const MCSection *
213 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
214 Mangler *Mang, const TargetMachine &TM) const;
216 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
218 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
219 /// decide not to emit the UsedDirective for some symbols in llvm.used.
220 /// FIXME: REMOVE this (rdar://7071300)
221 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
227 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
229 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
231 virtual 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;
239 } // end namespace llvm