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 21 namespace llvm { 22 class MachineModuleInfo; 23 class Mangler; 24 class MCAsmInfo; 25 class MCContext; 26 class MCExpr; 27 class MCSection; 28 class MCSectionMachO; 29 class MCSymbol; 30 class MCStreamer; 31 class GlobalValue; 32 class TargetMachine; 33 34 class TargetLoweringObjectFile { 35 MCContext *Ctx; 36 37 TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT 38 void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT 39 protected: 40 41 TargetLoweringObjectFile(); 42 43 /// TextSection - Section directive for standard text. 44 /// 45 const MCSection *TextSection; 46 47 /// DataSection - Section directive for standard data. 48 /// 49 const MCSection *DataSection; 50 51 /// BSSSection - Section that is default initialized to zero. 52 const MCSection *BSSSection; 53 54 /// ReadOnlySection - Section that is readonly and can contain arbitrary 55 /// initialized data. Targets are not required to have a readonly section. 56 /// If they don't, various bits of code will fall back to using the data 57 /// section for constants. 58 const MCSection *ReadOnlySection; 59 60 /// StaticCtorSection - This section contains the static constructor pointer 61 /// list. 62 const MCSection *StaticCtorSection; 63 64 /// StaticDtorSection - This section contains the static destructor pointer 65 /// list. 66 const MCSection *StaticDtorSection; 67 68 /// LSDASection - If exception handling is supported by the target, this is 69 /// the section the Language Specific Data Area information is emitted to. 70 const MCSection *LSDASection; 71 72 /// EHFrameSection - If exception handling is supported by the target, this is 73 /// the section the EH Frame is emitted to. 74 const MCSection *EHFrameSection; 75 76 // Dwarf sections for debug info. If a target supports debug info, these must 77 // be set. 78 const MCSection *DwarfAbbrevSection; 79 const MCSection *DwarfInfoSection; 80 const MCSection *DwarfLineSection; 81 const MCSection *DwarfFrameSection; 82 const MCSection *DwarfPubNamesSection; 83 const MCSection *DwarfPubTypesSection; 84 const MCSection *DwarfDebugInlineSection; 85 const MCSection *DwarfStrSection; 86 const MCSection *DwarfLocSection; 87 const MCSection *DwarfARangesSection; 88 const MCSection *DwarfRangesSection; 89 const MCSection *DwarfMacroInfoSection; 90 91 // Extra TLS Variable Data section. If the target needs to put additional 92 // information for a TLS variable, it'll go here. 93 const MCSection *TLSExtraDataSection; 94 95 /// SupportsWeakEmptyEHFrame - True if target object file supports a 96 /// weak_definition of constant 0 for an omitted EH frame. 97 bool SupportsWeakOmittedEHFrame; 98 99 /// IsFunctionEHSymbolGlobal - This flag is set to true if the ".eh" symbol 100 /// for a function should be marked .globl. 101 bool IsFunctionEHSymbolGlobal; 102 103 /// IsFunctionEHFrameSymbolPrivate - This flag is set to true if the 104 /// "EH_frame" symbol for EH information should be an assembler temporary (aka 105 /// private linkage, aka an L or .L label) or false if it should be a normal 106 /// non-.globl label. This defaults to true. 107 bool IsFunctionEHFrameSymbolPrivate; 108 public: 109 getContext()110 MCContext &getContext() const { return *Ctx; } 111 112 virtual ~TargetLoweringObjectFile(); 113 114 /// Initialize - this method must be called before any actual lowering is 115 /// done. This specifies the current context for codegen, and gives the 116 /// lowering implementations a chance to set up their default sections. Initialize(MCContext & ctx,const TargetMachine & TM)117 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) { 118 Ctx = &ctx; 119 } 120 isFunctionEHSymbolGlobal()121 bool isFunctionEHSymbolGlobal() const { 122 return IsFunctionEHSymbolGlobal; 123 } isFunctionEHFrameSymbolPrivate()124 bool isFunctionEHFrameSymbolPrivate() const { 125 return IsFunctionEHFrameSymbolPrivate; 126 } getSupportsWeakOmittedEHFrame()127 bool getSupportsWeakOmittedEHFrame() const { 128 return SupportsWeakOmittedEHFrame; 129 } 130 getTextSection()131 const MCSection *getTextSection() const { return TextSection; } getDataSection()132 const MCSection *getDataSection() const { return DataSection; } getBSSSection()133 const MCSection *getBSSSection() const { return BSSSection; } getStaticCtorSection()134 const MCSection *getStaticCtorSection() const { return StaticCtorSection; } getStaticDtorSection()135 const MCSection *getStaticDtorSection() const { return StaticDtorSection; } getLSDASection()136 const MCSection *getLSDASection() const { return LSDASection; } getEHFrameSection()137 const MCSection *getEHFrameSection() const { return EHFrameSection; } getDwarfAbbrevSection()138 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; } getDwarfInfoSection()139 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; } getDwarfLineSection()140 const MCSection *getDwarfLineSection() const { return DwarfLineSection; } getDwarfFrameSection()141 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; } getDwarfPubNamesSection()142 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;} getDwarfPubTypesSection()143 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;} getDwarfDebugInlineSection()144 const MCSection *getDwarfDebugInlineSection() const { 145 return DwarfDebugInlineSection; 146 } getDwarfStrSection()147 const MCSection *getDwarfStrSection() const { return DwarfStrSection; } getDwarfLocSection()148 const MCSection *getDwarfLocSection() const { return DwarfLocSection; } getDwarfARangesSection()149 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;} getDwarfRangesSection()150 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; } getDwarfMacroInfoSection()151 const MCSection *getDwarfMacroInfoSection() const { 152 return DwarfMacroInfoSection; 153 } getTLSExtraDataSection()154 const MCSection *getTLSExtraDataSection() const { 155 return TLSExtraDataSection; 156 } 157 158 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively 159 /// decide not to emit the UsedDirective for some symbols in llvm.used. 160 /// FIXME: REMOVE this (rdar://7071300) shouldEmitUsedDirectiveFor(const GlobalValue * GV,Mangler *)161 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, 162 Mangler *) const { 163 return GV != 0; 164 } 165 166 /// getSectionForConstant - Given a constant with the SectionKind, return a 167 /// section that it should be placed in. 168 virtual const MCSection *getSectionForConstant(SectionKind Kind) const; 169 170 /// getKindForGlobal - Classify the specified global variable into a set of 171 /// target independent categories embodied in SectionKind. 172 static SectionKind getKindForGlobal(const GlobalValue *GV, 173 const TargetMachine &TM); 174 175 /// SectionForGlobal - This method computes the appropriate section to emit 176 /// the specified global variable or function definition. This should not 177 /// be passed external (or available externally) globals. 178 const MCSection *SectionForGlobal(const GlobalValue *GV, 179 SectionKind Kind, Mangler *Mang, 180 const TargetMachine &TM) const; 181 182 /// SectionForGlobal - This method computes the appropriate section to emit 183 /// the specified global variable or function definition. This should not 184 /// be passed external (or available externally) globals. SectionForGlobal(const GlobalValue * GV,Mangler * Mang,const TargetMachine & TM)185 const MCSection *SectionForGlobal(const GlobalValue *GV, 186 Mangler *Mang, 187 const TargetMachine &TM) const { 188 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM); 189 } 190 191 192 193 /// getExplicitSectionGlobal - Targets should implement this method to assign 194 /// a section to globals with an explicit section specfied. The 195 /// implementation of this method can assume that GV->hasSection() is true. 196 virtual const MCSection * 197 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 198 Mangler *Mang, const TargetMachine &TM) const = 0; 199 200 /// getSpecialCasedSectionGlobals - Allow the target to completely override 201 /// section assignment of a global. 202 virtual const MCSection * getSpecialCasedSectionGlobals(const GlobalValue * GV,Mangler * Mang,SectionKind Kind)203 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang, 204 SectionKind Kind) const { 205 return 0; 206 } 207 208 /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference 209 /// to the specified global variable from exception handling information. 210 /// 211 virtual const MCExpr * 212 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, 213 MachineModuleInfo *MMI, unsigned Encoding, 214 MCStreamer &Streamer) const; 215 216 /// 217 const MCExpr * 218 getExprForDwarfReference(const MCSymbol *Sym, Mangler *Mang, 219 MachineModuleInfo *MMI, unsigned Encoding, 220 MCStreamer &Streamer) const; 221 222 virtual unsigned getPersonalityEncoding() const; 223 virtual unsigned getLSDAEncoding() const; 224 virtual unsigned getFDEEncoding() const; 225 virtual unsigned getTTypeEncoding() const; 226 227 protected: 228 virtual const MCSection * 229 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 230 Mangler *Mang, const TargetMachine &TM) const; 231 }; 232 233 } // end namespace llvm 234 235 #endif 236