clang 20.0.0git
PS4CPU.cpp
Go to the documentation of this file.
1//===--- PS4CPU.cpp - PS4CPU ToolChain Implementations ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "PS4CPU.h"
10#include "CommonArgs.h"
11#include "clang/Config/config.h"
13#include "clang/Driver/Driver.h"
17#include "llvm/Option/ArgList.h"
18#include "llvm/Support/FileSystem.h"
19#include "llvm/Support/Path.h"
20#include <cstdlib> // ::getenv
21
22using namespace clang::driver;
23using namespace clang;
24using namespace llvm::opt;
25
26// Helper to paste bits of an option together and return a saved string.
27static const char *makeArgString(const ArgList &Args, const char *Prefix,
28 const char *Base, const char *Suffix) {
29 // Basically "Prefix + Base + Suffix" all converted to Twine then saved.
30 return Args.MakeArgString(Twine(StringRef(Prefix), Base) + Suffix);
31}
32
33void tools::PScpu::addProfileRTArgs(const ToolChain &TC, const ArgList &Args,
34 ArgStringList &CmdArgs) {
35 assert(TC.getTriple().isPS());
36 auto &PSTC = static_cast<const toolchains::PS4PS5Base &>(TC);
37
38 if ((Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
39 false) ||
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)))
54 CmdArgs.push_back(makeArgString(
55 Args, "--dependent-lib=", PSTC.getProfileRTLibName(), ""));
56}
57
59 const InputInfo &Output,
60 const InputInfoList &Inputs,
61 const ArgList &Args,
62 const char *LinkingOutput) const {
63 auto &TC = static_cast<const toolchains::PS4PS5Base &>(getToolChain());
64 claimNoWarnArgs(Args);
65 ArgStringList CmdArgs;
66
67 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
68
69 CmdArgs.push_back("-o");
70 CmdArgs.push_back(Output.getFilename());
71
72 assert(Inputs.size() == 1 && "Unexpected number of inputs.");
73 const InputInfo &Input = Inputs[0];
74 assert(Input.isFilename() && "Invalid input.");
75 CmdArgs.push_back(Input.getFilename());
76
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));
82}
83
84void tools::PScpu::addSanitizerArgs(const ToolChain &TC, const ArgList &Args,
85 ArgStringList &CmdArgs) {
86 assert(TC.getTriple().isPS());
87 auto &PSTC = static_cast<const toolchains::PS4PS5Base &>(TC);
88 PSTC.addSanitizerArgs(Args, CmdArgs, "--dependent-lib=lib", ".a");
89}
90
91void toolchains::PS4CPU::addSanitizerArgs(const ArgList &Args,
92 ArgStringList &CmdArgs,
93 const char *Prefix,
94 const char *Suffix) const {
95 auto arg = [&](const char *Name) -> const char * {
96 return makeArgString(Args, Prefix, Name, Suffix);
97 };
98 const SanitizerArgs &SanArgs = getSanitizerArgs(Args);
99 if (SanArgs.needsUbsanRt())
100 CmdArgs.push_back(arg("SceDbgUBSanitizer_stub_weak"));
101 if (SanArgs.needsAsanRt())
102 CmdArgs.push_back(arg("SceDbgAddressSanitizer_stub_weak"));
103}
104
106 ArgStringList &CmdArgs,
107 const char *Prefix,
108 const char *Suffix) const {
109 auto arg = [&](const char *Name) -> const char * {
110 return makeArgString(Args, Prefix, Name, Suffix);
111 };
112 const SanitizerArgs &SanArgs = getSanitizerArgs(Args);
113 if (SanArgs.needsUbsanRt())
114 CmdArgs.push_back(arg("SceUBSanitizer_nosubmission_stub_weak"));
115 if (SanArgs.needsAsanRt())
116 CmdArgs.push_back(arg("SceAddressSanitizer_nosubmission_stub_weak"));
117 if (SanArgs.needsTsanRt())
118 CmdArgs.push_back(arg("SceThreadSanitizer_nosubmission_stub_weak"));
119}
120
122 const InputInfo &Output,
123 const InputInfoList &Inputs,
124 const ArgList &Args,
125 const char *LinkingOutput) const {
126 auto &TC = static_cast<const toolchains::PS4PS5Base &>(getToolChain());
127 const Driver &D = TC.getDriver();
128 ArgStringList CmdArgs;
129
130 // Silence warning for "clang -g foo.o -o foo"
131 Args.ClaimAllArgs(options::OPT_g_Group);
132 // and "clang -emit-llvm foo.o -o foo"
133 Args.ClaimAllArgs(options::OPT_emit_llvm);
134 // and for "clang -w foo.o -o foo". Other warning options are already
135 // handled somewhere else.
136 Args.ClaimAllArgs(options::OPT_w);
137
138 CmdArgs.push_back(
139 Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
140
141 if (Args.hasArg(options::OPT_pie))
142 CmdArgs.push_back("-pie");
143
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");
150
151 assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
152 if (Output.isFilename()) {
153 CmdArgs.push_back("-o");
154 CmdArgs.push_back(Output.getFilename());
155 }
156
157 const bool UseJMC =
158 Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
159
160 const char *LTOArgs = "";
161 auto AddLTOFlag = [&](Twine Flag) {
162 LTOArgs = Args.MakeArgString(Twine(LTOArgs) + " " + Flag);
163 };
164
165 // If the linker sees bitcode objects it will perform LTO. We can't tell
166 // whether or not that will be the case at this point. So, unconditionally
167 // pass LTO options to ensure proper codegen, metadata production, etc if
168 // LTO indeed occurs.
169 if (Args.hasFlag(options::OPT_funified_lto, options::OPT_fno_unified_lto,
170 true))
171 CmdArgs.push_back(D.getLTOMode() == LTOK_Thin ? "--lto=thin"
172 : "--lto=full");
173 if (UseJMC)
174 AddLTOFlag("-enable-jmc-instrument");
175
176 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
177 AddLTOFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
178
179 if (StringRef Threads = getLTOParallelism(Args, D); !Threads.empty())
180 AddLTOFlag(Twine("-threads=") + Threads);
181
182 if (*LTOArgs)
183 CmdArgs.push_back(
184 Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
185
186 // Sanitizer runtimes must be supplied before all other objects and libs.
187 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
188 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
189
190 // Other drivers typically add library search paths (`-L`) here via
191 // TC.AddFilePathLibArgs(). We don't do that on PS4 as the PS4 linker
192 // searches those locations by default.
193 Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
194 options::OPT_s, options::OPT_t});
195
196 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
197 CmdArgs.push_back("--no-demangle");
198
199 AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
200
201 if (Args.hasArg(options::OPT_pthread)) {
202 CmdArgs.push_back("-lpthread");
203 }
204
205 if (UseJMC) {
206 CmdArgs.push_back("--whole-archive");
207 CmdArgs.push_back("-lSceDbgJmc");
208 CmdArgs.push_back("--no-whole-archive");
209 }
210
211 if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
212 D.Diag(diag::err_drv_unsupported_opt_for_target)
213 << "-fuse-ld" << TC.getTriple().str();
214 }
215
216 std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
217 const char *Exec = Args.MakeArgString(TC.GetProgramPath(LdName.c_str()));
218
219 C.addCommand(std::make_unique<Command>(JA, *this,
221 Exec, CmdArgs, Inputs, Output));
222}
223
225 const InputInfo &Output,
226 const InputInfoList &Inputs,
227 const ArgList &Args,
228 const char *LinkingOutput) const {
229 auto &TC = static_cast<const toolchains::PS4PS5Base &>(getToolChain());
230 const Driver &D = TC.getDriver();
231 ArgStringList CmdArgs;
232
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);
236
237 // Silence warning for "clang -g foo.o -o foo"
238 Args.ClaimAllArgs(options::OPT_g_Group);
239 // and "clang -emit-llvm foo.o -o foo"
240 Args.ClaimAllArgs(options::OPT_emit_llvm);
241 // and for "clang -w foo.o -o foo". Other warning options are already
242 // handled somewhere else.
243 Args.ClaimAllArgs(options::OPT_w);
244
245 CmdArgs.push_back("-m");
246 CmdArgs.push_back("elf_x86_64_fbsd");
247
248 CmdArgs.push_back(
249 Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
250
251 // Default to PIE for non-static executables.
252 const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
253 !Relocatable && !Shared && !Static);
254 if (PIE)
255 CmdArgs.push_back("-pie");
256
257 if (!Relocatable) {
258 CmdArgs.push_back("--eh-frame-hdr");
259 CmdArgs.push_back("--hash-style=sysv");
260
261 // Add a build-id by default to allow the PlayStation symbol server to
262 // index the symbols. `uuid` is the cheapest fool-proof method.
263 // (The non-determinism and alternative methods are noted in the downstream
264 // PlayStation docs).
265 CmdArgs.push_back("--build-id=uuid");
266
267 // All references are expected to be resolved at static link time for both
268 // executables and dynamic libraries. This has been the default linking
269 // behaviour for numerous PlayStation generations.
270 CmdArgs.push_back("--unresolved-symbols=report-all");
271
272 // Lazy binding of PLTs is not supported on PlayStation. They are placed in
273 // the RelRo segment.
274 CmdArgs.push_back("-z");
275 CmdArgs.push_back("now");
276
277 // Don't export linker-generated __start/stop... section bookends.
278 CmdArgs.push_back("-z");
279 CmdArgs.push_back("start-stop-visibility=hidden");
280
281 // DT_DEBUG is not supported on PlayStation.
282 CmdArgs.push_back("-z");
283 CmdArgs.push_back("rodynamic");
284
285 CmdArgs.push_back("-z");
286 CmdArgs.push_back("common-page-size=0x4000");
287
288 CmdArgs.push_back("-z");
289 CmdArgs.push_back("max-page-size=0x4000");
290
291 // Patch relocated regions of DWARF whose targets are eliminated at link
292 // time with specific tombstones, such that they're recognisable by the
293 // PlayStation debugger.
294 CmdArgs.push_back("-z");
295 CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_*=0xffffffffffffffff");
296 CmdArgs.push_back("-z");
297 CmdArgs.push_back(
298 "dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe");
299 CmdArgs.push_back("-z");
300 CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe");
301
302 // The PlayStation loader expects linked objects to be laid out in a
303 // particular way. This is achieved by linker scripts that are supplied
304 // with the SDK. The scripts are inside <sdkroot>/target/lib, which is
305 // added as a search path elsewhere.
306 // "PRX" has long stood for "PlayStation Relocatable eXecutable".
307 if (!Args.hasArgNoClaim(options::OPT_T)) {
308 CmdArgs.push_back("--default-script");
309 CmdArgs.push_back(Static ? "static.script"
310 : Shared ? "prx.script"
311 : "main.script");
312 }
313 }
314
315 if (Static)
316 CmdArgs.push_back("-static");
317 if (Args.hasArg(options::OPT_rdynamic))
318 CmdArgs.push_back("-export-dynamic");
319 if (Shared)
320 CmdArgs.push_back("--shared");
321
322 // Provide a base address for non-PIE executables. This includes cases where
323 // -static is supplied without -pie.
324 if (!Relocatable && !Shared && !PIE)
325 CmdArgs.push_back("--image-base=0x400000");
326
327 assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
328 if (Output.isFilename()) {
329 CmdArgs.push_back("-o");
330 CmdArgs.push_back(Output.getFilename());
331 }
332
333 const bool UseJMC =
334 Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false);
335
336 auto AddLTOFlag = [&](Twine Flag) {
337 CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=") + Flag));
338 };
339
340 // If the linker sees bitcode objects it will perform LTO. We can't tell
341 // whether or not that will be the case at this point. So, unconditionally
342 // pass LTO options to ensure proper codegen, metadata production, etc if
343 // LTO indeed occurs.
344 if (Args.hasFlag(options::OPT_funified_lto, options::OPT_fno_unified_lto,
345 true))
346 CmdArgs.push_back(D.getLTOMode() == LTOK_Thin ? "--lto=thin"
347 : "--lto=full");
348
349 AddLTOFlag("-emit-jump-table-sizes-section");
350
351 if (UseJMC)
352 AddLTOFlag("-enable-jmc-instrument");
353
354 if (Args.hasFlag(options::OPT_fstack_size_section,
355 options::OPT_fno_stack_size_section, false))
356 AddLTOFlag("-stack-size-section");
357
358 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
359 AddLTOFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
360
361 if (StringRef Jobs = getLTOParallelism(Args, D); !Jobs.empty())
362 AddLTOFlag(Twine("jobs=") + Jobs);
363
364 Args.AddAllArgs(CmdArgs, options::OPT_L);
365 TC.AddFilePathLibArgs(Args, CmdArgs);
366 Args.addAllArgs(CmdArgs,
367 {options::OPT_T_Group, options::OPT_s, options::OPT_t});
368
369 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
370 CmdArgs.push_back("--no-demangle");
371
372 // Sanitizer runtimes must be supplied before all other objects and libs.
373 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
374 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
375
376 const bool AddStartFiles =
377 !Relocatable &&
378 !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
379
380 auto AddCRTObject = [&](const char *Name) {
381 CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
382 };
383
384 if (AddStartFiles) {
385 if (!Shared)
386 AddCRTObject("crt1.o");
387 AddCRTObject("crti.o");
388 AddCRTObject(Shared ? "crtbeginS.o"
389 : Static ? "crtbeginT.o"
390 : "crtbegin.o");
391 }
392
393 AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
394
395 if (!Relocatable &&
396 !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
397
398 if (UseJMC) {
399 CmdArgs.push_back("--push-state");
400 CmdArgs.push_back("--whole-archive");
401 CmdArgs.push_back("-lSceJmc_nosubmission");
402 CmdArgs.push_back("--pop-state");
403 }
404
405 if (Args.hasArg(options::OPT_pthread))
406 CmdArgs.push_back("-lpthread");
407
408 if (Static) {
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");
414 }
415
416 CmdArgs.push_back("-lcompiler_rt");
417 CmdArgs.push_back("-lkernel");
418 } else {
419 // The C and C++ libraries are combined.
420 if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
421 CmdArgs.push_back("-lc_stub_weak");
422
423 CmdArgs.push_back("-lkernel_stub_weak");
424 }
425 }
426 if (AddStartFiles) {
427 AddCRTObject(Shared ? "crtendS.o" : "crtend.o");
428 AddCRTObject("crtn.o");
429 }
430
431 if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
432 D.Diag(diag::err_drv_unsupported_opt_for_target)
433 << "-fuse-ld" << TC.getTriple().str();
434 }
435
436 std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
437 const char *Exec = Args.MakeArgString(TC.GetProgramPath(LdName.c_str()));
438
439 C.addCommand(std::make_unique<Command>(JA, *this,
441 Exec, CmdArgs, Inputs, Output));
442}
443
444toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple,
445 const ArgList &Args, StringRef Platform,
446 const char *EnvVar)
447 : Generic_ELF(D, Triple, Args) {
448 // Determine the baseline SDK directory from the environment, else
449 // the driver's location, which should be <SDK_DIR>/host_tools/bin.
450 SmallString<128> SDKRootDir;
451 SmallString<80> Whence;
452 if (const char *EnvValue = getenv(EnvVar)) {
453 SDKRootDir = EnvValue;
454 Whence = {"environment variable '", EnvVar, "'"};
455 } else {
456 SDKRootDir = D.Dir + "/../../";
457 Whence = "compiler's location";
458 }
459
460 // Allow --sysroot= to override the root directory for header and library
461 // search, and -isysroot to override header search. If both are specified,
462 // -isysroot overrides --sysroot for header search.
463 auto OverrideRoot = [&](const options::ID &Opt, std::string &Root,
464 StringRef Default) {
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;
469 return true;
470 }
471 Root = Default.str();
472 return false;
473 };
474
475 bool CustomSysroot =
476 OverrideRoot(options::OPT__sysroot_EQ, SDKLibraryRootDir, SDKRootDir);
477 bool CustomISysroot =
478 OverrideRoot(options::OPT_isysroot, SDKHeaderRootDir, SDKLibraryRootDir);
479
480 // Emit warnings if parts of the SDK are missing, unless the user has taken
481 // control of header or library search. If we're not linking, don't check
482 // for missing libraries.
483 auto CheckSDKPartExists = [&](StringRef Dir, StringRef Desc) {
484 if (llvm::sys::fs::exists(Dir))
485 return true;
486 D.Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
487 << (Twine(Platform) + " " + Desc).str() << Dir << Whence;
488 return false;
489 };
490
491 bool Linking = !Args.hasArg(options::OPT_E, options::OPT_c, options::OPT_S,
492 options::OPT_emit_ast);
493 if (!CustomSysroot && Linking) {
494 SmallString<128> Dir(SDKLibraryRootDir);
495 llvm::sys::path::append(Dir, "target/lib");
496 if (CheckSDKPartExists(Dir, "system libraries"))
497 getFilePaths().push_back(std::string(Dir));
498 }
499 if (!CustomSysroot && !CustomISysroot &&
500 !Args.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc)) {
501 SmallString<128> Dir(SDKHeaderRootDir);
502 llvm::sys::path::append(Dir, "target/include");
503 CheckSDKPartExists(Dir, "system headers");
504 }
505
506 getFilePaths().push_back(".");
507}
508
510 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
511 const Driver &D = getDriver();
512
513 if (DriverArgs.hasArg(options::OPT_nostdinc))
514 return;
515
516 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
517 SmallString<128> Dir(D.ResourceDir);
518 llvm::sys::path::append(Dir, "include");
519 addSystemInclude(DriverArgs, CC1Args, Dir.str());
520 }
521
522 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
523 return;
524
525 addExternCSystemInclude(DriverArgs, CC1Args,
526 SDKHeaderRootDir + "/target/include");
527 addExternCSystemInclude(DriverArgs, CC1Args,
528 SDKHeaderRootDir + "/target/include_common");
529}
530
532 return new tools::PScpu::Assembler(*this);
533}
534
536 return new tools::PS4cpu::Linker(*this);
537}
538
540 // PS5 does not support an external assembler.
541 getDriver().Diag(clang::diag::err_no_external_assembler);
542 return nullptr;
543}
544
546 return new tools::PS5cpu::Linker(*this);
547}
548
551 Res |= SanitizerKind::Address;
552 Res |= SanitizerKind::PointerCompare;
553 Res |= SanitizerKind::PointerSubtract;
554 Res |= SanitizerKind::Vptr;
555 return Res;
556}
557
560 Res |= SanitizerKind::Thread;
561 return Res;
562}
563
565 const ArgList &DriverArgs, ArgStringList &CC1Args,
566 Action::OffloadKind DeviceOffloadingKind) const {
567 // PS4/PS5 do not use init arrays.
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();
572 }
573
574 CC1Args.push_back("-fno-use-init-array");
575
576 // Default to `hidden` visibility for PS5.
577 if (getTriple().isPS5() &&
578 !DriverArgs.hasArg(options::OPT_fvisibility_EQ,
579 options::OPT_fvisibility_ms_compat))
580 CC1Args.push_back("-fvisibility=hidden");
581
582 // Default to -fvisibility-global-new-delete=source for PS5.
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");
587
588 const Arg *A =
589 DriverArgs.getLastArg(options::OPT_fvisibility_from_dllstorageclass,
590 options::OPT_fno_visibility_from_dllstorageclass);
591 if (!A ||
592 A->getOption().matches(options::OPT_fvisibility_from_dllstorageclass)) {
593 CC1Args.push_back("-fvisibility-from-dllstorageclass");
594
595 if (DriverArgs.hasArg(options::OPT_fvisibility_dllexport_EQ))
596 DriverArgs.AddLastArg(CC1Args, options::OPT_fvisibility_dllexport_EQ);
597 else
598 CC1Args.push_back("-fvisibility-dllexport=protected");
599
600 // For PS4 we override the visibilty of globals definitions without
601 // dllimport or dllexport annotations.
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");
607 else
608 CC1Args.push_back("-fvisibility-nodllstorageclass=keep");
609
610 if (DriverArgs.hasArg(options::OPT_fvisibility_externs_dllimport_EQ))
611 DriverArgs.AddLastArg(CC1Args,
612 options::OPT_fvisibility_externs_dllimport_EQ);
613 else
614 CC1Args.push_back("-fvisibility-externs-dllimport=default");
615
616 // For PS4 we override the visibilty of external globals without
617 // dllimport or dllexport annotations.
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");
624 else
625 CC1Args.push_back("-fvisibility-externs-nodllstorageclass=keep");
626 }
627
628 // Enable jump table sizes section for PS5.
629 if (getTriple().isPS5()) {
630 CC1Args.push_back("-mllvm");
631 CC1Args.push_back("-emit-jump-table-sizes-section");
632 }
633}
634
635// PS4 toolchain.
636toolchains::PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple,
637 const llvm::opt::ArgList &Args)
638 : PS4PS5Base(D, Triple, Args, "PS4", "SCE_ORBIS_SDK_DIR") {}
639
640// PS5 toolchain.
641toolchains::PS5CPU::PS5CPU(const Driver &D, const llvm::Triple &Triple,
642 const llvm::opt::ArgList &Args)
643 : PS4PS5Base(D, Triple, Args, "PS5", "SCE_PROSPERO_SDK_DIR") {}
const Decl * D
static const char * makeArgString(const ArgList &Args, const char *Prefix, const char *Base, const char *Suffix)
Definition: PS4CPU.cpp:27
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
const char * getFilename() const
Definition: InputInfo.h:83
bool isNothing() const
Definition: InputInfo.h:74
bool isFilename() const
Definition: InputInfo.h:75
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:949
path_list & getFilePaths()
Definition: ToolChain.h:294
const Driver & getDriver() const
Definition: ToolChain.h:252
const llvm::Triple & getTriple() const
Definition: ToolChain.h:254
std::string GetProgramPath(const char *Name) const
Definition: ToolChain.cpp:953
void AddFilePathLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option.
Definition: ToolChain.cpp:1392
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:1456
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
const ToolChain & getToolChain() const
Definition: Tool.h:52
Tool * buildLinker() const override
Definition: PS4CPU.cpp:535
void addSanitizerArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const char *Prefix, const char *Suffix) const override
Definition: PS4CPU.cpp:91
Tool * buildAssembler() const override
Definition: PS4CPU.cpp:531
PS4CPU(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: PS4CPU.cpp:636
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: PS4CPU.cpp:509
virtual void addSanitizerArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const char *Prefix, const char *Suffix) const =0
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadingKind) const override
Add options that need to be passed to cc1 for this target.
Definition: PS4CPU.cpp:564
PS4PS5Base(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, StringRef Platform, const char *EnvVar)
Definition: PS4CPU.cpp:444
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: PS4CPU.cpp:549
Tool * buildAssembler() const override
Definition: PS4CPU.cpp:539
void addSanitizerArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const char *Prefix, const char *Suffix) const override
Definition: PS4CPU.cpp:105
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: PS4CPU.cpp:558
Tool * buildLinker() const override
Definition: PS4CPU.cpp:545
PS5CPU(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: PS4CPU.cpp:641
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: PS4CPU.cpp:121
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: PS4CPU.cpp:224
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: PS4CPU.cpp:58
void addSanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
void addProfileRTArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args, const Driver &D)
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport AtFileUTF8()
Definition: Job.h:85