TargetLoweringObjectFile.h revision 4813035b726e7f0a3fd17bec437185fc72a50988
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 *FourByteConstantSection; 262 const MCSection *EightByteConstantSection; 263 const MCSection *SixteenByteConstantSection; 264 265 const MCSection *LazySymbolPointerSection; 266 const MCSection *NonLazySymbolPointerSection; 267public: 268 TargetLoweringObjectFileMachO() : UniquingMap(0) {} 269 ~TargetLoweringObjectFileMachO(); 270 271 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 272 273 virtual const MCSection * 274 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 275 Mangler *Mang, const TargetMachine &TM) const; 276 277 virtual const MCSection * 278 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 279 Mangler *Mang, const TargetMachine &TM) const; 280 281 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 282 283 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively 284 /// decide not to emit the UsedDirective for some symbols in llvm.used. 285 /// FIXME: REMOVE this (rdar://7071300) 286 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, 287 Mangler *) const; 288 289 /// getMachOSection - Return the MCSection for the specified mach-o section. 290 /// This requires the operands to be valid. 291 const MCSectionMachO *getMachOSection(StringRef Segment, 292 StringRef Section, 293 unsigned TypeAndAttributes, 294 SectionKind K) const { 295 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K); 296 } 297 const MCSectionMachO *getMachOSection(StringRef Segment, 298 StringRef Section, 299 unsigned TypeAndAttributes, 300 unsigned Reserved2, 301 SectionKind K) const; 302 303 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak 304 /// text symbols into. 305 const MCSection *getTextCoalSection() const { 306 return TextCoalSection; 307 } 308 309 /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section 310 /// we put weak read-only symbols into. 311 const MCSection *getConstTextCoalSection() const { 312 return ConstTextCoalSection; 313 } 314 315 /// getLazySymbolPointerSection - Return the section corresponding to 316 /// the .lazy_symbol_pointer directive. 317 const MCSection *getLazySymbolPointerSection() const { 318 return LazySymbolPointerSection; 319 } 320 321 /// getNonLazySymbolPointerSection - Return the section corresponding to 322 /// the .non_lazy_symbol_pointer directive. 323 const MCSection *getNonLazySymbolPointerSection() const { 324 return NonLazySymbolPointerSection; 325 } 326 327 /// getSymbolForDwarfGlobalReference - The mach-o version of this method 328 /// defaults to returning a stub reference. 329 virtual const MCExpr * 330 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, 331 MachineModuleInfo *MMI, 332 bool &IsIndirect, bool &IsPCRel) const; 333}; 334 335 336 337class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { 338 mutable void *UniquingMap; 339public: 340 TargetLoweringObjectFileCOFF() : UniquingMap(0) {} 341 ~TargetLoweringObjectFileCOFF(); 342 343 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 344 345 virtual const MCSection * 346 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 347 Mangler *Mang, const TargetMachine &TM) const; 348 349 virtual const MCSection * 350 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 351 Mangler *Mang, const TargetMachine &TM) const; 352 353 /// getCOFFSection - Return the MCSection for the specified COFF section. 354 /// FIXME: Switch this to a semantic view eventually. 355 const MCSection *getCOFFSection(StringRef Name, bool isDirective, 356 SectionKind K) const; 357}; 358 359} // end namespace llvm 360 361#endif 362