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);
139 Args.MakeArgString(
"--sysroot=" + TC.getSDKLibraryRootDir()));
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));
187 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
188 TC.addSanitizerArgs(Args, CmdArgs,
"-l",
"");
193 Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
194 options::OPT_s, options::OPT_t});
196 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
197 CmdArgs.push_back(
"--no-demangle");
201 if (Args.hasArg(options::OPT_pthread)) {
202 CmdArgs.push_back(
"-lpthread");
206 CmdArgs.push_back(
"--whole-archive");
207 CmdArgs.push_back(
"-lSceDbgJmc");
208 CmdArgs.push_back(
"--no-whole-archive");
211 if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
212 D.Diag(diag::err_drv_unsupported_opt_for_target)
216 std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
217 const char *Exec = Args.MakeArgString(TC.
GetProgramPath(LdName.c_str()));
219 C.addCommand(std::make_unique<Command>(JA, *
this,
221 Exec, CmdArgs, Inputs, Output));
228 const char *LinkingOutput)
const {
231 ArgStringList CmdArgs;
233 const bool Relocatable = Args.hasArg(options::OPT_r);
234 const bool Shared = Args.hasArg(options::OPT_shared);
235 const bool Static = Args.hasArg(options::OPT_static);
238 Args.ClaimAllArgs(options::OPT_g_Group);
240 Args.ClaimAllArgs(options::OPT_emit_llvm);
243 Args.ClaimAllArgs(options::OPT_w);
245 CmdArgs.push_back(
"-m");
246 CmdArgs.push_back(
"elf_x86_64_fbsd");
249 Args.MakeArgString(
"--sysroot=" + TC.getSDKLibraryRootDir()));
252 const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
253 !Relocatable && !Shared && !
Static);
255 CmdArgs.push_back(
"-pie");
258 CmdArgs.push_back(
"--eh-frame-hdr");
259 CmdArgs.push_back(
"--hash-style=sysv");
265 CmdArgs.push_back(
"--build-id=uuid");
270 CmdArgs.push_back(
"--unresolved-symbols=report-all");
274 CmdArgs.push_back(
"-z");
275 CmdArgs.push_back(
"now");
278 CmdArgs.push_back(
"-z");
279 CmdArgs.push_back(
"start-stop-visibility=hidden");
282 CmdArgs.push_back(
"-z");
283 CmdArgs.push_back(
"rodynamic");
285 CmdArgs.push_back(
"-z");
286 CmdArgs.push_back(
"common-page-size=0x4000");
288 CmdArgs.push_back(
"-z");
289 CmdArgs.push_back(
"max-page-size=0x4000");
294 CmdArgs.push_back(
"-z");
295 CmdArgs.push_back(
"dead-reloc-in-nonalloc=.debug_*=0xffffffffffffffff");
296 CmdArgs.push_back(
"-z");
298 "dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe");
299 CmdArgs.push_back(
"-z");
300 CmdArgs.push_back(
"dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe");
307 if (!Args.hasArgNoClaim(options::OPT_T)) {
308 CmdArgs.push_back(
"--default-script");
309 CmdArgs.push_back(
Static ?
"static.script"
310 : Shared ?
"prx.script"
316 CmdArgs.push_back(
"-static");
317 if (Args.hasArg(options::OPT_rdynamic))
318 CmdArgs.push_back(
"-export-dynamic");
320 CmdArgs.push_back(
"--shared");
324 if (!Relocatable && !Shared && !PIE)
325 CmdArgs.push_back(
"--image-base=0x400000");
329 CmdArgs.push_back(
"-o");
334 Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false);
336 auto AddLTOFlag = [&](Twine Flag) {
337 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-opt=") + Flag));
344 if (Args.hasFlag(options::OPT_funified_lto, options::OPT_fno_unified_lto,
346 CmdArgs.push_back(
D.getLTOMode() ==
LTOK_Thin ?
"--lto=thin"
349 AddLTOFlag(
"-emit-jump-table-sizes-section");
352 AddLTOFlag(
"-enable-jmc-instrument");
354 if (Args.hasFlag(options::OPT_fstack_size_section,
355 options::OPT_fno_stack_size_section,
false))
356 AddLTOFlag(
"-stack-size-section");
358 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
359 AddLTOFlag(Twine(
"-crash-diagnostics-dir=") + A->getValue());
362 AddLTOFlag(Twine(
"jobs=") + Jobs);
364 Args.AddAllArgs(CmdArgs, options::OPT_L);
366 Args.addAllArgs(CmdArgs,
367 {options::OPT_T_Group, options::OPT_s, options::OPT_t});
369 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
370 CmdArgs.push_back(
"--no-demangle");
373 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
374 TC.addSanitizerArgs(Args, CmdArgs,
"-l",
"");
376 const bool AddStartFiles =
378 !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
380 auto AddCRTObject = [&](
const char *Name) {
381 CmdArgs.push_back(Args.MakeArgString(TC.
GetFilePath(Name)));
386 AddCRTObject(
"crt1.o");
387 AddCRTObject(
"crti.o");
388 AddCRTObject(Shared ?
"crtbeginS.o"
396 !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
399 CmdArgs.push_back(
"--push-state");
400 CmdArgs.push_back(
"--whole-archive");
401 CmdArgs.push_back(
"-lSceJmc_nosubmission");
402 CmdArgs.push_back(
"--pop-state");
405 if (Args.hasArg(options::OPT_pthread))
406 CmdArgs.push_back(
"-lpthread");
409 if (!Args.hasArg(options::OPT_nostdlibxx))
410 CmdArgs.push_back(
"-lstdc++");
411 if (!Args.hasArg(options::OPT_nolibc)) {
412 CmdArgs.push_back(
"-lm");
413 CmdArgs.push_back(
"-lc");
416 CmdArgs.push_back(
"-lcompiler_rt");
417 CmdArgs.push_back(
"-lkernel");
420 if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
421 CmdArgs.push_back(
"-lc_stub_weak");
423 CmdArgs.push_back(
"-lkernel_stub_weak");
427 AddCRTObject(Shared ?
"crtendS.o" :
"crtend.o");
428 AddCRTObject(
"crtn.o");
431 if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
432 D.Diag(diag::err_drv_unsupported_opt_for_target)
436 std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
437 const char *Exec = Args.MakeArgString(TC.
GetProgramPath(LdName.c_str()));
439 C.addCommand(std::make_unique<Command>(JA, *
this,
441 Exec, CmdArgs, Inputs, Output));
445 const ArgList &Args, StringRef Platform,
452 if (
const char *EnvValue = getenv(EnvVar)) {
453 SDKRootDir = EnvValue;
454 Whence = {
"environment variable '", EnvVar,
"'"};
456 SDKRootDir =
D.Dir +
"/../../";
457 Whence =
"compiler's location";
463 auto OverrideRoot = [&](
const options::ID &Opt, std::string &Root,
465 if (
const Arg *A = Args.getLastArg(Opt)) {
466 Root = A->getValue();
467 if (!llvm::sys::fs::exists(Root))
468 D.Diag(clang::diag::warn_missing_sysroot) << Root;
476 OverrideRoot(options::OPT__sysroot_EQ, SDKLibraryRootDir, SDKRootDir);
477 bool CustomISysroot =
478 OverrideRoot(options::OPT_isysroot, SDKHeaderRootDir, SDKLibraryRootDir);
483 auto CheckSDKPartExists = [&](StringRef Dir, StringRef Desc) {
484 if (llvm::sys::fs::exists(Dir))
486 D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
487 << (Twine(Platform) +
" " + Desc).str() << Dir << Whence;
491 bool Linking = !Args.hasArg(options::OPT_E, options::OPT_c, options::OPT_S,
492 options::OPT_emit_ast);
493 if (!CustomSysroot && Linking) {
495 llvm::sys::path::append(Dir,
"target/lib");
496 if (CheckSDKPartExists(Dir,
"system libraries"))
499 if (!CustomSysroot && !CustomISysroot &&
500 !Args.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc)) {
502 llvm::sys::path::append(Dir,
"target/include");
503 CheckSDKPartExists(Dir,
"system headers");
510 const ArgList &DriverArgs, ArgStringList &CC1Args)
const {
513 if (DriverArgs.hasArg(options::OPT_nostdinc))
516 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
518 llvm::sys::path::append(Dir,
"include");
519 addSystemInclude(DriverArgs, CC1Args, Dir.str());
522 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
525 addExternCSystemInclude(DriverArgs, CC1Args,
526 SDKHeaderRootDir +
"/target/include");
527 addExternCSystemInclude(DriverArgs, CC1Args,
528 SDKHeaderRootDir +
"/target/include_common");
541 getDriver().Diag(clang::diag::err_no_external_assembler);
551 Res |= SanitizerKind::Address;
552 Res |= SanitizerKind::PointerCompare;
553 Res |= SanitizerKind::PointerSubtract;
554 Res |= SanitizerKind::Vptr;
560 Res |= SanitizerKind::Thread;
565 const ArgList &DriverArgs, ArgStringList &CC1Args,
568 if (DriverArgs.hasArg(options::OPT_fuse_init_array)) {
569 Arg *A = DriverArgs.getLastArg(options::OPT_fuse_init_array);
570 getDriver().Diag(clang::diag::err_drv_unsupported_opt_for_target)
571 << A->getAsString(DriverArgs) << getTriple().str();
574 CC1Args.push_back(
"-fno-use-init-array");
577 if (getTriple().isPS5() &&
578 !DriverArgs.hasArg(options::OPT_fvisibility_EQ,
579 options::OPT_fvisibility_ms_compat))
580 CC1Args.push_back(
"-fvisibility=hidden");
583 if (getTriple().isPS5() &&
584 !DriverArgs.hasArg(options::OPT_fvisibility_global_new_delete_EQ,
585 options::OPT_fvisibility_global_new_delete_hidden))
586 CC1Args.push_back(
"-fvisibility-global-new-delete=source");
589 DriverArgs.getLastArg(options::OPT_fvisibility_from_dllstorageclass,
590 options::OPT_fno_visibility_from_dllstorageclass);
592 A->getOption().matches(options::OPT_fvisibility_from_dllstorageclass)) {
593 CC1Args.push_back(
"-fvisibility-from-dllstorageclass");
595 if (DriverArgs.hasArg(options::OPT_fvisibility_dllexport_EQ))
596 DriverArgs.AddLastArg(CC1Args, options::OPT_fvisibility_dllexport_EQ);
598 CC1Args.push_back(
"-fvisibility-dllexport=protected");
602 if (DriverArgs.hasArg(options::OPT_fvisibility_nodllstorageclass_EQ))
603 DriverArgs.AddLastArg(CC1Args,
604 options::OPT_fvisibility_nodllstorageclass_EQ);
605 else if (getTriple().isPS4())
606 CC1Args.push_back(
"-fvisibility-nodllstorageclass=hidden");
608 CC1Args.push_back(
"-fvisibility-nodllstorageclass=keep");
610 if (DriverArgs.hasArg(options::OPT_fvisibility_externs_dllimport_EQ))
611 DriverArgs.AddLastArg(CC1Args,
612 options::OPT_fvisibility_externs_dllimport_EQ);
614 CC1Args.push_back(
"-fvisibility-externs-dllimport=default");
618 if (DriverArgs.hasArg(
619 options::OPT_fvisibility_externs_nodllstorageclass_EQ))
620 DriverArgs.AddLastArg(
621 CC1Args, options::OPT_fvisibility_externs_nodllstorageclass_EQ);
622 else if (getTriple().isPS4())
623 CC1Args.push_back(
"-fvisibility-externs-nodllstorageclass=default");
625 CC1Args.push_back(
"-fvisibility-externs-nodllstorageclass=keep");
629 if (getTriple().isPS5()) {
630 CC1Args.push_back(
"-mllvm");
631 CC1Args.push_back(
"-emit-jump-table-sizes-section");
637 const llvm::opt::ArgList &Args)
638 :
PS4PS5Base(
D, Triple, Args,
"PS4",
"SCE_ORBIS_SDK_DIR") {}
642 const llvm::opt::ArgList &Args)
643 :
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()