Mercurial > hg > CbC > CbC_llvm
comparison clang/lib/Driver/ToolChains/PS4CPU.cpp @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 0572611fdcc8 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
220:42394fc6a535 | 221:79ff65ed7e25 |
---|---|
64 assert(Input.isFilename() && "Invalid input."); | 64 assert(Input.isFilename() && "Invalid input."); |
65 CmdArgs.push_back(Input.getFilename()); | 65 CmdArgs.push_back(Input.getFilename()); |
66 | 66 |
67 const char *Exec = | 67 const char *Exec = |
68 Args.MakeArgString(getToolChain().GetProgramPath("orbis-as")); | 68 Args.MakeArgString(getToolChain().GetProgramPath("orbis-as")); |
69 C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); | 69 C.addCommand(std::make_unique<Command>(JA, *this, |
70 ResponseFileSupport::AtFileUTF8(), | |
71 Exec, CmdArgs, Inputs, Output)); | |
70 } | 72 } |
71 | 73 |
72 static void AddPS4SanitizerArgs(const ToolChain &TC, ArgStringList &CmdArgs) { | 74 static void AddPS4SanitizerArgs(const ToolChain &TC, ArgStringList &CmdArgs) { |
73 const SanitizerArgs &SanArgs = TC.getSanitizerArgs(); | 75 const SanitizerArgs &SanArgs = TC.getSanitizerArgs(); |
74 if (SanArgs.needsUbsanRt()) { | 76 if (SanArgs.needsUbsanRt()) { |
84 const SanitizerArgs &SanArgs = TC.getSanitizerArgs(); | 86 const SanitizerArgs &SanArgs = TC.getSanitizerArgs(); |
85 if (SanArgs.needsUbsanRt()) | 87 if (SanArgs.needsUbsanRt()) |
86 CmdArgs.push_back("--dependent-lib=libSceDbgUBSanitizer_stub_weak.a"); | 88 CmdArgs.push_back("--dependent-lib=libSceDbgUBSanitizer_stub_weak.a"); |
87 if (SanArgs.needsAsanRt()) | 89 if (SanArgs.needsAsanRt()) |
88 CmdArgs.push_back("--dependent-lib=libSceDbgAddressSanitizer_stub_weak.a"); | 90 CmdArgs.push_back("--dependent-lib=libSceDbgAddressSanitizer_stub_weak.a"); |
89 } | |
90 | |
91 static void ConstructPS4LinkJob(const Tool &T, Compilation &C, | |
92 const JobAction &JA, const InputInfo &Output, | |
93 const InputInfoList &Inputs, | |
94 const ArgList &Args, | |
95 const char *LinkingOutput) { | |
96 const toolchains::FreeBSD &ToolChain = | |
97 static_cast<const toolchains::FreeBSD &>(T.getToolChain()); | |
98 const Driver &D = ToolChain.getDriver(); | |
99 ArgStringList CmdArgs; | |
100 | |
101 // Silence warning for "clang -g foo.o -o foo" | |
102 Args.ClaimAllArgs(options::OPT_g_Group); | |
103 // and "clang -emit-llvm foo.o -o foo" | |
104 Args.ClaimAllArgs(options::OPT_emit_llvm); | |
105 // and for "clang -w foo.o -o foo". Other warning options are already | |
106 // handled somewhere else. | |
107 Args.ClaimAllArgs(options::OPT_w); | |
108 | |
109 if (!D.SysRoot.empty()) | |
110 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); | |
111 | |
112 if (Args.hasArg(options::OPT_pie)) | |
113 CmdArgs.push_back("-pie"); | |
114 | |
115 if (Args.hasArg(options::OPT_rdynamic)) | |
116 CmdArgs.push_back("-export-dynamic"); | |
117 if (Args.hasArg(options::OPT_shared)) | |
118 CmdArgs.push_back("--oformat=so"); | |
119 | |
120 if (Output.isFilename()) { | |
121 CmdArgs.push_back("-o"); | |
122 CmdArgs.push_back(Output.getFilename()); | |
123 } else { | |
124 assert(Output.isNothing() && "Invalid output."); | |
125 } | |
126 | |
127 if(!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) | |
128 AddPS4SanitizerArgs(ToolChain, CmdArgs); | |
129 | |
130 Args.AddAllArgs(CmdArgs, options::OPT_L); | |
131 Args.AddAllArgs(CmdArgs, options::OPT_T_Group); | |
132 Args.AddAllArgs(CmdArgs, options::OPT_e); | |
133 Args.AddAllArgs(CmdArgs, options::OPT_s); | |
134 Args.AddAllArgs(CmdArgs, options::OPT_t); | |
135 Args.AddAllArgs(CmdArgs, options::OPT_r); | |
136 | |
137 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) | |
138 CmdArgs.push_back("--no-demangle"); | |
139 | |
140 AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); | |
141 | |
142 if (Args.hasArg(options::OPT_pthread)) { | |
143 CmdArgs.push_back("-lpthread"); | |
144 } | |
145 | |
146 const char *Exec = Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld")); | |
147 | |
148 C.addCommand(std::make_unique<Command>(JA, T, Exec, CmdArgs, Inputs)); | |
149 } | |
150 | |
151 static void ConstructGoldLinkJob(const Tool &T, Compilation &C, | |
152 const JobAction &JA, const InputInfo &Output, | |
153 const InputInfoList &Inputs, | |
154 const ArgList &Args, | |
155 const char *LinkingOutput) { | |
156 const toolchains::FreeBSD &ToolChain = | |
157 static_cast<const toolchains::FreeBSD &>(T.getToolChain()); | |
158 const Driver &D = ToolChain.getDriver(); | |
159 ArgStringList CmdArgs; | |
160 | |
161 // Silence warning for "clang -g foo.o -o foo" | |
162 Args.ClaimAllArgs(options::OPT_g_Group); | |
163 // and "clang -emit-llvm foo.o -o foo" | |
164 Args.ClaimAllArgs(options::OPT_emit_llvm); | |
165 // and for "clang -w foo.o -o foo". Other warning options are already | |
166 // handled somewhere else. | |
167 Args.ClaimAllArgs(options::OPT_w); | |
168 | |
169 if (!D.SysRoot.empty()) | |
170 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); | |
171 | |
172 if (Args.hasArg(options::OPT_pie)) | |
173 CmdArgs.push_back("-pie"); | |
174 | |
175 if (Args.hasArg(options::OPT_static)) { | |
176 CmdArgs.push_back("-Bstatic"); | |
177 } else { | |
178 if (Args.hasArg(options::OPT_rdynamic)) | |
179 CmdArgs.push_back("-export-dynamic"); | |
180 CmdArgs.push_back("--eh-frame-hdr"); | |
181 if (Args.hasArg(options::OPT_shared)) { | |
182 CmdArgs.push_back("-Bshareable"); | |
183 } else { | |
184 CmdArgs.push_back("-dynamic-linker"); | |
185 CmdArgs.push_back("/libexec/ld-elf.so.1"); | |
186 } | |
187 CmdArgs.push_back("--enable-new-dtags"); | |
188 } | |
189 | |
190 if (Output.isFilename()) { | |
191 CmdArgs.push_back("-o"); | |
192 CmdArgs.push_back(Output.getFilename()); | |
193 } else { | |
194 assert(Output.isNothing() && "Invalid output."); | |
195 } | |
196 | |
197 if(!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) | |
198 AddPS4SanitizerArgs(ToolChain, CmdArgs); | |
199 | |
200 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { | |
201 const char *crt1 = nullptr; | |
202 if (!Args.hasArg(options::OPT_shared)) { | |
203 if (Args.hasArg(options::OPT_pg)) | |
204 crt1 = "gcrt1.o"; | |
205 else if (Args.hasArg(options::OPT_pie)) | |
206 crt1 = "Scrt1.o"; | |
207 else | |
208 crt1 = "crt1.o"; | |
209 } | |
210 if (crt1) | |
211 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1))); | |
212 | |
213 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); | |
214 | |
215 const char *crtbegin = nullptr; | |
216 if (Args.hasArg(options::OPT_static)) | |
217 crtbegin = "crtbeginT.o"; | |
218 else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) | |
219 crtbegin = "crtbeginS.o"; | |
220 else | |
221 crtbegin = "crtbegin.o"; | |
222 | |
223 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); | |
224 } | |
225 | |
226 Args.AddAllArgs(CmdArgs, options::OPT_L); | |
227 ToolChain.AddFilePathLibArgs(Args, CmdArgs); | |
228 Args.AddAllArgs(CmdArgs, options::OPT_T_Group); | |
229 Args.AddAllArgs(CmdArgs, options::OPT_e); | |
230 Args.AddAllArgs(CmdArgs, options::OPT_s); | |
231 Args.AddAllArgs(CmdArgs, options::OPT_t); | |
232 Args.AddAllArgs(CmdArgs, options::OPT_r); | |
233 | |
234 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) | |
235 CmdArgs.push_back("--no-demangle"); | |
236 | |
237 AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); | |
238 | |
239 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { | |
240 // For PS4, we always want to pass libm, libstdc++ and libkernel | |
241 // libraries for both C and C++ compilations. | |
242 CmdArgs.push_back("-lkernel"); | |
243 if (D.CCCIsCXX()) { | |
244 if (ToolChain.ShouldLinkCXXStdlib(Args)) | |
245 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); | |
246 if (Args.hasArg(options::OPT_pg)) | |
247 CmdArgs.push_back("-lm_p"); | |
248 else | |
249 CmdArgs.push_back("-lm"); | |
250 } | |
251 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding | |
252 // the default system libraries. Just mimic this for now. | |
253 if (Args.hasArg(options::OPT_pg)) | |
254 CmdArgs.push_back("-lgcc_p"); | |
255 else | |
256 CmdArgs.push_back("-lcompiler_rt"); | |
257 if (Args.hasArg(options::OPT_static)) { | |
258 CmdArgs.push_back("-lstdc++"); | |
259 } else if (Args.hasArg(options::OPT_pg)) { | |
260 CmdArgs.push_back("-lgcc_eh_p"); | |
261 } else { | |
262 CmdArgs.push_back("--as-needed"); | |
263 CmdArgs.push_back("-lstdc++"); | |
264 CmdArgs.push_back("--no-as-needed"); | |
265 } | |
266 | |
267 if (Args.hasArg(options::OPT_pthread)) { | |
268 if (Args.hasArg(options::OPT_pg)) | |
269 CmdArgs.push_back("-lpthread_p"); | |
270 else | |
271 CmdArgs.push_back("-lpthread"); | |
272 } | |
273 | |
274 if (Args.hasArg(options::OPT_pg)) { | |
275 if (Args.hasArg(options::OPT_shared)) | |
276 CmdArgs.push_back("-lc"); | |
277 else { | |
278 if (Args.hasArg(options::OPT_static)) { | |
279 CmdArgs.push_back("--start-group"); | |
280 CmdArgs.push_back("-lc_p"); | |
281 CmdArgs.push_back("-lpthread_p"); | |
282 CmdArgs.push_back("--end-group"); | |
283 } else { | |
284 CmdArgs.push_back("-lc_p"); | |
285 } | |
286 } | |
287 CmdArgs.push_back("-lgcc_p"); | |
288 } else { | |
289 if (Args.hasArg(options::OPT_static)) { | |
290 CmdArgs.push_back("--start-group"); | |
291 CmdArgs.push_back("-lc"); | |
292 CmdArgs.push_back("-lpthread"); | |
293 CmdArgs.push_back("--end-group"); | |
294 } else { | |
295 CmdArgs.push_back("-lc"); | |
296 } | |
297 CmdArgs.push_back("-lcompiler_rt"); | |
298 } | |
299 | |
300 if (Args.hasArg(options::OPT_static)) { | |
301 CmdArgs.push_back("-lstdc++"); | |
302 } else if (Args.hasArg(options::OPT_pg)) { | |
303 CmdArgs.push_back("-lgcc_eh_p"); | |
304 } else { | |
305 CmdArgs.push_back("--as-needed"); | |
306 CmdArgs.push_back("-lstdc++"); | |
307 CmdArgs.push_back("--no-as-needed"); | |
308 } | |
309 } | |
310 | |
311 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { | |
312 if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) | |
313 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); | |
314 else | |
315 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); | |
316 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); | |
317 } | |
318 | |
319 const char *Exec = | |
320 #ifdef _WIN32 | |
321 Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld.gold")); | |
322 #else | |
323 Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld")); | |
324 #endif | |
325 | |
326 C.addCommand(std::make_unique<Command>(JA, T, Exec, CmdArgs, Inputs)); | |
327 } | 91 } |
328 | 92 |
329 void tools::PS4cpu::Link::ConstructJob(Compilation &C, const JobAction &JA, | 93 void tools::PS4cpu::Link::ConstructJob(Compilation &C, const JobAction &JA, |
330 const InputInfo &Output, | 94 const InputInfo &Output, |
331 const InputInfoList &Inputs, | 95 const InputInfoList &Inputs, |
332 const ArgList &Args, | 96 const ArgList &Args, |
333 const char *LinkingOutput) const { | 97 const char *LinkingOutput) const { |
334 const toolchains::FreeBSD &ToolChain = | 98 const toolchains::FreeBSD &ToolChain = |
335 static_cast<const toolchains::FreeBSD &>(getToolChain()); | 99 static_cast<const toolchains::FreeBSD &>(getToolChain()); |
336 const Driver &D = ToolChain.getDriver(); | 100 const Driver &D = ToolChain.getDriver(); |
337 bool PS4Linker; | 101 ArgStringList CmdArgs; |
338 StringRef LinkerOptName; | 102 |
339 if (const Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) { | 103 // Silence warning for "clang -g foo.o -o foo" |
340 LinkerOptName = A->getValue(); | 104 Args.ClaimAllArgs(options::OPT_g_Group); |
341 if (LinkerOptName != "ps4" && LinkerOptName != "gold") | 105 // and "clang -emit-llvm foo.o -o foo" |
342 D.Diag(diag::err_drv_unsupported_linker) << LinkerOptName; | 106 Args.ClaimAllArgs(options::OPT_emit_llvm); |
343 } | 107 // and for "clang -w foo.o -o foo". Other warning options are already |
344 | 108 // handled somewhere else. |
345 if (LinkerOptName == "gold") | 109 Args.ClaimAllArgs(options::OPT_w); |
346 PS4Linker = false; | 110 |
347 else if (LinkerOptName == "ps4") | 111 if (!D.SysRoot.empty()) |
348 PS4Linker = true; | 112 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
349 else | 113 |
350 PS4Linker = !Args.hasArg(options::OPT_shared); | 114 if (Args.hasArg(options::OPT_pie)) |
351 | 115 CmdArgs.push_back("-pie"); |
352 if (PS4Linker) | 116 |
353 ConstructPS4LinkJob(*this, C, JA, Output, Inputs, Args, LinkingOutput); | 117 if (Args.hasArg(options::OPT_rdynamic)) |
354 else | 118 CmdArgs.push_back("-export-dynamic"); |
355 ConstructGoldLinkJob(*this, C, JA, Output, Inputs, Args, LinkingOutput); | 119 if (Args.hasArg(options::OPT_shared)) |
120 CmdArgs.push_back("--oformat=so"); | |
121 | |
122 if (Output.isFilename()) { | |
123 CmdArgs.push_back("-o"); | |
124 CmdArgs.push_back(Output.getFilename()); | |
125 } else { | |
126 assert(Output.isNothing() && "Invalid output."); | |
127 } | |
128 | |
129 if(!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) | |
130 AddPS4SanitizerArgs(ToolChain, CmdArgs); | |
131 | |
132 Args.AddAllArgs(CmdArgs, options::OPT_L); | |
133 Args.AddAllArgs(CmdArgs, options::OPT_T_Group); | |
134 Args.AddAllArgs(CmdArgs, options::OPT_e); | |
135 Args.AddAllArgs(CmdArgs, options::OPT_s); | |
136 Args.AddAllArgs(CmdArgs, options::OPT_t); | |
137 Args.AddAllArgs(CmdArgs, options::OPT_r); | |
138 | |
139 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) | |
140 CmdArgs.push_back("--no-demangle"); | |
141 | |
142 AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); | |
143 | |
144 if (Args.hasArg(options::OPT_pthread)) { | |
145 CmdArgs.push_back("-lpthread"); | |
146 } | |
147 | |
148 if (Args.hasArg(options::OPT_fuse_ld_EQ)) { | |
149 D.Diag(diag::err_drv_unsupported_opt_for_target) | |
150 << "-fuse-ld" << getToolChain().getTriple().str(); | |
151 } | |
152 | |
153 const char *Exec = | |
154 Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld")); | |
155 | |
156 C.addCommand(std::make_unique<Command>(JA, *this, | |
157 ResponseFileSupport::AtFileUTF8(), | |
158 Exec, CmdArgs, Inputs, Output)); | |
356 } | 159 } |
357 | 160 |
358 toolchains::PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, | 161 toolchains::PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, |
359 const ArgList &Args) | 162 const ArgList &Args) |
360 : Generic_ELF(D, Triple, Args) { | 163 : Generic_ELF(D, Triple, Args) { |
434 Res |= SanitizerKind::Vptr; | 237 Res |= SanitizerKind::Vptr; |
435 return Res; | 238 return Res; |
436 } | 239 } |
437 | 240 |
438 void toolchains::PS4CPU::addClangTargetOptions( | 241 void toolchains::PS4CPU::addClangTargetOptions( |
439 const ArgList &DriverArgs, | 242 const ArgList &DriverArgs, ArgStringList &CC1Args, |
440 ArgStringList &CC1Args, | 243 Action::OffloadKind DeviceOffloadingKind) const { |
441 Action::OffloadKind DeviceOffloadingKind) const { | |
442 // PS4 does not use init arrays. | 244 // PS4 does not use init arrays. |
443 if (DriverArgs.hasArg(options::OPT_fuse_init_array)) { | 245 if (DriverArgs.hasArg(options::OPT_fuse_init_array)) { |
444 Arg *A = DriverArgs.getLastArg(options::OPT_fuse_init_array); | 246 Arg *A = DriverArgs.getLastArg(options::OPT_fuse_init_array); |
445 getDriver().Diag(clang::diag::err_drv_unsupported_opt_for_target) | 247 getDriver().Diag(clang::diag::err_drv_unsupported_opt_for_target) |
446 << A->getAsString(DriverArgs) << getTriple().str(); | 248 << A->getAsString(DriverArgs) << getTriple().str(); |
447 } | 249 } |
448 | 250 |
449 CC1Args.push_back("-fno-use-init-array"); | 251 CC1Args.push_back("-fno-use-init-array"); |
450 } | 252 |
253 const Arg *A = | |
254 DriverArgs.getLastArg(options::OPT_fvisibility_from_dllstorageclass, | |
255 options::OPT_fno_visibility_from_dllstorageclass); | |
256 if (!A || | |
257 A->getOption().matches(options::OPT_fvisibility_from_dllstorageclass)) { | |
258 CC1Args.push_back("-fvisibility-from-dllstorageclass"); | |
259 | |
260 if (DriverArgs.hasArg(options::OPT_fvisibility_dllexport_EQ)) | |
261 DriverArgs.AddLastArg(CC1Args, options::OPT_fvisibility_dllexport_EQ); | |
262 else | |
263 CC1Args.push_back("-fvisibility-dllexport=protected"); | |
264 | |
265 if (DriverArgs.hasArg(options::OPT_fvisibility_nodllstorageclass_EQ)) | |
266 DriverArgs.AddLastArg(CC1Args, | |
267 options::OPT_fvisibility_nodllstorageclass_EQ); | |
268 else | |
269 CC1Args.push_back("-fvisibility-nodllstorageclass=hidden"); | |
270 | |
271 if (DriverArgs.hasArg(options::OPT_fvisibility_externs_dllimport_EQ)) | |
272 DriverArgs.AddLastArg(CC1Args, | |
273 options::OPT_fvisibility_externs_dllimport_EQ); | |
274 else | |
275 CC1Args.push_back("-fvisibility-externs-dllimport=default"); | |
276 | |
277 if (DriverArgs.hasArg( | |
278 options::OPT_fvisibility_externs_nodllstorageclass_EQ)) | |
279 DriverArgs.AddLastArg( | |
280 CC1Args, options::OPT_fvisibility_externs_nodllstorageclass_EQ); | |
281 else | |
282 CC1Args.push_back("-fvisibility-externs-nodllstorageclass=default"); | |
283 } | |
284 } |