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