1 //===-- llvm/MC/MCObjectFileInfo.h - Object File 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 describes common object file formats. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_MC_MCOBJECTFILEINFO_H 15 #define LLVM_MC_MCOBJECTFILEINFO_H 16 17 #include "llvm/ADT/Triple.h" 18 #include "llvm/Support/CodeGen.h" 19 20 namespace llvm { 21 class MCContext; 22 class MCSection; 23 24 class MCObjectFileInfo { 25 protected: 26 /// True if .comm supports alignment. This is a hack for as long as we 27 /// support 10.4 Tiger, whose assembler doesn't support alignment on comm. 28 bool CommDirectiveSupportsAlignment; 29 30 /// True if target object file supports a weak_definition of constant 0 for an 31 /// omitted EH frame. 32 bool SupportsWeakOmittedEHFrame; 33 34 /// True if the target object file supports emitting a compact unwind section 35 /// without an associated EH frame section. 36 bool SupportsCompactUnwindWithoutEHFrame; 37 38 /// Some encoding values for EH. 39 unsigned PersonalityEncoding; 40 unsigned LSDAEncoding; 41 unsigned FDECFIEncoding; 42 unsigned TTypeEncoding; 43 44 /// Section flags for eh_frame 45 unsigned EHSectionType; 46 unsigned EHSectionFlags; 47 48 /// Compact unwind encoding indicating that we should emit only an EH frame. 49 unsigned CompactUnwindDwarfEHFrameOnly; 50 51 /// Section directive for standard text. 52 MCSection *TextSection; 53 54 /// Section directive for standard data. 55 MCSection *DataSection; 56 57 /// Section that is default initialized to zero. 58 MCSection *BSSSection; 59 60 /// Section that is readonly and can contain arbitrary initialized data. 61 /// Targets are not required to have a readonly section. If they don't, 62 /// various bits of code will fall back to using the data section for 63 /// constants. 64 MCSection *ReadOnlySection; 65 66 /// This section contains the static constructor pointer list. 67 MCSection *StaticCtorSection; 68 69 /// This section contains the static destructor pointer list. 70 MCSection *StaticDtorSection; 71 72 /// If exception handling is supported by the target, this is the section the 73 /// Language Specific Data Area information is emitted to. 74 MCSection *LSDASection; 75 76 /// If exception handling is supported by the target and the target can 77 /// support a compact representation of the CIE and FDE, this is the section 78 /// to emit them into. 79 MCSection *CompactUnwindSection; 80 81 // Dwarf sections for debug info. If a target supports debug info, these must 82 // be set. 83 MCSection *DwarfAbbrevSection; 84 MCSection *DwarfInfoSection; 85 MCSection *DwarfLineSection; 86 MCSection *DwarfFrameSection; 87 MCSection *DwarfPubTypesSection; 88 const MCSection *DwarfDebugInlineSection; 89 MCSection *DwarfStrSection; 90 MCSection *DwarfLocSection; 91 MCSection *DwarfARangesSection; 92 MCSection *DwarfRangesSection; 93 // The pubnames section is no longer generated by default. The generation 94 // can be enabled by a compiler flag. 95 MCSection *DwarfPubNamesSection; 96 97 /// DWARF5 Experimental Debug Info Sections 98 /// DwarfAccelNamesSection, DwarfAccelObjCSection, 99 /// DwarfAccelNamespaceSection, DwarfAccelTypesSection - 100 /// If we use the DWARF accelerated hash tables then we want to emit these 101 /// sections. 102 MCSection *DwarfAccelNamesSection; 103 MCSection *DwarfAccelObjCSection; 104 MCSection *DwarfAccelNamespaceSection; 105 MCSection *DwarfAccelTypesSection; 106 107 // These are used for the Fission separate debug information files. 108 MCSection *DwarfInfoDWOSection; 109 MCSection *DwarfTypesDWOSection; 110 MCSection *DwarfAbbrevDWOSection; 111 MCSection *DwarfStrDWOSection; 112 MCSection *DwarfLineDWOSection; 113 MCSection *DwarfLocDWOSection; 114 MCSection *DwarfStrOffDWOSection; 115 MCSection *DwarfAddrSection; 116 117 /// Section for newer gnu pubnames. 118 MCSection *DwarfGnuPubNamesSection; 119 /// Section for newer gnu pubtypes. 120 MCSection *DwarfGnuPubTypesSection; 121 122 MCSection *COFFDebugSymbolsSection; 123 124 /// Extra TLS Variable Data section. 125 /// 126 /// If the target needs to put additional information for a TLS variable, 127 /// it'll go here. 128 MCSection *TLSExtraDataSection; 129 130 /// Section directive for Thread Local data. ELF, MachO and COFF. 131 MCSection *TLSDataSection; // Defaults to ".tdata". 132 133 /// Section directive for Thread Local uninitialized data. 134 /// 135 /// Null if this target doesn't support a BSS section. ELF and MachO only. 136 MCSection *TLSBSSSection; // Defaults to ".tbss". 137 138 /// StackMap section. 139 MCSection *StackMapSection; 140 141 /// FaultMap section. 142 MCSection *FaultMapSection; 143 144 /// EH frame section. 145 /// 146 /// It is initialized on demand so it can be overwritten (with uniquing). 147 MCSection *EHFrameSection; 148 149 // ELF specific sections. 150 MCSection *DataRelSection; 151 const MCSection *DataRelLocalSection; 152 MCSection *DataRelROSection; 153 MCSection *DataRelROLocalSection; 154 MCSection *MergeableConst4Section; 155 MCSection *MergeableConst8Section; 156 MCSection *MergeableConst16Section; 157 158 // MachO specific sections. 159 160 /// Section for thread local structure information. 161 /// 162 /// Contains the source code name of the variable, visibility and a pointer to 163 /// the initial value (.tdata or .tbss). 164 MCSection *TLSTLVSection; // Defaults to ".tlv". 165 166 /// Section for thread local data initialization functions. 167 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func". 168 169 MCSection *CStringSection; 170 MCSection *UStringSection; 171 MCSection *TextCoalSection; 172 MCSection *ConstTextCoalSection; 173 MCSection *ConstDataSection; 174 MCSection *DataCoalSection; 175 MCSection *DataCommonSection; 176 MCSection *DataBSSSection; 177 MCSection *FourByteConstantSection; 178 MCSection *EightByteConstantSection; 179 MCSection *SixteenByteConstantSection; 180 MCSection *LazySymbolPointerSection; 181 MCSection *NonLazySymbolPointerSection; 182 183 /// COFF specific sections. 184 MCSection *DrectveSection; 185 MCSection *PDataSection; 186 MCSection *XDataSection; 187 MCSection *SXDataSection; 188 189 public: 190 void InitMCObjectFileInfo(const Triple &TT, Reloc::Model RM, 191 CodeModel::Model CM, MCContext &ctx); 192 LLVM_ATTRIBUTE_DEPRECATED( 193 void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, 194 CodeModel::Model CM, MCContext &ctx), 195 "StringRef GNU Triple argument replaced by a llvm::Triple object"); 196 getSupportsWeakOmittedEHFrame()197 bool getSupportsWeakOmittedEHFrame() const { 198 return SupportsWeakOmittedEHFrame; 199 } getSupportsCompactUnwindWithoutEHFrame()200 bool getSupportsCompactUnwindWithoutEHFrame() const { 201 return SupportsCompactUnwindWithoutEHFrame; 202 } getCommDirectiveSupportsAlignment()203 bool getCommDirectiveSupportsAlignment() const { 204 return CommDirectiveSupportsAlignment; 205 } 206 getPersonalityEncoding()207 unsigned getPersonalityEncoding() const { return PersonalityEncoding; } getLSDAEncoding()208 unsigned getLSDAEncoding() const { return LSDAEncoding; } getFDEEncoding()209 unsigned getFDEEncoding() const { return FDECFIEncoding; } getTTypeEncoding()210 unsigned getTTypeEncoding() const { return TTypeEncoding; } 211 getCompactUnwindDwarfEHFrameOnly()212 unsigned getCompactUnwindDwarfEHFrameOnly() const { 213 return CompactUnwindDwarfEHFrameOnly; 214 } 215 getTextSection()216 MCSection *getTextSection() const { return TextSection; } getDataSection()217 MCSection *getDataSection() const { return DataSection; } getBSSSection()218 MCSection *getBSSSection() const { return BSSSection; } getLSDASection()219 MCSection *getLSDASection() const { return LSDASection; } getCompactUnwindSection()220 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; } getDwarfAbbrevSection()221 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; } getDwarfInfoSection()222 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; } getDwarfLineSection()223 MCSection *getDwarfLineSection() const { return DwarfLineSection; } getDwarfFrameSection()224 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; } getDwarfPubNamesSection()225 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; } getDwarfPubTypesSection()226 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; } getDwarfGnuPubNamesSection()227 MCSection *getDwarfGnuPubNamesSection() const { 228 return DwarfGnuPubNamesSection; 229 } getDwarfGnuPubTypesSection()230 MCSection *getDwarfGnuPubTypesSection() const { 231 return DwarfGnuPubTypesSection; 232 } getDwarfDebugInlineSection()233 const MCSection *getDwarfDebugInlineSection() const { 234 return DwarfDebugInlineSection; 235 } getDwarfStrSection()236 MCSection *getDwarfStrSection() const { return DwarfStrSection; } getDwarfLocSection()237 MCSection *getDwarfLocSection() const { return DwarfLocSection; } getDwarfARangesSection()238 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; } getDwarfRangesSection()239 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; } 240 241 // DWARF5 Experimental Debug Info Sections getDwarfAccelNamesSection()242 MCSection *getDwarfAccelNamesSection() const { 243 return DwarfAccelNamesSection; 244 } getDwarfAccelObjCSection()245 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; } getDwarfAccelNamespaceSection()246 MCSection *getDwarfAccelNamespaceSection() const { 247 return DwarfAccelNamespaceSection; 248 } getDwarfAccelTypesSection()249 MCSection *getDwarfAccelTypesSection() const { 250 return DwarfAccelTypesSection; 251 } getDwarfInfoDWOSection()252 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; } 253 MCSection *getDwarfTypesSection(uint64_t Hash) const; getDwarfTypesDWOSection()254 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; } getDwarfAbbrevDWOSection()255 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; } getDwarfStrDWOSection()256 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; } getDwarfLineDWOSection()257 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; } getDwarfLocDWOSection()258 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; } getDwarfStrOffDWOSection()259 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; } getDwarfAddrSection()260 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; } 261 getCOFFDebugSymbolsSection()262 MCSection *getCOFFDebugSymbolsSection() const { 263 return COFFDebugSymbolsSection; 264 } 265 getTLSExtraDataSection()266 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; } getTLSDataSection()267 const MCSection *getTLSDataSection() const { return TLSDataSection; } getTLSBSSSection()268 MCSection *getTLSBSSSection() const { return TLSBSSSection; } 269 getStackMapSection()270 MCSection *getStackMapSection() const { return StackMapSection; } getFaultMapSection()271 MCSection *getFaultMapSection() const { return FaultMapSection; } 272 273 // ELF specific sections. getDataRelSection()274 MCSection *getDataRelSection() const { return DataRelSection; } getDataRelLocalSection()275 const MCSection *getDataRelLocalSection() const { 276 return DataRelLocalSection; 277 } getDataRelROSection()278 MCSection *getDataRelROSection() const { return DataRelROSection; } getDataRelROLocalSection()279 MCSection *getDataRelROLocalSection() const { return DataRelROLocalSection; } getMergeableConst4Section()280 const MCSection *getMergeableConst4Section() const { 281 return MergeableConst4Section; 282 } getMergeableConst8Section()283 const MCSection *getMergeableConst8Section() const { 284 return MergeableConst8Section; 285 } getMergeableConst16Section()286 const MCSection *getMergeableConst16Section() const { 287 return MergeableConst16Section; 288 } 289 290 // MachO specific sections. getTLSTLVSection()291 const MCSection *getTLSTLVSection() const { return TLSTLVSection; } getTLSThreadInitSection()292 const MCSection *getTLSThreadInitSection() const { 293 return TLSThreadInitSection; 294 } getCStringSection()295 const MCSection *getCStringSection() const { return CStringSection; } getUStringSection()296 const MCSection *getUStringSection() const { return UStringSection; } getTextCoalSection()297 MCSection *getTextCoalSection() const { return TextCoalSection; } getConstTextCoalSection()298 const MCSection *getConstTextCoalSection() const { 299 return ConstTextCoalSection; 300 } getConstDataSection()301 const MCSection *getConstDataSection() const { return ConstDataSection; } getDataCoalSection()302 const MCSection *getDataCoalSection() const { return DataCoalSection; } getDataCommonSection()303 const MCSection *getDataCommonSection() const { return DataCommonSection; } getDataBSSSection()304 MCSection *getDataBSSSection() const { return DataBSSSection; } getFourByteConstantSection()305 const MCSection *getFourByteConstantSection() const { 306 return FourByteConstantSection; 307 } getEightByteConstantSection()308 const MCSection *getEightByteConstantSection() const { 309 return EightByteConstantSection; 310 } getSixteenByteConstantSection()311 const MCSection *getSixteenByteConstantSection() const { 312 return SixteenByteConstantSection; 313 } getLazySymbolPointerSection()314 MCSection *getLazySymbolPointerSection() const { 315 return LazySymbolPointerSection; 316 } getNonLazySymbolPointerSection()317 MCSection *getNonLazySymbolPointerSection() const { 318 return NonLazySymbolPointerSection; 319 } 320 321 // COFF specific sections. getDrectveSection()322 MCSection *getDrectveSection() const { return DrectveSection; } getPDataSection()323 MCSection *getPDataSection() const { return PDataSection; } getXDataSection()324 MCSection *getXDataSection() const { return XDataSection; } getSXDataSection()325 MCSection *getSXDataSection() const { return SXDataSection; } 326 getEHFrameSection()327 MCSection *getEHFrameSection() { 328 if (!EHFrameSection) 329 InitEHFrameSection(); 330 return EHFrameSection; 331 } 332 333 enum Environment { IsMachO, IsELF, IsCOFF }; getObjectFileType()334 Environment getObjectFileType() const { return Env; } 335 getRelocM()336 Reloc::Model getRelocM() const { return RelocM; } 337 338 private: 339 Environment Env; 340 Reloc::Model RelocM; 341 CodeModel::Model CMModel; 342 MCContext *Ctx; 343 Triple TT; 344 345 void initMachOMCObjectFileInfo(Triple T); 346 void initELFMCObjectFileInfo(Triple T); 347 void initCOFFMCObjectFileInfo(Triple T); 348 349 /// Initialize EHFrameSection on demand. 350 void InitEHFrameSection(); 351 352 public: getTargetTriple()353 const Triple &getTargetTriple() const { return TT; } 354 }; 355 356 } // end namespace llvm 357 358 #endif 359