LLVM API Documentation

MCObjectFileInfo.cpp
Go to the documentation of this file.
00001 //===-- MObjectFileInfo.cpp - Object File Information ---------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "llvm/MC/MCObjectFileInfo.h"
00011 #include "llvm/ADT/StringExtras.h"
00012 #include "llvm/ADT/Triple.h"
00013 #include "llvm/MC/MCAsmInfo.h"
00014 #include "llvm/MC/MCContext.h"
00015 #include "llvm/MC/MCSection.h"
00016 #include "llvm/MC/MCSectionCOFF.h"
00017 #include "llvm/MC/MCSectionELF.h"
00018 #include "llvm/MC/MCSectionMachO.h"
00019 using namespace llvm;
00020 
00021 static bool useCompactUnwind(const Triple &T) {
00022   // Only on darwin.
00023   if (!T.isOSDarwin())
00024     return false;
00025 
00026   // aarch64 always has it.
00027   if (T.getArch() == Triple::aarch64)
00028     return true;
00029 
00030   // Use it on newer version of OS X.
00031   if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
00032     return true;
00033 
00034   // And the iOS simulator.
00035   if (T.isiOS() &&
00036       (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
00037     return true;
00038 
00039   return false;
00040 }
00041 
00042 void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
00043   // MachO
00044   SupportsWeakOmittedEHFrame = false;
00045 
00046   if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
00047     SupportsCompactUnwindWithoutEHFrame = true;
00048 
00049   PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
00050     | dwarf::DW_EH_PE_sdata4;
00051   LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
00052   TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00053     dwarf::DW_EH_PE_sdata4;
00054 
00055   // .comm doesn't support alignment before Leopard.
00056   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
00057     CommDirectiveSupportsAlignment = false;
00058 
00059   TextSection // .text
00060     = Ctx->getMachOSection("__TEXT", "__text",
00061                            MachO::S_ATTR_PURE_INSTRUCTIONS,
00062                            SectionKind::getText());
00063   DataSection // .data
00064     = Ctx->getMachOSection("__DATA", "__data", 0,
00065                            SectionKind::getDataRel());
00066 
00067   // BSSSection might not be expected initialized on msvc.
00068   BSSSection = nullptr;
00069 
00070   TLSDataSection // .tdata
00071     = Ctx->getMachOSection("__DATA", "__thread_data",
00072                            MachO::S_THREAD_LOCAL_REGULAR,
00073                            SectionKind::getDataRel());
00074   TLSBSSSection // .tbss
00075     = Ctx->getMachOSection("__DATA", "__thread_bss",
00076                            MachO::S_THREAD_LOCAL_ZEROFILL,
00077                            SectionKind::getThreadBSS());
00078 
00079   // TODO: Verify datarel below.
00080   TLSTLVSection // .tlv
00081     = Ctx->getMachOSection("__DATA", "__thread_vars",
00082                            MachO::S_THREAD_LOCAL_VARIABLES,
00083                            SectionKind::getDataRel());
00084 
00085   TLSThreadInitSection
00086     = Ctx->getMachOSection("__DATA", "__thread_init",
00087                           MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
00088                           SectionKind::getDataRel());
00089 
00090   CStringSection // .cstring
00091     = Ctx->getMachOSection("__TEXT", "__cstring",
00092                            MachO::S_CSTRING_LITERALS,
00093                            SectionKind::getMergeable1ByteCString());
00094   UStringSection
00095     = Ctx->getMachOSection("__TEXT","__ustring", 0,
00096                            SectionKind::getMergeable2ByteCString());
00097   FourByteConstantSection // .literal4
00098     = Ctx->getMachOSection("__TEXT", "__literal4",
00099                            MachO::S_4BYTE_LITERALS,
00100                            SectionKind::getMergeableConst4());
00101   EightByteConstantSection // .literal8
00102     = Ctx->getMachOSection("__TEXT", "__literal8",
00103                            MachO::S_8BYTE_LITERALS,
00104                            SectionKind::getMergeableConst8());
00105 
00106   SixteenByteConstantSection // .literal16
00107       = Ctx->getMachOSection("__TEXT", "__literal16",
00108                              MachO::S_16BYTE_LITERALS,
00109                              SectionKind::getMergeableConst16());
00110 
00111   ReadOnlySection  // .const
00112     = Ctx->getMachOSection("__TEXT", "__const", 0,
00113                            SectionKind::getReadOnly());
00114 
00115   TextCoalSection
00116     = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
00117                            MachO::S_COALESCED |
00118                            MachO::S_ATTR_PURE_INSTRUCTIONS,
00119                            SectionKind::getText());
00120   ConstTextCoalSection
00121     = Ctx->getMachOSection("__TEXT", "__const_coal",
00122                            MachO::S_COALESCED,
00123                            SectionKind::getReadOnly());
00124   ConstDataSection  // .const_data
00125     = Ctx->getMachOSection("__DATA", "__const", 0,
00126                            SectionKind::getReadOnlyWithRel());
00127   DataCoalSection
00128     = Ctx->getMachOSection("__DATA","__datacoal_nt",
00129                            MachO::S_COALESCED,
00130                            SectionKind::getDataRel());
00131   DataCommonSection
00132     = Ctx->getMachOSection("__DATA","__common",
00133                            MachO::S_ZEROFILL,
00134                            SectionKind::getBSS());
00135   DataBSSSection
00136     = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
00137                            SectionKind::getBSS());
00138 
00139 
00140   LazySymbolPointerSection
00141     = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
00142                            MachO::S_LAZY_SYMBOL_POINTERS,
00143                            SectionKind::getMetadata());
00144   NonLazySymbolPointerSection
00145     = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
00146                            MachO::S_NON_LAZY_SYMBOL_POINTERS,
00147                            SectionKind::getMetadata());
00148 
00149   if (RelocM == Reloc::Static) {
00150     StaticCtorSection
00151       = Ctx->getMachOSection("__TEXT", "__constructor", 0,
00152                              SectionKind::getDataRel());
00153     StaticDtorSection
00154       = Ctx->getMachOSection("__TEXT", "__destructor", 0,
00155                              SectionKind::getDataRel());
00156   } else {
00157     StaticCtorSection
00158       = Ctx->getMachOSection("__DATA", "__mod_init_func",
00159                              MachO::S_MOD_INIT_FUNC_POINTERS,
00160                              SectionKind::getDataRel());
00161     StaticDtorSection
00162       = Ctx->getMachOSection("__DATA", "__mod_term_func",
00163                              MachO::S_MOD_TERM_FUNC_POINTERS,
00164                              SectionKind::getDataRel());
00165   }
00166 
00167   // Exception Handling.
00168   LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
00169                                      SectionKind::getReadOnlyWithRel());
00170 
00171   COFFDebugSymbolsSection = nullptr;
00172 
00173   if (useCompactUnwind(T)) {
00174     CompactUnwindSection =
00175         Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
00176                              SectionKind::getReadOnly());
00177 
00178     if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
00179       CompactUnwindDwarfEHFrameOnly = 0x04000000;
00180     else if (T.getArch() == Triple::aarch64)
00181       CompactUnwindDwarfEHFrameOnly = 0x03000000;
00182   }
00183 
00184   // Debug Information.
00185   DwarfAccelNamesSection =
00186     Ctx->getMachOSection("__DWARF", "__apple_names",
00187                          MachO::S_ATTR_DEBUG,
00188                          SectionKind::getMetadata());
00189   DwarfAccelObjCSection =
00190     Ctx->getMachOSection("__DWARF", "__apple_objc",
00191                          MachO::S_ATTR_DEBUG,
00192                          SectionKind::getMetadata());
00193   // 16 character section limit...
00194   DwarfAccelNamespaceSection =
00195     Ctx->getMachOSection("__DWARF", "__apple_namespac",
00196                          MachO::S_ATTR_DEBUG,
00197                          SectionKind::getMetadata());
00198   DwarfAccelTypesSection =
00199     Ctx->getMachOSection("__DWARF", "__apple_types",
00200                          MachO::S_ATTR_DEBUG,
00201                          SectionKind::getMetadata());
00202 
00203   DwarfAbbrevSection =
00204     Ctx->getMachOSection("__DWARF", "__debug_abbrev",
00205                          MachO::S_ATTR_DEBUG,
00206                          SectionKind::getMetadata());
00207   DwarfInfoSection =
00208     Ctx->getMachOSection("__DWARF", "__debug_info",
00209                          MachO::S_ATTR_DEBUG,
00210                          SectionKind::getMetadata());
00211   DwarfLineSection =
00212     Ctx->getMachOSection("__DWARF", "__debug_line",
00213                          MachO::S_ATTR_DEBUG,
00214                          SectionKind::getMetadata());
00215   DwarfFrameSection =
00216     Ctx->getMachOSection("__DWARF", "__debug_frame",
00217                          MachO::S_ATTR_DEBUG,
00218                          SectionKind::getMetadata());
00219   DwarfPubNamesSection =
00220     Ctx->getMachOSection("__DWARF", "__debug_pubnames",
00221                          MachO::S_ATTR_DEBUG,
00222                          SectionKind::getMetadata());
00223   DwarfPubTypesSection =
00224     Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
00225                          MachO::S_ATTR_DEBUG,
00226                          SectionKind::getMetadata());
00227   DwarfGnuPubNamesSection =
00228     Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
00229                          MachO::S_ATTR_DEBUG,
00230                          SectionKind::getMetadata());
00231   DwarfGnuPubTypesSection =
00232     Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
00233                          MachO::S_ATTR_DEBUG,
00234                          SectionKind::getMetadata());
00235   DwarfStrSection =
00236     Ctx->getMachOSection("__DWARF", "__debug_str",
00237                          MachO::S_ATTR_DEBUG,
00238                          SectionKind::getMetadata());
00239   DwarfLocSection =
00240     Ctx->getMachOSection("__DWARF", "__debug_loc",
00241                          MachO::S_ATTR_DEBUG,
00242                          SectionKind::getMetadata());
00243   DwarfARangesSection =
00244     Ctx->getMachOSection("__DWARF", "__debug_aranges",
00245                          MachO::S_ATTR_DEBUG,
00246                          SectionKind::getMetadata());
00247   DwarfRangesSection =
00248     Ctx->getMachOSection("__DWARF", "__debug_ranges",
00249                          MachO::S_ATTR_DEBUG,
00250                          SectionKind::getMetadata());
00251   DwarfMacroInfoSection =
00252     Ctx->getMachOSection("__DWARF", "__debug_macinfo",
00253                          MachO::S_ATTR_DEBUG,
00254                          SectionKind::getMetadata());
00255   DwarfDebugInlineSection =
00256     Ctx->getMachOSection("__DWARF", "__debug_inlined",
00257                          MachO::S_ATTR_DEBUG,
00258                          SectionKind::getMetadata());
00259   StackMapSection =
00260     Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
00261                          SectionKind::getMetadata());
00262 
00263   TLSExtraDataSection = TLSTLVSection;
00264 }
00265 
00266 void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
00267   switch (T.getArch()) {
00268   case Triple::mips:
00269   case Triple::mipsel:
00270     FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
00271     break;
00272   case Triple::mips64:
00273   case Triple::mips64el:
00274     FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
00275     break;
00276   default:
00277     FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
00278     break;
00279   }
00280 
00281   switch (T.getArch()) {
00282   case Triple::arm:
00283   case Triple::armeb:
00284   case Triple::thumb:
00285   case Triple::thumbeb:
00286     if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
00287       break;
00288     // Fallthrough if not using EHABI
00289   case Triple::ppc:
00290   case Triple::x86:
00291     PersonalityEncoding = (RelocM == Reloc::PIC_)
00292      ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
00293      : dwarf::DW_EH_PE_absptr;
00294     LSDAEncoding = (RelocM == Reloc::PIC_)
00295       ? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
00296       : dwarf::DW_EH_PE_absptr;
00297     TTypeEncoding = (RelocM == Reloc::PIC_)
00298      ? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
00299      : dwarf::DW_EH_PE_absptr;
00300     break;
00301   case Triple::x86_64:
00302     if (RelocM == Reloc::PIC_) {
00303       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00304         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
00305          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
00306       LSDAEncoding = dwarf::DW_EH_PE_pcrel |
00307         (CMModel == CodeModel::Small
00308          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
00309       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00310         ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
00311          ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
00312     } else {
00313       PersonalityEncoding =
00314         (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
00315         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
00316       LSDAEncoding = (CMModel == CodeModel::Small)
00317         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
00318       TTypeEncoding = (CMModel == CodeModel::Small)
00319         ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
00320     }
00321     break;
00322   case Triple::aarch64:
00323   case Triple::aarch64_be:
00324     // The small model guarantees static code/data size < 4GB, but not where it
00325     // will be in memory. Most of these could end up >2GB away so even a signed
00326     // pc-relative 32-bit address is insufficient, theoretically.
00327     if (RelocM == Reloc::PIC_) {
00328       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00329         dwarf::DW_EH_PE_sdata8;
00330       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
00331       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00332         dwarf::DW_EH_PE_sdata8;
00333     } else {
00334       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
00335       LSDAEncoding = dwarf::DW_EH_PE_absptr;
00336       TTypeEncoding = dwarf::DW_EH_PE_absptr;
00337     }
00338     break;
00339   case Triple::mips:
00340   case Triple::mipsel:
00341     // MIPS uses indirect pointer to refer personality functions, so that the
00342     // eh_frame section can be read-only.  DW.ref.personality will be generated
00343     // for relocation.
00344     PersonalityEncoding = dwarf::DW_EH_PE_indirect;
00345     break;
00346   case Triple::ppc64:
00347   case Triple::ppc64le:
00348     PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00349       dwarf::DW_EH_PE_udata8;
00350     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
00351     TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00352       dwarf::DW_EH_PE_udata8;
00353     break;
00354   case Triple::sparc:
00355     if (RelocM == Reloc::PIC_) {
00356       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
00357       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00358         dwarf::DW_EH_PE_sdata4;
00359       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00360         dwarf::DW_EH_PE_sdata4;
00361     } else {
00362       LSDAEncoding = dwarf::DW_EH_PE_absptr;
00363       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
00364       TTypeEncoding = dwarf::DW_EH_PE_absptr;
00365     }
00366     break;
00367   case Triple::sparcv9:
00368     LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
00369     if (RelocM == Reloc::PIC_) {
00370       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00371         dwarf::DW_EH_PE_sdata4;
00372       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00373         dwarf::DW_EH_PE_sdata4;
00374     } else {
00375       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
00376       TTypeEncoding = dwarf::DW_EH_PE_absptr;
00377     }
00378     break;
00379   case Triple::systemz:
00380     // All currently-defined code models guarantee that 4-byte PC-relative
00381     // values will be in range.
00382     if (RelocM == Reloc::PIC_) {
00383       PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00384         dwarf::DW_EH_PE_sdata4;
00385       LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
00386       TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
00387         dwarf::DW_EH_PE_sdata4;
00388     } else {
00389       PersonalityEncoding = dwarf::DW_EH_PE_absptr;
00390       LSDAEncoding = dwarf::DW_EH_PE_absptr;
00391       TTypeEncoding = dwarf::DW_EH_PE_absptr;
00392     }
00393     break;
00394   default:
00395     break;
00396   }
00397 
00398   // Solaris requires different flags for .eh_frame to seemingly every other
00399   // platform.
00400   EHSectionType = ELF::SHT_PROGBITS;
00401   EHSectionFlags = ELF::SHF_ALLOC;
00402   if (T.getOS() == Triple::Solaris) {
00403     if (T.getArch() == Triple::x86_64)
00404       EHSectionType = ELF::SHT_X86_64_UNWIND;
00405     else
00406       EHSectionFlags |= ELF::SHF_WRITE;
00407   }
00408 
00409 
00410   // ELF
00411   BSSSection =
00412     Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
00413                        ELF::SHF_WRITE | ELF::SHF_ALLOC,
00414                        SectionKind::getBSS());
00415 
00416   TextSection =
00417     Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
00418                        ELF::SHF_EXECINSTR |
00419                        ELF::SHF_ALLOC,
00420                        SectionKind::getText());
00421 
00422   DataSection =
00423     Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
00424                        ELF::SHF_WRITE |ELF::SHF_ALLOC,
00425                        SectionKind::getDataRel());
00426 
00427   ReadOnlySection =
00428     Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS,
00429                        ELF::SHF_ALLOC,
00430                        SectionKind::getReadOnly());
00431 
00432   TLSDataSection =
00433     Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
00434                        ELF::SHF_ALLOC | ELF::SHF_TLS |
00435                        ELF::SHF_WRITE,
00436                        SectionKind::getThreadData());
00437 
00438   TLSBSSSection =
00439     Ctx->getELFSection(".tbss", ELF::SHT_NOBITS,
00440                        ELF::SHF_ALLOC | ELF::SHF_TLS |
00441                        ELF::SHF_WRITE,
00442                        SectionKind::getThreadBSS());
00443 
00444   DataRelSection =
00445     Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
00446                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
00447                        SectionKind::getDataRel());
00448 
00449   DataRelLocalSection =
00450     Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
00451                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
00452                        SectionKind::getDataRelLocal());
00453 
00454   DataRelROSection =
00455     Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
00456                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
00457                        SectionKind::getReadOnlyWithRel());
00458 
00459   DataRelROLocalSection =
00460     Ctx->getELFSection(".data.rel.ro.local", ELF::SHT_PROGBITS,
00461                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
00462                        SectionKind::getReadOnlyWithRelLocal());
00463 
00464   MergeableConst4Section =
00465     Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
00466                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
00467                        SectionKind::getMergeableConst4());
00468 
00469   MergeableConst8Section =
00470     Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
00471                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
00472                        SectionKind::getMergeableConst8());
00473 
00474   MergeableConst16Section =
00475     Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
00476                        ELF::SHF_ALLOC |ELF::SHF_MERGE,
00477                        SectionKind::getMergeableConst16());
00478 
00479   StaticCtorSection =
00480     Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
00481                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
00482                        SectionKind::getDataRel());
00483 
00484   StaticDtorSection =
00485     Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
00486                        ELF::SHF_ALLOC |ELF::SHF_WRITE,
00487                        SectionKind::getDataRel());
00488 
00489   // Exception Handling Sections.
00490 
00491   // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
00492   // it contains relocatable pointers.  In PIC mode, this is probably a big
00493   // runtime hit for C++ apps.  Either the contents of the LSDA need to be
00494   // adjusted or this should be a data section.
00495   LSDASection =
00496     Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
00497                        ELF::SHF_ALLOC,
00498                        SectionKind::getReadOnly());
00499 
00500   COFFDebugSymbolsSection = nullptr;
00501 
00502   // Debug Info Sections.
00503   DwarfAbbrevSection =
00504     Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
00505                        SectionKind::getMetadata());
00506   DwarfInfoSection =
00507     Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0,
00508                        SectionKind::getMetadata());
00509   DwarfLineSection =
00510     Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0,
00511                        SectionKind::getMetadata());
00512   DwarfFrameSection =
00513     Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0,
00514                        SectionKind::getMetadata());
00515   DwarfPubNamesSection =
00516     Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0,
00517                        SectionKind::getMetadata());
00518   DwarfPubTypesSection =
00519     Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0,
00520                        SectionKind::getMetadata());
00521   DwarfGnuPubNamesSection =
00522     Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0,
00523                        SectionKind::getMetadata());
00524   DwarfGnuPubTypesSection =
00525     Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0,
00526                        SectionKind::getMetadata());
00527   DwarfStrSection =
00528     Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
00529                        ELF::SHF_MERGE | ELF::SHF_STRINGS,
00530                        SectionKind::getMergeable1ByteCString());
00531   DwarfLocSection =
00532     Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0,
00533                        SectionKind::getMetadata());
00534   DwarfARangesSection =
00535     Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0,
00536                        SectionKind::getMetadata());
00537   DwarfRangesSection =
00538     Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0,
00539                        SectionKind::getMetadata());
00540   DwarfMacroInfoSection =
00541     Ctx->getELFSection(".debug_macinfo", ELF::SHT_PROGBITS, 0,
00542                        SectionKind::getMetadata());
00543 
00544   // DWARF5 Experimental Debug Info
00545 
00546   // Accelerator Tables
00547   DwarfAccelNamesSection =
00548     Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0,
00549                        SectionKind::getMetadata());
00550   DwarfAccelObjCSection =
00551     Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0,
00552                        SectionKind::getMetadata());
00553   DwarfAccelNamespaceSection =
00554     Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0,
00555                        SectionKind::getMetadata());
00556   DwarfAccelTypesSection =
00557     Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0,
00558                        SectionKind::getMetadata());
00559 
00560   // Fission Sections
00561   DwarfInfoDWOSection =
00562     Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0,
00563                        SectionKind::getMetadata());
00564   DwarfTypesDWOSection =
00565     Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0,
00566                        SectionKind::getMetadata());
00567   DwarfAbbrevDWOSection =
00568     Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0,
00569                        SectionKind::getMetadata());
00570   DwarfStrDWOSection =
00571     Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
00572                        ELF::SHF_MERGE | ELF::SHF_STRINGS,
00573                        SectionKind::getMergeable1ByteCString());
00574   DwarfLineDWOSection =
00575     Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0,
00576                        SectionKind::getMetadata());
00577   DwarfLocDWOSection =
00578     Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0,
00579                        SectionKind::getMetadata());
00580   DwarfStrOffDWOSection =
00581     Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0,
00582                        SectionKind::getMetadata());
00583   DwarfAddrSection =
00584     Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0,
00585                        SectionKind::getMetadata());
00586 
00587   StackMapSection =
00588     Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS,
00589                        ELF::SHF_ALLOC,
00590                        SectionKind::getMetadata());
00591 
00592 }
00593 
00594 
00595 void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
00596   bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
00597 
00598   // The object file format cannot represent common symbols with explicit
00599   // alignments.
00600   CommDirectiveSupportsAlignment = false;
00601 
00602   // COFF
00603   BSSSection =
00604     Ctx->getCOFFSection(".bss",
00605                         COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
00606                         COFF::IMAGE_SCN_MEM_READ |
00607                         COFF::IMAGE_SCN_MEM_WRITE,
00608                         SectionKind::getBSS());
00609   TextSection =
00610     Ctx->getCOFFSection(".text",
00611                         (IsWoA ? COFF::IMAGE_SCN_MEM_16BIT
00612                                : (COFF::SectionCharacteristics)0) |
00613                         COFF::IMAGE_SCN_CNT_CODE |
00614                         COFF::IMAGE_SCN_MEM_EXECUTE |
00615                         COFF::IMAGE_SCN_MEM_READ,
00616                         SectionKind::getText());
00617   DataSection =
00618     Ctx->getCOFFSection(".data",
00619                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00620                         COFF::IMAGE_SCN_MEM_READ |
00621                         COFF::IMAGE_SCN_MEM_WRITE,
00622                         SectionKind::getDataRel());
00623   ReadOnlySection =
00624     Ctx->getCOFFSection(".rdata",
00625                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00626                         COFF::IMAGE_SCN_MEM_READ,
00627                         SectionKind::getReadOnly());
00628 
00629   if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
00630     StaticCtorSection =
00631       Ctx->getCOFFSection(".CRT$XCU",
00632                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00633                           COFF::IMAGE_SCN_MEM_READ,
00634                           SectionKind::getReadOnly());
00635     StaticDtorSection =
00636       Ctx->getCOFFSection(".CRT$XTX",
00637                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00638                           COFF::IMAGE_SCN_MEM_READ,
00639                           SectionKind::getReadOnly());
00640   } else {
00641     StaticCtorSection =
00642       Ctx->getCOFFSection(".ctors",
00643                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00644                           COFF::IMAGE_SCN_MEM_READ |
00645                           COFF::IMAGE_SCN_MEM_WRITE,
00646                           SectionKind::getDataRel());
00647     StaticDtorSection =
00648       Ctx->getCOFFSection(".dtors",
00649                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00650                           COFF::IMAGE_SCN_MEM_READ |
00651                           COFF::IMAGE_SCN_MEM_WRITE,
00652                           SectionKind::getDataRel());
00653   }
00654 
00655   // FIXME: We're emitting LSDA info into a readonly section on COFF, even
00656   // though it contains relocatable pointers.  In PIC mode, this is probably a
00657   // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
00658   // adjusted or this should be a data section.
00659   assert(T.isOSWindows() && "Windows is the only supported COFF target");
00660   if (T.getArch() == Triple::x86_64) {
00661     // On Windows 64 with SEH, the LSDA is emitted into the .xdata section
00662     LSDASection = 0;
00663   } else {
00664     LSDASection = Ctx->getCOFFSection(".gcc_except_table",
00665                                       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00666                                           COFF::IMAGE_SCN_MEM_READ,
00667                                       SectionKind::getReadOnly());
00668   }
00669 
00670   // Debug info.
00671   COFFDebugSymbolsSection =
00672     Ctx->getCOFFSection(".debug$S",
00673                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00674                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00675                         COFF::IMAGE_SCN_MEM_READ,
00676                         SectionKind::getMetadata());
00677 
00678   DwarfAbbrevSection =
00679     Ctx->getCOFFSection(".debug_abbrev",
00680                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00681                         COFF::IMAGE_SCN_MEM_READ,
00682                         SectionKind::getMetadata());
00683   DwarfInfoSection =
00684     Ctx->getCOFFSection(".debug_info",
00685                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00686                         COFF::IMAGE_SCN_MEM_READ,
00687                         SectionKind::getMetadata());
00688   DwarfLineSection =
00689     Ctx->getCOFFSection(".debug_line",
00690                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00691                         COFF::IMAGE_SCN_MEM_READ,
00692                         SectionKind::getMetadata());
00693   DwarfFrameSection =
00694     Ctx->getCOFFSection(".debug_frame",
00695                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00696                         COFF::IMAGE_SCN_MEM_READ,
00697                         SectionKind::getMetadata());
00698   DwarfPubNamesSection =
00699     Ctx->getCOFFSection(".debug_pubnames",
00700                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00701                         COFF::IMAGE_SCN_MEM_READ,
00702                         SectionKind::getMetadata());
00703   DwarfPubTypesSection =
00704     Ctx->getCOFFSection(".debug_pubtypes",
00705                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00706                         COFF::IMAGE_SCN_MEM_READ,
00707                         SectionKind::getMetadata());
00708   DwarfGnuPubNamesSection =
00709     Ctx->getCOFFSection(".debug_gnu_pubnames",
00710                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00711                         COFF::IMAGE_SCN_MEM_READ,
00712                         SectionKind::getMetadata());
00713   DwarfGnuPubTypesSection =
00714     Ctx->getCOFFSection(".debug_gnu_pubtypes",
00715                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00716                         COFF::IMAGE_SCN_MEM_READ,
00717                         SectionKind::getMetadata());
00718   DwarfStrSection =
00719     Ctx->getCOFFSection(".debug_str",
00720                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00721                         COFF::IMAGE_SCN_MEM_READ,
00722                         SectionKind::getMetadata());
00723   DwarfLocSection =
00724     Ctx->getCOFFSection(".debug_loc",
00725                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00726                         COFF::IMAGE_SCN_MEM_READ,
00727                         SectionKind::getMetadata());
00728   DwarfARangesSection =
00729     Ctx->getCOFFSection(".debug_aranges",
00730                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00731                         COFF::IMAGE_SCN_MEM_READ,
00732                         SectionKind::getMetadata());
00733   DwarfRangesSection =
00734     Ctx->getCOFFSection(".debug_ranges",
00735                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00736                         COFF::IMAGE_SCN_MEM_READ,
00737                         SectionKind::getMetadata());
00738   DwarfMacroInfoSection =
00739     Ctx->getCOFFSection(".debug_macinfo",
00740                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00741                         COFF::IMAGE_SCN_MEM_READ,
00742                         SectionKind::getMetadata());
00743   DwarfInfoDWOSection =
00744       Ctx->getCOFFSection(".debug_info.dwo",
00745                           COFF::IMAGE_SCN_MEM_DISCARDABLE |
00746                           COFF::IMAGE_SCN_MEM_READ,
00747                           SectionKind::getMetadata());
00748   DwarfTypesDWOSection =
00749       Ctx->getCOFFSection(".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |
00750                                                   COFF::IMAGE_SCN_MEM_READ,
00751                           SectionKind::getMetadata());
00752   DwarfAbbrevDWOSection =
00753       Ctx->getCOFFSection(".debug_abbrev.dwo",
00754                           COFF::IMAGE_SCN_MEM_DISCARDABLE |
00755                           COFF::IMAGE_SCN_MEM_READ,
00756                           SectionKind::getMetadata());
00757   DwarfStrDWOSection =
00758       Ctx->getCOFFSection(".debug_str.dwo",
00759                           COFF::IMAGE_SCN_MEM_DISCARDABLE |
00760                           COFF::IMAGE_SCN_MEM_READ,
00761                           SectionKind::getMetadata());
00762   DwarfLineDWOSection =
00763       Ctx->getCOFFSection(".debug_line.dwo",
00764                           COFF::IMAGE_SCN_MEM_DISCARDABLE |
00765                           COFF::IMAGE_SCN_MEM_READ,
00766                           SectionKind::getMetadata());
00767   DwarfLocDWOSection =
00768       Ctx->getCOFFSection(".debug_loc.dwo",
00769                           COFF::IMAGE_SCN_MEM_DISCARDABLE |
00770                           COFF::IMAGE_SCN_MEM_READ,
00771                           SectionKind::getMetadata());
00772   DwarfStrOffDWOSection =
00773       Ctx->getCOFFSection(".debug_str_offsets.dwo",
00774                           COFF::IMAGE_SCN_MEM_DISCARDABLE |
00775                           COFF::IMAGE_SCN_MEM_READ,
00776                           SectionKind::getMetadata());
00777 
00778   DwarfAddrSection =
00779     Ctx->getCOFFSection(".debug_addr",
00780                         COFF::IMAGE_SCN_MEM_DISCARDABLE |
00781                         COFF::IMAGE_SCN_MEM_READ,
00782                         SectionKind::getMetadata());
00783 
00784   DrectveSection =
00785     Ctx->getCOFFSection(".drectve",
00786                         COFF::IMAGE_SCN_LNK_INFO |
00787                         COFF::IMAGE_SCN_LNK_REMOVE,
00788                         SectionKind::getMetadata());
00789 
00790   PDataSection =
00791     Ctx->getCOFFSection(".pdata",
00792                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00793                         COFF::IMAGE_SCN_MEM_READ,
00794                         SectionKind::getDataRel());
00795 
00796   XDataSection =
00797     Ctx->getCOFFSection(".xdata",
00798                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00799                         COFF::IMAGE_SCN_MEM_READ,
00800                         SectionKind::getDataRel());
00801 
00802   TLSDataSection =
00803     Ctx->getCOFFSection(".tls$",
00804                         COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00805                         COFF::IMAGE_SCN_MEM_READ |
00806                         COFF::IMAGE_SCN_MEM_WRITE,
00807                         SectionKind::getDataRel());
00808 }
00809 
00810 void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
00811                                             CodeModel::Model cm,
00812                                             MCContext &ctx) {
00813   RelocM = relocm;
00814   CMModel = cm;
00815   Ctx = &ctx;
00816 
00817   // Common.
00818   CommDirectiveSupportsAlignment = true;
00819   SupportsWeakOmittedEHFrame = true;
00820   SupportsCompactUnwindWithoutEHFrame = false;
00821 
00822   PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
00823       dwarf::DW_EH_PE_absptr;
00824 
00825   CompactUnwindDwarfEHFrameOnly = 0;
00826 
00827   EHFrameSection = nullptr;             // Created on demand.
00828   CompactUnwindSection = nullptr;       // Used only by selected targets.
00829   DwarfAccelNamesSection = nullptr;     // Used only by selected targets.
00830   DwarfAccelObjCSection = nullptr;      // Used only by selected targets.
00831   DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
00832   DwarfAccelTypesSection = nullptr;     // Used only by selected targets.
00833 
00834   TT = Triple(T);
00835 
00836   Triple::ArchType Arch = TT.getArch();
00837   // FIXME: Checking for Arch here to filter out bogus triples such as
00838   // cellspu-apple-darwin. Perhaps we should fix in Triple?
00839   if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
00840        Arch == Triple::arm || Arch == Triple::thumb ||
00841        Arch == Triple::aarch64 ||
00842        Arch == Triple::ppc || Arch == Triple::ppc64 ||
00843        Arch == Triple::UnknownArch) &&
00844       (TT.isOSDarwin() || TT.isOSBinFormatMachO())) {
00845     Env = IsMachO;
00846     InitMachOMCObjectFileInfo(TT);
00847   } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
00848               Arch == Triple::arm || Arch == Triple::thumb) &&
00849              (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
00850     Env = IsCOFF;
00851     InitCOFFMCObjectFileInfo(TT);
00852   } else {
00853     Env = IsELF;
00854     InitELFMCObjectFileInfo(TT);
00855   }
00856 }
00857 
00858 const MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
00859   return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
00860                             SectionKind::getMetadata(), 0, utostr(Hash));
00861 }
00862 
00863 void MCObjectFileInfo::InitEHFrameSection() {
00864   if (Env == IsMachO)
00865     EHFrameSection =
00866       Ctx->getMachOSection("__TEXT", "__eh_frame",
00867                            MachO::S_COALESCED |
00868                            MachO::S_ATTR_NO_TOC |
00869                            MachO::S_ATTR_STRIP_STATIC_SYMS |
00870                            MachO::S_ATTR_LIVE_SUPPORT,
00871                            SectionKind::getReadOnly());
00872   else if (Env == IsELF)
00873     EHFrameSection =
00874       Ctx->getELFSection(".eh_frame", EHSectionType,
00875                          EHSectionFlags,
00876                          SectionKind::getDataRel());
00877   else
00878     EHFrameSection =
00879       Ctx->getCOFFSection(".eh_frame",
00880                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
00881                           COFF::IMAGE_SCN_MEM_READ |
00882                           COFF::IMAGE_SCN_MEM_WRITE,
00883                           SectionKind::getDataRel());
00884 }