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