LCOV - code coverage report
Current view: top level - lib/MC - MCObjectFileInfo.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 418 422 99.1 %
Date: 2018-07-13 00:08:38 Functions: 8 8 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        3402 : static bool useCompactUnwind(const Triple &T) {
      26             :   // Only on darwin.
      27             :   if (!T.isOSDarwin())
      28             :     return false;
      29             : 
      30             :   // aarch64 always has it.
      31        3319 :   if (T.getArch() == Triple::aarch64)
      32             :     return true;
      33             : 
      34             :   // armv7k always has it.
      35        2955 :   if (T.isWatchABI())
      36             :     return true;
      37             : 
      38             :   // Use it on newer version of OS X.
      39        2552 :   if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
      40             :     return true;
      41             : 
      42             :   // And the iOS simulator.
      43         372 :   if (T.isiOS() &&
      44         731 :       (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
      45             :     return true;
      46             : 
      47             :   return false;
      48             : }
      49             : 
      50        3402 : void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {
      51             :   // MachO
      52        3402 :   SupportsWeakOmittedEHFrame = false;
      53             : 
      54        6804 :   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        3319 :   if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
      61         364 :     SupportsCompactUnwindWithoutEHFrame = true;
      62             : 
      63        3402 :   if (T.isWatchABI())
      64          25 :     OmitDwarfIfHaveCompactUnwind = true;
      65             : 
      66        3402 :   PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
      67             :     | dwarf::DW_EH_PE_sdata4;
      68        3402 :   LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
      69        3402 :   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        2732 :   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
      74        1755 :     CommDirectiveSupportsAlignment = false;
      75             : 
      76             :   TextSection // .text
      77        6804 :     = Ctx->getMachOSection("__TEXT", "__text",
      78             :                            MachO::S_ATTR_PURE_INSTRUCTIONS,
      79             :                            SectionKind::getText());
      80             :   DataSection // .data
      81        6804 :       = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());
      82             : 
      83             :   // BSSSection might not be expected initialized on msvc.
      84        3402 :   BSSSection = nullptr;
      85             : 
      86             :   TLSDataSection // .tdata
      87        6804 :       = Ctx->getMachOSection("__DATA", "__thread_data",
      88             :                              MachO::S_THREAD_LOCAL_REGULAR,
      89             :                              SectionKind::getData());
      90             :   TLSBSSSection // .tbss
      91        6804 :     = Ctx->getMachOSection("__DATA", "__thread_bss",
      92             :                            MachO::S_THREAD_LOCAL_ZEROFILL,
      93             :                            SectionKind::getThreadBSS());
      94             : 
      95             :   // TODO: Verify datarel below.
      96             :   TLSTLVSection // .tlv
      97        6804 :       = Ctx->getMachOSection("__DATA", "__thread_vars",
      98             :                              MachO::S_THREAD_LOCAL_VARIABLES,
      99             :                              SectionKind::getData());
     100             : 
     101        6804 :   TLSThreadInitSection = Ctx->getMachOSection(
     102             :       "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
     103             :       SectionKind::getData());
     104             : 
     105             :   CStringSection // .cstring
     106        6804 :     = Ctx->getMachOSection("__TEXT", "__cstring",
     107             :                            MachO::S_CSTRING_LITERALS,
     108             :                            SectionKind::getMergeable1ByteCString());
     109             :   UStringSection
     110        6804 :     = Ctx->getMachOSection("__TEXT","__ustring", 0,
     111             :                            SectionKind::getMergeable2ByteCString());
     112             :   FourByteConstantSection // .literal4
     113        6804 :     = Ctx->getMachOSection("__TEXT", "__literal4",
     114             :                            MachO::S_4BYTE_LITERALS,
     115             :                            SectionKind::getMergeableConst4());
     116             :   EightByteConstantSection // .literal8
     117        6804 :     = Ctx->getMachOSection("__TEXT", "__literal8",
     118             :                            MachO::S_8BYTE_LITERALS,
     119             :                            SectionKind::getMergeableConst8());
     120             : 
     121             :   SixteenByteConstantSection // .literal16
     122        6804 :       = Ctx->getMachOSection("__TEXT", "__literal16",
     123             :                              MachO::S_16BYTE_LITERALS,
     124             :                              SectionKind::getMergeableConst16());
     125             : 
     126             :   ReadOnlySection  // .const
     127        6804 :     = 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        3402 :   Triple::ArchType ArchTy = T.getArch();
     137             : 
     138             :   ConstDataSection  // .const_data
     139        6804 :     = Ctx->getMachOSection("__DATA", "__const", 0,
     140             :                            SectionKind::getReadOnlyWithRel());
     141             : 
     142        3402 :   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        3238 :     TextCoalSection = TextSection;
     157        3238 :     ConstTextCoalSection = ReadOnlySection;
     158        3238 :     DataCoalSection = DataSection;
     159        3238 :     ConstDataCoalSection = ConstDataSection;
     160             :   }
     161             : 
     162             :   DataCommonSection
     163        6804 :     = Ctx->getMachOSection("__DATA","__common",
     164             :                            MachO::S_ZEROFILL,
     165             :                            SectionKind::getBSS());
     166             :   DataBSSSection
     167        6804 :     = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
     168             :                            SectionKind::getBSS());
     169             : 
     170             : 
     171             :   LazySymbolPointerSection
     172        6804 :     = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
     173             :                            MachO::S_LAZY_SYMBOL_POINTERS,
     174             :                            SectionKind::getMetadata());
     175             :   NonLazySymbolPointerSection
     176        6804 :     = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
     177             :                            MachO::S_NON_LAZY_SYMBOL_POINTERS,
     178             :                            SectionKind::getMetadata());
     179             : 
     180             :   ThreadLocalPointerSection
     181        6804 :     = Ctx->getMachOSection("__DATA", "__thread_ptr",
     182             :                            MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
     183             :                            SectionKind::getMetadata());
     184             : 
     185             :   // Exception Handling.
     186        6804 :   LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
     187             :                                      SectionKind::getReadOnlyWithRel());
     188             : 
     189        3402 :   COFFDebugSymbolsSection = nullptr;
     190        3402 :   COFFDebugTypesSection = nullptr;
     191        3402 :   COFFGlobalTypeHashesSection = nullptr;
     192             : 
     193        3402 :   if (useCompactUnwind(T)) {
     194        1135 :     CompactUnwindSection =
     195        1135 :         Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
     196             :                              SectionKind::getReadOnly());
     197             : 
     198        1135 :     if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
     199         665 :       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        3402 :   DwarfDebugNamesSection =
     208        3402 :       Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,
     209             :                            SectionKind::getMetadata(), "debug_names_begin");
     210        3402 :   DwarfAccelNamesSection =
     211        3402 :       Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
     212             :                            SectionKind::getMetadata(), "names_begin");
     213        3402 :   DwarfAccelObjCSection =
     214        3402 :       Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
     215             :                            SectionKind::getMetadata(), "objc_begin");
     216             :   // 16 character section limit...
     217        3402 :   DwarfAccelNamespaceSection =
     218        3402 :       Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
     219             :                            SectionKind::getMetadata(), "namespac_begin");
     220        3402 :   DwarfAccelTypesSection =
     221        3402 :       Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
     222             :                            SectionKind::getMetadata(), "types_begin");
     223             : 
     224        3402 :   DwarfSwiftASTSection =
     225        3402 :       Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,
     226             :                            SectionKind::getMetadata());
     227             : 
     228        3402 :   DwarfAbbrevSection =
     229        3402 :       Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
     230             :                            SectionKind::getMetadata(), "section_abbrev");
     231        3402 :   DwarfInfoSection =
     232        3402 :       Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
     233             :                            SectionKind::getMetadata(), "section_info");
     234        3402 :   DwarfLineSection =
     235        3402 :       Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
     236             :                            SectionKind::getMetadata(), "section_line");
     237        3402 :   DwarfLineStrSection =
     238        3402 :       Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,
     239             :                            SectionKind::getMetadata(), "section_line_str");
     240        3402 :   DwarfFrameSection =
     241        3402 :       Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
     242             :                            SectionKind::getMetadata());
     243        3402 :   DwarfPubNamesSection =
     244        3402 :       Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
     245             :                            SectionKind::getMetadata());
     246        3402 :   DwarfPubTypesSection =
     247        3402 :       Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
     248             :                            SectionKind::getMetadata());
     249        3402 :   DwarfGnuPubNamesSection =
     250        3402 :       Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
     251             :                            SectionKind::getMetadata());
     252        3402 :   DwarfGnuPubTypesSection =
     253        3402 :       Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
     254             :                            SectionKind::getMetadata());
     255        3402 :   DwarfStrSection =
     256        3402 :       Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
     257             :                            SectionKind::getMetadata(), "info_string");
     258        3402 :   DwarfStrOffSection =
     259        3402 :       Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,
     260             :                            SectionKind::getMetadata(), "section_str_off");
     261        3402 :   DwarfLocSection =
     262        3402 :       Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
     263             :                            SectionKind::getMetadata(), "section_debug_loc");
     264        3402 :   DwarfARangesSection =
     265        3402 :       Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
     266             :                            SectionKind::getMetadata());
     267        3402 :   DwarfRangesSection =
     268        3402 :       Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
     269             :                            SectionKind::getMetadata(), "debug_range");
     270        3402 :   DwarfMacinfoSection =
     271        3402 :       Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,
     272             :                            SectionKind::getMetadata(), "debug_macinfo");
     273        3402 :   DwarfDebugInlineSection =
     274        3402 :       Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
     275             :                            SectionKind::getMetadata());
     276        3402 :   DwarfCUIndexSection =
     277        3402 :       Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
     278             :                            SectionKind::getMetadata());
     279        3402 :   DwarfTUIndexSection =
     280        3402 :       Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,
     281             :                            SectionKind::getMetadata());
     282        6804 :   StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
     283             :                                          0, SectionKind::getMetadata());
     284             : 
     285        6804 :   FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
     286             :                                          0, SectionKind::getMetadata());
     287             : 
     288        3402 :   TLSExtraDataSection = TLSTLVSection;
     289        3402 : }
     290             : 
     291       26702 : void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
     292       26702 :   switch (T.getArch()) {
     293        2131 :   case Triple::mips:
     294             :   case Triple::mipsel:
     295        2131 :     FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
     296        2131 :     break;
     297         962 :   case Triple::mips64:
     298             :   case Triple::mips64el:
     299         962 :     FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
     300         962 :     break;
     301       10097 :   case Triple::ppc64:
     302             :   case Triple::ppc64le:
     303             :   case Triple::x86_64:
     304       10097 :     FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
     305             :                      (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
     306       10097 :     break;
     307          79 :   case Triple::bpfel:
     308             :   case Triple::bpfeb:
     309          79 :     FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
     310          79 :     break;
     311       13433 :   default:
     312       13433 :     FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
     313       13433 :     break;
     314             :   }
     315             : 
     316       26702 :   switch (T.getArch()) {
     317        3043 :   case Triple::arm:
     318             :   case Triple::armeb:
     319             :   case Triple::thumb:
     320             :   case Triple::thumbeb:
     321        3043 :     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        4446 :     PersonalityEncoding = PositionIndependent
     328        2223 :                               ? dwarf::DW_EH_PE_indirect |
     329             :                                     dwarf::DW_EH_PE_pcrel |
     330             :                                     dwarf::DW_EH_PE_sdata4
     331             :                               : dwarf::DW_EH_PE_absptr;
     332        2223 :     LSDAEncoding = PositionIndependent
     333        2223 :                        ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
     334             :                        : dwarf::DW_EH_PE_absptr;
     335        2223 :     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        2223 :     break;
     340        8740 :   case Triple::x86_64:
     341        8740 :     if (PositionIndependent) {
     342         672 :       PersonalityEncoding =
     343         672 :           dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     344             :           (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
     345         672 :       LSDAEncoding = dwarf::DW_EH_PE_pcrel |
     346             :                      (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
     347         672 :       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        8068 :       PersonalityEncoding =
     351        8068 :           Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
     352        8068 :       LSDAEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
     353        8068 :       TTypeEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
     354             :     }
     355             :     break;
     356        1110 :   case Triple::hexagon:
     357        1110 :     PersonalityEncoding = dwarf::DW_EH_PE_absptr;
     358        1110 :     LSDAEncoding = dwarf::DW_EH_PE_absptr;
     359        1110 :     FDECFIEncoding = dwarf::DW_EH_PE_absptr;
     360        1110 :     TTypeEncoding = dwarf::DW_EH_PE_absptr;
     361        1110 :     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        2833 :   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        2833 :     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        2799 :       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
     381        2799 :       LSDAEncoding = dwarf::DW_EH_PE_absptr;
     382        2799 :       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        3093 :   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        3093 :     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        3093 :     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        3093 :     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        1357 :   case Triple::ppc64:
     414             :   case Triple::ppc64le:
     415        1357 :     PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     416             :       dwarf::DW_EH_PE_udata8;
     417        1357 :     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
     418        1357 :     TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     419             :       dwarf::DW_EH_PE_udata8;
     420        1357 :     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       26702 :                                ? 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       26702 :   if (T.isOSSolaris() && T.getArch() != Triple::x86_64)
     474             :     EHSectionFlags |= ELF::SHF_WRITE;
     475             : 
     476             :   // ELF
     477       53404 :   BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
     478             :                                   ELF::SHF_WRITE | ELF::SHF_ALLOC);
     479             : 
     480       53404 :   TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
     481             :                                    ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
     482             : 
     483       53404 :   DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
     484             :                                    ELF::SHF_WRITE | ELF::SHF_ALLOC);
     485             : 
     486       26702 :   ReadOnlySection =
     487       53404 :       Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
     488             : 
     489       26702 :   TLSDataSection =
     490       53404 :       Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
     491             :                          ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
     492             : 
     493       53404 :   TLSBSSSection = Ctx->getELFSection(
     494             :       ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
     495             : 
     496       53404 :   DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
     497             :                                         ELF::SHF_ALLOC | ELF::SHF_WRITE);
     498             : 
     499       26702 :   MergeableConst4Section =
     500       53404 :       Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
     501             :                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
     502             : 
     503       26702 :   MergeableConst8Section =
     504       53404 :       Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
     505             :                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
     506             : 
     507       26702 :   MergeableConst16Section =
     508       53404 :       Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
     509             :                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
     510             : 
     511       26702 :   MergeableConst32Section =
     512       53404 :       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       53404 :   LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
     522             :                                    ELF::SHF_ALLOC);
     523             : 
     524       26702 :   COFFDebugSymbolsSection = nullptr;
     525       26702 :   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             :   if (T.isMIPS())
     533             :     DebugSecType = ELF::SHT_MIPS_DWARF;
     534             : 
     535             :   // Debug Info Sections.
     536       26702 :   DwarfAbbrevSection =
     537       53404 :       Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);
     538       53404 :   DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);
     539       53404 :   DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);
     540       26702 :   DwarfLineStrSection =
     541       53404 :       Ctx->getELFSection(".debug_line_str", DebugSecType,
     542             :                          ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
     543       53404 :   DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);
     544       26702 :   DwarfPubNamesSection =
     545       53404 :       Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);
     546       26702 :   DwarfPubTypesSection =
     547       53404 :       Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);
     548       26702 :   DwarfGnuPubNamesSection =
     549       53404 :       Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);
     550       26702 :   DwarfGnuPubTypesSection =
     551       53404 :       Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);
     552       26702 :   DwarfStrSection =
     553       53404 :       Ctx->getELFSection(".debug_str", DebugSecType,
     554             :                          ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
     555       53404 :   DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);
     556       26702 :   DwarfARangesSection =
     557       53404 :       Ctx->getELFSection(".debug_aranges", DebugSecType, 0);
     558       26702 :   DwarfRangesSection =
     559       53404 :       Ctx->getELFSection(".debug_ranges", DebugSecType, 0);
     560       26702 :   DwarfMacinfoSection =
     561       53404 :       Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);
     562             : 
     563             :   // DWARF5 Experimental Debug Info
     564             : 
     565             :   // Accelerator Tables
     566       26702 :   DwarfDebugNamesSection =
     567       53404 :       Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);
     568       26702 :   DwarfAccelNamesSection =
     569       53404 :       Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);
     570       26702 :   DwarfAccelObjCSection =
     571       53404 :       Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);
     572       26702 :   DwarfAccelNamespaceSection =
     573       53404 :       Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);
     574       26702 :   DwarfAccelTypesSection =
     575       53404 :       Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);
     576             : 
     577             :   // String Offset and Address Sections
     578       26702 :   DwarfStrOffSection =
     579       53404 :       Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);
     580       53404 :   DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);
     581             : 
     582             :   // Fission Sections
     583       26702 :   DwarfInfoDWOSection =
     584       53404 :       Ctx->getELFSection(".debug_info.dwo", DebugSecType, 0);
     585       26702 :   DwarfTypesDWOSection =
     586       53404 :       Ctx->getELFSection(".debug_types.dwo", DebugSecType, 0);
     587       26702 :   DwarfAbbrevDWOSection =
     588       53404 :       Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, 0);
     589       26702 :   DwarfStrDWOSection =
     590       53404 :       Ctx->getELFSection(".debug_str.dwo", DebugSecType,
     591             :                          ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
     592       26702 :   DwarfLineDWOSection =
     593       53404 :       Ctx->getELFSection(".debug_line.dwo", DebugSecType, 0);
     594       26702 :   DwarfLocDWOSection =
     595       53404 :       Ctx->getELFSection(".debug_loc.dwo", DebugSecType, 0);
     596       26702 :   DwarfStrOffDWOSection =
     597       53404 :       Ctx->getELFSection(".debug_str_offsets.dwo", DebugSecType, 0);
     598             : 
     599             :   // DWP Sections
     600       26702 :   DwarfCUIndexSection =
     601       53404 :       Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
     602       26702 :   DwarfTUIndexSection =
     603       53404 :       Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);
     604             : 
     605       26702 :   StackMapSection =
     606       53404 :       Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
     607             : 
     608       26702 :   FaultMapSection =
     609       53404 :       Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
     610             : 
     611       26702 :   EHFrameSection =
     612       53404 :       Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
     613             : 
     614       53404 :   StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);
     615       26702 : }
     616             : 
     617         976 : void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {
     618        1952 :   EHFrameSection = Ctx->getCOFFSection(
     619             :       ".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     620             :                        COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
     621             :       SectionKind::getData());
     622             : 
     623             :   // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode.  This is
     624             :   // used to indicate to the linker that the text segment contains thumb instructions
     625             :   // and to set the ISA selection bit for calls accordingly.
     626         976 :   const bool IsThumb = T.getArch() == Triple::thumb;
     627             : 
     628         976 :   CommDirectiveSupportsAlignment = true;
     629             : 
     630             :   // COFF
     631        1952 :   BSSSection = Ctx->getCOFFSection(
     632             :       ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
     633             :                   COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
     634             :       SectionKind::getBSS());
     635        1952 :   TextSection = Ctx->getCOFFSection(
     636             :       ".text",
     637             :       (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
     638             :           COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
     639             :           COFF::IMAGE_SCN_MEM_READ,
     640             :       SectionKind::getText());
     641        1952 :   DataSection = Ctx->getCOFFSection(
     642             :       ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
     643             :                    COFF::IMAGE_SCN_MEM_WRITE,
     644             :       SectionKind::getData());
     645        1952 :   ReadOnlySection = Ctx->getCOFFSection(
     646             :       ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
     647             :       SectionKind::getReadOnly());
     648             : 
     649             :   // FIXME: We're emitting LSDA info into a readonly section on COFF, even
     650             :   // though it contains relocatable pointers.  In PIC mode, this is probably a
     651             :   // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
     652             :   // adjusted or this should be a data section.
     653         976 :   if (T.getArch() == Triple::x86_64) {
     654             :     // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
     655         484 :     LSDASection = nullptr;
     656             :   } else {
     657         984 :     LSDASection = Ctx->getCOFFSection(".gcc_except_table",
     658             :                                       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     659             :                                           COFF::IMAGE_SCN_MEM_READ,
     660             :                                       SectionKind::getReadOnly());
     661             :   }
     662             : 
     663             :   // Debug info.
     664         976 :   COFFDebugSymbolsSection =
     665        2928 :       Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
     666             :                                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     667             :                                        COFF::IMAGE_SCN_MEM_READ),
     668             :                           SectionKind::getMetadata());
     669         976 :   COFFDebugTypesSection =
     670        2928 :       Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |
     671             :                                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     672             :                                        COFF::IMAGE_SCN_MEM_READ),
     673             :                           SectionKind::getMetadata());
     674        1952 :   COFFGlobalTypeHashesSection = Ctx->getCOFFSection(
     675             :       ".debug$H",
     676             :       (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     677             :        COFF::IMAGE_SCN_MEM_READ),
     678             :       SectionKind::getMetadata());
     679             : 
     680        1952 :   DwarfAbbrevSection = Ctx->getCOFFSection(
     681             :       ".debug_abbrev",
     682             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     683             :           COFF::IMAGE_SCN_MEM_READ,
     684             :       SectionKind::getMetadata(), "section_abbrev");
     685        1952 :   DwarfInfoSection = Ctx->getCOFFSection(
     686             :       ".debug_info",
     687             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     688             :           COFF::IMAGE_SCN_MEM_READ,
     689             :       SectionKind::getMetadata(), "section_info");
     690        1952 :   DwarfLineSection = Ctx->getCOFFSection(
     691             :       ".debug_line",
     692             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     693             :           COFF::IMAGE_SCN_MEM_READ,
     694             :       SectionKind::getMetadata(), "section_line");
     695        1952 :   DwarfLineStrSection = Ctx->getCOFFSection(
     696             :       ".debug_line_str",
     697             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     698             :           COFF::IMAGE_SCN_MEM_READ,
     699             :       SectionKind::getMetadata(), "section_line_str");
     700        1952 :   DwarfFrameSection = Ctx->getCOFFSection(
     701             :       ".debug_frame",
     702             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     703             :           COFF::IMAGE_SCN_MEM_READ,
     704             :       SectionKind::getMetadata());
     705        1952 :   DwarfPubNamesSection = Ctx->getCOFFSection(
     706             :       ".debug_pubnames",
     707             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     708             :           COFF::IMAGE_SCN_MEM_READ,
     709             :       SectionKind::getMetadata());
     710        1952 :   DwarfPubTypesSection = Ctx->getCOFFSection(
     711             :       ".debug_pubtypes",
     712             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     713             :           COFF::IMAGE_SCN_MEM_READ,
     714             :       SectionKind::getMetadata());
     715        1952 :   DwarfGnuPubNamesSection = Ctx->getCOFFSection(
     716             :       ".debug_gnu_pubnames",
     717             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     718             :           COFF::IMAGE_SCN_MEM_READ,
     719             :       SectionKind::getMetadata());
     720        1952 :   DwarfGnuPubTypesSection = Ctx->getCOFFSection(
     721             :       ".debug_gnu_pubtypes",
     722             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     723             :           COFF::IMAGE_SCN_MEM_READ,
     724             :       SectionKind::getMetadata());
     725        1952 :   DwarfStrSection = Ctx->getCOFFSection(
     726             :       ".debug_str",
     727             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     728             :           COFF::IMAGE_SCN_MEM_READ,
     729             :       SectionKind::getMetadata(), "info_string");
     730        1952 :   DwarfStrOffSection = Ctx->getCOFFSection(
     731             :       ".debug_str_offsets",
     732             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     733             :           COFF::IMAGE_SCN_MEM_READ,
     734             :       SectionKind::getMetadata(), "section_str_off");
     735        1952 :   DwarfLocSection = Ctx->getCOFFSection(
     736             :       ".debug_loc",
     737             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     738             :           COFF::IMAGE_SCN_MEM_READ,
     739             :       SectionKind::getMetadata(), "section_debug_loc");
     740        1952 :   DwarfARangesSection = Ctx->getCOFFSection(
     741             :       ".debug_aranges",
     742             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     743             :           COFF::IMAGE_SCN_MEM_READ,
     744             :       SectionKind::getMetadata());
     745        1952 :   DwarfRangesSection = Ctx->getCOFFSection(
     746             :       ".debug_ranges",
     747             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     748             :           COFF::IMAGE_SCN_MEM_READ,
     749             :       SectionKind::getMetadata(), "debug_range");
     750        1952 :   DwarfMacinfoSection = Ctx->getCOFFSection(
     751             :       ".debug_macinfo",
     752             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     753             :           COFF::IMAGE_SCN_MEM_READ,
     754             :       SectionKind::getMetadata(), "debug_macinfo");
     755        1952 :   DwarfInfoDWOSection = Ctx->getCOFFSection(
     756             :       ".debug_info.dwo",
     757             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     758             :           COFF::IMAGE_SCN_MEM_READ,
     759             :       SectionKind::getMetadata(), "section_info_dwo");
     760        1952 :   DwarfTypesDWOSection = Ctx->getCOFFSection(
     761             :       ".debug_types.dwo",
     762             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     763             :           COFF::IMAGE_SCN_MEM_READ,
     764             :       SectionKind::getMetadata(), "section_types_dwo");
     765        1952 :   DwarfAbbrevDWOSection = Ctx->getCOFFSection(
     766             :       ".debug_abbrev.dwo",
     767             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     768             :           COFF::IMAGE_SCN_MEM_READ,
     769             :       SectionKind::getMetadata(), "section_abbrev_dwo");
     770        1952 :   DwarfStrDWOSection = Ctx->getCOFFSection(
     771             :       ".debug_str.dwo",
     772             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     773             :           COFF::IMAGE_SCN_MEM_READ,
     774             :       SectionKind::getMetadata(), "skel_string");
     775        1952 :   DwarfLineDWOSection = Ctx->getCOFFSection(
     776             :       ".debug_line.dwo",
     777             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     778             :           COFF::IMAGE_SCN_MEM_READ,
     779             :       SectionKind::getMetadata());
     780        1952 :   DwarfLocDWOSection = Ctx->getCOFFSection(
     781             :       ".debug_loc.dwo",
     782             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     783             :           COFF::IMAGE_SCN_MEM_READ,
     784             :       SectionKind::getMetadata(), "skel_loc");
     785        1952 :   DwarfStrOffDWOSection = Ctx->getCOFFSection(
     786             :       ".debug_str_offsets.dwo",
     787             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     788             :           COFF::IMAGE_SCN_MEM_READ,
     789             :       SectionKind::getMetadata(), "section_str_off_dwo");
     790        1952 :   DwarfAddrSection = Ctx->getCOFFSection(
     791             :       ".debug_addr",
     792             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     793             :           COFF::IMAGE_SCN_MEM_READ,
     794             :       SectionKind::getMetadata(), "addr_sec");
     795        1952 :   DwarfCUIndexSection = Ctx->getCOFFSection(
     796             :       ".debug_cu_index",
     797             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     798             :           COFF::IMAGE_SCN_MEM_READ,
     799             :       SectionKind::getMetadata());
     800        1952 :   DwarfTUIndexSection = Ctx->getCOFFSection(
     801             :       ".debug_tu_index",
     802             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     803             :           COFF::IMAGE_SCN_MEM_READ,
     804             :       SectionKind::getMetadata());
     805        1952 :   DwarfDebugNamesSection = Ctx->getCOFFSection(
     806             :       ".debug_names",
     807             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     808             :           COFF::IMAGE_SCN_MEM_READ,
     809             :       SectionKind::getMetadata(), "debug_names_begin");
     810        1952 :   DwarfAccelNamesSection = Ctx->getCOFFSection(
     811             :       ".apple_names",
     812             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     813             :           COFF::IMAGE_SCN_MEM_READ,
     814             :       SectionKind::getMetadata(), "names_begin");
     815        1952 :   DwarfAccelNamespaceSection = Ctx->getCOFFSection(
     816             :       ".apple_namespaces",
     817             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     818             :           COFF::IMAGE_SCN_MEM_READ,
     819             :       SectionKind::getMetadata(), "namespac_begin");
     820        1952 :   DwarfAccelTypesSection = Ctx->getCOFFSection(
     821             :       ".apple_types",
     822             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     823             :           COFF::IMAGE_SCN_MEM_READ,
     824             :       SectionKind::getMetadata(), "types_begin");
     825        1952 :   DwarfAccelObjCSection = Ctx->getCOFFSection(
     826             :       ".apple_objc",
     827             :       COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     828             :           COFF::IMAGE_SCN_MEM_READ,
     829             :       SectionKind::getMetadata(), "objc_begin");
     830             : 
     831        1952 :   DrectveSection = Ctx->getCOFFSection(
     832             :       ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
     833             :       SectionKind::getMetadata());
     834             : 
     835        1952 :   PDataSection = Ctx->getCOFFSection(
     836             :       ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
     837             :       SectionKind::getData());
     838             : 
     839        1952 :   XDataSection = Ctx->getCOFFSection(
     840             :       ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
     841             :       SectionKind::getData());
     842             : 
     843        1952 :   SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
     844             :                                       SectionKind::getMetadata());
     845             : 
     846        1952 :   GFIDsSection = Ctx->getCOFFSection(".gfids$y",
     847             :                                      COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     848             :                                          COFF::IMAGE_SCN_MEM_READ,
     849             :                                      SectionKind::getMetadata());
     850             : 
     851        1952 :   TLSDataSection = Ctx->getCOFFSection(
     852             :       ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
     853             :                    COFF::IMAGE_SCN_MEM_WRITE,
     854             :       SectionKind::getData());
     855             : 
     856        1952 :   StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
     857             :                                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
     858             :                                             COFF::IMAGE_SCN_MEM_READ,
     859             :                                         SectionKind::getReadOnly());
     860         976 : }
     861             : 
     862         265 : void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {
     863         530 :   TextSection = Ctx->getWasmSection(".text", SectionKind::getText());
     864         530 :   DataSection = Ctx->getWasmSection(".data", SectionKind::getData());
     865             : 
     866         265 :   DwarfLineSection =
     867         530 :       Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());
     868         265 :   DwarfLineStrSection =
     869         530 :       Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata());
     870         265 :   DwarfStrSection =
     871         530 :       Ctx->getWasmSection(".debug_str", SectionKind::getMetadata());
     872         265 :   DwarfLocSection =
     873         530 :       Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());
     874         265 :   DwarfAbbrevSection =
     875         530 :       Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());
     876         530 :   DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());
     877         265 :   DwarfRangesSection =
     878         530 :       Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());
     879         265 :   DwarfMacinfoSection =
     880         530 :       Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());
     881         530 :   DwarfAddrSection = Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());
     882         530 :   DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());
     883         530 :   DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());
     884         265 :   DwarfInfoSection =
     885         530 :       Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());
     886         530 :   DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());
     887         530 :   DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());
     888         530 :   DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());
     889             : 
     890             :   // TODO: Define more sections.
     891         265 : }
     892             : 
     893       31345 : void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
     894             :                                             MCContext &ctx,
     895             :                                             bool LargeCodeModel) {
     896       31345 :   PositionIndependent = PIC;
     897       31345 :   Ctx = &ctx;
     898             : 
     899             :   // Common.
     900       31345 :   CommDirectiveSupportsAlignment = true;
     901       31345 :   SupportsWeakOmittedEHFrame = true;
     902       31345 :   SupportsCompactUnwindWithoutEHFrame = false;
     903       31345 :   OmitDwarfIfHaveCompactUnwind = false;
     904             : 
     905       31345 :   PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
     906             :       dwarf::DW_EH_PE_absptr;
     907             : 
     908       31345 :   CompactUnwindDwarfEHFrameOnly = 0;
     909             : 
     910       31345 :   EHFrameSection = nullptr;             // Created on demand.
     911       31345 :   CompactUnwindSection = nullptr;       // Used only by selected targets.
     912       31345 :   DwarfAccelNamesSection = nullptr;     // Used only by selected targets.
     913       31345 :   DwarfAccelObjCSection = nullptr;      // Used only by selected targets.
     914       31345 :   DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
     915       31345 :   DwarfAccelTypesSection = nullptr;     // Used only by selected targets.
     916             : 
     917       31345 :   TT = TheTriple;
     918             : 
     919       31345 :   switch (TT.getObjectFormat()) {
     920        3402 :   case Triple::MachO:
     921        3402 :     Env = IsMachO;
     922        3402 :     initMachOMCObjectFileInfo(TT);
     923        3402 :     break;
     924         976 :   case Triple::COFF:
     925         976 :     if (!TT.isOSWindows())
     926           0 :       report_fatal_error(
     927             :           "Cannot initialize MC for non-Windows COFF object files.");
     928             : 
     929         976 :     Env = IsCOFF;
     930         976 :     initCOFFMCObjectFileInfo(TT);
     931         976 :     break;
     932       26702 :   case Triple::ELF:
     933       26702 :     Env = IsELF;
     934       26702 :     initELFMCObjectFileInfo(TT, LargeCodeModel);
     935       26702 :     break;
     936         265 :   case Triple::Wasm:
     937         265 :     Env = IsWasm;
     938         265 :     initWasmMCObjectFileInfo(TT);
     939         265 :     break;
     940           0 :   case Triple::UnknownObjectFormat:
     941           0 :     report_fatal_error("Cannot initialize MC for unknown object file format.");
     942             :     break;
     943             :   }
     944       31345 : }
     945             : 
     946          20 : MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
     947          40 :   return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
     948          40 :                             0, utostr(Hash));
     949             : }
     950             : 
     951             : MCSection *
     952          20 : MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {
     953          20 :   if (Env != IsELF)
     954           0 :     return StackSizesSection;
     955             : 
     956             :   const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
     957             :   unsigned Flags = ELF::SHF_LINK_ORDER;
     958          20 :   StringRef GroupName;
     959          20 :   if (const MCSymbol *Group = ElfSec.getGroup()) {
     960           2 :     GroupName = Group->getName();
     961             :     Flags |= ELF::SHF_GROUP;
     962             :   }
     963             : 
     964             :   const MCSymbol *Link = TextSec.getBeginSymbol();
     965          40 :   auto It = StackSizesUniquing.insert({Link, StackSizesUniquing.size()});
     966          20 :   unsigned UniqueID = It.first->second;
     967             : 
     968          40 :   return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
     969          20 :                             GroupName, UniqueID, cast<MCSymbolELF>(Link));
     970             : }

Generated by: LCOV version 1.13