LLVM API Documentation
00001 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements classes used to handle lowerings specific to common 00011 // object file formats. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H 00016 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H 00017 00018 #include "llvm/MC/SectionKind.h" 00019 00020 namespace llvm { 00021 class Mangler; 00022 class MCSection; 00023 class MCSectionMachO; 00024 class MCContext; 00025 class GlobalValue; 00026 class StringRef; 00027 class TargetMachine; 00028 class TargetAsmInfo; 00029 00030 class TargetLoweringObjectFile { 00031 MCContext *Ctx; 00032 00033 TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT 00034 void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT 00035 protected: 00036 00037 TargetLoweringObjectFile(); 00038 00039 /// TextSection - Section directive for standard text. 00040 /// 00041 const MCSection *TextSection; 00042 00043 /// DataSection - Section directive for standard data. 00044 /// 00045 const MCSection *DataSection; 00046 00047 /// BSSSection - Section that is default initialized to zero. 00048 const MCSection *BSSSection; 00049 00050 /// ReadOnlySection - Section that is readonly and can contain arbitrary 00051 /// initialized data. Targets are not required to have a readonly section. 00052 /// If they don't, various bits of code will fall back to using the data 00053 /// section for constants. 00054 const MCSection *ReadOnlySection; 00055 00056 /// StaticCtorSection - This section contains the static constructor pointer 00057 /// list. 00058 const MCSection *StaticCtorSection; 00059 00060 /// StaticDtorSection - This section contains the static destructor pointer 00061 /// list. 00062 const MCSection *StaticDtorSection; 00063 00064 /// LSDASection - If exception handling is supported by the target, this is 00065 /// the section the Language Specific Data Area information is emitted to. 00066 const MCSection *LSDASection; 00067 00068 /// EHFrameSection - If exception handling is supported by the target, this is 00069 /// the section the EH Frame is emitted to. 00070 const MCSection *EHFrameSection; 00071 00072 // Dwarf sections for debug info. If a target supports debug info, these must 00073 // be set. 00074 const MCSection *DwarfAbbrevSection; 00075 const MCSection *DwarfInfoSection; 00076 const MCSection *DwarfLineSection; 00077 const MCSection *DwarfFrameSection; 00078 const MCSection *DwarfPubNamesSection; 00079 const MCSection *DwarfPubTypesSection; 00080 const MCSection *DwarfDebugInlineSection; 00081 const MCSection *DwarfStrSection; 00082 const MCSection *DwarfLocSection; 00083 const MCSection *DwarfARangesSection; 00084 const MCSection *DwarfRangesSection; 00085 const MCSection *DwarfMacroInfoSection; 00086 00087 public: 00088 00089 MCContext &getContext() const { return *Ctx; } 00090 00091 00092 virtual ~TargetLoweringObjectFile(); 00093 00094 /// Initialize - this method must be called before any actual lowering is 00095 /// done. This specifies the current context for codegen, and gives the 00096 /// lowering implementations a chance to set up their default sections. 00097 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) { 00098 Ctx = &ctx; 00099 } 00100 00101 00102 const MCSection *getTextSection() const { return TextSection; } 00103 const MCSection *getDataSection() const { return DataSection; } 00104 const MCSection *getBSSSection() const { return BSSSection; } 00105 const MCSection *getStaticCtorSection() const { return StaticCtorSection; } 00106 const MCSection *getStaticDtorSection() const { return StaticDtorSection; } 00107 const MCSection *getLSDASection() const { return LSDASection; } 00108 const MCSection *getEHFrameSection() const { return EHFrameSection; } 00109 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; } 00110 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; } 00111 const MCSection *getDwarfLineSection() const { return DwarfLineSection; } 00112 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; } 00113 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;} 00114 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;} 00115 const MCSection *getDwarfDebugInlineSection() const { 00116 return DwarfDebugInlineSection; 00117 } 00118 const MCSection *getDwarfStrSection() const { return DwarfStrSection; } 00119 const MCSection *getDwarfLocSection() const { return DwarfLocSection; } 00120 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;} 00121 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; } 00122 const MCSection *getDwarfMacroInfoSection() const { 00123 return DwarfMacroInfoSection; 00124 } 00125 00126 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively 00127 /// decide not to emit the UsedDirective for some symbols in llvm.used. 00128 /// FIXME: REMOVE this (rdar://7071300) 00129 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, 00130 Mangler *) const { 00131 return GV != 0; 00132 } 00133 00134 /// getSectionForConstant - Given a constant with the SectionKind, return a 00135 /// section that it should be placed in. 00136 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 00137 00138 /// getKindForGlobal - Classify the specified global variable into a set of 00139 /// target independent categories embodied in SectionKind. 00140 static SectionKind getKindForGlobal(const GlobalValue *GV, 00141 const TargetMachine &TM); 00142 00143 /// SectionForGlobal - This method computes the appropriate section to emit 00144 /// the specified global variable or function definition. This should not 00145 /// be passed external (or available externally) globals. 00146 const MCSection *SectionForGlobal(const GlobalValue *GV, 00147 SectionKind Kind, Mangler *Mang, 00148 const TargetMachine &TM) const; 00149 00150 /// SectionForGlobal - This method computes the appropriate section to emit 00151 /// the specified global variable or function definition. This should not 00152 /// be passed external (or available externally) globals. 00153 const MCSection *SectionForGlobal(const GlobalValue *GV, 00154 Mangler *Mang, 00155 const TargetMachine &TM) const { 00156 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM); 00157 } 00158 00159 00160 00161 /// getExplicitSectionGlobal - Targets should implement this method to assign 00162 /// a section to globals with an explicit section specfied. The 00163 /// implementation of this method can assume that GV->hasSection() is true. 00164 virtual const MCSection * 00165 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 00166 Mangler *Mang, const TargetMachine &TM) const = 0; 00167 00168 /// getSpecialCasedSectionGlobals - Allow the target to completely override 00169 /// section assignment of a global. 00170 virtual const MCSection * 00171 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang, 00172 SectionKind Kind) const { 00173 return 0; 00174 } 00175 00176 protected: 00177 virtual const MCSection * 00178 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 00179 Mangler *Mang, const TargetMachine &TM) const; 00180 }; 00181 00182 00183 00184 00185 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile { 00186 mutable void *UniquingMap; 00187 protected: 00188 /// TLSDataSection - Section directive for Thread Local data. 00189 /// 00190 const MCSection *TLSDataSection; // Defaults to ".tdata". 00191 00192 /// TLSBSSSection - Section directive for Thread Local uninitialized data. 00193 /// Null if this target doesn't support a BSS section. 00194 /// 00195 const MCSection *TLSBSSSection; // Defaults to ".tbss". 00196 00197 const MCSection *DataRelSection; 00198 const MCSection *DataRelLocalSection; 00199 const MCSection *DataRelROSection; 00200 const MCSection *DataRelROLocalSection; 00201 00202 const MCSection *MergeableConst4Section; 00203 const MCSection *MergeableConst8Section; 00204 const MCSection *MergeableConst16Section; 00205 00206 protected: 00207 const MCSection *getELFSection(StringRef Section, unsigned Type, 00208 unsigned Flags, SectionKind Kind, 00209 bool IsExplicit = false) const; 00210 public: 00211 TargetLoweringObjectFileELF() : UniquingMap(0) {} 00212 ~TargetLoweringObjectFileELF(); 00213 00214 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 00215 00216 /// getSectionForConstant - Given a constant with the SectionKind, return a 00217 /// section that it should be placed in. 00218 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 00219 00220 00221 virtual const MCSection * 00222 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 00223 Mangler *Mang, const TargetMachine &TM) const; 00224 00225 virtual const MCSection * 00226 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 00227 Mangler *Mang, const TargetMachine &TM) const; 00228 }; 00229 00230 00231 00232 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { 00233 mutable void *UniquingMap; 00234 00235 const MCSection *CStringSection; 00236 const MCSection *UStringSection; 00237 const MCSection *TextCoalSection; 00238 const MCSection *ConstTextCoalSection; 00239 const MCSection *ConstDataCoalSection; 00240 const MCSection *ConstDataSection; 00241 const MCSection *DataCoalSection; 00242 const MCSection *FourByteConstantSection; 00243 const MCSection *EightByteConstantSection; 00244 const MCSection *SixteenByteConstantSection; 00245 00246 const MCSection *LazySymbolPointerSection; 00247 const MCSection *NonLazySymbolPointerSection; 00248 public: 00249 TargetLoweringObjectFileMachO() : UniquingMap(0) {} 00250 ~TargetLoweringObjectFileMachO(); 00251 00252 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 00253 00254 virtual const MCSection * 00255 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 00256 Mangler *Mang, const TargetMachine &TM) const; 00257 00258 virtual const MCSection * 00259 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 00260 Mangler *Mang, const TargetMachine &TM) const; 00261 00262 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 00263 00264 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively 00265 /// decide not to emit the UsedDirective for some symbols in llvm.used. 00266 /// FIXME: REMOVE this (rdar://7071300) 00267 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, 00268 Mangler *) const; 00269 00270 /// getMachOSection - Return the MCSection for the specified mach-o section. 00271 /// This requires the operands to be valid. 00272 const MCSectionMachO *getMachOSection(const StringRef &Segment, 00273 const StringRef &Section, 00274 unsigned TypeAndAttributes, 00275 SectionKind K) const { 00276 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K); 00277 } 00278 const MCSectionMachO *getMachOSection(const StringRef &Segment, 00279 const StringRef &Section, 00280 unsigned TypeAndAttributes, 00281 unsigned Reserved2, 00282 SectionKind K) const; 00283 00284 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak 00285 /// symbols into. 00286 const MCSection *getTextCoalSection() const { 00287 return TextCoalSection; 00288 } 00289 00290 /// getLazySymbolPointerSection - Return the section corresponding to 00291 /// the .lazy_symbol_pointer directive. 00292 const MCSection *getLazySymbolPointerSection() const { 00293 return LazySymbolPointerSection; 00294 } 00295 00296 /// getNonLazySymbolPointerSection - Return the section corresponding to 00297 /// the .non_lazy_symbol_pointer directive. 00298 const MCSection *getNonLazySymbolPointerSection() const { 00299 return NonLazySymbolPointerSection; 00300 } 00301 }; 00302 00303 00304 00305 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { 00306 mutable void *UniquingMap; 00307 public: 00308 TargetLoweringObjectFileCOFF() : UniquingMap(0) {} 00309 ~TargetLoweringObjectFileCOFF(); 00310 00311 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 00312 00313 virtual const MCSection * 00314 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 00315 Mangler *Mang, const TargetMachine &TM) const; 00316 00317 virtual const MCSection * 00318 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 00319 Mangler *Mang, const TargetMachine &TM) const; 00320 00321 /// getCOFFSection - Return the MCSection for the specified COFF section. 00322 /// FIXME: Switch this to a semantic view eventually. 00323 const MCSection *getCOFFSection(const char *Name, bool isDirective, 00324 SectionKind K) const; 00325 }; 00326 00327 } // end namespace llvm 00328 00329 #endif