MCObjectFileInfo.h 13 KB

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