MCObjectFileInfo.cpp 28 KB

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