1 | //===--- PS4CPU.h - 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 | #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_PS4CPU_H |
10 | #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_PS4CPU_H |
11 | |
12 | #include "Gnu.h" |
13 | #include "clang/Basic/LangOptions.h" |
14 | #include "clang/Driver/Tool.h" |
15 | #include "clang/Driver/ToolChain.h" |
16 | |
17 | namespace clang { |
18 | namespace driver { |
19 | namespace tools { |
20 | |
21 | namespace PScpu { |
22 | // Functions/classes in this namespace support both PS4 and PS5. |
23 | |
24 | void addProfileRTArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, |
25 | llvm::opt::ArgStringList &CmdArgs); |
26 | |
27 | void addSanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, |
28 | llvm::opt::ArgStringList &CmdArgs); |
29 | |
30 | class LLVM_LIBRARY_VISIBILITY Assembler final : public Tool { |
31 | public: |
32 | Assembler(const ToolChain &TC) : Tool("PScpu::Assembler" , "assembler" , TC) {} |
33 | |
34 | bool hasIntegratedCPP() const override { return false; } |
35 | |
36 | void ConstructJob(Compilation &C, const JobAction &JA, |
37 | const InputInfo &Output, const InputInfoList &Inputs, |
38 | const llvm::opt::ArgList &TCArgs, |
39 | const char *LinkingOutput) const override; |
40 | }; |
41 | |
42 | class LLVM_LIBRARY_VISIBILITY Linker final : public Tool { |
43 | public: |
44 | Linker(const ToolChain &TC) : Tool("PScpu::Linker" , "linker" , TC) {} |
45 | |
46 | bool hasIntegratedCPP() const override { return false; } |
47 | bool isLinkJob() const override { return true; } |
48 | |
49 | void ConstructJob(Compilation &C, const JobAction &JA, |
50 | const InputInfo &Output, const InputInfoList &Inputs, |
51 | const llvm::opt::ArgList &TCArgs, |
52 | const char *LinkingOutput) const override; |
53 | }; |
54 | } // namespace PScpu |
55 | } // namespace tools |
56 | |
57 | namespace toolchains { |
58 | |
59 | // Common Toolchain base class for PS4 and PS5. |
60 | class LLVM_LIBRARY_VISIBILITY PS4PS5Base : public Generic_ELF { |
61 | public: |
62 | PS4PS5Base(const Driver &D, const llvm::Triple &Triple, |
63 | const llvm::opt::ArgList &Args, StringRef Platform, |
64 | const char *EnvVar); |
65 | |
66 | void |
67 | AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, |
68 | llvm::opt::ArgStringList &CC1Args) const override; |
69 | // No support for finding a C++ standard library yet. |
70 | void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
71 | llvm::opt::ArgStringList &CC1Args) const override { |
72 | } |
73 | void |
74 | addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, |
75 | llvm::opt::ArgStringList &CC1Args) const override {} |
76 | |
77 | bool IsMathErrnoDefault() const override { return false; } |
78 | bool IsObjCNonFragileABIDefault() const override { return true; } |
79 | bool HasNativeLLVMSupport() const override { return true; } |
80 | bool isPICDefault() const override { return true; } |
81 | |
82 | LangOptions::StackProtectorMode |
83 | GetDefaultStackProtectorLevel(bool KernelOrKext) const override { |
84 | return LangOptions::SSPStrong; |
85 | } |
86 | |
87 | llvm::DebuggerKind getDefaultDebuggerTuning() const override { |
88 | return llvm::DebuggerKind::SCE; |
89 | } |
90 | |
91 | SanitizerMask getSupportedSanitizers() const override; |
92 | |
93 | void addClangTargetOptions( |
94 | const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, |
95 | Action::OffloadKind DeviceOffloadingKind) const override; |
96 | |
97 | llvm::DenormalMode getDefaultDenormalModeForType( |
98 | const llvm::opt::ArgList &DriverArgs, const JobAction &JA, |
99 | const llvm::fltSemantics *FPType) const override { |
100 | // DAZ and FTZ are on by default. |
101 | return llvm::DenormalMode::getPreserveSign(); |
102 | } |
103 | |
104 | // Helper methods for PS4/PS5. |
105 | virtual const char *getLinkerBaseName() const = 0; |
106 | virtual std::string qualifyPSCmdName(StringRef CmdName) const = 0; |
107 | virtual void addSanitizerArgs(const llvm::opt::ArgList &Args, |
108 | llvm::opt::ArgStringList &CmdArgs, |
109 | const char *Prefix, |
110 | const char *Suffix) const = 0; |
111 | virtual const char *getProfileRTLibName() const = 0; |
112 | |
113 | protected: |
114 | Tool *buildLinker() const override; |
115 | |
116 | private: |
117 | // We compute the SDK root dir in the ctor, and use it later. |
118 | std::string SDKRootDir; |
119 | }; |
120 | |
121 | // PS4-specific Toolchain class. |
122 | class LLVM_LIBRARY_VISIBILITY PS4CPU : public PS4PS5Base { |
123 | public: |
124 | PS4CPU(const Driver &D, const llvm::Triple &Triple, |
125 | const llvm::opt::ArgList &Args); |
126 | |
127 | unsigned GetDefaultDwarfVersion() const override { return 4; } |
128 | |
129 | // PS4 toolchain uses legacy thin LTO API, which is not |
130 | // capable of unit splitting. |
131 | bool canSplitThinLTOUnit() const override { return false; } |
132 | |
133 | const char *getLinkerBaseName() const override { return "ld" ; } |
134 | std::string qualifyPSCmdName(StringRef CmdName) const override { |
135 | return Twine("orbis-" , CmdName).str(); |
136 | } |
137 | void addSanitizerArgs(const llvm::opt::ArgList &Args, |
138 | llvm::opt::ArgStringList &CmdArgs, const char *Prefix, |
139 | const char *Suffix) const override; |
140 | const char *getProfileRTLibName() const override { |
141 | return "libclang_rt.profile-x86_64.a" ; |
142 | } |
143 | |
144 | protected: |
145 | Tool *buildAssembler() const override; |
146 | }; |
147 | |
148 | // PS5-specific Toolchain class. |
149 | class LLVM_LIBRARY_VISIBILITY PS5CPU : public PS4PS5Base { |
150 | public: |
151 | PS5CPU(const Driver &D, const llvm::Triple &Triple, |
152 | const llvm::opt::ArgList &Args); |
153 | |
154 | unsigned GetDefaultDwarfVersion() const override { return 5; } |
155 | |
156 | SanitizerMask getSupportedSanitizers() const override; |
157 | |
158 | const char *getLinkerBaseName() const override { return "lld" ; } |
159 | std::string qualifyPSCmdName(StringRef CmdName) const override { |
160 | return Twine("prospero-" , CmdName).str(); |
161 | } |
162 | void addSanitizerArgs(const llvm::opt::ArgList &Args, |
163 | llvm::opt::ArgStringList &CmdArgs, const char *Prefix, |
164 | const char *Suffix) const override; |
165 | const char *getProfileRTLibName() const override { |
166 | return "libclang_rt.profile-x86_64_nosubmission.a" ; |
167 | } |
168 | |
169 | protected: |
170 | Tool *buildAssembler() const override; |
171 | }; |
172 | |
173 | } // end namespace toolchains |
174 | } // end namespace driver |
175 | } // end namespace clang |
176 | |
177 | #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_PS4CPU_H |
178 | |