| 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 | |
| 9 | #include "llvm/MC/MCObjectFileInfo.h" |
| 10 | #include "llvm/ADT/StringExtras.h" |
| 11 | #include "llvm/BinaryFormat/COFF.h" |
| 12 | #include "llvm/BinaryFormat/ELF.h" |
| 13 | #include "llvm/BinaryFormat/GOFF.h" |
| 14 | #include "llvm/BinaryFormat/SFrame.h" |
| 15 | #include "llvm/BinaryFormat/Wasm.h" |
| 16 | #include "llvm/MC/MCAsmInfo.h" |
| 17 | #include "llvm/MC/MCContext.h" |
| 18 | #include "llvm/MC/MCGOFFAttributes.h" |
| 19 | #include "llvm/MC/MCSection.h" |
| 20 | #include "llvm/MC/MCSectionCOFF.h" |
| 21 | #include "llvm/MC/MCSectionDXContainer.h" |
| 22 | #include "llvm/MC/MCSectionELF.h" |
| 23 | #include "llvm/MC/MCSectionGOFF.h" |
| 24 | #include "llvm/MC/MCSectionMachO.h" |
| 25 | #include "llvm/MC/MCSectionSPIRV.h" |
| 26 | #include "llvm/MC/MCSectionWasm.h" |
| 27 | #include "llvm/MC/MCSectionXCOFF.h" |
| 28 | #include "llvm/MC/MCSymbolGOFF.h" |
| 29 | #include "llvm/TargetParser/Triple.h" |
| 30 | |
| 31 | using namespace llvm; |
| 32 | |
| 33 | static bool useCompactUnwind(const Triple &T) { |
| 34 | // Only on darwin. |
| 35 | if (!T.isOSDarwin()) |
| 36 | return false; |
| 37 | |
| 38 | // aarch64 always has it. |
| 39 | if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32) |
| 40 | return true; |
| 41 | |
| 42 | // armv7k always has it. |
| 43 | if (T.isWatchABI()) |
| 44 | return true; |
| 45 | |
| 46 | // Use it on newer version of OS X. |
| 47 | if (T.isMacOSX() && !T.isMacOSXVersionLT(Major: 10, Minor: 6)) |
| 48 | return true; |
| 49 | |
| 50 | // And the iOS simulator. |
| 51 | if (T.isiOS() && T.isX86()) |
| 52 | return true; |
| 53 | |
| 54 | // The rest of the simulators always have it. |
| 55 | if (T.isSimulatorEnvironment()) |
| 56 | return true; |
| 57 | |
| 58 | // XROS always has it. |
| 59 | if (T.isXROS()) |
| 60 | return true; |
| 61 | |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) { |
| 66 | EHFrameSection = Ctx->getMachOSection( |
| 67 | Segment: "__TEXT" , Section: "__eh_frame" , |
| 68 | TypeAndAttributes: MachO::S_COALESCED | MachO::S_ATTR_NO_TOC | |
| 69 | MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT, |
| 70 | K: SectionKind::getReadOnly()); |
| 71 | |
| 72 | if (T.isOSDarwin() && |
| 73 | (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32 || |
| 74 | T.isSimulatorEnvironment())) |
| 75 | SupportsCompactUnwindWithoutEHFrame = true; |
| 76 | |
| 77 | switch (Ctx->emitDwarfUnwindInfo()) { |
| 78 | case EmitDwarfUnwindType::Always: |
| 79 | OmitDwarfIfHaveCompactUnwind = false; |
| 80 | break; |
| 81 | case EmitDwarfUnwindType::NoCompactUnwind: |
| 82 | OmitDwarfIfHaveCompactUnwind = true; |
| 83 | break; |
| 84 | case EmitDwarfUnwindType::Default: |
| 85 | OmitDwarfIfHaveCompactUnwind = |
| 86 | T.isWatchABI() || SupportsCompactUnwindWithoutEHFrame; |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | FDECFIEncoding = dwarf::DW_EH_PE_pcrel; |
| 91 | |
| 92 | TextSection // .text |
| 93 | = Ctx->getMachOSection(Segment: "__TEXT" , Section: "__text" , |
| 94 | TypeAndAttributes: MachO::S_ATTR_PURE_INSTRUCTIONS, |
| 95 | K: SectionKind::getText()); |
| 96 | DataSection // .data |
| 97 | = Ctx->getMachOSection(Segment: "__DATA" , Section: "__data" , TypeAndAttributes: 0, K: SectionKind::getData()); |
| 98 | |
| 99 | // BSSSection might not be expected initialized on msvc. |
| 100 | BSSSection = nullptr; |
| 101 | |
| 102 | TLSDataSection // .tdata |
| 103 | = Ctx->getMachOSection(Segment: "__DATA" , Section: "__thread_data" , |
| 104 | TypeAndAttributes: MachO::S_THREAD_LOCAL_REGULAR, |
| 105 | K: SectionKind::getData()); |
| 106 | TLSBSSSection // .tbss |
| 107 | = Ctx->getMachOSection(Segment: "__DATA" , Section: "__thread_bss" , |
| 108 | TypeAndAttributes: MachO::S_THREAD_LOCAL_ZEROFILL, |
| 109 | K: SectionKind::getThreadBSS()); |
| 110 | |
| 111 | // TODO: Verify datarel below. |
| 112 | TLSTLVSection // .tlv |
| 113 | = Ctx->getMachOSection(Segment: "__DATA" , Section: "__thread_vars" , |
| 114 | TypeAndAttributes: MachO::S_THREAD_LOCAL_VARIABLES, |
| 115 | K: SectionKind::getData()); |
| 116 | |
| 117 | TLSThreadInitSection = Ctx->getMachOSection( |
| 118 | Segment: "__DATA" , Section: "__thread_init" , TypeAndAttributes: MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, |
| 119 | K: SectionKind::getData()); |
| 120 | |
| 121 | CStringSection // .cstring |
| 122 | = Ctx->getMachOSection(Segment: "__TEXT" , Section: "__cstring" , |
| 123 | TypeAndAttributes: MachO::S_CSTRING_LITERALS, |
| 124 | K: SectionKind::getMergeable1ByteCString()); |
| 125 | UStringSection |
| 126 | = Ctx->getMachOSection(Segment: "__TEXT" ,Section: "__ustring" , TypeAndAttributes: 0, |
| 127 | K: SectionKind::getMergeable2ByteCString()); |
| 128 | FourByteConstantSection // .literal4 |
| 129 | = Ctx->getMachOSection(Segment: "__TEXT" , Section: "__literal4" , |
| 130 | TypeAndAttributes: MachO::S_4BYTE_LITERALS, |
| 131 | K: SectionKind::getMergeableConst4()); |
| 132 | EightByteConstantSection // .literal8 |
| 133 | = Ctx->getMachOSection(Segment: "__TEXT" , Section: "__literal8" , |
| 134 | TypeAndAttributes: MachO::S_8BYTE_LITERALS, |
| 135 | K: SectionKind::getMergeableConst8()); |
| 136 | |
| 137 | SixteenByteConstantSection // .literal16 |
| 138 | = Ctx->getMachOSection(Segment: "__TEXT" , Section: "__literal16" , |
| 139 | TypeAndAttributes: MachO::S_16BYTE_LITERALS, |
| 140 | K: SectionKind::getMergeableConst16()); |
| 141 | |
| 142 | ReadOnlySection // .const |
| 143 | = Ctx->getMachOSection(Segment: "__TEXT" , Section: "__const" , TypeAndAttributes: 0, |
| 144 | K: SectionKind::getReadOnly()); |
| 145 | |
| 146 | // If the target is not powerpc, map the coal sections to the non-coal |
| 147 | // sections. |
| 148 | // |
| 149 | // "__TEXT/__textcoal_nt" => section "__TEXT/__text" |
| 150 | // "__TEXT/__const_coal" => section "__TEXT/__const" |
| 151 | // "__DATA/__datacoal_nt" => section "__DATA/__data" |
| 152 | Triple::ArchType ArchTy = T.getArch(); |
| 153 | |
| 154 | ConstDataSection // .const_data |
| 155 | = Ctx->getMachOSection(Segment: "__DATA" , Section: "__const" , TypeAndAttributes: 0, |
| 156 | K: SectionKind::getReadOnlyWithRel()); |
| 157 | |
| 158 | if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) { |
| 159 | TextCoalSection |
| 160 | = Ctx->getMachOSection(Segment: "__TEXT" , Section: "__textcoal_nt" , |
| 161 | TypeAndAttributes: MachO::S_COALESCED | |
| 162 | MachO::S_ATTR_PURE_INSTRUCTIONS, |
| 163 | K: SectionKind::getText()); |
| 164 | ConstTextCoalSection |
| 165 | = Ctx->getMachOSection(Segment: "__TEXT" , Section: "__const_coal" , |
| 166 | TypeAndAttributes: MachO::S_COALESCED, |
| 167 | K: SectionKind::getReadOnly()); |
| 168 | DataCoalSection = Ctx->getMachOSection( |
| 169 | Segment: "__DATA" , Section: "__datacoal_nt" , TypeAndAttributes: MachO::S_COALESCED, K: SectionKind::getData()); |
| 170 | ConstDataCoalSection = DataCoalSection; |
| 171 | } else { |
| 172 | TextCoalSection = TextSection; |
| 173 | ConstTextCoalSection = ReadOnlySection; |
| 174 | DataCoalSection = DataSection; |
| 175 | ConstDataCoalSection = ConstDataSection; |
| 176 | } |
| 177 | |
| 178 | DataCommonSection |
| 179 | = Ctx->getMachOSection(Segment: "__DATA" ,Section: "__common" , |
| 180 | TypeAndAttributes: MachO::S_ZEROFILL, |
| 181 | K: SectionKind::getBSS()); |
| 182 | DataBSSSection |
| 183 | = Ctx->getMachOSection(Segment: "__DATA" ,Section: "__bss" , TypeAndAttributes: MachO::S_ZEROFILL, |
| 184 | K: SectionKind::getBSS()); |
| 185 | |
| 186 | |
| 187 | LazySymbolPointerSection |
| 188 | = Ctx->getMachOSection(Segment: "__DATA" , Section: "__la_symbol_ptr" , |
| 189 | TypeAndAttributes: MachO::S_LAZY_SYMBOL_POINTERS, |
| 190 | K: SectionKind::getMetadata()); |
| 191 | NonLazySymbolPointerSection |
| 192 | = Ctx->getMachOSection(Segment: "__DATA" , Section: "__nl_symbol_ptr" , |
| 193 | TypeAndAttributes: MachO::S_NON_LAZY_SYMBOL_POINTERS, |
| 194 | K: SectionKind::getMetadata()); |
| 195 | |
| 196 | ThreadLocalPointerSection |
| 197 | = Ctx->getMachOSection(Segment: "__DATA" , Section: "__thread_ptr" , |
| 198 | TypeAndAttributes: MachO::S_THREAD_LOCAL_VARIABLE_POINTERS, |
| 199 | K: SectionKind::getMetadata()); |
| 200 | |
| 201 | AddrSigSection = Ctx->getMachOSection(Segment: "__DATA" , Section: "__llvm_addrsig" , TypeAndAttributes: 0, |
| 202 | K: SectionKind::getData()); |
| 203 | |
| 204 | // Exception Handling. |
| 205 | LSDASection = Ctx->getMachOSection(Segment: "__TEXT" , Section: "__gcc_except_tab" , TypeAndAttributes: 0, |
| 206 | K: SectionKind::getReadOnlyWithRel()); |
| 207 | |
| 208 | COFFDebugSymbolsSection = nullptr; |
| 209 | COFFDebugTypesSection = nullptr; |
| 210 | COFFGlobalTypeHashesSection = nullptr; |
| 211 | |
| 212 | if (useCompactUnwind(T)) { |
| 213 | CompactUnwindSection = |
| 214 | Ctx->getMachOSection(Segment: "__LD" , Section: "__compact_unwind" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 215 | K: SectionKind::getReadOnly()); |
| 216 | |
| 217 | if (T.isX86()) |
| 218 | CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF |
| 219 | else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32) |
| 220 | CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF |
| 221 | else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb) |
| 222 | CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF |
| 223 | } |
| 224 | |
| 225 | // Debug Information. |
| 226 | DwarfDebugNamesSection = |
| 227 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_names" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 228 | K: SectionKind::getMetadata(), BeginSymName: "debug_names_begin" ); |
| 229 | DwarfAccelNamesSection = |
| 230 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__apple_names" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 231 | K: SectionKind::getMetadata(), BeginSymName: "names_begin" ); |
| 232 | DwarfAccelObjCSection = |
| 233 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__apple_objc" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 234 | K: SectionKind::getMetadata(), BeginSymName: "objc_begin" ); |
| 235 | // 16 character section limit... |
| 236 | DwarfAccelNamespaceSection = |
| 237 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__apple_namespac" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 238 | K: SectionKind::getMetadata(), BeginSymName: "namespac_begin" ); |
| 239 | DwarfAccelTypesSection = |
| 240 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__apple_types" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 241 | K: SectionKind::getMetadata(), BeginSymName: "types_begin" ); |
| 242 | |
| 243 | DwarfSwiftASTSection = |
| 244 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__swift_ast" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 245 | K: SectionKind::getMetadata()); |
| 246 | |
| 247 | DwarfAbbrevSection = |
| 248 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_abbrev" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 249 | K: SectionKind::getMetadata(), BeginSymName: "section_abbrev" ); |
| 250 | DwarfInfoSection = |
| 251 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_info" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 252 | K: SectionKind::getMetadata(), BeginSymName: "section_info" ); |
| 253 | DwarfLineSection = |
| 254 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_line" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 255 | K: SectionKind::getMetadata(), BeginSymName: "section_line" ); |
| 256 | DwarfLineStrSection = |
| 257 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_line_str" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 258 | K: SectionKind::getMetadata(), BeginSymName: "section_line_str" ); |
| 259 | DwarfFrameSection = |
| 260 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_frame" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 261 | K: SectionKind::getMetadata(), BeginSymName: "section_frame" ); |
| 262 | DwarfPubNamesSection = |
| 263 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_pubnames" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 264 | K: SectionKind::getMetadata()); |
| 265 | DwarfPubTypesSection = |
| 266 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_pubtypes" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 267 | K: SectionKind::getMetadata()); |
| 268 | DwarfGnuPubNamesSection = |
| 269 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_gnu_pubn" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 270 | K: SectionKind::getMetadata()); |
| 271 | DwarfGnuPubTypesSection = |
| 272 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_gnu_pubt" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 273 | K: SectionKind::getMetadata()); |
| 274 | DwarfStrSection = |
| 275 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_str" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 276 | K: SectionKind::getMetadata(), BeginSymName: "info_string" ); |
| 277 | DwarfStrOffSection = |
| 278 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_str_offs" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 279 | K: SectionKind::getMetadata(), BeginSymName: "section_str_off" ); |
| 280 | DwarfAddrSection = |
| 281 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_addr" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 282 | K: SectionKind::getMetadata(), BeginSymName: "section_info" ); |
| 283 | DwarfLocSection = |
| 284 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_loc" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 285 | K: SectionKind::getMetadata(), BeginSymName: "section_debug_loc" ); |
| 286 | DwarfLoclistsSection = |
| 287 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_loclists" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 288 | K: SectionKind::getMetadata(), BeginSymName: "section_debug_loc" ); |
| 289 | |
| 290 | DwarfARangesSection = |
| 291 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_aranges" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 292 | K: SectionKind::getMetadata()); |
| 293 | DwarfRangesSection = |
| 294 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_ranges" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 295 | K: SectionKind::getMetadata(), BeginSymName: "debug_range" ); |
| 296 | DwarfRnglistsSection = |
| 297 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_rnglists" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 298 | K: SectionKind::getMetadata(), BeginSymName: "debug_range" ); |
| 299 | DwarfMacinfoSection = |
| 300 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_macinfo" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 301 | K: SectionKind::getMetadata(), BeginSymName: "debug_macinfo" ); |
| 302 | DwarfMacroSection = |
| 303 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_macro" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 304 | K: SectionKind::getMetadata(), BeginSymName: "debug_macro" ); |
| 305 | DwarfDebugInlineSection = |
| 306 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_inlined" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 307 | K: SectionKind::getMetadata()); |
| 308 | DwarfCUIndexSection = |
| 309 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_cu_index" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 310 | K: SectionKind::getMetadata()); |
| 311 | DwarfTUIndexSection = |
| 312 | Ctx->getMachOSection(Segment: "__DWARF" , Section: "__debug_tu_index" , TypeAndAttributes: MachO::S_ATTR_DEBUG, |
| 313 | K: SectionKind::getMetadata()); |
| 314 | StackMapSection = Ctx->getMachOSection(Segment: "__LLVM_STACKMAPS" , Section: "__llvm_stackmaps" , |
| 315 | TypeAndAttributes: 0, K: SectionKind::getMetadata()); |
| 316 | |
| 317 | FaultMapSection = Ctx->getMachOSection(Segment: "__LLVM_FAULTMAPS" , Section: "__llvm_faultmaps" , |
| 318 | TypeAndAttributes: 0, K: SectionKind::getMetadata()); |
| 319 | |
| 320 | RemarksSection = Ctx->getMachOSection( |
| 321 | Segment: "__LLVM" , Section: "__remarks" , TypeAndAttributes: MachO::S_ATTR_DEBUG, K: SectionKind::getMetadata()); |
| 322 | |
| 323 | // The architecture of dsymutil makes it very difficult to copy the Swift |
| 324 | // reflection metadata sections into the __TEXT segment, so dsymutil creates |
| 325 | // these sections in the __DWARF segment instead. |
| 326 | if (!Ctx->getSwift5ReflectionSegmentName().empty()) { |
| 327 | #define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \ |
| 328 | Swift5ReflectionSections \ |
| 329 | [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \ |
| 330 | Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \ |
| 331 | MACHO, 0, SectionKind::getMetadata()); |
| 332 | #include "llvm/BinaryFormat/Swift.def" |
| 333 | } |
| 334 | |
| 335 | TLSExtraDataSection = TLSTLVSection; |
| 336 | } |
| 337 | |
| 338 | void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) { |
| 339 | switch (T.getArch()) { |
| 340 | case Triple::mips: |
| 341 | case Triple::mipsel: |
| 342 | case Triple::mips64: |
| 343 | case Triple::mips64el: |
| 344 | // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case |
| 345 | // since there is no R_MIPS_PC64 relocation (only a 32-bit version). |
| 346 | // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't |
| 347 | // support pcrel|sdata8 well. Let's use sdata4 for now. |
| 348 | if (PositionIndependent) |
| 349 | FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
| 350 | else |
| 351 | FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4 |
| 352 | ? dwarf::DW_EH_PE_sdata4 |
| 353 | : dwarf::DW_EH_PE_sdata8; |
| 354 | break; |
| 355 | case Triple::ppc64: |
| 356 | case Triple::ppc64le: |
| 357 | case Triple::aarch64: |
| 358 | case Triple::aarch64_be: |
| 359 | case Triple::x86_64: |
| 360 | FDECFIEncoding = dwarf::DW_EH_PE_pcrel | |
| 361 | (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4); |
| 362 | break; |
| 363 | case Triple::bpfel: |
| 364 | case Triple::bpfeb: |
| 365 | FDECFIEncoding = dwarf::DW_EH_PE_sdata8; |
| 366 | break; |
| 367 | case Triple::hexagon: |
| 368 | FDECFIEncoding = |
| 369 | PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr; |
| 370 | break; |
| 371 | case Triple::xtensa: |
| 372 | FDECFIEncoding = dwarf::DW_EH_PE_sdata4; |
| 373 | break; |
| 374 | default: |
| 375 | FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; |
| 376 | break; |
| 377 | } |
| 378 | |
| 379 | unsigned EHSectionType = T.getArch() == Triple::x86_64 |
| 380 | ? ELF::SHT_X86_64_UNWIND |
| 381 | : ELF::SHT_PROGBITS; |
| 382 | switch (T.getArch()) { |
| 383 | case Triple::x86_64: |
| 384 | SFrameABIArch = sframe::ABI::AMD64EndianLittle; |
| 385 | break; |
| 386 | case Triple::aarch64: |
| 387 | SFrameABIArch = sframe::ABI::AArch64EndianLittle; |
| 388 | break; |
| 389 | case Triple::aarch64_be: |
| 390 | SFrameABIArch = sframe::ABI::AArch64EndianBig; |
| 391 | break; |
| 392 | default: |
| 393 | break; |
| 394 | } |
| 395 | |
| 396 | // Solaris requires different flags for .eh_frame to seemingly every other |
| 397 | // platform. |
| 398 | unsigned EHSectionFlags = ELF::SHF_ALLOC; |
| 399 | if (T.isOSSolaris() && T.getArch() != Triple::x86_64) |
| 400 | EHSectionFlags |= ELF::SHF_WRITE; |
| 401 | |
| 402 | // ELF |
| 403 | BSSSection = Ctx->getELFSection(Section: ".bss" , Type: ELF::SHT_NOBITS, |
| 404 | Flags: ELF::SHF_WRITE | ELF::SHF_ALLOC); |
| 405 | |
| 406 | TextSection = Ctx->getELFSection(Section: ".text" , Type: ELF::SHT_PROGBITS, |
| 407 | Flags: ELF::SHF_EXECINSTR | ELF::SHF_ALLOC); |
| 408 | |
| 409 | DataSection = Ctx->getELFSection(Section: ".data" , Type: ELF::SHT_PROGBITS, |
| 410 | Flags: ELF::SHF_WRITE | ELF::SHF_ALLOC); |
| 411 | |
| 412 | ReadOnlySection = |
| 413 | Ctx->getELFSection(Section: ".rodata" , Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC); |
| 414 | |
| 415 | TLSDataSection = |
| 416 | Ctx->getELFSection(Section: ".tdata" , Type: ELF::SHT_PROGBITS, |
| 417 | Flags: ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); |
| 418 | |
| 419 | TLSBSSSection = Ctx->getELFSection( |
| 420 | Section: ".tbss" , Type: ELF::SHT_NOBITS, Flags: ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); |
| 421 | |
| 422 | DataRelROSection = Ctx->getELFSection(Section: ".data.rel.ro" , Type: ELF::SHT_PROGBITS, |
| 423 | Flags: ELF::SHF_ALLOC | ELF::SHF_WRITE); |
| 424 | |
| 425 | MergeableConst4Section = |
| 426 | Ctx->getELFSection(Section: ".rodata.cst4" , Type: ELF::SHT_PROGBITS, |
| 427 | Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 4); |
| 428 | |
| 429 | MergeableConst8Section = |
| 430 | Ctx->getELFSection(Section: ".rodata.cst8" , Type: ELF::SHT_PROGBITS, |
| 431 | Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 8); |
| 432 | |
| 433 | MergeableConst16Section = |
| 434 | Ctx->getELFSection(Section: ".rodata.cst16" , Type: ELF::SHT_PROGBITS, |
| 435 | Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 16); |
| 436 | |
| 437 | MergeableConst32Section = |
| 438 | Ctx->getELFSection(Section: ".rodata.cst32" , Type: ELF::SHT_PROGBITS, |
| 439 | Flags: ELF::SHF_ALLOC | ELF::SHF_MERGE, EntrySize: 32); |
| 440 | |
| 441 | // Exception Handling Sections. |
| 442 | |
| 443 | // FIXME: We're emitting LSDA info into a readonly section on ELF, even though |
| 444 | // it contains relocatable pointers. In PIC mode, this is probably a big |
| 445 | // runtime hit for C++ apps. Either the contents of the LSDA need to be |
| 446 | // adjusted or this should be a data section. |
| 447 | LSDASection = Ctx->getELFSection(Section: ".gcc_except_table" , Type: ELF::SHT_PROGBITS, |
| 448 | Flags: ELF::SHF_ALLOC); |
| 449 | |
| 450 | COFFDebugSymbolsSection = nullptr; |
| 451 | COFFDebugTypesSection = nullptr; |
| 452 | |
| 453 | unsigned DebugSecType = ELF::SHT_PROGBITS; |
| 454 | |
| 455 | // MIPS .debug_* sections should have SHT_MIPS_DWARF section type |
| 456 | // to distinguish among sections contain DWARF and ECOFF debug formats. |
| 457 | // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS. |
| 458 | if (T.isMIPS()) |
| 459 | DebugSecType = ELF::SHT_MIPS_DWARF; |
| 460 | |
| 461 | // Debug Info Sections. |
| 462 | DwarfAbbrevSection = |
| 463 | Ctx->getELFSection(Section: ".debug_abbrev" , Type: DebugSecType, Flags: 0); |
| 464 | DwarfInfoSection = Ctx->getELFSection(Section: ".debug_info" , Type: DebugSecType, Flags: 0); |
| 465 | DwarfLineSection = Ctx->getELFSection(Section: ".debug_line" , Type: DebugSecType, Flags: 0); |
| 466 | DwarfLineStrSection = |
| 467 | Ctx->getELFSection(Section: ".debug_line_str" , Type: DebugSecType, |
| 468 | Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize: 1); |
| 469 | DwarfFrameSection = Ctx->getELFSection(Section: ".debug_frame" , Type: DebugSecType, Flags: 0); |
| 470 | DwarfPubNamesSection = |
| 471 | Ctx->getELFSection(Section: ".debug_pubnames" , Type: DebugSecType, Flags: 0); |
| 472 | DwarfPubTypesSection = |
| 473 | Ctx->getELFSection(Section: ".debug_pubtypes" , Type: DebugSecType, Flags: 0); |
| 474 | DwarfGnuPubNamesSection = |
| 475 | Ctx->getELFSection(Section: ".debug_gnu_pubnames" , Type: DebugSecType, Flags: 0); |
| 476 | DwarfGnuPubTypesSection = |
| 477 | Ctx->getELFSection(Section: ".debug_gnu_pubtypes" , Type: DebugSecType, Flags: 0); |
| 478 | DwarfStrSection = |
| 479 | Ctx->getELFSection(Section: ".debug_str" , Type: DebugSecType, |
| 480 | Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize: 1); |
| 481 | DwarfLocSection = Ctx->getELFSection(Section: ".debug_loc" , Type: DebugSecType, Flags: 0); |
| 482 | DwarfARangesSection = |
| 483 | Ctx->getELFSection(Section: ".debug_aranges" , Type: DebugSecType, Flags: 0); |
| 484 | DwarfRangesSection = |
| 485 | Ctx->getELFSection(Section: ".debug_ranges" , Type: DebugSecType, Flags: 0); |
| 486 | DwarfMacinfoSection = |
| 487 | Ctx->getELFSection(Section: ".debug_macinfo" , Type: DebugSecType, Flags: 0); |
| 488 | DwarfMacroSection = Ctx->getELFSection(Section: ".debug_macro" , Type: DebugSecType, Flags: 0); |
| 489 | |
| 490 | // DWARF5 Experimental Debug Info |
| 491 | |
| 492 | // Accelerator Tables |
| 493 | DwarfDebugNamesSection = |
| 494 | Ctx->getELFSection(Section: ".debug_names" , Type: ELF::SHT_PROGBITS, Flags: 0); |
| 495 | DwarfAccelNamesSection = |
| 496 | Ctx->getELFSection(Section: ".apple_names" , Type: ELF::SHT_PROGBITS, Flags: 0); |
| 497 | DwarfAccelObjCSection = |
| 498 | Ctx->getELFSection(Section: ".apple_objc" , Type: ELF::SHT_PROGBITS, Flags: 0); |
| 499 | DwarfAccelNamespaceSection = |
| 500 | Ctx->getELFSection(Section: ".apple_namespaces" , Type: ELF::SHT_PROGBITS, Flags: 0); |
| 501 | DwarfAccelTypesSection = |
| 502 | Ctx->getELFSection(Section: ".apple_types" , Type: ELF::SHT_PROGBITS, Flags: 0); |
| 503 | |
| 504 | // String Offset and Address Sections |
| 505 | DwarfStrOffSection = |
| 506 | Ctx->getELFSection(Section: ".debug_str_offsets" , Type: DebugSecType, Flags: 0); |
| 507 | DwarfAddrSection = Ctx->getELFSection(Section: ".debug_addr" , Type: DebugSecType, Flags: 0); |
| 508 | DwarfRnglistsSection = Ctx->getELFSection(Section: ".debug_rnglists" , Type: DebugSecType, Flags: 0); |
| 509 | DwarfLoclistsSection = Ctx->getELFSection(Section: ".debug_loclists" , Type: DebugSecType, Flags: 0); |
| 510 | |
| 511 | // Fission Sections |
| 512 | DwarfInfoDWOSection = |
| 513 | Ctx->getELFSection(Section: ".debug_info.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 514 | DwarfTypesDWOSection = |
| 515 | Ctx->getELFSection(Section: ".debug_types.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 516 | DwarfAbbrevDWOSection = |
| 517 | Ctx->getELFSection(Section: ".debug_abbrev.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 518 | DwarfStrDWOSection = Ctx->getELFSection( |
| 519 | Section: ".debug_str.dwo" , Type: DebugSecType, |
| 520 | Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, EntrySize: 1); |
| 521 | DwarfLineDWOSection = |
| 522 | Ctx->getELFSection(Section: ".debug_line.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 523 | DwarfLocDWOSection = |
| 524 | Ctx->getELFSection(Section: ".debug_loc.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 525 | DwarfStrOffDWOSection = Ctx->getELFSection(Section: ".debug_str_offsets.dwo" , |
| 526 | Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 527 | DwarfRnglistsDWOSection = |
| 528 | Ctx->getELFSection(Section: ".debug_rnglists.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 529 | DwarfMacinfoDWOSection = |
| 530 | Ctx->getELFSection(Section: ".debug_macinfo.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 531 | DwarfMacroDWOSection = |
| 532 | Ctx->getELFSection(Section: ".debug_macro.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 533 | |
| 534 | DwarfLoclistsDWOSection = |
| 535 | Ctx->getELFSection(Section: ".debug_loclists.dwo" , Type: DebugSecType, Flags: ELF::SHF_EXCLUDE); |
| 536 | |
| 537 | // DWP Sections |
| 538 | DwarfCUIndexSection = |
| 539 | Ctx->getELFSection(Section: ".debug_cu_index" , Type: DebugSecType, Flags: 0); |
| 540 | DwarfTUIndexSection = |
| 541 | Ctx->getELFSection(Section: ".debug_tu_index" , Type: DebugSecType, Flags: 0); |
| 542 | |
| 543 | StackMapSection = |
| 544 | Ctx->getELFSection(Section: ".llvm_stackmaps" , Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC); |
| 545 | |
| 546 | FaultMapSection = |
| 547 | Ctx->getELFSection(Section: ".llvm_faultmaps" , Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_ALLOC); |
| 548 | |
| 549 | EHFrameSection = |
| 550 | Ctx->getELFSection(Section: ".eh_frame" , Type: EHSectionType, Flags: EHSectionFlags); |
| 551 | |
| 552 | SFrameSection = |
| 553 | Ctx->getELFSection(Section: ".sframe" , Type: ELF::SHT_GNU_SFRAME, Flags: ELF::SHF_ALLOC); |
| 554 | |
| 555 | CallGraphSection = |
| 556 | Ctx->getELFSection(Section: ".llvm.callgraph" , Type: ELF::SHT_LLVM_CALL_GRAPH, Flags: 0); |
| 557 | |
| 558 | StackSizesSection = Ctx->getELFSection(Section: ".stack_sizes" , Type: ELF::SHT_PROGBITS, Flags: 0); |
| 559 | |
| 560 | PseudoProbeSection = Ctx->getELFSection(Section: ".pseudo_probe" , Type: DebugSecType, Flags: 0); |
| 561 | PseudoProbeDescSection = |
| 562 | Ctx->getELFSection(Section: ".pseudo_probe_desc" , Type: DebugSecType, Flags: 0); |
| 563 | |
| 564 | LLVMStatsSection = Ctx->getELFSection(Section: ".llvm_stats" , Type: ELF::SHT_PROGBITS, Flags: 0); |
| 565 | } |
| 566 | |
| 567 | void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) { |
| 568 | MCSectionGOFF *RootSDSection = Ctx->getGOFFSection( |
| 569 | Kind: SectionKind::getMetadata(), Name: "#C" , |
| 570 | SDAttributes: GOFF::SDAttr{.TaskingBehavior: GOFF::ESD_TA_Rent, .BindingScope: GOFF::ESD_BSC_Section}); |
| 571 | |
| 572 | MCSectionGOFF *ADAEDSection = Ctx->getGOFFSection( |
| 573 | Kind: SectionKind::getMetadata(), Name: GOFF::CLASS_WSA, |
| 574 | EDAttributes: GOFF::EDAttr{.IsReadOnly: false, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_Parts, |
| 575 | .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Merge, |
| 576 | .LoadBehavior: GOFF::ESD_LB_Deferred, .ReservedQwords: GOFF::ESD_RQ_1, |
| 577 | .Alignment: GOFF::ESD_ALIGN_Quadword, .FillByteValue: 0}, |
| 578 | Parent: RootSDSection); |
| 579 | ADASection = Ctx->getGOFFSection(Kind: SectionKind::getData(), Name: "#S" , |
| 580 | PRAttributes: GOFF::PRAttr{.IsRenamable: false, .Executable: GOFF::ESD_EXE_DATA, |
| 581 | .Linkage: GOFF::ESD_LT_XPLink, |
| 582 | .BindingScope: GOFF::ESD_BSC_Section, .SortKey: 0}, |
| 583 | Parent: ADAEDSection); |
| 584 | |
| 585 | TextSection = Ctx->getGOFFSection( |
| 586 | Kind: SectionKind::getText(), Name: GOFF::CLASS_CODE, |
| 587 | EDAttributes: GOFF::EDAttr{.IsReadOnly: true, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_NormalName, |
| 588 | .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Concatenate, |
| 589 | .LoadBehavior: GOFF::ESD_LB_Initial, .ReservedQwords: GOFF::ESD_RQ_0, |
| 590 | .Alignment: GOFF::ESD_ALIGN_Doubleword, .FillByteValue: 0}, |
| 591 | Parent: RootSDSection); |
| 592 | |
| 593 | MCSectionGOFF *PPA2ListEDSection = Ctx->getGOFFSection( |
| 594 | Kind: SectionKind::getMetadata(), Name: GOFF::CLASS_PPA2, |
| 595 | EDAttributes: GOFF::EDAttr{.IsReadOnly: true, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_Parts, |
| 596 | .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Merge, |
| 597 | .LoadBehavior: GOFF::ESD_LB_Initial, .ReservedQwords: GOFF::ESD_RQ_0, |
| 598 | .Alignment: GOFF::ESD_ALIGN_Doubleword, .FillByteValue: 0}, |
| 599 | Parent: RootSDSection); |
| 600 | PPA2ListSection = Ctx->getGOFFSection(Kind: SectionKind::getData(), Name: ".&ppa2" , |
| 601 | PRAttributes: GOFF::PRAttr{.IsRenamable: true, .Executable: GOFF::ESD_EXE_DATA, |
| 602 | .Linkage: GOFF::ESD_LT_OS, |
| 603 | .BindingScope: GOFF::ESD_BSC_Section, .SortKey: 0}, |
| 604 | Parent: PPA2ListEDSection); |
| 605 | |
| 606 | IDRLSection = Ctx->getGOFFSection( |
| 607 | Kind: SectionKind::getData(), Name: "B_IDRL" , |
| 608 | EDAttributes: GOFF::EDAttr{.IsReadOnly: true, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_NormalName, |
| 609 | .TextStyle: GOFF::ESD_TS_Structured, .BindAlgorithm: GOFF::ESD_BA_Concatenate, |
| 610 | .LoadBehavior: GOFF::ESD_LB_NoLoad, .ReservedQwords: GOFF::ESD_RQ_0, |
| 611 | .Alignment: GOFF::ESD_ALIGN_Doubleword, .FillByteValue: 0}, |
| 612 | Parent: RootSDSection); |
| 613 | |
| 614 | // Debug Info Sections. The ED name is the same used by the XL compiler. |
| 615 | auto InitDebugSection = [this, |
| 616 | RootSDSection](StringRef EDName, |
| 617 | StringRef LDName) -> MCSectionGOFF * { |
| 618 | MCSectionGOFF *ED = Ctx->getGOFFSection( |
| 619 | Kind: SectionKind::getMetadata(), Name: EDName, |
| 620 | EDAttributes: GOFF::EDAttr{.IsReadOnly: false, .Rmode: GOFF::ESD_RMODE_64, .NameSpace: GOFF::ESD_NS_Parts, |
| 621 | .TextStyle: GOFF::ESD_TS_ByteOriented, .BindAlgorithm: GOFF::ESD_BA_Concatenate, |
| 622 | .LoadBehavior: GOFF::ESD_LB_NoLoad, .ReservedQwords: GOFF::ESD_RQ_0, |
| 623 | .Alignment: GOFF::ESD_ALIGN_Doubleword, .FillByteValue: 0}, |
| 624 | Parent: RootSDSection); |
| 625 | // At least for llc, this function is called twice! (See function |
| 626 | // compileModule() in llc.cpp). Since the context is not cleared, the |
| 627 | // already allocated section is returned above. We only add the begin symbol |
| 628 | // if it is not yet set to avoid an assertion. |
| 629 | MCSymbolGOFF *LD = static_cast<MCSymbolGOFF *>(ED->getBeginSymbol()); |
| 630 | if (!LD) { |
| 631 | LD = static_cast<MCSymbolGOFF *>(getContext().getOrCreateSymbol(Name: LDName)); |
| 632 | LD->setCodeData(GOFF::ESD_EXE_DATA); |
| 633 | LD->setWeak(false); |
| 634 | LD->setLinkage(GOFF::ESD_LT_XPLink); |
| 635 | LD->setExternal(false); |
| 636 | ED->setBeginSymbol(LD); |
| 637 | } else |
| 638 | assert(LD->getName() == LDName && "Wrong label name" ); |
| 639 | return ED; |
| 640 | }; |
| 641 | DwarfAbbrevSection = InitDebugSection("D_ABREV" , ".debug_abbrev" ); |
| 642 | DwarfInfoSection = InitDebugSection("D_INFO" , ".debug_info" ); |
| 643 | DwarfLineSection = InitDebugSection("D_LINE" , ".debug_line" ); |
| 644 | DwarfFrameSection = InitDebugSection("D_FRAME" , ".debug_frame" ); |
| 645 | DwarfPubNamesSection = InitDebugSection("D_PBNMS" , ".debug_pubnames" ); |
| 646 | DwarfPubTypesSection = InitDebugSection("D_PTYPES" , ".debug_pubtypes" ); |
| 647 | DwarfStrSection = InitDebugSection("D_STR" , ".debug_str" ); |
| 648 | DwarfLocSection = InitDebugSection("D_LOC" , ".debug_loc" ); |
| 649 | DwarfARangesSection = InitDebugSection("D_ARNGE" , ".debug_aranges" ); |
| 650 | DwarfRangesSection = InitDebugSection("D_RNGES" , ".debug_ranges" ); |
| 651 | DwarfMacinfoSection = InitDebugSection("D_MACIN" , ".debug_macinfo" ); |
| 652 | |
| 653 | // DWARF 5 sections. |
| 654 | DwarfDebugNamesSection = InitDebugSection("D_NAMES" , ".debug_names" ); |
| 655 | DwarfStrOffSection = InitDebugSection("D_STROFFS" , ".debug_str_offsets" ); |
| 656 | DwarfAddrSection = InitDebugSection("D_ADDR" , ".debug_addr" ); |
| 657 | DwarfRnglistsSection = InitDebugSection("D_RNGLISTS" , ".debug_rnglists" ); |
| 658 | DwarfLoclistsSection = InitDebugSection("D_LOCLISTS" , ".debug_loclists" ); |
| 659 | DwarfLineStrSection = InitDebugSection("D_LINESTR" , ".debug_line_str" ); |
| 660 | |
| 661 | // Special GNU sections. |
| 662 | DwarfGnuPubNamesSection = InitDebugSection("D_GPBNMS" , ".debug_gnu_pubnames" ); |
| 663 | DwarfGnuPubTypesSection = |
| 664 | InitDebugSection("D_GPTYPES" , ".debug_gnu_pubtypes" ); |
| 665 | |
| 666 | // Accelerator Tables. |
| 667 | DwarfAccelNamesSection = InitDebugSection("D_APPLNMS" , ".apple_names" ); |
| 668 | DwarfAccelNamespaceSection = |
| 669 | InitDebugSection("D_APPLNMSP" , ".apple_namespaces" ); |
| 670 | DwarfAccelTypesSection = InitDebugSection("D_APPLTYPS" , ".apple_types" ); |
| 671 | DwarfAccelObjCSection = InitDebugSection("D_APPLOBJC" , ".apple_objc" ); |
| 672 | } |
| 673 | |
| 674 | void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) { |
| 675 | EHFrameSection = |
| 676 | Ctx->getCOFFSection(Section: ".eh_frame" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 677 | COFF::IMAGE_SCN_MEM_READ); |
| 678 | |
| 679 | // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is |
| 680 | // used to indicate to the linker that the text segment contains thumb instructions |
| 681 | // and to set the ISA selection bit for calls accordingly. |
| 682 | const bool IsThumb = T.getArch() == Triple::thumb; |
| 683 | |
| 684 | // COFF |
| 685 | BSSSection = Ctx->getCOFFSection( |
| 686 | Section: ".bss" , Characteristics: COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | |
| 687 | COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE); |
| 688 | TextSection = Ctx->getCOFFSection( |
| 689 | Section: ".text" , |
| 690 | Characteristics: (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) | |
| 691 | COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE | |
| 692 | COFF::IMAGE_SCN_MEM_READ); |
| 693 | DataSection = Ctx->getCOFFSection( |
| 694 | Section: ".data" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | |
| 695 | COFF::IMAGE_SCN_MEM_WRITE); |
| 696 | ReadOnlySection = |
| 697 | Ctx->getCOFFSection(Section: ".rdata" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 698 | COFF::IMAGE_SCN_MEM_READ); |
| 699 | |
| 700 | if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 || |
| 701 | T.getArch() == Triple::arm || T.getArch() == Triple::thumb) { |
| 702 | // On Windows with SEH, the LSDA is emitted into the .xdata section |
| 703 | LSDASection = nullptr; |
| 704 | } else { |
| 705 | LSDASection = Ctx->getCOFFSection(Section: ".gcc_except_table" , |
| 706 | Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 707 | COFF::IMAGE_SCN_MEM_READ); |
| 708 | } |
| 709 | |
| 710 | if (T.getArch() == Triple::aarch64) { |
| 711 | ImportCallSection = |
| 712 | Ctx->getCOFFSection(Section: ".impcall" , Characteristics: COFF::IMAGE_SCN_LNK_INFO); |
| 713 | } else if (T.getArch() == Triple::x86_64) { |
| 714 | // Import Call Optimization on x64 leverages the same metadata as the |
| 715 | // retpoline mitigation, hence the unusual section name. |
| 716 | ImportCallSection = |
| 717 | Ctx->getCOFFSection(Section: ".retplne" , Characteristics: COFF::IMAGE_SCN_LNK_INFO); |
| 718 | } |
| 719 | |
| 720 | // Debug info. |
| 721 | COFFDebugSymbolsSection = |
| 722 | Ctx->getCOFFSection(Section: ".debug$S" , Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 723 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 724 | COFF::IMAGE_SCN_MEM_READ)); |
| 725 | COFFDebugTypesSection = |
| 726 | Ctx->getCOFFSection(Section: ".debug$T" , Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 727 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 728 | COFF::IMAGE_SCN_MEM_READ)); |
| 729 | COFFGlobalTypeHashesSection = |
| 730 | Ctx->getCOFFSection(Section: ".debug$H" , Characteristics: (COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 731 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 732 | COFF::IMAGE_SCN_MEM_READ)); |
| 733 | |
| 734 | DwarfAbbrevSection = Ctx->getCOFFSection( |
| 735 | Section: ".debug_abbrev" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 736 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 737 | COFF::IMAGE_SCN_MEM_READ); |
| 738 | DwarfInfoSection = Ctx->getCOFFSection( |
| 739 | Section: ".debug_info" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 740 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 741 | COFF::IMAGE_SCN_MEM_READ); |
| 742 | DwarfLineSection = Ctx->getCOFFSection( |
| 743 | Section: ".debug_line" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 744 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 745 | COFF::IMAGE_SCN_MEM_READ); |
| 746 | DwarfLineStrSection = Ctx->getCOFFSection( |
| 747 | Section: ".debug_line_str" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 748 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 749 | COFF::IMAGE_SCN_MEM_READ); |
| 750 | DwarfFrameSection = Ctx->getCOFFSection( |
| 751 | Section: ".debug_frame" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 752 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 753 | COFF::IMAGE_SCN_MEM_READ); |
| 754 | DwarfPubNamesSection = Ctx->getCOFFSection( |
| 755 | Section: ".debug_pubnames" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 756 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 757 | COFF::IMAGE_SCN_MEM_READ); |
| 758 | DwarfPubTypesSection = Ctx->getCOFFSection( |
| 759 | Section: ".debug_pubtypes" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 760 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 761 | COFF::IMAGE_SCN_MEM_READ); |
| 762 | DwarfGnuPubNamesSection = Ctx->getCOFFSection( |
| 763 | Section: ".debug_gnu_pubnames" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 764 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 765 | COFF::IMAGE_SCN_MEM_READ); |
| 766 | DwarfGnuPubTypesSection = Ctx->getCOFFSection( |
| 767 | Section: ".debug_gnu_pubtypes" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 768 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 769 | COFF::IMAGE_SCN_MEM_READ); |
| 770 | DwarfStrSection = Ctx->getCOFFSection( |
| 771 | Section: ".debug_str" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 772 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 773 | COFF::IMAGE_SCN_MEM_READ); |
| 774 | DwarfStrOffSection = Ctx->getCOFFSection( |
| 775 | Section: ".debug_str_offsets" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 776 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 777 | COFF::IMAGE_SCN_MEM_READ); |
| 778 | DwarfLocSection = Ctx->getCOFFSection( |
| 779 | Section: ".debug_loc" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 780 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 781 | COFF::IMAGE_SCN_MEM_READ); |
| 782 | DwarfLoclistsSection = Ctx->getCOFFSection( |
| 783 | Section: ".debug_loclists" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 784 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 785 | COFF::IMAGE_SCN_MEM_READ); |
| 786 | DwarfARangesSection = Ctx->getCOFFSection( |
| 787 | Section: ".debug_aranges" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 788 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 789 | COFF::IMAGE_SCN_MEM_READ); |
| 790 | DwarfRangesSection = Ctx->getCOFFSection( |
| 791 | Section: ".debug_ranges" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 792 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 793 | COFF::IMAGE_SCN_MEM_READ); |
| 794 | DwarfRnglistsSection = Ctx->getCOFFSection( |
| 795 | Section: ".debug_rnglists" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 796 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 797 | COFF::IMAGE_SCN_MEM_READ); |
| 798 | DwarfMacinfoSection = Ctx->getCOFFSection( |
| 799 | Section: ".debug_macinfo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 800 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 801 | COFF::IMAGE_SCN_MEM_READ); |
| 802 | DwarfMacroSection = Ctx->getCOFFSection( |
| 803 | Section: ".debug_macro" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 804 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 805 | COFF::IMAGE_SCN_MEM_READ); |
| 806 | DwarfMacinfoDWOSection = Ctx->getCOFFSection( |
| 807 | Section: ".debug_macinfo.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 808 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 809 | COFF::IMAGE_SCN_MEM_READ); |
| 810 | DwarfMacroDWOSection = Ctx->getCOFFSection( |
| 811 | Section: ".debug_macro.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 812 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 813 | COFF::IMAGE_SCN_MEM_READ); |
| 814 | DwarfInfoDWOSection = Ctx->getCOFFSection( |
| 815 | Section: ".debug_info.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 816 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 817 | COFF::IMAGE_SCN_MEM_READ); |
| 818 | DwarfTypesDWOSection = Ctx->getCOFFSection( |
| 819 | Section: ".debug_types.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 820 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 821 | COFF::IMAGE_SCN_MEM_READ); |
| 822 | DwarfAbbrevDWOSection = Ctx->getCOFFSection( |
| 823 | Section: ".debug_abbrev.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 824 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 825 | COFF::IMAGE_SCN_MEM_READ); |
| 826 | DwarfStrDWOSection = Ctx->getCOFFSection( |
| 827 | Section: ".debug_str.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 828 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 829 | COFF::IMAGE_SCN_MEM_READ); |
| 830 | DwarfLineDWOSection = Ctx->getCOFFSection( |
| 831 | Section: ".debug_line.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 832 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 833 | COFF::IMAGE_SCN_MEM_READ); |
| 834 | DwarfLocDWOSection = Ctx->getCOFFSection( |
| 835 | Section: ".debug_loc.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 836 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 837 | COFF::IMAGE_SCN_MEM_READ); |
| 838 | DwarfLoclistsDWOSection = Ctx->getCOFFSection( |
| 839 | Section: ".debug_loclists.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 840 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 841 | COFF::IMAGE_SCN_MEM_READ); |
| 842 | DwarfStrOffDWOSection = Ctx->getCOFFSection( |
| 843 | Section: ".debug_str_offsets.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 844 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 845 | COFF::IMAGE_SCN_MEM_READ); |
| 846 | DwarfRnglistsDWOSection = Ctx->getCOFFSection( |
| 847 | Section: ".debug_rnglists.dwo" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 848 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 849 | COFF::IMAGE_SCN_MEM_READ); |
| 850 | DwarfAddrSection = Ctx->getCOFFSection( |
| 851 | Section: ".debug_addr" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 852 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 853 | COFF::IMAGE_SCN_MEM_READ); |
| 854 | DwarfCUIndexSection = Ctx->getCOFFSection( |
| 855 | Section: ".debug_cu_index" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 856 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 857 | COFF::IMAGE_SCN_MEM_READ); |
| 858 | DwarfTUIndexSection = Ctx->getCOFFSection( |
| 859 | Section: ".debug_tu_index" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 860 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 861 | COFF::IMAGE_SCN_MEM_READ); |
| 862 | DwarfDebugNamesSection = Ctx->getCOFFSection( |
| 863 | Section: ".debug_names" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 864 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 865 | COFF::IMAGE_SCN_MEM_READ); |
| 866 | DwarfAccelNamesSection = Ctx->getCOFFSection( |
| 867 | Section: ".apple_names" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 868 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 869 | COFF::IMAGE_SCN_MEM_READ); |
| 870 | DwarfAccelNamespaceSection = Ctx->getCOFFSection( |
| 871 | Section: ".apple_namespaces" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 872 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 873 | COFF::IMAGE_SCN_MEM_READ); |
| 874 | DwarfAccelTypesSection = Ctx->getCOFFSection( |
| 875 | Section: ".apple_types" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 876 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 877 | COFF::IMAGE_SCN_MEM_READ); |
| 878 | DwarfAccelObjCSection = Ctx->getCOFFSection( |
| 879 | Section: ".apple_objc" , Characteristics: COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 880 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 881 | COFF::IMAGE_SCN_MEM_READ); |
| 882 | |
| 883 | DrectveSection = Ctx->getCOFFSection( |
| 884 | Section: ".drectve" , Characteristics: COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE); |
| 885 | |
| 886 | PDataSection = |
| 887 | Ctx->getCOFFSection(Section: ".pdata" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 888 | COFF::IMAGE_SCN_MEM_READ); |
| 889 | |
| 890 | XDataSection = |
| 891 | Ctx->getCOFFSection(Section: ".xdata" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 892 | COFF::IMAGE_SCN_MEM_READ); |
| 893 | |
| 894 | SXDataSection = Ctx->getCOFFSection(Section: ".sxdata" , Characteristics: COFF::IMAGE_SCN_LNK_INFO); |
| 895 | |
| 896 | GEHContSection = |
| 897 | Ctx->getCOFFSection(Section: ".gehcont$y" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 898 | COFF::IMAGE_SCN_MEM_READ); |
| 899 | |
| 900 | GFIDsSection = |
| 901 | Ctx->getCOFFSection(Section: ".gfids$y" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 902 | COFF::IMAGE_SCN_MEM_READ); |
| 903 | |
| 904 | GIATsSection = |
| 905 | Ctx->getCOFFSection(Section: ".giats$y" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 906 | COFF::IMAGE_SCN_MEM_READ); |
| 907 | |
| 908 | GLJMPSection = |
| 909 | Ctx->getCOFFSection(Section: ".gljmp$y" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 910 | COFF::IMAGE_SCN_MEM_READ); |
| 911 | |
| 912 | TLSDataSection = Ctx->getCOFFSection( |
| 913 | Section: ".tls$" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | |
| 914 | COFF::IMAGE_SCN_MEM_WRITE); |
| 915 | |
| 916 | StackMapSection = Ctx->getCOFFSection(Section: ".llvm_stackmaps" , |
| 917 | Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 918 | COFF::IMAGE_SCN_MEM_READ); |
| 919 | |
| 920 | // Set IMAGE_SCN_MEM_DISCARDABLE so that lld will not truncate section name. |
| 921 | PseudoProbeSection = Ctx->getCOFFSection( |
| 922 | Section: ".pseudo_probe" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 923 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 924 | COFF::IMAGE_SCN_MEM_READ); |
| 925 | PseudoProbeDescSection = Ctx->getCOFFSection( |
| 926 | Section: ".pseudo_probe_desc" , Characteristics: COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | |
| 927 | COFF::IMAGE_SCN_MEM_DISCARDABLE | |
| 928 | COFF::IMAGE_SCN_MEM_READ); |
| 929 | } |
| 930 | |
| 931 | void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) { |
| 932 | // Put everything in a single binary section. |
| 933 | TextSection = Ctx->getSPIRVSection(); |
| 934 | } |
| 935 | |
| 936 | void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) { |
| 937 | TextSection = Ctx->getWasmSection(Section: ".text" , K: SectionKind::getText()); |
| 938 | DataSection = Ctx->getWasmSection(Section: ".data" , K: SectionKind::getData()); |
| 939 | |
| 940 | DwarfLineSection = |
| 941 | Ctx->getWasmSection(Section: ".debug_line" , K: SectionKind::getMetadata()); |
| 942 | DwarfLineStrSection = |
| 943 | Ctx->getWasmSection(Section: ".debug_line_str" , K: SectionKind::getMetadata(), |
| 944 | Flags: wasm::WASM_SEG_FLAG_STRINGS); |
| 945 | DwarfStrSection = Ctx->getWasmSection( |
| 946 | Section: ".debug_str" , K: SectionKind::getMetadata(), Flags: wasm::WASM_SEG_FLAG_STRINGS); |
| 947 | DwarfLocSection = |
| 948 | Ctx->getWasmSection(Section: ".debug_loc" , K: SectionKind::getMetadata()); |
| 949 | DwarfAbbrevSection = |
| 950 | Ctx->getWasmSection(Section: ".debug_abbrev" , K: SectionKind::getMetadata()); |
| 951 | DwarfARangesSection = Ctx->getWasmSection(Section: ".debug_aranges" , K: SectionKind::getMetadata()); |
| 952 | DwarfRangesSection = |
| 953 | Ctx->getWasmSection(Section: ".debug_ranges" , K: SectionKind::getMetadata()); |
| 954 | DwarfMacinfoSection = |
| 955 | Ctx->getWasmSection(Section: ".debug_macinfo" , K: SectionKind::getMetadata()); |
| 956 | DwarfMacroSection = |
| 957 | Ctx->getWasmSection(Section: ".debug_macro" , K: SectionKind::getMetadata()); |
| 958 | DwarfCUIndexSection = Ctx->getWasmSection(Section: ".debug_cu_index" , K: SectionKind::getMetadata()); |
| 959 | DwarfTUIndexSection = Ctx->getWasmSection(Section: ".debug_tu_index" , K: SectionKind::getMetadata()); |
| 960 | DwarfInfoSection = |
| 961 | Ctx->getWasmSection(Section: ".debug_info" , K: SectionKind::getMetadata()); |
| 962 | DwarfFrameSection = Ctx->getWasmSection(Section: ".debug_frame" , K: SectionKind::getMetadata()); |
| 963 | DwarfPubNamesSection = Ctx->getWasmSection(Section: ".debug_pubnames" , K: SectionKind::getMetadata()); |
| 964 | DwarfPubTypesSection = Ctx->getWasmSection(Section: ".debug_pubtypes" , K: SectionKind::getMetadata()); |
| 965 | DwarfGnuPubNamesSection = |
| 966 | Ctx->getWasmSection(Section: ".debug_gnu_pubnames" , K: SectionKind::getMetadata()); |
| 967 | DwarfGnuPubTypesSection = |
| 968 | Ctx->getWasmSection(Section: ".debug_gnu_pubtypes" , K: SectionKind::getMetadata()); |
| 969 | |
| 970 | DwarfDebugNamesSection = |
| 971 | Ctx->getWasmSection(Section: ".debug_names" , K: SectionKind::getMetadata()); |
| 972 | DwarfStrOffSection = |
| 973 | Ctx->getWasmSection(Section: ".debug_str_offsets" , K: SectionKind::getMetadata()); |
| 974 | DwarfAddrSection = |
| 975 | Ctx->getWasmSection(Section: ".debug_addr" , K: SectionKind::getMetadata()); |
| 976 | DwarfRnglistsSection = |
| 977 | Ctx->getWasmSection(Section: ".debug_rnglists" , K: SectionKind::getMetadata()); |
| 978 | DwarfLoclistsSection = |
| 979 | Ctx->getWasmSection(Section: ".debug_loclists" , K: SectionKind::getMetadata()); |
| 980 | |
| 981 | // Fission Sections |
| 982 | DwarfInfoDWOSection = |
| 983 | Ctx->getWasmSection(Section: ".debug_info.dwo" , K: SectionKind::getMetadata()); |
| 984 | DwarfTypesDWOSection = |
| 985 | Ctx->getWasmSection(Section: ".debug_types.dwo" , K: SectionKind::getMetadata()); |
| 986 | DwarfAbbrevDWOSection = |
| 987 | Ctx->getWasmSection(Section: ".debug_abbrev.dwo" , K: SectionKind::getMetadata()); |
| 988 | DwarfStrDWOSection = |
| 989 | Ctx->getWasmSection(Section: ".debug_str.dwo" , K: SectionKind::getMetadata(), |
| 990 | Flags: wasm::WASM_SEG_FLAG_STRINGS); |
| 991 | DwarfLineDWOSection = |
| 992 | Ctx->getWasmSection(Section: ".debug_line.dwo" , K: SectionKind::getMetadata()); |
| 993 | DwarfLocDWOSection = |
| 994 | Ctx->getWasmSection(Section: ".debug_loc.dwo" , K: SectionKind::getMetadata()); |
| 995 | DwarfStrOffDWOSection = |
| 996 | Ctx->getWasmSection(Section: ".debug_str_offsets.dwo" , K: SectionKind::getMetadata()); |
| 997 | DwarfRnglistsDWOSection = |
| 998 | Ctx->getWasmSection(Section: ".debug_rnglists.dwo" , K: SectionKind::getMetadata()); |
| 999 | DwarfMacinfoDWOSection = |
| 1000 | Ctx->getWasmSection(Section: ".debug_macinfo.dwo" , K: SectionKind::getMetadata()); |
| 1001 | DwarfMacroDWOSection = |
| 1002 | Ctx->getWasmSection(Section: ".debug_macro.dwo" , K: SectionKind::getMetadata()); |
| 1003 | |
| 1004 | DwarfLoclistsDWOSection = |
| 1005 | Ctx->getWasmSection(Section: ".debug_loclists.dwo" , K: SectionKind::getMetadata()); |
| 1006 | |
| 1007 | // DWP Sections |
| 1008 | DwarfCUIndexSection = |
| 1009 | Ctx->getWasmSection(Section: ".debug_cu_index" , K: SectionKind::getMetadata()); |
| 1010 | DwarfTUIndexSection = |
| 1011 | Ctx->getWasmSection(Section: ".debug_tu_index" , K: SectionKind::getMetadata()); |
| 1012 | |
| 1013 | // Wasm use data section for LSDA. |
| 1014 | // TODO Consider putting each function's exception table in a separate |
| 1015 | // section, as in -function-sections, to facilitate lld's --gc-section. |
| 1016 | LSDASection = Ctx->getWasmSection(Section: ".rodata.gcc_except_table" , |
| 1017 | K: SectionKind::getReadOnlyWithRel()); |
| 1018 | |
| 1019 | // TODO: Define more sections. |
| 1020 | } |
| 1021 | |
| 1022 | void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) { |
| 1023 | // The default csect for program code. Functions without a specified section |
| 1024 | // get placed into this csect. The choice of csect name is not a property of |
| 1025 | // the ABI or object file format, but various tools rely on the section |
| 1026 | // name being empty (considering named symbols to be "user symbol names"). |
| 1027 | TextSection = Ctx->getXCOFFSection( |
| 1028 | Section: "..text.." , // Use a non-null name to work around an AIX assembler bug... |
| 1029 | K: SectionKind::getText(), |
| 1030 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD), |
| 1031 | /* MultiSymbolsAllowed*/ true); |
| 1032 | |
| 1033 | // ... but use a null name when generating the symbol table. |
| 1034 | MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection); |
| 1035 | TS->getQualNameSymbol()->setSymbolTableName("" ); |
| 1036 | TS->setSymbolTableName("" ); |
| 1037 | |
| 1038 | DataSection = Ctx->getXCOFFSection( |
| 1039 | Section: ".data" , K: SectionKind::getData(), |
| 1040 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD), |
| 1041 | /* MultiSymbolsAllowed*/ true); |
| 1042 | |
| 1043 | ReadOnlySection = Ctx->getXCOFFSection( |
| 1044 | Section: ".rodata" , K: SectionKind::getReadOnly(), |
| 1045 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), |
| 1046 | /* MultiSymbolsAllowed*/ true); |
| 1047 | ReadOnlySection->setAlignment(Align(4)); |
| 1048 | |
| 1049 | ReadOnly8Section = Ctx->getXCOFFSection( |
| 1050 | Section: ".rodata.8" , K: SectionKind::getReadOnly(), |
| 1051 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), |
| 1052 | /* MultiSymbolsAllowed*/ true); |
| 1053 | ReadOnly8Section->setAlignment(Align(8)); |
| 1054 | |
| 1055 | ReadOnly16Section = Ctx->getXCOFFSection( |
| 1056 | Section: ".rodata.16" , K: SectionKind::getReadOnly(), |
| 1057 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), |
| 1058 | /* MultiSymbolsAllowed*/ true); |
| 1059 | ReadOnly16Section->setAlignment(Align(16)); |
| 1060 | |
| 1061 | TLSDataSection = Ctx->getXCOFFSection( |
| 1062 | Section: ".tdata" , K: SectionKind::getThreadData(), |
| 1063 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD), |
| 1064 | /* MultiSymbolsAllowed*/ true); |
| 1065 | |
| 1066 | TOCBaseSection = Ctx->getXCOFFSection( |
| 1067 | Section: "TOC" , K: SectionKind::getData(), |
| 1068 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0, |
| 1069 | XCOFF::XTY_SD)); |
| 1070 | |
| 1071 | // The TOC-base always has 0 size, but 4 byte alignment. |
| 1072 | TOCBaseSection->setAlignment(Align(4)); |
| 1073 | |
| 1074 | LSDASection = Ctx->getXCOFFSection( |
| 1075 | Section: ".gcc_except_table" , K: SectionKind::getReadOnly(), |
| 1076 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, |
| 1077 | XCOFF::XTY_SD)); |
| 1078 | |
| 1079 | CompactUnwindSection = Ctx->getXCOFFSection( |
| 1080 | Section: ".eh_info_table" , K: SectionKind::getData(), |
| 1081 | CsectProp: XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, |
| 1082 | XCOFF::XTY_SD)); |
| 1083 | |
| 1084 | // DWARF sections for XCOFF are not csects. They are special STYP_DWARF |
| 1085 | // sections, and the individual DWARF sections are distinguished by their |
| 1086 | // section subtype. |
| 1087 | DwarfAbbrevSection = Ctx->getXCOFFSection( |
| 1088 | Section: ".dwabrev" , K: SectionKind::getMetadata(), |
| 1089 | /* CsectProperties */ CsectProp: std::nullopt, |
| 1090 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWABREV); |
| 1091 | |
| 1092 | DwarfInfoSection = Ctx->getXCOFFSection( |
| 1093 | Section: ".dwinfo" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
| 1094 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWINFO); |
| 1095 | |
| 1096 | DwarfLineSection = Ctx->getXCOFFSection( |
| 1097 | Section: ".dwline" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
| 1098 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLINE); |
| 1099 | |
| 1100 | DwarfFrameSection = Ctx->getXCOFFSection( |
| 1101 | Section: ".dwframe" , K: SectionKind::getMetadata(), |
| 1102 | /* CsectProperties */ CsectProp: std::nullopt, |
| 1103 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWFRAME); |
| 1104 | |
| 1105 | DwarfPubNamesSection = Ctx->getXCOFFSection( |
| 1106 | Section: ".dwpbnms" , K: SectionKind::getMetadata(), |
| 1107 | /* CsectProperties */ CsectProp: std::nullopt, |
| 1108 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBNMS); |
| 1109 | |
| 1110 | DwarfPubTypesSection = Ctx->getXCOFFSection( |
| 1111 | Section: ".dwpbtyp" , K: SectionKind::getMetadata(), |
| 1112 | /* CsectProperties */ CsectProp: std::nullopt, |
| 1113 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWPBTYP); |
| 1114 | |
| 1115 | DwarfStrSection = Ctx->getXCOFFSection( |
| 1116 | Section: ".dwstr" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
| 1117 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWSTR); |
| 1118 | |
| 1119 | DwarfLocSection = Ctx->getXCOFFSection( |
| 1120 | Section: ".dwloc" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
| 1121 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWLOC); |
| 1122 | |
| 1123 | DwarfARangesSection = Ctx->getXCOFFSection( |
| 1124 | Section: ".dwarnge" , K: SectionKind::getMetadata(), |
| 1125 | /* CsectProperties */ CsectProp: std::nullopt, |
| 1126 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWARNGE); |
| 1127 | |
| 1128 | DwarfRangesSection = Ctx->getXCOFFSection( |
| 1129 | Section: ".dwrnges" , K: SectionKind::getMetadata(), |
| 1130 | /* CsectProperties */ CsectProp: std::nullopt, |
| 1131 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWRNGES); |
| 1132 | |
| 1133 | DwarfMacinfoSection = Ctx->getXCOFFSection( |
| 1134 | Section: ".dwmac" , K: SectionKind::getMetadata(), /* CsectProperties */ CsectProp: std::nullopt, |
| 1135 | /* MultiSymbolsAllowed */ true, DwarfSubtypeFlags: XCOFF::SSUBTYP_DWMAC); |
| 1136 | } |
| 1137 | |
| 1138 | void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) { |
| 1139 | // At the moment the DXBC section should end up empty. |
| 1140 | TextSection = Ctx->getDXContainerSection(Section: "DXBC" , K: SectionKind::getText()); |
| 1141 | } |
| 1142 | |
| 1143 | MCObjectFileInfo::~MCObjectFileInfo() = default; |
| 1144 | |
| 1145 | void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC, |
| 1146 | bool LargeCodeModel) { |
| 1147 | PositionIndependent = PIC; |
| 1148 | Ctx = &MCCtx; |
| 1149 | |
| 1150 | // Common. |
| 1151 | SupportsCompactUnwindWithoutEHFrame = false; |
| 1152 | OmitDwarfIfHaveCompactUnwind = false; |
| 1153 | |
| 1154 | FDECFIEncoding = dwarf::DW_EH_PE_absptr; |
| 1155 | |
| 1156 | CompactUnwindDwarfEHFrameOnly = 0; |
| 1157 | |
| 1158 | EHFrameSection = nullptr; // Created on demand. |
| 1159 | SFrameSection = nullptr; // Created on demand. |
| 1160 | CompactUnwindSection = nullptr; // Used only by selected targets. |
| 1161 | DwarfAccelNamesSection = nullptr; // Used only by selected targets. |
| 1162 | DwarfAccelObjCSection = nullptr; // Used only by selected targets. |
| 1163 | DwarfAccelNamespaceSection = nullptr; // Used only by selected targets. |
| 1164 | DwarfAccelTypesSection = nullptr; // Used only by selected targets. |
| 1165 | |
| 1166 | const Triple &TheTriple = Ctx->getTargetTriple(); |
| 1167 | switch (Ctx->getObjectFileType()) { |
| 1168 | case MCContext::IsMachO: |
| 1169 | initMachOMCObjectFileInfo(T: TheTriple); |
| 1170 | break; |
| 1171 | case MCContext::IsCOFF: |
| 1172 | initCOFFMCObjectFileInfo(T: TheTriple); |
| 1173 | break; |
| 1174 | case MCContext::IsELF: |
| 1175 | initELFMCObjectFileInfo(T: TheTriple, Large: LargeCodeModel); |
| 1176 | break; |
| 1177 | case MCContext::IsGOFF: |
| 1178 | initGOFFMCObjectFileInfo(T: TheTriple); |
| 1179 | break; |
| 1180 | case MCContext::IsSPIRV: |
| 1181 | initSPIRVMCObjectFileInfo(T: TheTriple); |
| 1182 | break; |
| 1183 | case MCContext::IsWasm: |
| 1184 | initWasmMCObjectFileInfo(T: TheTriple); |
| 1185 | break; |
| 1186 | case MCContext::IsXCOFF: |
| 1187 | initXCOFFMCObjectFileInfo(T: TheTriple); |
| 1188 | break; |
| 1189 | case MCContext::IsDXContainer: |
| 1190 | initDXContainerObjectFileInfo(T: TheTriple); |
| 1191 | break; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, |
| 1196 | uint64_t Hash) const { |
| 1197 | switch (Ctx->getTargetTriple().getObjectFormat()) { |
| 1198 | case Triple::ELF: |
| 1199 | return Ctx->getELFSection(Section: Name, Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_GROUP, EntrySize: 0, |
| 1200 | Group: utostr(X: Hash), /*IsComdat=*/true); |
| 1201 | case Triple::Wasm: |
| 1202 | return Ctx->getWasmSection(Section: Name, K: SectionKind::getMetadata(), Flags: 0, |
| 1203 | Group: utostr(X: Hash), UniqueID: MCSection::NonUniqueID); |
| 1204 | case Triple::MachO: |
| 1205 | case Triple::COFF: |
| 1206 | case Triple::GOFF: |
| 1207 | case Triple::SPIRV: |
| 1208 | case Triple::XCOFF: |
| 1209 | case Triple::DXContainer: |
| 1210 | case Triple::UnknownObjectFormat: |
| 1211 | report_fatal_error(reason: "Cannot get DWARF comdat section for this object file " |
| 1212 | "format: not implemented." ); |
| 1213 | break; |
| 1214 | } |
| 1215 | llvm_unreachable("Unknown ObjectFormatType" ); |
| 1216 | } |
| 1217 | |
| 1218 | MCSection * |
| 1219 | MCObjectFileInfo::getCallGraphSection(const MCSection &TextSec) const { |
| 1220 | if (Ctx->getObjectFileType() != MCContext::IsELF) |
| 1221 | return CallGraphSection; |
| 1222 | |
| 1223 | const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); |
| 1224 | unsigned Flags = ELF::SHF_LINK_ORDER; |
| 1225 | StringRef GroupName; |
| 1226 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
| 1227 | GroupName = Group->getName(); |
| 1228 | Flags |= ELF::SHF_GROUP; |
| 1229 | } |
| 1230 | |
| 1231 | return Ctx->getELFSection( |
| 1232 | Section: ".llvm.callgraph" , Type: ELF::SHT_LLVM_CALL_GRAPH, Flags, EntrySize: 0, Group: GroupName, |
| 1233 | /*IsComdat=*/true, UniqueID: ElfSec.getUniqueID(), |
| 1234 | LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol())); |
| 1235 | } |
| 1236 | |
| 1237 | MCSection * |
| 1238 | MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const { |
| 1239 | if ((Ctx->getObjectFileType() != MCContext::IsELF) || |
| 1240 | Ctx->getTargetTriple().isPS4()) |
| 1241 | return StackSizesSection; |
| 1242 | |
| 1243 | const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); |
| 1244 | unsigned Flags = ELF::SHF_LINK_ORDER; |
| 1245 | StringRef GroupName; |
| 1246 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
| 1247 | GroupName = Group->getName(); |
| 1248 | Flags |= ELF::SHF_GROUP; |
| 1249 | } |
| 1250 | |
| 1251 | return Ctx->getELFSection( |
| 1252 | Section: ".stack_sizes" , Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, IsComdat: true, |
| 1253 | UniqueID: ElfSec.getUniqueID(), |
| 1254 | LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol())); |
| 1255 | } |
| 1256 | |
| 1257 | MCSection * |
| 1258 | MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const { |
| 1259 | if (Ctx->getObjectFileType() != MCContext::IsELF) |
| 1260 | return nullptr; |
| 1261 | |
| 1262 | const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); |
| 1263 | unsigned Flags = ELF::SHF_LINK_ORDER; |
| 1264 | StringRef GroupName; |
| 1265 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
| 1266 | GroupName = Group->getName(); |
| 1267 | Flags |= ELF::SHF_GROUP; |
| 1268 | } |
| 1269 | |
| 1270 | // Use the text section's begin symbol and unique ID to create a separate |
| 1271 | // .llvm_bb_addr_map section associated with every unique text section. |
| 1272 | return Ctx->getELFSection( |
| 1273 | Section: ".llvm_bb_addr_map" , Type: ELF::SHT_LLVM_BB_ADDR_MAP, Flags, EntrySize: 0, Group: GroupName, IsComdat: true, |
| 1274 | UniqueID: ElfSec.getUniqueID(), |
| 1275 | LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol())); |
| 1276 | } |
| 1277 | |
| 1278 | MCSection * |
| 1279 | MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const { |
| 1280 | if (Ctx->getObjectFileType() != MCContext::IsELF) |
| 1281 | return nullptr; |
| 1282 | |
| 1283 | const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); |
| 1284 | unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC; |
| 1285 | StringRef GroupName; |
| 1286 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
| 1287 | GroupName = Group->getName(); |
| 1288 | Flags |= ELF::SHF_GROUP; |
| 1289 | } |
| 1290 | |
| 1291 | return Ctx->getELFSection( |
| 1292 | Section: ".kcfi_traps" , Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, |
| 1293 | /*IsComdat=*/true, UniqueID: ElfSec.getUniqueID(), |
| 1294 | LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol())); |
| 1295 | } |
| 1296 | |
| 1297 | MCSection * |
| 1298 | MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const { |
| 1299 | auto ObjFileType = Ctx->getObjectFileType(); |
| 1300 | if (ObjFileType == MCContext::IsELF) { |
| 1301 | const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec); |
| 1302 | unsigned Flags = ELF::SHF_LINK_ORDER; |
| 1303 | StringRef GroupName; |
| 1304 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
| 1305 | GroupName = Group->getName(); |
| 1306 | Flags |= ELF::SHF_GROUP; |
| 1307 | } |
| 1308 | return Ctx->getELFSection( |
| 1309 | Section: PseudoProbeSection->getName(), Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, |
| 1310 | IsComdat: true, UniqueID: ElfSec.getUniqueID(), |
| 1311 | LinkedToSym: static_cast<const MCSymbolELF *>(TextSec.getBeginSymbol())); |
| 1312 | } else if (ObjFileType == MCContext::IsCOFF) { |
| 1313 | StringRef COMDATSymName = "" ; |
| 1314 | int Selection = 0; |
| 1315 | unsigned Characteristics = |
| 1316 | static_cast<MCSectionCOFF *>(PseudoProbeSection)->getCharacteristics(); |
| 1317 | const auto &COFFSec = static_cast<const MCSectionCOFF &>(TextSec); |
| 1318 | if (const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) { |
| 1319 | // Associate .pseudo_probe to its function section. |
| 1320 | COMDATSymName = COMDATSym->getName(); |
| 1321 | Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; |
| 1322 | Selection = COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE; |
| 1323 | } |
| 1324 | return Ctx->getCOFFSection(Section: PseudoProbeSection->getName(), Characteristics, |
| 1325 | COMDATSymName, Selection, UniqueID: COFFSec.getUniqueID()); |
| 1326 | } |
| 1327 | |
| 1328 | return PseudoProbeSection; |
| 1329 | } |
| 1330 | |
| 1331 | MCSection * |
| 1332 | MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const { |
| 1333 | if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty()) |
| 1334 | return PseudoProbeDescSection; |
| 1335 | |
| 1336 | // Create a separate comdat group for each function's descriptor in order |
| 1337 | // for the linker to deduplicate. The duplication, must be from different |
| 1338 | // tranlation unit, can come from: |
| 1339 | // 1. Inline functions defined in header files; |
| 1340 | // 2. ThinLTO imported funcions; |
| 1341 | // 3. Weak-linkage definitions. |
| 1342 | // Use a concatenation of the section name and the function name as the |
| 1343 | // group name so that descriptor-only groups won't be folded with groups of |
| 1344 | // code. |
| 1345 | auto ObjFileType = Ctx->getObjectFileType(); |
| 1346 | if (ObjFileType == MCContext::IsELF) { |
| 1347 | auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection); |
| 1348 | auto Flags = S->getFlags() | ELF::SHF_GROUP; |
| 1349 | return Ctx->getELFSection(Section: S->getName(), Type: S->getType(), Flags, |
| 1350 | EntrySize: S->getEntrySize(), Group: S->getName() + "_" + FuncName, |
| 1351 | /*IsComdat=*/true); |
| 1352 | } else if (ObjFileType == MCContext::IsCOFF) { |
| 1353 | auto *S = static_cast<MCSectionCOFF *>(PseudoProbeDescSection); |
| 1354 | unsigned Characteristics = |
| 1355 | S->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT; |
| 1356 | std::string COMDATSymName = (S->getName() + "_" + FuncName).str(); |
| 1357 | return Ctx->getCOFFSection(Section: S->getName(), Characteristics, COMDATSymName, |
| 1358 | Selection: COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH); |
| 1359 | } |
| 1360 | |
| 1361 | return PseudoProbeDescSection; |
| 1362 | } |
| 1363 | |
| 1364 | MCSection *MCObjectFileInfo::getLLVMStatsSection() const { |
| 1365 | return LLVMStatsSection; |
| 1366 | } |
| 1367 | |
| 1368 | MCSection *MCObjectFileInfo::getPCSection(StringRef Name, |
| 1369 | const MCSection *TextSec) const { |
| 1370 | if (Ctx->getObjectFileType() != MCContext::IsELF) |
| 1371 | return nullptr; |
| 1372 | |
| 1373 | // SHF_WRITE for relocations, and let user post-process data in-place. |
| 1374 | unsigned Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER; |
| 1375 | |
| 1376 | if (!TextSec) |
| 1377 | TextSec = getTextSection(); |
| 1378 | |
| 1379 | StringRef GroupName; |
| 1380 | const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec); |
| 1381 | if (const MCSymbol *Group = ElfSec.getGroup()) { |
| 1382 | GroupName = Group->getName(); |
| 1383 | Flags |= ELF::SHF_GROUP; |
| 1384 | } |
| 1385 | return Ctx->getELFSection( |
| 1386 | Section: Name, Type: ELF::SHT_PROGBITS, Flags, EntrySize: 0, Group: GroupName, IsComdat: true, UniqueID: ElfSec.getUniqueID(), |
| 1387 | LinkedToSym: static_cast<const MCSymbolELF *>(TextSec->getBeginSymbol())); |
| 1388 | } |
| 1389 | |