TargetLoweringObjectFile.h revision 38cff389af1d78bd80df0479ef258493e0c5897e
1//===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements classes used to handle lowerings specific to common 11// object file formats. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H 16#define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H 17 18#include "llvm/MC/SectionKind.h" 19 20namespace llvm { 21 class Mangler; 22 class MCSection; 23 class MCSectionMachO; 24 class MCContext; 25 class GlobalValue; 26 class StringRef; 27 class TargetMachine; 28 class TargetAsmInfo; 29 30class TargetLoweringObjectFile { 31 MCContext *Ctx; 32 33 TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT 34 void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT 35protected: 36 37 TargetLoweringObjectFile(); 38 39 /// TextSection - Section directive for standard text. 40 /// 41 const MCSection *TextSection; 42 43 /// DataSection - Section directive for standard data. 44 /// 45 const MCSection *DataSection; 46 47 /// BSSSection - Section that is default initialized to zero. 48 const MCSection *BSSSection; 49 50 /// ReadOnlySection - Section that is readonly and can contain arbitrary 51 /// initialized data. Targets are not required to have a readonly section. 52 /// If they don't, various bits of code will fall back to using the data 53 /// section for constants. 54 const MCSection *ReadOnlySection; 55 56 /// StaticCtorSection - This section contains the static constructor pointer 57 /// list. 58 const MCSection *StaticCtorSection; 59 60 /// StaticDtorSection - This section contains the static destructor pointer 61 /// list. 62 const MCSection *StaticDtorSection; 63 64 /// LSDASection - If exception handling is supported by the target, this is 65 /// the section the Language Specific Data Area information is emitted to. 66 const MCSection *LSDASection; 67 68 /// EHFrameSection - If exception handling is supported by the target, this is 69 /// the section the EH Frame is emitted to. 70 const MCSection *EHFrameSection; 71 72 // Dwarf sections for debug info. If a target supports debug info, these must 73 // be set. 74 const MCSection *DwarfAbbrevSection; 75 const MCSection *DwarfInfoSection; 76 const MCSection *DwarfLineSection; 77 const MCSection *DwarfFrameSection; 78 const MCSection *DwarfPubNamesSection; 79 const MCSection *DwarfPubTypesSection; 80 const MCSection *DwarfDebugInlineSection; 81 const MCSection *DwarfStrSection; 82 const MCSection *DwarfLocSection; 83 const MCSection *DwarfARangesSection; 84 const MCSection *DwarfRangesSection; 85 const MCSection *DwarfMacroInfoSection; 86 87public: 88 89 MCContext &getContext() const { return *Ctx; } 90 91 92 virtual ~TargetLoweringObjectFile(); 93 94 /// Initialize - this method must be called before any actual lowering is 95 /// done. This specifies the current context for codegen, and gives the 96 /// lowering implementations a chance to set up their default sections. 97 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) { 98 Ctx = &ctx; 99 } 100 101 102 const MCSection *getTextSection() const { return TextSection; } 103 const MCSection *getDataSection() const { return DataSection; } 104 const MCSection *getStaticCtorSection() const { return StaticCtorSection; } 105 const MCSection *getStaticDtorSection() const { return StaticDtorSection; } 106 const MCSection *getLSDASection() const { return LSDASection; } 107 const MCSection *getEHFrameSection() const { return EHFrameSection; } 108 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; } 109 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; } 110 const MCSection *getDwarfLineSection() const { return DwarfLineSection; } 111 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; } 112 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;} 113 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;} 114 const MCSection *getDwarfDebugInlineSection() const { 115 return DwarfDebugInlineSection; 116 } 117 const MCSection *getDwarfStrSection() const { return DwarfStrSection; } 118 const MCSection *getDwarfLocSection() const { return DwarfLocSection; } 119 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;} 120 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; } 121 const MCSection *getDwarfMacroInfoSection() const { 122 return DwarfMacroInfoSection; 123 } 124 125 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively 126 /// decide not to emit the UsedDirective for some symbols in llvm.used. 127 /// FIXME: REMOVE this (rdar://7071300) 128 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, 129 Mangler *) const { 130 return GV != 0; 131 } 132 133 /// getSectionForConstant - Given a constant with the SectionKind, return a 134 /// section that it should be placed in. 135 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 136 137 /// getKindForGlobal - Classify the specified global variable into a set of 138 /// target independent categories embodied in SectionKind. 139 static SectionKind getKindForGlobal(const GlobalValue *GV, 140 const TargetMachine &TM); 141 142 /// SectionForGlobal - This method computes the appropriate section to emit 143 /// the specified global variable or function definition. This should not 144 /// be passed external (or available externally) globals. 145 const MCSection *SectionForGlobal(const GlobalValue *GV, 146 SectionKind Kind, Mangler *Mang, 147 const TargetMachine &TM) const; 148 149 /// SectionForGlobal - This method computes the appropriate section to emit 150 /// the specified global variable or function definition. This should not 151 /// be passed external (or available externally) globals. 152 const MCSection *SectionForGlobal(const GlobalValue *GV, 153 Mangler *Mang, 154 const TargetMachine &TM) const { 155 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM); 156 } 157 158 159 160 /// getExplicitSectionGlobal - Targets should implement this method to assign 161 /// a section to globals with an explicit section specfied. The 162 /// implementation of this method can assume that GV->hasSection() is true. 163 virtual const MCSection * 164 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 165 Mangler *Mang, const TargetMachine &TM) const = 0; 166 167 /// getSpecialCasedSectionGlobals - Allow the target to completely override 168 /// section assignment of a global. 169 virtual const MCSection * 170 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang, 171 SectionKind Kind) const { 172 return 0; 173 } 174 175protected: 176 virtual const MCSection * 177 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 178 Mangler *Mang, const TargetMachine &TM) const; 179}; 180 181 182 183 184class TargetLoweringObjectFileELF : public TargetLoweringObjectFile { 185 bool HasCrazyBSS; 186 mutable void *UniquingMap; 187protected: 188 /// TLSDataSection - Section directive for Thread Local data. 189 /// 190 const MCSection *TLSDataSection; // Defaults to ".tdata". 191 192 /// TLSBSSSection - Section directive for Thread Local uninitialized data. 193 /// Null if this target doesn't support a BSS section. 194 /// 195 const MCSection *TLSBSSSection; // Defaults to ".tbss". 196 197 const MCSection *DataRelSection; 198 const MCSection *DataRelLocalSection; 199 const MCSection *DataRelROSection; 200 const MCSection *DataRelROLocalSection; 201 202 const MCSection *MergeableConst4Section; 203 const MCSection *MergeableConst8Section; 204 const MCSection *MergeableConst16Section; 205 206protected: 207 const MCSection *getELFSection(const char *Name, bool isDirective, 208 SectionKind Kind) const; 209public: 210 TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED. 211 bool hasCrazyBSS = false) 212 : HasCrazyBSS(hasCrazyBSS), UniquingMap(0) {} 213 214 ~TargetLoweringObjectFileELF(); 215 216 217 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 218 219 /// getSectionForConstant - Given a constant with the SectionKind, return a 220 /// section that it should be placed in. 221 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 222 223 224 virtual const MCSection * 225 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 226 Mangler *Mang, const TargetMachine &TM) const; 227 228 virtual const MCSection * 229 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 230 Mangler *Mang, const TargetMachine &TM) const; 231}; 232 233 234 235class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { 236 mutable void *UniquingMap; 237 238 const MCSection *CStringSection; 239 const MCSection *UStringSection; 240 const MCSection *TextCoalSection; 241 const MCSection *ConstTextCoalSection; 242 const MCSection *ConstDataCoalSection; 243 const MCSection *ConstDataSection; 244 const MCSection *DataCoalSection; 245 const MCSection *FourByteConstantSection; 246 const MCSection *EightByteConstantSection; 247 const MCSection *SixteenByteConstantSection; 248 249 const MCSection *LazySymbolPointerSection; 250 const MCSection *NonLazySymbolPointerSection; 251public: 252 TargetLoweringObjectFileMachO() : UniquingMap(0) {} 253 ~TargetLoweringObjectFileMachO(); 254 255 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 256 257 virtual const MCSection * 258 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 259 Mangler *Mang, const TargetMachine &TM) const; 260 261 virtual const MCSection * 262 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 263 Mangler *Mang, const TargetMachine &TM) const; 264 265 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 266 267 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively 268 /// decide not to emit the UsedDirective for some symbols in llvm.used. 269 /// FIXME: REMOVE this (rdar://7071300) 270 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, 271 Mangler *) const; 272 273 /// getMachOSection - Return the MCSection for the specified mach-o section. 274 /// This requires the operands to be valid. 275 const MCSectionMachO *getMachOSection(const StringRef &Segment, 276 const StringRef &Section, 277 unsigned TypeAndAttributes, 278 SectionKind K) const { 279 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K); 280 } 281 const MCSectionMachO *getMachOSection(const StringRef &Segment, 282 const StringRef &Section, 283 unsigned TypeAndAttributes, 284 unsigned Reserved2, 285 SectionKind K) const; 286 287 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak 288 /// symbols into. 289 const MCSection *getTextCoalSection() const { 290 return TextCoalSection; 291 } 292 293 /// getLazySymbolPointerSection - Return the section corresponding to 294 /// the .lazy_symbol_pointer directive. 295 const MCSection *getLazySymbolPointerSection() const { 296 return LazySymbolPointerSection; 297 } 298 299 /// getNonLazySymbolPointerSection - Return the section corresponding to 300 /// the .non_lazy_symbol_pointer directive. 301 const MCSection *getNonLazySymbolPointerSection() const { 302 return NonLazySymbolPointerSection; 303 } 304}; 305 306 307 308class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { 309 mutable void *UniquingMap; 310public: 311 TargetLoweringObjectFileCOFF() : UniquingMap(0) {} 312 ~TargetLoweringObjectFileCOFF(); 313 314 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 315 316 virtual const MCSection * 317 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 318 Mangler *Mang, const TargetMachine &TM) const; 319 320 virtual const MCSection * 321 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 322 Mangler *Mang, const TargetMachine &TM) const; 323 324 /// getCOFFSection - Return the MCSection for the specified COFF section. 325 /// FIXME: Switch this to a semantic view eventually. 326 const MCSection *getCOFFSection(const char *Name, bool isDirective, 327 SectionKind K) const; 328}; 329 330} // end namespace llvm 331 332#endif 333