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