blob: 7cbbc80f3063a0004de81582c67366da9d06e2bb [file] [log] [blame]
David L. Jonesf561aba2017-03-08 01:02:16 +00001//===--- Darwin.cpp - Darwin Tool and ToolChain Implementations -*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "Darwin.h"
11#include "Arch/ARM.h"
12#include "CommonArgs.h"
Akira Hatanaka3e40c302017-07-19 17:17:50 +000013#include "clang/Basic/AlignedAllocation.h"
David L. Jonesf561aba2017-03-08 01:02:16 +000014#include "clang/Basic/ObjCRuntime.h"
15#include "clang/Basic/VirtualFileSystem.h"
16#include "clang/Driver/Compilation.h"
17#include "clang/Driver/Driver.h"
18#include "clang/Driver/DriverDiagnostic.h"
19#include "clang/Driver/Options.h"
20#include "clang/Driver/SanitizerArgs.h"
21#include "llvm/ADT/StringSwitch.h"
22#include "llvm/Option/ArgList.h"
23#include "llvm/Support/Path.h"
24#include "llvm/Support/ScopedPrinter.h"
25#include "llvm/Support/TargetParser.h"
26#include <cstdlib> // ::getenv
27
28using namespace clang::driver;
29using namespace clang::driver::tools;
30using namespace clang::driver::toolchains;
31using namespace clang;
32using namespace llvm::opt;
33
34llvm::Triple::ArchType darwin::getArchTypeForMachOArchName(StringRef Str) {
35 // See arch(3) and llvm-gcc's driver-driver.c. We don't implement support for
36 // archs which Darwin doesn't use.
37
38 // The matching this routine does is fairly pointless, since it is neither the
39 // complete architecture list, nor a reasonable subset. The problem is that
40 // historically the driver driver accepts this and also ties its -march=
41 // handling to the architecture name, so we need to be careful before removing
42 // support for it.
43
44 // This code must be kept in sync with Clang's Darwin specific argument
45 // translation.
46
47 return llvm::StringSwitch<llvm::Triple::ArchType>(Str)
48 .Cases("ppc", "ppc601", "ppc603", "ppc604", "ppc604e", llvm::Triple::ppc)
49 .Cases("ppc750", "ppc7400", "ppc7450", "ppc970", llvm::Triple::ppc)
50 .Case("ppc64", llvm::Triple::ppc64)
51 .Cases("i386", "i486", "i486SX", "i586", "i686", llvm::Triple::x86)
52 .Cases("pentium", "pentpro", "pentIIm3", "pentIIm5", "pentium4",
53 llvm::Triple::x86)
54 .Cases("x86_64", "x86_64h", llvm::Triple::x86_64)
55 // This is derived from the driver driver.
56 .Cases("arm", "armv4t", "armv5", "armv6", "armv6m", llvm::Triple::arm)
57 .Cases("armv7", "armv7em", "armv7k", "armv7m", llvm::Triple::arm)
58 .Cases("armv7s", "xscale", llvm::Triple::arm)
59 .Case("arm64", llvm::Triple::aarch64)
60 .Case("r600", llvm::Triple::r600)
61 .Case("amdgcn", llvm::Triple::amdgcn)
62 .Case("nvptx", llvm::Triple::nvptx)
63 .Case("nvptx64", llvm::Triple::nvptx64)
64 .Case("amdil", llvm::Triple::amdil)
65 .Case("spir", llvm::Triple::spir)
66 .Default(llvm::Triple::UnknownArch);
67}
68
69void darwin::setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str) {
70 const llvm::Triple::ArchType Arch = getArchTypeForMachOArchName(Str);
Florian Hahnef5bbd62017-07-27 16:28:39 +000071 llvm::ARM::ArchKind ArchKind = llvm::ARM::parseArch(Str);
David L. Jonesf561aba2017-03-08 01:02:16 +000072 T.setArch(Arch);
73
74 if (Str == "x86_64h")
75 T.setArchName(Str);
Florian Hahnef5bbd62017-07-27 16:28:39 +000076 else if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
77 ArchKind == llvm::ARM::ArchKind::ARMV7M ||
78 ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
David L. Jonesf561aba2017-03-08 01:02:16 +000079 T.setOS(llvm::Triple::UnknownOS);
80 T.setObjectFormat(llvm::Triple::MachO);
81 }
82}
83
84void darwin::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
85 const InputInfo &Output,
86 const InputInfoList &Inputs,
87 const ArgList &Args,
88 const char *LinkingOutput) const {
89 ArgStringList CmdArgs;
90
91 assert(Inputs.size() == 1 && "Unexpected number of inputs.");
92 const InputInfo &Input = Inputs[0];
93
94 // Determine the original source input.
95 const Action *SourceAction = &JA;
96 while (SourceAction->getKind() != Action::InputClass) {
97 assert(!SourceAction->getInputs().empty() && "unexpected root action!");
98 SourceAction = SourceAction->getInputs()[0];
99 }
100
101 // If -fno-integrated-as is used add -Q to the darwin assember driver to make
102 // sure it runs its system assembler not clang's integrated assembler.
103 // Applicable to darwin11+ and Xcode 4+. darwin<10 lacked integrated-as.
104 // FIXME: at run-time detect assembler capabilities or rely on version
105 // information forwarded by -target-assembler-version.
106 if (Args.hasArg(options::OPT_fno_integrated_as)) {
107 const llvm::Triple &T(getToolChain().getTriple());
108 if (!(T.isMacOSX() && T.isMacOSXVersionLT(10, 7)))
109 CmdArgs.push_back("-Q");
110 }
111
112 // Forward -g, assuming we are dealing with an actual assembly file.
113 if (SourceAction->getType() == types::TY_Asm ||
114 SourceAction->getType() == types::TY_PP_Asm) {
115 if (Args.hasArg(options::OPT_gstabs))
116 CmdArgs.push_back("--gstabs");
117 else if (Args.hasArg(options::OPT_g_Group))
118 CmdArgs.push_back("-g");
119 }
120
121 // Derived from asm spec.
122 AddMachOArch(Args, CmdArgs);
123
124 // Use -force_cpusubtype_ALL on x86 by default.
125 if (getToolChain().getArch() == llvm::Triple::x86 ||
126 getToolChain().getArch() == llvm::Triple::x86_64 ||
127 Args.hasArg(options::OPT_force__cpusubtype__ALL))
128 CmdArgs.push_back("-force_cpusubtype_ALL");
129
130 if (getToolChain().getArch() != llvm::Triple::x86_64 &&
131 (((Args.hasArg(options::OPT_mkernel) ||
132 Args.hasArg(options::OPT_fapple_kext)) &&
133 getMachOToolChain().isKernelStatic()) ||
134 Args.hasArg(options::OPT_static)))
135 CmdArgs.push_back("-static");
136
137 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
138
139 assert(Output.isFilename() && "Unexpected lipo output.");
140 CmdArgs.push_back("-o");
141 CmdArgs.push_back(Output.getFilename());
142
143 assert(Input.isFilename() && "Invalid input.");
144 CmdArgs.push_back(Input.getFilename());
145
146 // asm_final spec is empty.
147
148 const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
149 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
150}
151
152void darwin::MachOTool::anchor() {}
153
154void darwin::MachOTool::AddMachOArch(const ArgList &Args,
155 ArgStringList &CmdArgs) const {
156 StringRef ArchName = getMachOToolChain().getMachOArchName(Args);
157
158 // Derived from darwin_arch spec.
159 CmdArgs.push_back("-arch");
160 CmdArgs.push_back(Args.MakeArgString(ArchName));
161
162 // FIXME: Is this needed anymore?
163 if (ArchName == "arm")
164 CmdArgs.push_back("-force_cpusubtype_ALL");
165}
166
167bool darwin::Linker::NeedsTempPath(const InputInfoList &Inputs) const {
168 // We only need to generate a temp path for LTO if we aren't compiling object
169 // files. When compiling source files, we run 'dsymutil' after linking. We
170 // don't run 'dsymutil' when compiling object files.
171 for (const auto &Input : Inputs)
172 if (Input.getType() != types::TY_Object)
173 return true;
174
175 return false;
176}
177
178/// \brief Pass -no_deduplicate to ld64 under certain conditions:
179///
180/// - Either -O0 or -O1 is explicitly specified
181/// - No -O option is specified *and* this is a compile+link (implicit -O0)
182///
183/// Also do *not* add -no_deduplicate when no -O option is specified and this
184/// is just a link (we can't imply -O0)
185static bool shouldLinkerNotDedup(bool IsLinkerOnlyAction, const ArgList &Args) {
186 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
187 if (A->getOption().matches(options::OPT_O0))
188 return true;
189 if (A->getOption().matches(options::OPT_O))
190 return llvm::StringSwitch<bool>(A->getValue())
191 .Case("1", true)
192 .Default(false);
193 return false; // OPT_Ofast & OPT_O4
194 }
195
196 if (!IsLinkerOnlyAction) // Implicit -O0 for compile+linker only.
197 return true;
198 return false;
199}
200
201void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args,
202 ArgStringList &CmdArgs,
203 const InputInfoList &Inputs) const {
204 const Driver &D = getToolChain().getDriver();
205 const toolchains::MachO &MachOTC = getMachOToolChain();
206
207 unsigned Version[5] = {0, 0, 0, 0, 0};
208 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
209 if (!Driver::GetReleaseVersion(A->getValue(), Version))
210 D.Diag(diag::err_drv_invalid_version_number) << A->getAsString(Args);
211 }
212
213 // Newer linkers support -demangle. Pass it if supported and not disabled by
214 // the user.
215 if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
216 CmdArgs.push_back("-demangle");
217
218 if (Args.hasArg(options::OPT_rdynamic) && Version[0] >= 137)
219 CmdArgs.push_back("-export_dynamic");
220
221 // If we are using App Extension restrictions, pass a flag to the linker
222 // telling it that the compiled code has been audited.
223 if (Args.hasFlag(options::OPT_fapplication_extension,
224 options::OPT_fno_application_extension, false))
225 CmdArgs.push_back("-application_extension");
226
227 if (D.isUsingLTO()) {
228 // If we are using LTO, then automatically create a temporary file path for
229 // the linker to use, so that it's lifetime will extend past a possible
230 // dsymutil step.
231 if (Version[0] >= 116 && NeedsTempPath(Inputs)) {
232 const char *TmpPath = C.getArgs().MakeArgString(
233 D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object)));
234 C.addTempFile(TmpPath);
235 CmdArgs.push_back("-object_path_lto");
236 CmdArgs.push_back(TmpPath);
237 }
238 }
239
240 // Use -lto_library option to specify the libLTO.dylib path. Try to find
241 // it in clang installed libraries. ld64 will only look at this argument
242 // when it actually uses LTO, so libLTO.dylib only needs to exist at link
243 // time if ld64 decides that it needs to use LTO.
244 // Since this is passed unconditionally, ld64 will never look for libLTO.dylib
245 // next to it. That's ok since ld64 using a libLTO.dylib not matching the
246 // clang version won't work anyways.
247 if (Version[0] >= 133) {
248 // Search for libLTO in <InstalledDir>/../lib/libLTO.dylib
249 StringRef P = llvm::sys::path::parent_path(D.Dir);
250 SmallString<128> LibLTOPath(P);
251 llvm::sys::path::append(LibLTOPath, "lib");
252 llvm::sys::path::append(LibLTOPath, "libLTO.dylib");
253 CmdArgs.push_back("-lto_library");
254 CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath));
255 }
256
257 // ld64 version 262 and above run the deduplicate pass by default.
258 if (Version[0] >= 262 && shouldLinkerNotDedup(C.getJobs().empty(), Args))
259 CmdArgs.push_back("-no_deduplicate");
260
261 // Derived from the "link" spec.
262 Args.AddAllArgs(CmdArgs, options::OPT_static);
263 if (!Args.hasArg(options::OPT_static))
264 CmdArgs.push_back("-dynamic");
265 if (Args.hasArg(options::OPT_fgnu_runtime)) {
266 // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu
267 // here. How do we wish to handle such things?
268 }
269
270 if (!Args.hasArg(options::OPT_dynamiclib)) {
271 AddMachOArch(Args, CmdArgs);
272 // FIXME: Why do this only on this path?
273 Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL);
274
275 Args.AddLastArg(CmdArgs, options::OPT_bundle);
276 Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader);
277 Args.AddAllArgs(CmdArgs, options::OPT_client__name);
278
279 Arg *A;
280 if ((A = Args.getLastArg(options::OPT_compatibility__version)) ||
281 (A = Args.getLastArg(options::OPT_current__version)) ||
282 (A = Args.getLastArg(options::OPT_install__name)))
283 D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args)
284 << "-dynamiclib";
285
286 Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace);
287 Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs);
288 Args.AddLastArg(CmdArgs, options::OPT_private__bundle);
289 } else {
290 CmdArgs.push_back("-dylib");
291
292 Arg *A;
293 if ((A = Args.getLastArg(options::OPT_bundle)) ||
294 (A = Args.getLastArg(options::OPT_bundle__loader)) ||
295 (A = Args.getLastArg(options::OPT_client__name)) ||
296 (A = Args.getLastArg(options::OPT_force__flat__namespace)) ||
297 (A = Args.getLastArg(options::OPT_keep__private__externs)) ||
298 (A = Args.getLastArg(options::OPT_private__bundle)))
299 D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args)
300 << "-dynamiclib";
301
302 Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version,
303 "-dylib_compatibility_version");
304 Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version,
305 "-dylib_current_version");
306
307 AddMachOArch(Args, CmdArgs);
308
309 Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name,
310 "-dylib_install_name");
311 }
312
313 Args.AddLastArg(CmdArgs, options::OPT_all__load);
314 Args.AddAllArgs(CmdArgs, options::OPT_allowable__client);
315 Args.AddLastArg(CmdArgs, options::OPT_bind__at__load);
316 if (MachOTC.isTargetIOSBased())
317 Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal);
318 Args.AddLastArg(CmdArgs, options::OPT_dead__strip);
319 Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms);
320 Args.AddAllArgs(CmdArgs, options::OPT_dylib__file);
321 Args.AddLastArg(CmdArgs, options::OPT_dynamic);
322 Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list);
323 Args.AddLastArg(CmdArgs, options::OPT_flat__namespace);
324 Args.AddAllArgs(CmdArgs, options::OPT_force__load);
325 Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names);
326 Args.AddAllArgs(CmdArgs, options::OPT_image__base);
327 Args.AddAllArgs(CmdArgs, options::OPT_init);
328
329 // Add the deployment target.
330 MachOTC.addMinVersionArgs(Args, CmdArgs);
331
332 Args.AddLastArg(CmdArgs, options::OPT_nomultidefs);
333 Args.AddLastArg(CmdArgs, options::OPT_multi__module);
334 Args.AddLastArg(CmdArgs, options::OPT_single__module);
335 Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined);
336 Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused);
337
338 if (const Arg *A =
339 Args.getLastArg(options::OPT_fpie, options::OPT_fPIE,
340 options::OPT_fno_pie, options::OPT_fno_PIE)) {
341 if (A->getOption().matches(options::OPT_fpie) ||
342 A->getOption().matches(options::OPT_fPIE))
343 CmdArgs.push_back("-pie");
344 else
345 CmdArgs.push_back("-no_pie");
346 }
347
348 // for embed-bitcode, use -bitcode_bundle in linker command
349 if (C.getDriver().embedBitcodeEnabled()) {
350 // Check if the toolchain supports bitcode build flow.
351 if (MachOTC.SupportsEmbeddedBitcode()) {
352 CmdArgs.push_back("-bitcode_bundle");
353 if (C.getDriver().embedBitcodeMarkerOnly() && Version[0] >= 278) {
354 CmdArgs.push_back("-bitcode_process_mode");
355 CmdArgs.push_back("marker");
356 }
357 } else
358 D.Diag(diag::err_drv_bitcode_unsupported_on_toolchain);
359 }
360
361 Args.AddLastArg(CmdArgs, options::OPT_prebind);
362 Args.AddLastArg(CmdArgs, options::OPT_noprebind);
363 Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding);
364 Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules);
365 Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs);
366 Args.AddAllArgs(CmdArgs, options::OPT_sectcreate);
367 Args.AddAllArgs(CmdArgs, options::OPT_sectorder);
368 Args.AddAllArgs(CmdArgs, options::OPT_seg1addr);
369 Args.AddAllArgs(CmdArgs, options::OPT_segprot);
370 Args.AddAllArgs(CmdArgs, options::OPT_segaddr);
371 Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr);
372 Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr);
373 Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table);
374 Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename);
375 Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
376 Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
377
378 // Give --sysroot= preference, over the Apple specific behavior to also use
379 // --isysroot as the syslibroot.
380 StringRef sysroot = C.getSysRoot();
381 if (sysroot != "") {
382 CmdArgs.push_back("-syslibroot");
383 CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
384 } else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
385 CmdArgs.push_back("-syslibroot");
386 CmdArgs.push_back(A->getValue());
387 }
388
389 Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace);
390 Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints);
391 Args.AddAllArgs(CmdArgs, options::OPT_umbrella);
392 Args.AddAllArgs(CmdArgs, options::OPT_undefined);
393 Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list);
394 Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches);
395 Args.AddLastArg(CmdArgs, options::OPT_X_Flag);
396 Args.AddAllArgs(CmdArgs, options::OPT_y);
397 Args.AddLastArg(CmdArgs, options::OPT_w);
398 Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size);
399 Args.AddAllArgs(CmdArgs, options::OPT_segs__read__);
400 Args.AddLastArg(CmdArgs, options::OPT_seglinkedit);
401 Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit);
402 Args.AddAllArgs(CmdArgs, options::OPT_sectalign);
403 Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols);
404 Args.AddAllArgs(CmdArgs, options::OPT_segcreate);
405 Args.AddLastArg(CmdArgs, options::OPT_whyload);
406 Args.AddLastArg(CmdArgs, options::OPT_whatsloaded);
407 Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name);
408 Args.AddLastArg(CmdArgs, options::OPT_dylinker);
409 Args.AddLastArg(CmdArgs, options::OPT_Mach);
410}
411
412/// \brief Determine whether we are linking the ObjC runtime.
413static bool isObjCRuntimeLinked(const ArgList &Args) {
414 if (isObjCAutoRefCount(Args)) {
415 Args.ClaimAllArgs(options::OPT_fobjc_link_runtime);
416 return true;
417 }
418 return Args.hasArg(options::OPT_fobjc_link_runtime);
419}
420
421void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
422 const InputInfo &Output,
423 const InputInfoList &Inputs,
424 const ArgList &Args,
425 const char *LinkingOutput) const {
426 assert(Output.getType() == types::TY_Image && "Invalid linker output type.");
427
428 // If the number of arguments surpasses the system limits, we will encode the
429 // input files in a separate file, shortening the command line. To this end,
430 // build a list of input file names that can be passed via a file with the
431 // -filelist linker option.
432 llvm::opt::ArgStringList InputFileList;
433
434 // The logic here is derived from gcc's behavior; most of which
435 // comes from specs (starting with link_command). Consult gcc for
436 // more information.
437 ArgStringList CmdArgs;
438
439 /// Hack(tm) to ignore linking errors when we are doing ARC migration.
440 if (Args.hasArg(options::OPT_ccc_arcmt_check,
441 options::OPT_ccc_arcmt_migrate)) {
442 for (const auto &Arg : Args)
443 Arg->claim();
444 const char *Exec =
445 Args.MakeArgString(getToolChain().GetProgramPath("touch"));
446 CmdArgs.push_back(Output.getFilename());
447 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, None));
448 return;
449 }
450
451 // I'm not sure why this particular decomposition exists in gcc, but
452 // we follow suite for ease of comparison.
453 AddLinkArgs(C, Args, CmdArgs, Inputs);
454
455 // For LTO, pass the name of the optimization record file.
456 if (Args.hasFlag(options::OPT_fsave_optimization_record,
457 options::OPT_fno_save_optimization_record, false)) {
458 CmdArgs.push_back("-mllvm");
459 CmdArgs.push_back("-lto-pass-remarks-output");
460 CmdArgs.push_back("-mllvm");
461
462 SmallString<128> F;
463 F = Output.getFilename();
464 F += ".opt.yaml";
465 CmdArgs.push_back(Args.MakeArgString(F));
466
467 if (getLastProfileUseArg(Args)) {
468 CmdArgs.push_back("-mllvm");
469 CmdArgs.push_back("-lto-pass-remarks-with-hotness");
470 }
471 }
472
473 // It seems that the 'e' option is completely ignored for dynamic executables
474 // (the default), and with static executables, the last one wins, as expected.
475 Args.AddAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, options::OPT_t,
476 options::OPT_Z_Flag, options::OPT_u_Group,
477 options::OPT_e, options::OPT_r});
478
479 // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
480 // members of static archive libraries which implement Objective-C classes or
481 // categories.
482 if (Args.hasArg(options::OPT_ObjC) || Args.hasArg(options::OPT_ObjCXX))
483 CmdArgs.push_back("-ObjC");
484
485 CmdArgs.push_back("-o");
486 CmdArgs.push_back(Output.getFilename());
487
488 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
489 getMachOToolChain().addStartObjectFileArgs(Args, CmdArgs);
490
491 // SafeStack requires its own runtime libraries
492 // These libraries should be linked first, to make sure the
493 // __safestack_init constructor executes before everything else
494 if (getToolChain().getSanitizerArgs().needsSafeStackRt()) {
495 getMachOToolChain().AddLinkRuntimeLib(Args, CmdArgs,
496 "libclang_rt.safestack_osx.a",
497 /*AlwaysLink=*/true);
498 }
499
500 Args.AddAllArgs(CmdArgs, options::OPT_L);
501
502 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
503 // Build the input file for -filelist (list of linker input files) in case we
504 // need it later
505 for (const auto &II : Inputs) {
506 if (!II.isFilename()) {
507 // This is a linker input argument.
508 // We cannot mix input arguments and file names in a -filelist input, thus
509 // we prematurely stop our list (remaining files shall be passed as
510 // arguments).
511 if (InputFileList.size() > 0)
512 break;
513
514 continue;
515 }
516
517 InputFileList.push_back(II.getFilename());
518 }
519
520 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
521 addOpenMPRuntime(CmdArgs, getToolChain(), Args);
522
523 if (isObjCRuntimeLinked(Args) &&
524 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
525 // We use arclite library for both ARC and subscripting support.
526 getMachOToolChain().AddLinkARCArgs(Args, CmdArgs);
527
528 CmdArgs.push_back("-framework");
529 CmdArgs.push_back("Foundation");
530 // Link libobj.
531 CmdArgs.push_back("-lobjc");
532 }
533
534 if (LinkingOutput) {
535 CmdArgs.push_back("-arch_multiple");
536 CmdArgs.push_back("-final_output");
537 CmdArgs.push_back(LinkingOutput);
538 }
539
540 if (Args.hasArg(options::OPT_fnested_functions))
541 CmdArgs.push_back("-allow_stack_execute");
542
543 getMachOToolChain().addProfileRTLibs(Args, CmdArgs);
544
545 if (unsigned Parallelism =
546 getLTOParallelism(Args, getToolChain().getDriver())) {
547 CmdArgs.push_back("-mllvm");
548 CmdArgs.push_back(
549 Args.MakeArgString(Twine("-threads=") + llvm::to_string(Parallelism)));
550 }
551
Nico Weber0ee47d92017-07-25 18:02:57 +0000552 if (getToolChain().ShouldLinkCXXStdlib(Args))
553 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
David L. Jonesf561aba2017-03-08 01:02:16 +0000554 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
David L. Jonesf561aba2017-03-08 01:02:16 +0000555 // link_ssp spec is empty.
556
557 // Let the tool chain choose which runtime library to link.
558 getMachOToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs);
559
560 // No need to do anything for pthreads. Claim argument to avoid warning.
561 Args.ClaimAllArgs(options::OPT_pthread);
562 Args.ClaimAllArgs(options::OPT_pthreads);
563 }
564
565 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
566 // endfile_spec is empty.
567 }
568
569 Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
570 Args.AddAllArgs(CmdArgs, options::OPT_F);
571
572 // -iframework should be forwarded as -F.
573 for (const Arg *A : Args.filtered(options::OPT_iframework))
574 CmdArgs.push_back(Args.MakeArgString(std::string("-F") + A->getValue()));
575
576 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
577 if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
578 if (A->getValue() == StringRef("Accelerate")) {
579 CmdArgs.push_back("-framework");
580 CmdArgs.push_back("Accelerate");
581 }
582 }
583 }
584
585 const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
586 std::unique_ptr<Command> Cmd =
587 llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs);
588 Cmd->setInputFileList(std::move(InputFileList));
589 C.addCommand(std::move(Cmd));
590}
591
592void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA,
593 const InputInfo &Output,
594 const InputInfoList &Inputs,
595 const ArgList &Args,
596 const char *LinkingOutput) const {
597 ArgStringList CmdArgs;
598
599 CmdArgs.push_back("-create");
600 assert(Output.isFilename() && "Unexpected lipo output.");
601
602 CmdArgs.push_back("-output");
603 CmdArgs.push_back(Output.getFilename());
604
605 for (const auto &II : Inputs) {
606 assert(II.isFilename() && "Unexpected lipo input.");
607 CmdArgs.push_back(II.getFilename());
608 }
609
610 const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo"));
611 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
612}
613
614void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA,
615 const InputInfo &Output,
616 const InputInfoList &Inputs,
617 const ArgList &Args,
618 const char *LinkingOutput) const {
619 ArgStringList CmdArgs;
620
621 CmdArgs.push_back("-o");
622 CmdArgs.push_back(Output.getFilename());
623
624 assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
625 const InputInfo &Input = Inputs[0];
626 assert(Input.isFilename() && "Unexpected dsymutil input.");
627 CmdArgs.push_back(Input.getFilename());
628
629 const char *Exec =
630 Args.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
631 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
632}
633
634void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA,
635 const InputInfo &Output,
636 const InputInfoList &Inputs,
637 const ArgList &Args,
638 const char *LinkingOutput) const {
639 ArgStringList CmdArgs;
640 CmdArgs.push_back("--verify");
641 CmdArgs.push_back("--debug-info");
642 CmdArgs.push_back("--eh-frame");
643 CmdArgs.push_back("--quiet");
644
645 assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
646 const InputInfo &Input = Inputs[0];
647 assert(Input.isFilename() && "Unexpected verify input");
648
649 // Grabbing the output of the earlier dsymutil run.
650 CmdArgs.push_back(Input.getFilename());
651
652 const char *Exec =
653 Args.MakeArgString(getToolChain().GetProgramPath("dwarfdump"));
654 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
655}
656
657MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
658 : ToolChain(D, Triple, Args) {
659 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
660 getProgramPaths().push_back(getDriver().getInstalledDir());
661 if (getDriver().getInstalledDir() != getDriver().Dir)
662 getProgramPaths().push_back(getDriver().Dir);
663}
664
665/// Darwin - Darwin tool chain for i386 and x86_64.
666Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
667 : MachO(D, Triple, Args), TargetInitialized(false),
668 CudaInstallation(D, Triple, Args) {}
669
670types::ID MachO::LookupTypeForExtension(StringRef Ext) const {
671 types::ID Ty = types::lookupTypeForExtension(Ext);
672
673 // Darwin always preprocesses assembly files (unless -x is used explicitly).
674 if (Ty == types::TY_PP_Asm)
675 return types::TY_Asm;
676
677 return Ty;
678}
679
680bool MachO::HasNativeLLVMSupport() const { return true; }
681
682ToolChain::CXXStdlibType Darwin::GetDefaultCXXStdlibType() const {
683 // Default to use libc++ on OS X 10.9+ and iOS 7+.
684 if ((isTargetMacOS() && !isMacosxVersionLT(10, 9)) ||
685 (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) ||
686 isTargetWatchOSBased())
687 return ToolChain::CST_Libcxx;
688
689 return ToolChain::CST_Libstdcxx;
690}
691
692/// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0.
693ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const {
694 if (isTargetWatchOSBased())
695 return ObjCRuntime(ObjCRuntime::WatchOS, TargetVersion);
696 if (isTargetIOSBased())
697 return ObjCRuntime(ObjCRuntime::iOS, TargetVersion);
698 if (isNonFragile)
699 return ObjCRuntime(ObjCRuntime::MacOSX, TargetVersion);
700 return ObjCRuntime(ObjCRuntime::FragileMacOSX, TargetVersion);
701}
702
703/// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2.
704bool Darwin::hasBlocksRuntime() const {
705 if (isTargetWatchOSBased())
706 return true;
707 else if (isTargetIOSBased())
708 return !isIPhoneOSVersionLT(3, 2);
709 else {
710 assert(isTargetMacOS() && "unexpected darwin target");
711 return !isMacosxVersionLT(10, 6);
712 }
713}
714
715void Darwin::AddCudaIncludeArgs(const ArgList &DriverArgs,
716 ArgStringList &CC1Args) const {
717 CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
718}
719
720// This is just a MachO name translation routine and there's no
721// way to join this into ARMTargetParser without breaking all
722// other assumptions. Maybe MachO should consider standardising
723// their nomenclature.
724static const char *ArmMachOArchName(StringRef Arch) {
725 return llvm::StringSwitch<const char *>(Arch)
726 .Case("armv6k", "armv6")
727 .Case("armv6m", "armv6m")
728 .Case("armv5tej", "armv5")
729 .Case("xscale", "xscale")
730 .Case("armv4t", "armv4t")
731 .Case("armv7", "armv7")
732 .Cases("armv7a", "armv7-a", "armv7")
733 .Cases("armv7r", "armv7-r", "armv7")
734 .Cases("armv7em", "armv7e-m", "armv7em")
735 .Cases("armv7k", "armv7-k", "armv7k")
736 .Cases("armv7m", "armv7-m", "armv7m")
737 .Cases("armv7s", "armv7-s", "armv7s")
738 .Default(nullptr);
739}
740
741static const char *ArmMachOArchNameCPU(StringRef CPU) {
Florian Hahnef5bbd62017-07-27 16:28:39 +0000742 llvm::ARM::ArchKind ArchKind = llvm::ARM::parseCPUArch(CPU);
743 if (ArchKind == llvm::ARM::ArchKind::INVALID)
David L. Jonesf561aba2017-03-08 01:02:16 +0000744 return nullptr;
745 StringRef Arch = llvm::ARM::getArchName(ArchKind);
746
747 // FIXME: Make sure this MachO triple mangling is really necessary.
748 // ARMv5* normalises to ARMv5.
749 if (Arch.startswith("armv5"))
750 Arch = Arch.substr(0, 5);
751 // ARMv6*, except ARMv6M, normalises to ARMv6.
752 else if (Arch.startswith("armv6") && !Arch.endswith("6m"))
753 Arch = Arch.substr(0, 5);
754 // ARMv7A normalises to ARMv7.
755 else if (Arch.endswith("v7a"))
756 Arch = Arch.substr(0, 5);
757 return Arch.data();
758}
759
760StringRef MachO::getMachOArchName(const ArgList &Args) const {
761 switch (getTriple().getArch()) {
762 default:
763 return getDefaultUniversalArchName();
764
765 case llvm::Triple::aarch64:
766 return "arm64";
767
768 case llvm::Triple::thumb:
769 case llvm::Triple::arm:
770 if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ))
771 if (const char *Arch = ArmMachOArchName(A->getValue()))
772 return Arch;
773
774 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
775 if (const char *Arch = ArmMachOArchNameCPU(A->getValue()))
776 return Arch;
777
778 return "arm";
779 }
780}
781
782Darwin::~Darwin() {}
783
784MachO::~MachO() {}
785
786std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args,
787 types::ID InputType) const {
788 llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
789
790 // If the target isn't initialized (e.g., an unknown Darwin platform, return
791 // the default triple).
792 if (!isTargetInitialized())
793 return Triple.getTriple();
794
795 SmallString<16> Str;
796 if (isTargetWatchOSBased())
797 Str += "watchos";
798 else if (isTargetTvOSBased())
799 Str += "tvos";
800 else if (isTargetIOSBased())
801 Str += "ios";
802 else
803 Str += "macosx";
804 Str += getTargetVersion().getAsString();
805 Triple.setOSName(Str);
806
807 return Triple.getTriple();
808}
809
810Tool *MachO::getTool(Action::ActionClass AC) const {
811 switch (AC) {
812 case Action::LipoJobClass:
813 if (!Lipo)
814 Lipo.reset(new tools::darwin::Lipo(*this));
815 return Lipo.get();
816 case Action::DsymutilJobClass:
817 if (!Dsymutil)
818 Dsymutil.reset(new tools::darwin::Dsymutil(*this));
819 return Dsymutil.get();
820 case Action::VerifyDebugInfoJobClass:
821 if (!VerifyDebug)
822 VerifyDebug.reset(new tools::darwin::VerifyDebug(*this));
823 return VerifyDebug.get();
824 default:
825 return ToolChain::getTool(AC);
826 }
827}
828
829Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); }
830
831Tool *MachO::buildAssembler() const {
832 return new tools::darwin::Assembler(*this);
833}
834
835DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple,
836 const ArgList &Args)
837 : Darwin(D, Triple, Args) {}
838
839void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const {
840 // For modern targets, promote certain warnings to errors.
841 if (isTargetWatchOSBased() || getTriple().isArch64Bit()) {
842 // Always enable -Wdeprecated-objc-isa-usage and promote it
843 // to an error.
844 CC1Args.push_back("-Wdeprecated-objc-isa-usage");
845 CC1Args.push_back("-Werror=deprecated-objc-isa-usage");
846
847 // For iOS and watchOS, also error about implicit function declarations,
848 // as that can impact calling conventions.
849 if (!isTargetMacOS())
850 CC1Args.push_back("-Werror=implicit-function-declaration");
851 }
852}
853
854void DarwinClang::AddLinkARCArgs(const ArgList &Args,
855 ArgStringList &CmdArgs) const {
856 // Avoid linking compatibility stubs on i386 mac.
857 if (isTargetMacOS() && getArch() == llvm::Triple::x86)
858 return;
859
860 ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true);
861
862 if ((runtime.hasNativeARC() || !isObjCAutoRefCount(Args)) &&
863 runtime.hasSubscripting())
864 return;
865
866 CmdArgs.push_back("-force_load");
867 SmallString<128> P(getDriver().ClangExecutable);
868 llvm::sys::path::remove_filename(P); // 'clang'
869 llvm::sys::path::remove_filename(P); // 'bin'
870 llvm::sys::path::append(P, "lib", "arc", "libarclite_");
871 // Mash in the platform.
872 if (isTargetWatchOSSimulator())
873 P += "watchsimulator";
874 else if (isTargetWatchOS())
875 P += "watchos";
876 else if (isTargetTvOSSimulator())
877 P += "appletvsimulator";
878 else if (isTargetTvOS())
879 P += "appletvos";
880 else if (isTargetIOSSimulator())
881 P += "iphonesimulator";
882 else if (isTargetIPhoneOS())
883 P += "iphoneos";
884 else
885 P += "macosx";
886 P += ".a";
887
888 CmdArgs.push_back(Args.MakeArgString(P));
889}
890
891unsigned DarwinClang::GetDefaultDwarfVersion() const {
892 // Default to use DWARF 2 on OS X 10.10 / iOS 8 and lower.
893 if ((isTargetMacOS() && isMacosxVersionLT(10, 11)) ||
894 (isTargetIOSBased() && isIPhoneOSVersionLT(9)))
895 return 2;
896 return 4;
897}
898
899void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
900 StringRef DarwinLibName, bool AlwaysLink,
901 bool IsEmbedded, bool AddRPath) const {
902 SmallString<128> Dir(getDriver().ResourceDir);
903 llvm::sys::path::append(Dir, "lib", IsEmbedded ? "macho_embedded" : "darwin");
904
905 SmallString<128> P(Dir);
906 llvm::sys::path::append(P, DarwinLibName);
907
908 // For now, allow missing resource libraries to support developers who may
909 // not have compiler-rt checked out or integrated into their build (unless
910 // we explicitly force linking with this library).
911 if (AlwaysLink || getVFS().exists(P))
912 CmdArgs.push_back(Args.MakeArgString(P));
913
914 // Adding the rpaths might negatively interact when other rpaths are involved,
915 // so we should make sure we add the rpaths last, after all user-specified
916 // rpaths. This is currently true from this place, but we need to be
917 // careful if this function is ever called before user's rpaths are emitted.
918 if (AddRPath) {
919 assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library");
920
921 // Add @executable_path to rpath to support having the dylib copied with
922 // the executable.
923 CmdArgs.push_back("-rpath");
924 CmdArgs.push_back("@executable_path");
925
926 // Add the path to the resource dir to rpath to support using the dylib
927 // from the default location without copying.
928 CmdArgs.push_back("-rpath");
929 CmdArgs.push_back(Args.MakeArgString(Dir));
930 }
931}
932
933StringRef Darwin::getPlatformFamily() const {
934 switch (TargetPlatform) {
935 case DarwinPlatformKind::MacOS:
936 return "MacOSX";
937 case DarwinPlatformKind::IPhoneOS:
938 case DarwinPlatformKind::IPhoneOSSimulator:
939 return "iPhone";
940 case DarwinPlatformKind::TvOS:
941 case DarwinPlatformKind::TvOSSimulator:
942 return "AppleTV";
943 case DarwinPlatformKind::WatchOS:
944 case DarwinPlatformKind::WatchOSSimulator:
945 return "Watch";
946 }
947 llvm_unreachable("Unsupported platform");
948}
949
950StringRef Darwin::getSDKName(StringRef isysroot) {
951 // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk
952 llvm::sys::path::const_iterator SDKDir;
953 auto BeginSDK = llvm::sys::path::begin(isysroot);
954 auto EndSDK = llvm::sys::path::end(isysroot);
955 for (auto IT = BeginSDK; IT != EndSDK; ++IT) {
956 StringRef SDK = *IT;
957 if (SDK.endswith(".sdk"))
958 return SDK.slice(0, SDK.size() - 4);
959 }
960 return "";
961}
962
963StringRef Darwin::getOSLibraryNameSuffix() const {
964 switch(TargetPlatform) {
965 case DarwinPlatformKind::MacOS:
966 return "osx";
967 case DarwinPlatformKind::IPhoneOS:
968 return "ios";
969 case DarwinPlatformKind::IPhoneOSSimulator:
970 return "iossim";
971 case DarwinPlatformKind::TvOS:
972 return "tvos";
973 case DarwinPlatformKind::TvOSSimulator:
974 return "tvossim";
975 case DarwinPlatformKind::WatchOS:
976 return "watchos";
977 case DarwinPlatformKind::WatchOSSimulator:
978 return "watchossim";
979 }
980 llvm_unreachable("Unsupported platform");
981}
982
983void Darwin::addProfileRTLibs(const ArgList &Args,
984 ArgStringList &CmdArgs) const {
985 if (!needsProfileRT(Args)) return;
986
987 AddLinkRuntimeLib(Args, CmdArgs, (Twine("libclang_rt.profile_") +
988 getOSLibraryNameSuffix() + ".a").str(),
989 /*AlwaysLink*/ true);
990}
991
992void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args,
993 ArgStringList &CmdArgs,
George Karpenkov9f6f74c2017-08-21 23:25:19 +0000994 StringRef Sanitizer,
995 bool Shared) const {
David L. Jonesf561aba2017-03-08 01:02:16 +0000996 AddLinkRuntimeLib(
997 Args, CmdArgs,
998 (Twine("libclang_rt.") + Sanitizer + "_" +
George Karpenkov9f6f74c2017-08-21 23:25:19 +0000999 getOSLibraryNameSuffix() + (Shared ? "_dynamic.dylib" : ".a")).str(),
David L. Jonesf561aba2017-03-08 01:02:16 +00001000 /*AlwaysLink*/ true, /*IsEmbedded*/ false,
George Karpenkov5509c732017-08-22 02:10:53 +00001001 /*AddRPath*/ Shared);
David L. Jonesf561aba2017-03-08 01:02:16 +00001002}
1003
1004ToolChain::RuntimeLibType DarwinClang::GetRuntimeLibType(
1005 const ArgList &Args) const {
1006 if (Arg* A = Args.getLastArg(options::OPT_rtlib_EQ)) {
1007 StringRef Value = A->getValue();
1008 if (Value != "compiler-rt")
1009 getDriver().Diag(clang::diag::err_drv_unsupported_rtlib_for_platform)
1010 << Value << "darwin";
1011 }
1012
1013 return ToolChain::RLT_CompilerRT;
1014}
1015
1016void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
1017 ArgStringList &CmdArgs) const {
1018 // Call once to ensure diagnostic is printed if wrong value was specified
1019 GetRuntimeLibType(Args);
1020
1021 // Darwin doesn't support real static executables, don't link any runtime
1022 // libraries with -static.
1023 if (Args.hasArg(options::OPT_static) ||
1024 Args.hasArg(options::OPT_fapple_kext) ||
1025 Args.hasArg(options::OPT_mkernel))
1026 return;
1027
1028 // Reject -static-libgcc for now, we can deal with this when and if someone
1029 // cares. This is useful in situations where someone wants to statically link
1030 // something like libstdc++, and needs its runtime support routines.
1031 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
1032 getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args);
1033 return;
1034 }
1035
1036 const SanitizerArgs &Sanitize = getSanitizerArgs();
1037 if (Sanitize.needsAsanRt())
1038 AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
Francis Ricci8e63e542017-04-20 21:11:51 +00001039 if (Sanitize.needsLsanRt())
1040 AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
David L. Jonesf561aba2017-03-08 01:02:16 +00001041 if (Sanitize.needsUbsanRt())
1042 AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan");
1043 if (Sanitize.needsTsanRt())
1044 AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
George Karpenkov9f6f74c2017-08-21 23:25:19 +00001045 if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
1046 AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
1047
1048 // Libfuzzer is written in C++ and requires libcxx.
1049 AddCXXStdlibLibArgs(Args, CmdArgs);
1050 }
David L. Jonesf561aba2017-03-08 01:02:16 +00001051 if (Sanitize.needsStatsRt()) {
1052 StringRef OS = isTargetMacOS() ? "osx" : "iossim";
1053 AddLinkRuntimeLib(Args, CmdArgs,
1054 (Twine("libclang_rt.stats_client_") + OS + ".a").str(),
1055 /*AlwaysLink=*/true);
1056 AddLinkSanitizerLibArgs(Args, CmdArgs, "stats");
1057 }
1058 if (Sanitize.needsEsanRt())
1059 AddLinkSanitizerLibArgs(Args, CmdArgs, "esan");
1060
1061 // Otherwise link libSystem, then the dynamic runtime library, and finally any
1062 // target specific static runtime library.
1063 CmdArgs.push_back("-lSystem");
1064
1065 // Select the dynamic runtime library and the target specific static library.
1066 if (isTargetWatchOSBased()) {
1067 // We currently always need a static runtime library for watchOS.
1068 AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.watchos.a");
1069 } else if (isTargetTvOSBased()) {
1070 // We currently always need a static runtime library for tvOS.
1071 AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.tvos.a");
1072 } else if (isTargetIOSBased()) {
1073 // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1,
1074 // it never went into the SDK.
1075 // Linking against libgcc_s.1 isn't needed for iOS 5.0+
1076 if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
1077 getTriple().getArch() != llvm::Triple::aarch64)
1078 CmdArgs.push_back("-lgcc_s.1");
1079
1080 // We currently always need a static runtime library for iOS.
1081 AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ios.a");
1082 } else {
1083 assert(isTargetMacOS() && "unexpected non MacOS platform");
1084 // The dynamic runtime library was merged with libSystem for 10.6 and
1085 // beyond; only 10.4 and 10.5 need an additional runtime library.
1086 if (isMacosxVersionLT(10, 5))
1087 CmdArgs.push_back("-lgcc_s.10.4");
1088 else if (isMacosxVersionLT(10, 6))
1089 CmdArgs.push_back("-lgcc_s.10.5");
1090
1091 // Originally for OS X, we thought we would only need a static runtime
1092 // library when targeting 10.4, to provide versions of the static functions
1093 // which were omitted from 10.4.dylib. This led to the creation of the 10.4
1094 // builtins library.
1095 //
1096 // Unfortunately, that turned out to not be true, because Darwin system
1097 // headers can still use eprintf on i386, and it is not exported from
1098 // libSystem. Therefore, we still must provide a runtime library just for
1099 // the tiny tiny handful of projects that *might* use that symbol.
1100 //
1101 // Then over time, we figured out it was useful to add more things to the
1102 // runtime so we created libclang_rt.osx.a to provide new functions when
1103 // deploying to old OS builds, and for a long time we had both eprintf and
1104 // osx builtin libraries. Which just seems excessive. So with PR 28855, we
1105 // are removing the eprintf library and expecting eprintf to be provided by
1106 // the OS X builtins library.
1107 if (isMacosxVersionLT(10, 5))
1108 AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.10.4.a");
1109 else
1110 AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.osx.a");
1111 }
1112}
1113
Alex Lorenzb249c9b2017-07-07 10:41:19 +00001114/// Returns the most appropriate macOS target version for the current process.
1115///
1116/// If the macOS SDK version is the same or earlier than the system version,
1117/// then the SDK version is returned. Otherwise the system version is returned.
1118static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) {
1119 unsigned Major, Minor, Micro;
1120 llvm::Triple SystemTriple(llvm::sys::getProcessTriple());
1121 if (!SystemTriple.isMacOSX())
1122 return MacOSSDKVersion;
1123 SystemTriple.getMacOSXVersion(Major, Minor, Micro);
1124 VersionTuple SystemVersion(Major, Minor, Micro);
1125 bool HadExtra;
1126 if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro,
1127 HadExtra))
1128 return MacOSSDKVersion;
1129 VersionTuple SDKVersion(Major, Minor, Micro);
1130 if (SDKVersion > SystemVersion)
1131 return SystemVersion.getAsString();
1132 return MacOSSDKVersion;
1133}
1134
David L. Jonesf561aba2017-03-08 01:02:16 +00001135void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
1136 const OptTable &Opts = getDriver().getOpts();
1137
1138 // Support allowing the SDKROOT environment variable used by xcrun and other
1139 // Xcode tools to define the default sysroot, by making it the default for
1140 // isysroot.
1141 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
1142 // Warn if the path does not exist.
1143 if (!getVFS().exists(A->getValue()))
1144 getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
1145 } else {
1146 if (char *env = ::getenv("SDKROOT")) {
1147 // We only use this value as the default if it is an absolute path,
1148 // exists, and it is not the root path.
1149 if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
1150 StringRef(env) != "/") {
1151 Args.append(Args.MakeSeparateArg(
1152 nullptr, Opts.getOption(options::OPT_isysroot), env));
1153 }
1154 }
1155 }
1156
1157 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
Akira Hatanakaf86ded22017-03-15 18:04:13 +00001158 Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
1159 options::OPT_mios_simulator_version_min_EQ);
1160 Arg *TvOSVersion =
1161 Args.getLastArg(options::OPT_mtvos_version_min_EQ,
1162 options::OPT_mtvos_simulator_version_min_EQ);
1163 Arg *WatchOSVersion =
1164 Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
1165 options::OPT_mwatchos_simulator_version_min_EQ);
1166
Akira Hatanakadc9d8fb2017-07-01 00:57:52 +00001167 unsigned Major, Minor, Micro;
1168 bool HadExtra;
1169
Akira Hatanaka4a94d8d2017-07-31 22:19:34 +00001170 // The iOS deployment target that is explicitly specified via a command line
1171 // option or an environment variable.
1172 std::string ExplicitIOSDeploymentTargetStr;
1173
1174 if (iOSVersion)
1175 ExplicitIOSDeploymentTargetStr = iOSVersion->getAsString(Args);
Akira Hatanakadc9d8fb2017-07-01 00:57:52 +00001176
Akira Hatanakaf86ded22017-03-15 18:04:13 +00001177 // Add a macro to differentiate between m(iphone|tv|watch)os-version-min=X.Y and
1178 // -m(iphone|tv|watch)simulator-version-min=X.Y.
1179 if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ) ||
1180 Args.hasArg(options::OPT_mtvos_simulator_version_min_EQ) ||
1181 Args.hasArg(options::OPT_mwatchos_simulator_version_min_EQ))
1182 Args.append(Args.MakeSeparateArg(nullptr, Opts.getOption(options::OPT_D),
1183 " __APPLE_EMBEDDED_SIMULATOR__=1"));
David L. Jonesf561aba2017-03-08 01:02:16 +00001184
1185 if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) {
1186 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
1187 << OSXVersion->getAsString(Args)
1188 << (iOSVersion ? iOSVersion :
1189 TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args);
1190 iOSVersion = TvOSVersion = WatchOSVersion = nullptr;
1191 } else if (iOSVersion && (TvOSVersion || WatchOSVersion)) {
1192 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
1193 << iOSVersion->getAsString(Args)
1194 << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args);
1195 TvOSVersion = WatchOSVersion = nullptr;
1196 } else if (TvOSVersion && WatchOSVersion) {
1197 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
1198 << TvOSVersion->getAsString(Args)
1199 << WatchOSVersion->getAsString(Args);
1200 WatchOSVersion = nullptr;
1201 } else if (!OSXVersion && !iOSVersion && !TvOSVersion && !WatchOSVersion) {
1202 // If no deployment target was specified on the command line, check for
1203 // environment defines.
1204 std::string OSXTarget;
1205 std::string iOSTarget;
1206 std::string TvOSTarget;
1207 std::string WatchOSTarget;
1208
1209 if (char *env = ::getenv("MACOSX_DEPLOYMENT_TARGET"))
1210 OSXTarget = env;
1211 if (char *env = ::getenv("IPHONEOS_DEPLOYMENT_TARGET"))
1212 iOSTarget = env;
1213 if (char *env = ::getenv("TVOS_DEPLOYMENT_TARGET"))
1214 TvOSTarget = env;
1215 if (char *env = ::getenv("WATCHOS_DEPLOYMENT_TARGET"))
1216 WatchOSTarget = env;
1217
Akira Hatanaka4a94d8d2017-07-31 22:19:34 +00001218 if (!iOSTarget.empty())
1219 ExplicitIOSDeploymentTargetStr =
1220 std::string("IPHONEOS_DEPLOYMENT_TARGET=") + iOSTarget;
Akira Hatanakadc9d8fb2017-07-01 00:57:52 +00001221
David L. Jonesf561aba2017-03-08 01:02:16 +00001222 // If there is no command-line argument to specify the Target version and
1223 // no environment variable defined, see if we can set the default based
1224 // on -isysroot.
1225 if (OSXTarget.empty() && iOSTarget.empty() && WatchOSTarget.empty() &&
1226 TvOSTarget.empty() && Args.hasArg(options::OPT_isysroot)) {
1227 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
1228 StringRef isysroot = A->getValue();
1229 StringRef SDK = getSDKName(isysroot);
1230 if (SDK.size() > 0) {
1231 // Slice the version number out.
1232 // Version number is between the first and the last number.
1233 size_t StartVer = SDK.find_first_of("0123456789");
1234 size_t EndVer = SDK.find_last_of("0123456789");
1235 if (StartVer != StringRef::npos && EndVer > StartVer) {
1236 StringRef Version = SDK.slice(StartVer, EndVer + 1);
1237 if (SDK.startswith("iPhoneOS") ||
1238 SDK.startswith("iPhoneSimulator"))
1239 iOSTarget = Version;
1240 else if (SDK.startswith("MacOSX"))
Alex Lorenzb249c9b2017-07-07 10:41:19 +00001241 OSXTarget = getSystemOrSDKMacOSVersion(Version);
David L. Jonesf561aba2017-03-08 01:02:16 +00001242 else if (SDK.startswith("WatchOS") ||
1243 SDK.startswith("WatchSimulator"))
1244 WatchOSTarget = Version;
1245 else if (SDK.startswith("AppleTVOS") ||
1246 SDK.startswith("AppleTVSimulator"))
1247 TvOSTarget = Version;
1248 }
1249 }
1250 }
1251 }
1252
Akira Hatanaka136ec492017-07-14 00:21:32 +00001253 // If no OS targets have been specified, try to guess platform from -target
1254 // or arch name and compute the version from the triple.
David L. Jonesf561aba2017-03-08 01:02:16 +00001255 if (OSXTarget.empty() && iOSTarget.empty() && TvOSTarget.empty() &&
1256 WatchOSTarget.empty()) {
Akira Hatanaka136ec492017-07-14 00:21:32 +00001257 llvm::Triple::OSType OSTy = llvm::Triple::UnknownOS;
1258
1259 // Set the OSTy based on -target if -arch isn't present.
1260 if (Args.hasArg(options::OPT_target) && !Args.hasArg(options::OPT_arch)) {
1261 OSTy = getTriple().getOS();
1262 } else {
1263 StringRef MachOArchName = getMachOArchName(Args);
1264 if (MachOArchName == "armv7" || MachOArchName == "armv7s" ||
1265 MachOArchName == "arm64")
1266 OSTy = llvm::Triple::IOS;
1267 else if (MachOArchName == "armv7k")
1268 OSTy = llvm::Triple::WatchOS;
1269 else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" &&
1270 MachOArchName != "armv7em")
1271 OSTy = llvm::Triple::MacOSX;
1272 }
1273
1274
1275 if (OSTy != llvm::Triple::UnknownOS) {
1276 unsigned Major, Minor, Micro;
1277 std::string *OSTarget;
1278
1279 switch (OSTy) {
1280 case llvm::Triple::Darwin:
1281 case llvm::Triple::MacOSX:
1282 if (!getTriple().getMacOSXVersion(Major, Minor, Micro))
1283 getDriver().Diag(diag::err_drv_invalid_darwin_version)
1284 << getTriple().getOSName();
1285 OSTarget = &OSXTarget;
1286 break;
1287 case llvm::Triple::IOS:
1288 getTriple().getiOSVersion(Major, Minor, Micro);
1289 OSTarget = &iOSTarget;
1290 break;
1291 case llvm::Triple::TvOS:
1292 getTriple().getOSVersion(Major, Minor, Micro);
1293 OSTarget = &TvOSTarget;
1294 break;
1295 case llvm::Triple::WatchOS:
1296 getTriple().getWatchOSVersion(Major, Minor, Micro);
1297 OSTarget = &WatchOSTarget;
1298 break;
1299 default:
1300 llvm_unreachable("Unexpected OS type");
1301 break;
David L. Jonesf561aba2017-03-08 01:02:16 +00001302 }
Akira Hatanaka136ec492017-07-14 00:21:32 +00001303
1304 llvm::raw_string_ostream(*OSTarget) << Major << '.' << Minor << '.'
David L. Jonesf561aba2017-03-08 01:02:16 +00001305 << Micro;
1306 }
1307 }
1308
1309 // Do not allow conflicts with the watchOS target.
1310 if (!WatchOSTarget.empty() && (!iOSTarget.empty() || !TvOSTarget.empty())) {
1311 getDriver().Diag(diag::err_drv_conflicting_deployment_targets)
1312 << "WATCHOS_DEPLOYMENT_TARGET"
1313 << (!iOSTarget.empty() ? "IPHONEOS_DEPLOYMENT_TARGET" :
1314 "TVOS_DEPLOYMENT_TARGET");
1315 }
1316
1317 // Do not allow conflicts with the tvOS target.
1318 if (!TvOSTarget.empty() && !iOSTarget.empty()) {
1319 getDriver().Diag(diag::err_drv_conflicting_deployment_targets)
1320 << "TVOS_DEPLOYMENT_TARGET"
1321 << "IPHONEOS_DEPLOYMENT_TARGET";
1322 }
1323
1324 // Allow conflicts among OSX and iOS for historical reasons, but choose the
1325 // default platform.
1326 if (!OSXTarget.empty() && (!iOSTarget.empty() ||
1327 !WatchOSTarget.empty() ||
1328 !TvOSTarget.empty())) {
1329 if (getTriple().getArch() == llvm::Triple::arm ||
1330 getTriple().getArch() == llvm::Triple::aarch64 ||
1331 getTriple().getArch() == llvm::Triple::thumb)
1332 OSXTarget = "";
1333 else
1334 iOSTarget = WatchOSTarget = TvOSTarget = "";
1335 }
1336
1337 if (!OSXTarget.empty()) {
1338 const Option O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
1339 OSXVersion = Args.MakeJoinedArg(nullptr, O, OSXTarget);
1340 Args.append(OSXVersion);
1341 } else if (!iOSTarget.empty()) {
1342 const Option O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
1343 iOSVersion = Args.MakeJoinedArg(nullptr, O, iOSTarget);
1344 Args.append(iOSVersion);
1345 } else if (!TvOSTarget.empty()) {
1346 const Option O = Opts.getOption(options::OPT_mtvos_version_min_EQ);
1347 TvOSVersion = Args.MakeJoinedArg(nullptr, O, TvOSTarget);
1348 Args.append(TvOSVersion);
1349 } else if (!WatchOSTarget.empty()) {
1350 const Option O = Opts.getOption(options::OPT_mwatchos_version_min_EQ);
1351 WatchOSVersion = Args.MakeJoinedArg(nullptr, O, WatchOSTarget);
1352 Args.append(WatchOSVersion);
1353 }
1354 }
1355
1356 DarwinPlatformKind Platform;
1357 if (OSXVersion)
1358 Platform = MacOS;
1359 else if (iOSVersion)
1360 Platform = IPhoneOS;
1361 else if (TvOSVersion)
1362 Platform = TvOS;
1363 else if (WatchOSVersion)
1364 Platform = WatchOS;
1365 else
1366 llvm_unreachable("Unable to infer Darwin variant");
1367
1368 // Set the tool chain target information.
David L. Jonesf561aba2017-03-08 01:02:16 +00001369 if (Platform == MacOS) {
1370 assert((!iOSVersion && !TvOSVersion && !WatchOSVersion) &&
1371 "Unknown target platform!");
1372 if (!Driver::GetReleaseVersion(OSXVersion->getValue(), Major, Minor, Micro,
1373 HadExtra) ||
1374 HadExtra || Major != 10 || Minor >= 100 || Micro >= 100)
1375 getDriver().Diag(diag::err_drv_invalid_version_number)
1376 << OSXVersion->getAsString(Args);
1377 } else if (Platform == IPhoneOS) {
1378 assert(iOSVersion && "Unknown target platform!");
1379 if (!Driver::GetReleaseVersion(iOSVersion->getValue(), Major, Minor, Micro,
1380 HadExtra) ||
1381 HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)
1382 getDriver().Diag(diag::err_drv_invalid_version_number)
1383 << iOSVersion->getAsString(Args);
Akira Hatanaka4a94d8d2017-07-31 22:19:34 +00001384 // For 32-bit targets, the deployment target for iOS has to be earlier than
1385 // iOS 11.
1386 if (getTriple().isArch32Bit() && Major >= 11) {
1387 // If the deployment target is explicitly specified, print a diagnostic.
1388 if (!ExplicitIOSDeploymentTargetStr.empty()) {
1389 getDriver().Diag(diag::warn_invalid_ios_deployment_target)
1390 << ExplicitIOSDeploymentTargetStr;
1391 // Otherwise, set it to 10.99.99.
1392 } else {
1393 Major = 10;
1394 Minor = 99;
1395 Micro = 99;
1396 }
1397 }
David L. Jonesf561aba2017-03-08 01:02:16 +00001398 } else if (Platform == TvOS) {
1399 if (!Driver::GetReleaseVersion(TvOSVersion->getValue(), Major, Minor,
1400 Micro, HadExtra) || HadExtra ||
1401 Major >= 100 || Minor >= 100 || Micro >= 100)
1402 getDriver().Diag(diag::err_drv_invalid_version_number)
1403 << TvOSVersion->getAsString(Args);
1404 } else if (Platform == WatchOS) {
1405 if (!Driver::GetReleaseVersion(WatchOSVersion->getValue(), Major, Minor,
1406 Micro, HadExtra) || HadExtra ||
1407 Major >= 10 || Minor >= 100 || Micro >= 100)
1408 getDriver().Diag(diag::err_drv_invalid_version_number)
1409 << WatchOSVersion->getAsString(Args);
1410 } else
1411 llvm_unreachable("unknown kind of Darwin platform");
1412
1413 // Recognize iOS targets with an x86 architecture as the iOS simulator.
1414 if (iOSVersion && (getTriple().getArch() == llvm::Triple::x86 ||
1415 getTriple().getArch() == llvm::Triple::x86_64))
1416 Platform = IPhoneOSSimulator;
1417 if (TvOSVersion && (getTriple().getArch() == llvm::Triple::x86 ||
1418 getTriple().getArch() == llvm::Triple::x86_64))
1419 Platform = TvOSSimulator;
1420 if (WatchOSVersion && (getTriple().getArch() == llvm::Triple::x86 ||
1421 getTriple().getArch() == llvm::Triple::x86_64))
1422 Platform = WatchOSSimulator;
1423
1424 setTarget(Platform, Major, Minor, Micro);
1425
1426 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
1427 StringRef SDK = getSDKName(A->getValue());
1428 if (SDK.size() > 0) {
1429 size_t StartVer = SDK.find_first_of("0123456789");
1430 StringRef SDKName = SDK.slice(0, StartVer);
1431 if (!SDKName.startswith(getPlatformFamily()))
1432 getDriver().Diag(diag::warn_incompatible_sysroot)
1433 << SDKName << getPlatformFamily();
1434 }
1435 }
1436}
1437
1438void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args,
1439 ArgStringList &CmdArgs) const {
1440 CXXStdlibType Type = GetCXXStdlibType(Args);
1441
1442 switch (Type) {
1443 case ToolChain::CST_Libcxx:
1444 CmdArgs.push_back("-lc++");
1445 break;
1446
1447 case ToolChain::CST_Libstdcxx:
1448 // Unfortunately, -lstdc++ doesn't always exist in the standard search path;
1449 // it was previously found in the gcc lib dir. However, for all the Darwin
1450 // platforms we care about it was -lstdc++.6, so we search for that
1451 // explicitly if we can't see an obvious -lstdc++ candidate.
1452
1453 // Check in the sysroot first.
1454 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
1455 SmallString<128> P(A->getValue());
1456 llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib");
1457
1458 if (!getVFS().exists(P)) {
1459 llvm::sys::path::remove_filename(P);
1460 llvm::sys::path::append(P, "libstdc++.6.dylib");
1461 if (getVFS().exists(P)) {
1462 CmdArgs.push_back(Args.MakeArgString(P));
1463 return;
1464 }
1465 }
1466 }
1467
1468 // Otherwise, look in the root.
1469 // FIXME: This should be removed someday when we don't have to care about
1470 // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist.
1471 if (!getVFS().exists("/usr/lib/libstdc++.dylib") &&
1472 getVFS().exists("/usr/lib/libstdc++.6.dylib")) {
1473 CmdArgs.push_back("/usr/lib/libstdc++.6.dylib");
1474 return;
1475 }
1476
1477 // Otherwise, let the linker search.
1478 CmdArgs.push_back("-lstdc++");
1479 break;
1480 }
1481}
1482
1483void DarwinClang::AddCCKextLibArgs(const ArgList &Args,
1484 ArgStringList &CmdArgs) const {
1485 // For Darwin platforms, use the compiler-rt-based support library
1486 // instead of the gcc-provided one (which is also incidentally
1487 // only present in the gcc lib dir, which makes it hard to find).
1488
1489 SmallString<128> P(getDriver().ResourceDir);
1490 llvm::sys::path::append(P, "lib", "darwin");
1491
1492 // Use the newer cc_kext for iOS ARM after 6.0.
1493 if (isTargetWatchOS()) {
1494 llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a");
1495 } else if (isTargetTvOS()) {
1496 llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a");
1497 } else if (isTargetIPhoneOS()) {
1498 llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a");
1499 } else {
1500 llvm::sys::path::append(P, "libclang_rt.cc_kext.a");
1501 }
1502
1503 // For now, allow missing resource libraries to support developers who may
1504 // not have compiler-rt checked out or integrated into their build.
1505 if (getVFS().exists(P))
1506 CmdArgs.push_back(Args.MakeArgString(P));
1507}
1508
1509DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args,
1510 StringRef BoundArch,
1511 Action::OffloadKind) const {
1512 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
1513 const OptTable &Opts = getDriver().getOpts();
1514
1515 // FIXME: We really want to get out of the tool chain level argument
1516 // translation business, as it makes the driver functionality much
1517 // more opaque. For now, we follow gcc closely solely for the
1518 // purpose of easily achieving feature parity & testability. Once we
1519 // have something that works, we should reevaluate each translation
1520 // and try to push it down into tool specific logic.
1521
1522 for (Arg *A : Args) {
1523 if (A->getOption().matches(options::OPT_Xarch__)) {
1524 // Skip this argument unless the architecture matches either the toolchain
1525 // triple arch, or the arch being bound.
1526 llvm::Triple::ArchType XarchArch =
1527 tools::darwin::getArchTypeForMachOArchName(A->getValue(0));
1528 if (!(XarchArch == getArch() ||
1529 (!BoundArch.empty() &&
1530 XarchArch ==
1531 tools::darwin::getArchTypeForMachOArchName(BoundArch))))
1532 continue;
1533
1534 Arg *OriginalArg = A;
1535 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
1536 unsigned Prev = Index;
1537 std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index));
1538
1539 // If the argument parsing failed or more than one argument was
1540 // consumed, the -Xarch_ argument's parameter tried to consume
1541 // extra arguments. Emit an error and ignore.
1542 //
1543 // We also want to disallow any options which would alter the
1544 // driver behavior; that isn't going to work in our model. We
1545 // use isDriverOption() as an approximation, although things
1546 // like -O4 are going to slip through.
1547 if (!XarchArg || Index > Prev + 1) {
1548 getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args)
1549 << A->getAsString(Args);
1550 continue;
1551 } else if (XarchArg->getOption().hasFlag(options::DriverOption)) {
1552 getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver)
1553 << A->getAsString(Args);
1554 continue;
1555 }
1556
1557 XarchArg->setBaseArg(A);
1558
1559 A = XarchArg.release();
1560 DAL->AddSynthesizedArg(A);
1561
1562 // Linker input arguments require custom handling. The problem is that we
1563 // have already constructed the phase actions, so we can not treat them as
1564 // "input arguments".
1565 if (A->getOption().hasFlag(options::LinkerInput)) {
1566 // Convert the argument into individual Zlinker_input_args.
1567 for (const char *Value : A->getValues()) {
1568 DAL->AddSeparateArg(
1569 OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value);
1570 }
1571 continue;
1572 }
1573 }
1574
1575 // Sob. These is strictly gcc compatible for the time being. Apple
1576 // gcc translates options twice, which means that self-expanding
1577 // options add duplicates.
1578 switch ((options::ID)A->getOption().getID()) {
1579 default:
1580 DAL->append(A);
1581 break;
1582
1583 case options::OPT_mkernel:
1584 case options::OPT_fapple_kext:
1585 DAL->append(A);
1586 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
1587 break;
1588
1589 case options::OPT_dependency_file:
1590 DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue());
1591 break;
1592
1593 case options::OPT_gfull:
1594 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
1595 DAL->AddFlagArg(
1596 A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols));
1597 break;
1598
1599 case options::OPT_gused:
1600 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
1601 DAL->AddFlagArg(
1602 A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols));
1603 break;
1604
1605 case options::OPT_shared:
1606 DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib));
1607 break;
1608
1609 case options::OPT_fconstant_cfstrings:
1610 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings));
1611 break;
1612
1613 case options::OPT_fno_constant_cfstrings:
1614 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings));
1615 break;
1616
1617 case options::OPT_Wnonportable_cfstrings:
1618 DAL->AddFlagArg(A,
1619 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings));
1620 break;
1621
1622 case options::OPT_Wno_nonportable_cfstrings:
1623 DAL->AddFlagArg(
1624 A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings));
1625 break;
1626
1627 case options::OPT_fpascal_strings:
1628 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings));
1629 break;
1630
1631 case options::OPT_fno_pascal_strings:
1632 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings));
1633 break;
1634 }
1635 }
1636
1637 if (getTriple().getArch() == llvm::Triple::x86 ||
1638 getTriple().getArch() == llvm::Triple::x86_64)
1639 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
1640 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ),
1641 "core2");
1642
1643 // Add the arch options based on the particular spelling of -arch, to match
1644 // how the driver driver works.
1645 if (!BoundArch.empty()) {
1646 StringRef Name = BoundArch;
1647 const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ);
1648 const Option MArch = Opts.getOption(clang::driver::options::OPT_march_EQ);
1649
1650 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
1651 // which defines the list of which architectures we accept.
1652 if (Name == "ppc")
1653 ;
1654 else if (Name == "ppc601")
1655 DAL->AddJoinedArg(nullptr, MCpu, "601");
1656 else if (Name == "ppc603")
1657 DAL->AddJoinedArg(nullptr, MCpu, "603");
1658 else if (Name == "ppc604")
1659 DAL->AddJoinedArg(nullptr, MCpu, "604");
1660 else if (Name == "ppc604e")
1661 DAL->AddJoinedArg(nullptr, MCpu, "604e");
1662 else if (Name == "ppc750")
1663 DAL->AddJoinedArg(nullptr, MCpu, "750");
1664 else if (Name == "ppc7400")
1665 DAL->AddJoinedArg(nullptr, MCpu, "7400");
1666 else if (Name == "ppc7450")
1667 DAL->AddJoinedArg(nullptr, MCpu, "7450");
1668 else if (Name == "ppc970")
1669 DAL->AddJoinedArg(nullptr, MCpu, "970");
1670
1671 else if (Name == "ppc64" || Name == "ppc64le")
1672 DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64));
1673
1674 else if (Name == "i386")
1675 ;
1676 else if (Name == "i486")
1677 DAL->AddJoinedArg(nullptr, MArch, "i486");
1678 else if (Name == "i586")
1679 DAL->AddJoinedArg(nullptr, MArch, "i586");
1680 else if (Name == "i686")
1681 DAL->AddJoinedArg(nullptr, MArch, "i686");
1682 else if (Name == "pentium")
1683 DAL->AddJoinedArg(nullptr, MArch, "pentium");
1684 else if (Name == "pentium2")
1685 DAL->AddJoinedArg(nullptr, MArch, "pentium2");
1686 else if (Name == "pentpro")
1687 DAL->AddJoinedArg(nullptr, MArch, "pentiumpro");
1688 else if (Name == "pentIIm3")
1689 DAL->AddJoinedArg(nullptr, MArch, "pentium2");
1690
1691 else if (Name == "x86_64")
1692 DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64));
1693 else if (Name == "x86_64h") {
1694 DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64));
1695 DAL->AddJoinedArg(nullptr, MArch, "x86_64h");
1696 }
1697
1698 else if (Name == "arm")
1699 DAL->AddJoinedArg(nullptr, MArch, "armv4t");
1700 else if (Name == "armv4t")
1701 DAL->AddJoinedArg(nullptr, MArch, "armv4t");
1702 else if (Name == "armv5")
1703 DAL->AddJoinedArg(nullptr, MArch, "armv5tej");
1704 else if (Name == "xscale")
1705 DAL->AddJoinedArg(nullptr, MArch, "xscale");
1706 else if (Name == "armv6")
1707 DAL->AddJoinedArg(nullptr, MArch, "armv6k");
1708 else if (Name == "armv6m")
1709 DAL->AddJoinedArg(nullptr, MArch, "armv6m");
1710 else if (Name == "armv7")
1711 DAL->AddJoinedArg(nullptr, MArch, "armv7a");
1712 else if (Name == "armv7em")
1713 DAL->AddJoinedArg(nullptr, MArch, "armv7em");
1714 else if (Name == "armv7k")
1715 DAL->AddJoinedArg(nullptr, MArch, "armv7k");
1716 else if (Name == "armv7m")
1717 DAL->AddJoinedArg(nullptr, MArch, "armv7m");
1718 else if (Name == "armv7s")
1719 DAL->AddJoinedArg(nullptr, MArch, "armv7s");
1720 }
1721
1722 return DAL;
1723}
1724
1725void MachO::AddLinkRuntimeLibArgs(const ArgList &Args,
1726 ArgStringList &CmdArgs) const {
1727 // Embedded targets are simple at the moment, not supporting sanitizers and
1728 // with different libraries for each member of the product { static, PIC } x
1729 // { hard-float, soft-float }
1730 llvm::SmallString<32> CompilerRT = StringRef("libclang_rt.");
1731 CompilerRT +=
1732 (tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard)
1733 ? "hard"
1734 : "soft";
1735 CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic.a" : "_static.a";
1736
1737 AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, false, true);
1738}
1739
Akira Hatanakacae83f72017-06-29 18:48:40 +00001740bool Darwin::isAlignedAllocationUnavailable() const {
Akira Hatanaka3e40c302017-07-19 17:17:50 +00001741 llvm::Triple::OSType OS;
1742
Akira Hatanakacae83f72017-06-29 18:48:40 +00001743 switch (TargetPlatform) {
1744 case MacOS: // Earlier than 10.13.
Akira Hatanaka3e40c302017-07-19 17:17:50 +00001745 OS = llvm::Triple::MacOSX;
1746 break;
Akira Hatanakacae83f72017-06-29 18:48:40 +00001747 case IPhoneOS:
1748 case IPhoneOSSimulator:
Akira Hatanaka3e40c302017-07-19 17:17:50 +00001749 OS = llvm::Triple::IOS;
1750 break;
Akira Hatanakacae83f72017-06-29 18:48:40 +00001751 case TvOS:
1752 case TvOSSimulator: // Earlier than 11.0.
Akira Hatanaka3e40c302017-07-19 17:17:50 +00001753 OS = llvm::Triple::TvOS;
1754 break;
Akira Hatanakacae83f72017-06-29 18:48:40 +00001755 case WatchOS:
1756 case WatchOSSimulator: // Earlier than 4.0.
Akira Hatanaka3e40c302017-07-19 17:17:50 +00001757 OS = llvm::Triple::WatchOS;
1758 break;
Akira Hatanakacae83f72017-06-29 18:48:40 +00001759 }
Akira Hatanaka3e40c302017-07-19 17:17:50 +00001760
1761 return TargetVersion < alignedAllocMinVersion(OS);
Akira Hatanakacae83f72017-06-29 18:48:40 +00001762}
1763
1764void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
Gheorghe-Teodor Berceaf0f29602017-07-06 16:22:21 +00001765 llvm::opt::ArgStringList &CC1Args,
1766 Action::OffloadKind DeviceOffloadKind) const {
Akira Hatanakacae83f72017-06-29 18:48:40 +00001767 if (isAlignedAllocationUnavailable())
1768 CC1Args.push_back("-faligned-alloc-unavailable");
1769}
1770
David L. Jonesf561aba2017-03-08 01:02:16 +00001771DerivedArgList *
1772Darwin::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
1773 Action::OffloadKind DeviceOffloadKind) const {
1774 // First get the generic Apple args, before moving onto Darwin-specific ones.
1775 DerivedArgList *DAL =
1776 MachO::TranslateArgs(Args, BoundArch, DeviceOffloadKind);
1777 const OptTable &Opts = getDriver().getOpts();
1778
1779 // If no architecture is bound, none of the translations here are relevant.
1780 if (BoundArch.empty())
1781 return DAL;
1782
1783 // Add an explicit version min argument for the deployment target. We do this
1784 // after argument translation because -Xarch_ arguments may add a version min
1785 // argument.
1786 AddDeploymentTarget(*DAL);
1787
1788 // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext.
1789 // FIXME: It would be far better to avoid inserting those -static arguments,
1790 // but we can't check the deployment target in the translation code until
1791 // it is set here.
1792 if (isTargetWatchOSBased() ||
1793 (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) {
1794 for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) {
1795 Arg *A = *it;
1796 ++it;
1797 if (A->getOption().getID() != options::OPT_mkernel &&
1798 A->getOption().getID() != options::OPT_fapple_kext)
1799 continue;
1800 assert(it != ie && "unexpected argument translation");
1801 A = *it;
1802 assert(A->getOption().getID() == options::OPT_static &&
1803 "missing expected -static argument");
Richard Smithac65f642017-04-12 23:21:25 +00001804 *it = nullptr;
1805 ++it;
David L. Jonesf561aba2017-03-08 01:02:16 +00001806 }
1807 }
1808
1809 if (!Args.getLastArg(options::OPT_stdlib_EQ) &&
1810 GetCXXStdlibType(Args) == ToolChain::CST_Libcxx)
1811 DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ),
1812 "libc++");
1813
1814 // Validate the C++ standard library choice.
1815 CXXStdlibType Type = GetCXXStdlibType(*DAL);
1816 if (Type == ToolChain::CST_Libcxx) {
1817 // Check whether the target provides libc++.
1818 StringRef where;
1819
1820 // Complain about targeting iOS < 5.0 in any way.
1821 if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0))
1822 where = "iOS 5.0";
1823
1824 if (where != StringRef()) {
1825 getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where;
1826 }
1827 }
1828
1829 auto Arch = tools::darwin::getArchTypeForMachOArchName(BoundArch);
1830 if ((Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)) {
1831 if (Args.hasFlag(options::OPT_fomit_frame_pointer,
1832 options::OPT_fno_omit_frame_pointer, false))
1833 getDriver().Diag(clang::diag::warn_drv_unsupported_opt_for_target)
1834 << "-fomit-frame-pointer" << BoundArch;
1835 }
1836
1837 return DAL;
1838}
1839
Akira Hatanakab72e35a2017-08-03 23:55:42 +00001840bool MachO::IsUnwindTablesDefault(const ArgList &Args) const {
Akira Hatanakaa423cb42017-08-21 22:46:46 +00001841 // Unwind tables are not emitted if -fno-exceptions is supplied (except when
1842 // targeting x86_64).
1843 return getArch() == llvm::Triple::x86_64 ||
1844 (!UseSjLjExceptions(Args) &&
1845 Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
1846 true));
David L. Jonesf561aba2017-03-08 01:02:16 +00001847}
1848
1849bool MachO::UseDwarfDebugFlags() const {
1850 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
1851 return S[0] != '\0';
1852 return false;
1853}
1854
1855bool Darwin::UseSjLjExceptions(const ArgList &Args) const {
1856 // Darwin uses SjLj exceptions on ARM.
1857 if (getTriple().getArch() != llvm::Triple::arm &&
1858 getTriple().getArch() != llvm::Triple::thumb)
1859 return false;
1860
1861 // Only watchOS uses the new DWARF/Compact unwinding method.
1862 llvm::Triple Triple(ComputeLLVMTriple(Args));
1863 return !Triple.isWatchABI();
1864}
1865
1866bool Darwin::SupportsEmbeddedBitcode() const {
1867 assert(TargetInitialized && "Target not initialized!");
1868 if (isTargetIPhoneOS() && isIPhoneOSVersionLT(6, 0))
1869 return false;
1870 return true;
1871}
1872
1873bool MachO::isPICDefault() const { return true; }
1874
1875bool MachO::isPIEDefault() const { return false; }
1876
1877bool MachO::isPICDefaultForced() const {
1878 return (getArch() == llvm::Triple::x86_64 ||
1879 getArch() == llvm::Triple::aarch64);
1880}
1881
1882bool MachO::SupportsProfiling() const {
1883 // Profiling instrumentation is only supported on x86.
1884 return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64;
1885}
1886
1887void Darwin::addMinVersionArgs(const ArgList &Args,
1888 ArgStringList &CmdArgs) const {
1889 VersionTuple TargetVersion = getTargetVersion();
1890
1891 if (isTargetWatchOS())
1892 CmdArgs.push_back("-watchos_version_min");
1893 else if (isTargetWatchOSSimulator())
1894 CmdArgs.push_back("-watchos_simulator_version_min");
1895 else if (isTargetTvOS())
1896 CmdArgs.push_back("-tvos_version_min");
1897 else if (isTargetTvOSSimulator())
1898 CmdArgs.push_back("-tvos_simulator_version_min");
1899 else if (isTargetIOSSimulator())
1900 CmdArgs.push_back("-ios_simulator_version_min");
1901 else if (isTargetIOSBased())
1902 CmdArgs.push_back("-iphoneos_version_min");
1903 else {
1904 assert(isTargetMacOS() && "unexpected target");
1905 CmdArgs.push_back("-macosx_version_min");
1906 }
1907
1908 CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString()));
1909}
1910
1911void Darwin::addStartObjectFileArgs(const ArgList &Args,
1912 ArgStringList &CmdArgs) const {
1913 // Derived from startfile spec.
1914 if (Args.hasArg(options::OPT_dynamiclib)) {
1915 // Derived from darwin_dylib1 spec.
1916 if (isTargetWatchOSBased()) {
1917 ; // watchOS does not need dylib1.o.
1918 } else if (isTargetIOSSimulator()) {
1919 ; // iOS simulator does not need dylib1.o.
1920 } else if (isTargetIPhoneOS()) {
1921 if (isIPhoneOSVersionLT(3, 1))
1922 CmdArgs.push_back("-ldylib1.o");
1923 } else {
1924 if (isMacosxVersionLT(10, 5))
1925 CmdArgs.push_back("-ldylib1.o");
1926 else if (isMacosxVersionLT(10, 6))
1927 CmdArgs.push_back("-ldylib1.10.5.o");
1928 }
1929 } else {
1930 if (Args.hasArg(options::OPT_bundle)) {
1931 if (!Args.hasArg(options::OPT_static)) {
1932 // Derived from darwin_bundle1 spec.
1933 if (isTargetWatchOSBased()) {
1934 ; // watchOS does not need bundle1.o.
1935 } else if (isTargetIOSSimulator()) {
1936 ; // iOS simulator does not need bundle1.o.
1937 } else if (isTargetIPhoneOS()) {
1938 if (isIPhoneOSVersionLT(3, 1))
1939 CmdArgs.push_back("-lbundle1.o");
1940 } else {
1941 if (isMacosxVersionLT(10, 6))
1942 CmdArgs.push_back("-lbundle1.o");
1943 }
1944 }
1945 } else {
1946 if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) {
1947 if (Args.hasArg(options::OPT_static) ||
1948 Args.hasArg(options::OPT_object) ||
1949 Args.hasArg(options::OPT_preload)) {
1950 CmdArgs.push_back("-lgcrt0.o");
1951 } else {
1952 CmdArgs.push_back("-lgcrt1.o");
1953
1954 // darwin_crt2 spec is empty.
1955 }
1956 // By default on OS X 10.8 and later, we don't link with a crt1.o
1957 // file and the linker knows to use _main as the entry point. But,
1958 // when compiling with -pg, we need to link with the gcrt1.o file,
1959 // so pass the -no_new_main option to tell the linker to use the
1960 // "start" symbol as the entry point.
1961 if (isTargetMacOS() && !isMacosxVersionLT(10, 8))
1962 CmdArgs.push_back("-no_new_main");
1963 } else {
1964 if (Args.hasArg(options::OPT_static) ||
1965 Args.hasArg(options::OPT_object) ||
1966 Args.hasArg(options::OPT_preload)) {
1967 CmdArgs.push_back("-lcrt0.o");
1968 } else {
1969 // Derived from darwin_crt1 spec.
1970 if (isTargetWatchOSBased()) {
1971 ; // watchOS does not need crt1.o.
1972 } else if (isTargetIOSSimulator()) {
1973 ; // iOS simulator does not need crt1.o.
1974 } else if (isTargetIPhoneOS()) {
1975 if (getArch() == llvm::Triple::aarch64)
1976 ; // iOS does not need any crt1 files for arm64
1977 else if (isIPhoneOSVersionLT(3, 1))
1978 CmdArgs.push_back("-lcrt1.o");
1979 else if (isIPhoneOSVersionLT(6, 0))
1980 CmdArgs.push_back("-lcrt1.3.1.o");
1981 } else {
1982 if (isMacosxVersionLT(10, 5))
1983 CmdArgs.push_back("-lcrt1.o");
1984 else if (isMacosxVersionLT(10, 6))
1985 CmdArgs.push_back("-lcrt1.10.5.o");
1986 else if (isMacosxVersionLT(10, 8))
1987 CmdArgs.push_back("-lcrt1.10.6.o");
1988
1989 // darwin_crt2 spec is empty.
1990 }
1991 }
1992 }
1993 }
1994 }
1995
1996 if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) &&
1997 !isTargetWatchOS() &&
1998 isMacosxVersionLT(10, 5)) {
1999 const char *Str = Args.MakeArgString(GetFilePath("crt3.o"));
2000 CmdArgs.push_back(Str);
2001 }
2002}
2003
2004bool Darwin::SupportsObjCGC() const { return isTargetMacOS(); }
2005
2006void Darwin::CheckObjCARC() const {
2007 if (isTargetIOSBased() || isTargetWatchOSBased() ||
2008 (isTargetMacOS() && !isMacosxVersionLT(10, 6)))
2009 return;
2010 getDriver().Diag(diag::err_arc_unsupported_on_toolchain);
2011}
2012
2013SanitizerMask Darwin::getSupportedSanitizers() const {
2014 const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
2015 SanitizerMask Res = ToolChain::getSupportedSanitizers();
2016 Res |= SanitizerKind::Address;
Francis Ricci8e63e542017-04-20 21:11:51 +00002017 Res |= SanitizerKind::Leak;
George Karpenkovf2fc5b02017-04-24 18:23:24 +00002018 Res |= SanitizerKind::Fuzzer;
George Karpenkov33613f62017-08-11 17:22:58 +00002019 Res |= SanitizerKind::FuzzerNoLink;
David L. Jonesf561aba2017-03-08 01:02:16 +00002020 if (isTargetMacOS()) {
2021 if (!isMacosxVersionLT(10, 9))
2022 Res |= SanitizerKind::Vptr;
2023 Res |= SanitizerKind::SafeStack;
2024 if (IsX86_64)
2025 Res |= SanitizerKind::Thread;
2026 } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) {
2027 if (IsX86_64)
2028 Res |= SanitizerKind::Thread;
2029 }
2030 return Res;
2031}
2032
2033void Darwin::printVerboseInfo(raw_ostream &OS) const {
2034 CudaInstallation.print(OS);
2035}