MCObjectFileInfo.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/MC/MCObjectFileInfo.h - Object File Info -----------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file describes common object file formats.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_MC_MCOBJECTFILEINFO_H
  18. #define LLVM_MC_MCOBJECTFILEINFO_H
  19. #include "llvm/ADT/DenseMap.h"
  20. #include "llvm/ADT/Triple.h"
  21. #include "llvm/BinaryFormat/Swift.h"
  22. #include "llvm/MC/MCSymbol.h"
  23. #include "llvm/Support/CodeGen.h"
  24. #include "llvm/Support/VersionTuple.h"
  25. namespace llvm {
  26. class MCContext;
  27. class MCSection;
  28. class MCObjectFileInfo {
  29. protected:
  30. /// True if .comm supports alignment. This is a hack for as long as we
  31. /// support 10.4 Tiger, whose assembler doesn't support alignment on comm.
  32. bool CommDirectiveSupportsAlignment = false;
  33. /// True if target object file supports a weak_definition of constant 0 for an
  34. /// omitted EH frame.
  35. bool SupportsWeakOmittedEHFrame = false;
  36. /// True if the target object file supports emitting a compact unwind section
  37. /// without an associated EH frame section.
  38. bool SupportsCompactUnwindWithoutEHFrame = false;
  39. /// OmitDwarfIfHaveCompactUnwind - True if the target object file
  40. /// supports having some functions with compact unwind and other with
  41. /// dwarf unwind.
  42. bool OmitDwarfIfHaveCompactUnwind = false;
  43. /// FDE CFI encoding. Controls the encoding of the begin label in the
  44. /// .eh_frame section. Unlike the LSDA encoding, personality encoding, and
  45. /// type encodings, this is something that the assembler just "knows" about
  46. /// its target
  47. unsigned FDECFIEncoding = 0;
  48. /// Compact unwind encoding indicating that we should emit only an EH frame.
  49. unsigned CompactUnwindDwarfEHFrameOnly = 0;
  50. /// Section directive for standard text.
  51. MCSection *TextSection = nullptr;
  52. /// Section directive for standard data.
  53. MCSection *DataSection = nullptr;
  54. /// Section that is default initialized to zero.
  55. MCSection *BSSSection = nullptr;
  56. /// Section that is readonly and can contain arbitrary initialized data.
  57. /// Targets are not required to have a readonly section. If they don't,
  58. /// various bits of code will fall back to using the data section for
  59. /// constants.
  60. MCSection *ReadOnlySection = nullptr;
  61. /// If exception handling is supported by the target, this is the section the
  62. /// Language Specific Data Area information is emitted to.
  63. MCSection *LSDASection = nullptr;
  64. /// If exception handling is supported by the target and the target can
  65. /// support a compact representation of the CIE and FDE, this is the section
  66. /// to emit them into.
  67. MCSection *CompactUnwindSection = nullptr;
  68. // Dwarf sections for debug info. If a target supports debug info, these must
  69. // be set.
  70. MCSection *DwarfAbbrevSection = nullptr;
  71. MCSection *DwarfInfoSection = nullptr;
  72. MCSection *DwarfLineSection = nullptr;
  73. MCSection *DwarfLineStrSection = nullptr;
  74. MCSection *DwarfFrameSection = nullptr;
  75. MCSection *DwarfPubTypesSection = nullptr;
  76. const MCSection *DwarfDebugInlineSection = nullptr;
  77. MCSection *DwarfStrSection = nullptr;
  78. MCSection *DwarfLocSection = nullptr;
  79. MCSection *DwarfARangesSection = nullptr;
  80. MCSection *DwarfRangesSection = nullptr;
  81. MCSection *DwarfMacinfoSection = nullptr;
  82. MCSection *DwarfMacroSection = nullptr;
  83. // The pubnames section is no longer generated by default. The generation
  84. // can be enabled by a compiler flag.
  85. MCSection *DwarfPubNamesSection = nullptr;
  86. /// Accelerator table sections. DwarfDebugNamesSection is the DWARF v5
  87. /// accelerator table, while DwarfAccelNamesSection, DwarfAccelObjCSection,
  88. /// DwarfAccelNamespaceSection, DwarfAccelTypesSection are pre-DWARF v5
  89. /// extensions.
  90. MCSection *DwarfDebugNamesSection = nullptr;
  91. MCSection *DwarfAccelNamesSection = nullptr;
  92. MCSection *DwarfAccelObjCSection = nullptr;
  93. MCSection *DwarfAccelNamespaceSection = nullptr;
  94. MCSection *DwarfAccelTypesSection = nullptr;
  95. // These are used for the Fission separate debug information files.
  96. MCSection *DwarfInfoDWOSection = nullptr;
  97. MCSection *DwarfTypesDWOSection = nullptr;
  98. MCSection *DwarfAbbrevDWOSection = nullptr;
  99. MCSection *DwarfStrDWOSection = nullptr;
  100. MCSection *DwarfLineDWOSection = nullptr;
  101. MCSection *DwarfLocDWOSection = nullptr;
  102. MCSection *DwarfStrOffDWOSection = nullptr;
  103. MCSection *DwarfMacinfoDWOSection = nullptr;
  104. MCSection *DwarfMacroDWOSection = nullptr;
  105. /// The DWARF v5 string offset and address table sections.
  106. MCSection *DwarfStrOffSection = nullptr;
  107. MCSection *DwarfAddrSection = nullptr;
  108. /// The DWARF v5 range list section.
  109. MCSection *DwarfRnglistsSection = nullptr;
  110. /// The DWARF v5 locations list section.
  111. MCSection *DwarfLoclistsSection = nullptr;
  112. /// The DWARF v5 range and location list sections for fission.
  113. MCSection *DwarfRnglistsDWOSection = nullptr;
  114. MCSection *DwarfLoclistsDWOSection = nullptr;
  115. // These are for Fission DWP files.
  116. MCSection *DwarfCUIndexSection = nullptr;
  117. MCSection *DwarfTUIndexSection = nullptr;
  118. /// Section for newer gnu pubnames.
  119. MCSection *DwarfGnuPubNamesSection = nullptr;
  120. /// Section for newer gnu pubtypes.
  121. MCSection *DwarfGnuPubTypesSection = nullptr;
  122. // Section for Swift AST
  123. MCSection *DwarfSwiftASTSection = nullptr;
  124. MCSection *COFFDebugSymbolsSection = nullptr;
  125. MCSection *COFFDebugTypesSection = nullptr;
  126. MCSection *COFFGlobalTypeHashesSection = nullptr;
  127. /// Extra TLS Variable Data section.
  128. ///
  129. /// If the target needs to put additional information for a TLS variable,
  130. /// it'll go here.
  131. MCSection *TLSExtraDataSection = nullptr;
  132. /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
  133. MCSection *TLSDataSection = nullptr; // Defaults to ".tdata".
  134. /// Section directive for Thread Local uninitialized data.
  135. ///
  136. /// Null if this target doesn't support a BSS section. ELF and MachO only.
  137. MCSection *TLSBSSSection = nullptr; // Defaults to ".tbss".
  138. /// StackMap section.
  139. MCSection *StackMapSection = nullptr;
  140. /// FaultMap section.
  141. MCSection *FaultMapSection = nullptr;
  142. /// Remarks section.
  143. MCSection *RemarksSection = nullptr;
  144. /// EH frame section.
  145. ///
  146. /// It is initialized on demand so it can be overwritten (with uniquing).
  147. MCSection *EHFrameSection = nullptr;
  148. /// Section containing metadata on function stack sizes.
  149. MCSection *StackSizesSection = nullptr;
  150. /// Section for pseudo probe information used by AutoFDO
  151. MCSection *PseudoProbeSection = nullptr;
  152. MCSection *PseudoProbeDescSection = nullptr;
  153. // ELF specific sections.
  154. MCSection *DataRelROSection = nullptr;
  155. MCSection *MergeableConst4Section = nullptr;
  156. MCSection *MergeableConst8Section = nullptr;
  157. MCSection *MergeableConst16Section = nullptr;
  158. MCSection *MergeableConst32Section = nullptr;
  159. // MachO specific sections.
  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 = nullptr; // Defaults to ".tlv".
  165. /// Section for thread local data initialization functions.
  166. // Defaults to ".thread_init_func".
  167. const MCSection *TLSThreadInitSection = nullptr;
  168. MCSection *CStringSection = nullptr;
  169. MCSection *UStringSection = nullptr;
  170. MCSection *TextCoalSection = nullptr;
  171. MCSection *ConstTextCoalSection = nullptr;
  172. MCSection *ConstDataSection = nullptr;
  173. MCSection *DataCoalSection = nullptr;
  174. MCSection *ConstDataCoalSection = nullptr;
  175. MCSection *DataCommonSection = nullptr;
  176. MCSection *DataBSSSection = nullptr;
  177. MCSection *FourByteConstantSection = nullptr;
  178. MCSection *EightByteConstantSection = nullptr;
  179. MCSection *SixteenByteConstantSection = nullptr;
  180. MCSection *LazySymbolPointerSection = nullptr;
  181. MCSection *NonLazySymbolPointerSection = nullptr;
  182. MCSection *ThreadLocalPointerSection = nullptr;
  183. /// COFF specific sections.
  184. MCSection *DrectveSection = nullptr;
  185. MCSection *PDataSection = nullptr;
  186. MCSection *XDataSection = nullptr;
  187. MCSection *SXDataSection = nullptr;
  188. MCSection *GEHContSection = nullptr;
  189. MCSection *GFIDsSection = nullptr;
  190. MCSection *GIATsSection = nullptr;
  191. MCSection *GLJMPSection = nullptr;
  192. // XCOFF specific sections
  193. MCSection *TOCBaseSection = nullptr;
  194. MCSection *ReadOnly8Section = nullptr;
  195. MCSection *ReadOnly16Section = nullptr;
  196. // Swift5 Reflection Data Sections
  197. std::array<MCSection *, binaryformat::Swift5ReflectionSectionKind::last>
  198. Swift5ReflectionSections = {};
  199. public:
  200. void initMCObjectFileInfo(MCContext &MCCtx, bool PIC,
  201. bool LargeCodeModel = false);
  202. virtual ~MCObjectFileInfo();
  203. MCContext &getContext() const { return *Ctx; }
  204. bool getSupportsWeakOmittedEHFrame() const {
  205. return SupportsWeakOmittedEHFrame;
  206. }
  207. bool getSupportsCompactUnwindWithoutEHFrame() const {
  208. return SupportsCompactUnwindWithoutEHFrame;
  209. }
  210. bool getOmitDwarfIfHaveCompactUnwind() const {
  211. return OmitDwarfIfHaveCompactUnwind;
  212. }
  213. bool getCommDirectiveSupportsAlignment() const {
  214. return CommDirectiveSupportsAlignment;
  215. }
  216. unsigned getFDEEncoding() const { return FDECFIEncoding; }
  217. unsigned getCompactUnwindDwarfEHFrameOnly() const {
  218. return CompactUnwindDwarfEHFrameOnly;
  219. }
  220. virtual unsigned getTextSectionAlignment() const { return 4; }
  221. MCSection *getTextSection() const { return TextSection; }
  222. MCSection *getDataSection() const { return DataSection; }
  223. MCSection *getBSSSection() const { return BSSSection; }
  224. MCSection *getReadOnlySection() const { return ReadOnlySection; }
  225. MCSection *getLSDASection() const { return LSDASection; }
  226. MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
  227. MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
  228. MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
  229. MCSection *getDwarfInfoSection(uint64_t Hash) const {
  230. return getDwarfComdatSection(".debug_info", Hash);
  231. }
  232. MCSection *getDwarfLineSection() const { return DwarfLineSection; }
  233. MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; }
  234. MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
  235. MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
  236. MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
  237. MCSection *getDwarfGnuPubNamesSection() const {
  238. return DwarfGnuPubNamesSection;
  239. }
  240. MCSection *getDwarfGnuPubTypesSection() const {
  241. return DwarfGnuPubTypesSection;
  242. }
  243. const MCSection *getDwarfDebugInlineSection() const {
  244. return DwarfDebugInlineSection;
  245. }
  246. MCSection *getDwarfStrSection() const { return DwarfStrSection; }
  247. MCSection *getDwarfLocSection() const { return DwarfLocSection; }
  248. MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
  249. MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
  250. MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; }
  251. MCSection *getDwarfLoclistsSection() const { return DwarfLoclistsSection; }
  252. MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
  253. MCSection *getDwarfMacroSection() const { return DwarfMacroSection; }
  254. MCSection *getDwarfDebugNamesSection() const {
  255. return DwarfDebugNamesSection;
  256. }
  257. MCSection *getDwarfAccelNamesSection() const {
  258. return DwarfAccelNamesSection;
  259. }
  260. MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
  261. MCSection *getDwarfAccelNamespaceSection() const {
  262. return DwarfAccelNamespaceSection;
  263. }
  264. MCSection *getDwarfAccelTypesSection() const {
  265. return DwarfAccelTypesSection;
  266. }
  267. MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
  268. MCSection *getDwarfTypesSection(uint64_t Hash) const {
  269. return getDwarfComdatSection(".debug_types", Hash);
  270. }
  271. MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
  272. MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
  273. MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
  274. MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
  275. MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
  276. MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
  277. MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; }
  278. MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
  279. MCSection *getDwarfRnglistsDWOSection() const {
  280. return DwarfRnglistsDWOSection;
  281. }
  282. MCSection *getDwarfLoclistsDWOSection() const {
  283. return DwarfLoclistsDWOSection;
  284. }
  285. MCSection *getDwarfMacroDWOSection() const { return DwarfMacroDWOSection; }
  286. MCSection *getDwarfMacinfoDWOSection() const {
  287. return DwarfMacinfoDWOSection;
  288. }
  289. MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
  290. MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
  291. MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
  292. MCSection *getCOFFDebugSymbolsSection() const {
  293. return COFFDebugSymbolsSection;
  294. }
  295. MCSection *getCOFFDebugTypesSection() const {
  296. return COFFDebugTypesSection;
  297. }
  298. MCSection *getCOFFGlobalTypeHashesSection() const {
  299. return COFFGlobalTypeHashesSection;
  300. }
  301. MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
  302. const MCSection *getTLSDataSection() const { return TLSDataSection; }
  303. MCSection *getTLSBSSSection() const { return TLSBSSSection; }
  304. MCSection *getStackMapSection() const { return StackMapSection; }
  305. MCSection *getFaultMapSection() const { return FaultMapSection; }
  306. MCSection *getRemarksSection() const { return RemarksSection; }
  307. MCSection *getStackSizesSection(const MCSection &TextSec) const;
  308. MCSection *getBBAddrMapSection(const MCSection &TextSec) const;
  309. MCSection *getPseudoProbeSection(const MCSection *TextSec) const;
  310. MCSection *getPseudoProbeDescSection(StringRef FuncName) const;
  311. // ELF specific sections.
  312. MCSection *getDataRelROSection() const { return DataRelROSection; }
  313. const MCSection *getMergeableConst4Section() const {
  314. return MergeableConst4Section;
  315. }
  316. const MCSection *getMergeableConst8Section() const {
  317. return MergeableConst8Section;
  318. }
  319. const MCSection *getMergeableConst16Section() const {
  320. return MergeableConst16Section;
  321. }
  322. const MCSection *getMergeableConst32Section() const {
  323. return MergeableConst32Section;
  324. }
  325. // MachO specific sections.
  326. const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
  327. const MCSection *getTLSThreadInitSection() const {
  328. return TLSThreadInitSection;
  329. }
  330. const MCSection *getCStringSection() const { return CStringSection; }
  331. const MCSection *getUStringSection() const { return UStringSection; }
  332. MCSection *getTextCoalSection() const { return TextCoalSection; }
  333. const MCSection *getConstTextCoalSection() const {
  334. return ConstTextCoalSection;
  335. }
  336. const MCSection *getConstDataSection() const { return ConstDataSection; }
  337. const MCSection *getDataCoalSection() const { return DataCoalSection; }
  338. const MCSection *getConstDataCoalSection() const {
  339. return ConstDataCoalSection;
  340. }
  341. const MCSection *getDataCommonSection() const { return DataCommonSection; }
  342. MCSection *getDataBSSSection() const { return DataBSSSection; }
  343. const MCSection *getFourByteConstantSection() const {
  344. return FourByteConstantSection;
  345. }
  346. const MCSection *getEightByteConstantSection() const {
  347. return EightByteConstantSection;
  348. }
  349. const MCSection *getSixteenByteConstantSection() const {
  350. return SixteenByteConstantSection;
  351. }
  352. MCSection *getLazySymbolPointerSection() const {
  353. return LazySymbolPointerSection;
  354. }
  355. MCSection *getNonLazySymbolPointerSection() const {
  356. return NonLazySymbolPointerSection;
  357. }
  358. MCSection *getThreadLocalPointerSection() const {
  359. return ThreadLocalPointerSection;
  360. }
  361. // COFF specific sections.
  362. MCSection *getDrectveSection() const { return DrectveSection; }
  363. MCSection *getPDataSection() const { return PDataSection; }
  364. MCSection *getXDataSection() const { return XDataSection; }
  365. MCSection *getSXDataSection() const { return SXDataSection; }
  366. MCSection *getGEHContSection() const { return GEHContSection; }
  367. MCSection *getGFIDsSection() const { return GFIDsSection; }
  368. MCSection *getGIATsSection() const { return GIATsSection; }
  369. MCSection *getGLJMPSection() const { return GLJMPSection; }
  370. // XCOFF specific sections
  371. MCSection *getTOCBaseSection() const { return TOCBaseSection; }
  372. MCSection *getEHFrameSection() const { return EHFrameSection; }
  373. bool isPositionIndependent() const { return PositionIndependent; }
  374. // Swift5 Reflection Data Sections
  375. MCSection *getSwift5ReflectionSection(
  376. llvm::binaryformat::Swift5ReflectionSectionKind ReflSectionKind) {
  377. return ReflSectionKind !=
  378. llvm::binaryformat::Swift5ReflectionSectionKind::unknown
  379. ? Swift5ReflectionSections[ReflSectionKind]
  380. : nullptr;
  381. }
  382. private:
  383. bool PositionIndependent = false;
  384. MCContext *Ctx = nullptr;
  385. VersionTuple SDKVersion;
  386. Optional<Triple> DarwinTargetVariantTriple;
  387. VersionTuple DarwinTargetVariantSDKVersion;
  388. void initMachOMCObjectFileInfo(const Triple &T);
  389. void initELFMCObjectFileInfo(const Triple &T, bool Large);
  390. void initGOFFMCObjectFileInfo(const Triple &T);
  391. void initCOFFMCObjectFileInfo(const Triple &T);
  392. void initWasmMCObjectFileInfo(const Triple &T);
  393. void initXCOFFMCObjectFileInfo(const Triple &T);
  394. MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const;
  395. public:
  396. void setSDKVersion(const VersionTuple &TheSDKVersion) {
  397. SDKVersion = TheSDKVersion;
  398. }
  399. const VersionTuple &getSDKVersion() const { return SDKVersion; }
  400. void setDarwinTargetVariantTriple(const Triple &T) {
  401. DarwinTargetVariantTriple = T;
  402. }
  403. const Triple *getDarwinTargetVariantTriple() const {
  404. return DarwinTargetVariantTriple ? DarwinTargetVariantTriple.getPointer()
  405. : nullptr;
  406. }
  407. void setDarwinTargetVariantSDKVersion(const VersionTuple &TheSDKVersion) {
  408. DarwinTargetVariantSDKVersion = TheSDKVersion;
  409. }
  410. const VersionTuple &getDarwinTargetVariantSDKVersion() const {
  411. return DarwinTargetVariantSDKVersion;
  412. }
  413. };
  414. } // end namespace llvm
  415. #endif
  416. #ifdef __GNUC__
  417. #pragma GCC diagnostic pop
  418. #endif