11#include "clang/Config/config.h"
17#include "llvm/Option/ArgList.h"
18#include "llvm/Support/FileSystem.h"
19#include "llvm/Support/Path.h"
27static const char *
makeArgString(
const ArgList &Args,
const char *Prefix,
28 const char *
Base,
const char *Suffix) {
30 return Args.MakeArgString(Twine(StringRef(Prefix),
Base) + Suffix);
34 ArgStringList &CmdArgs) {
38 if ((Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
40 Args.hasFlag(options::OPT_fprofile_generate,
41 options::OPT_fno_profile_generate,
false) ||
42 Args.hasFlag(options::OPT_fprofile_generate_EQ,
43 options::OPT_fno_profile_generate,
false) ||
44 Args.hasFlag(options::OPT_fprofile_instr_generate,
45 options::OPT_fno_profile_instr_generate,
false) ||
46 Args.hasFlag(options::OPT_fprofile_instr_generate_EQ,
47 options::OPT_fno_profile_instr_generate,
false) ||
48 Args.hasFlag(options::OPT_fcs_profile_generate,
49 options::OPT_fno_profile_generate,
false) ||
50 Args.hasFlag(options::OPT_fcs_profile_generate_EQ,
51 options::OPT_fno_profile_generate,
false) ||
52 Args.hasArg(options::OPT_fcreate_profile) ||
53 Args.hasArg(options::OPT_coverage)))
55 Args,
"--dependent-lib=", PSTC.getProfileRTLibName(),
""));
62 const char *LinkingOutput)
const {
65 ArgStringList CmdArgs;
67 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
69 CmdArgs.push_back(
"-o");
72 assert(Inputs.size() == 1 &&
"Unexpected number of inputs.");
74 assert(Input.
isFilename() &&
"Invalid input.");
77 std::string AsName = TC.qualifyPSCmdName(
"as");
78 const char *Exec = Args.MakeArgString(TC.
GetProgramPath(AsName.c_str()));
79 C.addCommand(std::make_unique<Command>(JA, *
this,
81 Exec, CmdArgs, Inputs, Output));
85 ArgStringList &CmdArgs) {
92 ArgStringList &CmdArgs,
94 const char *Suffix)
const {
95 auto arg = [&](
const char *Name) ->
const char * {
100 CmdArgs.push_back(arg(
"SceDbgUBSanitizer_stub_weak"));
102 CmdArgs.push_back(arg(
"SceDbgAddressSanitizer_stub_weak"));
106 ArgStringList &CmdArgs,
108 const char *Suffix)
const {
109 auto arg = [&](
const char *Name) ->
const char * {
114 CmdArgs.push_back(arg(
"SceUBSanitizer_nosubmission_stub_weak"));
116 CmdArgs.push_back(arg(
"SceAddressSanitizer_nosubmission_stub_weak"));
118 CmdArgs.push_back(arg(
"SceThreadSanitizer_nosubmission_stub_weak"));
125 const char *LinkingOutput)
const {
128 ArgStringList CmdArgs;
131 Args.ClaimAllArgs(options::OPT_g_Group);
133 Args.ClaimAllArgs(options::OPT_emit_llvm);
136 Args.ClaimAllArgs(options::OPT_w);
138 if (!
D.SysRoot.empty())
139 CmdArgs.push_back(Args.MakeArgString(
"--sysroot=" +
D.SysRoot));
141 if (Args.hasArg(options::OPT_pie))
142 CmdArgs.push_back(
"-pie");
144 if (Args.hasArg(options::OPT_static))
145 CmdArgs.push_back(
"-static");
146 if (Args.hasArg(options::OPT_rdynamic))
147 CmdArgs.push_back(
"-export-dynamic");
148 if (Args.hasArg(options::OPT_shared))
149 CmdArgs.push_back(
"--shared");
153 CmdArgs.push_back(
"-o");
158 Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false);
160 const char *LTOArgs =
"";
161 auto AddLTOFlag = [&](Twine Flag) {
162 LTOArgs = Args.MakeArgString(Twine(LTOArgs) +
" " + Flag);
169 if (Args.hasFlag(options::OPT_funified_lto, options::OPT_fno_unified_lto,
171 CmdArgs.push_back(
D.getLTOMode() ==
LTOK_Thin ?
"--lto=thin"
174 AddLTOFlag(
"-enable-jmc-instrument");
176 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
177 AddLTOFlag(Twine(
"-crash-diagnostics-dir=") + A->getValue());
180 AddLTOFlag(Twine(
"-threads=") + Threads);
184 Args.MakeArgString(Twine(
"-lto-debug-options=") + LTOArgs));
186 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
187 TC.addSanitizerArgs(Args, CmdArgs,
"-l",
"");
189 Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
190 options::OPT_s, options::OPT_t});
192 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
193 CmdArgs.push_back(
"--no-demangle");
197 if (Args.hasArg(options::OPT_pthread)) {
198 CmdArgs.push_back(
"-lpthread");
202 CmdArgs.push_back(
"--whole-archive");
203 CmdArgs.push_back(
"-lSceDbgJmc");
204 CmdArgs.push_back(
"--no-whole-archive");
207 if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
208 D.Diag(diag::err_drv_unsupported_opt_for_target)
212 std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
213 const char *Exec = Args.MakeArgString(TC.
GetProgramPath(LdName.c_str()));
215 C.addCommand(std::make_unique<Command>(JA, *
this,
217 Exec, CmdArgs, Inputs, Output));
224 const char *LinkingOutput)
const {
227 ArgStringList CmdArgs;
230 Args.ClaimAllArgs(options::OPT_g_Group);
232 Args.ClaimAllArgs(options::OPT_emit_llvm);
235 Args.ClaimAllArgs(options::OPT_w);
237 if (!
D.SysRoot.empty())
238 CmdArgs.push_back(Args.MakeArgString(
"--sysroot=" +
D.SysRoot));
240 if (Args.hasArg(options::OPT_pie))
241 CmdArgs.push_back(
"-pie");
243 if (Args.hasArg(options::OPT_static))
244 CmdArgs.push_back(
"-static");
245 if (Args.hasArg(options::OPT_rdynamic))
246 CmdArgs.push_back(
"-export-dynamic");
247 if (Args.hasArg(options::OPT_shared))
248 CmdArgs.push_back(
"--shared");
252 CmdArgs.push_back(
"-o");
257 Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false);
259 auto AddLTOFlag = [&](Twine Flag) {
260 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-opt=") + Flag));
267 if (Args.hasFlag(options::OPT_funified_lto, options::OPT_fno_unified_lto,
269 CmdArgs.push_back(
D.getLTOMode() ==
LTOK_Thin ?
"--lto=thin"
273 AddLTOFlag(
"-enable-jmc-instrument");
275 if (Args.hasFlag(options::OPT_fstack_size_section,
276 options::OPT_fno_stack_size_section,
false))
277 AddLTOFlag(
"-stack-size-section");
279 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
280 AddLTOFlag(Twine(
"-crash-diagnostics-dir=") + A->getValue());
283 AddLTOFlag(Twine(
"jobs=") + Jobs);
285 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
286 TC.addSanitizerArgs(Args, CmdArgs,
"-l",
"");
288 Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
289 options::OPT_s, options::OPT_t});
291 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
292 CmdArgs.push_back(
"--no-demangle");
296 if (Args.hasArg(options::OPT_pthread)) {
297 CmdArgs.push_back(
"-lpthread");
301 CmdArgs.push_back(
"--whole-archive");
302 CmdArgs.push_back(
"-lSceJmc_nosubmission");
303 CmdArgs.push_back(
"--no-whole-archive");
306 if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
307 D.Diag(diag::err_drv_unsupported_opt_for_target)
311 std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
312 const char *Exec = Args.MakeArgString(TC.
GetProgramPath(LdName.c_str()));
314 C.addCommand(std::make_unique<Command>(JA, *
this,
316 Exec, CmdArgs, Inputs, Output));
320 const ArgList &Args, StringRef Platform,
328 if (
const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
329 SDKRootDir = A->getValue();
330 if (!llvm::sys::fs::exists(SDKRootDir))
331 D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
332 Whence = A->getSpelling();
333 }
else if (
const char *EnvValue = getenv(EnvVar)) {
334 SDKRootDir = EnvValue;
335 Whence = {
"environment variable '", EnvVar,
"'" };
337 SDKRootDir =
D.Dir +
"/../../";
338 Whence =
"compiler's location";
342 llvm::sys::path::append(SDKIncludeDir,
"target/include");
343 if (!Args.hasArg(options::OPT_nostdinc) &&
344 !Args.hasArg(options::OPT_nostdlibinc) &&
345 !Args.hasArg(options::OPT_isysroot) &&
346 !Args.hasArg(options::OPT__sysroot_EQ) &&
347 !llvm::sys::fs::exists(SDKIncludeDir)) {
348 D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
349 << Twine(Platform,
" system headers").str() << SDKIncludeDir << Whence;
353 llvm::sys::path::append(SDKLibDir,
"target/lib");
354 if (!Args.hasArg(options::OPT_nostdlib) &&
355 !Args.hasArg(options::OPT_nodefaultlibs) &&
356 !Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) &&
357 !Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) &&
358 !Args.hasArg(options::OPT_emit_ast) &&
359 !llvm::sys::fs::exists(SDKLibDir)) {
360 D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
361 << Twine(Platform,
" system libraries").str() << SDKLibDir << Whence;
368 const ArgList &DriverArgs,
369 ArgStringList &CC1Args)
const {
372 if (DriverArgs.hasArg(options::OPT_nostdinc))
375 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
377 llvm::sys::path::append(Dir,
"include");
378 addSystemInclude(DriverArgs, CC1Args, Dir.str());
381 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
384 addExternCSystemInclude(DriverArgs, CC1Args,
385 SDKRootDir +
"/target/include");
386 addExternCSystemInclude(DriverArgs, CC1Args,
387 SDKRootDir +
"/target/include_common");
400 getDriver().Diag(clang::diag::err_no_external_assembler);
410 Res |= SanitizerKind::Address;
411 Res |= SanitizerKind::PointerCompare;
412 Res |= SanitizerKind::PointerSubtract;
413 Res |= SanitizerKind::Vptr;
419 Res |= SanitizerKind::Thread;
424 const ArgList &DriverArgs, ArgStringList &CC1Args,
427 if (DriverArgs.hasArg(options::OPT_fuse_init_array)) {
428 Arg *A = DriverArgs.getLastArg(options::OPT_fuse_init_array);
429 getDriver().Diag(clang::diag::err_drv_unsupported_opt_for_target)
430 << A->getAsString(DriverArgs) << getTriple().str();
433 CC1Args.push_back(
"-fno-use-init-array");
436 if (getTriple().isPS5() &&
437 !DriverArgs.hasArg(options::OPT_fvisibility_EQ,
438 options::OPT_fvisibility_ms_compat))
439 CC1Args.push_back(
"-fvisibility=hidden");
442 if (getTriple().isPS5() &&
443 !DriverArgs.hasArg(options::OPT_fvisibility_global_new_delete_EQ,
444 options::OPT_fvisibility_global_new_delete_hidden))
445 CC1Args.push_back(
"-fvisibility-global-new-delete=source");
448 DriverArgs.getLastArg(options::OPT_fvisibility_from_dllstorageclass,
449 options::OPT_fno_visibility_from_dllstorageclass);
451 A->getOption().matches(options::OPT_fvisibility_from_dllstorageclass)) {
452 CC1Args.push_back(
"-fvisibility-from-dllstorageclass");
454 if (DriverArgs.hasArg(options::OPT_fvisibility_dllexport_EQ))
455 DriverArgs.AddLastArg(CC1Args, options::OPT_fvisibility_dllexport_EQ);
457 CC1Args.push_back(
"-fvisibility-dllexport=protected");
461 if (DriverArgs.hasArg(options::OPT_fvisibility_nodllstorageclass_EQ))
462 DriverArgs.AddLastArg(CC1Args,
463 options::OPT_fvisibility_nodllstorageclass_EQ);
464 else if (getTriple().isPS4())
465 CC1Args.push_back(
"-fvisibility-nodllstorageclass=hidden");
467 CC1Args.push_back(
"-fvisibility-nodllstorageclass=keep");
469 if (DriverArgs.hasArg(options::OPT_fvisibility_externs_dllimport_EQ))
470 DriverArgs.AddLastArg(CC1Args,
471 options::OPT_fvisibility_externs_dllimport_EQ);
473 CC1Args.push_back(
"-fvisibility-externs-dllimport=default");
477 if (DriverArgs.hasArg(
478 options::OPT_fvisibility_externs_nodllstorageclass_EQ))
479 DriverArgs.AddLastArg(
480 CC1Args, options::OPT_fvisibility_externs_nodllstorageclass_EQ);
481 else if (getTriple().isPS4())
482 CC1Args.push_back(
"-fvisibility-externs-nodllstorageclass=default");
484 CC1Args.push_back(
"-fvisibility-externs-nodllstorageclass=keep");
490 const llvm::opt::ArgList &Args)
491 :
PS4PS5Base(
D, Triple, Args,
"PS4",
"SCE_ORBIS_SDK_DIR") {}
495 const llvm::opt::ArgList &Args)
496 :
PS4PS5Base(
D, Triple, Args,
"PS5",
"SCE_PROSPERO_SDK_DIR") {}
static const char * makeArgString(const ArgList &Args, const char *Prefix, const char *Base, const char *Suffix)
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
bool needsUbsanRt() const
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport AtFileUTF8()