12#include "clang/Config/config.h"
18#include "llvm/Option/ArgList.h"
19#include "llvm/ProfileData/InstrProf.h"
20#include "llvm/Support/FileSystem.h"
21#include "llvm/Support/Path.h"
22#include "llvm/Support/VirtualFileSystem.h"
23#include "llvm/Support/ScopedPrinter.h"
43 Multilib(
"/a7_soft", {}, {}, {
"-mcpu=cortex-a7",
"-mfloat-abi=soft"}));
46 Multilib(
"/a7_softfp_neon-vfpv4", {}, {},
47 {
"-mcpu=cortex-a7",
"-mfloat-abi=softfp",
"-mfpu=neon-vfpv4"}));
50 Multilib(
"/a7_hard_neon-vfpv4", {}, {},
51 {
"-mcpu=cortex-a7",
"-mfloat-abi=hard",
"-mfpu=neon-vfpv4"}));
53 if (Multilibs.
select(Flags, Result.SelectedMultilibs)) {
54 Result.Multilibs = Multilibs;
62 const llvm::Triple &TargetTriple,
63 StringRef
Path,
const ArgList &Args,
67 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
68 IsA7 = A->getValue() == StringRef(
"cortex-a7");
72 if (
const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ))
73 IsMFPU = A->getValue() == StringRef(
"neon-vfpv4");
78 "-mfloat-abi=soft", Flags);
80 "-mfloat-abi=softfp", Flags);
82 "-mfloat-abi=hard", Flags);
90 switch (
T.getArch()) {
98 case llvm::Triple::arm:
99 case llvm::Triple::thumb:
100 return T.isOSLiteOS() ?
"arm-liteos-ohos" :
"arm-linux-ohos";
101 case llvm::Triple::riscv32:
102 return "riscv32-linux-ohos";
103 case llvm::Triple::riscv64:
104 return "riscv64-linux-ohos";
105 case llvm::Triple::mipsel:
106 return "mipsel-linux-ohos";
107 case llvm::Triple::x86:
108 return "i686-linux-ohos";
109 case llvm::Triple::x86_64:
110 return "x86_64-linux-ohos";
111 case llvm::Triple::aarch64:
112 return "aarch64-linux-ohos";
118 const llvm::Triple &TargetTriple,
119 StringRef SysRoot)
const {
123static std::string
makePath(
const std::initializer_list<std::string> &IL) {
125 for (
const auto &S : IL)
126 llvm::sys::path::append(
P, S);
127 return static_cast<std::string
>(
P.str());
146 if (
getVFS().exists(CandidateLibPath))
159 std::string SysRootLibPath =
makePath({SysRoot,
"usr",
"lib"});
164 makePath({
D.Dir,
"..",
"lib", MultiarchTriple,
175 const ArgList &Args)
const {
176 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) {
177 StringRef
Value = A->getValue();
178 if (
Value !=
"compiler-rt")
180 << A->getAsString(Args);
188 if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
189 StringRef
Value = A->getValue();
190 if (
Value !=
"libc++")
192 << A->getAsString(Args);
199 ArgStringList &CC1Args)
const {
201 const llvm::Triple &Triple =
getTriple();
204 if (DriverArgs.hasArg(options::OPT_nostdinc))
207 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
209 llvm::sys::path::append(
P,
"include");
213 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
217 StringRef CIncludeDirs(C_INCLUDE_DIRS);
218 if (CIncludeDirs !=
"") {
220 CIncludeDirs.split(dirs,
":");
221 for (StringRef dir : dirs) {
223 llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) :
"";
230 SysRoot +
"/usr/include/" +
237 ArgStringList &CC1Args)
const {
238 if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
239 DriverArgs.hasArg(options::OPT_nostdincxx))
245 std::string IncTargetPath =
247 if (
getVFS().exists(IncTargetPath)) {
255 llvm_unreachable(
"invalid stdlib name");
260 ArgStringList &CmdArgs)
const {
263 CmdArgs.push_back(
"-lc++");
264 CmdArgs.push_back(
"-lc++abi");
265 CmdArgs.push_back(
"-lunwind");
269 llvm_unreachable(
"invalid stdlib name");
274 std::string SysRoot =
278 if (!llvm::sys::fs::exists(SysRoot))
279 return std::string();
282 return llvm::sys::fs::exists(ArchRoot) ? ArchRoot : SysRoot;
289 const llvm::Triple &Triple =
getTriple();
292 P.assign(
D.ResourceDir);
293 llvm::sys::path::append(
P,
"lib",
D.getTargetTriple(), SelectedMultilib.
gccSuffix());
294 Paths.push_back(
P.c_str());
297 P.assign(
D.ResourceDir);
298 llvm::sys::path::append(
P,
"lib", Triple.str(), SelectedMultilib.
gccSuffix());
299 Paths.push_back(
P.c_str());
302 P.assign(
D.ResourceDir);
306 Paths.push_back(
P.c_str());
312 const llvm::Triple &Triple =
getTriple();
313 const llvm::Triple::ArchType Arch =
getArch();
315 assert(Triple.isMusl());
316 std::string ArchName;
320 case llvm::Triple::arm:
321 case llvm::Triple::thumb:
325 case llvm::Triple::armeb:
326 case llvm::Triple::thumbeb:
331 ArchName = Triple.getArchName().str();
337 return "/lib/ld-musl-" + ArchName +
".so.1";
359 llvm::sys::path::append(
360 Path, Prefix + Twine(
"clang_rt.") + Component + Suffix);
361 return static_cast<std::string
>(
Path.str());
365 CmdArgs.push_back(
"-z");
366 CmdArgs.push_back(
"now");
367 CmdArgs.push_back(
"-z");
368 CmdArgs.push_back(
"relro");
369 CmdArgs.push_back(
"-z");
370 CmdArgs.push_back(
"max-page-size=4096");
372 if (
getArch() != llvm::Triple::mipsel)
373 CmdArgs.push_back(
"--hash-style=both");
374#ifdef ENABLE_LINKER_BUILD_ID
375 CmdArgs.push_back(
"--build-id");
377 CmdArgs.push_back(
"--enable-new-dtags");
382 Res |= SanitizerKind::Address;
383 Res |= SanitizerKind::PointerCompare;
384 Res |= SanitizerKind::PointerSubtract;
385 Res |= SanitizerKind::Fuzzer;
386 Res |= SanitizerKind::FuzzerNoLink;
387 Res |= SanitizerKind::Memory;
388 Res |= SanitizerKind::Vptr;
389 Res |= SanitizerKind::SafeStack;
390 Res |= SanitizerKind::Scudo;
398 llvm::opt::ArgStringList &CmdArgs)
const {
402 CmdArgs.push_back(Args.MakeArgString(
403 Twine(
"-u", llvm::getInstrProfRuntimeHookVarName())));
416 if (Args.getLastArg(options::OPT_unwindlib_EQ))
static std::string makePath(const std::initializer_list< std::string > &IL)
static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
static bool findOHOSMuslMultilibs(const Multilib::flags_list &Flags, DetectedMultilibs &Result)
The base class of the type hierarchy.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
std::string SysRoot
sysroot, if present
DiagnosticBuilder Diag(unsigned DiagID) const
std::string ResourceDir
The path to the compiler resource directory.
std::string Dir
The path the driver executable was in, as invoked from the command line.
See also MultilibSetBuilder for combining multilibs into a set.
bool select(const Multilib::flags_list &Flags, llvm::SmallVectorImpl< Multilib > &) const
Select compatible variants,.
void push_back(const Multilib &M)
Add a completed Multilib to the set.
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag.
const std::string & gccSuffix() const
Get the detected GCC installation path suffix for the multi-arch target variant.
std::vector< std::string > flags_list
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T