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; // Defaults to ".text".
40 /// DataSection - Section directive for standard data.
42 const MCSection *DataSection; // Defaults to ".data".
47 const MCSection *BSSSection_;
49 /// ReadOnlySection - This is the directive that is emitted to switch to a
50 /// read-only section for constant data (e.g. data declared const,
52 const MCSection *ReadOnlySection; // Defaults to NULL
54 /// TLSDataSection - Section directive for Thread Local data.
56 const MCSection *TLSDataSection; // Defaults to ".tdata".
58 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
59 /// Null if this target doesn't support a BSS section.
61 const MCSection *TLSBSSSection; // Defaults to ".tbss".
63 const MCSection *CStringSection_;
67 const MCSection *getOrCreateSection(const char *Name,
72 virtual ~TargetLoweringObjectFile();
74 /// Initialize - this method must be called before any actual lowering is
75 /// done. This specifies the current context for codegen, and gives the
76 /// lowering implementations a chance to set up their default sections.
77 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
82 const MCSection *getTextSection() const { return TextSection; }
83 const MCSection *getDataSection() const { return DataSection; }
85 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
86 /// decide not to emit the UsedDirective for some symbols in llvm.used.
87 /// FIXME: REMOVE this (rdar://7071300)
88 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
93 /// getSectionForMergeableConstant - Given a mergeable constant with the
94 /// specified size and relocation information, return a section that it
95 /// should be placed in.
96 virtual const MCSection *
97 getSectionForMergeableConstant(SectionKind Kind) const;
99 /// getKindForNamedSection - If this target wants to be able to override
100 /// section flags based on the name of the section specified for a global
101 /// variable, it can implement this. This is used on ELF systems so that
102 /// ".tbss" gets the TLS bit set etc.
103 virtual SectionKind getKindForNamedSection(const char *Section,
104 SectionKind K) const {
108 /// SectionForGlobal - This method computes the appropriate section to emit
109 /// the specified global variable or function definition. This should not
110 /// be passed external (or available externally) globals.
111 const MCSection *SectionForGlobal(const GlobalValue *GV,
113 const TargetMachine &TM) const;
115 /// getSpecialCasedSectionGlobals - Allow the target to completely override
116 /// section assignment of a global.
117 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
118 /// getFlagsForNamedSection.
119 virtual const MCSection *
120 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
121 SectionKind Kind) const {
125 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
126 /// into a string that can be printed to the assembly file after the
127 /// ".section foo" part of a section directive.
128 virtual void getSectionFlagsAsString(SectionKind Kind,
129 SmallVectorImpl<char> &Str) const {
133 virtual const MCSection *
134 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
135 Mangler *Mang, const TargetMachine &TM) const;
141 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
142 bool AtIsCommentChar; // True if @ is the comment character on this target.
145 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
147 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
148 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
149 bool hasCrazyBSS = false)
150 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
152 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
155 /// getSectionForMergeableConstant - Given a mergeable constant with the
156 /// specified size and relocation information, return a section that it
157 /// should be placed in.
158 virtual const MCSection *
159 getSectionForMergeableConstant(SectionKind Kind) const;
161 virtual SectionKind getKindForNamedSection(const char *Section,
162 SectionKind K) const;
163 void getSectionFlagsAsString(SectionKind Kind,
164 SmallVectorImpl<char> &Str) const;
166 virtual const MCSection *
167 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
168 Mangler *Mang, const TargetMachine &TM) const;
170 const MCSection *DataRelSection;
171 const MCSection *DataRelLocalSection;
172 const MCSection *DataRelROSection;
173 const MCSection *DataRelROLocalSection;
175 const MCSection *MergeableConst4Section;
176 const MCSection *MergeableConst8Section;
177 const MCSection *MergeableConst16Section;
182 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
183 const MCSection *TextCoalSection;
184 const MCSection *ConstTextCoalSection;
185 const MCSection *ConstDataCoalSection;
186 const MCSection *ConstDataSection;
187 const MCSection *DataCoalSection;
188 const MCSection *FourByteConstantSection;
189 const MCSection *EightByteConstantSection;
190 const MCSection *SixteenByteConstantSection;
193 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
195 virtual const MCSection *
196 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
197 Mangler *Mang, const TargetMachine &TM) const;
199 virtual const MCSection *
200 getSectionForMergeableConstant(SectionKind Kind) const;
202 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
203 /// decide not to emit the UsedDirective for some symbols in llvm.used.
204 /// FIXME: REMOVE this (rdar://7071300)
205 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
211 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
213 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
215 virtual void getSectionFlagsAsString(SectionKind Kind,
216 SmallVectorImpl<char> &Str) const;
218 virtual const MCSection *
219 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
220 Mangler *Mang, const TargetMachine &TM) const;
223 } // end namespace llvm