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 // FIXME: Switch to MC.
19 #include "llvm/Target/TargetAsmInfo.h"
23 class TargetLoweringObjectFile {
25 mutable StringMap<Section> Sections;
28 TargetLoweringObjectFile();
30 /// TextSection - Section directive for standard text.
32 const Section *TextSection; // Defaults to ".text".
34 /// DataSection - Section directive for standard data.
36 const Section *DataSection; // Defaults to ".data".
41 const Section *BSSSection_;
43 /// ReadOnlySection - This is the directive that is emitted to switch to a
44 /// read-only section for constant data (e.g. data declared const,
46 const Section *ReadOnlySection; // Defaults to NULL
48 /// TLSDataSection - Section directive for Thread Local data.
50 const Section *TLSDataSection; // Defaults to ".tdata".
52 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
53 /// Null if this target doesn't support a BSS section.
55 const Section *TLSBSSSection; // Defaults to ".tbss".
57 const Section *CStringSection_;
61 const Section *getOrCreateSection(const char *Name,
63 SectionKind::Kind K) const;
66 virtual ~TargetLoweringObjectFile();
68 const Section *getTextSection() const { return TextSection; }
69 const Section *getDataSection() const { return DataSection; }
72 /// getSectionForMergeableConstant - Given a mergeable constant with the
73 /// specified size and relocation information, return a section that it
74 /// should be placed in.
75 virtual const Section *
76 getSectionForMergeableConstant(SectionKind Kind) const;
78 /// getKindForNamedSection - If this target wants to be able to override
79 /// section flags based on the name of the section specified for a global
80 /// variable, it can implement this. This is used on ELF systems so that
81 /// ".tbss" gets the TLS bit set etc.
82 virtual SectionKind::Kind getKindForNamedSection(const char *Section,
83 SectionKind::Kind K) const{
87 /// SectionForGlobal - This method computes the appropriate section to emit
88 /// the specified global variable or function definition. This should not
89 /// be passed external (or available externally) globals.
90 const Section *SectionForGlobal(const GlobalValue *GV,
91 const TargetMachine &TM) const;
93 /// getSpecialCasedSectionGlobals - Allow the target to completely override
94 /// section assignment of a global.
95 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
96 /// getFlagsForNamedSection.
97 virtual const Section *
98 getSpecialCasedSectionGlobals(const GlobalValue *GV,
99 SectionKind Kind) const {
103 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
104 /// into a string that can be printed to the assembly file after the
105 /// ".section foo" part of a section directive.
106 virtual void getSectionFlagsAsString(SectionKind Kind,
107 SmallVectorImpl<char> &Str) const {
111 virtual const Section *SelectSectionForGlobal(const GlobalValue *GV,
113 const TargetMachine &TM) const;
119 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
120 bool AtIsCommentChar; // True if @ is the comment character on this target.
122 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
124 TargetLoweringObjectFileELF(bool AtIsCommentChar = false,
125 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
126 bool HasCrazyBSS = false);
128 /// getSectionForMergeableConstant - Given a mergeable constant with the
129 /// specified size and relocation information, return a section that it
130 /// should be placed in.
131 virtual const Section *
132 getSectionForMergeableConstant(SectionKind Kind) const;
134 virtual SectionKind::Kind getKindForNamedSection(const char *Section,
135 SectionKind::Kind K) const;
136 void getSectionFlagsAsString(SectionKind Kind,
137 SmallVectorImpl<char> &Str) const;
139 virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
141 const TargetMachine &TM) const;
143 const Section *DataRelSection;
144 const Section *DataRelLocalSection;
145 const Section *DataRelROSection;
146 const Section *DataRelROLocalSection;
148 const Section *MergeableConst4Section;
149 const Section *MergeableConst8Section;
150 const Section *MergeableConst16Section;
153 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
154 const Section *TextCoalSection;
155 const Section *ConstTextCoalSection;
156 const Section *ConstDataCoalSection;
157 const Section *ConstDataSection;
158 const Section *DataCoalSection;
159 const Section *FourByteConstantSection;
160 const Section *EightByteConstantSection;
161 const Section *SixteenByteConstantSection;
163 TargetLoweringObjectFileMachO(const TargetMachine &TM);
164 virtual const Section *SelectSectionForGlobal(const GlobalValue *GV,
166 const TargetMachine &TM) const;
168 virtual const Section *
169 getSectionForMergeableConstant(SectionKind Kind) const;
174 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
176 TargetLoweringObjectFileCOFF();
177 virtual void getSectionFlagsAsString(SectionKind Kind,
178 SmallVectorImpl<char> &Str) const;
180 virtual const Section *
181 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
182 const TargetMachine &TM) const;
185 } // end namespace llvm