clang 20.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 "CommonArgs.h"
12#include "clang/Driver/Driver.h"
15#include "llvm/Option/ArgList.h"
16#include "llvm/Support/FileSystem.h"
17#include "llvm/Support/Path.h"
18
19using namespace clang::driver;
20using namespace clang::driver::toolchains;
21using namespace clang;
22using namespace llvm::opt;
23
24/// Mips Toolchain
26 const llvm::Triple &Triple,
27 const ArgList &Args)
28 : Linux(D, Triple, Args) {
29 // Select the correct multilib according to the given arguments.
31 findMIPSMultilibs(D, Triple, "", Args, Result);
32 Multilibs = Result.Multilibs;
33 SelectedMultilibs = Result.SelectedMultilibs;
34
35 // Find out the library suffix based on the ABI.
36 LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple);
37 getFilePaths().clear();
38 getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix);
39}
40
42 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
43 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
44 return;
45
46 const Driver &D = getDriver();
47
48 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
49 SmallString<128> P(D.ResourceDir);
50 llvm::sys::path::append(P, "include");
51 addSystemInclude(DriverArgs, CC1Args, P);
52 }
53
54 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
55 return;
56
57 const auto &Callback = Multilibs.includeDirsCallback();
58 if (Callback) {
59 for (const auto &Path : Callback(SelectedMultilibs.back()))
60 addExternCSystemIncludeIfExists(DriverArgs, CC1Args, D.Dir + Path);
61 }
62}
63
65 return new tools::gnutools::Linker(*this);
66}
67
69 if (!getDriver().SysRoot.empty())
70 return getDriver().SysRoot + SelectedMultilibs.back().osSuffix();
71
72 const std::string InstalledDir(getDriver().Dir);
73 std::string SysRootPath =
74 InstalledDir + "/../sysroot" + SelectedMultilibs.back().osSuffix();
75 if (llvm::sys::fs::exists(SysRootPath))
76 return SysRootPath;
77
78 return std::string();
79}
80
82MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const {
83 Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
84 if (A) {
85 StringRef Value = A->getValue();
86 if (Value != "libc++")
87 getDriver().Diag(clang::diag::err_drv_invalid_stdlib_name)
88 << A->getAsString(Args);
89 }
90
92}
93
95 const llvm::opt::ArgList &DriverArgs,
96 llvm::opt::ArgStringList &CC1Args) const {
97 if (const auto &Callback = Multilibs.includeDirsCallback()) {
98 for (std::string Path : Callback(SelectedMultilibs.back())) {
99 Path = getDriver().Dir + Path + "/c++/v1";
100 if (llvm::sys::fs::exists(Path)) {
101 addSystemInclude(DriverArgs, CC1Args, Path);
102 return;
103 }
104 }
105 }
106}
107
109 ArgStringList &CmdArgs) const {
110 assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
111 "Only -lc++ (aka libxx) is supported in this toolchain.");
112
113 CmdArgs.push_back("-lc++");
114 if (Args.hasArg(options::OPT_fexperimental_library))
115 CmdArgs.push_back("-lc++experimental");
116 CmdArgs.push_back("-lc++abi");
117 CmdArgs.push_back("-lunwind");
118}
119
120std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args,
121 StringRef Component,
122 FileType Type) const {
123 SmallString<128> Path(getDriver().ResourceDir);
124 llvm::sys::path::append(Path, SelectedMultilibs.back().osSuffix(), "lib" + LibSuffix,
125 getOS());
126 const char *Suffix;
127 switch (Type) {
129 Suffix = ".o";
130 break;
132 Suffix = ".a";
133 break;
135 Suffix = ".so";
136 break;
137 }
138 llvm::sys::path::append(
139 Path, Twine("libclang_rt." + Component + "-" + "mips" + Suffix));
140 return std::string(Path);
141}
StringRef P
const Decl * D
IndirectLocalPath & Path
The base class of the type hierarchy.
Definition: Type.h:1829
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
std::string SysRoot
sysroot, if present
Definition: Driver.h:180
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:144
std::string Dir
The path the driver executable was in, as invoked from the command line.
Definition: Driver.h:155
const IncludeDirsFunc & includeDirsCallback() const
Definition: Multilib.h:150
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.
Definition: ToolChain.cpp:1209
path_list & getFilePaths()
Definition: ToolChain.h:294
StringRef getOS() const
Definition: ToolChain.h:271
const Driver & getDriver() const
Definition: ToolChain.h:252
static void addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Definition: ToolChain.cpp:1231
llvm::SmallVector< Multilib > SelectedMultilibs
Definition: ToolChain.h:201
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
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...
Definition: MipsLinux.cpp:108
MipsLLVMToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Mips Toolchain.
Definition: MipsLinux.cpp:25
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition: MipsLinux.cpp:82
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:41
std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const override
Definition: MipsLinux.cpp:120
void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Definition: MipsLinux.cpp:94
std::string computeSysRoot() const override
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
Definition: MipsLinux.cpp:68
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.