static bool useCompactUnwind(const Triple &T) {
  // Only on darwin.
  if (!T.isOSDarwin())
    return false;

  // aarch64 always has it.
  if (T.getArch() == Triple::aarch64)
    return true;

  // armv7k always has it.
  if (T.getArchName().equals("thumbv7k") ||
      T.getArchName().equals("armv7k"))
    return true;

  // Use it on newer version of OS X.
  if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
    return true;

  // And the iOS simulator.
  if (T.isiOS() &&
      (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
    return true;

  return false;
}
Example #2
0
// checkMachOAndArchFlags() checks to see if the SymbolicFile is a Mach-O file
// and if it is and there is a list of architecture flags is specified then
// check to make sure this Mach-O file is one of those architectures or all
// architectures was specificed.  If not then an error is generated and this
// routine returns false.  Else it returns true.
static bool checkMachOAndArchFlags(SymbolicFile *O, std::string &Filename) {
  if (isa<MachOObjectFile>(O) && !ArchAll && ArchFlags.size() != 0) {
    MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(O);
    bool ArchFound = false;
    MachO::mach_header H;
    MachO::mach_header_64 H_64;
    Triple T;
    if (MachO->is64Bit()) {
      H_64 = MachO->MachOObjectFile::getHeader64();
      T = MachOObjectFile::getArch(H_64.cputype, H_64.cpusubtype);
    } else {
      H = MachO->MachOObjectFile::getHeader();
      T = MachOObjectFile::getArch(H.cputype, H.cpusubtype);
    }
    unsigned i;
    for (i = 0; i < ArchFlags.size(); ++i) {
      if (ArchFlags[i] == T.getArchName())
        ArchFound = true;
      break;
    }
    if (!ArchFound) {
      error(ArchFlags[i],
            "file: " + Filename + " does not contain architecture");
      return false;
    }
  }
  return true;
}
Example #3
0
/// @brief Checks to see if the @p o ObjectFile is a Mach-O file and if it is
///        and there is a list of architecture flags specified then check to
///        make sure this Mach-O file is one of those architectures or all
///        architectures was specificed.  If not then an error is generated and
///        this routine returns false.  Else it returns true.
static bool checkMachOAndArchFlags(ObjectFile *o, StringRef file) {
  if (isa<MachOObjectFile>(o) && !ArchAll && ArchFlags.size() != 0) {
    MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
    bool ArchFound = false;
    MachO::mach_header H;
    MachO::mach_header_64 H_64;
    Triple T;
    if (MachO->is64Bit()) {
      H_64 = MachO->MachOObjectFile::getHeader64();
      T = MachOObjectFile::getArch(H_64.cputype, H_64.cpusubtype);
    } else {
      H = MachO->MachOObjectFile::getHeader();
      T = MachOObjectFile::getArch(H.cputype, H.cpusubtype);
    }
    unsigned i;
    for (i = 0; i < ArchFlags.size(); ++i) {
      if (ArchFlags[i] == T.getArchName())
        ArchFound = true;
      break;
    }
    if (!ArchFound) {
      errs() << ToolName << ": file: " << file
             << " does not contain architecture: " << ArchFlags[i] << ".\n";
      return false;
    }
  }
  return true;
}
Example #4
0
StringRef ARM::computeDefaultTargetABI(const Triple &TT, StringRef CPU) {
  StringRef ArchName =
      CPU.empty() ? TT.getArchName() : getArchName(parseCPUArch(CPU));

  if (TT.isOSBinFormatMachO()) {
    if (TT.getEnvironment() == Triple::EABI ||
        TT.getOS() == Triple::UnknownOS ||
        parseArchProfile(ArchName) == ProfileKind::M)
      return "aapcs";
    if (TT.isWatchABI())
      return "aapcs16";
    return "apcs-gnu";
  } else if (TT.isOSWindows())
    // FIXME: this is invalid for WindowsCE.
    return "aapcs";

  // Select the default based on the platform.
  switch (TT.getEnvironment()) {
  case Triple::Android:
  case Triple::GNUEABI:
  case Triple::GNUEABIHF:
  case Triple::MuslEABI:
  case Triple::MuslEABIHF:
    return "aapcs-linux";
  case Triple::EABIHF:
  case Triple::EABI:
    return "aapcs";
  default:
    if (TT.isOSNetBSD())
      return "apcs-gnu";
    if (TT.isOSOpenBSD())
      return "aapcs-linux";
    return "aapcs";
  }
}
Example #5
0
std::string ARM_MC::ParseARMTriple(const Triple &TT, StringRef CPU) {
  bool isThumb =
      TT.getArch() == Triple::thumb || TT.getArch() == Triple::thumbeb;

  std::string ARMArchFeature;

  unsigned ArchID = ARM::parseArch(TT.getArchName());
  if (ArchID != ARM::AK_INVALID &&  (CPU.empty() || CPU == "generic"))
    ARMArchFeature = (ARMArchFeature + "+" + ARM::getArchName(ArchID)).str();

  if (isThumb) {
    if (ARMArchFeature.empty())
      ARMArchFeature = "+thumb-mode";
    else
      ARMArchFeature += ",+thumb-mode";
  }

  if (TT.isOSNaCl()) {
    if (ARMArchFeature.empty())
      ARMArchFeature = "+nacl-trap";
    else
      ARMArchFeature += ",+nacl-trap";
  }

  return ARMArchFeature;
}
Example #6
0
// checkMachOAndArchFlags() checks to see if the SymbolicFile is a Mach-O file
// and if it is and there is a list of architecture flags is specified then
// check to make sure this Mach-O file is one of those architectures or all
// architectures was specificed.  If not then an error is generated and this
// routine returns false.  Else it returns true.
static bool checkMachOAndArchFlags(SymbolicFile *O, std::string &Filename) {
  MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(O);

  if (!MachO || ArchAll || ArchFlags.size() == 0)
    return true;

  MachO::mach_header H;
  MachO::mach_header_64 H_64;
  Triple T;
  if (MachO->is64Bit()) {
    H_64 = MachO->MachOObjectFile::getHeader64();
    T = MachOObjectFile::getArch(H_64.cputype, H_64.cpusubtype);
  } else {
    H = MachO->MachOObjectFile::getHeader();
    T = MachOObjectFile::getArch(H.cputype, H.cpusubtype);
  }
  if (std::none_of(
          ArchFlags.begin(), ArchFlags.end(),
          [&](const std::string &Name) { return Name == T.getArchName(); })) {
    error("No architecture specified", Filename);
    return false;
  }
  return true;
}
Example #7
0
static std::string getArchName(const object::MachOObjectFile &Obj) {
  Triple ThumbTriple;
  Triple T = Obj.getArch(nullptr, &ThumbTriple);
  return T.getArchName();
}
Example #8
0
static std::string getArchName(const object::MachOObjectFile &Obj) {
  Triple T = Obj.getArchTriple();
  return T.getArchName();
}
Example #9
0
static int get_arm_sub_arch_version(const Triple &triple) {
    return ARMTargetParser::parseArchVersion(triple.getArchName());
}
void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
  // MachO
  SupportsWeakOmittedEHFrame = false;

  if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
    SupportsCompactUnwindWithoutEHFrame = true;

  if (T.isOSDarwin() && T.getArchName().equals("thumbv7k"))
    OmitDwarfIfHaveCompactUnwind = true;

  PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
    | dwarf::DW_EH_PE_sdata4;
  LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
  TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
    dwarf::DW_EH_PE_sdata4;

  // .comm doesn't support alignment before Leopard.
  if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
    CommDirectiveSupportsAlignment = false;

  TextSection // .text
    = Ctx->getMachOSection("__TEXT", "__text",
                           MachO::S_ATTR_PURE_INSTRUCTIONS,
                           SectionKind::getText());
  DataSection // .data
    = Ctx->getMachOSection("__DATA", "__data", 0,
                           SectionKind::getDataRel());

  // BSSSection might not be expected initialized on msvc.
  BSSSection = nullptr;

  TLSDataSection // .tdata
    = Ctx->getMachOSection("__DATA", "__thread_data",
                           MachO::S_THREAD_LOCAL_REGULAR,
                           SectionKind::getDataRel());
  TLSBSSSection // .tbss
    = Ctx->getMachOSection("__DATA", "__thread_bss",
                           MachO::S_THREAD_LOCAL_ZEROFILL,
                           SectionKind::getThreadBSS());

  // TODO: Verify datarel below.
  TLSTLVSection // .tlv
    = Ctx->getMachOSection("__DATA", "__thread_vars",
                           MachO::S_THREAD_LOCAL_VARIABLES,
                           SectionKind::getDataRel());

  TLSThreadInitSection
    = Ctx->getMachOSection("__DATA", "__thread_init",
                          MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
                          SectionKind::getDataRel());

  CStringSection // .cstring
    = Ctx->getMachOSection("__TEXT", "__cstring",
                           MachO::S_CSTRING_LITERALS,
                           SectionKind::getMergeable1ByteCString());
  UStringSection
    = Ctx->getMachOSection("__TEXT","__ustring", 0,
                           SectionKind::getMergeable2ByteCString());
  FourByteConstantSection // .literal4
    = Ctx->getMachOSection("__TEXT", "__literal4",
                           MachO::S_4BYTE_LITERALS,
                           SectionKind::getMergeableConst4());
  EightByteConstantSection // .literal8
    = Ctx->getMachOSection("__TEXT", "__literal8",
                           MachO::S_8BYTE_LITERALS,
                           SectionKind::getMergeableConst8());

  SixteenByteConstantSection // .literal16
      = Ctx->getMachOSection("__TEXT", "__literal16",
                             MachO::S_16BYTE_LITERALS,
                             SectionKind::getMergeableConst16());

  ReadOnlySection  // .const
    = Ctx->getMachOSection("__TEXT", "__const", 0,
                           SectionKind::getReadOnly());

  TextCoalSection
    = Ctx->getMachOSection("__TEXT", "__textcoal_nt",
                           MachO::S_COALESCED |
                           MachO::S_ATTR_PURE_INSTRUCTIONS,
                           SectionKind::getText());
  ConstTextCoalSection
    = Ctx->getMachOSection("__TEXT", "__const_coal",
                           MachO::S_COALESCED,
                           SectionKind::getReadOnly());
  ConstDataSection  // .const_data
    = Ctx->getMachOSection("__DATA", "__const", 0,
                           SectionKind::getReadOnlyWithRel());
  DataCoalSection
    = Ctx->getMachOSection("__DATA","__datacoal_nt",
                           MachO::S_COALESCED,
                           SectionKind::getDataRel());
  DataCommonSection
    = Ctx->getMachOSection("__DATA","__common",
                           MachO::S_ZEROFILL,
                           SectionKind::getBSS());
  DataBSSSection
    = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
                           SectionKind::getBSS());


  LazySymbolPointerSection
    = Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
                           MachO::S_LAZY_SYMBOL_POINTERS,
                           SectionKind::getMetadata());
  NonLazySymbolPointerSection
    = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
                           MachO::S_NON_LAZY_SYMBOL_POINTERS,
                           SectionKind::getMetadata());

  if (RelocM == Reloc::Static) {
    StaticCtorSection
      = Ctx->getMachOSection("__TEXT", "__constructor", 0,
                             SectionKind::getDataRel());
    StaticDtorSection
      = Ctx->getMachOSection("__TEXT", "__destructor", 0,
                             SectionKind::getDataRel());
  } else {
    StaticCtorSection
      = Ctx->getMachOSection("__DATA", "__mod_init_func",
                             MachO::S_MOD_INIT_FUNC_POINTERS,
                             SectionKind::getDataRel());
    StaticDtorSection
      = Ctx->getMachOSection("__DATA", "__mod_term_func",
                             MachO::S_MOD_TERM_FUNC_POINTERS,
                             SectionKind::getDataRel());
  }

  // Exception Handling.
  LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
                                     SectionKind::getReadOnlyWithRel());

  COFFDebugSymbolsSection = nullptr;

  if (useCompactUnwind(T)) {
    CompactUnwindSection =
        Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
                             SectionKind::getReadOnly());

    if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
      CompactUnwindDwarfEHFrameOnly = 0x04000000;  // UNWIND_X86_64_MODE_DWARF
    else if (T.getArch() == Triple::aarch64)
      CompactUnwindDwarfEHFrameOnly = 0x03000000;  // UNWIND_ARM64_MODE_DWARF
    else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)
      CompactUnwindDwarfEHFrameOnly = 0x04000000;  // UNWIND_ARM_MODE_DWARF
  }

  // Debug Information.
  DwarfAccelNamesSection =
    Ctx->getMachOSection("__DWARF", "__apple_names",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfAccelObjCSection =
    Ctx->getMachOSection("__DWARF", "__apple_objc",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  // 16 character section limit...
  DwarfAccelNamespaceSection =
    Ctx->getMachOSection("__DWARF", "__apple_namespac",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfAccelTypesSection =
    Ctx->getMachOSection("__DWARF", "__apple_types",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());

  DwarfAccelExternalTypesSection =
      Ctx->getMachOSection("__DWARF", "__apple_exttypes",
                           MachO::S_ATTR_DEBUG,
                           SectionKind::getMetadata());

  DwarfAbbrevSection =
    Ctx->getMachOSection("__DWARF", "__debug_abbrev",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfInfoSection =
    Ctx->getMachOSection("__DWARF", "__debug_info",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfLineSection =
    Ctx->getMachOSection("__DWARF", "__debug_line",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfFrameSection =
    Ctx->getMachOSection("__DWARF", "__debug_frame",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfPubNamesSection =
    Ctx->getMachOSection("__DWARF", "__debug_pubnames",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfPubTypesSection =
    Ctx->getMachOSection("__DWARF", "__debug_pubtypes",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfGnuPubNamesSection =
    Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfGnuPubTypesSection =
    Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfStrSection =
    Ctx->getMachOSection("__DWARF", "__debug_str",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfLocSection =
    Ctx->getMachOSection("__DWARF", "__debug_loc",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfARangesSection =
    Ctx->getMachOSection("__DWARF", "__debug_aranges",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfRangesSection =
    Ctx->getMachOSection("__DWARF", "__debug_ranges",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfMacroInfoSection =
    Ctx->getMachOSection("__DWARF", "__debug_macinfo",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  DwarfDebugInlineSection =
    Ctx->getMachOSection("__DWARF", "__debug_inlined",
                         MachO::S_ATTR_DEBUG,
                         SectionKind::getMetadata());
  StackMapSection =
    Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 0,
                         SectionKind::getMetadata());

  TLSExtraDataSection = TLSTLVSection;
}