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