MCObjectFileInfo.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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/MC/MCContext.h"
  11. #include "llvm/MC/MCSection.h"
  12. #include "llvm/MC/MCSectionCOFF.h"
  13. #include "llvm/MC/MCSectionELF.h"
  14. #include "llvm/MC/MCSectionMachO.h"
  15. #include "llvm/ADT/Triple.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. // Debug Information.
  137. DwarfAccelNamesSection =
  138. Ctx->getMachOSection("__DWARF", "__apple_names",
  139. MCSectionMachO::S_ATTR_DEBUG,
  140. SectionKind::getMetadata());
  141. DwarfAccelObjCSection =
  142. Ctx->getMachOSection("__DWARF", "__apple_objc",
  143. MCSectionMachO::S_ATTR_DEBUG,
  144. SectionKind::getMetadata());
  145. // 16 character section limit...
  146. DwarfAccelNamespaceSection =
  147. Ctx->getMachOSection("__DWARF", "__apple_namespac",
  148. MCSectionMachO::S_ATTR_DEBUG,
  149. SectionKind::getMetadata());
  150. DwarfAccelTypesSection =
  151. Ctx->getMachOSection("__DWARF", "__apple_types",
  152. MCSectionMachO::S_ATTR_DEBUG,
  153. SectionKind::getMetadata());
  154. DwarfAbbrevSection =
  155. Ctx->getMachOSection("__DWARF", "__debug_abbrev",
  156. MCSectionMachO::S_ATTR_DEBUG,
  157. SectionKind::getMetadata());
  158. DwarfInfoSection =
  159. Ctx->getMachOSection("__DWARF", "__debug_info",
  160. MCSectionMachO::S_ATTR_DEBUG,
  161. SectionKind::getMetadata());
  162. DwarfLineSection =
  163. Ctx->getMachOSection("__DWARF", "__debug_line",
  164. MCSectionMachO::S_ATTR_DEBUG,
  165. SectionKind::getMetadata());
  166. DwarfFrameSection =
  167. Ctx->getMachOSection("__DWARF", "__debug_frame",
  168. MCSectionMachO::S_ATTR_DEBUG,
  169. SectionKind::getMetadata());
  170. DwarfPubTypesSection =
  171. Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
  172. MCSectionMachO::S_ATTR_DEBUG,
  173. SectionKind::getMetadata());
  174. DwarfStrSection =
  175. Ctx->getMachOSection("__DWARF", "__debug_str",
  176. MCSectionMachO::S_ATTR_DEBUG,
  177. SectionKind::getMetadata());
  178. DwarfLocSection =
  179. Ctx->getMachOSection("__DWARF", "__debug_loc",
  180. MCSectionMachO::S_ATTR_DEBUG,
  181. SectionKind::getMetadata());
  182. DwarfARangesSection =
  183. Ctx->getMachOSection("__DWARF", "__debug_aranges",
  184. MCSectionMachO::S_ATTR_DEBUG,
  185. SectionKind::getMetadata());
  186. DwarfRangesSection =
  187. Ctx->getMachOSection("__DWARF", "__debug_ranges",
  188. MCSectionMachO::S_ATTR_DEBUG,
  189. SectionKind::getMetadata());
  190. DwarfMacroInfoSection =
  191. Ctx->getMachOSection("__DWARF", "__debug_macinfo",
  192. MCSectionMachO::S_ATTR_DEBUG,
  193. SectionKind::getMetadata());
  194. DwarfDebugInlineSection =
  195. Ctx->getMachOSection("__DWARF", "__debug_inlined",
  196. MCSectionMachO::S_ATTR_DEBUG,
  197. SectionKind::getMetadata());
  198. TLSExtraDataSection = TLSTLVSection;
  199. }
  200. void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
  201. if (T.getArch() == Triple::x86) {
  202. PersonalityEncoding = (RelocM == Reloc::PIC_)
  203. ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
  204. : dwarf::DW_EH_PE_absptr;
  205. LSDAEncoding = (RelocM == Reloc::PIC_)
  206. ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
  207. : dwarf::DW_EH_PE_absptr;
  208. FDEEncoding = FDECFIEncoding = (RelocM == Reloc::PIC_)
  209. ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
  210. : dwarf::DW_EH_PE_absptr;
  211. TTypeEncoding = (RelocM == Reloc::PIC_)
  212. ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
  213. : dwarf::DW_EH_PE_absptr;
  214. } else if (T.getArch() == Triple::x86_64) {
  215. FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
  216. if (RelocM == Reloc::PIC_) {
  217. PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  218. ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
  219. ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
  220. LSDAEncoding = dwarf::DW_EH_PE_pcrel |
  221. (CMModel == CodeModel::Small
  222. ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
  223. FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
  224. TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
  225. ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
  226. ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
  227. } else {
  228. PersonalityEncoding =
  229. (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
  230. ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
  231. LSDAEncoding = (CMModel == CodeModel::Small)
  232. ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
  233. FDEEncoding = dwarf::DW_EH_PE_udata4;
  234. TTypeEncoding = (CMModel == CodeModel::Small)
  235. ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
  236. }
  237. }
  238. // Solaris requires different flags for .eh_frame to seemingly every other
  239. // platform.
  240. EHSectionType = ELF::SHT_PROGBITS;
  241. EHSectionFlags = ELF::SHF_ALLOC;
  242. if (T.getOS() == Triple::Solaris) {
  243. if (T.getArch() == Triple::x86_64)
  244. EHSectionType = ELF::SHT_X86_64_UNWIND;
  245. else
  246. EHSectionFlags |= ELF::SHF_WRITE;
  247. }
  248. // ELF
  249. BSSSection =
  250. Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
  251. ELF::SHF_WRITE | ELF::SHF_ALLOC,
  252. SectionKind::getBSS());
  253. TextSection =
  254. Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
  255. ELF::SHF_EXECINSTR |
  256. ELF::SHF_ALLOC,
  257. SectionKind::getText());
  258. DataSection =
  259. Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
  260. ELF::SHF_WRITE |ELF::SHF_ALLOC,
  261. SectionKind::getDataRel());
  262. ReadOnlySection =
  263. Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
  264. ELF::SHF_ALLOC,
  265. SectionKind::getReadOnly());
  266. TLSDataSection =
  267. Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
  268. ELF::SHF_ALLOC | ELF::SHF_TLS |
  269. ELF::SHF_WRITE,
  270. SectionKind::getThreadData());
  271. TLSBSSSection =
  272. Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
  273. ELF::SHF_ALLOC | ELF::SHF_TLS |
  274. ELF::SHF_WRITE,
  275. SectionKind::getThreadBSS());
  276. DataRelSection =
  277. Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
  278. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  279. SectionKind::getDataRel());
  280. DataRelLocalSection =
  281. Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
  282. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  283. SectionKind::getDataRelLocal());
  284. DataRelROSection =
  285. Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
  286. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  287. SectionKind::getReadOnlyWithRel());
  288. DataRelROLocalSection =
  289. Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
  290. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  291. SectionKind::getReadOnlyWithRelLocal());
  292. MergeableConst4Section =
  293. Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
  294. ELF::SHF_ALLOC |ELF::SHF_MERGE,
  295. SectionKind::getMergeableConst4());
  296. MergeableConst8Section =
  297. Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
  298. ELF::SHF_ALLOC |ELF::SHF_MERGE,
  299. SectionKind::getMergeableConst8());
  300. MergeableConst16Section =
  301. Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
  302. ELF::SHF_ALLOC |ELF::SHF_MERGE,
  303. SectionKind::getMergeableConst16());
  304. StaticCtorSection =
  305. Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
  306. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  307. SectionKind::getDataRel());
  308. StaticDtorSection =
  309. Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
  310. ELF::SHF_ALLOC |ELF::SHF_WRITE,
  311. SectionKind::getDataRel());
  312. // Exception Handling Sections.
  313. // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
  314. // it contains relocatable pointers. In PIC mode, this is probably a big
  315. // runtime hit for C++ apps. Either the contents of the LSDA need to be
  316. // adjusted or this should be a data section.
  317. LSDASection =
  318. Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
  319. ELF::SHF_ALLOC,
  320. SectionKind::getReadOnly());
  321. // Debug Info Sections.
  322. DwarfAbbrevSection =
  323. Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
  324. SectionKind::getMetadata());
  325. DwarfInfoSection =
  326. Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
  327. SectionKind::getMetadata());
  328. DwarfLineSection =
  329. Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
  330. SectionKind::getMetadata());
  331. DwarfFrameSection =
  332. Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
  333. SectionKind::getMetadata());
  334. DwarfPubTypesSection =
  335. Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
  336. SectionKind::getMetadata());
  337. DwarfStrSection =
  338. Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
  339. ELF::SHF_MERGE | ELF::SHF_STRINGS,
  340. SectionKind::getMergeable1ByteCString());
  341. DwarfLocSection =
  342. Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
  343. SectionKind::getMetadata());
  344. DwarfARangesSection =
  345. Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
  346. SectionKind::getMetadata());
  347. DwarfRangesSection =
  348. Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
  349. SectionKind::getMetadata());
  350. DwarfMacroInfoSection =
  351. Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
  352. SectionKind::getMetadata());
  353. }
  354. void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
  355. // COFF
  356. TextSection =
  357. Ctx->getCOFFSection(".text",
  358. COFF::IMAGE_SCN_CNT_CODE |
  359. COFF::IMAGE_SCN_MEM_EXECUTE |
  360. COFF::IMAGE_SCN_MEM_READ,
  361. SectionKind::getText());
  362. DataSection =
  363. Ctx->getCOFFSection(".data",
  364. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  365. COFF::IMAGE_SCN_MEM_READ |
  366. COFF::IMAGE_SCN_MEM_WRITE,
  367. SectionKind::getDataRel());
  368. ReadOnlySection =
  369. Ctx->getCOFFSection(".rdata",
  370. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  371. COFF::IMAGE_SCN_MEM_READ,
  372. SectionKind::getReadOnly());
  373. if (T.getOS() == Triple::Win32) {
  374. StaticCtorSection =
  375. Ctx->getCOFFSection(".CRT$XCU",
  376. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  377. COFF::IMAGE_SCN_MEM_READ,
  378. SectionKind::getReadOnly());
  379. } else {
  380. StaticCtorSection =
  381. Ctx->getCOFFSection(".ctors",
  382. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  383. COFF::IMAGE_SCN_MEM_READ |
  384. COFF::IMAGE_SCN_MEM_WRITE,
  385. SectionKind::getDataRel());
  386. }
  387. if (T.getOS() == Triple::Win32) {
  388. StaticDtorSection =
  389. Ctx->getCOFFSection(".CRT$XTX",
  390. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  391. COFF::IMAGE_SCN_MEM_READ,
  392. SectionKind::getReadOnly());
  393. } else {
  394. StaticDtorSection =
  395. Ctx->getCOFFSection(".dtors",
  396. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  397. COFF::IMAGE_SCN_MEM_READ |
  398. COFF::IMAGE_SCN_MEM_WRITE,
  399. SectionKind::getDataRel());
  400. }
  401. // FIXME: We're emitting LSDA info into a readonly section on COFF, even
  402. // though it contains relocatable pointers. In PIC mode, this is probably a
  403. // big runtime hit for C++ apps. Either the contents of the LSDA need to be
  404. // adjusted or this should be a data section.
  405. LSDASection =
  406. Ctx->getCOFFSection(".gcc_except_table",
  407. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  408. COFF::IMAGE_SCN_MEM_READ,
  409. SectionKind::getReadOnly());
  410. // Debug info.
  411. DwarfAbbrevSection =
  412. Ctx->getCOFFSection(".debug_abbrev",
  413. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  414. COFF::IMAGE_SCN_MEM_READ,
  415. SectionKind::getMetadata());
  416. DwarfInfoSection =
  417. Ctx->getCOFFSection(".debug_info",
  418. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  419. COFF::IMAGE_SCN_MEM_READ,
  420. SectionKind::getMetadata());
  421. DwarfLineSection =
  422. Ctx->getCOFFSection(".debug_line",
  423. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  424. COFF::IMAGE_SCN_MEM_READ,
  425. SectionKind::getMetadata());
  426. DwarfFrameSection =
  427. Ctx->getCOFFSection(".debug_frame",
  428. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  429. COFF::IMAGE_SCN_MEM_READ,
  430. SectionKind::getMetadata());
  431. DwarfPubTypesSection =
  432. Ctx->getCOFFSection(".debug_pubtypes",
  433. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  434. COFF::IMAGE_SCN_MEM_READ,
  435. SectionKind::getMetadata());
  436. DwarfStrSection =
  437. Ctx->getCOFFSection(".debug_str",
  438. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  439. COFF::IMAGE_SCN_MEM_READ,
  440. SectionKind::getMetadata());
  441. DwarfLocSection =
  442. Ctx->getCOFFSection(".debug_loc",
  443. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  444. COFF::IMAGE_SCN_MEM_READ,
  445. SectionKind::getMetadata());
  446. DwarfARangesSection =
  447. Ctx->getCOFFSection(".debug_aranges",
  448. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  449. COFF::IMAGE_SCN_MEM_READ,
  450. SectionKind::getMetadata());
  451. DwarfRangesSection =
  452. Ctx->getCOFFSection(".debug_ranges",
  453. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  454. COFF::IMAGE_SCN_MEM_READ,
  455. SectionKind::getMetadata());
  456. DwarfMacroInfoSection =
  457. Ctx->getCOFFSection(".debug_macinfo",
  458. COFF::IMAGE_SCN_MEM_DISCARDABLE |
  459. COFF::IMAGE_SCN_MEM_READ,
  460. SectionKind::getMetadata());
  461. DrectveSection =
  462. Ctx->getCOFFSection(".drectve",
  463. COFF::IMAGE_SCN_LNK_INFO,
  464. SectionKind::getMetadata());
  465. PDataSection =
  466. Ctx->getCOFFSection(".pdata",
  467. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  468. COFF::IMAGE_SCN_MEM_READ,
  469. SectionKind::getDataRel());
  470. XDataSection =
  471. Ctx->getCOFFSection(".xdata",
  472. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  473. COFF::IMAGE_SCN_MEM_READ,
  474. SectionKind::getDataRel());
  475. TLSDataSection =
  476. Ctx->getCOFFSection(".tls$",
  477. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  478. COFF::IMAGE_SCN_MEM_READ |
  479. COFF::IMAGE_SCN_MEM_WRITE,
  480. SectionKind::getDataRel());
  481. }
  482. void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
  483. CodeModel::Model cm,
  484. MCContext &ctx) {
  485. RelocM = relocm;
  486. CMModel = cm;
  487. Ctx = &ctx;
  488. // Common.
  489. CommDirectiveSupportsAlignment = true;
  490. SupportsWeakOmittedEHFrame = true;
  491. IsFunctionEHFrameSymbolPrivate = true;
  492. PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
  493. TTypeEncoding = dwarf::DW_EH_PE_absptr;
  494. EHFrameSection = 0; // Created on demand.
  495. CompactUnwindSection = 0; // Used only by selected targets.
  496. DwarfAccelNamesSection = 0; // Used only by selected targets.
  497. DwarfAccelObjCSection = 0; // Used only by selected targets.
  498. DwarfAccelNamespaceSection = 0; // Used only by selected targets.
  499. DwarfAccelTypesSection = 0; // Used only by selected targets.
  500. Triple T(TT);
  501. Triple::ArchType Arch = T.getArch();
  502. // FIXME: Checking for Arch here to filter out bogus triples such as
  503. // cellspu-apple-darwin. Perhaps we should fix in Triple?
  504. if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
  505. Arch == Triple::arm || Arch == Triple::thumb ||
  506. Arch == Triple::ppc || Arch == Triple::ppc64 ||
  507. Arch == Triple::UnknownArch) &&
  508. (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
  509. Env = IsMachO;
  510. InitMachOMCObjectFileInfo(T);
  511. } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
  512. (T.getEnvironment() != Triple::ELF) &&
  513. (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
  514. T.getOS() == Triple::Win32)) {
  515. Env = IsCOFF;
  516. InitCOFFMCObjectFileInfo(T);
  517. } else {
  518. Env = IsELF;
  519. InitELFMCObjectFileInfo(T);
  520. }
  521. }
  522. void MCObjectFileInfo::InitEHFrameSection() {
  523. if (Env == IsMachO)
  524. EHFrameSection =
  525. Ctx->getMachOSection("__TEXT", "__eh_frame",
  526. MCSectionMachO::S_COALESCED |
  527. MCSectionMachO::S_ATTR_NO_TOC |
  528. MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
  529. MCSectionMachO::S_ATTR_LIVE_SUPPORT,
  530. SectionKind::getReadOnly());
  531. else if (Env == IsELF)
  532. EHFrameSection =
  533. Ctx->getELFSection(".eh_frame", EHSectionType,
  534. EHSectionFlags,
  535. SectionKind::getDataRel());
  536. else
  537. EHFrameSection =
  538. Ctx->getCOFFSection(".eh_frame",
  539. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  540. COFF::IMAGE_SCN_MEM_READ |
  541. COFF::IMAGE_SCN_MEM_WRITE,
  542. SectionKind::getDataRel());
  543. }