19
19
#include " llvm/ProfileData/InstrProf.h"
20
20
#include " llvm/Support/FileSystem.h"
21
21
#include " llvm/Support/Path.h"
22
- #include " llvm/Support/VirtualFileSystem.h"
23
22
#include " llvm/Support/ScopedPrinter.h"
23
+ #include " llvm/Support/VirtualFileSystem.h"
24
24
25
25
using namespace clang ::driver;
26
26
using namespace clang ::driver::toolchains;
@@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D,
58
58
return false ;
59
59
}
60
60
61
- static bool findOHOSMultilibs (const Driver &D,
62
- const ToolChain &TC,
63
- const llvm::Triple &TargetTriple,
64
- StringRef Path, const ArgList &Args,
65
- DetectedMultilibs &Result) {
61
+ static bool findOHOSMultilibs (const Driver &D, const ToolChain &TC,
62
+ const llvm::Triple &TargetTriple, StringRef Path,
63
+ const ArgList &Args, DetectedMultilibs &Result) {
66
64
Multilib::flags_list Flags;
67
65
bool IsA7 = false ;
68
66
if (const Arg *A = Args.getLastArg (options::OPT_mcpu_EQ))
@@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
172
170
Paths);
173
171
}
174
172
175
- ToolChain::RuntimeLibType OHOS::GetRuntimeLibType (
176
- const ArgList &Args) const {
173
+ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType (const ArgList &Args) const {
177
174
if (Arg *A = Args.getLastArg (clang::driver::options::OPT_rtlib_EQ)) {
178
175
StringRef Value = A->getValue ();
179
176
if (Value != " compiler-rt" )
@@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(
184
181
return ToolChain::RLT_CompilerRT;
185
182
}
186
183
187
- ToolChain::CXXStdlibType
188
- OHOS::GetCXXStdlibType (const ArgList &Args) const {
184
+ ToolChain::CXXStdlibType OHOS::GetCXXStdlibType (const ArgList &Args) const {
189
185
if (Arg *A = Args.getLastArg (options::OPT_stdlib_EQ)) {
190
186
StringRef Value = A->getValue ();
191
187
if (Value != " libc++" )
192
188
getDriver ().Diag (diag::err_drv_invalid_stdlib_name)
193
- << A->getAsString (Args);
189
+ << A->getAsString (Args);
194
190
}
195
191
196
192
return ToolChain::CST_Libcxx;
197
193
}
198
194
199
195
void OHOS::AddClangSystemIncludeArgs (const ArgList &DriverArgs,
200
- ArgStringList &CC1Args) const {
196
+ ArgStringList &CC1Args) const {
201
197
const Driver &D = getDriver ();
202
198
const llvm::Triple &Triple = getTriple ();
203
199
std::string SysRoot = computeSysRoot ();
@@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
258
254
}
259
255
260
256
void OHOS::AddCXXStdlibLibArgs (const ArgList &Args,
261
- ArgStringList &CmdArgs) const {
257
+ ArgStringList &CmdArgs) const {
262
258
switch (GetCXXStdlibType (Args)) {
263
259
case ToolChain::CST_Libcxx:
264
260
CmdArgs.push_back (" -lc++" );
@@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
291
287
292
288
// First try the triple passed to driver as --target=<triple>.
293
289
P.assign (D.ResourceDir );
294
- llvm::sys::path::append (P, " lib" , D.getTargetTriple (), SelectedMultilib.gccSuffix ());
290
+ llvm::sys::path::append (P, " lib" , D.getTargetTriple (),
291
+ SelectedMultilib.gccSuffix ());
295
292
Paths.push_back (P.c_str ());
296
293
297
294
// Second try the normalized triple.
@@ -340,26 +337,20 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const {
340
337
341
338
std::string OHOS::getCompilerRT (const ArgList &Args, StringRef Component,
342
339
FileType Type) const {
340
+ std::string CRTBasename =
341
+ buildCompilerRTBasename (Args, Component, Type, /* AddArch=*/ false );
342
+
343
343
SmallString<128 > Path (getDriver ().ResourceDir );
344
344
llvm::sys::path::append (Path, " lib" , getMultiarchTriple (getTriple ()),
345
- SelectedMultilib.gccSuffix ());
346
- const char *Prefix =
347
- Type == ToolChain::FT_Object ? " " : " lib" ;
348
- const char *Suffix;
349
- switch (Type) {
350
- case ToolChain::FT_Object:
351
- Suffix = " .o" ;
352
- break ;
353
- case ToolChain::FT_Static:
354
- Suffix = " .a" ;
355
- break ;
356
- case ToolChain::FT_Shared:
357
- Suffix = " .so" ;
358
- break ;
359
- }
360
- llvm::sys::path::append (
361
- Path, Prefix + Twine (" clang_rt." ) + Component + Suffix);
362
- return static_cast <std::string>(Path.str ());
345
+ SelectedMultilib.gccSuffix (), CRTBasename);
346
+ if (getVFS ().exists (Path))
347
+ return std::string (Path);
348
+
349
+ std::string NewPath = ToolChain::getCompilerRT (Args, Component, Type);
350
+ if (getVFS ().exists (NewPath))
351
+ return NewPath;
352
+
353
+ return std::string (Path);
363
354
}
364
355
365
356
void OHOS::addExtraOpts (llvm::opt::ArgStringList &CmdArgs) const {
@@ -396,7 +387,7 @@ SanitizerMask OHOS::getSupportedSanitizers() const {
396
387
397
388
// TODO: Make a base class for Linux and OHOS and move this there.
398
389
void OHOS::addProfileRTLibs (const llvm::opt::ArgList &Args,
399
- llvm::opt::ArgStringList &CmdArgs) const {
390
+ llvm::opt::ArgStringList &CmdArgs) const {
400
391
// Add linker option -u__llvm_profile_runtime to cause runtime
401
392
// initialization module to be linked in.
402
393
if (needsProfileRT (Args))
@@ -413,7 +404,8 @@ ToolChain::path_list OHOS::getArchSpecificLibPaths() const {
413
404
return Paths;
414
405
}
415
406
416
- ToolChain::UnwindLibType OHOS::GetUnwindLibType (const llvm::opt::ArgList &Args) const {
407
+ ToolChain::UnwindLibType
408
+ OHOS::GetUnwindLibType (const llvm::opt::ArgList &Args) const {
417
409
if (Args.getLastArg (options::OPT_unwindlib_EQ))
418
410
return Generic_ELF::GetUnwindLibType (Args);
419
411
return GetDefaultUnwindLibType ();
0 commit comments