LCOV - code coverage report
Current view: top level - lib/MC - MCObjectFileInfo.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 411 414 99.3 %
Date: 2018-06-17 00:07:59 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "llvm/MC/MCObjectFileInfo.h"
      11             : #include "llvm/ADT/StringExtras.h"
      12             : #include "llvm/ADT/Triple.h"
      13             : #include "llvm/BinaryFormat/COFF.h"
      14             : #include "llvm/BinaryFormat/ELF.h"
      15             : #include "llvm/MC/MCAsmInfo.h"
      16             : #include "llvm/MC/MCContext.h"
      17             : #include "llvm/MC/MCSection.h"
      18             : #include "llvm/MC/MCSectionCOFF.h"
      19             : #include "llvm/MC/MCSectionELF.h"
      20             : #include "llvm/MC/MCSectionMachO.h"
      21             : #include "llvm/MC/MCSectionWasm.h"
      22             : 
      23             : using namespace llvm;
      24             : 
      25        3393 : static bool useCompactUnwind(const Triple &T) {
      26             :   // Only on darwin.
      27             :   if (!T.isOSDarwin())
      28             :     return false;
      29             : 
      30             :   // aarch64 always has it.
      31        3313 :   if (T.getArch() == Triple::aarch64)
      32             :     return true;
      33             : 
      34             :   // armv7k always has it.
      35        2949 :   if (T.isWatchABI())
      36             :     return true;
      37             : 
      38             :   // Use it on newer version of OS X.
      39        2545 :   if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
      40             :     return true;
      41             : 
      42             :   // And the iOS simulator.
      43         373 :   if (T.isiOS() &&
      44         733 :       (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
      45             :     return true;
      46             : 
      47             :   return false;
      48             : }
      49             : 
      50        3393 : void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
      51             :   // MachO
      52        3393 :   SupportsWeakOmittedEHFrame = false;
      53             : 
      54        6786 :   EHFrameSection = Ctx->getMachOSection(
      55             :       "__TEXT", "__eh_frame",
      56             :       MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |
      57             :           MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,
      58             :       SectionKind::getReadOnly());
      59             : 
      60        3313 :   if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
      61         364 :     SupportsCompactUnwindWithoutEHFrame = true;
      62             : 
      63        3393 :   if (T.isWatchABI())
      64          25 :     OmitDwarfIfHaveCompactUnwind = true;
      65             : 
      66        3393 :   PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
      67             :     | dwarf::DW_EH_PE_sdata4;
      68        3393 :   LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
      69        3393 :   TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
      70             :     dwarf::DW_EH_PE_sdata4;
      71             : 
      72             :   // .comm doesn't support alignment before Leopard.
      73        2725 :   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
      74        1749 :     CommDirectiveSupportsAlignment = false;
      75             : 
      76             :   TextSection // .text
      77        6786 :     = Ctx->getMachOSection("__TEXT", "__text",
      78             :                            MachO::S_ATTR_PURE_INSTRUCTIONS,
      79             :                            SectionKind::getText());
      80             :   DataSection // .data
      81        6786 :       = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
      82             : 
      83             :   // BSSSection might not be expected initialized on msvc.
      84        3393 :   BSSSection = nullptr;
      85             : 
      86             :   TLSDataSection // .tdata
      87        6786 :       = Ctx->getMachOSection("__DATA", "__thread_data",
      88             :                              MachO::S_THREAD_LOCAL_REGULAR,
      89             :                              SectionKind::getData());
      90             :   TLSBSSSection // .tbss
      91        6786 :     = Ctx->getMachOSection("__DATA", "__thread_bss",
      92             :                            MachO::S_THREAD_LOCAL_ZEROFILL,
      93             :                            SectionKind::getThreadBSS());
      94             : 
      95             :   // TODO: Verify datarel below.
      96             :   TLSTLVSection // .tlv
      97        6786 :       = Ctx->getMachOSection("__DATA", "__thread_vars",
      98             :                              MachO::S_THREAD_LOCAL_VARIABLES,
      99             :                              SectionKind::getData());
     100             : 
     101        6786 :   TLSThreadInitSection = Ctx->getMachOSection(
     102             :       "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
     103             :       SectionKind::getData());
     104             : 
     105             :   CStringSection // .cstring
     106        6786 :     = Ctx->getMachOSection("__TEXT", "__cstring",
     107             :                            MachO::S_CSTRING_LITERALS,
     108             :                            SectionKind::getMergeable1ByteCString());
     109             :   UStringSection
     110        6786 :     = Ctx->getMachOSection("__TEXT","__ustring", 0,
     111             :                            SectionKind::getMergeable2ByteCString());
     112             :   FourByteConstantSection // .literal4
     113        6786 :     = Ctx->getMachOSection("__TEXT", "__literal4",
     114             :                            MachO::S_4BYTE_LITERALS,
     115             :                            SectionKind::getMergeableConst4());
     116             :   EightByteConstantSection // .literal8
     117        6786 :     = Ctx->getMachOSection("__TEXT", "__literal8",
     118             :                            MachO::S_8BYTE_LITERALS,
     119             :                            SectionKind::getMergeableConst8());
     120             : 
     121             :   SixteenByteConstantSection // .literal16
     122        6786 :       = Ctx->getMachOSection("__TEXT", "__literal16",
     123             :                              MachO::S_16BYTE_LITERALS,
     124             :                              SectionKind::getMergeableConst16());
     125             : 
     126             :   ReadOnlySection  // .const
     127        6786 :     = Ctx->getMachOSection("__TEXT", "__const", 0,
     128             :                            SectionKind::getReadOnly());
     129             : 
     130             :   // If the target is not powerpc, map the coal sections to the non-coal
     131             :   // sections.
     132             :   //
     133             :   // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
     134             :   // "__TEXT/__const_coal"  => section "__TEXT/__const"
     135             :   // "__DATA/__datacoal_nt" => section "__DATA/__data"
     136        3393 :   Triple::ArchType ArchTy = T.getArch();
     137             : 
     138             :   ConstDataSection  // .const_data
     139        6786 :     = Ctx->getMachOSection("__DATA", "__const", 0,
     140             :                            SectionKind::getReadOnlyWithRel());
     141             : 
     142        3393 :   if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {
     143             :     TextCoalSection
     144         328 :       = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
     145             :                              MachO::S_COALESCED |
     146             :                              MachO::S_ATTR_PURE_INSTRUCTIONS,
     147             :                              SectionKind::getText());
     148             :     ConstTextCoalSection
     149         328 :       = Ctx->getMachOSection("__TEXT", "__const_coal",
     150             :                              MachO::S_COALESCED,
     151             :                              SectionKind::getReadOnly());
     152         328 :     DataCoalSection = Ctx->getMachOSection(
     153             :         "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());
     154         164 :     ConstDataCoalSection = DataCoalSection;
     155             :   } else {
     156        3229 :     TextCoalSection = TextSection;
     157        3229 :     ConstTextCoalSection = ReadOnlySection;
     158        3229 :     DataCoalSection = DataSection;
     159        3229 :     ConstDataCoalSection = ConstDataSection;
     160             :   }
     161             : 
     162             :   DataCommonSection
     163        6786 :     = Ctx->getMachOSection("__DATA","__common",
     164             :                            MachO::S_ZEROFILL,
     165             :                            SectionKind::getBSS());
     166             :   DataBSSSection
     167        6786 :     = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
     168             :                            SectionKind::getBSS());
     169             : 
     170             : 
     171             :   LazySymbolPointerSection
     172        6786 :     = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
     173             :                            MachO::S_LAZY_SYMBOL_POINTERS,
     174             :                            SectionKind::getMetadata());
     175             :   NonLazySymbolPointerSection
     176        6786 :     = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
     177             :                            MachO::S_NON_LAZY_SYMBOL_POINTERS,
     178             :                            SectionKind::getMetadata());
     179             : 
     180             :   ThreadLocalPointerSection
     181        6786 :     = Ctx->getMachOSection("__DATA", "__thread_ptr",
     182             :                            MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
     183             :                            SectionKind::getMetadata());
     184             : 
     185             :   // Exception Handling.
     186        6786 :   LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
     187             :                                      SectionKind::getReadOnlyWithRel());
     188             : 
     189        3393 :   COFFDebugSymbolsSection = nullptr;
     190        3393 :   COFFDebugTypesSection = nullptr;
     191        3393 :   COFFGlobalTypeHashesSection = nullptr;
     192             : 
     193        3393 :   if (useCompactUnwind(T)) {
     194        1136 :     CompactUnwindSection =
     195        1136 :         Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
     196             :                              SectionKind::getReadOnly());
     197             : 
     198        1136 :     if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
     199         666 :       CompactUnwindDwarfEHFrameOnly = 0x04000000;  // UNWIND_X86_64_MODE_DWARF
     200         470 :     else if (T.getArch() == Triple::aarch64)
     201         364 :       CompactUnwindDwarfEHFrameOnly = 0x03000000;  // UNWIND_ARM64_MODE_DWARF
     202         106 :     else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
     203          98 :       CompactUnwindDwarfEHFrameOnly = 0x04000000;  // UNWIND_ARM_MODE_DWARF
     204             :   }
     205             : 
     206             :   // Debug Information.
     207        3393 :   DwarfDebugNamesSection =
     208        3393 :       Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
     209             :                            SectionKind::getMetadata(), "debug_names_begin");
     210        3393 :   DwarfAccelNamesSection =
     211        3393 :       Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
     212             :                            SectionKind::getMetadata(), "names_begin");
     213        3393 :   DwarfAccelObjCSection =
     214        3393 :       Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
     215             :                            SectionKind::getMetadata(), "objc_begin");
     216             :   // 16 character section limit...
     217        3393 :   DwarfAccelNamespaceSection =
     218        3393 :       Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
     219             :                            SectionKind::getMetadata(), "namespac_begin");
     220        3393 :   DwarfAccelTypesSection =
     221        3393 :       Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
     222             :                            SectionKind::getMetadata(), "types_begin");
     223             : 
     224        3393 :   DwarfSwiftASTSection =
     225        3393 :       Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
     226             :                            SectionKind::getMetadata());
     227             : 
     228        3393 :   DwarfAbbrevSection =
     229        3393 :       Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
     230             :                            SectionKind::getMetadata(), "section_abbrev");
     231        3393 :   DwarfInfoSection =
     232        3393 :       Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
     233             :                            SectionKind::getMetadata(), "section_info");
     234        3393 :   DwarfLineSection =
     235        3393 :       Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
     236             :                            SectionKind::getMetadata(), "section_line");
     237        3393 :   DwarfLineStrSection =
     238        3393 :       Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
     239             :                            SectionKind::getMetadata(), "section_line_str");
     240        3393 :   DwarfFrameSection =
     241        3393 :       Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
     242             :                            SectionKind::getMetadata());
     243        3393 :   DwarfPubNamesSection =
     244        3393 :       Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
     245             :                            SectionKind::getMetadata());
     246        3393 :   DwarfPubTypesSection =
     247        3393 :       Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
     248             :                            SectionKind::getMetadata());
     249        3393 :   DwarfGnuPubNamesSection =
     250        3393 :       Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
     251             :                            SectionKind::getMetadata());
     252        3393 :   DwarfGnuPubTypesSection =
     253        3393 :       Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
     254             :                            SectionKind::getMetadata());
     255        3393 :   DwarfStrSection =
     256        3393 :       Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
     257             :                            SectionKind::getMetadata(), "info_string");
     258        3393 :   DwarfStrOffSection =
     259        3393 :       Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
     260             :                            SectionKind::getMetadata(), "section_str_off");
     261        3393 :   DwarfLocSection =
     262        3393 :       Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
     263             :                            SectionKind::getMetadata(), "section_debug_loc");
     264        3393 :   DwarfARangesSection =
     265        3393 :       Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
     266             :                            SectionKind::getMetadata());
     267        3393 :   DwarfRangesSection =
     268        3393 :       Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
     269             :                            SectionKind::getMetadata(), "debug_range");
     270        3393 :   DwarfMacinfoSection =
     271        3393 :       Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
     272             :                            SectionKind::getMetadata(), "debug_macinfo");
     273        3393 :   DwarfDebugInlineSection =
     274        3393 :       Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
     275             :                            SectionKind::getMetadata());
     276        3393 :   DwarfCUIndexSection =
     277        3393 :       Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
     278             :                            SectionKind::getMetadata());
     279        3393 :   DwarfTUIndexSection =
     280        3393 :       Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
     281             :                            SectionKind::getMetadata());
     282        6786 :   StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
     283             :                                          0, SectionKind::getMetadata());
     284             : 
     285        6786 :   FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
     286             :                                          0, SectionKind::getMetadata());
     287             : 
     288        3393 :   TLSExtraDataSection = TLSTLVSection;
     289        3393 : }
     290             : 
     291       26336 : void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
     292       26336 :   switch (T.getArch()) {
     293        2117 :   case Triple::mips:
     294             :   case Triple::mipsel:
     295        2117 :     FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
     296        2117 :     break;
     297         943 :   case Triple::mips64:
     298             :   case Triple::mips64el:
     299         943 :     FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
     300         943 :     break;
     301       10651 :   case Triple::ppc64:
     302             :   case Triple::ppc64le:
     303             :   case Triple::x86_64:
     304       10651 :     FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
     305             :                      (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
     306       10651 :     break;
     307          79 :   case Triple::bpfel:
     308             :   case Triple::bpfeb:
     309          79 :     FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
     310          79 :     break;
     311       12546 :   default:
     312       12546 :     FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
     313       12546 :     break;
     314             :   }
     315             : 
     316       26336 :   switch (T.getArch()) {
     317        3024 :   case Triple::arm:
     318             :   case Triple::armeb:
     319             :   case Triple::thumb:
     320             :   case Triple::thumbeb:
     321        3024 :     if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
     322             :       break;
     323             :     // Fallthrough if not using EHABI
     324             :     LLVM_FALLTHROUGH;
     325             :   case Triple::ppc:
     326             :   case Triple::x86:
     327        4412 :     PersonalityEncoding = PositionIndependent
     328        2206 :                               ? dwarf::DW_EH_PE_indirect |
     329             :                                     dwarf::DW_EH_PE_pcrel |
     330             :                                     dwarf::DW_EH_PE_sdata4
     331             :                               : dwarf::DW_EH_PE_absptr;
     332        2206 :     LSDAEncoding = PositionIndependent
     333        2206 :                        ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
     334             :                        : dwarf::DW_EH_PE_absptr;
     335        2206 :     TTypeEncoding = PositionIndependent
     336             :                         ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     337             :                               dwarf::DW_EH_PE_sdata4
     338             :                         : dwarf::DW_EH_PE_absptr;
     339        2206 :     break;
     340        9325 :   case Triple::x86_64:
     341        9325 :     if (PositionIndependent) {
     342         822 :       PersonalityEncoding =
     343         822 :           dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     344             :           (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
     345         822 :       LSDAEncoding = dwarf::DW_EH_PE_pcrel |
     346             :                      (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
     347         822 :       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     348             :                       (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
     349             :     } else {
     350        8503 :       PersonalityEncoding =
     351        8503 :           Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
     352        8503 :       LSDAEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
     353        8503 :       TTypeEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
     354             :     }
     355             :     break;
     356        1109 :   case Triple::hexagon:
     357        1109 :     PersonalityEncoding = dwarf::DW_EH_PE_absptr;
     358        1109 :     LSDAEncoding = dwarf::DW_EH_PE_absptr;
     359        1109 :     FDECFIEncoding = dwarf::DW_EH_PE_absptr;
     360        1109 :     TTypeEncoding = dwarf::DW_EH_PE_absptr;
     361        1109 :     if (PositionIndependent) {
     362          16 :       PersonalityEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
     363          16 :       LSDAEncoding |= dwarf::DW_EH_PE_pcrel;
     364          16 :       FDECFIEncoding |= dwarf::DW_EH_PE_pcrel;
     365          16 :       TTypeEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
     366             :     }
     367             :     break;
     368        1983 :   case Triple::aarch64:
     369             :   case Triple::aarch64_be:
     370             :     // The small model guarantees static code/data size < 4GB, but not where it
     371             :     // will be in memory. Most of these could end up >2GB away so even a signed
     372             :     // pc-relative 32-bit address is insufficient, theoretically.
     373        1983 :     if (PositionIndependent) {
     374          34 :       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     375             :         dwarf::DW_EH_PE_sdata8;
     376          34 :       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
     377          34 :       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     378             :         dwarf::DW_EH_PE_sdata8;
     379             :     } else {
     380        1949 :       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
     381        1949 :       LSDAEncoding = dwarf::DW_EH_PE_absptr;
     382        1949 :       TTypeEncoding = dwarf::DW_EH_PE_absptr;
     383             :     }
     384             :     break;
     385          26 :   case Triple::lanai:
     386          26 :     LSDAEncoding = dwarf::DW_EH_PE_absptr;
     387          26 :     PersonalityEncoding = dwarf::DW_EH_PE_absptr;
     388          26 :     TTypeEncoding = dwarf::DW_EH_PE_absptr;
     389          26 :     break;
     390        3060 :   case Triple::mips:
     391             :   case Triple::mipsel:
     392             :   case Triple::mips64:
     393             :   case Triple::mips64el:
     394             :     // MIPS uses indirect pointer to refer personality functions and types, so
     395             :     // that the eh_frame section can be read-only. DW.ref.personality will be
     396             :     // generated for relocation.
     397        3060 :     PersonalityEncoding = dwarf::DW_EH_PE_indirect;
     398             :     // FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
     399             :     //        identify N64 from just a triple.
     400        3060 :     TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     401             :                     dwarf::DW_EH_PE_sdata4;
     402             :     // We don't support PC-relative LSDA references in GAS so we use the default
     403             :     // DW_EH_PE_absptr for those.
     404             : 
     405             :     // FreeBSD must be explicit about the data size and using pcrel since it's
     406             :     // assembler/linker won't do the automatic conversion that the Linux tools
     407             :     // do.
     408        3060 :     if (T.isOSFreeBSD()) {
     409          20 :       PersonalityEncoding |= dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
     410          20 :       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
     411             :     }
     412             :     break;
     413        1326 :   case Triple::ppc64:
     414             :   case Triple::ppc64le:
     415        1326 :     PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     416             :       dwarf::DW_EH_PE_udata8;
     417        1326 :     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
     418        1326 :     TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     419             :       dwarf::DW_EH_PE_udata8;
     420        1326 :     break;
     421         166 :   case Triple::sparcel:
     422             :   case Triple::sparc:
     423         166 :     if (PositionIndependent) {
     424          10 :       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
     425          10 :       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     426             :         dwarf::DW_EH_PE_sdata4;
     427          10 :       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     428             :         dwarf::DW_EH_PE_sdata4;
     429             :     } else {
     430         156 :       LSDAEncoding = dwarf::DW_EH_PE_absptr;
     431         156 :       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
     432         156 :       TTypeEncoding = dwarf::DW_EH_PE_absptr;
     433             :     }
     434             :     break;
     435          88 :   case Triple::sparcv9:
     436          88 :     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
     437          88 :     if (PositionIndependent) {
     438          11 :       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     439             :         dwarf::DW_EH_PE_sdata4;
     440          11 :       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     441             :         dwarf::DW_EH_PE_sdata4;
     442             :     } else {
     443          77 :       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
     444          77 :       TTypeEncoding = dwarf::DW_EH_PE_absptr;
     445             :     }
     446             :     break;
     447         929 :   case Triple::systemz:
     448             :     // All currently-defined code models guarantee that 4-byte PC-relative
     449             :     // values will be in range.
     450         929 :     if (PositionIndependent) {
     451          12 :       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     452             :         dwarf::DW_EH_PE_sdata4;
     453          12 :       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
     454          12 :       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     455             :         dwarf::DW_EH_PE_sdata4;
     456             :     } else {
     457         917 :       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
     458         917 :       LSDAEncoding = dwarf::DW_EH_PE_absptr;
     459         917 :       TTypeEncoding = dwarf::DW_EH_PE_absptr;
     460             :     }
     461             :     break;
     462             :   default:
     463             :     break;
     464             :   }
     465             : 
     466             :   unsigned EHSectionType = T.getArch() == Triple::x86_64
     467       26336 :                                ? ELF::SHT_X86_64_UNWIND
     468             :                                : ELF::SHT_PROGBITS;
     469             : 
     470             :   // Solaris requires different flags for .eh_frame to seemingly every other
     471             :   // platform.
     472             :   unsigned EHSectionFlags = ELF::SHF_ALLOC;
     473       26336 :   if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
     474             :     EHSectionFlags |= ELF::SHF_WRITE;
     475             : 
     476             :   // ELF
     477       52672 :   BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
     478             :                                   ELF::SHF_WRITE | ELF::SHF_ALLOC);
     479             : 
     480       52672 :   TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
     481             :                                    ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
     482             : 
     483       52672 :   DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
     484             :                                    ELF::SHF_WRITE | ELF::SHF_ALLOC);
     485             : 
     486       26336 :   ReadOnlySection =
     487       52672 :       Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
     488             : 
     489       26336 :   TLSDataSection =
     490       52672 :       Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
     491             :                          ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
     492             : 
     493       52672 :   TLSBSSSection = Ctx->getELFSection(
     494             :       ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
     495             : 
     496       52672 :   DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
     497             :                                         ELF::SHF_ALLOC | ELF::SHF_WRITE);
     498             : 
     499       26336 :   MergeableConst4Section =
     500       52672 :       Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
     501             :                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
     502             : 
     503       26336 :   MergeableConst8Section =
     504       52672 :       Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
     505             :                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
     506             : 
     507       26336 :   MergeableConst16Section =
     508       52672 :       Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
     509             :                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
     510             : 
     511       26336 :   MergeableConst32Section =
     512       52672 :       Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
     513             :                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
     514             : 
     515             :   // Exception Handling Sections.
     516             : 
     517             :   // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
     518             :   // it contains relocatable pointers.  In PIC mode, this is probably a big
     519             :   // runtime hit for C++ apps.  Either the contents of the LSDA need to be
     520             :   // adjusted or this should be a data section.
     521       52672 :   LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
     522             :                                    ELF::SHF_ALLOC);
     523             : 
     524       26336 :   COFFDebugSymbolsSection = nullptr;
     525       26336 :   COFFDebugTypesSection = nullptr;
     526             : 
     527             :   unsigned DebugSecType = ELF::SHT_PROGBITS;
     528             : 
     529             :   // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
     530             :   // to distinguish among sections contain DWARF and ECOFF debug formats.
     531             :   // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
     532       51437 :   if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
     533       49934 :       T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el)
     534             :     DebugSecType = ELF::SHT_MIPS_DWARF;
     535             : 
     536             :   // Debug Info Sections.
     537       26336 :   DwarfAbbrevSection =
     538       52672 :       Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
     539       52672 :   DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
     540       52672 :   DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
     541       26336 :   DwarfLineStrSection =
     542       52672 :       Ctx->getELFSection(".debug_line_str", DebugSecType,
     543             :                          ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
     544       52672 :   DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
     545       26336 :   DwarfPubNamesSection =
     546       52672 :       Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
     547       26336 :   DwarfPubTypesSection =
     548       52672 :       Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
     549       26336 :   DwarfGnuPubNamesSection =
     550       52672 :       Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
     551       26336 :   DwarfGnuPubTypesSection =
     552       52672 :       Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
     553       26336 :   DwarfStrSection =
     554       52672 :       Ctx->getELFSection(".debug_str", DebugSecType,
     555             :                          ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
     556       52672 :   DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
     557       26336 :   DwarfARangesSection =
     558       52672 :       Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
     559       26336 :   DwarfRangesSection =
     560       52672 :       Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
     561       26336 :   DwarfMacinfoSection =
     562       52672 :       Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
     563             : 
     564             :   // DWARF5 Experimental Debug Info
     565             : 
     566             :   // Accelerator Tables
     567       26336 :   DwarfDebugNamesSection =
     568       52672 :       Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
     569       26336 :   DwarfAccelNamesSection =
     570       52672 :       Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
     571       26336 :   DwarfAccelObjCSection =
     572       52672 :       Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
     573       26336 :   DwarfAccelNamespaceSection =
     574       52672 :       Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
     575       26336 :   DwarfAccelTypesSection =
     576       52672 :       Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
     577             : 
     578             :   // String Offset and Address Sections
     579       26336 :   DwarfStrOffSection =
     580       52672 :       Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
     581       52672 :   DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
     582             : 
     583             :   // Fission Sections
     584       26336 :   DwarfInfoDWOSection =
     585       52672 :       Ctx->getELFSection(".debug_info.dwo", DebugSecType, 0);
     586       26336 :   DwarfTypesDWOSection =
     587       52672 :       Ctx->getELFSection(".debug_types.dwo", DebugSecType, 0);
     588       26336 :   DwarfAbbrevDWOSection =
     589       52672 :       Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, 0);
     590       26336 :   DwarfStrDWOSection =
     591       52672 :       Ctx->getELFSection(".debug_str.dwo", DebugSecType,
     592             :                          ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
     593       26336 :   DwarfLineDWOSection =
     594       52672 :       Ctx->getELFSection(".debug_line.dwo", DebugSecType, 0);
     595       26336 :   DwarfLocDWOSection =
     596       52672 :       Ctx->getELFSection(".debug_loc.dwo", DebugSecType, 0);
     597       26336 :   DwarfStrOffDWOSection =
     598       52672 :       Ctx->getELFSection(".debug_str_offsets.dwo", DebugSecType, 0);
     599             : 
     600             :   // DWP Sections
     601       26336 :   DwarfCUIndexSection =
     602       52672 :       Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
     603       26336 :   DwarfTUIndexSection =
     604       52672 :       Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
     605             : 
     606       26336 :   StackMapSection =
     607       52672 :       Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
     608             : 
     609       26336 :   FaultMapSection =
     610       52672 :       Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
     611             : 
     612       26336 :   EHFrameSection =
     613       52672 :       Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
     614             : 
     615       52672 :   StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
     616       26336 : }
     617             : 
     618         964 : void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
     619        1928 :   EHFrameSection = Ctx->getCOFFSection(
     620             :       ".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     621             :                        COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
     622             :       SectionKind::getData());
     623             : 
     624             :   // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode.  This is
     625             :   // used to indicate to the linker that the text segment contains thumb instructions
     626             :   // and to set the ISA selection bit for calls accordingly.
     627         964 :   const bool IsThumb = T.getArch() == Triple::thumb;
     628             : 
     629         964 :   CommDirectiveSupportsAlignment = true;
     630             : 
     631             :   // COFF
     632        1928 :   BSSSection = Ctx->getCOFFSection(
     633             :       ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
     634             :                   COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
     635             :       SectionKind::getBSS());
     636        1928 :   TextSection = Ctx->getCOFFSection(
     637             :       ".text",
     638             :       (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
     639             :           COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
     640             :           COFF::IMAGE_SCN_MEM_READ,
     641             :       SectionKind::getText());
     642        1928 :   DataSection = Ctx->getCOFFSection(
     643             :       ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
     644             :                    COFF::IMAGE_SCN_MEM_WRITE,
     645             :       SectionKind::getData());
     646        1928 :   ReadOnlySection = Ctx->getCOFFSection(
     647             :       ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
     648             :       SectionKind::getReadOnly());
     649             : 
     650             :   // FIXME: We're emitting LSDA info into a readonly section on COFF, even
     651             :   // though it contains relocatable pointers.  In PIC mode, this is probably a
     652             :   // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
     653             :   // adjusted or this should be a data section.
     654         964 :   if (T.getArch() == Triple::x86_64) {
     655             :     // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
     656         473 :     LSDASection = nullptr;
     657             :   } else {
     658         982 :     LSDASection = Ctx->getCOFFSection(".gcc_except_table",
     659             :                                       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     660             :                                           COFF::IMAGE_SCN_MEM_READ,
     661             :                                       SectionKind::getReadOnly());
     662             :   }
     663             : 
     664             :   // Debug info.
     665         964 :   COFFDebugSymbolsSection =
     666        2892 :       Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
     667             :                                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     668             :                                        COFF::IMAGE_SCN_MEM_READ),
     669             :                           SectionKind::getMetadata());
     670         964 :   COFFDebugTypesSection =
     671        2892 :       Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
     672             :                                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     673             :                                        COFF::IMAGE_SCN_MEM_READ),
     674             :                           SectionKind::getMetadata());
     675        1928 :   COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
     676             :       ".debug$H",
     677             :       (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     678             :        COFF::IMAGE_SCN_MEM_READ),
     679             :       SectionKind::getMetadata());
     680             : 
     681        1928 :   DwarfAbbrevSection = Ctx->getCOFFSection(
     682             :       ".debug_abbrev",
     683             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     684             :           COFF::IMAGE_SCN_MEM_READ,
     685             :       SectionKind::getMetadata(), "section_abbrev");
     686        1928 :   DwarfInfoSection = Ctx->getCOFFSection(
     687             :       ".debug_info",
     688             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     689             :           COFF::IMAGE_SCN_MEM_READ,
     690             :       SectionKind::getMetadata(), "section_info");
     691        1928 :   DwarfLineSection = Ctx->getCOFFSection(
     692             :       ".debug_line",
     693             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     694             :           COFF::IMAGE_SCN_MEM_READ,
     695             :       SectionKind::getMetadata(), "section_line");
     696        1928 :   DwarfLineStrSection = Ctx->getCOFFSection(
     697             :       ".debug_line_str",
     698             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     699             :           COFF::IMAGE_SCN_MEM_READ,
     700             :       SectionKind::getMetadata(), "section_line_str");
     701        1928 :   DwarfFrameSection = Ctx->getCOFFSection(
     702             :       ".debug_frame",
     703             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     704             :           COFF::IMAGE_SCN_MEM_READ,
     705             :       SectionKind::getMetadata());
     706        1928 :   DwarfPubNamesSection = Ctx->getCOFFSection(
     707             :       ".debug_pubnames",
     708             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     709             :           COFF::IMAGE_SCN_MEM_READ,
     710             :       SectionKind::getMetadata());
     711        1928 :   DwarfPubTypesSection = Ctx->getCOFFSection(
     712             :       ".debug_pubtypes",
     713             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     714             :           COFF::IMAGE_SCN_MEM_READ,
     715             :       SectionKind::getMetadata());
     716        1928 :   DwarfGnuPubNamesSection = Ctx->getCOFFSection(
     717             :       ".debug_gnu_pubnames",
     718             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     719             :           COFF::IMAGE_SCN_MEM_READ,
     720             :       SectionKind::getMetadata());
     721        1928 :   DwarfGnuPubTypesSection = Ctx->getCOFFSection(
     722             :       ".debug_gnu_pubtypes",
     723             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     724             :           COFF::IMAGE_SCN_MEM_READ,
     725             :       SectionKind::getMetadata());
     726        1928 :   DwarfStrSection = Ctx->getCOFFSection(
     727             :       ".debug_str",
     728             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     729             :           COFF::IMAGE_SCN_MEM_READ,
     730             :       SectionKind::getMetadata(), "info_string");
     731        1928 :   DwarfStrOffSection = Ctx->getCOFFSection(
     732             :       ".debug_str_offsets",
     733             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     734             :           COFF::IMAGE_SCN_MEM_READ,
     735             :       SectionKind::getMetadata(), "section_str_off");
     736        1928 :   DwarfLocSection = Ctx->getCOFFSection(
     737             :       ".debug_loc",
     738             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     739             :           COFF::IMAGE_SCN_MEM_READ,
     740             :       SectionKind::getMetadata(), "section_debug_loc");
     741        1928 :   DwarfARangesSection = Ctx->getCOFFSection(
     742             :       ".debug_aranges",
     743             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     744             :           COFF::IMAGE_SCN_MEM_READ,
     745             :       SectionKind::getMetadata());
     746        1928 :   DwarfRangesSection = Ctx->getCOFFSection(
     747             :       ".debug_ranges",
     748             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     749             :           COFF::IMAGE_SCN_MEM_READ,
     750             :       SectionKind::getMetadata(), "debug_range");
     751        1928 :   DwarfMacinfoSection = Ctx->getCOFFSection(
     752             :       ".debug_macinfo",
     753             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     754             :           COFF::IMAGE_SCN_MEM_READ,
     755             :       SectionKind::getMetadata(), "debug_macinfo");
     756        1928 :   DwarfInfoDWOSection = Ctx->getCOFFSection(
     757             :       ".debug_info.dwo",
     758             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     759             :           COFF::IMAGE_SCN_MEM_READ,
     760             :       SectionKind::getMetadata(), "section_info_dwo");
     761        1928 :   DwarfTypesDWOSection = Ctx->getCOFFSection(
     762             :       ".debug_types.dwo",
     763             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     764             :           COFF::IMAGE_SCN_MEM_READ,
     765             :       SectionKind::getMetadata(), "section_types_dwo");
     766        1928 :   DwarfAbbrevDWOSection = Ctx->getCOFFSection(
     767             :       ".debug_abbrev.dwo",
     768             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     769             :           COFF::IMAGE_SCN_MEM_READ,
     770             :       SectionKind::getMetadata(), "section_abbrev_dwo");
     771        1928 :   DwarfStrDWOSection = Ctx->getCOFFSection(
     772             :       ".debug_str.dwo",
     773             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     774             :           COFF::IMAGE_SCN_MEM_READ,
     775             :       SectionKind::getMetadata(), "skel_string");
     776        1928 :   DwarfLineDWOSection = Ctx->getCOFFSection(
     777             :       ".debug_line.dwo",
     778             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     779             :           COFF::IMAGE_SCN_MEM_READ,
     780             :       SectionKind::getMetadata());
     781        1928 :   DwarfLocDWOSection = Ctx->getCOFFSection(
     782             :       ".debug_loc.dwo",
     783             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     784             :           COFF::IMAGE_SCN_MEM_READ,
     785             :       SectionKind::getMetadata(), "skel_loc");
     786        1928 :   DwarfStrOffDWOSection = Ctx->getCOFFSection(
     787             :       ".debug_str_offsets.dwo",
     788             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     789             :           COFF::IMAGE_SCN_MEM_READ,
     790             :       SectionKind::getMetadata(), "section_str_off_dwo");
     791        1928 :   DwarfAddrSection = Ctx->getCOFFSection(
     792             :       ".debug_addr",
     793             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     794             :           COFF::IMAGE_SCN_MEM_READ,
     795             :       SectionKind::getMetadata(), "addr_sec");
     796        1928 :   DwarfCUIndexSection = Ctx->getCOFFSection(
     797             :       ".debug_cu_index",
     798             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     799             :           COFF::IMAGE_SCN_MEM_READ,
     800             :       SectionKind::getMetadata());
     801        1928 :   DwarfTUIndexSection = Ctx->getCOFFSection(
     802             :       ".debug_tu_index",
     803             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     804             :           COFF::IMAGE_SCN_MEM_READ,
     805             :       SectionKind::getMetadata());
     806        1928 :   DwarfDebugNamesSection = Ctx->getCOFFSection(
     807             :       ".debug_names",
     808             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     809             :           COFF::IMAGE_SCN_MEM_READ,
     810             :       SectionKind::getMetadata(), "debug_names_begin");
     811        1928 :   DwarfAccelNamesSection = Ctx->getCOFFSection(
     812             :       ".apple_names",
     813             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     814             :           COFF::IMAGE_SCN_MEM_READ,
     815             :       SectionKind::getMetadata(), "names_begin");
     816        1928 :   DwarfAccelNamespaceSection = Ctx->getCOFFSection(
     817             :       ".apple_namespaces",
     818             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     819             :           COFF::IMAGE_SCN_MEM_READ,
     820             :       SectionKind::getMetadata(), "namespac_begin");
     821        1928 :   DwarfAccelTypesSection = Ctx->getCOFFSection(
     822             :       ".apple_types",
     823             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     824             :           COFF::IMAGE_SCN_MEM_READ,
     825             :       SectionKind::getMetadata(), "types_begin");
     826        1928 :   DwarfAccelObjCSection = Ctx->getCOFFSection(
     827             :       ".apple_objc",
     828             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     829             :           COFF::IMAGE_SCN_MEM_READ,
     830             :       SectionKind::getMetadata(), "objc_begin");
     831             : 
     832        1928 :   DrectveSection = Ctx->getCOFFSection(
     833             :       ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
     834             :       SectionKind::getMetadata());
     835             : 
     836        1928 :   PDataSection = Ctx->getCOFFSection(
     837             :       ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
     838             :       SectionKind::getData());
     839             : 
     840        1928 :   XDataSection = Ctx->getCOFFSection(
     841             :       ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
     842             :       SectionKind::getData());
     843             : 
     844        1928 :   SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
     845             :                                       SectionKind::getMetadata());
     846             : 
     847        1928 :   GFIDsSection = Ctx->getCOFFSection(".gfids$y",
     848             :                                      COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     849             :                                          COFF::IMAGE_SCN_MEM_READ,
     850             :                                      SectionKind::getMetadata());
     851             : 
     852        1928 :   TLSDataSection = Ctx->getCOFFSection(
     853             :       ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
     854             :                    COFF::IMAGE_SCN_MEM_WRITE,
     855             :       SectionKind::getData());
     856             : 
     857        1928 :   StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
     858             :                                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     859             :                                             COFF::IMAGE_SCN_MEM_READ,
     860             :                                         SectionKind::getReadOnly());
     861         964 : }
     862             : 
     863         252 : void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
     864         504 :   TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
     865         504 :   DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
     866             : 
     867         252 :   DwarfLineSection =
     868         504 :       Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
     869         252 :   DwarfLineStrSection =
     870         504 :       Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
     871         252 :   DwarfStrSection =
     872         504 :       Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
     873         252 :   DwarfLocSection =
     874         504 :       Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
     875         252 :   DwarfAbbrevSection =
     876         504 :       Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
     877         504 :   DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
     878         252 :   DwarfRangesSection =
     879         504 :       Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
     880         252 :   DwarfMacinfoSection =
     881         504 :       Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
     882         504 :   DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
     883         504 :   DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
     884         504 :   DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
     885         252 :   DwarfInfoSection =
     886         504 :       Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
     887         504 :   DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
     888         504 :   DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
     889         504 :   DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
     890             : 
     891             :   // TODO: Define more sections.
     892         252 : }
     893             : 
     894       30945 : void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
     895             :                                             MCContext &ctx,
     896             :                                             bool LargeCodeModel) {
     897       30945 :   PositionIndependent = PIC;
     898       30945 :   Ctx = &ctx;
     899             : 
     900             :   // Common.
     901       30945 :   CommDirectiveSupportsAlignment = true;
     902       30945 :   SupportsWeakOmittedEHFrame = true;
     903       30945 :   SupportsCompactUnwindWithoutEHFrame = false;
     904       30945 :   OmitDwarfIfHaveCompactUnwind = false;
     905             : 
     906       30945 :   PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
     907             :       dwarf::DW_EH_PE_absptr;
     908             : 
     909       30945 :   CompactUnwindDwarfEHFrameOnly = 0;
     910             : 
     911       30945 :   EHFrameSection = nullptr;             // Created on demand.
     912       30945 :   CompactUnwindSection = nullptr;       // Used only by selected targets.
     913       30945 :   DwarfAccelNamesSection = nullptr;     // Used only by selected targets.
     914       30945 :   DwarfAccelObjCSection = nullptr;      // Used only by selected targets.
     915       30945 :   DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
     916       30945 :   DwarfAccelTypesSection = nullptr;     // Used only by selected targets.
     917             : 
     918       30945 :   TT = TheTriple;
     919             : 
     920       30945 :   switch (TT.getObjectFormat()) {
     921        3393 :   case Triple::MachO:
     922        3393 :     Env = IsMachO;
     923        3393 :     initMachOMCObjectFileInfo(TT);
     924        3393 :     break;
     925         964 :   case Triple::COFF:
     926         964 :     if (!TT.isOSWindows())
     927           0 :       report_fatal_error(
     928             :           "Cannot initialize MC for non-Windows COFF object files.");
     929             : 
     930         964 :     Env = IsCOFF;
     931         964 :     initCOFFMCObjectFileInfo(TT);
     932         964 :     break;
     933       26336 :   case Triple::ELF:
     934       26336 :     Env = IsELF;
     935       26336 :     initELFMCObjectFileInfo(TT, LargeCodeModel);
     936       26336 :     break;
     937         252 :   case Triple::Wasm:
     938         252 :     Env = IsWasm;
     939         252 :     initWasmMCObjectFileInfo(TT);
     940         252 :     break;
     941           0 :   case Triple::UnknownObjectFormat:
     942           0 :     report_fatal_error("Cannot initialize MC for unknown object file format.");
     943             :     break;
     944             :   }
     945       30945 : }
     946             : 
     947          20 : MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
     948          40 :   return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
     949          40 :                             0, utostr(Hash));
     950             : }

Generated by: LCOV version 1.13