TargetLoweringObjectFile.h revision 18a4c16726db2b8874c7b84d04650dda80746074
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 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 // FIXME: NONPUB. 86 const MCSection *getOrCreateSection(const char *Name, 87 bool isDirective, 88 SectionKind K) const; 89public: 90 91 virtual ~TargetLoweringObjectFile(); 92 93 /// Initialize - this method must be called before any actual lowering is 94 /// done. This specifies the current context for codegen, and gives the 95 /// lowering implementations a chance to set up their default sections. 96 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) { 97 Ctx = &ctx; 98 } 99 100 101 const MCSection *getTextSection() const { return TextSection; } 102 const MCSection *getDataSection() const { return DataSection; } 103 const MCSection *getStaticCtorSection() const { return StaticCtorSection; } 104 const MCSection *getStaticDtorSection() const { return StaticDtorSection; } 105 const MCSection *getLSDASection() const { return LSDASection; } 106 const MCSection *getEHFrameSection() const { return EHFrameSection; } 107 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; } 108 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; } 109 const MCSection *getDwarfLineSection() const { return DwarfLineSection; } 110 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; } 111 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;} 112 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;} 113 const MCSection *getDwarfDebugInlineSection() const { 114 return DwarfDebugInlineSection; 115 } 116 const MCSection *getDwarfStrSection() const { return DwarfStrSection; } 117 const MCSection *getDwarfLocSection() const { return DwarfLocSection; } 118 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;} 119 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; } 120 const MCSection *getDwarfMacroInfoSection() const { 121 return DwarfMacroInfoSection; 122 } 123 124 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively 125 /// decide not to emit the UsedDirective for some symbols in llvm.used. 126 /// FIXME: REMOVE this (rdar://7071300) 127 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, 128 Mangler *) const { 129 return GV != 0; 130 } 131 132 /// getSectionForConstant - Given a constant with the SectionKind, return a 133 /// section that it should be placed in. 134 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 135 136 /// getKindForNamedSection - If this target wants to be able to override 137 /// section flags based on the name of the section specified for a global 138 /// variable, it can implement this. This is used on ELF systems so that 139 /// ".tbss" gets the TLS bit set etc. 140 virtual SectionKind getKindForNamedSection(const char *Section, 141 SectionKind K) const { 142 return K; 143 } 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 Mangler *Mang, 150 const TargetMachine &TM) const; 151 152 /// getSpecialCasedSectionGlobals - Allow the target to completely override 153 /// section assignment of a global. 154 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with 155 /// getFlagsForNamedSection. 156 virtual const MCSection * 157 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang, 158 SectionKind Kind) const { 159 return 0; 160 } 161 162 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind 163 /// into a string that can be printed to the assembly file after the 164 /// ".section foo" part of a section directive. 165 virtual void getSectionFlagsAsString(SectionKind Kind, 166 SmallVectorImpl<char> &Str) const { 167 } 168 169protected: 170 virtual const MCSection * 171 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 172 Mangler *Mang, const TargetMachine &TM) const; 173}; 174 175 176 177 178class TargetLoweringObjectFileELF : public TargetLoweringObjectFile { 179 bool AtIsCommentChar; // True if @ is the comment character on this target. 180 bool HasCrazyBSS; 181protected: 182 /// TLSDataSection - Section directive for Thread Local data. 183 /// 184 const MCSection *TLSDataSection; // Defaults to ".tdata". 185 186 /// TLSBSSSection - Section directive for Thread Local uninitialized data. 187 /// Null if this target doesn't support a BSS section. 188 /// 189 const MCSection *TLSBSSSection; // Defaults to ".tbss". 190 191 const MCSection *CStringSection; 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; 201public: 202 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI 203 /// is "@". 204 TargetLoweringObjectFileELF(bool atIsCommentChar = false, 205 // FIXME: REMOVE AFTER UNIQUING IS FIXED. 206 bool hasCrazyBSS = false) 207 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {} 208 209 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 210 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 virtual SectionKind getKindForNamedSection(const char *Section, 217 SectionKind K) const; 218 void getSectionFlagsAsString(SectionKind Kind, 219 SmallVectorImpl<char> &Str) 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 *TextCoalSection; 231 const MCSection *ConstTextCoalSection; 232 const MCSection *ConstDataCoalSection; 233 const MCSection *ConstDataSection; 234 const MCSection *DataCoalSection; 235 const MCSection *FourByteConstantSection; 236 const MCSection *EightByteConstantSection; 237 const MCSection *SixteenByteConstantSection; 238public: 239 240 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 241 242 virtual const MCSection * 243 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 244 Mangler *Mang, const TargetMachine &TM) const; 245 246 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 247 248 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively 249 /// decide not to emit the UsedDirective for some symbols in llvm.used. 250 /// FIXME: REMOVE this (rdar://7071300) 251 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, 252 Mangler *) const; 253}; 254 255 256 257class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { 258public: 259 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); 260 261 virtual void getSectionFlagsAsString(SectionKind Kind, 262 SmallVectorImpl<char> &Str) const; 263 264 virtual const MCSection * 265 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 266 Mangler *Mang, const TargetMachine &TM) const; 267}; 268 269} // end namespace llvm 270 271#endif 272