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 /// SectionInfo - This class is a target-independent classification of a global
31 /// which is used to simplify target-specific code by exposing common
33 class SectionInfo : public SectionKind {
34 /// Weak - This is true if the referenced symbol is weak (i.e. linkonce,
35 /// weak, weak_odr, etc). This is orthogonal from the categorization.
40 /// Weak - This is true if the referenced symbol is weak (i.e. linkonce,
41 /// weak, weak_odr, etc). This is orthogonal from the categorization.
42 bool isWeak() const { return Weak; }
44 static SectionInfo get(Kind K, bool isWeak = false) {
50 static SectionInfo get(SectionKind K, bool isWeak = false) {
52 *(SectionKind*)&Res = K;
58 class TargetLoweringObjectFile {
62 TargetLoweringObjectFile();
64 /// TextSection - Section directive for standard text.
66 const MCSection *TextSection; // Defaults to ".text".
68 /// DataSection - Section directive for standard data.
70 const MCSection *DataSection; // Defaults to ".data".
75 const MCSection *BSSSection_;
77 /// ReadOnlySection - This is the directive that is emitted to switch to a
78 /// read-only section for constant data (e.g. data declared const,
80 const MCSection *ReadOnlySection; // Defaults to NULL
82 /// TLSDataSection - Section directive for Thread Local data.
84 const MCSection *TLSDataSection; // Defaults to ".tdata".
86 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
87 /// Null if this target doesn't support a BSS section.
89 const MCSection *TLSBSSSection; // Defaults to ".tbss".
91 const MCSection *CStringSection_;
95 const MCSection *getOrCreateSection(const char *Name,
100 virtual ~TargetLoweringObjectFile();
102 /// Initialize - this method must be called before any actual lowering is
103 /// done. This specifies the current context for codegen, and gives the
104 /// lowering implementations a chance to set up their default sections.
105 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
110 const MCSection *getTextSection() const { return TextSection; }
111 const MCSection *getDataSection() const { return DataSection; }
113 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
114 /// decide not to emit the UsedDirective for some symbols in llvm.used.
115 /// FIXME: REMOVE this (rdar://7071300)
116 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
121 /// getSectionForMergeableConstant - Given a mergeable constant with the
122 /// specified size and relocation information, return a section that it
123 /// should be placed in.
124 virtual const MCSection *
125 getSectionForMergeableConstant(SectionKind Kind) const;
127 /// getKindForNamedSection - If this target wants to be able to override
128 /// section flags based on the name of the section specified for a global
129 /// variable, it can implement this. This is used on ELF systems so that
130 /// ".tbss" gets the TLS bit set etc.
131 virtual SectionKind getKindForNamedSection(const char *Section,
132 SectionKind K) const {
136 /// SectionForGlobal - This method computes the appropriate section to emit
137 /// the specified global variable or function definition. This should not
138 /// be passed external (or available externally) globals.
139 const MCSection *SectionForGlobal(const GlobalValue *GV,
141 const TargetMachine &TM) const;
143 /// getSpecialCasedSectionGlobals - Allow the target to completely override
144 /// section assignment of a global.
145 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
146 /// getFlagsForNamedSection.
147 virtual const MCSection *
148 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
149 SectionInfo Kind) const {
153 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
154 /// into a string that can be printed to the assembly file after the
155 /// ".section foo" part of a section directive.
156 virtual void getSectionFlagsAsString(SectionKind Kind,
157 SmallVectorImpl<char> &Str) const {
161 virtual const MCSection *
162 SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Kind,
163 Mangler *Mang, const TargetMachine &TM) const;
169 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
170 bool AtIsCommentChar; // True if @ is the comment character on this target.
173 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
175 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
176 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
177 bool hasCrazyBSS = false)
178 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
180 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
183 /// getSectionForMergeableConstant - Given a mergeable constant with the
184 /// specified size and relocation information, return a section that it
185 /// should be placed in.
186 virtual const MCSection *
187 getSectionForMergeableConstant(SectionKind Kind) const;
189 virtual SectionKind getKindForNamedSection(const char *Section,
190 SectionKind K) const;
191 void getSectionFlagsAsString(SectionKind Kind,
192 SmallVectorImpl<char> &Str) const;
194 virtual const MCSection *
195 SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Kind,
196 Mangler *Mang, const TargetMachine &TM) const;
198 const MCSection *DataRelSection;
199 const MCSection *DataRelLocalSection;
200 const MCSection *DataRelROSection;
201 const MCSection *DataRelROLocalSection;
203 const MCSection *MergeableConst4Section;
204 const MCSection *MergeableConst8Section;
205 const MCSection *MergeableConst16Section;
210 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
211 const MCSection *TextCoalSection;
212 const MCSection *ConstTextCoalSection;
213 const MCSection *ConstDataCoalSection;
214 const MCSection *ConstDataSection;
215 const MCSection *DataCoalSection;
216 const MCSection *FourByteConstantSection;
217 const MCSection *EightByteConstantSection;
218 const MCSection *SixteenByteConstantSection;
221 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
223 virtual const MCSection *
224 SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Kind,
225 Mangler *Mang, const TargetMachine &TM) const;
227 virtual const MCSection *
228 getSectionForMergeableConstant(SectionKind Kind) const;
230 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
231 /// decide not to emit the UsedDirective for some symbols in llvm.used.
232 /// FIXME: REMOVE this (rdar://7071300)
233 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
239 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
241 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
243 virtual void getSectionFlagsAsString(SectionKind Kind,
244 SmallVectorImpl<char> &Str) const;
246 virtual const MCSection *
247 SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Kind,
248 Mangler *Mang, const TargetMachine &TM) const;
251 } // end namespace llvm