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;
63 const MCSection *getOrCreateSection(const char *Name,
68 virtual ~TargetLoweringObjectFile();
70 /// Initialize - this method must be called before any actual lowering is
71 /// done. This specifies the current context for codegen, and gives the
72 /// lowering implementations a chance to set up their default sections.
73 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
78 const MCSection *getTextSection() const { return TextSection; }
79 const MCSection *getDataSection() const { return DataSection; }
81 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
82 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
84 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
85 /// decide not to emit the UsedDirective for some symbols in llvm.used.
86 /// FIXME: REMOVE this (rdar://7071300)
87 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
92 /// getSectionForConstant - Given a constant with the SectionKind, return a
93 /// section that it should be placed in.
94 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
96 /// getKindForNamedSection - If this target wants to be able to override
97 /// section flags based on the name of the section specified for a global
98 /// variable, it can implement this. This is used on ELF systems so that
99 /// ".tbss" gets the TLS bit set etc.
100 virtual SectionKind getKindForNamedSection(const char *Section,
101 SectionKind K) const {
105 /// SectionForGlobal - This method computes the appropriate section to emit
106 /// the specified global variable or function definition. This should not
107 /// be passed external (or available externally) globals.
108 const MCSection *SectionForGlobal(const GlobalValue *GV,
110 const TargetMachine &TM) const;
112 /// getSpecialCasedSectionGlobals - Allow the target to completely override
113 /// section assignment of a global.
114 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
115 /// getFlagsForNamedSection.
116 virtual const MCSection *
117 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
118 SectionKind Kind) const {
122 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
123 /// into a string that can be printed to the assembly file after the
124 /// ".section foo" part of a section directive.
125 virtual void getSectionFlagsAsString(SectionKind Kind,
126 SmallVectorImpl<char> &Str) const {
130 virtual const MCSection *
131 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
132 Mangler *Mang, const TargetMachine &TM) const;
138 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
139 bool AtIsCommentChar; // True if @ is the comment character on this target.
142 /// TLSDataSection - Section directive for Thread Local data.
144 const MCSection *TLSDataSection; // Defaults to ".tdata".
146 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
147 /// Null if this target doesn't support a BSS section.
149 const MCSection *TLSBSSSection; // Defaults to ".tbss".
151 const MCSection *CStringSection;
153 const MCSection *DataRelSection;
154 const MCSection *DataRelLocalSection;
155 const MCSection *DataRelROSection;
156 const MCSection *DataRelROLocalSection;
158 const MCSection *MergeableConst4Section;
159 const MCSection *MergeableConst8Section;
160 const MCSection *MergeableConst16Section;
162 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
164 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
165 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
166 bool hasCrazyBSS = false)
167 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
169 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
172 /// getSectionForConstant - Given a constant with the SectionKind, return a
173 /// section that it should be placed in.
174 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
176 virtual SectionKind getKindForNamedSection(const char *Section,
177 SectionKind K) const;
178 void getSectionFlagsAsString(SectionKind Kind,
179 SmallVectorImpl<char> &Str) const;
181 virtual const MCSection *
182 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
183 Mangler *Mang, const TargetMachine &TM) const;
188 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
189 const MCSection *CStringSection;
190 const MCSection *TextCoalSection;
191 const MCSection *ConstTextCoalSection;
192 const MCSection *ConstDataCoalSection;
193 const MCSection *ConstDataSection;
194 const MCSection *DataCoalSection;
195 const MCSection *FourByteConstantSection;
196 const MCSection *EightByteConstantSection;
197 const MCSection *SixteenByteConstantSection;
200 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
202 virtual const MCSection *
203 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
204 Mangler *Mang, const TargetMachine &TM) const;
206 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
208 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
209 /// decide not to emit the UsedDirective for some symbols in llvm.used.
210 /// FIXME: REMOVE this (rdar://7071300)
211 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
217 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
219 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
221 virtual void getSectionFlagsAsString(SectionKind Kind,
222 SmallVectorImpl<char> &Str) const;
224 virtual const MCSection *
225 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
226 Mangler *Mang, const TargetMachine &TM) const;
229 } // end namespace llvm