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

Generated by: LCOV version 1.13