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