MCObjectFileInfo.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. //===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/MC/MCObjectFileInfo.h"
  9. #include "llvm/ADT/StringExtras.h"
  10. #include "llvm/ADT/Triple.h"
  11. #include "llvm/BinaryFormat/COFF.h"
  12. #include "llvm/BinaryFormat/ELF.h"
  13. #include "llvm/MC/MCAsmInfo.h"
  14. #include "llvm/MC/MCContext.h"
  15. #include "llvm/MC/MCSection.h"
  16. #include "llvm/MC/MCSectionCOFF.h"
  17. #include "llvm/MC/MCSectionELF.h"
  18. #include "llvm/MC/MCSectionMachO.h"
  19. #include "llvm/MC/MCSectionWasm.h"
  20. #include "llvm/MC/MCSectionXCOFF.h"
  21. using namespace llvm;
  22. static bool useCompactUnwind(const Triple &T) {
  23. // Only on darwin.
  24. if (!T.isOSDarwin())
  25. return false;
  26. // aarch64 always has it.
  27. if (T.getArch() == Triple::aarch64)
  28. return true;
  29. // armv7k always has it.
  30. if (T.isWatchABI())
  31. return true;
  32. // Use it on newer version of OS X.
  33. if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
  34. return true;
  35. // And the iOS simulator.
  36. if (T.isiOS() &&
  37. (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
  38. return true;
  39. return false;
  40. }
  41. void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
  42. // MachO
  43. SupportsWeakOmittedEHFrame = false;
  44. EHFrameSection = Ctx->getMachOSection(
  45. "__TEXT", "__eh_frame",
  46. MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
  47. MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
  48. SectionKind::getReadOnly());
  49. if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
  50. SupportsCompactUnwindWithoutEHFrame = true;
  51. if (T.isWatchABI())
  52. OmitDwarfIfHaveCompactUnwind = true;
  53. FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
  54. // .comm doesn't support alignment before Leopard.
  55. if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
  56. CommDirectiveSupportsAlignment = false;
  57. TextSection // .text
  58. = Ctx->getMachOSection("__TEXT", "__text",
  59. MachO::S_ATTR_PURE_INSTRUCTIONS,
  60. SectionKind::getText());
  61. DataSection // .data
  62. = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
  63. // BSSSection might not be expected initialized on msvc.
  64. BSSSection = nullptr;
  65. TLSDataSection // .tdata
  66. = Ctx->getMachOSection("__DATA", "__thread_data",
  67. MachO::S_THREAD_LOCAL_REGULAR,
  68. SectionKind::getData());
  69. TLSBSSSection // .tbss
  70. = Ctx->getMachOSection("__DATA", "__thread_bss",
  71. MachO::S_THREAD_LOCAL_ZEROFILL,
  72. SectionKind::getThreadBSS());
  73. // TODO: Verify datarel below.
  74. TLSTLVSection // .tlv
  75. = Ctx->getMachOSection("__DATA", "__thread_vars",
  76. MachO::S_THREAD_LOCAL_VARIABLES,
  77. SectionKind::getData());
  78. TLSThreadInitSection = Ctx->getMachOSection(
  79. "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
  80. SectionKind::getData());
  81. CStringSection // .cstring
  82. = Ctx->getMachOSection("__TEXT", "__cstring",
  83. MachO::S_CSTRING_LITERALS,
  84. SectionKind::getMergeable1ByteCString());
  85. UStringSection
  86. = Ctx->getMachOSection("__TEXT","__ustring", 0,
  87. SectionKind::getMergeable2ByteCString());
  88. FourByteConstantSection // .literal4
  89. = Ctx->getMachOSection("__TEXT", "__literal4",
  90. MachO::S_4BYTE_LITERALS,
  91. SectionKind::getMergeableConst4());
  92. EightByteConstantSection // .literal8
  93. = Ctx->getMachOSection("__TEXT", "__literal8",
  94. MachO::S_8BYTE_LITERALS,
  95. SectionKind::getMergeableConst8());
  96. SixteenByteConstantSection // .literal16
  97. = Ctx->getMachOSection("__TEXT", "__literal16",
  98. MachO::S_16BYTE_LITERALS,
  99. SectionKind::getMergeableConst16());
  100. ReadOnlySection // .const
  101. = Ctx->getMachOSection("__TEXT", "__const", 0,
  102. SectionKind::getReadOnly());
  103. // If the target is not powerpc, map the coal sections to the non-coal
  104. // sections.
  105. //
  106. // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
  107. // "__TEXT/__const_coal" => section "__TEXT/__const"
  108. // "__DATA/__datacoal_nt" => section "__DATA/__data"
  109. Triple::ArchType ArchTy = T.getArch();
  110. ConstDataSection // .const_data
  111. = Ctx->getMachOSection("__DATA", "__const", 0,
  112. SectionKind::getReadOnlyWithRel());
  113. if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
  114. TextCoalSection
  115. = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
  116. MachO::S_COALESCED |
  117. MachO::S_ATTR_PURE_INSTRUCTIONS,
  118. SectionKind::getText());
  119. ConstTextCoalSection
  120. = Ctx->getMachOSection("__TEXT", "__const_coal",
  121. MachO::S_COALESCED,
  122. SectionKind::getReadOnly());
  123. DataCoalSection = Ctx->getMachOSection(
  124. "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
  125. ConstDataCoalSection = DataCoalSection;
  126. } else {
  127. TextCoalSection = TextSection;
  128. ConstTextCoalSection = ReadOnlySection;
  129. DataCoalSection = DataSection;
  130. ConstDataCoalSection = ConstDataSection;
  131. }
  132. DataCommonSection
  133. = Ctx->getMachOSection("__DATA","__common",
  134. MachO::S_ZEROFILL,
  135. SectionKind::getBSS());
  136. DataBSSSection
  137. = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
  138. SectionKind::getBSS());
  139. LazySymbolPointerSection
  140. = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
  141. MachO::S_LAZY_SYMBOL_POINTERS,
  142. SectionKind::getMetadata());
  143. NonLazySymbolPointerSection
  144. = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
  145. MachO::S_NON_LAZY_SYMBOL_POINTERS,
  146. SectionKind::getMetadata());
  147. ThreadLocalPointerSection
  148. = Ctx->getMachOSection("__DATA", "__thread_ptr",
  149. MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
  150. SectionKind::getMetadata());
  151. // Exception Handling.
  152. LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
  153. SectionKind::getReadOnlyWithRel());
  154. COFFDebugSymbolsSection = nullptr;
  155. COFFDebugTypesSection = nullptr;
  156. COFFGlobalTypeHashesSection = nullptr;
  157. if (useCompactUnwind(T)) {
  158. CompactUnwindSection =
  159. Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
  160. SectionKind::getReadOnly());
  161. if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
  162. CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF
  163. else if (T.getArch() == Triple::aarch64)
  164. CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF
  165. else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
  166. CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF
  167. }
  168. // Debug Information.
  169. DwarfDebugNamesSection =
  170. Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
  171. SectionKind::getMetadata(), "debug_names_begin");
  172. DwarfAccelNamesSection =
  173. Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
  174. SectionKind::getMetadata(), "names_begin");
  175. DwarfAccelObjCSection =
  176. Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
  177. SectionKind::getMetadata(), "objc_begin");
  178. // 16 character section limit...
  179. DwarfAccelNamespaceSection =
  180. Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
  181. SectionKind::getMetadata(), "namespac_begin");
  182. DwarfAccelTypesSection =
  183. Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
  184. SectionKind::getMetadata(), "types_begin");
  185. DwarfSwiftASTSection =
  186. Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
  187. SectionKind::getMetadata());
  188. DwarfAbbrevSection =
  189. Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
  190. SectionKind::getMetadata(), "section_abbrev");
  191. DwarfInfoSection =
  192. Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
  193. SectionKind::getMetadata(), "section_info");
  194. DwarfLineSection =
  195. Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
  196. SectionKind::getMetadata(), "section_line");
  197. DwarfLineStrSection =
  198. Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
  199. SectionKind::getMetadata(), "section_line_str");
  200. DwarfFrameSection =
  201. Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
  202. SectionKind::getMetadata());
  203. DwarfPubNamesSection =
  204. Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
  205. SectionKind::getMetadata());
  206. DwarfPubTypesSection =
  207. Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
  208. SectionKind::getMetadata());
  209. DwarfGnuPubNamesSection =
  210. Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
  211. SectionKind::getMetadata());
  212. DwarfGnuPubTypesSection =
  213. Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
  214. SectionKind::getMetadata());
  215. DwarfStrSection =
  216. Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
  217. SectionKind::getMetadata(), "info_string");
  218. DwarfStrOffSection =
  219. Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
  220. SectionKind::getMetadata(), "section_str_off");
  221. DwarfAddrSection =
  222. Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,
  223. SectionKind::getMetadata(), "section_info");
  224. DwarfLocSection =
  225. Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
  226. SectionKind::getMetadata(), "section_debug_loc");
  227. DwarfLoclistsSection =
  228. Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,
  229. SectionKind::getMetadata(), "section_debug_loc");
  230. DwarfARangesSection =
  231. Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
  232. SectionKind::getMetadata());
  233. DwarfRangesSection =
  234. Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
  235. SectionKind::getMetadata(), "debug_range");
  236. DwarfRnglistsSection =
  237. Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,
  238. SectionKind::getMetadata(), "debug_range");
  239. DwarfMacinfoSection =
  240. Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
  241. SectionKind::getMetadata(), "debug_macinfo");
  242. DwarfDebugInlineSection =
  243. Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
  244. SectionKind::getMetadata());
  245. DwarfCUIndexSection =
  246. Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
  247. SectionKind::getMetadata());
  248. DwarfTUIndexSection =
  249. Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
  250. SectionKind::getMetadata());
  251. StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
  252. 0, SectionKind::getMetadata());
  253. FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
  254. 0, SectionKind::getMetadata());
  255. RemarksSection = Ctx->getMachOSection(
  256. "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());
  257. TLSExtraDataSection = TLSTLVSection;
  258. }
  259. void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
  260. switch (T.getArch()) {
  261. case Triple::mips:
  262. case Triple::mipsel:
  263. case Triple::mips64:
  264. case Triple::mips64el:
  265. FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4
  266. ? dwarf::DW_EH_PE_sdata4
  267. : dwarf::DW_EH_PE_sdata8;
  268. break;
  269. case Triple::ppc64:
  270. case Triple::ppc64le:
  271. case Triple::x86_64:
  272. FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
  273. (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
  274. break;
  275. case Triple::bpfel:
  276. case Triple::bpfeb:
  277. FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
  278. break;
  279. case Triple::hexagon:
  280. FDECFIEncoding =
  281. PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;
  282. break;
  283. default:
  284. FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
  285. break;
  286. }
  287. unsigned EHSectionType = T.getArch() == Triple::x86_64
  288. ? ELF::SHT_X86_64_UNWIND
  289. : ELF::SHT_PROGBITS;
  290. // Solaris requires different flags for .eh_frame to seemingly every other
  291. // platform.
  292. unsigned EHSectionFlags = ELF::SHF_ALLOC;
  293. if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
  294. EHSectionFlags |= ELF::SHF_WRITE;
  295. // ELF
  296. BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
  297. ELF::SHF_WRITE | ELF::SHF_ALLOC);
  298. TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
  299. ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
  300. DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
  301. ELF::SHF_WRITE | ELF::SHF_ALLOC);
  302. ReadOnlySection =
  303. Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
  304. TLSDataSection =
  305. Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
  306. ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
  307. TLSBSSSection = Ctx->getELFSection(
  308. ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
  309. DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
  310. ELF::SHF_ALLOC | ELF::SHF_WRITE);
  311. MergeableConst4Section =
  312. Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
  313. ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
  314. MergeableConst8Section =
  315. Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
  316. ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
  317. MergeableConst16Section =
  318. Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
  319. ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
  320. MergeableConst32Section =
  321. Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
  322. ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
  323. // Exception Handling Sections.
  324. // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
  325. // it contains relocatable pointers. In PIC mode, this is probably a big
  326. // runtime hit for C++ apps. Either the contents of the LSDA need to be
  327. // adjusted or this should be a data section.
  328. LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
  329. ELF::SHF_ALLOC);
  330. COFFDebugSymbolsSection = nullptr;
  331. COFFDebugTypesSection = nullptr;
  332. unsigned DebugSecType = ELF::SHT_PROGBITS;
  333. // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
  334. // to distinguish among sections contain DWARF and ECOFF debug formats.
  335. // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
  336. if (T.isMIPS())
  337. DebugSecType = ELF::SHT_MIPS_DWARF;
  338. // Debug Info Sections.
  339. DwarfAbbrevSection =
  340. Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
  341. DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
  342. DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
  343. DwarfLineStrSection =
  344. Ctx->getELFSection(".debug_line_str", DebugSecType,
  345. ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
  346. DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
  347. DwarfPubNamesSection =
  348. Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
  349. DwarfPubTypesSection =
  350. Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
  351. DwarfGnuPubNamesSection =
  352. Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
  353. DwarfGnuPubTypesSection =
  354. Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
  355. DwarfStrSection =
  356. Ctx->getELFSection(".debug_str", DebugSecType,
  357. ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
  358. DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
  359. DwarfARangesSection =
  360. Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
  361. DwarfRangesSection =
  362. Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
  363. DwarfMacinfoSection =
  364. Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
  365. // DWARF5 Experimental Debug Info
  366. // Accelerator Tables
  367. DwarfDebugNamesSection =
  368. Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
  369. DwarfAccelNamesSection =
  370. Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
  371. DwarfAccelObjCSection =
  372. Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
  373. DwarfAccelNamespaceSection =
  374. Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
  375. DwarfAccelTypesSection =
  376. Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
  377. // String Offset and Address Sections
  378. DwarfStrOffSection =
  379. Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
  380. DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
  381. DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);
  382. DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);
  383. // Fission Sections
  384. DwarfInfoDWOSection =
  385. Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);
  386. DwarfTypesDWOSection =
  387. Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);
  388. DwarfAbbrevDWOSection =
  389. Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);
  390. DwarfStrDWOSection = Ctx->getELFSection(
  391. ".debug_str.dwo", DebugSecType,
  392. ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1, "");
  393. DwarfLineDWOSection =
  394. Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);
  395. DwarfLocDWOSection =
  396. Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);
  397. DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",
  398. DebugSecType, ELF::SHF_EXCLUDE);
  399. DwarfRnglistsDWOSection =
  400. Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
  401. // DWP Sections
  402. DwarfCUIndexSection =
  403. Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
  404. DwarfTUIndexSection =
  405. Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
  406. StackMapSection =
  407. Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
  408. FaultMapSection =
  409. Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
  410. EHFrameSection =
  411. Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
  412. StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
  413. RemarksSection =
  414. Ctx->getELFSection(".remarks", ELF::SHT_PROGBITS, ELF::SHF_EXCLUDE);
  415. }
  416. void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
  417. EHFrameSection =
  418. Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  419. COFF::IMAGE_SCN_MEM_READ,
  420. SectionKind::getData());
  421. // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
  422. // used to indicate to the linker that the text segment contains thumb instructions
  423. // and to set the ISA selection bit for calls accordingly.
  424. const bool IsThumb = T.getArch() == Triple::thumb;
  425. CommDirectiveSupportsAlignment = true;
  426. // COFF
  427. BSSSection = Ctx->getCOFFSection(
  428. ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
  429. COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
  430. SectionKind::getBSS());
  431. TextSection = Ctx->getCOFFSection(
  432. ".text",
  433. (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
  434. COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
  435. COFF::IMAGE_SCN_MEM_READ,
  436. SectionKind::getText());
  437. DataSection = Ctx->getCOFFSection(
  438. ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
  439. COFF::IMAGE_SCN_MEM_WRITE,
  440. SectionKind::getData());
  441. ReadOnlySection = Ctx->getCOFFSection(
  442. ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
  443. SectionKind::getReadOnly());
  444. if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64) {
  445. // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
  446. LSDASection = nullptr;
  447. } else {
  448. LSDASection = Ctx->getCOFFSection(".gcc_except_table",
  449. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  450. COFF::IMAGE_SCN_MEM_READ,
  451. SectionKind::getReadOnly());
  452. }
  453. // Debug info.
  454. COFFDebugSymbolsSection =
  455. Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
  456. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  457. COFF::IMAGE_SCN_MEM_READ),
  458. SectionKind::getMetadata());
  459. COFFDebugTypesSection =
  460. Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
  461. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  462. COFF::IMAGE_SCN_MEM_READ),
  463. SectionKind::getMetadata());
  464. COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
  465. ".debug$H",
  466. (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  467. COFF::IMAGE_SCN_MEM_READ),
  468. SectionKind::getMetadata());
  469. DwarfAbbrevSection = Ctx->getCOFFSection(
  470. ".debug_abbrev",
  471. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  472. COFF::IMAGE_SCN_MEM_READ,
  473. SectionKind::getMetadata(), "section_abbrev");
  474. DwarfInfoSection = Ctx->getCOFFSection(
  475. ".debug_info",
  476. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  477. COFF::IMAGE_SCN_MEM_READ,
  478. SectionKind::getMetadata(), "section_info");
  479. DwarfLineSection = Ctx->getCOFFSection(
  480. ".debug_line",
  481. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  482. COFF::IMAGE_SCN_MEM_READ,
  483. SectionKind::getMetadata(), "section_line");
  484. DwarfLineStrSection = Ctx->getCOFFSection(
  485. ".debug_line_str",
  486. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  487. COFF::IMAGE_SCN_MEM_READ,
  488. SectionKind::getMetadata(), "section_line_str");
  489. DwarfFrameSection = Ctx->getCOFFSection(
  490. ".debug_frame",
  491. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  492. COFF::IMAGE_SCN_MEM_READ,
  493. SectionKind::getMetadata());
  494. DwarfPubNamesSection = Ctx->getCOFFSection(
  495. ".debug_pubnames",
  496. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  497. COFF::IMAGE_SCN_MEM_READ,
  498. SectionKind::getMetadata());
  499. DwarfPubTypesSection = Ctx->getCOFFSection(
  500. ".debug_pubtypes",
  501. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  502. COFF::IMAGE_SCN_MEM_READ,
  503. SectionKind::getMetadata());
  504. DwarfGnuPubNamesSection = Ctx->getCOFFSection(
  505. ".debug_gnu_pubnames",
  506. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  507. COFF::IMAGE_SCN_MEM_READ,
  508. SectionKind::getMetadata());
  509. DwarfGnuPubTypesSection = Ctx->getCOFFSection(
  510. ".debug_gnu_pubtypes",
  511. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  512. COFF::IMAGE_SCN_MEM_READ,
  513. SectionKind::getMetadata());
  514. DwarfStrSection = Ctx->getCOFFSection(
  515. ".debug_str",
  516. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  517. COFF::IMAGE_SCN_MEM_READ,
  518. SectionKind::getMetadata(), "info_string");
  519. DwarfStrOffSection = Ctx->getCOFFSection(
  520. ".debug_str_offsets",
  521. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  522. COFF::IMAGE_SCN_MEM_READ,
  523. SectionKind::getMetadata(), "section_str_off");
  524. DwarfLocSection = Ctx->getCOFFSection(
  525. ".debug_loc",
  526. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  527. COFF::IMAGE_SCN_MEM_READ,
  528. SectionKind::getMetadata(), "section_debug_loc");
  529. DwarfARangesSection = Ctx->getCOFFSection(
  530. ".debug_aranges",
  531. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  532. COFF::IMAGE_SCN_MEM_READ,
  533. SectionKind::getMetadata());
  534. DwarfRangesSection = Ctx->getCOFFSection(
  535. ".debug_ranges",
  536. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  537. COFF::IMAGE_SCN_MEM_READ,
  538. SectionKind::getMetadata(), "debug_range");
  539. DwarfMacinfoSection = Ctx->getCOFFSection(
  540. ".debug_macinfo",
  541. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  542. COFF::IMAGE_SCN_MEM_READ,
  543. SectionKind::getMetadata(), "debug_macinfo");
  544. DwarfInfoDWOSection = Ctx->getCOFFSection(
  545. ".debug_info.dwo",
  546. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  547. COFF::IMAGE_SCN_MEM_READ,
  548. SectionKind::getMetadata(), "section_info_dwo");
  549. DwarfTypesDWOSection = Ctx->getCOFFSection(
  550. ".debug_types.dwo",
  551. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  552. COFF::IMAGE_SCN_MEM_READ,
  553. SectionKind::getMetadata(), "section_types_dwo");
  554. DwarfAbbrevDWOSection = Ctx->getCOFFSection(
  555. ".debug_abbrev.dwo",
  556. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  557. COFF::IMAGE_SCN_MEM_READ,
  558. SectionKind::getMetadata(), "section_abbrev_dwo");
  559. DwarfStrDWOSection = Ctx->getCOFFSection(
  560. ".debug_str.dwo",
  561. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  562. COFF::IMAGE_SCN_MEM_READ,
  563. SectionKind::getMetadata(), "skel_string");
  564. DwarfLineDWOSection = Ctx->getCOFFSection(
  565. ".debug_line.dwo",
  566. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  567. COFF::IMAGE_SCN_MEM_READ,
  568. SectionKind::getMetadata());
  569. DwarfLocDWOSection = Ctx->getCOFFSection(
  570. ".debug_loc.dwo",
  571. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  572. COFF::IMAGE_SCN_MEM_READ,
  573. SectionKind::getMetadata(), "skel_loc");
  574. DwarfStrOffDWOSection = Ctx->getCOFFSection(
  575. ".debug_str_offsets.dwo",
  576. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  577. COFF::IMAGE_SCN_MEM_READ,
  578. SectionKind::getMetadata(), "section_str_off_dwo");
  579. DwarfAddrSection = Ctx->getCOFFSection(
  580. ".debug_addr",
  581. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  582. COFF::IMAGE_SCN_MEM_READ,
  583. SectionKind::getMetadata(), "addr_sec");
  584. DwarfCUIndexSection = Ctx->getCOFFSection(
  585. ".debug_cu_index",
  586. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  587. COFF::IMAGE_SCN_MEM_READ,
  588. SectionKind::getMetadata());
  589. DwarfTUIndexSection = Ctx->getCOFFSection(
  590. ".debug_tu_index",
  591. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  592. COFF::IMAGE_SCN_MEM_READ,
  593. SectionKind::getMetadata());
  594. DwarfDebugNamesSection = Ctx->getCOFFSection(
  595. ".debug_names",
  596. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  597. COFF::IMAGE_SCN_MEM_READ,
  598. SectionKind::getMetadata(), "debug_names_begin");
  599. DwarfAccelNamesSection = Ctx->getCOFFSection(
  600. ".apple_names",
  601. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  602. COFF::IMAGE_SCN_MEM_READ,
  603. SectionKind::getMetadata(), "names_begin");
  604. DwarfAccelNamespaceSection = Ctx->getCOFFSection(
  605. ".apple_namespaces",
  606. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  607. COFF::IMAGE_SCN_MEM_READ,
  608. SectionKind::getMetadata(), "namespac_begin");
  609. DwarfAccelTypesSection = Ctx->getCOFFSection(
  610. ".apple_types",
  611. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  612. COFF::IMAGE_SCN_MEM_READ,
  613. SectionKind::getMetadata(), "types_begin");
  614. DwarfAccelObjCSection = Ctx->getCOFFSection(
  615. ".apple_objc",
  616. COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  617. COFF::IMAGE_SCN_MEM_READ,
  618. SectionKind::getMetadata(), "objc_begin");
  619. DrectveSection = Ctx->getCOFFSection(
  620. ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
  621. SectionKind::getMetadata());
  622. PDataSection = Ctx->getCOFFSection(
  623. ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
  624. SectionKind::getData());
  625. XDataSection = Ctx->getCOFFSection(
  626. ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
  627. SectionKind::getData());
  628. SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
  629. SectionKind::getMetadata());
  630. GFIDsSection = Ctx->getCOFFSection(".gfids$y",
  631. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  632. COFF::IMAGE_SCN_MEM_READ,
  633. SectionKind::getMetadata());
  634. TLSDataSection = Ctx->getCOFFSection(
  635. ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
  636. COFF::IMAGE_SCN_MEM_WRITE,
  637. SectionKind::getData());
  638. StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
  639. COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
  640. COFF::IMAGE_SCN_MEM_READ,
  641. SectionKind::getReadOnly());
  642. }
  643. void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
  644. TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
  645. DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
  646. DwarfLineSection =
  647. Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
  648. DwarfLineStrSection =
  649. Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
  650. DwarfStrSection =
  651. Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
  652. DwarfLocSection =
  653. Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
  654. DwarfAbbrevSection =
  655. Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
  656. DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
  657. DwarfRangesSection =
  658. Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
  659. DwarfMacinfoSection =
  660. Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
  661. DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
  662. DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
  663. DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
  664. DwarfInfoSection =
  665. Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
  666. DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
  667. DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
  668. DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
  669. // Wasm use data section for LSDA.
  670. // TODO Consider putting each function's exception table in a separate
  671. // section, as in -function-sections, to facilitate lld's --gc-section.
  672. LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",
  673. SectionKind::getReadOnlyWithRel());
  674. // TODO: Define more sections.
  675. }
  676. void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {
  677. // The default csect for program code. Functions without a specified section
  678. // get placed into this csect. The choice of csect name is not a property of
  679. // the ABI or object file format. For example, the XL compiler uses an unnamed
  680. // csect for program code.
  681. TextSection =
  682. Ctx->getXCOFFSection(".text", XCOFF::StorageMappingClass::XMC_PR,
  683. XCOFF::XTY_SD, SectionKind::getText());
  684. }
  685. void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
  686. MCContext &ctx,
  687. bool LargeCodeModel) {
  688. PositionIndependent = PIC;
  689. Ctx = &ctx;
  690. // Common.
  691. CommDirectiveSupportsAlignment = true;
  692. SupportsWeakOmittedEHFrame = true;
  693. SupportsCompactUnwindWithoutEHFrame = false;
  694. OmitDwarfIfHaveCompactUnwind = false;
  695. FDECFIEncoding = dwarf::DW_EH_PE_absptr;
  696. CompactUnwindDwarfEHFrameOnly = 0;
  697. EHFrameSection = nullptr; // Created on demand.
  698. CompactUnwindSection = nullptr; // Used only by selected targets.
  699. DwarfAccelNamesSection = nullptr; // Used only by selected targets.
  700. DwarfAccelObjCSection = nullptr; // Used only by selected targets.
  701. DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
  702. DwarfAccelTypesSection = nullptr; // Used only by selected targets.
  703. TT = TheTriple;
  704. switch (TT.getObjectFormat()) {
  705. case Triple::MachO:
  706. Env = IsMachO;
  707. initMachOMCObjectFileInfo(TT);
  708. break;
  709. case Triple::COFF:
  710. if (!TT.isOSWindows())
  711. report_fatal_error(
  712. "Cannot initialize MC for non-Windows COFF object files.");
  713. Env = IsCOFF;
  714. initCOFFMCObjectFileInfo(TT);
  715. break;
  716. case Triple::ELF:
  717. Env = IsELF;
  718. initELFMCObjectFileInfo(TT, LargeCodeModel);
  719. break;
  720. case Triple::Wasm:
  721. Env = IsWasm;
  722. initWasmMCObjectFileInfo(TT);
  723. break;
  724. case Triple::XCOFF:
  725. Env = IsXCOFF;
  726. initXCOFFMCObjectFileInfo(TT);
  727. break;
  728. case Triple::UnknownObjectFormat:
  729. report_fatal_error("Cannot initialize MC for unknown object file format.");
  730. break;
  731. }
  732. }
  733. MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
  734. uint64_t Hash) const {
  735. switch (TT.getObjectFormat()) {
  736. case Triple::ELF:
  737. return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,
  738. utostr(Hash));
  739. case Triple::MachO:
  740. case Triple::COFF:
  741. case Triple::Wasm:
  742. case Triple::XCOFF:
  743. case Triple::UnknownObjectFormat:
  744. report_fatal_error("Cannot get DWARF comdat section for this object file "
  745. "format: not implemented.");
  746. break;
  747. }
  748. llvm_unreachable("Unknown ObjectFormatType");
  749. }
  750. MCSection *
  751. MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
  752. if (Env != IsELF)
  753. return StackSizesSection;
  754. const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
  755. unsigned Flags = ELF::SHF_LINK_ORDER;
  756. StringRef GroupName;
  757. if (const MCSymbol *Group = ElfSec.getGroup()) {
  758. GroupName = Group->getName();
  759. Flags |= ELF::SHF_GROUP;
  760. }
  761. const MCSymbol *Link = TextSec.getBeginSymbol();
  762. auto It = StackSizesUniquing.insert({Link, StackSizesUniquing.size()});
  763. unsigned UniqueID = It.first->second;
  764. return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
  765. GroupName, UniqueID, cast<MCSymbolELF>(Link));
  766. }