MCObjectFileInfo.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. //===-- MObjectFileInfo.cpp - Object File Information ---------------------===//
  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. #include "llvm/MC/MCObjectFileInfo.h"
  10. #include "llvm/ADT/Triple.h"
  11. #include "llvm/MC/MCContext.h"
  12. #include "llvm/MC/MCSection.h"
  13. #include "llvm/MC/MCSectionCOFF.h"
  14. #include "llvm/MC/MCSectionELF.h"
  15. #include "llvm/MC/MCSectionMachO.h"
  16. using namespace llvm;
  17. void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
  18. // MachO
  19. IsFunctionEHFrameSymbolPrivate = false;
  20. SupportsWeakOmittedEHFrame = false;
  21. PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
  22. | dwarf::DW_EH_PE_sdata4;
  23. LSDAEncoding = FDEEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
  24. TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  25. dwarf::DW_EH_PE_sdata4;
  26. // .comm doesn't support alignment before Leopard.
  27. if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
  28. CommDirectiveSupportsAlignment = false;
  29. TextSection // .text
  30. = Ctx->getMachOSection("__TEXT", "__text",
  31. MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
  32. SectionKind::getText());
  33. DataSection // .data
  34. = Ctx->getMachOSection("__DATA", "__data", 0,
  35. SectionKind::getDataRel());
  36. // BSSSection might not be expected initialized on msvc.
  37. BSSSection = 0;
  38. TLSDataSection // .tdata
  39. = Ctx->getMachOSection("__DATA", "__thread_data",
  40. MCSectionMachO::S_THREAD_LOCAL_REGULAR,
  41. SectionKind::getDataRel());
  42. TLSBSSSection // .tbss
  43. = Ctx->getMachOSection("__DATA", "__thread_bss",
  44. MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
  45. SectionKind::getThreadBSS());
  46. // TODO: Verify datarel below.
  47. TLSTLVSection // .tlv
  48. = Ctx->getMachOSection("__DATA", "__thread_vars",
  49. MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
  50. SectionKind::getDataRel());
  51. TLSThreadInitSection
  52. = Ctx->getMachOSection("__DATA", "__thread_init",
  53. MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
  54. SectionKind::getDataRel());
  55. CStringSection // .cstring
  56. = Ctx->getMachOSection("__TEXT", "__cstring",
  57. MCSectionMachO::S_CSTRING_LITERALS,
  58. SectionKind::getMergeable1ByteCString());
  59. UStringSection
  60. = Ctx->getMachOSection("__TEXT","__ustring", 0,
  61. SectionKind::getMergeable2ByteCString());
  62. FourByteConstantSection // .literal4
  63. = Ctx->getMachOSection("__TEXT", "__literal4",
  64. MCSectionMachO::S_4BYTE_LITERALS,
  65. SectionKind::getMergeableConst4());
  66. EightByteConstantSection // .literal8
  67. = Ctx->getMachOSection("__TEXT", "__literal8",
  68. MCSectionMachO::S_8BYTE_LITERALS,
  69. SectionKind::getMergeableConst8());
  70. // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
  71. // to using it in -static mode.
  72. SixteenByteConstantSection = 0;
  73. if (RelocM != Reloc::Static &&
  74. T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 &&
  75. T.getArch() != Triple::ppc64le)
  76. SixteenByteConstantSection = // .literal16
  77. Ctx->getMachOSection("__TEXT", "__literal16",
  78. MCSectionMachO::S_16BYTE_LITERALS,
  79. SectionKind::getMergeableConst16());
  80. ReadOnlySection // .const
  81. = Ctx->getMachOSection("__TEXT", "__const", 0,
  82. SectionKind::getReadOnly());
  83. TextCoalSection
  84. = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
  85. MCSectionMachO::S_COALESCED |
  86. MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
  87. SectionKind::getText());
  88. ConstTextCoalSection
  89. = Ctx->getMachOSection("__TEXT", "__const_coal",
  90. MCSectionMachO::S_COALESCED,
  91. SectionKind::getReadOnly());
  92. ConstDataSection // .const_data
  93. = Ctx->getMachOSection("__DATA", "__const", 0,
  94. SectionKind::getReadOnlyWithRel());
  95. DataCoalSection
  96. = Ctx->getMachOSection("__DATA","__datacoal_nt",
  97. MCSectionMachO::S_COALESCED,
  98. SectionKind::getDataRel());
  99. DataCommonSection
  100. = Ctx->getMachOSection("__DATA","__common",
  101. MCSectionMachO::S_ZEROFILL,
  102. SectionKind::getBSS());
  103. DataBSSSection
  104. = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
  105. SectionKind::getBSS());
  106. LazySymbolPointerSection
  107. = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
  108. MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
  109. SectionKind::getMetadata());
  110. NonLazySymbolPointerSection
  111. = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
  112. MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
  113. SectionKind::getMetadata());
  114. if (RelocM == Reloc::Static) {
  115. StaticCtorSection
  116. = Ctx->getMachOSection("__TEXT", "__constructor", 0,
  117. SectionKind::getDataRel());
  118. StaticDtorSection
  119. = Ctx->getMachOSection("__TEXT", "__destructor", 0,
  120. SectionKind::getDataRel());
  121. } else {
  122. StaticCtorSection
  123. = Ctx->getMachOSection("__DATA", "__mod_init_func",
  124. MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
  125. SectionKind::getDataRel());
  126. StaticDtorSection
  127. = Ctx->getMachOSection("__DATA", "__mod_term_func",
  128. MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
  129. SectionKind::getDataRel());
  130. }
  131. // Exception Handling.
  132. LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
  133. SectionKind::getReadOnlyWithRel());
  134. if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
  135. CompactUnwindSection =
  136. Ctx->getMachOSection("__LD", "__compact_unwind",
  137. MCSectionMachO::S_ATTR_DEBUG,
  138. SectionKind::getReadOnly());
  139. if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
  140. CompactUnwindDwarfEHFrameOnly = 0x04000000;
  141. }
  142. // Debug Information.
  143. DwarfAccelNamesSection =
  144. Ctx->getMachOSection("__DWARF", "__apple_names",
  145. MCSectionMachO::S_ATTR_DEBUG,
  146. SectionKind::getMetadata());
  147. DwarfAccelObjCSection =
  148. Ctx->getMachOSection("__DWARF", "__apple_objc",
  149. MCSectionMachO::S_ATTR_DEBUG,
  150. SectionKind::getMetadata());
  151. // 16 character section limit...
  152. DwarfAccelNamespaceSection =
  153. Ctx->getMachOSection("__DWARF", "__apple_namespac",
  154. MCSectionMachO::S_ATTR_DEBUG,
  155. SectionKind::getMetadata());
  156. DwarfAccelTypesSection =
  157. Ctx->getMachOSection("__DWARF", "__apple_types",
  158. MCSectionMachO::S_ATTR_DEBUG,
  159. SectionKind::getMetadata());
  160. DwarfAbbrevSection =
  161. Ctx->getMachOSection("__DWARF", "__debug_abbrev",
  162. MCSectionMachO::S_ATTR_DEBUG,
  163. SectionKind::getMetadata());
  164. DwarfInfoSection =
  165. Ctx->getMachOSection("__DWARF", "__debug_info",
  166. MCSectionMachO::S_ATTR_DEBUG,
  167. SectionKind::getMetadata());
  168. DwarfLineSection =
  169. Ctx->getMachOSection("__DWARF", "__debug_line",
  170. MCSectionMachO::S_ATTR_DEBUG,
  171. SectionKind::getMetadata());
  172. DwarfFrameSection =
  173. Ctx->getMachOSection("__DWARF", "__debug_frame",
  174. MCSectionMachO::S_ATTR_DEBUG,
  175. SectionKind::getMetadata());
  176. DwarfPubNamesSection =
  177. Ctx->getMachOSection("__DWARF", "__debug_pubnames",
  178. MCSectionMachO::S_ATTR_DEBUG,
  179. SectionKind::getMetadata());
  180. DwarfPubTypesSection =
  181. Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
  182. MCSectionMachO::S_ATTR_DEBUG,
  183. SectionKind::getMetadata());
  184. DwarfGnuPubNamesSection =
  185. Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
  186. MCSectionMachO::S_ATTR_DEBUG,
  187. SectionKind::getMetadata());
  188. DwarfGnuPubTypesSection =
  189. Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
  190. MCSectionMachO::S_ATTR_DEBUG,
  191. SectionKind::getMetadata());
  192. DwarfStrSection =
  193. Ctx->getMachOSection("__DWARF", "__debug_str",
  194. MCSectionMachO::S_ATTR_DEBUG,
  195. SectionKind::getMetadata());
  196. DwarfLocSection =
  197. Ctx->getMachOSection("__DWARF", "__debug_loc",
  198. MCSectionMachO::S_ATTR_DEBUG,
  199. SectionKind::getMetadata());
  200. DwarfARangesSection =
  201. Ctx->getMachOSection("__DWARF", "__debug_aranges",
  202. MCSectionMachO::S_ATTR_DEBUG,
  203. SectionKind::getMetadata());
  204. DwarfRangesSection =
  205. Ctx->getMachOSection("__DWARF", "__debug_ranges",
  206. MCSectionMachO::S_ATTR_DEBUG,
  207. SectionKind::getMetadata());
  208. DwarfMacroInfoSection =
  209. Ctx->getMachOSection("__DWARF", "__debug_macinfo",
  210. MCSectionMachO::S_ATTR_DEBUG,
  211. SectionKind::getMetadata());
  212. DwarfDebugInlineSection =
  213. Ctx->getMachOSection("__DWARF", "__debug_inlined",
  214. MCSectionMachO::S_ATTR_DEBUG,
  215. SectionKind::getMetadata());
  216. StackMapSection =
  217. Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
  218. SectionKind::getMetadata());
  219. TLSExtraDataSection = TLSTLVSection;
  220. }
  221. void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
  222. if (T.getArch() == Triple::mips ||
  223. T.getArch() == Triple::mipsel)
  224. FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
  225. else if (T.getArch() == Triple::mips64 ||
  226. T.getArch() == Triple::mips64el)
  227. FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
  228. else
  229. FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
  230. if (T.getArch() == Triple::x86) {
  231. PersonalityEncoding = (RelocM == Reloc::PIC_)
  232. ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
  233. : dwarf::DW_EH_PE_absptr;
  234. LSDAEncoding = (RelocM == Reloc::PIC_)
  235. ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
  236. : dwarf::DW_EH_PE_absptr;
  237. FDEEncoding = (RelocM == Reloc::PIC_)
  238. ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
  239. : dwarf::DW_EH_PE_absptr;
  240. TTypeEncoding = (RelocM == Reloc::PIC_)
  241. ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
  242. : dwarf::DW_EH_PE_absptr;
  243. } else if (T.getArch() == Triple::x86_64) {
  244. if (RelocM == Reloc::PIC_) {
  245. PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  246. ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
  247. ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
  248. LSDAEncoding = dwarf::DW_EH_PE_pcrel |
  249. (CMModel == CodeModel::Small
  250. ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
  251. FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
  252. TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  253. ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
  254. ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
  255. } else {
  256. PersonalityEncoding =
  257. (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
  258. ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
  259. LSDAEncoding = (CMModel == CodeModel::Small)
  260. ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
  261. FDEEncoding = dwarf::DW_EH_PE_udata4;
  262. TTypeEncoding = (CMModel == CodeModel::Small)
  263. ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
  264. }
  265. } else if (T.getArch() == Triple::aarch64) {
  266. // The small model guarantees static code/data size < 4GB, but not where it
  267. // will be in memory. Most of these could end up >2GB away so even a signed
  268. // pc-relative 32-bit address is insufficient, theoretically.
  269. if (RelocM == Reloc::PIC_) {
  270. PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  271. dwarf::DW_EH_PE_sdata8;
  272. LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
  273. FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
  274. TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  275. dwarf::DW_EH_PE_sdata8;
  276. } else {
  277. PersonalityEncoding = dwarf::DW_EH_PE_absptr;
  278. LSDAEncoding = dwarf::DW_EH_PE_absptr;
  279. FDEEncoding = dwarf::DW_EH_PE_udata4;
  280. TTypeEncoding = dwarf::DW_EH_PE_absptr;
  281. }
  282. } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
  283. PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  284. dwarf::DW_EH_PE_udata8;
  285. LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
  286. FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
  287. TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  288. dwarf::DW_EH_PE_udata8;
  289. } else if (T.getArch() == Triple::systemz) {
  290. // All currently-defined code models guarantee that 4-byte PC-relative
  291. // values will be in range.
  292. if (RelocM == Reloc::PIC_) {
  293. PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  294. dwarf::DW_EH_PE_sdata4;
  295. LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
  296. FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
  297. TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  298. dwarf::DW_EH_PE_sdata4;
  299. } else {
  300. PersonalityEncoding = dwarf::DW_EH_PE_absptr;
  301. LSDAEncoding = dwarf::DW_EH_PE_absptr;
  302. FDEEncoding = dwarf::DW_EH_PE_absptr;
  303. TTypeEncoding = dwarf::DW_EH_PE_absptr;
  304. }
  305. }
  306. // Solaris requires different flags for .eh_frame to seemingly every other
  307. // platform.
  308. EHSectionType = ELF::SHT_PROGBITS;
  309. EHSectionFlags = ELF::SHF_ALLOC;
  310. if (T.getOS() == Triple::Solaris) {
  311. if (T.getArch() == Triple::x86_64)
  312. EHSectionType = ELF::SHT_X86_64_UNWIND;
  313. else
  314. EHSectionFlags |= ELF::SHF_WRITE;
  315. }
  316. // ELF
  317. BSSSection =
  318. Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
  319. ELF::SHF_WRITE | ELF::SHF_ALLOC,
  320. SectionKind::getBSS());
  321. TextSection =
  322. Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
  323. ELF::SHF_EXECINSTR |
  324. ELF::SHF_ALLOC,
  325. SectionKind::getText());
  326. DataSection =
  327. Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
  328. ELF::SHF_WRITE |ELF::SHF_ALLOC,
  329. SectionKind::getDataRel());
  330. ReadOnlySection =
  331. Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
  332. ELF::SHF_ALLOC,
  333. SectionKind::getReadOnly());
  334. TLSDataSection =
  335. Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
  336. ELF::SHF_ALLOC | ELF::SHF_TLS |
  337. ELF::SHF_WRITE,
  338. SectionKind::getThreadData());
  339. TLSBSSSection =
  340. Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
  341. ELF::SHF_ALLOC | ELF::SHF_TLS |
  342. ELF::SHF_WRITE,
  343. SectionKind::getThreadBSS());
  344. DataRelSection =
  345. Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
  346. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  347. SectionKind::getDataRel());
  348. DataRelLocalSection =
  349. Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
  350. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  351. SectionKind::getDataRelLocal());
  352. DataRelROSection =
  353. Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
  354. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  355. SectionKind::getReadOnlyWithRel());
  356. DataRelROLocalSection =
  357. Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
  358. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  359. SectionKind::getReadOnlyWithRelLocal());
  360. MergeableConst4Section =
  361. Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
  362. ELF::SHF_ALLOC |ELF::SHF_MERGE,
  363. SectionKind::getMergeableConst4());
  364. MergeableConst8Section =
  365. Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
  366. ELF::SHF_ALLOC |ELF::SHF_MERGE,
  367. SectionKind::getMergeableConst8());
  368. MergeableConst16Section =
  369. Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
  370. ELF::SHF_ALLOC |ELF::SHF_MERGE,
  371. SectionKind::getMergeableConst16());
  372. StaticCtorSection =
  373. Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
  374. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  375. SectionKind::getDataRel());
  376. StaticDtorSection =
  377. Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
  378. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  379. SectionKind::getDataRel());
  380. // Exception Handling Sections.
  381. // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
  382. // it contains relocatable pointers. In PIC mode, this is probably a big
  383. // runtime hit for C++ apps. Either the contents of the LSDA need to be
  384. // adjusted or this should be a data section.
  385. LSDASection =
  386. Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
  387. ELF::SHF_ALLOC,
  388. SectionKind::getReadOnly());
  389. // Debug Info Sections.
  390. DwarfAbbrevSection =
  391. Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
  392. SectionKind::getMetadata());
  393. DwarfInfoSection =
  394. Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
  395. SectionKind::getMetadata());
  396. DwarfLineSection =
  397. Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
  398. SectionKind::getMetadata());
  399. DwarfFrameSection =
  400. Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
  401. SectionKind::getMetadata());
  402. DwarfPubNamesSection =
  403. Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
  404. SectionKind::getMetadata());
  405. DwarfPubTypesSection =
  406. Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
  407. SectionKind::getMetadata());
  408. DwarfGnuPubNamesSection =
  409. Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
  410. SectionKind::getMetadata());
  411. DwarfGnuPubTypesSection =
  412. Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
  413. SectionKind::getMetadata());
  414. DwarfStrSection =
  415. Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
  416. ELF::SHF_MERGE | ELF::SHF_STRINGS,
  417. SectionKind::getMergeable1ByteCString());
  418. DwarfLocSection =
  419. Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
  420. SectionKind::getMetadata());
  421. DwarfARangesSection =
  422. Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
  423. SectionKind::getMetadata());
  424. DwarfRangesSection =
  425. Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
  426. SectionKind::getMetadata());
  427. DwarfMacroInfoSection =
  428. Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
  429. SectionKind::getMetadata());
  430. // DWARF5 Experimental Debug Info
  431. // Accelerator Tables
  432. DwarfAccelNamesSection =
  433. Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
  434. SectionKind::getMetadata());
  435. DwarfAccelObjCSection =
  436. Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
  437. SectionKind::getMetadata());
  438. DwarfAccelNamespaceSection =
  439. Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
  440. SectionKind::getMetadata());
  441. DwarfAccelTypesSection =
  442. Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
  443. SectionKind::getMetadata());
  444. // Fission Sections
  445. DwarfInfoDWOSection =
  446. Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
  447. SectionKind::getMetadata());
  448. DwarfAbbrevDWOSection =
  449. Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
  450. SectionKind::getMetadata());
  451. DwarfStrDWOSection =
  452. Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
  453. ELF::SHF_MERGE | ELF::SHF_STRINGS,
  454. SectionKind::getMergeable1ByteCString());
  455. DwarfLineDWOSection =
  456. Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
  457. SectionKind::getMetadata());
  458. DwarfLocDWOSection =
  459. Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
  460. SectionKind::getMetadata());
  461. DwarfStrOffDWOSection =
  462. Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
  463. SectionKind::getMetadata());
  464. DwarfAddrSection =
  465. Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
  466. SectionKind::getMetadata());
  467. }
  468. void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
  469. // COFF
  470. BSSSection =
  471. Ctx->getCOFFSection(".bss",
  472. COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
  473. COFF::IMAGE_SCN_MEM_READ |
  474. COFF::IMAGE_SCN_MEM_WRITE,
  475. SectionKind::getBSS());
  476. TextSection =
  477. Ctx->getCOFFSection(".text",
  478. COFF::IMAGE_SCN_CNT_CODE |
  479. COFF::IMAGE_SCN_MEM_EXECUTE |
  480. COFF::IMAGE_SCN_MEM_READ,
  481. SectionKind::getText());
  482. DataSection =
  483. Ctx->getCOFFSection(".data",
  484. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  485. COFF::IMAGE_SCN_MEM_READ |
  486. COFF::IMAGE_SCN_MEM_WRITE,
  487. SectionKind::getDataRel());
  488. ReadOnlySection =
  489. Ctx->getCOFFSection(".rdata",
  490. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  491. COFF::IMAGE_SCN_MEM_READ,
  492. SectionKind::getReadOnly());
  493. if (T.getOS() == Triple::Win32) {
  494. StaticCtorSection =
  495. Ctx->getCOFFSection(".CRT$XCU",
  496. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  497. COFF::IMAGE_SCN_MEM_READ,
  498. SectionKind::getReadOnly());
  499. } else {
  500. StaticCtorSection =
  501. Ctx->getCOFFSection(".ctors",
  502. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  503. COFF::IMAGE_SCN_MEM_READ |
  504. COFF::IMAGE_SCN_MEM_WRITE,
  505. SectionKind::getDataRel());
  506. }
  507. if (T.getOS() == Triple::Win32) {
  508. StaticDtorSection =
  509. Ctx->getCOFFSection(".CRT$XTX",
  510. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  511. COFF::IMAGE_SCN_MEM_READ,
  512. SectionKind::getReadOnly());
  513. } else {
  514. StaticDtorSection =
  515. Ctx->getCOFFSection(".dtors",
  516. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  517. COFF::IMAGE_SCN_MEM_READ |
  518. COFF::IMAGE_SCN_MEM_WRITE,
  519. SectionKind::getDataRel());
  520. }
  521. // FIXME: We're emitting LSDA info into a readonly section on COFF, even
  522. // though it contains relocatable pointers. In PIC mode, this is probably a
  523. // big runtime hit for C++ apps. Either the contents of the LSDA need to be
  524. // adjusted or this should be a data section.
  525. LSDASection =
  526. Ctx->getCOFFSection(".gcc_except_table",
  527. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  528. COFF::IMAGE_SCN_MEM_READ,
  529. SectionKind::getReadOnly());
  530. // Debug info.
  531. DwarfAbbrevSection =
  532. Ctx->getCOFFSection(".debug_abbrev",
  533. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  534. COFF::IMAGE_SCN_MEM_READ,
  535. SectionKind::getMetadata());
  536. DwarfInfoSection =
  537. Ctx->getCOFFSection(".debug_info",
  538. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  539. COFF::IMAGE_SCN_MEM_READ,
  540. SectionKind::getMetadata());
  541. DwarfLineSection =
  542. Ctx->getCOFFSection(".debug_line",
  543. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  544. COFF::IMAGE_SCN_MEM_READ,
  545. SectionKind::getMetadata());
  546. DwarfFrameSection =
  547. Ctx->getCOFFSection(".debug_frame",
  548. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  549. COFF::IMAGE_SCN_MEM_READ,
  550. SectionKind::getMetadata());
  551. DwarfPubNamesSection =
  552. Ctx->getCOFFSection(".debug_pubnames",
  553. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  554. COFF::IMAGE_SCN_MEM_READ,
  555. SectionKind::getMetadata());
  556. DwarfPubTypesSection =
  557. Ctx->getCOFFSection(".debug_pubtypes",
  558. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  559. COFF::IMAGE_SCN_MEM_READ,
  560. SectionKind::getMetadata());
  561. DwarfGnuPubNamesSection =
  562. Ctx->getCOFFSection(".debug_gnu_pubnames",
  563. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  564. COFF::IMAGE_SCN_MEM_READ,
  565. SectionKind::getMetadata());
  566. DwarfGnuPubTypesSection =
  567. Ctx->getCOFFSection(".debug_gnu_pubtypes",
  568. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  569. COFF::IMAGE_SCN_MEM_READ,
  570. SectionKind::getMetadata());
  571. DwarfStrSection =
  572. Ctx->getCOFFSection(".debug_str",
  573. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  574. COFF::IMAGE_SCN_MEM_READ,
  575. SectionKind::getMetadata());
  576. DwarfLocSection =
  577. Ctx->getCOFFSection(".debug_loc",
  578. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  579. COFF::IMAGE_SCN_MEM_READ,
  580. SectionKind::getMetadata());
  581. DwarfARangesSection =
  582. Ctx->getCOFFSection(".debug_aranges",
  583. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  584. COFF::IMAGE_SCN_MEM_READ,
  585. SectionKind::getMetadata());
  586. DwarfRangesSection =
  587. Ctx->getCOFFSection(".debug_ranges",
  588. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  589. COFF::IMAGE_SCN_MEM_READ,
  590. SectionKind::getMetadata());
  591. DwarfMacroInfoSection =
  592. Ctx->getCOFFSection(".debug_macinfo",
  593. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  594. COFF::IMAGE_SCN_MEM_READ,
  595. SectionKind::getMetadata());
  596. DrectveSection =
  597. Ctx->getCOFFSection(".drectve",
  598. COFF::IMAGE_SCN_LNK_INFO,
  599. SectionKind::getMetadata());
  600. PDataSection =
  601. Ctx->getCOFFSection(".pdata",
  602. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  603. COFF::IMAGE_SCN_MEM_READ,
  604. SectionKind::getDataRel());
  605. XDataSection =
  606. Ctx->getCOFFSection(".xdata",
  607. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  608. COFF::IMAGE_SCN_MEM_READ,
  609. SectionKind::getDataRel());
  610. TLSDataSection =
  611. Ctx->getCOFFSection(".tls$",
  612. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  613. COFF::IMAGE_SCN_MEM_READ |
  614. COFF::IMAGE_SCN_MEM_WRITE,
  615. SectionKind::getDataRel());
  616. }
  617. void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
  618. CodeModel::Model cm,
  619. MCContext &ctx) {
  620. RelocM = relocm;
  621. CMModel = cm;
  622. Ctx = &ctx;
  623. // Common.
  624. CommDirectiveSupportsAlignment = true;
  625. SupportsWeakOmittedEHFrame = true;
  626. IsFunctionEHFrameSymbolPrivate = true;
  627. PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
  628. TTypeEncoding = dwarf::DW_EH_PE_absptr;
  629. CompactUnwindDwarfEHFrameOnly = 0;
  630. EHFrameSection = 0; // Created on demand.
  631. CompactUnwindSection = 0; // Used only by selected targets.
  632. DwarfAccelNamesSection = 0; // Used only by selected targets.
  633. DwarfAccelObjCSection = 0; // Used only by selected targets.
  634. DwarfAccelNamespaceSection = 0; // Used only by selected targets.
  635. DwarfAccelTypesSection = 0; // Used only by selected targets.
  636. Triple T(TT);
  637. Triple::ArchType Arch = T.getArch();
  638. // FIXME: Checking for Arch here to filter out bogus triples such as
  639. // cellspu-apple-darwin. Perhaps we should fix in Triple?
  640. if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
  641. Arch == Triple::arm || Arch == Triple::thumb ||
  642. Arch == Triple::ppc || Arch == Triple::ppc64 ||
  643. Arch == Triple::UnknownArch) &&
  644. (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
  645. Env = IsMachO;
  646. InitMachOMCObjectFileInfo(T);
  647. } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
  648. (T.getEnvironment() != Triple::ELF) &&
  649. (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
  650. T.getOS() == Triple::Win32)) {
  651. Env = IsCOFF;
  652. InitCOFFMCObjectFileInfo(T);
  653. } else {
  654. Env = IsELF;
  655. InitELFMCObjectFileInfo(T);
  656. }
  657. }
  658. void MCObjectFileInfo::InitEHFrameSection() {
  659. if (Env == IsMachO)
  660. EHFrameSection =
  661. Ctx->getMachOSection("__TEXT", "__eh_frame",
  662. MCSectionMachO::S_COALESCED |
  663. MCSectionMachO::S_ATTR_NO_TOC |
  664. MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
  665. MCSectionMachO::S_ATTR_LIVE_SUPPORT,
  666. SectionKind::getReadOnly());
  667. else if (Env == IsELF)
  668. EHFrameSection =
  669. Ctx->getELFSection(".eh_frame", EHSectionType,
  670. EHSectionFlags,
  671. SectionKind::getDataRel());
  672. else
  673. EHFrameSection =
  674. Ctx->getCOFFSection(".eh_frame",
  675. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  676. COFF::IMAGE_SCN_MEM_READ |
  677. COFF::IMAGE_SCN_MEM_WRITE,
  678. SectionKind::getDataRel());
  679. }