clang 22.0.0git
MipsLinux.cpp
Go to the documentation of this file.
1//===-- MipsLinux.cpp - Mips ToolChain Implementations ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "MipsLinux.h"
10#include "Arch/Mips.h"
11#include "clang/Driver/Driver.h"
13#include "llvm/Option/ArgList.h"
14#include "llvm/Support/FileSystem.h"
15#include "llvm/Support/Path.h"
16
17using namespace clang::driver;
18using namespace clang::driver::toolchains;
19using namespace clang;
20using namespace llvm::opt;
21
22/// Mips Toolchain
24 const llvm::Triple &Triple,
25 const ArgList &Args)
26 : Linux(D, Triple, Args) {
27 // Select the correct multilib according to the given arguments.
29 findMIPSMultilibs(D, Triple, "", Args, Result);
30 Multilibs = Result.Multilibs;
31 SelectedMultilibs = Result.SelectedMultilibs;
32
33 // Find out the library suffix based on the ABI.
34 LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple);
35 getFilePaths().clear();
36 getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix);
37}
38
40 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
41 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
42 return;
43
44 const Driver &D = getDriver();
45
46 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
47 SmallString<128> P(D.ResourceDir);
48 llvm::sys::path::append(P, "include");
49 addSystemInclude(DriverArgs, CC1Args, P);
50 }
51
52 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
53 return;
54
55 const auto &Callback = Multilibs.includeDirsCallback();
56 if (Callback) {
57 for (const auto &Path : Callback(SelectedMultilibs.back()))
58 addExternCSystemIncludeIfExists(DriverArgs, CC1Args, D.Dir + Path);
59 }
60}
61
63 return new tools::gnutools::Linker(*this);
64}
65
67 if (!getDriver().SysRoot.empty())
68 return getDriver().SysRoot + SelectedMultilibs.back().osSuffix();
69
70 const std::string InstalledDir(getDriver().Dir);
71 std::string SysRootPath =
72 InstalledDir + "/../sysroot" + SelectedMultilibs.back().osSuffix();
73 if (llvm::sys::fs::exists(SysRootPath))
74 return SysRootPath;
75
76 return std::string();
77}
78
80MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const {
81 Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
82 if (A) {
83 StringRef Value = A->getValue();
84 if (Value != "libc++")
85 getDriver().Diag(clang::diag::err_drv_invalid_stdlib_name)
86 << A->getAsString(Args);
87 }
88
90}
91
93 const llvm::opt::ArgList &DriverArgs,
94 llvm::opt::ArgStringList &CC1Args) const {
95 if (const auto &Callback = Multilibs.includeDirsCallback()) {
96 for (std::string Path : Callback(SelectedMultilibs.back())) {
97 Path = getDriver().Dir + Path + "/c++/v1";
98 if (llvm::sys::fs::exists(Path)) {
99 addSystemInclude(DriverArgs, CC1Args, Path);
100 return;
101 }
102 }
103 }
104}
105
107 ArgStringList &CmdArgs) const {
108 assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
109 "Only -lc++ (aka libxx) is supported in this toolchain.");
110
111 CmdArgs.push_back("-lc++");
112 if (Args.hasArg(options::OPT_fexperimental_library))
113 CmdArgs.push_back("-lc++experimental");
114 CmdArgs.push_back("-lc++abi");
115 CmdArgs.push_back("-lunwind");
116}
117
118std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args,
119 StringRef Component, FileType Type,
120 bool IsFortran) const {
121 SmallString<128> Path(getDriver().ResourceDir);
122 llvm::sys::path::append(Path, SelectedMultilibs.back().osSuffix(), "lib" + LibSuffix,
123 getOS());
124 const char *Suffix;
125 switch (Type) {
127 Suffix = ".o";
128 break;
130 Suffix = ".a";
131 break;
133 Suffix = ".so";
134 break;
135 }
136 llvm::sys::path::append(
137 Path, Twine("libclang_rt." + Component + "-" + "mips" + Suffix));
138 return std::string(Path);
139}
The base class of the type hierarchy.
Definition TypeBase.h:1833
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:99
std::string SysRoot
sysroot, if present
Definition Driver.h:205
DiagnosticBuilder Diag(unsigned DiagID) const
Definition Driver.h:169
std::string Dir
The path the driver executable was in, as invoked from the command line.
Definition Driver.h:180
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
path_list & getFilePaths()
Definition ToolChain.h:295
StringRef getOS() const
Definition ToolChain.h:272
const Driver & getDriver() const
Definition ToolChain.h:253
static void addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
llvm::SmallVector< Multilib > SelectedMultilibs
Definition ToolChain.h:200
Tool - Information on a specific compilation tool.
Definition Tool.h:32
Linux(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition Linux.cpp:212
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
MipsLLVMToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Mips Toolchain.
Definition MipsLinux.cpp:23
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition MipsLinux.cpp:80
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition MipsLinux.cpp:39
void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Definition MipsLinux.cpp:92
std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static, bool IsFortran=false) const override
std::string computeSysRoot() const override
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
Definition MipsLinux.cpp:66
std::string getMipsABILibSuffix(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
bool findMIPSMultilibs(const Driver &D, const llvm::Triple &TargetTriple, StringRef Path, const llvm::opt::ArgList &Args, DetectedMultilibs &Result)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
Definition TypeBase.h:905