clang: lib/Driver/ToolChains/OHOS.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
11#include "clang/Config/config.h"
17#include "llvm/Option/ArgList.h"
18#include "llvm/ProfileData/InstrProf.h"
19#include "llvm/Support/FileSystem.h"
20#include "llvm/Support/Path.h"
21#include "llvm/Support/VirtualFileSystem.h"
22
26using namespace clang;
29
32
38
39
40
42 Multilib("/a7_soft", {}, {}, {"-mcpu=cortex-a7", "-mfloat-abi=soft"}));
43
45 Multilib("/a7_softfp_neon-vfpv4", {}, {},
46 {"-mcpu=cortex-a7", "-mfloat-abi=softfp", "-mfpu=neon-vfpv4"}));
47
49 Multilib("/a7_hard_neon-vfpv4", {}, {},
50 {"-mcpu=cortex-a7", "-mfloat-abi=hard", "-mfpu=neon-vfpv4"}));
51
52 if (Multilibs.select(D, Flags, Result.SelectedMultilibs)) {
53 Result.Multilibs = Multilibs;
54 return true;
55 }
56 return false;
57}
58
61 const llvm::Triple &TargetTriple,
62 StringRef Path, const ArgList &Args,
65 bool IsA7 = false;
66 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
67 IsA7 = A->getValue() == StringRef("cortex-a7");
69
70 bool IsMFPU = false;
71 if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ))
72 IsMFPU = A->getValue() == StringRef("neon-vfpv4");
74
77 "-mfloat-abi=soft", Flags);
79 "-mfloat-abi=softfp", Flags);
81 "-mfloat-abi=hard", Flags);
82
84}
85
87
88
89 switch (T.getArch()) {
90 default:
91 break;
92
93
94
95
96
97 case llvm::Triple::arm:
98 case llvm::Triple::thumb:
99 return T.isOSLiteOS() ? "arm-liteos-ohos" : "arm-linux-ohos";
100 case llvm::Triple::riscv32:
101 return "riscv32-linux-ohos";
102 case llvm::Triple::riscv64:
103 return "riscv64-linux-ohos";
104 case llvm::Triple::mipsel:
105 return "mipsel-linux-ohos";
106 case llvm::Triple::x86:
107 return "i686-linux-ohos";
108 case llvm::Triple::x86_64:
109 return "x86_64-linux-ohos";
110 case llvm::Triple::aarch64:
111 return "aarch64-linux-ohos";
112 case llvm::Triple::loongarch64:
113 return "loongarch64-linux-ohos";
114 }
115 return T.str();
116}
117
119 const llvm::Triple &TargetTriple,
120 StringRef SysRoot) const {
122}
123
124static std::string makePath(const std::initializer_liststd::string &IL) {
126 for (const auto &S : IL)
127 llvm::sys::path::append(P, S);
128 return static_caststd::string\(P.str());
129}
130
131
132OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
135
136
143 }
144
147 if (getVFS().exists(CandidateLibPath))
149
152 if (getVFS().exists(Path))
154
155
156
157
158
160 std::string SysRootLibPath = makePath({SysRoot, "usr", "lib"});
163 Paths);
165 makePath({D.Dir, "..", "lib", MultiarchTriple,
166 SelectedMultilib.gccSuffix()}),
167 Paths);
168
170 D,
171 makePath({SysRootLibPath, MultiarchTriple, SelectedMultilib.gccSuffix()}),
172 Paths);
173}
174
176 const ArgList &Args) const {
177 if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
178 StringRef Value = A->getValue();
179 if (Value != "compiler-rt")
180 getDriver().Diag(clang::diag::err_drv_invalid_rtlib_name)
181 << A->getAsString(Args);
182 }
183
185}
186
189 if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
190 StringRef Value = A->getValue();
191 if (Value != "libc++")
192 getDriver().Diag(diag::err_drv_invalid_stdlib_name)
193 << A->getAsString(Args);
194 }
195
197}
198
200 ArgStringList &CC1Args) const {
202 const llvm::Triple &Triple = getTriple();
204
205 if (DriverArgs.hasArg(options::OPT_nostdinc))
206 return;
207
208 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
210 llvm::sys::path::append(P, "include");
212 }
213
214 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
215 return;
216
217
218 StringRef CIncludeDirs(C_INCLUDE_DIRS);
219 if (CIncludeDirs != "") {
221 CIncludeDirs.split(dirs, ":");
222 for (StringRef dir : dirs) {
223 StringRef Prefix =
224 llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : "";
226 }
227 return;
228 }
229
231 SysRoot + "/usr/include/" +
235}
236
238 ArgStringList &CC1Args) const {
239 if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
240 DriverArgs.hasArg(options::OPT_nostdincxx))
241 return;
242
246 std::string IncTargetPath =
248 if (getVFS().exists(IncTargetPath)) {
251 }
252 break;
253 }
254
255 default:
256 llvm_unreachable("invalid stdlib name");
257 }
258}
259
261 ArgStringList &CmdArgs) const {
264 CmdArgs.push_back("-lc++");
265 CmdArgs.push_back("-lc++abi");
266 CmdArgs.push_back("-lunwind");
267 break;
268
270 llvm_unreachable("invalid stdlib name");
271 }
272}
273
275 std::string SysRoot =
279 if (!llvm::sys::fs::exists(SysRoot))
280 return std::string();
281
283 return llvm::sys::fs::exists(ArchRoot) ? ArchRoot : SysRoot;
284}
285
290 const llvm::Triple &Triple = getTriple();
291
292
293 P.assign(D.ResourceDir);
294 llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix());
295 Paths.push_back(P.c_str());
296
297
298 P.assign(D.ResourceDir);
299 llvm::sys::path::append(P, "lib", Triple.str(), SelectedMultilib.gccSuffix());
300 Paths.push_back(P.c_str());
301
302
303 P.assign(D.ResourceDir);
305 SelectedMultilib.gccSuffix());
306 Paths.push_back(P.c_str());
307
308 return Paths;
309}
310
312 const llvm::Triple &Triple = getTriple();
313 const llvm::Triple::ArchType Arch = getArch();
314
315 assert(Triple.isMusl());
316 std::string ArchName;
317 bool IsArm = false;
318
319 switch (Arch) {
320 case llvm::Triple::arm:
321 case llvm::Triple::thumb:
322 ArchName = "arm";
323 IsArm = true;
324 break;
325 case llvm::Triple::armeb:
326 case llvm::Triple::thumbeb:
327 ArchName = "armeb";
328 IsArm = true;
329 break;
330 default:
331 ArchName = Triple.getArchName().str();
332 }
333 if (IsArm &&
335 ArchName += "hf";
336
337 return "/lib/ld-musl-" + ArchName + ".so.1";
338}
339
344 SelectedMultilib.gccSuffix());
345 const char *Prefix =
347 const char *Suffix;
348 switch (Type) {
350 Suffix = ".o";
351 break;
353 Suffix = ".a";
354 break;
356 Suffix = ".so";
357 break;
358 }
359 llvm::sys::path::append(
360 Path, Prefix + Twine("clang_rt.") + Component + Suffix);
361 return static_caststd::string\(Path.str());
362}
363
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(getArch() == llvm::Triple::loongarch64
371 ? "max-page-size=16384"
372 : "max-page-size=4096");
373
374 if (getArch() != llvm::Triple::mipsel)
375 CmdArgs.push_back("--hash-style=both");
376#ifdef ENABLE_LINKER_BUILD_ID
377 CmdArgs.push_back("--build-id");
378#endif
379 CmdArgs.push_back("--enable-new-dtags");
380}
381
384 Res |= SanitizerKind::Address;
385 Res |= SanitizerKind::PointerCompare;
386 Res |= SanitizerKind::PointerSubtract;
387 Res |= SanitizerKind::Fuzzer;
388 Res |= SanitizerKind::FuzzerNoLink;
389 Res |= SanitizerKind::Memory;
390 Res |= SanitizerKind::Vptr;
391 Res |= SanitizerKind::SafeStack;
392 Res |= SanitizerKind::Scudo;
393
394
395 return Res;
396}
397
398
400 llvm::opt::ArgStringList &CmdArgs) const {
401
402
404 CmdArgs.push_back(Args.MakeArgString(
405 Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
407}
408
411 llvm::Triple Triple = getTriple();
412 Paths.push_back(
414 return Paths;
415}
416
418 if (Args.getLastArg(options::OPT_unwindlib_EQ))
421}
static bool findOHOSMuslMultilibs(const Driver &D, const Multilib::flags_list &Flags, DetectedMultilibs &Result)
Definition OHOS.cpp:33
static std::string makePath(const std::initializer_list< std::string > &IL)
Definition OHOS.cpp:124
static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC, const llvm::Triple &TargetTriple, StringRef Path, const ArgList &Args, DetectedMultilibs &Result)
Definition OHOS.cpp:59
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 Driver &D, const Multilib::flags_list &Flags, llvm::SmallVectorImpl< Multilib > &, llvm::SmallVector< StringRef > *=nullptr) 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.
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