Home | History | Annotate | Download | only in MC
      1 //===-- MObjectFileInfo.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/Triple.h"
     12 #include "llvm/MC/MCContext.h"
     13 #include "llvm/MC/MCSection.h"
     14 #include "llvm/MC/MCSectionCOFF.h"
     15 #include "llvm/MC/MCSectionELF.h"
     16 #include "llvm/MC/MCSectionMachO.h"
     17 using namespace llvm;
     18 
     19 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
     20   // MachO
     21   IsFunctionEHFrameSymbolPrivate = false;
     22   SupportsWeakOmittedEHFrame = false;
     23 
     24   PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
     25     | dwarf::DW_EH_PE_sdata4;
     26   LSDAEncoding = FDEEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
     27   TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
     28     dwarf::DW_EH_PE_sdata4;
     29 
     30   // .comm doesn't support alignment before Leopard.
     31   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
     32     CommDirectiveSupportsAlignment = false;
     33 
     34   TextSection // .text
     35     = Ctx->getMachOSection("__TEXT", "__text",
     36                            MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
     37                            SectionKind::getText());
     38   DataSection // .data
     39     = Ctx->getMachOSection("__DATA", "__data", 0,
     40                            SectionKind::getDataRel());
     41 
     42   TLSDataSection // .tdata
     43     = Ctx->getMachOSection("__DATA", "__thread_data",
     44                            MCSectionMachO::S_THREAD_LOCAL_REGULAR,
     45                            SectionKind::getDataRel());
     46   TLSBSSSection // .tbss
     47     = Ctx->getMachOSection("__DATA", "__thread_bss",
     48                            MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
     49                            SectionKind::getThreadBSS());
     50 
     51   // TODO: Verify datarel below.
     52   TLSTLVSection // .tlv
     53     = Ctx->getMachOSection("__DATA", "__thread_vars",
     54                            MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
     55                            SectionKind::getDataRel());
     56 
     57   TLSThreadInitSection
     58     = Ctx->getMachOSection("__DATA", "__thread_init",
     59                           MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
     60                           SectionKind::getDataRel());
     61 
     62   CStringSection // .cstring
     63     = Ctx->getMachOSection("__TEXT", "__cstring",
     64                            MCSectionMachO::S_CSTRING_LITERALS,
     65                            SectionKind::getMergeable1ByteCString());
     66   UStringSection
     67     = Ctx->getMachOSection("__TEXT","__ustring", 0,
     68                            SectionKind::getMergeable2ByteCString());
     69   FourByteConstantSection // .literal4
     70     = Ctx->getMachOSection("__TEXT", "__literal4",
     71                            MCSectionMachO::S_4BYTE_LITERALS,
     72                            SectionKind::getMergeableConst4());
     73   EightByteConstantSection // .literal8
     74     = Ctx->getMachOSection("__TEXT", "__literal8",
     75                            MCSectionMachO::S_8BYTE_LITERALS,
     76                            SectionKind::getMergeableConst8());
     77 
     78   // ld_classic doesn't support .literal16 in 32-bit mode, and ld64 falls back
     79   // to using it in -static mode.
     80   SixteenByteConstantSection = 0;
     81   if (RelocM != Reloc::Static &&
     82       T.getArch() != Triple::x86_64 && T.getArch() != Triple::ppc64 &&
     83       T.getArch() != Triple::ppc64le)
     84     SixteenByteConstantSection =   // .literal16
     85       Ctx->getMachOSection("__TEXT", "__literal16",
     86                            MCSectionMachO::S_16BYTE_LITERALS,
     87                            SectionKind::getMergeableConst16());
     88 
     89   ReadOnlySection  // .const
     90     = Ctx->getMachOSection("__TEXT", "__const", 0,
     91                            SectionKind::getReadOnly());
     92 
     93   TextCoalSection
     94     = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
     95                            MCSectionMachO::S_COALESCED |
     96                            MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
     97                            SectionKind::getText());
     98   ConstTextCoalSection
     99     = Ctx->getMachOSection("__TEXT", "__const_coal",
    100                            MCSectionMachO::S_COALESCED,
    101                            SectionKind::getReadOnly());
    102   ConstDataSection  // .const_data
    103     = Ctx->getMachOSection("__DATA", "__const", 0,
    104                            SectionKind::getReadOnlyWithRel());
    105   DataCoalSection
    106     = Ctx->getMachOSection("__DATA","__datacoal_nt",
    107                            MCSectionMachO::S_COALESCED,
    108                            SectionKind::getDataRel());
    109   DataCommonSection
    110     = Ctx->getMachOSection("__DATA","__common",
    111                            MCSectionMachO::S_ZEROFILL,
    112                            SectionKind::getBSS());
    113   DataBSSSection
    114     = Ctx->getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
    115                            SectionKind::getBSS());
    116 
    117 
    118   LazySymbolPointerSection
    119     = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
    120                            MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
    121                            SectionKind::getMetadata());
    122   NonLazySymbolPointerSection
    123     = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
    124                            MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
    125                            SectionKind::getMetadata());
    126 
    127   if (RelocM == Reloc::Static) {
    128     StaticCtorSection
    129       = Ctx->getMachOSection("__TEXT", "__constructor", 0,
    130                              SectionKind::getDataRel());
    131     StaticDtorSection
    132       = Ctx->getMachOSection("__TEXT", "__destructor", 0,
    133                              SectionKind::getDataRel());
    134   } else {
    135     StaticCtorSection
    136       = Ctx->getMachOSection("__DATA", "__mod_init_func",
    137                              MCSectionMachO::S_MOD_INIT_FUNC_POINTERS,
    138                              SectionKind::getDataRel());
    139     StaticDtorSection
    140       = Ctx->getMachOSection("__DATA", "__mod_term_func",
    141                              MCSectionMachO::S_MOD_TERM_FUNC_POINTERS,
    142                              SectionKind::getDataRel());
    143   }
    144 
    145   // Exception Handling.
    146   LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
    147                                      SectionKind::getReadOnlyWithRel());
    148 
    149   if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) {
    150     CompactUnwindSection =
    151       Ctx->getMachOSection("__LD", "__compact_unwind",
    152                            MCSectionMachO::S_ATTR_DEBUG,
    153                            SectionKind::getReadOnly());
    154 
    155     if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
    156       CompactUnwindDwarfEHFrameOnly = 0x04000000;
    157   }
    158 
    159   // Debug Information.
    160   DwarfAccelNamesSection =
    161     Ctx->getMachOSection("__DWARF", "__apple_names",
    162                          MCSectionMachO::S_ATTR_DEBUG,
    163                          SectionKind::getMetadata());
    164   DwarfAccelObjCSection =
    165     Ctx->getMachOSection("__DWARF", "__apple_objc",
    166                          MCSectionMachO::S_ATTR_DEBUG,
    167                          SectionKind::getMetadata());
    168   // 16 character section limit...
    169   DwarfAccelNamespaceSection =
    170     Ctx->getMachOSection("__DWARF", "__apple_namespac",
    171                          MCSectionMachO::S_ATTR_DEBUG,
    172                          SectionKind::getMetadata());
    173   DwarfAccelTypesSection =
    174     Ctx->getMachOSection("__DWARF", "__apple_types",
    175                          MCSectionMachO::S_ATTR_DEBUG,
    176                          SectionKind::getMetadata());
    177 
    178   DwarfAbbrevSection =
    179     Ctx->getMachOSection("__DWARF", "__debug_abbrev",
    180                          MCSectionMachO::S_ATTR_DEBUG,
    181                          SectionKind::getMetadata());
    182   DwarfInfoSection =
    183     Ctx->getMachOSection("__DWARF", "__debug_info",
    184                          MCSectionMachO::S_ATTR_DEBUG,
    185                          SectionKind::getMetadata());
    186   DwarfLineSection =
    187     Ctx->getMachOSection("__DWARF", "__debug_line",
    188                          MCSectionMachO::S_ATTR_DEBUG,
    189                          SectionKind::getMetadata());
    190   DwarfFrameSection =
    191     Ctx->getMachOSection("__DWARF", "__debug_frame",
    192                          MCSectionMachO::S_ATTR_DEBUG,
    193                          SectionKind::getMetadata());
    194   DwarfPubNamesSection =
    195     Ctx->getMachOSection("__DWARF", "__debug_pubnames",
    196                          MCSectionMachO::S_ATTR_DEBUG,
    197                          SectionKind::getMetadata());
    198   DwarfPubTypesSection =
    199     Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
    200                          MCSectionMachO::S_ATTR_DEBUG,
    201                          SectionKind::getMetadata());
    202   DwarfStrSection =
    203     Ctx->getMachOSection("__DWARF", "__debug_str",
    204                          MCSectionMachO::S_ATTR_DEBUG,
    205                          SectionKind::getMetadata());
    206   DwarfLocSection =
    207     Ctx->getMachOSection("__DWARF", "__debug_loc",
    208                          MCSectionMachO::S_ATTR_DEBUG,
    209                          SectionKind::getMetadata());
    210   DwarfARangesSection =
    211     Ctx->getMachOSection("__DWARF", "__debug_aranges",
    212                          MCSectionMachO::S_ATTR_DEBUG,
    213                          SectionKind::getMetadata());
    214   DwarfRangesSection =
    215     Ctx->getMachOSection("__DWARF", "__debug_ranges",
    216                          MCSectionMachO::S_ATTR_DEBUG,
    217                          SectionKind::getMetadata());
    218   DwarfMacroInfoSection =
    219     Ctx->getMachOSection("__DWARF", "__debug_macinfo",
    220                          MCSectionMachO::S_ATTR_DEBUG,
    221                          SectionKind::getMetadata());
    222   DwarfDebugInlineSection =
    223     Ctx->getMachOSection("__DWARF", "__debug_inlined",
    224                          MCSectionMachO::S_ATTR_DEBUG,
    225                          SectionKind::getMetadata());
    226 
    227   TLSExtraDataSection = TLSTLVSection;
    228 }
    229 
    230 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
    231   if (T.getArch() == Triple::mips ||
    232       T.getArch() == Triple::mipsel)
    233     FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
    234   else if (T.getArch() == Triple::mips64 ||
    235            T.getArch() == Triple::mips64el)
    236     FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
    237   else
    238     FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
    239 
    240   if (T.getArch() == Triple::x86) {
    241     PersonalityEncoding = (RelocM == Reloc::PIC_)
    242      ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
    243      : dwarf::DW_EH_PE_absptr;
    244     LSDAEncoding = (RelocM == Reloc::PIC_)
    245       ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
    246       : dwarf::DW_EH_PE_absptr;
    247     FDEEncoding = (RelocM == Reloc::PIC_)
    248       ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
    249       : dwarf::DW_EH_PE_absptr;
    250     TTypeEncoding = (RelocM == Reloc::PIC_)
    251      ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
    252      : dwarf::DW_EH_PE_absptr;
    253   } else if (T.getArch() == Triple::x86_64) {
    254     if (RelocM == Reloc::PIC_) {
    255       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
    256         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
    257          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
    258       LSDAEncoding = dwarf::DW_EH_PE_pcrel |
    259         (CMModel == CodeModel::Small
    260          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
    261       FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
    262       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
    263         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
    264          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
    265     } else {
    266       PersonalityEncoding =
    267         (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
    268         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
    269       LSDAEncoding = (CMModel == CodeModel::Small)
    270         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
    271       FDEEncoding = dwarf::DW_EH_PE_udata4;
    272       TTypeEncoding = (CMModel == CodeModel::Small)
    273         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
    274     }
    275   }  else if (T.getArch() ==  Triple::aarch64) {
    276     // The small model guarantees static code/data size < 4GB, but not where it
    277     // will be in memory. Most of these could end up >2GB away so even a signed
    278     // pc-relative 32-bit address is insufficient, theoretically.
    279     if (RelocM == Reloc::PIC_) {
    280       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
    281         dwarf::DW_EH_PE_sdata8;
    282       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
    283       FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
    284       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
    285         dwarf::DW_EH_PE_sdata8;
    286     } else {
    287       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
    288       LSDAEncoding = dwarf::DW_EH_PE_absptr;
    289       FDEEncoding = dwarf::DW_EH_PE_udata4;
    290       TTypeEncoding = dwarf::DW_EH_PE_absptr;
    291     }
    292   } else if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le) {
    293     PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
    294       dwarf::DW_EH_PE_udata8;
    295     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
    296     FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
    297     TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
    298       dwarf::DW_EH_PE_udata8;
    299   } else if (T.getArch() == Triple::systemz) {
    300     // All currently-defined code models guarantee that 4-byte PC-relative
    301     // values will be in range.
    302     if (RelocM == Reloc::PIC_) {
    303       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
    304         dwarf::DW_EH_PE_sdata4;
    305       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
    306       FDEEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
    307       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
    308         dwarf::DW_EH_PE_sdata4;
    309     } else {
    310       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
    311       LSDAEncoding = dwarf::DW_EH_PE_absptr;
    312       FDEEncoding = dwarf::DW_EH_PE_absptr;
    313       TTypeEncoding = dwarf::DW_EH_PE_absptr;
    314     }
    315   }
    316 
    317   // Solaris requires different flags for .eh_frame to seemingly every other
    318   // platform.
    319   EHSectionType = ELF::SHT_PROGBITS;
    320   EHSectionFlags = ELF::SHF_ALLOC;
    321   if (T.getOS() == Triple::Solaris) {
    322     if (T.getArch() == Triple::x86_64)
    323       EHSectionType = ELF::SHT_X86_64_UNWIND;
    324     else
    325       EHSectionFlags |= ELF::SHF_WRITE;
    326   }
    327 
    328 
    329   // ELF
    330   BSSSection =
    331     Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
    332                        ELF::SHF_WRITE | ELF::SHF_ALLOC,
    333                        SectionKind::getBSS());
    334 
    335   TextSection =
    336     Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
    337                        ELF::SHF_EXECINSTR |
    338                        ELF::SHF_ALLOC,
    339                        SectionKind::getText());
    340 
    341   DataSection =
    342     Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
    343                        ELF::SHF_WRITE |ELF::SHF_ALLOC,
    344                        SectionKind::getDataRel());
    345 
    346   ReadOnlySection =
    347     Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
    348                        ELF::SHF_ALLOC,
    349                        SectionKind::getReadOnly());
    350 
    351   TLSDataSection =
    352     Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
    353                        ELF::SHF_ALLOC | ELF::SHF_TLS |
    354                        ELF::SHF_WRITE,
    355                        SectionKind::getThreadData());
    356 
    357   TLSBSSSection =
    358     Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
    359                        ELF::SHF_ALLOC | ELF::SHF_TLS |
    360                        ELF::SHF_WRITE,
    361                        SectionKind::getThreadBSS());
    362 
    363   DataRelSection =
    364     Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
    365                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
    366                        SectionKind::getDataRel());
    367 
    368   DataRelLocalSection =
    369     Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
    370                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
    371                        SectionKind::getDataRelLocal());
    372 
    373   DataRelROSection =
    374     Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
    375                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
    376                        SectionKind::getReadOnlyWithRel());
    377 
    378   DataRelROLocalSection =
    379     Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
    380                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
    381                        SectionKind::getReadOnlyWithRelLocal());
    382 
    383   MergeableConst4Section =
    384     Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
    385                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
    386                        SectionKind::getMergeableConst4());
    387 
    388   MergeableConst8Section =
    389     Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
    390                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
    391                        SectionKind::getMergeableConst8());
    392 
    393   MergeableConst16Section =
    394     Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
    395                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
    396                        SectionKind::getMergeableConst16());
    397 
    398   StaticCtorSection =
    399     Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
    400                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
    401                        SectionKind::getDataRel());
    402 
    403   StaticDtorSection =
    404     Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
    405                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
    406                        SectionKind::getDataRel());
    407 
    408   // Exception Handling Sections.
    409 
    410   // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
    411   // it contains relocatable pointers.  In PIC mode, this is probably a big
    412   // runtime hit for C++ apps.  Either the contents of the LSDA need to be
    413   // adjusted or this should be a data section.
    414   LSDASection =
    415     Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
    416                        ELF::SHF_ALLOC,
    417                        SectionKind::getReadOnly());
    418 
    419   // Debug Info Sections.
    420   DwarfAbbrevSection =
    421     Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
    422                        SectionKind::getMetadata());
    423   DwarfInfoSection =
    424     Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
    425                        SectionKind::getMetadata());
    426   DwarfLineSection =
    427     Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
    428                        SectionKind::getMetadata());
    429   DwarfFrameSection =
    430     Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
    431                        SectionKind::getMetadata());
    432   DwarfPubNamesSection =
    433     Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
    434                        SectionKind::getMetadata());
    435   DwarfPubTypesSection =
    436     Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
    437                        SectionKind::getMetadata());
    438   DwarfStrSection =
    439     Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
    440                        ELF::SHF_MERGE | ELF::SHF_STRINGS,
    441                        SectionKind::getMergeable1ByteCString());
    442   DwarfLocSection =
    443     Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
    444                        SectionKind::getMetadata());
    445   DwarfARangesSection =
    446     Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
    447                        SectionKind::getMetadata());
    448   DwarfRangesSection =
    449     Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
    450                        SectionKind::getMetadata());
    451   DwarfMacroInfoSection =
    452     Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
    453                        SectionKind::getMetadata());
    454 
    455   // DWARF5 Experimental Debug Info
    456 
    457   // Accelerator Tables
    458   DwarfAccelNamesSection =
    459     Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
    460                        SectionKind::getMetadata());
    461   DwarfAccelObjCSection =
    462     Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
    463                        SectionKind::getMetadata());
    464   DwarfAccelNamespaceSection =
    465     Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
    466                        SectionKind::getMetadata());
    467   DwarfAccelTypesSection =
    468     Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
    469                        SectionKind::getMetadata());
    470 
    471   // Fission Sections
    472   DwarfInfoDWOSection =
    473     Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
    474                        SectionKind::getMetadata());
    475   DwarfAbbrevDWOSection =
    476     Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
    477                        SectionKind::getMetadata());
    478   DwarfStrDWOSection =
    479     Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
    480                        ELF::SHF_MERGE | ELF::SHF_STRINGS,
    481                        SectionKind::getMergeable1ByteCString());
    482   DwarfLineDWOSection =
    483     Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
    484                        SectionKind::getMetadata());
    485   DwarfLocDWOSection =
    486     Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
    487                        SectionKind::getMetadata());
    488   DwarfStrOffDWOSection =
    489     Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
    490                        SectionKind::getMetadata());
    491   DwarfAddrSection =
    492     Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
    493                        SectionKind::getMetadata());
    494 }
    495 
    496 
    497 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
    498   // COFF
    499   TextSection =
    500     Ctx->getCOFFSection(".text",
    501                         COFF::IMAGE_SCN_CNT_CODE |
    502                         COFF::IMAGE_SCN_MEM_EXECUTE |
    503                         COFF::IMAGE_SCN_MEM_READ,
    504                         SectionKind::getText());
    505   DataSection =
    506     Ctx->getCOFFSection(".data",
    507                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    508                         COFF::IMAGE_SCN_MEM_READ |
    509                         COFF::IMAGE_SCN_MEM_WRITE,
    510                         SectionKind::getDataRel());
    511   ReadOnlySection =
    512     Ctx->getCOFFSection(".rdata",
    513                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    514                         COFF::IMAGE_SCN_MEM_READ,
    515                         SectionKind::getReadOnly());
    516   if (T.getOS() == Triple::Win32) {
    517     StaticCtorSection =
    518       Ctx->getCOFFSection(".CRT$XCU",
    519                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    520                           COFF::IMAGE_SCN_MEM_READ,
    521                           SectionKind::getReadOnly());
    522   } else {
    523     StaticCtorSection =
    524       Ctx->getCOFFSection(".ctors",
    525                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    526                           COFF::IMAGE_SCN_MEM_READ |
    527                           COFF::IMAGE_SCN_MEM_WRITE,
    528                           SectionKind::getDataRel());
    529   }
    530 
    531 
    532   if (T.getOS() == Triple::Win32) {
    533     StaticDtorSection =
    534       Ctx->getCOFFSection(".CRT$XTX",
    535                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    536                           COFF::IMAGE_SCN_MEM_READ,
    537                           SectionKind::getReadOnly());
    538   } else {
    539     StaticDtorSection =
    540       Ctx->getCOFFSection(".dtors",
    541                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    542                           COFF::IMAGE_SCN_MEM_READ |
    543                           COFF::IMAGE_SCN_MEM_WRITE,
    544                           SectionKind::getDataRel());
    545   }
    546 
    547   // FIXME: We're emitting LSDA info into a readonly section on COFF, even
    548   // though it contains relocatable pointers.  In PIC mode, this is probably a
    549   // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
    550   // adjusted or this should be a data section.
    551   LSDASection =
    552     Ctx->getCOFFSection(".gcc_except_table",
    553                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    554                         COFF::IMAGE_SCN_MEM_READ,
    555                         SectionKind::getReadOnly());
    556 
    557   // Debug info.
    558   DwarfAbbrevSection =
    559     Ctx->getCOFFSection(".debug_abbrev",
    560                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    561                         COFF::IMAGE_SCN_MEM_READ,
    562                         SectionKind::getMetadata());
    563   DwarfInfoSection =
    564     Ctx->getCOFFSection(".debug_info",
    565                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    566                         COFF::IMAGE_SCN_MEM_READ,
    567                         SectionKind::getMetadata());
    568   DwarfLineSection =
    569     Ctx->getCOFFSection(".debug_line",
    570                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    571                         COFF::IMAGE_SCN_MEM_READ,
    572                         SectionKind::getMetadata());
    573   DwarfFrameSection =
    574     Ctx->getCOFFSection(".debug_frame",
    575                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    576                         COFF::IMAGE_SCN_MEM_READ,
    577                         SectionKind::getMetadata());
    578   DwarfPubNamesSection =
    579     Ctx->getCOFFSection(".debug_pubnames",
    580                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    581                         COFF::IMAGE_SCN_MEM_READ,
    582                         SectionKind::getMetadata());
    583   DwarfPubTypesSection =
    584     Ctx->getCOFFSection(".debug_pubtypes",
    585                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    586                         COFF::IMAGE_SCN_MEM_READ,
    587                         SectionKind::getMetadata());
    588   DwarfStrSection =
    589     Ctx->getCOFFSection(".debug_str",
    590                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    591                         COFF::IMAGE_SCN_MEM_READ,
    592                         SectionKind::getMetadata());
    593   DwarfLocSection =
    594     Ctx->getCOFFSection(".debug_loc",
    595                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    596                         COFF::IMAGE_SCN_MEM_READ,
    597                         SectionKind::getMetadata());
    598   DwarfARangesSection =
    599     Ctx->getCOFFSection(".debug_aranges",
    600                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    601                         COFF::IMAGE_SCN_MEM_READ,
    602                         SectionKind::getMetadata());
    603   DwarfRangesSection =
    604     Ctx->getCOFFSection(".debug_ranges",
    605                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    606                         COFF::IMAGE_SCN_MEM_READ,
    607                         SectionKind::getMetadata());
    608   DwarfMacroInfoSection =
    609     Ctx->getCOFFSection(".debug_macinfo",
    610                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
    611                         COFF::IMAGE_SCN_MEM_READ,
    612                         SectionKind::getMetadata());
    613 
    614   DrectveSection =
    615     Ctx->getCOFFSection(".drectve",
    616                         COFF::IMAGE_SCN_LNK_INFO,
    617                         SectionKind::getMetadata());
    618 
    619   PDataSection =
    620     Ctx->getCOFFSection(".pdata",
    621                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    622                         COFF::IMAGE_SCN_MEM_READ,
    623                         SectionKind::getDataRel());
    624 
    625   XDataSection =
    626     Ctx->getCOFFSection(".xdata",
    627                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    628                         COFF::IMAGE_SCN_MEM_READ,
    629                         SectionKind::getDataRel());
    630   TLSDataSection =
    631     Ctx->getCOFFSection(".tls$",
    632                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    633                         COFF::IMAGE_SCN_MEM_READ |
    634                         COFF::IMAGE_SCN_MEM_WRITE,
    635                         SectionKind::getDataRel());
    636 }
    637 
    638 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
    639                                             CodeModel::Model cm,
    640                                             MCContext &ctx) {
    641   RelocM = relocm;
    642   CMModel = cm;
    643   Ctx = &ctx;
    644 
    645   // Common.
    646   CommDirectiveSupportsAlignment = true;
    647   SupportsWeakOmittedEHFrame = true;
    648   IsFunctionEHFrameSymbolPrivate = true;
    649 
    650   PersonalityEncoding = LSDAEncoding = FDEEncoding = FDECFIEncoding =
    651     TTypeEncoding = dwarf::DW_EH_PE_absptr;
    652 
    653   CompactUnwindDwarfEHFrameOnly = 0;
    654 
    655   EHFrameSection = 0;             // Created on demand.
    656   CompactUnwindSection = 0;       // Used only by selected targets.
    657   DwarfAccelNamesSection = 0;     // Used only by selected targets.
    658   DwarfAccelObjCSection = 0;      // Used only by selected targets.
    659   DwarfAccelNamespaceSection = 0; // Used only by selected targets.
    660   DwarfAccelTypesSection = 0;     // Used only by selected targets.
    661 
    662   Triple T(TT);
    663   Triple::ArchType Arch = T.getArch();
    664   // FIXME: Checking for Arch here to filter out bogus triples such as
    665   // cellspu-apple-darwin. Perhaps we should fix in Triple?
    666   if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
    667        Arch == Triple::arm || Arch == Triple::thumb ||
    668        Arch == Triple::ppc || Arch == Triple::ppc64 ||
    669        Arch == Triple::UnknownArch) &&
    670       (T.isOSDarwin() || T.getEnvironment() == Triple::MachO)) {
    671     Env = IsMachO;
    672     InitMachOMCObjectFileInfo(T);
    673   } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
    674              (T.getEnvironment() != Triple::ELF) &&
    675              (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
    676               T.getOS() == Triple::Win32)) {
    677     Env = IsCOFF;
    678     InitCOFFMCObjectFileInfo(T);
    679   } else {
    680     Env = IsELF;
    681     InitELFMCObjectFileInfo(T);
    682   }
    683 }
    684 
    685 void MCObjectFileInfo::InitEHFrameSection() {
    686   if (Env == IsMachO)
    687     EHFrameSection =
    688       Ctx->getMachOSection("__TEXT", "__eh_frame",
    689                            MCSectionMachO::S_COALESCED |
    690                            MCSectionMachO::S_ATTR_NO_TOC |
    691                            MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
    692                            MCSectionMachO::S_ATTR_LIVE_SUPPORT,
    693                            SectionKind::getReadOnly());
    694   else if (Env == IsELF)
    695     EHFrameSection =
    696       Ctx->getELFSection(".eh_frame", EHSectionType,
    697                          EHSectionFlags,
    698                          SectionKind::getDataRel());
    699   else
    700     EHFrameSection =
    701       Ctx->getCOFFSection(".eh_frame",
    702                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
    703                           COFF::IMAGE_SCN_MEM_READ |
    704                           COFF::IMAGE_SCN_MEM_WRITE,
    705                           SectionKind::getDataRel());
    706 }
    707