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