197a14e60SZachary Turner //===-- HostInfoBase.cpp ----------------------------------------*- C++ -*-===// 297a14e60SZachary Turner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 697a14e60SZachary Turner // 797a14e60SZachary Turner //===----------------------------------------------------------------------===// 897a14e60SZachary Turner 997a14e60SZachary Turner #include "lldb/Host/Config.h" 1097a14e60SZachary Turner 1142ff0ad8SZachary Turner #include "lldb/Host/FileSystem.h" 1297a14e60SZachary Turner #include "lldb/Host/Host.h" 1313b18261SZachary Turner #include "lldb/Host/HostInfo.h" 1413b18261SZachary Turner #include "lldb/Host/HostInfoBase.h" 155f19b907SPavel Labath #include "lldb/Utility/ArchSpec.h" 166f9e6901SZachary Turner #include "lldb/Utility/Log.h" 17bf9a7730SZachary Turner #include "lldb/Utility/StreamString.h" 1813b18261SZachary Turner 19270e99abSZachary Turner #include "llvm/ADT/StringExtras.h" 201eb0d42aSPavel Labath #include "llvm/ADT/Triple.h" 2113b18261SZachary Turner #include "llvm/Support/Host.h" 2233183147SPavel Labath #include "llvm/Support/Path.h" 231eb0d42aSPavel Labath #include "llvm/Support/ScopedPrinter.h" 24c5f28e2aSKamil Rytarowski #include "llvm/Support/Threading.h" 25270e99abSZachary Turner #include "llvm/Support/raw_ostream.h" 2697a14e60SZachary Turner 27c5f28e2aSKamil Rytarowski #include <mutex> 28b9c1b51eSKate Stone #include <thread> 2997a14e60SZachary Turner 3097a14e60SZachary Turner using namespace lldb; 3197a14e60SZachary Turner using namespace lldb_private; 3297a14e60SZachary Turner 33b9c1b51eSKate Stone namespace { 3405097246SAdrian Prantl // The HostInfoBaseFields is a work around for windows not supporting static 3505097246SAdrian Prantl // variables correctly in a thread safe way. Really each of the variables in 3605097246SAdrian Prantl // HostInfoBaseFields should live in the functions in which they are used and 3705097246SAdrian Prantl // each one should be static, but the work around is in place to avoid this 3805097246SAdrian Prantl // restriction. Ick. 39ff48e4beSGreg Clayton 40b9c1b51eSKate Stone struct HostInfoBaseFields { 41b9c1b51eSKate Stone ~HostInfoBaseFields() { 42dbd7fabaSJonas Devlieghere if (FileSystem::Instance().Exists(m_lldb_process_tmp_dir)) { 4341331afaSZachary Turner // Remove the LLDB temporary directory if we have one. Set "recurse" to 4405097246SAdrian Prantl // true to all files that were created for the LLDB process can be 4505097246SAdrian Prantl // cleaned up. 46d82067f8SZachary Turner llvm::sys::fs::remove_directories(m_lldb_process_tmp_dir.GetPath()); 4741331afaSZachary Turner } 4841331afaSZachary Turner } 4941331afaSZachary Turner 50b2371791SRaphael Isemann llvm::once_flag m_host_triple_once; 51673b6e4fSZachary Turner std::string m_host_triple; 52673b6e4fSZachary Turner 53b2371791SRaphael Isemann llvm::once_flag m_host_arch_once; 54673b6e4fSZachary Turner ArchSpec m_host_arch_32; 55673b6e4fSZachary Turner ArchSpec m_host_arch_64; 56673b6e4fSZachary Turner 57b2371791SRaphael Isemann llvm::once_flag m_lldb_so_dir_once; 58673b6e4fSZachary Turner FileSpec m_lldb_so_dir; 59b2371791SRaphael Isemann llvm::once_flag m_lldb_support_exe_dir_once; 60673b6e4fSZachary Turner FileSpec m_lldb_support_exe_dir; 61b2371791SRaphael Isemann llvm::once_flag m_lldb_headers_dir_once; 62673b6e4fSZachary Turner FileSpec m_lldb_headers_dir; 63b2371791SRaphael Isemann llvm::once_flag m_lldb_clang_resource_dir_once; 64b1e1c62fSSean Callanan FileSpec m_lldb_clang_resource_dir; 65b2371791SRaphael Isemann llvm::once_flag m_lldb_system_plugin_dir_once; 66673b6e4fSZachary Turner FileSpec m_lldb_system_plugin_dir; 67b2371791SRaphael Isemann llvm::once_flag m_lldb_user_plugin_dir_once; 68673b6e4fSZachary Turner FileSpec m_lldb_user_plugin_dir; 69b2371791SRaphael Isemann llvm::once_flag m_lldb_process_tmp_dir_once; 7063acdfdeSOleksiy Vyalov FileSpec m_lldb_process_tmp_dir; 71b2371791SRaphael Isemann llvm::once_flag m_lldb_global_tmp_dir_once; 7263acdfdeSOleksiy Vyalov FileSpec m_lldb_global_tmp_dir; 73673b6e4fSZachary Turner }; 74673b6e4fSZachary Turner 75673b6e4fSZachary Turner HostInfoBaseFields *g_fields = nullptr; 7642ff0ad8SZachary Turner } 7742ff0ad8SZachary Turner 78b9c1b51eSKate Stone void HostInfoBase::Initialize() { g_fields = new HostInfoBaseFields(); } 7942ff0ad8SZachary Turner 80b9c1b51eSKate Stone void HostInfoBase::Terminate() { 8141331afaSZachary Turner delete g_fields; 8241331afaSZachary Turner g_fields = nullptr; 8341331afaSZachary Turner } 8441331afaSZachary Turner 85b9c1b51eSKate Stone llvm::StringRef HostInfoBase::GetTargetTriple() { 86b2371791SRaphael Isemann llvm::call_once(g_fields->m_host_triple_once, []() { 87b9c1b51eSKate Stone g_fields->m_host_triple = 88b9c1b51eSKate Stone HostInfo::GetArchitecture().GetTriple().getTriple(); 89ff48e4beSGreg Clayton }); 90673b6e4fSZachary Turner return g_fields->m_host_triple; 9197a14e60SZachary Turner } 9213b18261SZachary Turner 93b9c1b51eSKate Stone const ArchSpec &HostInfoBase::GetArchitecture(ArchitectureKind arch_kind) { 94b2371791SRaphael Isemann llvm::call_once(g_fields->m_host_arch_once, []() { 95b9c1b51eSKate Stone HostInfo::ComputeHostArchitectureSupport(g_fields->m_host_arch_32, 96b9c1b51eSKate Stone g_fields->m_host_arch_64); 97ff48e4beSGreg Clayton }); 9813b18261SZachary Turner 9913b18261SZachary Turner // If an explicit 32 or 64-bit architecture was requested, return that. 10013b18261SZachary Turner if (arch_kind == eArchKind32) 101673b6e4fSZachary Turner return g_fields->m_host_arch_32; 10213b18261SZachary Turner if (arch_kind == eArchKind64) 103673b6e4fSZachary Turner return g_fields->m_host_arch_64; 10413b18261SZachary Turner 10513b18261SZachary Turner // Otherwise prefer the 64-bit architecture if it is valid. 106b9c1b51eSKate Stone return (g_fields->m_host_arch_64.IsValid()) ? g_fields->m_host_arch_64 107b9c1b51eSKate Stone : g_fields->m_host_arch_32; 10813b18261SZachary Turner } 10913b18261SZachary Turner 1104ebb64b9SPavel Labath llvm::Optional<HostInfoBase::ArchitectureKind> HostInfoBase::ParseArchitectureKind(llvm::StringRef kind) { 1114ebb64b9SPavel Labath return llvm::StringSwitch<llvm::Optional<ArchitectureKind>>(kind) 1124ebb64b9SPavel Labath .Case(LLDB_ARCH_DEFAULT, eArchKindDefault) 1134ebb64b9SPavel Labath .Case(LLDB_ARCH_DEFAULT_32BIT, eArchKind32) 1144ebb64b9SPavel Labath .Case(LLDB_ARCH_DEFAULT_64BIT, eArchKind64) 1154ebb64b9SPavel Labath .Default(llvm::None); 1164ebb64b9SPavel Labath } 1174ebb64b9SPavel Labath 11860f028ffSPavel Labath FileSpec HostInfoBase::GetShlibDir() { 119b2371791SRaphael Isemann llvm::call_once(g_fields->m_lldb_so_dir_once, []() { 120b2371791SRaphael Isemann if (!HostInfo::ComputeSharedLibraryDirectory(g_fields->m_lldb_so_dir)) 121b2371791SRaphael Isemann g_fields->m_lldb_so_dir = FileSpec(); 12260f028ffSPavel Labath Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 12360f028ffSPavel Labath LLDB_LOG(log, "shlib dir -> `{0}`", g_fields->m_lldb_so_dir); 12460f028ffSPavel Labath }); 125b2371791SRaphael Isemann return g_fields->m_lldb_so_dir; 12660f028ffSPavel Labath } 12742ff0ad8SZachary Turner 12860f028ffSPavel Labath FileSpec HostInfoBase::GetSupportExeDir() { 129b2371791SRaphael Isemann llvm::call_once(g_fields->m_lldb_support_exe_dir_once, []() { 130b2371791SRaphael Isemann if (!HostInfo::ComputeSupportExeDirectory(g_fields->m_lldb_support_exe_dir)) 131b2371791SRaphael Isemann g_fields->m_lldb_support_exe_dir = FileSpec(); 132ff48e4beSGreg Clayton Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 13360f028ffSPavel Labath LLDB_LOG(log, "support exe dir -> `{0}`", g_fields->m_lldb_support_exe_dir); 134ff48e4beSGreg Clayton }); 135b2371791SRaphael Isemann return g_fields->m_lldb_support_exe_dir; 13660f028ffSPavel Labath } 13760f028ffSPavel Labath 13860f028ffSPavel Labath FileSpec HostInfoBase::GetHeaderDir() { 139b2371791SRaphael Isemann llvm::call_once(g_fields->m_lldb_headers_dir_once, []() { 140b2371791SRaphael Isemann if (!HostInfo::ComputeHeaderDirectory(g_fields->m_lldb_headers_dir)) 141b2371791SRaphael Isemann g_fields->m_lldb_headers_dir = FileSpec(); 142ff48e4beSGreg Clayton Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 14360f028ffSPavel Labath LLDB_LOG(log, "header dir -> `{0}`", g_fields->m_lldb_headers_dir); 144ff48e4beSGreg Clayton }); 145b2371791SRaphael Isemann return g_fields->m_lldb_headers_dir; 14660f028ffSPavel Labath } 14760f028ffSPavel Labath 14860f028ffSPavel Labath FileSpec HostInfoBase::GetSystemPluginDir() { 149b2371791SRaphael Isemann llvm::call_once(g_fields->m_lldb_system_plugin_dir_once, []() { 150b2371791SRaphael Isemann if (!HostInfo::ComputeSystemPluginsDirectory(g_fields->m_lldb_system_plugin_dir)) 151b2371791SRaphael Isemann g_fields->m_lldb_system_plugin_dir = FileSpec(); 152ff48e4beSGreg Clayton Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 15360f028ffSPavel Labath LLDB_LOG(log, "system plugin dir -> `{0}`", 15460f028ffSPavel Labath g_fields->m_lldb_system_plugin_dir); 155ff48e4beSGreg Clayton }); 156b2371791SRaphael Isemann return g_fields->m_lldb_system_plugin_dir; 15760f028ffSPavel Labath } 15860f028ffSPavel Labath 15960f028ffSPavel Labath FileSpec HostInfoBase::GetUserPluginDir() { 160b2371791SRaphael Isemann llvm::call_once(g_fields->m_lldb_user_plugin_dir_once, []() { 161b2371791SRaphael Isemann if (!HostInfo::ComputeUserPluginsDirectory(g_fields->m_lldb_user_plugin_dir)) 162b2371791SRaphael Isemann g_fields->m_lldb_user_plugin_dir = FileSpec(); 163ff48e4beSGreg Clayton Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 16460f028ffSPavel Labath LLDB_LOG(log, "user plugin dir -> `{0}`", g_fields->m_lldb_user_plugin_dir); 165ff48e4beSGreg Clayton }); 166b2371791SRaphael Isemann return g_fields->m_lldb_user_plugin_dir; 16760f028ffSPavel Labath } 16860f028ffSPavel Labath 16960f028ffSPavel Labath FileSpec HostInfoBase::GetProcessTempDir() { 170b2371791SRaphael Isemann llvm::call_once(g_fields->m_lldb_process_tmp_dir_once, []() { 171b2371791SRaphael Isemann if (!HostInfo::ComputeProcessTempFileDirectory( g_fields->m_lldb_process_tmp_dir)) 172b2371791SRaphael Isemann g_fields->m_lldb_process_tmp_dir = FileSpec(); 173ff48e4beSGreg Clayton Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 17460f028ffSPavel Labath LLDB_LOG(log, "process temp dir -> `{0}`", 17560f028ffSPavel Labath g_fields->m_lldb_process_tmp_dir); 176ff48e4beSGreg Clayton }); 177b2371791SRaphael Isemann return g_fields->m_lldb_process_tmp_dir; 17860f028ffSPavel Labath } 17960f028ffSPavel Labath 18060f028ffSPavel Labath FileSpec HostInfoBase::GetGlobalTempDir() { 181b2371791SRaphael Isemann llvm::call_once(g_fields->m_lldb_global_tmp_dir_once, []() { 182b2371791SRaphael Isemann if (!HostInfo::ComputeGlobalTempFileDirectory( g_fields->m_lldb_global_tmp_dir)) 183b2371791SRaphael Isemann g_fields->m_lldb_global_tmp_dir = FileSpec(); 184b2371791SRaphael Isemann 18563acdfdeSOleksiy Vyalov Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 18660f028ffSPavel Labath LLDB_LOG(log, "global temp dir -> `{0}`", g_fields->m_lldb_global_tmp_dir); 18763acdfdeSOleksiy Vyalov }); 188b2371791SRaphael Isemann return g_fields->m_lldb_global_tmp_dir; 18942ff0ad8SZachary Turner } 19042ff0ad8SZachary Turner 1917263f1bdSPavel Labath ArchSpec HostInfoBase::GetAugmentedArchSpec(llvm::StringRef triple) { 1927263f1bdSPavel Labath if (triple.empty()) 1937263f1bdSPavel Labath return ArchSpec(); 1947263f1bdSPavel Labath llvm::Triple normalized_triple(llvm::Triple::normalize(triple)); 1957263f1bdSPavel Labath if (!ArchSpec::ContainsOnlyArch(normalized_triple)) 1967263f1bdSPavel Labath return ArchSpec(triple); 1977263f1bdSPavel Labath 1984ebb64b9SPavel Labath if (auto kind = HostInfo::ParseArchitectureKind(triple)) 1994ebb64b9SPavel Labath return HostInfo::GetArchitecture(*kind); 2004ebb64b9SPavel Labath 2017263f1bdSPavel Labath llvm::Triple host_triple(llvm::sys::getDefaultTargetTriple()); 2027263f1bdSPavel Labath 2037263f1bdSPavel Labath if (normalized_triple.getVendorName().empty()) 2047263f1bdSPavel Labath normalized_triple.setVendor(host_triple.getVendor()); 2057263f1bdSPavel Labath if (normalized_triple.getOSName().empty()) 2067263f1bdSPavel Labath normalized_triple.setOS(host_triple.getOS()); 2077263f1bdSPavel Labath if (normalized_triple.getEnvironmentName().empty()) 2087263f1bdSPavel Labath normalized_triple.setEnvironment(host_triple.getEnvironment()); 2097263f1bdSPavel Labath return ArchSpec(normalized_triple); 2107263f1bdSPavel Labath } 2117263f1bdSPavel Labath 21253954b5eSAlex Langford bool HostInfoBase::ComputePathRelativeToLibrary(FileSpec &file_spec, 21353954b5eSAlex Langford llvm::StringRef dir) { 21453954b5eSAlex Langford Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); 21553954b5eSAlex Langford 21653954b5eSAlex Langford FileSpec lldb_file_spec = GetShlibDir(); 21753954b5eSAlex Langford if (!lldb_file_spec) 21853954b5eSAlex Langford return false; 21953954b5eSAlex Langford 22053954b5eSAlex Langford std::string raw_path = lldb_file_spec.GetPath(); 22163e5fb76SJonas Devlieghere LLDB_LOGF(log, 22263e5fb76SJonas Devlieghere "HostInfo::%s() attempting to " 22353954b5eSAlex Langford "derive the path %s relative to liblldb install path: %s", 22453954b5eSAlex Langford __FUNCTION__, dir.data(), raw_path.c_str()); 22553954b5eSAlex Langford 22653954b5eSAlex Langford // Drop bin (windows) or lib 22753954b5eSAlex Langford llvm::StringRef parent_path = llvm::sys::path::parent_path(raw_path); 22853954b5eSAlex Langford if (parent_path.empty()) { 22963e5fb76SJonas Devlieghere LLDB_LOGF(log, 23063e5fb76SJonas Devlieghere "HostInfo::%s() failed to find liblldb within the shared " 23153954b5eSAlex Langford "lib path", 23253954b5eSAlex Langford __FUNCTION__); 23353954b5eSAlex Langford return false; 23453954b5eSAlex Langford } 23553954b5eSAlex Langford 23653954b5eSAlex Langford raw_path = (parent_path + dir).str(); 23763e5fb76SJonas Devlieghere LLDB_LOGF(log, "HostInfo::%s() derived the path as: %s", __FUNCTION__, 23853954b5eSAlex Langford raw_path.c_str()); 23953954b5eSAlex Langford file_spec.GetDirectory().SetString(raw_path); 24053954b5eSAlex Langford return (bool)file_spec.GetDirectory(); 24153954b5eSAlex Langford } 24253954b5eSAlex Langford 243b9c1b51eSKate Stone bool HostInfoBase::ComputeSharedLibraryDirectory(FileSpec &file_spec) { 24442ff0ad8SZachary Turner // To get paths related to LLDB we get the path to the executable that 245cc2ba028SPavel Labath // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB". 246cc2ba028SPavel Labath // On other posix systems, we will get .../lib(64|32)?/liblldb.so. 24742ff0ad8SZachary Turner 24860f028ffSPavel Labath FileSpec lldb_file_spec(Host::GetModuleFileSpecForHostAddress( 249*df6879ecSJan Kratochvil reinterpret_cast<void *>( 250*df6879ecSJan Kratochvil HostInfoBase::ComputeSharedLibraryDirectory))); 25142ff0ad8SZachary Turner 252b9c1b51eSKate Stone // This is necessary because when running the testsuite the shlib might be a 253b9c1b51eSKate Stone // symbolic link inside the Python resource dir. 25446376966SJonas Devlieghere FileSystem::Instance().ResolveSymbolicLink(lldb_file_spec, lldb_file_spec); 255db7d8083SSean Callanan 25642ff0ad8SZachary Turner // Remove the filename so that this FileSpec only represents the directory. 2570d8400c8SGreg Clayton file_spec.GetDirectory() = lldb_file_spec.GetDirectory(); 25842ff0ad8SZachary Turner 25942ff0ad8SZachary Turner return (bool)file_spec.GetDirectory(); 26042ff0ad8SZachary Turner } 26142ff0ad8SZachary Turner 262b9c1b51eSKate Stone bool HostInfoBase::ComputeSupportExeDirectory(FileSpec &file_spec) { 26360f028ffSPavel Labath file_spec = GetShlibDir(); 26460f028ffSPavel Labath return bool(file_spec); 26542ff0ad8SZachary Turner } 26642ff0ad8SZachary Turner 267b9c1b51eSKate Stone bool HostInfoBase::ComputeProcessTempFileDirectory(FileSpec &file_spec) { 26863acdfdeSOleksiy Vyalov FileSpec temp_file_spec; 269f3a24329STamas Berghammer if (!HostInfo::ComputeGlobalTempFileDirectory(temp_file_spec)) 27063acdfdeSOleksiy Vyalov return false; 27163acdfdeSOleksiy Vyalov 2721eb0d42aSPavel Labath std::string pid_str{llvm::to_string(Host::GetCurrentProcessID())}; 273d3173f34SChaoren Lin temp_file_spec.AppendPathComponent(pid_str); 274d3d95fd6SZachary Turner if (llvm::sys::fs::create_directory(temp_file_spec.GetPath())) 27563acdfdeSOleksiy Vyalov return false; 27663acdfdeSOleksiy Vyalov 277b79863c2SChaoren Lin file_spec.GetDirectory().SetCString(temp_file_spec.GetCString()); 27863acdfdeSOleksiy Vyalov return true; 27963acdfdeSOleksiy Vyalov } 28063acdfdeSOleksiy Vyalov 281b9c1b51eSKate Stone bool HostInfoBase::ComputeTempFileBaseDirectory(FileSpec &file_spec) { 28233183147SPavel Labath llvm::SmallVector<char, 16> tmpdir; 28333183147SPavel Labath llvm::sys::path::system_temp_directory(/*ErasedOnReboot*/ true, tmpdir); 2848f3be7a3SJonas Devlieghere file_spec = FileSpec(std::string(tmpdir.data(), tmpdir.size())); 2858f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(file_spec); 286f3a24329STamas Berghammer return true; 287f3a24329STamas Berghammer } 288f3a24329STamas Berghammer 289b9c1b51eSKate Stone bool HostInfoBase::ComputeGlobalTempFileDirectory(FileSpec &file_spec) { 290f3a24329STamas Berghammer file_spec.Clear(); 291f3a24329STamas Berghammer 292f3a24329STamas Berghammer FileSpec temp_file_spec; 293f3a24329STamas Berghammer if (!HostInfo::ComputeTempFileBaseDirectory(temp_file_spec)) 294f3a24329STamas Berghammer return false; 295f3a24329STamas Berghammer 296270e99abSZachary Turner temp_file_spec.AppendPathComponent("lldb"); 297d3d95fd6SZachary Turner if (llvm::sys::fs::create_directory(temp_file_spec.GetPath())) 29842ff0ad8SZachary Turner return false; 29942ff0ad8SZachary Turner 300b79863c2SChaoren Lin file_spec.GetDirectory().SetCString(temp_file_spec.GetCString()); 30142ff0ad8SZachary Turner return true; 30242ff0ad8SZachary Turner } 30342ff0ad8SZachary Turner 304b9c1b51eSKate Stone bool HostInfoBase::ComputeHeaderDirectory(FileSpec &file_spec) { 305b9c1b51eSKate Stone // TODO(zturner): Figure out how to compute the header directory for all 306b9c1b51eSKate Stone // platforms. 30742ff0ad8SZachary Turner return false; 30842ff0ad8SZachary Turner } 30942ff0ad8SZachary Turner 310b9c1b51eSKate Stone bool HostInfoBase::ComputeSystemPluginsDirectory(FileSpec &file_spec) { 311b9c1b51eSKate Stone // TODO(zturner): Figure out how to compute the system plugins directory for 312b9c1b51eSKate Stone // all platforms. 31342ff0ad8SZachary Turner return false; 31442ff0ad8SZachary Turner } 31542ff0ad8SZachary Turner 316b9c1b51eSKate Stone bool HostInfoBase::ComputeUserPluginsDirectory(FileSpec &file_spec) { 31705097246SAdrian Prantl // TODO(zturner): Figure out how to compute the user plugins directory for 31805097246SAdrian Prantl // all platforms. 319b1e1c62fSSean Callanan return false; 320b1e1c62fSSean Callanan } 321b1e1c62fSSean Callanan 322b9c1b51eSKate Stone void HostInfoBase::ComputeHostArchitectureSupport(ArchSpec &arch_32, 323b9c1b51eSKate Stone ArchSpec &arch_64) { 324b071bee2SOleksiy Vyalov llvm::Triple triple(llvm::sys::getProcessTriple()); 32513b18261SZachary Turner 32613b18261SZachary Turner arch_32.Clear(); 32713b18261SZachary Turner arch_64.Clear(); 32813b18261SZachary Turner 329b9c1b51eSKate Stone switch (triple.getArch()) { 33013b18261SZachary Turner default: 33113b18261SZachary Turner arch_32.SetTriple(triple); 33213b18261SZachary Turner break; 33313b18261SZachary Turner 334e85e6021STamas Berghammer case llvm::Triple::aarch64: 3352559abdaSJustin Hibbits case llvm::Triple::ppc64: 336686b27b5SPavel Labath case llvm::Triple::ppc64le: 337f9ee7e4cSJustin Hibbits case llvm::Triple::x86_64: 33813b18261SZachary Turner arch_64.SetTriple(triple); 33913b18261SZachary Turner arch_32.SetTriple(triple.get32BitArchVariant()); 34013b18261SZachary Turner break; 34113b18261SZachary Turner 34213b18261SZachary Turner case llvm::Triple::mips64: 3433df471c3SMohit K. Bhakkad case llvm::Triple::mips64el: 34413b18261SZachary Turner case llvm::Triple::sparcv9: 345bb00d0b6SUlrich Weigand case llvm::Triple::systemz: 34613b18261SZachary Turner arch_64.SetTriple(triple); 34713b18261SZachary Turner break; 34813b18261SZachary Turner } 34913b18261SZachary Turner } 350