clang  9.0.0svn
Darwin.cpp
Go to the documentation of this file.
1 //===--- Darwin.cpp - Darwin Tool and ToolChain Implementations -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "Darwin.h"
10 #include "Arch/ARM.h"
11 #include "CommonArgs.h"
15 #include "clang/Driver/Driver.h"
17 #include "clang/Driver/Options.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/Option/ArgList.h"
21 #include "llvm/Support/Path.h"
22 #include "llvm/Support/ScopedPrinter.h"
23 #include "llvm/Support/TargetParser.h"
24 #include "llvm/Support/VirtualFileSystem.h"
25 #include <cstdlib> // ::getenv
26 
27 using namespace clang::driver;
28 using namespace clang::driver::tools;
29 using namespace clang::driver::toolchains;
30 using namespace clang;
31 using namespace llvm::opt;
32 
33 llvm::Triple::ArchType darwin::getArchTypeForMachOArchName(StringRef Str) {
34  // See arch(3) and llvm-gcc's driver-driver.c. We don't implement support for
35  // archs which Darwin doesn't use.
36 
37  // The matching this routine does is fairly pointless, since it is neither the
38  // complete architecture list, nor a reasonable subset. The problem is that
39  // historically the driver driver accepts this and also ties its -march=
40  // handling to the architecture name, so we need to be careful before removing
41  // support for it.
42 
43  // This code must be kept in sync with Clang's Darwin specific argument
44  // translation.
45 
46  return llvm::StringSwitch<llvm::Triple::ArchType>(Str)
47  .Cases("ppc", "ppc601", "ppc603", "ppc604", "ppc604e", llvm::Triple::ppc)
48  .Cases("ppc750", "ppc7400", "ppc7450", "ppc970", llvm::Triple::ppc)
49  .Case("ppc64", llvm::Triple::ppc64)
50  .Cases("i386", "i486", "i486SX", "i586", "i686", llvm::Triple::x86)
51  .Cases("pentium", "pentpro", "pentIIm3", "pentIIm5", "pentium4",
52  llvm::Triple::x86)
53  .Cases("x86_64", "x86_64h", llvm::Triple::x86_64)
54  // This is derived from the driver driver.
55  .Cases("arm", "armv4t", "armv5", "armv6", "armv6m", llvm::Triple::arm)
56  .Cases("armv7", "armv7em", "armv7k", "armv7m", llvm::Triple::arm)
57  .Cases("armv7s", "xscale", llvm::Triple::arm)
58  .Case("arm64", llvm::Triple::aarch64)
59  .Case("r600", llvm::Triple::r600)
60  .Case("amdgcn", llvm::Triple::amdgcn)
61  .Case("nvptx", llvm::Triple::nvptx)
62  .Case("nvptx64", llvm::Triple::nvptx64)
63  .Case("amdil", llvm::Triple::amdil)
64  .Case("spir", llvm::Triple::spir)
65  .Default(llvm::Triple::UnknownArch);
66 }
67 
68 void darwin::setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str) {
69  const llvm::Triple::ArchType Arch = getArchTypeForMachOArchName(Str);
70  llvm::ARM::ArchKind ArchKind = llvm::ARM::parseArch(Str);
71  T.setArch(Arch);
72 
73  if (Str == "x86_64h")
74  T.setArchName(Str);
75  else if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
76  ArchKind == llvm::ARM::ArchKind::ARMV7M ||
77  ArchKind == llvm::ARM::ArchKind::ARMV7EM) {
78  T.setOS(llvm::Triple::UnknownOS);
79  T.setObjectFormat(llvm::Triple::MachO);
80  }
81 }
82 
84  const InputInfo &Output,
85  const InputInfoList &Inputs,
86  const ArgList &Args,
87  const char *LinkingOutput) const {
88  ArgStringList CmdArgs;
89 
90  assert(Inputs.size() == 1 && "Unexpected number of inputs.");
91  const InputInfo &Input = Inputs[0];
92 
93  // Determine the original source input.
94  const Action *SourceAction = &JA;
95  while (SourceAction->getKind() != Action::InputClass) {
96  assert(!SourceAction->getInputs().empty() && "unexpected root action!");
97  SourceAction = SourceAction->getInputs()[0];
98  }
99 
100  // If -fno-integrated-as is used add -Q to the darwin assembler driver to make
101  // sure it runs its system assembler not clang's integrated assembler.
102  // Applicable to darwin11+ and Xcode 4+. darwin<10 lacked integrated-as.
103  // FIXME: at run-time detect assembler capabilities or rely on version
104  // information forwarded by -target-assembler-version.
105  if (Args.hasArg(options::OPT_fno_integrated_as)) {
106  const llvm::Triple &T(getToolChain().getTriple());
107  if (!(T.isMacOSX() && T.isMacOSXVersionLT(10, 7)))
108  CmdArgs.push_back("-Q");
109  }
110 
111  // Forward -g, assuming we are dealing with an actual assembly file.
112  if (SourceAction->getType() == types::TY_Asm ||
113  SourceAction->getType() == types::TY_PP_Asm) {
114  if (Args.hasArg(options::OPT_gstabs))
115  CmdArgs.push_back("--gstabs");
116  else if (Args.hasArg(options::OPT_g_Group))
117  CmdArgs.push_back("-g");
118  }
119 
120  // Derived from asm spec.
121  AddMachOArch(Args, CmdArgs);
122 
123  // Use -force_cpusubtype_ALL on x86 by default.
124  if (getToolChain().getArch() == llvm::Triple::x86 ||
125  getToolChain().getArch() == llvm::Triple::x86_64 ||
126  Args.hasArg(options::OPT_force__cpusubtype__ALL))
127  CmdArgs.push_back("-force_cpusubtype_ALL");
128 
129  if (getToolChain().getArch() != llvm::Triple::x86_64 &&
130  (((Args.hasArg(options::OPT_mkernel) ||
131  Args.hasArg(options::OPT_fapple_kext)) &&
132  getMachOToolChain().isKernelStatic()) ||
133  Args.hasArg(options::OPT_static)))
134  CmdArgs.push_back("-static");
135 
136  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
137 
138  assert(Output.isFilename() && "Unexpected lipo output.");
139  CmdArgs.push_back("-o");
140  CmdArgs.push_back(Output.getFilename());
141 
142  assert(Input.isFilename() && "Invalid input.");
143  CmdArgs.push_back(Input.getFilename());
144 
145  // asm_final spec is empty.
146 
147  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
148  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
149 }
150 
151 void darwin::MachOTool::anchor() {}
152 
153 void darwin::MachOTool::AddMachOArch(const ArgList &Args,
154  ArgStringList &CmdArgs) const {
155  StringRef ArchName = getMachOToolChain().getMachOArchName(Args);
156 
157  // Derived from darwin_arch spec.
158  CmdArgs.push_back("-arch");
159  CmdArgs.push_back(Args.MakeArgString(ArchName));
160 
161  // FIXME: Is this needed anymore?
162  if (ArchName == "arm")
163  CmdArgs.push_back("-force_cpusubtype_ALL");
164 }
165 
166 bool darwin::Linker::NeedsTempPath(const InputInfoList &Inputs) const {
167  // We only need to generate a temp path for LTO if we aren't compiling object
168  // files. When compiling source files, we run 'dsymutil' after linking. We
169  // don't run 'dsymutil' when compiling object files.
170  for (const auto &Input : Inputs)
171  if (Input.getType() != types::TY_Object)
172  return true;
173 
174  return false;
175 }
176 
177 /// Pass -no_deduplicate to ld64 under certain conditions:
178 ///
179 /// - Either -O0 or -O1 is explicitly specified
180 /// - No -O option is specified *and* this is a compile+link (implicit -O0)
181 ///
182 /// Also do *not* add -no_deduplicate when no -O option is specified and this
183 /// is just a link (we can't imply -O0)
184 static bool shouldLinkerNotDedup(bool IsLinkerOnlyAction, const ArgList &Args) {
185  if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
186  if (A->getOption().matches(options::OPT_O0))
187  return true;
188  if (A->getOption().matches(options::OPT_O))
189  return llvm::StringSwitch<bool>(A->getValue())
190  .Case("1", true)
191  .Default(false);
192  return false; // OPT_Ofast & OPT_O4
193  }
194 
195  if (!IsLinkerOnlyAction) // Implicit -O0 for compile+linker only.
196  return true;
197  return false;
198 }
199 
200 void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args,
201  ArgStringList &CmdArgs,
202  const InputInfoList &Inputs) const {
203  const Driver &D = getToolChain().getDriver();
204  const toolchains::MachO &MachOTC = getMachOToolChain();
205 
206  unsigned Version[5] = {0, 0, 0, 0, 0};
207  if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
208  if (!Driver::GetReleaseVersion(A->getValue(), Version))
209  D.Diag(diag::err_drv_invalid_version_number) << A->getAsString(Args);
210  }
211 
212  // Newer linkers support -demangle. Pass it if supported and not disabled by
213  // the user.
214  if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
215  CmdArgs.push_back("-demangle");
216 
217  if (Args.hasArg(options::OPT_rdynamic) && Version[0] >= 137)
218  CmdArgs.push_back("-export_dynamic");
219 
220  // If we are using App Extension restrictions, pass a flag to the linker
221  // telling it that the compiled code has been audited.
222  if (Args.hasFlag(options::OPT_fapplication_extension,
223  options::OPT_fno_application_extension, false))
224  CmdArgs.push_back("-application_extension");
225 
226  if (D.isUsingLTO() && Version[0] >= 116 && NeedsTempPath(Inputs)) {
227  std::string TmpPathName;
228  if (D.getLTOMode() == LTOK_Full) {
229  // If we are using full LTO, then automatically create a temporary file
230  // path for the linker to use, so that it's lifetime will extend past a
231  // possible dsymutil step.
232  TmpPathName =
233  D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object));
234  } else if (D.getLTOMode() == LTOK_Thin)
235  // If we are using thin LTO, then create a directory instead.
236  TmpPathName = D.GetTemporaryDirectory("thinlto");
237 
238  if (!TmpPathName.empty()) {
239  auto *TmpPath = C.getArgs().MakeArgString(TmpPathName);
240  C.addTempFile(TmpPath);
241  CmdArgs.push_back("-object_path_lto");
242  CmdArgs.push_back(TmpPath);
243  }
244  }
245 
246  // Use -lto_library option to specify the libLTO.dylib path. Try to find
247  // it in clang installed libraries. ld64 will only look at this argument
248  // when it actually uses LTO, so libLTO.dylib only needs to exist at link
249  // time if ld64 decides that it needs to use LTO.
250  // Since this is passed unconditionally, ld64 will never look for libLTO.dylib
251  // next to it. That's ok since ld64 using a libLTO.dylib not matching the
252  // clang version won't work anyways.
253  if (Version[0] >= 133) {
254  // Search for libLTO in <InstalledDir>/../lib/libLTO.dylib
255  StringRef P = llvm::sys::path::parent_path(D.Dir);
256  SmallString<128> LibLTOPath(P);
257  llvm::sys::path::append(LibLTOPath, "lib");
258  llvm::sys::path::append(LibLTOPath, "libLTO.dylib");
259  CmdArgs.push_back("-lto_library");
260  CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath));
261  }
262 
263  // ld64 version 262 and above run the deduplicate pass by default.
264  if (Version[0] >= 262 && shouldLinkerNotDedup(C.getJobs().empty(), Args))
265  CmdArgs.push_back("-no_deduplicate");
266 
267  // Derived from the "link" spec.
268  Args.AddAllArgs(CmdArgs, options::OPT_static);
269  if (!Args.hasArg(options::OPT_static))
270  CmdArgs.push_back("-dynamic");
271  if (Args.hasArg(options::OPT_fgnu_runtime)) {
272  // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu
273  // here. How do we wish to handle such things?
274  }
275 
276  if (!Args.hasArg(options::OPT_dynamiclib)) {
277  AddMachOArch(Args, CmdArgs);
278  // FIXME: Why do this only on this path?
279  Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL);
280 
281  Args.AddLastArg(CmdArgs, options::OPT_bundle);
282  Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader);
283  Args.AddAllArgs(CmdArgs, options::OPT_client__name);
284 
285  Arg *A;
286  if ((A = Args.getLastArg(options::OPT_compatibility__version)) ||
287  (A = Args.getLastArg(options::OPT_current__version)) ||
288  (A = Args.getLastArg(options::OPT_install__name)))
289  D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args)
290  << "-dynamiclib";
291 
292  Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace);
293  Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs);
294  Args.AddLastArg(CmdArgs, options::OPT_private__bundle);
295  } else {
296  CmdArgs.push_back("-dylib");
297 
298  Arg *A;
299  if ((A = Args.getLastArg(options::OPT_bundle)) ||
300  (A = Args.getLastArg(options::OPT_bundle__loader)) ||
301  (A = Args.getLastArg(options::OPT_client__name)) ||
302  (A = Args.getLastArg(options::OPT_force__flat__namespace)) ||
303  (A = Args.getLastArg(options::OPT_keep__private__externs)) ||
304  (A = Args.getLastArg(options::OPT_private__bundle)))
305  D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args)
306  << "-dynamiclib";
307 
308  Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version,
309  "-dylib_compatibility_version");
310  Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version,
311  "-dylib_current_version");
312 
313  AddMachOArch(Args, CmdArgs);
314 
315  Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name,
316  "-dylib_install_name");
317  }
318 
319  Args.AddLastArg(CmdArgs, options::OPT_all__load);
320  Args.AddAllArgs(CmdArgs, options::OPT_allowable__client);
321  Args.AddLastArg(CmdArgs, options::OPT_bind__at__load);
322  if (MachOTC.isTargetIOSBased())
323  Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal);
324  Args.AddLastArg(CmdArgs, options::OPT_dead__strip);
325  Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms);
326  Args.AddAllArgs(CmdArgs, options::OPT_dylib__file);
327  Args.AddLastArg(CmdArgs, options::OPT_dynamic);
328  Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list);
329  Args.AddLastArg(CmdArgs, options::OPT_flat__namespace);
330  Args.AddAllArgs(CmdArgs, options::OPT_force__load);
331  Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names);
332  Args.AddAllArgs(CmdArgs, options::OPT_image__base);
333  Args.AddAllArgs(CmdArgs, options::OPT_init);
334 
335  // Add the deployment target.
336  MachOTC.addMinVersionArgs(Args, CmdArgs);
337 
338  Args.AddLastArg(CmdArgs, options::OPT_nomultidefs);
339  Args.AddLastArg(CmdArgs, options::OPT_multi__module);
340  Args.AddLastArg(CmdArgs, options::OPT_single__module);
341  Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined);
342  Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused);
343 
344  if (const Arg *A =
345  Args.getLastArg(options::OPT_fpie, options::OPT_fPIE,
346  options::OPT_fno_pie, options::OPT_fno_PIE)) {
347  if (A->getOption().matches(options::OPT_fpie) ||
348  A->getOption().matches(options::OPT_fPIE))
349  CmdArgs.push_back("-pie");
350  else
351  CmdArgs.push_back("-no_pie");
352  }
353 
354  // for embed-bitcode, use -bitcode_bundle in linker command
355  if (C.getDriver().embedBitcodeEnabled()) {
356  // Check if the toolchain supports bitcode build flow.
357  if (MachOTC.SupportsEmbeddedBitcode()) {
358  CmdArgs.push_back("-bitcode_bundle");
359  if (C.getDriver().embedBitcodeMarkerOnly() && Version[0] >= 278) {
360  CmdArgs.push_back("-bitcode_process_mode");
361  CmdArgs.push_back("marker");
362  }
363  } else
364  D.Diag(diag::err_drv_bitcode_unsupported_on_toolchain);
365  }
366 
367  Args.AddLastArg(CmdArgs, options::OPT_prebind);
368  Args.AddLastArg(CmdArgs, options::OPT_noprebind);
369  Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding);
370  Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules);
371  Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs);
372  Args.AddAllArgs(CmdArgs, options::OPT_sectcreate);
373  Args.AddAllArgs(CmdArgs, options::OPT_sectorder);
374  Args.AddAllArgs(CmdArgs, options::OPT_seg1addr);
375  Args.AddAllArgs(CmdArgs, options::OPT_segprot);
376  Args.AddAllArgs(CmdArgs, options::OPT_segaddr);
377  Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr);
378  Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr);
379  Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table);
380  Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename);
381  Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
382  Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
383 
384  // Give --sysroot= preference, over the Apple specific behavior to also use
385  // --isysroot as the syslibroot.
386  StringRef sysroot = C.getSysRoot();
387  if (sysroot != "") {
388  CmdArgs.push_back("-syslibroot");
389  CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
390  } else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
391  CmdArgs.push_back("-syslibroot");
392  CmdArgs.push_back(A->getValue());
393  }
394 
395  Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace);
396  Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints);
397  Args.AddAllArgs(CmdArgs, options::OPT_umbrella);
398  Args.AddAllArgs(CmdArgs, options::OPT_undefined);
399  Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list);
400  Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches);
401  Args.AddLastArg(CmdArgs, options::OPT_X_Flag);
402  Args.AddAllArgs(CmdArgs, options::OPT_y);
403  Args.AddLastArg(CmdArgs, options::OPT_w);
404  Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size);
405  Args.AddAllArgs(CmdArgs, options::OPT_segs__read__);
406  Args.AddLastArg(CmdArgs, options::OPT_seglinkedit);
407  Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit);
408  Args.AddAllArgs(CmdArgs, options::OPT_sectalign);
409  Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols);
410  Args.AddAllArgs(CmdArgs, options::OPT_segcreate);
411  Args.AddLastArg(CmdArgs, options::OPT_whyload);
412  Args.AddLastArg(CmdArgs, options::OPT_whatsloaded);
413  Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name);
414  Args.AddLastArg(CmdArgs, options::OPT_dylinker);
415  Args.AddLastArg(CmdArgs, options::OPT_Mach);
416 }
417 
418 /// Determine whether we are linking the ObjC runtime.
419 static bool isObjCRuntimeLinked(const ArgList &Args) {
420  if (isObjCAutoRefCount(Args)) {
421  Args.ClaimAllArgs(options::OPT_fobjc_link_runtime);
422  return true;
423  }
424  return Args.hasArg(options::OPT_fobjc_link_runtime);
425 }
426 
428  const InputInfo &Output,
429  const InputInfoList &Inputs,
430  const ArgList &Args,
431  const char *LinkingOutput) const {
432  assert(Output.getType() == types::TY_Image && "Invalid linker output type.");
433 
434  // If the number of arguments surpasses the system limits, we will encode the
435  // input files in a separate file, shortening the command line. To this end,
436  // build a list of input file names that can be passed via a file with the
437  // -filelist linker option.
438  llvm::opt::ArgStringList InputFileList;
439 
440  // The logic here is derived from gcc's behavior; most of which
441  // comes from specs (starting with link_command). Consult gcc for
442  // more information.
443  ArgStringList CmdArgs;
444 
445  /// Hack(tm) to ignore linking errors when we are doing ARC migration.
446  if (Args.hasArg(options::OPT_ccc_arcmt_check,
447  options::OPT_ccc_arcmt_migrate)) {
448  for (const auto &Arg : Args)
449  Arg->claim();
450  const char *Exec =
451  Args.MakeArgString(getToolChain().GetProgramPath("touch"));
452  CmdArgs.push_back(Output.getFilename());
453  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, None));
454  return;
455  }
456 
457  // I'm not sure why this particular decomposition exists in gcc, but
458  // we follow suite for ease of comparison.
459  AddLinkArgs(C, Args, CmdArgs, Inputs);
460 
461  // For LTO, pass the name of the optimization record file and other
462  // opt-remarks flags.
463  if (Args.hasFlag(options::OPT_fsave_optimization_record,
464  options::OPT_fno_save_optimization_record, false)) {
465  CmdArgs.push_back("-mllvm");
466  CmdArgs.push_back("-lto-pass-remarks-output");
467  CmdArgs.push_back("-mllvm");
468 
470  F = Output.getFilename();
471  F += ".opt.yaml";
472  CmdArgs.push_back(Args.MakeArgString(F));
473 
474  if (getLastProfileUseArg(Args)) {
475  CmdArgs.push_back("-mllvm");
476  CmdArgs.push_back("-lto-pass-remarks-with-hotness");
477 
478  if (const Arg *A =
479  Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) {
480  CmdArgs.push_back("-mllvm");
481  std::string Opt =
482  std::string("-lto-pass-remarks-hotness-threshold=") + A->getValue();
483  CmdArgs.push_back(Args.MakeArgString(Opt));
484  }
485  }
486 
487  if (const Arg *A =
488  Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) {
489  CmdArgs.push_back("-mllvm");
490  std::string Passes =
491  std::string("-lto-pass-remarks-filter=") + A->getValue();
492  CmdArgs.push_back(Args.MakeArgString(Passes));
493  }
494  }
495 
496  // Propagate the -moutline flag to the linker in LTO.
497  if (Args.hasFlag(options::OPT_moutline, options::OPT_mno_outline, false)) {
498  if (getMachOToolChain().getMachOArchName(Args) == "arm64") {
499  CmdArgs.push_back("-mllvm");
500  CmdArgs.push_back("-enable-machine-outliner");
501 
502  // Outline from linkonceodr functions by default in LTO.
503  CmdArgs.push_back("-mllvm");
504  CmdArgs.push_back("-enable-linkonceodr-outlining");
505  }
506  }
507 
508  // It seems that the 'e' option is completely ignored for dynamic executables
509  // (the default), and with static executables, the last one wins, as expected.
510  Args.AddAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, options::OPT_t,
511  options::OPT_Z_Flag, options::OPT_u_Group,
512  options::OPT_e, options::OPT_r});
513 
514  // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
515  // members of static archive libraries which implement Objective-C classes or
516  // categories.
517  if (Args.hasArg(options::OPT_ObjC) || Args.hasArg(options::OPT_ObjCXX))
518  CmdArgs.push_back("-ObjC");
519 
520  CmdArgs.push_back("-o");
521  CmdArgs.push_back(Output.getFilename());
522 
523  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
524  getMachOToolChain().addStartObjectFileArgs(Args, CmdArgs);
525 
526  Args.AddAllArgs(CmdArgs, options::OPT_L);
527 
528  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
529  // Build the input file for -filelist (list of linker input files) in case we
530  // need it later
531  for (const auto &II : Inputs) {
532  if (!II.isFilename()) {
533  // This is a linker input argument.
534  // We cannot mix input arguments and file names in a -filelist input, thus
535  // we prematurely stop our list (remaining files shall be passed as
536  // arguments).
537  if (InputFileList.size() > 0)
538  break;
539 
540  continue;
541  }
542 
543  InputFileList.push_back(II.getFilename());
544  }
545 
546  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
547  addOpenMPRuntime(CmdArgs, getToolChain(), Args);
548 
549  if (isObjCRuntimeLinked(Args) &&
550  !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
551  // We use arclite library for both ARC and subscripting support.
552  getMachOToolChain().AddLinkARCArgs(Args, CmdArgs);
553 
554  CmdArgs.push_back("-framework");
555  CmdArgs.push_back("Foundation");
556  // Link libobj.
557  CmdArgs.push_back("-lobjc");
558  }
559 
560  if (LinkingOutput) {
561  CmdArgs.push_back("-arch_multiple");
562  CmdArgs.push_back("-final_output");
563  CmdArgs.push_back(LinkingOutput);
564  }
565 
566  if (Args.hasArg(options::OPT_fnested_functions))
567  CmdArgs.push_back("-allow_stack_execute");
568 
569  getMachOToolChain().addProfileRTLibs(Args, CmdArgs);
570 
571  if (unsigned Parallelism =
572  getLTOParallelism(Args, getToolChain().getDriver())) {
573  CmdArgs.push_back("-mllvm");
574  CmdArgs.push_back(Args.MakeArgString("-threads=" + Twine(Parallelism)));
575  }
576 
577  if (getToolChain().ShouldLinkCXXStdlib(Args))
578  getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
579  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
580  // link_ssp spec is empty.
581 
582  // Let the tool chain choose which runtime library to link.
583  getMachOToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs);
584 
585  // No need to do anything for pthreads. Claim argument to avoid warning.
586  Args.ClaimAllArgs(options::OPT_pthread);
587  Args.ClaimAllArgs(options::OPT_pthreads);
588  }
589 
590  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
591  // endfile_spec is empty.
592  }
593 
594  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
595  Args.AddAllArgs(CmdArgs, options::OPT_F);
596 
597  // -iframework should be forwarded as -F.
598  for (const Arg *A : Args.filtered(options::OPT_iframework))
599  CmdArgs.push_back(Args.MakeArgString(std::string("-F") + A->getValue()));
600 
601  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
602  if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
603  if (A->getValue() == StringRef("Accelerate")) {
604  CmdArgs.push_back("-framework");
605  CmdArgs.push_back("Accelerate");
606  }
607  }
608  }
609 
610  const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
611  std::unique_ptr<Command> Cmd =
612  llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs);
613  Cmd->setInputFileList(std::move(InputFileList));
614  C.addCommand(std::move(Cmd));
615 }
616 
618  const InputInfo &Output,
619  const InputInfoList &Inputs,
620  const ArgList &Args,
621  const char *LinkingOutput) const {
622  ArgStringList CmdArgs;
623 
624  CmdArgs.push_back("-create");
625  assert(Output.isFilename() && "Unexpected lipo output.");
626 
627  CmdArgs.push_back("-output");
628  CmdArgs.push_back(Output.getFilename());
629 
630  for (const auto &II : Inputs) {
631  assert(II.isFilename() && "Unexpected lipo input.");
632  CmdArgs.push_back(II.getFilename());
633  }
634 
635  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo"));
636  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
637 }
638 
640  const InputInfo &Output,
641  const InputInfoList &Inputs,
642  const ArgList &Args,
643  const char *LinkingOutput) const {
644  ArgStringList CmdArgs;
645 
646  CmdArgs.push_back("-o");
647  CmdArgs.push_back(Output.getFilename());
648 
649  assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
650  const InputInfo &Input = Inputs[0];
651  assert(Input.isFilename() && "Unexpected dsymutil input.");
652  CmdArgs.push_back(Input.getFilename());
653 
654  const char *Exec =
655  Args.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
656  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
657 }
658 
660  const InputInfo &Output,
661  const InputInfoList &Inputs,
662  const ArgList &Args,
663  const char *LinkingOutput) const {
664  ArgStringList CmdArgs;
665  CmdArgs.push_back("--verify");
666  CmdArgs.push_back("--debug-info");
667  CmdArgs.push_back("--eh-frame");
668  CmdArgs.push_back("--quiet");
669 
670  assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
671  const InputInfo &Input = Inputs[0];
672  assert(Input.isFilename() && "Unexpected verify input");
673 
674  // Grabbing the output of the earlier dsymutil run.
675  CmdArgs.push_back(Input.getFilename());
676 
677  const char *Exec =
678  Args.MakeArgString(getToolChain().GetProgramPath("dwarfdump"));
679  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
680 }
681 
682 MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
683  : ToolChain(D, Triple, Args) {
684  // We expect 'as', 'ld', etc. to be adjacent to our install dir.
685  getProgramPaths().push_back(getDriver().getInstalledDir());
686  if (getDriver().getInstalledDir() != getDriver().Dir)
687  getProgramPaths().push_back(getDriver().Dir);
688 }
689 
690 /// Darwin - Darwin tool chain for i386 and x86_64.
691 Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
692  : MachO(D, Triple, Args), TargetInitialized(false),
693  CudaInstallation(D, Triple, Args) {}
694 
697 
698  // Darwin always preprocesses assembly files (unless -x is used explicitly).
699  if (Ty == types::TY_PP_Asm)
700  return types::TY_Asm;
701 
702  return Ty;
703 }
704 
705 bool MachO::HasNativeLLVMSupport() const { return true; }
706 
708  // Default to use libc++ on OS X 10.9+ and iOS 7+.
709  if ((isTargetMacOS() && !isMacosxVersionLT(10, 9)) ||
710  (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) ||
712  return ToolChain::CST_Libcxx;
713 
715 }
716 
717 /// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0.
718 ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const {
719  if (isTargetWatchOSBased())
721  if (isTargetIOSBased())
723  if (isNonFragile)
726 }
727 
728 /// Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2.
730  if (isTargetWatchOSBased())
731  return true;
732  else if (isTargetIOSBased())
733  return !isIPhoneOSVersionLT(3, 2);
734  else {
735  assert(isTargetMacOS() && "unexpected darwin target");
736  return !isMacosxVersionLT(10, 6);
737  }
738 }
739 
740 void Darwin::AddCudaIncludeArgs(const ArgList &DriverArgs,
741  ArgStringList &CC1Args) const {
742  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
743 }
744 
745 // This is just a MachO name translation routine and there's no
746 // way to join this into ARMTargetParser without breaking all
747 // other assumptions. Maybe MachO should consider standardising
748 // their nomenclature.
749 static const char *ArmMachOArchName(StringRef Arch) {
750  return llvm::StringSwitch<const char *>(Arch)
751  .Case("armv6k", "armv6")
752  .Case("armv6m", "armv6m")
753  .Case("armv5tej", "armv5")
754  .Case("xscale", "xscale")
755  .Case("armv4t", "armv4t")
756  .Case("armv7", "armv7")
757  .Cases("armv7a", "armv7-a", "armv7")
758  .Cases("armv7r", "armv7-r", "armv7")
759  .Cases("armv7em", "armv7e-m", "armv7em")
760  .Cases("armv7k", "armv7-k", "armv7k")
761  .Cases("armv7m", "armv7-m", "armv7m")
762  .Cases("armv7s", "armv7-s", "armv7s")
763  .Default(nullptr);
764 }
765 
766 static const char *ArmMachOArchNameCPU(StringRef CPU) {
767  llvm::ARM::ArchKind ArchKind = llvm::ARM::parseCPUArch(CPU);
768  if (ArchKind == llvm::ARM::ArchKind::INVALID)
769  return nullptr;
770  StringRef Arch = llvm::ARM::getArchName(ArchKind);
771 
772  // FIXME: Make sure this MachO triple mangling is really necessary.
773  // ARMv5* normalises to ARMv5.
774  if (Arch.startswith("armv5"))
775  Arch = Arch.substr(0, 5);
776  // ARMv6*, except ARMv6M, normalises to ARMv6.
777  else if (Arch.startswith("armv6") && !Arch.endswith("6m"))
778  Arch = Arch.substr(0, 5);
779  // ARMv7A normalises to ARMv7.
780  else if (Arch.endswith("v7a"))
781  Arch = Arch.substr(0, 5);
782  return Arch.data();
783 }
784 
785 StringRef MachO::getMachOArchName(const ArgList &Args) const {
786  switch (getTriple().getArch()) {
787  default:
789 
790  case llvm::Triple::aarch64:
791  return "arm64";
792 
793  case llvm::Triple::thumb:
794  case llvm::Triple::arm:
795  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ))
796  if (const char *Arch = ArmMachOArchName(A->getValue()))
797  return Arch;
798 
799  if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
800  if (const char *Arch = ArmMachOArchNameCPU(A->getValue()))
801  return Arch;
802 
803  return "arm";
804  }
805 }
806 
808 
810 
811 std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args,
812  types::ID InputType) const {
813  llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
814 
815  // If the target isn't initialized (e.g., an unknown Darwin platform, return
816  // the default triple).
817  if (!isTargetInitialized())
818  return Triple.getTriple();
819 
820  SmallString<16> Str;
821  if (isTargetWatchOSBased())
822  Str += "watchos";
823  else if (isTargetTvOSBased())
824  Str += "tvos";
825  else if (isTargetIOSBased())
826  Str += "ios";
827  else
828  Str += "macosx";
829  Str += getTargetVersion().getAsString();
830  Triple.setOSName(Str);
831 
832  return Triple.getTriple();
833 }
834 
836  switch (AC) {
838  if (!Lipo)
839  Lipo.reset(new tools::darwin::Lipo(*this));
840  return Lipo.get();
842  if (!Dsymutil)
843  Dsymutil.reset(new tools::darwin::Dsymutil(*this));
844  return Dsymutil.get();
846  if (!VerifyDebug)
847  VerifyDebug.reset(new tools::darwin::VerifyDebug(*this));
848  return VerifyDebug.get();
849  default:
850  return ToolChain::getTool(AC);
851  }
852 }
853 
854 Tool *MachO::buildLinker() const { return new tools::darwin::Linker(*this); }
855 
857  return new tools::darwin::Assembler(*this);
858 }
859 
860 DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple,
861  const ArgList &Args)
862  : Darwin(D, Triple, Args) {}
863 
864 void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const {
865  // For modern targets, promote certain warnings to errors.
866  if (isTargetWatchOSBased() || getTriple().isArch64Bit()) {
867  // Always enable -Wdeprecated-objc-isa-usage and promote it
868  // to an error.
869  CC1Args.push_back("-Wdeprecated-objc-isa-usage");
870  CC1Args.push_back("-Werror=deprecated-objc-isa-usage");
871 
872  // For iOS and watchOS, also error about implicit function declarations,
873  // as that can impact calling conventions.
874  if (!isTargetMacOS())
875  CC1Args.push_back("-Werror=implicit-function-declaration");
876  }
877 }
878 
879 void DarwinClang::AddLinkARCArgs(const ArgList &Args,
880  ArgStringList &CmdArgs) const {
881  // Avoid linking compatibility stubs on i386 mac.
882  if (isTargetMacOS() && getArch() == llvm::Triple::x86)
883  return;
884 
885  ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true);
886 
887  if ((runtime.hasNativeARC() || !isObjCAutoRefCount(Args)) &&
888  runtime.hasSubscripting())
889  return;
890 
891  CmdArgs.push_back("-force_load");
892  SmallString<128> P(getDriver().ClangExecutable);
893  llvm::sys::path::remove_filename(P); // 'clang'
894  llvm::sys::path::remove_filename(P); // 'bin'
895  llvm::sys::path::append(P, "lib", "arc", "libarclite_");
896  // Mash in the platform.
898  P += "watchsimulator";
899  else if (isTargetWatchOS())
900  P += "watchos";
901  else if (isTargetTvOSSimulator())
902  P += "appletvsimulator";
903  else if (isTargetTvOS())
904  P += "appletvos";
905  else if (isTargetIOSSimulator())
906  P += "iphonesimulator";
907  else if (isTargetIPhoneOS())
908  P += "iphoneos";
909  else
910  P += "macosx";
911  P += ".a";
912 
913  CmdArgs.push_back(Args.MakeArgString(P));
914 }
915 
917  // Default to use DWARF 2 on OS X 10.10 / iOS 8 and lower.
918  if ((isTargetMacOS() && isMacosxVersionLT(10, 11)) ||
920  return 2;
921  return 4;
922 }
923 
924 void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
925  StringRef Component, RuntimeLinkOptions Opts,
926  bool IsShared) const {
927  SmallString<64> DarwinLibName = StringRef("libclang_rt.");
928  // an Darwin the builtins compomnent is not in the library name
929  if (Component != "builtins") {
930  DarwinLibName += Component;
931  if (!(Opts & RLO_IsEmbedded))
932  DarwinLibName += "_";
933  DarwinLibName += getOSLibraryNameSuffix();
934  } else
935  DarwinLibName += getOSLibraryNameSuffix(true);
936 
937  DarwinLibName += IsShared ? "_dynamic.dylib" : ".a";
938  SmallString<128> Dir(getDriver().ResourceDir);
939  llvm::sys::path::append(
940  Dir, "lib", (Opts & RLO_IsEmbedded) ? "macho_embedded" : "darwin");
941 
942  SmallString<128> P(Dir);
943  llvm::sys::path::append(P, DarwinLibName);
944 
945  // For now, allow missing resource libraries to support developers who may
946  // not have compiler-rt checked out or integrated into their build (unless
947  // we explicitly force linking with this library).
948  if ((Opts & RLO_AlwaysLink) || getVFS().exists(P)) {
949  const char *LibArg = Args.MakeArgString(P);
950  if (Opts & RLO_FirstLink)
951  CmdArgs.insert(CmdArgs.begin(), LibArg);
952  else
953  CmdArgs.push_back(LibArg);
954  }
955 
956  // Adding the rpaths might negatively interact when other rpaths are involved,
957  // so we should make sure we add the rpaths last, after all user-specified
958  // rpaths. This is currently true from this place, but we need to be
959  // careful if this function is ever called before user's rpaths are emitted.
960  if (Opts & RLO_AddRPath) {
961  assert(DarwinLibName.endswith(".dylib") && "must be a dynamic library");
962 
963  // Add @executable_path to rpath to support having the dylib copied with
964  // the executable.
965  CmdArgs.push_back("-rpath");
966  CmdArgs.push_back("@executable_path");
967 
968  // Add the path to the resource dir to rpath to support using the dylib
969  // from the default location without copying.
970  CmdArgs.push_back("-rpath");
971  CmdArgs.push_back(Args.MakeArgString(Dir));
972  }
973 }
974 
975 StringRef Darwin::getPlatformFamily() const {
976  switch (TargetPlatform) {
977  case DarwinPlatformKind::MacOS:
978  return "MacOSX";
979  case DarwinPlatformKind::IPhoneOS:
980  return "iPhone";
981  case DarwinPlatformKind::TvOS:
982  return "AppleTV";
983  case DarwinPlatformKind::WatchOS:
984  return "Watch";
985  }
986  llvm_unreachable("Unsupported platform");
987 }
988 
989 StringRef Darwin::getSDKName(StringRef isysroot) {
990  // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk
991  llvm::sys::path::const_iterator SDKDir;
992  auto BeginSDK = llvm::sys::path::begin(isysroot);
993  auto EndSDK = llvm::sys::path::end(isysroot);
994  for (auto IT = BeginSDK; IT != EndSDK; ++IT) {
995  StringRef SDK = *IT;
996  if (SDK.endswith(".sdk"))
997  return SDK.slice(0, SDK.size() - 4);
998  }
999  return "";
1000 }
1001 
1002 StringRef Darwin::getOSLibraryNameSuffix(bool IgnoreSim) const {
1003  switch (TargetPlatform) {
1004  case DarwinPlatformKind::MacOS:
1005  return "osx";
1006  case DarwinPlatformKind::IPhoneOS:
1007  return TargetEnvironment == NativeEnvironment || IgnoreSim ? "ios"
1008  : "iossim";
1009  case DarwinPlatformKind::TvOS:
1010  return TargetEnvironment == NativeEnvironment || IgnoreSim ? "tvos"
1011  : "tvossim";
1012  case DarwinPlatformKind::WatchOS:
1013  return TargetEnvironment == NativeEnvironment || IgnoreSim ? "watchos"
1014  : "watchossim";
1015  }
1016  llvm_unreachable("Unsupported platform");
1017 }
1018 
1019 /// Check if the link command contains a symbol export directive.
1020 static bool hasExportSymbolDirective(const ArgList &Args) {
1021  for (Arg *A : Args) {
1022  if (A->getOption().matches(options::OPT_exported__symbols__list))
1023  return true;
1024  if (!A->getOption().matches(options::OPT_Wl_COMMA) &&
1025  !A->getOption().matches(options::OPT_Xlinker))
1026  continue;
1027  if (A->containsValue("-exported_symbols_list") ||
1028  A->containsValue("-exported_symbol"))
1029  return true;
1030  }
1031  return false;
1032 }
1033 
1034 /// Add an export directive for \p Symbol to the link command.
1035 static void addExportedSymbol(ArgStringList &CmdArgs, const char *Symbol) {
1036  CmdArgs.push_back("-exported_symbol");
1037  CmdArgs.push_back(Symbol);
1038 }
1039 
1040 void Darwin::addProfileRTLibs(const ArgList &Args,
1041  ArgStringList &CmdArgs) const {
1042  if (!needsProfileRT(Args)) return;
1043 
1044  AddLinkRuntimeLib(Args, CmdArgs, "profile",
1046 
1047  // If we have a symbol export directive and we're linking in the profile
1048  // runtime, automatically export symbols necessary to implement some of the
1049  // runtime's functionality.
1050  if (hasExportSymbolDirective(Args)) {
1051  if (needsGCovInstrumentation(Args)) {
1052  addExportedSymbol(CmdArgs, "___gcov_flush");
1053  addExportedSymbol(CmdArgs, "_flush_fn_list");
1054  addExportedSymbol(CmdArgs, "_writeout_fn_list");
1055  } else {
1056  addExportedSymbol(CmdArgs, "___llvm_profile_filename");
1057  addExportedSymbol(CmdArgs, "___llvm_profile_raw_version");
1058  addExportedSymbol(CmdArgs, "_lprofCurFilename");
1059  }
1060  addExportedSymbol(CmdArgs, "_lprofDirMode");
1061  }
1062 }
1063 
1064 void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args,
1065  ArgStringList &CmdArgs,
1066  StringRef Sanitizer,
1067  bool Shared) const {
1068  auto RLO = RuntimeLinkOptions(RLO_AlwaysLink | (Shared ? RLO_AddRPath : 0U));
1069  AddLinkRuntimeLib(Args, CmdArgs, Sanitizer, RLO, Shared);
1070 }
1071 
1073  const ArgList &Args) const {
1074  if (Arg* A = Args.getLastArg(options::OPT_rtlib_EQ)) {
1075  StringRef Value = A->getValue();
1076  if (Value != "compiler-rt")
1077  getDriver().Diag(clang::diag::err_drv_unsupported_rtlib_for_platform)
1078  << Value << "darwin";
1079  }
1080 
1082 }
1083 
1084 void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
1085  ArgStringList &CmdArgs) const {
1086  // Call once to ensure diagnostic is printed if wrong value was specified
1087  GetRuntimeLibType(Args);
1088 
1089  // Darwin doesn't support real static executables, don't link any runtime
1090  // libraries with -static.
1091  if (Args.hasArg(options::OPT_static) ||
1092  Args.hasArg(options::OPT_fapple_kext) ||
1093  Args.hasArg(options::OPT_mkernel))
1094  return;
1095 
1096  // Reject -static-libgcc for now, we can deal with this when and if someone
1097  // cares. This is useful in situations where someone wants to statically link
1098  // something like libstdc++, and needs its runtime support routines.
1099  if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
1100  getDriver().Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args);
1101  return;
1102  }
1103 
1104  const SanitizerArgs &Sanitize = getSanitizerArgs();
1105  if (Sanitize.needsAsanRt())
1106  AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
1107  if (Sanitize.needsLsanRt())
1108  AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");
1109  if (Sanitize.needsUbsanRt())
1110  AddLinkSanitizerLibArgs(Args, CmdArgs,
1111  Sanitize.requiresMinimalRuntime() ? "ubsan_minimal"
1112  : "ubsan",
1113  Sanitize.needsSharedRt());
1114  if (Sanitize.needsTsanRt())
1115  AddLinkSanitizerLibArgs(Args, CmdArgs, "tsan");
1116  if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
1117  AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
1118 
1119  // Libfuzzer is written in C++ and requires libcxx.
1120  AddCXXStdlibLibArgs(Args, CmdArgs);
1121  }
1122  if (Sanitize.needsStatsRt()) {
1123  AddLinkRuntimeLib(Args, CmdArgs, "stats_client", RLO_AlwaysLink);
1124  AddLinkSanitizerLibArgs(Args, CmdArgs, "stats");
1125  }
1126 
1127  const XRayArgs &XRay = getXRayArgs();
1128  if (XRay.needsXRayRt()) {
1129  AddLinkRuntimeLib(Args, CmdArgs, "xray");
1130  AddLinkRuntimeLib(Args, CmdArgs, "xray-basic");
1131  AddLinkRuntimeLib(Args, CmdArgs, "xray-fdr");
1132  }
1133 
1134  // Otherwise link libSystem, then the dynamic runtime library, and finally any
1135  // target specific static runtime library.
1136  CmdArgs.push_back("-lSystem");
1137 
1138  // Select the dynamic runtime library and the target specific static library.
1139  if (isTargetIOSBased()) {
1140  // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1,
1141  // it never went into the SDK.
1142  // Linking against libgcc_s.1 isn't needed for iOS 5.0+
1143  if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
1144  getTriple().getArch() != llvm::Triple::aarch64)
1145  CmdArgs.push_back("-lgcc_s.1");
1146  }
1147  AddLinkRuntimeLib(Args, CmdArgs, "builtins");
1148 }
1149 
1150 /// Returns the most appropriate macOS target version for the current process.
1151 ///
1152 /// If the macOS SDK version is the same or earlier than the system version,
1153 /// then the SDK version is returned. Otherwise the system version is returned.
1154 static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion) {
1155  unsigned Major, Minor, Micro;
1156  llvm::Triple SystemTriple(llvm::sys::getProcessTriple());
1157  if (!SystemTriple.isMacOSX())
1158  return MacOSSDKVersion;
1159  SystemTriple.getMacOSXVersion(Major, Minor, Micro);
1160  VersionTuple SystemVersion(Major, Minor, Micro);
1161  bool HadExtra;
1162  if (!Driver::GetReleaseVersion(MacOSSDKVersion, Major, Minor, Micro,
1163  HadExtra))
1164  return MacOSSDKVersion;
1165  VersionTuple SDKVersion(Major, Minor, Micro);
1166  if (SDKVersion > SystemVersion)
1167  return SystemVersion.getAsString();
1168  return MacOSSDKVersion;
1169 }
1170 
1171 namespace {
1172 
1173 /// The Darwin OS that was selected or inferred from arguments / environment.
1174 struct DarwinPlatform {
1175  enum SourceKind {
1176  /// The OS was specified using the -target argument.
1177  TargetArg,
1178  /// The OS was specified using the -m<os>-version-min argument.
1179  OSVersionArg,
1180  /// The OS was specified using the OS_DEPLOYMENT_TARGET environment.
1181  DeploymentTargetEnv,
1182  /// The OS was inferred from the SDK.
1183  InferredFromSDK,
1184  /// The OS was inferred from the -arch.
1185  InferredFromArch
1186  };
1187 
1190 
1191  DarwinPlatformKind getPlatform() const { return Platform; }
1192 
1193  DarwinEnvironmentKind getEnvironment() const { return Environment; }
1194 
1195  void setEnvironment(DarwinEnvironmentKind Kind) {
1196  Environment = Kind;
1197  InferSimulatorFromArch = false;
1198  }
1199 
1200  StringRef getOSVersion() const {
1201  if (Kind == OSVersionArg)
1202  return Argument->getValue();
1203  return OSVersion;
1204  }
1205 
1206  void setOSVersion(StringRef S) {
1207  assert(Kind == TargetArg && "Unexpected kind!");
1208  OSVersion = S;
1209  }
1210 
1211  bool hasOSVersion() const { return HasOSVersion; }
1212 
1213  /// Returns true if the target OS was explicitly specified.
1214  bool isExplicitlySpecified() const { return Kind <= DeploymentTargetEnv; }
1215 
1216  /// Returns true if the simulator environment can be inferred from the arch.
1217  bool canInferSimulatorFromArch() const { return InferSimulatorFromArch; }
1218 
1219  /// Adds the -m<os>-version-min argument to the compiler invocation.
1220  void addOSVersionMinArgument(DerivedArgList &Args, const OptTable &Opts) {
1221  if (Argument)
1222  return;
1223  assert(Kind != TargetArg && Kind != OSVersionArg && "Invalid kind");
1224  options::ID Opt;
1225  switch (Platform) {
1226  case DarwinPlatformKind::MacOS:
1227  Opt = options::OPT_mmacosx_version_min_EQ;
1228  break;
1229  case DarwinPlatformKind::IPhoneOS:
1230  Opt = options::OPT_miphoneos_version_min_EQ;
1231  break;
1232  case DarwinPlatformKind::TvOS:
1233  Opt = options::OPT_mtvos_version_min_EQ;
1234  break;
1235  case DarwinPlatformKind::WatchOS:
1236  Opt = options::OPT_mwatchos_version_min_EQ;
1237  break;
1238  }
1239  Argument = Args.MakeJoinedArg(nullptr, Opts.getOption(Opt), OSVersion);
1240  Args.append(Argument);
1241  }
1242 
1243  /// Returns the OS version with the argument / environment variable that
1244  /// specified it.
1245  std::string getAsString(DerivedArgList &Args, const OptTable &Opts) {
1246  switch (Kind) {
1247  case TargetArg:
1248  case OSVersionArg:
1249  case InferredFromSDK:
1250  case InferredFromArch:
1251  assert(Argument && "OS version argument not yet inferred");
1252  return Argument->getAsString(Args);
1253  case DeploymentTargetEnv:
1254  return (llvm::Twine(EnvVarName) + "=" + OSVersion).str();
1255  }
1256  llvm_unreachable("Unsupported Darwin Source Kind");
1257  }
1258 
1259  static DarwinPlatform createFromTarget(const llvm::Triple &TT,
1260  StringRef OSVersion, Arg *A) {
1261  DarwinPlatform Result(TargetArg, getPlatformFromOS(TT.getOS()), OSVersion,
1262  A);
1263  switch (TT.getEnvironment()) {
1264  case llvm::Triple::Simulator:
1265  Result.Environment = DarwinEnvironmentKind::Simulator;
1266  break;
1267  default:
1268  break;
1269  }
1270  unsigned Major, Minor, Micro;
1271  TT.getOSVersion(Major, Minor, Micro);
1272  if (Major == 0)
1273  Result.HasOSVersion = false;
1274  return Result;
1275  }
1276  static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
1277  Arg *A) {
1278  return DarwinPlatform(OSVersionArg, Platform, A);
1279  }
1280  static DarwinPlatform createDeploymentTargetEnv(DarwinPlatformKind Platform,
1281  StringRef EnvVarName,
1282  StringRef Value) {
1283  DarwinPlatform Result(DeploymentTargetEnv, Platform, Value);
1284  Result.EnvVarName = EnvVarName;
1285  return Result;
1286  }
1287  static DarwinPlatform createFromSDK(DarwinPlatformKind Platform,
1288  StringRef Value,
1289  bool IsSimulator = false) {
1290  DarwinPlatform Result(InferredFromSDK, Platform, Value);
1291  if (IsSimulator)
1292  Result.Environment = DarwinEnvironmentKind::Simulator;
1293  Result.InferSimulatorFromArch = false;
1294  return Result;
1295  }
1296  static DarwinPlatform createFromArch(llvm::Triple::OSType OS,
1297  StringRef Value) {
1298  return DarwinPlatform(InferredFromArch, getPlatformFromOS(OS), Value);
1299  }
1300 
1301  /// Constructs an inferred SDKInfo value based on the version inferred from
1302  /// the SDK path itself. Only works for values that were created by inferring
1303  /// the platform from the SDKPath.
1304  DarwinSDKInfo inferSDKInfo() {
1305  assert(Kind == InferredFromSDK && "can infer SDK info only");
1306  llvm::VersionTuple Version;
1307  bool IsValid = !Version.tryParse(OSVersion);
1308  (void)IsValid;
1309  assert(IsValid && "invalid SDK version");
1310  return DarwinSDKInfo(Version);
1311  }
1312 
1313 private:
1314  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, Arg *Argument)
1315  : Kind(Kind), Platform(Platform), Argument(Argument) {}
1316  DarwinPlatform(SourceKind Kind, DarwinPlatformKind Platform, StringRef Value,
1317  Arg *Argument = nullptr)
1318  : Kind(Kind), Platform(Platform), OSVersion(Value), Argument(Argument) {}
1319 
1320  static DarwinPlatformKind getPlatformFromOS(llvm::Triple::OSType OS) {
1321  switch (OS) {
1322  case llvm::Triple::Darwin:
1323  case llvm::Triple::MacOSX:
1324  return DarwinPlatformKind::MacOS;
1325  case llvm::Triple::IOS:
1326  return DarwinPlatformKind::IPhoneOS;
1327  case llvm::Triple::TvOS:
1328  return DarwinPlatformKind::TvOS;
1329  case llvm::Triple::WatchOS:
1330  return DarwinPlatformKind::WatchOS;
1331  default:
1332  llvm_unreachable("Unable to infer Darwin variant");
1333  }
1334  }
1335 
1336  SourceKind Kind;
1337  DarwinPlatformKind Platform;
1338  DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
1339  std::string OSVersion;
1340  bool HasOSVersion = true, InferSimulatorFromArch = true;
1341  Arg *Argument;
1342  StringRef EnvVarName;
1343 };
1344 
1345 /// Returns the deployment target that's specified using the -m<os>-version-min
1346 /// argument.
1348 getDeploymentTargetFromOSVersionArg(DerivedArgList &Args,
1349  const Driver &TheDriver) {
1350  Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
1351  Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
1352  options::OPT_mios_simulator_version_min_EQ);
1353  Arg *TvOSVersion =
1354  Args.getLastArg(options::OPT_mtvos_version_min_EQ,
1355  options::OPT_mtvos_simulator_version_min_EQ);
1356  Arg *WatchOSVersion =
1357  Args.getLastArg(options::OPT_mwatchos_version_min_EQ,
1358  options::OPT_mwatchos_simulator_version_min_EQ);
1359  if (OSXVersion) {
1360  if (iOSVersion || TvOSVersion || WatchOSVersion) {
1361  TheDriver.Diag(diag::err_drv_argument_not_allowed_with)
1362  << OSXVersion->getAsString(Args)
1363  << (iOSVersion ? iOSVersion
1364  : TvOSVersion ? TvOSVersion : WatchOSVersion)
1365  ->getAsString(Args);
1366  }
1367  return DarwinPlatform::createOSVersionArg(Darwin::MacOS, OSXVersion);
1368  } else if (iOSVersion) {
1369  if (TvOSVersion || WatchOSVersion) {
1370  TheDriver.Diag(diag::err_drv_argument_not_allowed_with)
1371  << iOSVersion->getAsString(Args)
1372  << (TvOSVersion ? TvOSVersion : WatchOSVersion)->getAsString(Args);
1373  }
1374  return DarwinPlatform::createOSVersionArg(Darwin::IPhoneOS, iOSVersion);
1375  } else if (TvOSVersion) {
1376  if (WatchOSVersion) {
1377  TheDriver.Diag(diag::err_drv_argument_not_allowed_with)
1378  << TvOSVersion->getAsString(Args)
1379  << WatchOSVersion->getAsString(Args);
1380  }
1381  return DarwinPlatform::createOSVersionArg(Darwin::TvOS, TvOSVersion);
1382  } else if (WatchOSVersion)
1383  return DarwinPlatform::createOSVersionArg(Darwin::WatchOS, WatchOSVersion);
1384  return None;
1385 }
1386 
1387 /// Returns the deployment target that's specified using the
1388 /// OS_DEPLOYMENT_TARGET environment variable.
1390 getDeploymentTargetFromEnvironmentVariables(const Driver &TheDriver,
1391  const llvm::Triple &Triple) {
1392  std::string Targets[Darwin::LastDarwinPlatform + 1];
1393  const char *EnvVars[] = {
1394  "MACOSX_DEPLOYMENT_TARGET",
1395  "IPHONEOS_DEPLOYMENT_TARGET",
1396  "TVOS_DEPLOYMENT_TARGET",
1397  "WATCHOS_DEPLOYMENT_TARGET",
1398  };
1399  static_assert(llvm::array_lengthof(EnvVars) == Darwin::LastDarwinPlatform + 1,
1400  "Missing platform");
1401  for (const auto &I : llvm::enumerate(llvm::makeArrayRef(EnvVars))) {
1402  if (char *Env = ::getenv(I.value()))
1403  Targets[I.index()] = Env;
1404  }
1405 
1406  // Do not allow conflicts with the watchOS target.
1407  if (!Targets[Darwin::WatchOS].empty() &&
1408  (!Targets[Darwin::IPhoneOS].empty() || !Targets[Darwin::TvOS].empty())) {
1409  TheDriver.Diag(diag::err_drv_conflicting_deployment_targets)
1410  << "WATCHOS_DEPLOYMENT_TARGET"
1411  << (!Targets[Darwin::IPhoneOS].empty() ? "IPHONEOS_DEPLOYMENT_TARGET"
1412  : "TVOS_DEPLOYMENT_TARGET");
1413  }
1414 
1415  // Do not allow conflicts with the tvOS target.
1416  if (!Targets[Darwin::TvOS].empty() && !Targets[Darwin::IPhoneOS].empty()) {
1417  TheDriver.Diag(diag::err_drv_conflicting_deployment_targets)
1418  << "TVOS_DEPLOYMENT_TARGET"
1419  << "IPHONEOS_DEPLOYMENT_TARGET";
1420  }
1421 
1422  // Allow conflicts among OSX and iOS for historical reasons, but choose the
1423  // default platform.
1424  if (!Targets[Darwin::MacOS].empty() &&
1425  (!Targets[Darwin::IPhoneOS].empty() ||
1426  !Targets[Darwin::WatchOS].empty() || !Targets[Darwin::TvOS].empty())) {
1427  if (Triple.getArch() == llvm::Triple::arm ||
1428  Triple.getArch() == llvm::Triple::aarch64 ||
1429  Triple.getArch() == llvm::Triple::thumb)
1430  Targets[Darwin::MacOS] = "";
1431  else
1432  Targets[Darwin::IPhoneOS] = Targets[Darwin::WatchOS] =
1433  Targets[Darwin::TvOS] = "";
1434  }
1435 
1436  for (const auto &Target : llvm::enumerate(llvm::makeArrayRef(Targets))) {
1437  if (!Target.value().empty())
1438  return DarwinPlatform::createDeploymentTargetEnv(
1439  (Darwin::DarwinPlatformKind)Target.index(), EnvVars[Target.index()],
1440  Target.value());
1441  }
1442  return None;
1443 }
1444 
1445 /// Tries to infer the deployment target from the SDK specified by -isysroot
1446 /// (or SDKROOT). Uses the version specified in the SDKSettings.json file if
1447 /// it's available.
1449 inferDeploymentTargetFromSDK(DerivedArgList &Args,
1451  const Arg *A = Args.getLastArg(options::OPT_isysroot);
1452  if (!A)
1453  return None;
1454  StringRef isysroot = A->getValue();
1455  StringRef SDK = Darwin::getSDKName(isysroot);
1456  if (!SDK.size())
1457  return None;
1458 
1459  std::string Version;
1460  if (SDKInfo) {
1461  // Get the version from the SDKSettings.json if it's available.
1462  Version = SDKInfo->getVersion().getAsString();
1463  } else {
1464  // Slice the version number out.
1465  // Version number is between the first and the last number.
1466  size_t StartVer = SDK.find_first_of("0123456789");
1467  size_t EndVer = SDK.find_last_of("0123456789");
1468  if (StartVer != StringRef::npos && EndVer > StartVer)
1469  Version = SDK.slice(StartVer, EndVer + 1);
1470  }
1471  if (Version.empty())
1472  return None;
1473 
1474  if (SDK.startswith("iPhoneOS") || SDK.startswith("iPhoneSimulator"))
1475  return DarwinPlatform::createFromSDK(
1476  Darwin::IPhoneOS, Version,
1477  /*IsSimulator=*/SDK.startswith("iPhoneSimulator"));
1478  else if (SDK.startswith("MacOSX"))
1479  return DarwinPlatform::createFromSDK(Darwin::MacOS,
1480  getSystemOrSDKMacOSVersion(Version));
1481  else if (SDK.startswith("WatchOS") || SDK.startswith("WatchSimulator"))
1482  return DarwinPlatform::createFromSDK(
1483  Darwin::WatchOS, Version,
1484  /*IsSimulator=*/SDK.startswith("WatchSimulator"));
1485  else if (SDK.startswith("AppleTVOS") || SDK.startswith("AppleTVSimulator"))
1486  return DarwinPlatform::createFromSDK(
1487  Darwin::TvOS, Version,
1488  /*IsSimulator=*/SDK.startswith("AppleTVSimulator"));
1489  return None;
1490 }
1491 
1492 std::string getOSVersion(llvm::Triple::OSType OS, const llvm::Triple &Triple,
1493  const Driver &TheDriver) {
1494  unsigned Major, Minor, Micro;
1495  llvm::Triple SystemTriple(llvm::sys::getProcessTriple());
1496  switch (OS) {
1497  case llvm::Triple::Darwin:
1498  case llvm::Triple::MacOSX:
1499  // If there is no version specified on triple, and both host and target are
1500  // macos, use the host triple to infer OS version.
1501  if (Triple.isMacOSX() && SystemTriple.isMacOSX() &&
1502  !Triple.getOSMajorVersion())
1503  SystemTriple.getMacOSXVersion(Major, Minor, Micro);
1504  else if (!Triple.getMacOSXVersion(Major, Minor, Micro))
1505  TheDriver.Diag(diag::err_drv_invalid_darwin_version)
1506  << Triple.getOSName();
1507  break;
1508  case llvm::Triple::IOS:
1509  Triple.getiOSVersion(Major, Minor, Micro);
1510  break;
1511  case llvm::Triple::TvOS:
1512  Triple.getOSVersion(Major, Minor, Micro);
1513  break;
1514  case llvm::Triple::WatchOS:
1515  Triple.getWatchOSVersion(Major, Minor, Micro);
1516  break;
1517  default:
1518  llvm_unreachable("Unexpected OS type");
1519  break;
1520  }
1521 
1522  std::string OSVersion;
1523  llvm::raw_string_ostream(OSVersion) << Major << '.' << Minor << '.' << Micro;
1524  return OSVersion;
1525 }
1526 
1527 /// Tries to infer the target OS from the -arch.
1529 inferDeploymentTargetFromArch(DerivedArgList &Args, const Darwin &Toolchain,
1530  const llvm::Triple &Triple,
1531  const Driver &TheDriver) {
1532  llvm::Triple::OSType OSTy = llvm::Triple::UnknownOS;
1533 
1534  StringRef MachOArchName = Toolchain.getMachOArchName(Args);
1535  if (MachOArchName == "armv7" || MachOArchName == "armv7s" ||
1536  MachOArchName == "arm64")
1537  OSTy = llvm::Triple::IOS;
1538  else if (MachOArchName == "armv7k")
1539  OSTy = llvm::Triple::WatchOS;
1540  else if (MachOArchName != "armv6m" && MachOArchName != "armv7m" &&
1541  MachOArchName != "armv7em")
1542  OSTy = llvm::Triple::MacOSX;
1543 
1544  if (OSTy == llvm::Triple::UnknownOS)
1545  return None;
1546  return DarwinPlatform::createFromArch(OSTy,
1547  getOSVersion(OSTy, Triple, TheDriver));
1548 }
1549 
1550 /// Returns the deployment target that's specified using the -target option.
1551 Optional<DarwinPlatform> getDeploymentTargetFromTargetArg(
1552  DerivedArgList &Args, const llvm::Triple &Triple, const Driver &TheDriver) {
1553  if (!Args.hasArg(options::OPT_target))
1554  return None;
1555  if (Triple.getOS() == llvm::Triple::Darwin ||
1556  Triple.getOS() == llvm::Triple::UnknownOS)
1557  return None;
1558  std::string OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
1559  return DarwinPlatform::createFromTarget(Triple, OSVersion,
1560  Args.getLastArg(options::OPT_target));
1561 }
1562 
1563 Optional<DarwinSDKInfo> parseSDKSettings(llvm::vfs::FileSystem &VFS,
1564  const ArgList &Args,
1565  const Driver &TheDriver) {
1566  const Arg *A = Args.getLastArg(options::OPT_isysroot);
1567  if (!A)
1568  return None;
1569  StringRef isysroot = A->getValue();
1570  auto SDKInfoOrErr = driver::parseDarwinSDKInfo(VFS, isysroot);
1571  if (!SDKInfoOrErr) {
1572  llvm::consumeError(SDKInfoOrErr.takeError());
1573  TheDriver.Diag(diag::warn_drv_darwin_sdk_invalid_settings);
1574  return None;
1575  }
1576  return *SDKInfoOrErr;
1577 }
1578 
1579 } // namespace
1580 
1581 void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
1582  const OptTable &Opts = getDriver().getOpts();
1583 
1584  // Support allowing the SDKROOT environment variable used by xcrun and other
1585  // Xcode tools to define the default sysroot, by making it the default for
1586  // isysroot.
1587  if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
1588  // Warn if the path does not exist.
1589  if (!getVFS().exists(A->getValue()))
1590  getDriver().Diag(clang::diag::warn_missing_sysroot) << A->getValue();
1591  } else {
1592  if (char *env = ::getenv("SDKROOT")) {
1593  // We only use this value as the default if it is an absolute path,
1594  // exists, and it is not the root path.
1595  if (llvm::sys::path::is_absolute(env) && getVFS().exists(env) &&
1596  StringRef(env) != "/") {
1597  Args.append(Args.MakeSeparateArg(
1598  nullptr, Opts.getOption(options::OPT_isysroot), env));
1599  }
1600  }
1601  }
1602 
1603  // Read the SDKSettings.json file for more information, like the SDK version
1604  // that we can pass down to the compiler.
1605  SDKInfo = parseSDKSettings(getVFS(), Args, getDriver());
1606 
1607  // The OS and the version can be specified using the -target argument.
1608  Optional<DarwinPlatform> OSTarget =
1609  getDeploymentTargetFromTargetArg(Args, getTriple(), getDriver());
1610  if (OSTarget) {
1611  Optional<DarwinPlatform> OSVersionArgTarget =
1612  getDeploymentTargetFromOSVersionArg(Args, getDriver());
1613  if (OSVersionArgTarget) {
1614  unsigned TargetMajor, TargetMinor, TargetMicro;
1615  bool TargetExtra;
1616  unsigned ArgMajor, ArgMinor, ArgMicro;
1617  bool ArgExtra;
1618  if (OSTarget->getPlatform() != OSVersionArgTarget->getPlatform() ||
1619  (Driver::GetReleaseVersion(OSTarget->getOSVersion(), TargetMajor,
1620  TargetMinor, TargetMicro, TargetExtra) &&
1621  Driver::GetReleaseVersion(OSVersionArgTarget->getOSVersion(),
1622  ArgMajor, ArgMinor, ArgMicro, ArgExtra) &&
1623  (VersionTuple(TargetMajor, TargetMinor, TargetMicro) !=
1624  VersionTuple(ArgMajor, ArgMinor, ArgMicro) ||
1625  TargetExtra != ArgExtra))) {
1626  // Select the OS version from the -m<os>-version-min argument when
1627  // the -target does not include an OS version.
1628  if (OSTarget->getPlatform() == OSVersionArgTarget->getPlatform() &&
1629  !OSTarget->hasOSVersion()) {
1630  OSTarget->setOSVersion(OSVersionArgTarget->getOSVersion());
1631  } else {
1632  // Warn about -m<os>-version-min that doesn't match the OS version
1633  // that's specified in the target.
1634  std::string OSVersionArg =
1635  OSVersionArgTarget->getAsString(Args, Opts);
1636  std::string TargetArg = OSTarget->getAsString(Args, Opts);
1637  getDriver().Diag(clang::diag::warn_drv_overriding_flag_option)
1638  << OSVersionArg << TargetArg;
1639  }
1640  }
1641  }
1642  } else {
1643  // The OS target can be specified using the -m<os>version-min argument.
1644  OSTarget = getDeploymentTargetFromOSVersionArg(Args, getDriver());
1645  // If no deployment target was specified on the command line, check for
1646  // environment defines.
1647  if (!OSTarget) {
1648  OSTarget =
1649  getDeploymentTargetFromEnvironmentVariables(getDriver(), getTriple());
1650  if (OSTarget) {
1651  // Don't infer simulator from the arch when the SDK is also specified.
1652  Optional<DarwinPlatform> SDKTarget =
1653  inferDeploymentTargetFromSDK(Args, SDKInfo);
1654  if (SDKTarget)
1655  OSTarget->setEnvironment(SDKTarget->getEnvironment());
1656  }
1657  }
1658  // If there is no command-line argument to specify the Target version and
1659  // no environment variable defined, see if we can set the default based
1660  // on -isysroot using SDKSettings.json if it exists.
1661  if (!OSTarget) {
1662  OSTarget = inferDeploymentTargetFromSDK(Args, SDKInfo);
1663  /// If the target was successfully constructed from the SDK path, try to
1664  /// infer the SDK info if the SDK doesn't have it.
1665  if (OSTarget && !SDKInfo)
1666  SDKInfo = OSTarget->inferSDKInfo();
1667  }
1668  // If no OS targets have been specified, try to guess platform from -target
1669  // or arch name and compute the version from the triple.
1670  if (!OSTarget)
1671  OSTarget =
1672  inferDeploymentTargetFromArch(Args, *this, getTriple(), getDriver());
1673  }
1674 
1675  assert(OSTarget && "Unable to infer Darwin variant");
1676  OSTarget->addOSVersionMinArgument(Args, Opts);
1677  DarwinPlatformKind Platform = OSTarget->getPlatform();
1678 
1679  unsigned Major, Minor, Micro;
1680  bool HadExtra;
1681  // Set the tool chain target information.
1682  if (Platform == MacOS) {
1683  if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
1684  Micro, HadExtra) ||
1685  HadExtra || Major != 10 || Minor >= 100 || Micro >= 100)
1686  getDriver().Diag(diag::err_drv_invalid_version_number)
1687  << OSTarget->getAsString(Args, Opts);
1688  } else if (Platform == IPhoneOS) {
1689  if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
1690  Micro, HadExtra) ||
1691  HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)
1692  getDriver().Diag(diag::err_drv_invalid_version_number)
1693  << OSTarget->getAsString(Args, Opts);
1694  ;
1695  // For 32-bit targets, the deployment target for iOS has to be earlier than
1696  // iOS 11.
1697  if (getTriple().isArch32Bit() && Major >= 11) {
1698  // If the deployment target is explicitly specified, print a diagnostic.
1699  if (OSTarget->isExplicitlySpecified()) {
1700  getDriver().Diag(diag::warn_invalid_ios_deployment_target)
1701  << OSTarget->getAsString(Args, Opts);
1702  // Otherwise, set it to 10.99.99.
1703  } else {
1704  Major = 10;
1705  Minor = 99;
1706  Micro = 99;
1707  }
1708  }
1709  } else if (Platform == TvOS) {
1710  if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
1711  Micro, HadExtra) ||
1712  HadExtra || Major >= 100 || Minor >= 100 || Micro >= 100)
1713  getDriver().Diag(diag::err_drv_invalid_version_number)
1714  << OSTarget->getAsString(Args, Opts);
1715  } else if (Platform == WatchOS) {
1716  if (!Driver::GetReleaseVersion(OSTarget->getOSVersion(), Major, Minor,
1717  Micro, HadExtra) ||
1718  HadExtra || Major >= 10 || Minor >= 100 || Micro >= 100)
1719  getDriver().Diag(diag::err_drv_invalid_version_number)
1720  << OSTarget->getAsString(Args, Opts);
1721  } else
1722  llvm_unreachable("unknown kind of Darwin platform");
1723 
1724  DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
1725  // Recognize iOS targets with an x86 architecture as the iOS simulator.
1726  if (Environment == NativeEnvironment && Platform != MacOS &&
1727  OSTarget->canInferSimulatorFromArch() &&
1728  (getTriple().getArch() == llvm::Triple::x86 ||
1729  getTriple().getArch() == llvm::Triple::x86_64))
1730  Environment = Simulator;
1731 
1732  setTarget(Platform, Environment, Major, Minor, Micro);
1733 
1734  if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
1735  StringRef SDK = getSDKName(A->getValue());
1736  if (SDK.size() > 0) {
1737  size_t StartVer = SDK.find_first_of("0123456789");
1738  StringRef SDKName = SDK.slice(0, StartVer);
1739  if (!SDKName.startswith(getPlatformFamily()))
1740  getDriver().Diag(diag::warn_incompatible_sysroot)
1741  << SDKName << getPlatformFamily();
1742  }
1743  }
1744 }
1745 
1747  const llvm::opt::ArgList &DriverArgs,
1748  llvm::opt::ArgStringList &CC1Args) const {
1749  // The implementation from a base class will pass through the -stdlib to
1750  // CC1Args.
1751  // FIXME: this should not be necessary, remove usages in the frontend
1752  // (e.g. HeaderSearchOptions::UseLibcxx) and don't pipe -stdlib.
1753  ToolChain::AddClangCXXStdlibIncludeArgs(DriverArgs, CC1Args);
1754 
1755  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
1756  DriverArgs.hasArg(options::OPT_nostdincxx))
1757  return;
1758 
1759  switch (GetCXXStdlibType(DriverArgs)) {
1760  case ToolChain::CST_Libcxx: {
1761  llvm::StringRef InstallDir = getDriver().getInstalledDir();
1762  if (InstallDir.empty())
1763  break;
1764  // On Darwin, libc++ may be installed alongside the compiler in
1765  // include/c++/v1.
1766  // Get from 'foo/bin' to 'foo/include/c++/v1'.
1767  SmallString<128> P = InstallDir;
1768  // Note that InstallDir can be relative, so we have to '..' and not
1769  // parent_path.
1770  llvm::sys::path::append(P, "..", "include", "c++", "v1");
1771  addSystemInclude(DriverArgs, CC1Args, P);
1772  break;
1773  }
1775  // FIXME: should we do something about it?
1776  break;
1777  }
1778 }
1779 void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args,
1780  ArgStringList &CmdArgs) const {
1782 
1783  switch (Type) {
1784  case ToolChain::CST_Libcxx:
1785  CmdArgs.push_back("-lc++");
1786  break;
1787 
1789  // Unfortunately, -lstdc++ doesn't always exist in the standard search path;
1790  // it was previously found in the gcc lib dir. However, for all the Darwin
1791  // platforms we care about it was -lstdc++.6, so we search for that
1792  // explicitly if we can't see an obvious -lstdc++ candidate.
1793 
1794  // Check in the sysroot first.
1795  if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
1796  SmallString<128> P(A->getValue());
1797  llvm::sys::path::append(P, "usr", "lib", "libstdc++.dylib");
1798 
1799  if (!getVFS().exists(P)) {
1800  llvm::sys::path::remove_filename(P);
1801  llvm::sys::path::append(P, "libstdc++.6.dylib");
1802  if (getVFS().exists(P)) {
1803  CmdArgs.push_back(Args.MakeArgString(P));
1804  return;
1805  }
1806  }
1807  }
1808 
1809  // Otherwise, look in the root.
1810  // FIXME: This should be removed someday when we don't have to care about
1811  // 10.6 and earlier, where /usr/lib/libstdc++.dylib does not exist.
1812  if (!getVFS().exists("/usr/lib/libstdc++.dylib") &&
1813  getVFS().exists("/usr/lib/libstdc++.6.dylib")) {
1814  CmdArgs.push_back("/usr/lib/libstdc++.6.dylib");
1815  return;
1816  }
1817 
1818  // Otherwise, let the linker search.
1819  CmdArgs.push_back("-lstdc++");
1820  break;
1821  }
1822 }
1823 
1824 void DarwinClang::AddCCKextLibArgs(const ArgList &Args,
1825  ArgStringList &CmdArgs) const {
1826  // For Darwin platforms, use the compiler-rt-based support library
1827  // instead of the gcc-provided one (which is also incidentally
1828  // only present in the gcc lib dir, which makes it hard to find).
1829 
1830  SmallString<128> P(getDriver().ResourceDir);
1831  llvm::sys::path::append(P, "lib", "darwin");
1832 
1833  // Use the newer cc_kext for iOS ARM after 6.0.
1834  if (isTargetWatchOS()) {
1835  llvm::sys::path::append(P, "libclang_rt.cc_kext_watchos.a");
1836  } else if (isTargetTvOS()) {
1837  llvm::sys::path::append(P, "libclang_rt.cc_kext_tvos.a");
1838  } else if (isTargetIPhoneOS()) {
1839  llvm::sys::path::append(P, "libclang_rt.cc_kext_ios.a");
1840  } else {
1841  llvm::sys::path::append(P, "libclang_rt.cc_kext.a");
1842  }
1843 
1844  // For now, allow missing resource libraries to support developers who may
1845  // not have compiler-rt checked out or integrated into their build.
1846  if (getVFS().exists(P))
1847  CmdArgs.push_back(Args.MakeArgString(P));
1848 }
1849 
1850 DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args,
1851  StringRef BoundArch,
1852  Action::OffloadKind) const {
1853  DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
1854  const OptTable &Opts = getDriver().getOpts();
1855 
1856  // FIXME: We really want to get out of the tool chain level argument
1857  // translation business, as it makes the driver functionality much
1858  // more opaque. For now, we follow gcc closely solely for the
1859  // purpose of easily achieving feature parity & testability. Once we
1860  // have something that works, we should reevaluate each translation
1861  // and try to push it down into tool specific logic.
1862 
1863  for (Arg *A : Args) {
1864  if (A->getOption().matches(options::OPT_Xarch__)) {
1865  // Skip this argument unless the architecture matches either the toolchain
1866  // triple arch, or the arch being bound.
1867  llvm::Triple::ArchType XarchArch =
1869  if (!(XarchArch == getArch() ||
1870  (!BoundArch.empty() &&
1871  XarchArch ==
1873  continue;
1874 
1875  Arg *OriginalArg = A;
1876  unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
1877  unsigned Prev = Index;
1878  std::unique_ptr<Arg> XarchArg(Opts.ParseOneArg(Args, Index));
1879 
1880  // If the argument parsing failed or more than one argument was
1881  // consumed, the -Xarch_ argument's parameter tried to consume
1882  // extra arguments. Emit an error and ignore.
1883  //
1884  // We also want to disallow any options which would alter the
1885  // driver behavior; that isn't going to work in our model. We
1886  // use isDriverOption() as an approximation, although things
1887  // like -O4 are going to slip through.
1888  if (!XarchArg || Index > Prev + 1) {
1889  getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args)
1890  << A->getAsString(Args);
1891  continue;
1892  } else if (XarchArg->getOption().hasFlag(options::DriverOption)) {
1893  getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver)
1894  << A->getAsString(Args);
1895  continue;
1896  }
1897 
1898  XarchArg->setBaseArg(A);
1899 
1900  A = XarchArg.release();
1901  DAL->AddSynthesizedArg(A);
1902 
1903  // Linker input arguments require custom handling. The problem is that we
1904  // have already constructed the phase actions, so we can not treat them as
1905  // "input arguments".
1906  if (A->getOption().hasFlag(options::LinkerInput)) {
1907  // Convert the argument into individual Zlinker_input_args.
1908  for (const char *Value : A->getValues()) {
1909  DAL->AddSeparateArg(
1910  OriginalArg, Opts.getOption(options::OPT_Zlinker_input), Value);
1911  }
1912  continue;
1913  }
1914  }
1915 
1916  // Sob. These is strictly gcc compatible for the time being. Apple
1917  // gcc translates options twice, which means that self-expanding
1918  // options add duplicates.
1919  switch ((options::ID)A->getOption().getID()) {
1920  default:
1921  DAL->append(A);
1922  break;
1923 
1924  case options::OPT_mkernel:
1925  case options::OPT_fapple_kext:
1926  DAL->append(A);
1927  DAL->AddFlagArg(A, Opts.getOption(options::OPT_static));
1928  break;
1929 
1930  case options::OPT_dependency_file:
1931  DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue());
1932  break;
1933 
1934  case options::OPT_gfull:
1935  DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
1936  DAL->AddFlagArg(
1937  A, Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols));
1938  break;
1939 
1940  case options::OPT_gused:
1941  DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag));
1942  DAL->AddFlagArg(
1943  A, Opts.getOption(options::OPT_feliminate_unused_debug_symbols));
1944  break;
1945 
1946  case options::OPT_shared:
1947  DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib));
1948  break;
1949 
1950  case options::OPT_fconstant_cfstrings:
1951  DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings));
1952  break;
1953 
1954  case options::OPT_fno_constant_cfstrings:
1955  DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings));
1956  break;
1957 
1958  case options::OPT_Wnonportable_cfstrings:
1959  DAL->AddFlagArg(A,
1960  Opts.getOption(options::OPT_mwarn_nonportable_cfstrings));
1961  break;
1962 
1963  case options::OPT_Wno_nonportable_cfstrings:
1964  DAL->AddFlagArg(
1965  A, Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings));
1966  break;
1967 
1968  case options::OPT_fpascal_strings:
1969  DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings));
1970  break;
1971 
1972  case options::OPT_fno_pascal_strings:
1973  DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings));
1974  break;
1975  }
1976  }
1977 
1978  if (getTriple().getArch() == llvm::Triple::x86 ||
1979  getTriple().getArch() == llvm::Triple::x86_64)
1980  if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
1981  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ),
1982  "core2");
1983 
1984  // Add the arch options based on the particular spelling of -arch, to match
1985  // how the driver driver works.
1986  if (!BoundArch.empty()) {
1987  StringRef Name = BoundArch;
1988  const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ);
1989  const Option MArch = Opts.getOption(clang::driver::options::OPT_march_EQ);
1990 
1991  // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
1992  // which defines the list of which architectures we accept.
1993  if (Name == "ppc")
1994  ;
1995  else if (Name == "ppc601")
1996  DAL->AddJoinedArg(nullptr, MCpu, "601");
1997  else if (Name == "ppc603")
1998  DAL->AddJoinedArg(nullptr, MCpu, "603");
1999  else if (Name == "ppc604")
2000  DAL->AddJoinedArg(nullptr, MCpu, "604");
2001  else if (Name == "ppc604e")
2002  DAL->AddJoinedArg(nullptr, MCpu, "604e");
2003  else if (Name == "ppc750")
2004  DAL->AddJoinedArg(nullptr, MCpu, "750");
2005  else if (Name == "ppc7400")
2006  DAL->AddJoinedArg(nullptr, MCpu, "7400");
2007  else if (Name == "ppc7450")
2008  DAL->AddJoinedArg(nullptr, MCpu, "7450");
2009  else if (Name == "ppc970")
2010  DAL->AddJoinedArg(nullptr, MCpu, "970");
2011 
2012  else if (Name == "ppc64" || Name == "ppc64le")
2013  DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64));
2014 
2015  else if (Name == "i386")
2016  ;
2017  else if (Name == "i486")
2018  DAL->AddJoinedArg(nullptr, MArch, "i486");
2019  else if (Name == "i586")
2020  DAL->AddJoinedArg(nullptr, MArch, "i586");
2021  else if (Name == "i686")
2022  DAL->AddJoinedArg(nullptr, MArch, "i686");
2023  else if (Name == "pentium")
2024  DAL->AddJoinedArg(nullptr, MArch, "pentium");
2025  else if (Name == "pentium2")
2026  DAL->AddJoinedArg(nullptr, MArch, "pentium2");
2027  else if (Name == "pentpro")
2028  DAL->AddJoinedArg(nullptr, MArch, "pentiumpro");
2029  else if (Name == "pentIIm3")
2030  DAL->AddJoinedArg(nullptr, MArch, "pentium2");
2031 
2032  else if (Name == "x86_64" || Name == "x86_64h")
2033  DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_m64));
2034 
2035  else if (Name == "arm")
2036  DAL->AddJoinedArg(nullptr, MArch, "armv4t");
2037  else if (Name == "armv4t")
2038  DAL->AddJoinedArg(nullptr, MArch, "armv4t");
2039  else if (Name == "armv5")
2040  DAL->AddJoinedArg(nullptr, MArch, "armv5tej");
2041  else if (Name == "xscale")
2042  DAL->AddJoinedArg(nullptr, MArch, "xscale");
2043  else if (Name == "armv6")
2044  DAL->AddJoinedArg(nullptr, MArch, "armv6k");
2045  else if (Name == "armv6m")
2046  DAL->AddJoinedArg(nullptr, MArch, "armv6m");
2047  else if (Name == "armv7")
2048  DAL->AddJoinedArg(nullptr, MArch, "armv7a");
2049  else if (Name == "armv7em")
2050  DAL->AddJoinedArg(nullptr, MArch, "armv7em");
2051  else if (Name == "armv7k")
2052  DAL->AddJoinedArg(nullptr, MArch, "armv7k");
2053  else if (Name == "armv7m")
2054  DAL->AddJoinedArg(nullptr, MArch, "armv7m");
2055  else if (Name == "armv7s")
2056  DAL->AddJoinedArg(nullptr, MArch, "armv7s");
2057  }
2058 
2059  return DAL;
2060 }
2061 
2062 void MachO::AddLinkRuntimeLibArgs(const ArgList &Args,
2063  ArgStringList &CmdArgs) const {
2064  // Embedded targets are simple at the moment, not supporting sanitizers and
2065  // with different libraries for each member of the product { static, PIC } x
2066  // { hard-float, soft-float }
2067  llvm::SmallString<32> CompilerRT = StringRef("");
2068  CompilerRT +=
2070  ? "hard"
2071  : "soft";
2072  CompilerRT += Args.hasArg(options::OPT_fPIC) ? "_pic" : "_static";
2073 
2074  AddLinkRuntimeLib(Args, CmdArgs, CompilerRT, RLO_IsEmbedded);
2075 }
2076 
2078  llvm::Triple::OSType OS;
2079 
2080  switch (TargetPlatform) {
2081  case MacOS: // Earlier than 10.13.
2082  OS = llvm::Triple::MacOSX;
2083  break;
2084  case IPhoneOS:
2085  OS = llvm::Triple::IOS;
2086  break;
2087  case TvOS: // Earlier than 11.0.
2088  OS = llvm::Triple::TvOS;
2089  break;
2090  case WatchOS: // Earlier than 4.0.
2091  OS = llvm::Triple::WatchOS;
2092  break;
2093  }
2094 
2096 }
2097 
2098 void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
2099  llvm::opt::ArgStringList &CC1Args,
2100  Action::OffloadKind DeviceOffloadKind) const {
2101  // Pass "-faligned-alloc-unavailable" only when the user hasn't manually
2102  // enabled or disabled aligned allocations.
2103  if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
2104  options::OPT_fno_aligned_allocation) &&
2106  CC1Args.push_back("-faligned-alloc-unavailable");
2107 
2108  if (SDKInfo) {
2109  /// Pass the SDK version to the compiler when the SDK information is
2110  /// available.
2111  std::string Arg;
2112  llvm::raw_string_ostream OS(Arg);
2113  OS << "-target-sdk-version=" << SDKInfo->getVersion();
2114  CC1Args.push_back(DriverArgs.MakeArgString(OS.str()));
2115  }
2116 }
2117 
2118 DerivedArgList *
2119 Darwin::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
2120  Action::OffloadKind DeviceOffloadKind) const {
2121  // First get the generic Apple args, before moving onto Darwin-specific ones.
2122  DerivedArgList *DAL =
2123  MachO::TranslateArgs(Args, BoundArch, DeviceOffloadKind);
2124  const OptTable &Opts = getDriver().getOpts();
2125 
2126  // If no architecture is bound, none of the translations here are relevant.
2127  if (BoundArch.empty())
2128  return DAL;
2129 
2130  // Add an explicit version min argument for the deployment target. We do this
2131  // after argument translation because -Xarch_ arguments may add a version min
2132  // argument.
2133  AddDeploymentTarget(*DAL);
2134 
2135  // For iOS 6, undo the translation to add -static for -mkernel/-fapple-kext.
2136  // FIXME: It would be far better to avoid inserting those -static arguments,
2137  // but we can't check the deployment target in the translation code until
2138  // it is set here.
2139  if (isTargetWatchOSBased() ||
2140  (isTargetIOSBased() && !isIPhoneOSVersionLT(6, 0))) {
2141  for (ArgList::iterator it = DAL->begin(), ie = DAL->end(); it != ie; ) {
2142  Arg *A = *it;
2143  ++it;
2144  if (A->getOption().getID() != options::OPT_mkernel &&
2145  A->getOption().getID() != options::OPT_fapple_kext)
2146  continue;
2147  assert(it != ie && "unexpected argument translation");
2148  A = *it;
2149  assert(A->getOption().getID() == options::OPT_static &&
2150  "missing expected -static argument");
2151  *it = nullptr;
2152  ++it;
2153  }
2154  }
2155 
2156  if (!Args.getLastArg(options::OPT_stdlib_EQ) &&
2158  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ),
2159  "libc++");
2160 
2161  // Validate the C++ standard library choice.
2163  if (Type == ToolChain::CST_Libcxx) {
2164  // Check whether the target provides libc++.
2165  StringRef where;
2166 
2167  // Complain about targeting iOS < 5.0 in any way.
2168  if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0))
2169  where = "iOS 5.0";
2170 
2171  if (where != StringRef()) {
2172  getDriver().Diag(clang::diag::err_drv_invalid_libcxx_deployment) << where;
2173  }
2174  }
2175 
2176  auto Arch = tools::darwin::getArchTypeForMachOArchName(BoundArch);
2177  if ((Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)) {
2178  if (Args.hasFlag(options::OPT_fomit_frame_pointer,
2179  options::OPT_fno_omit_frame_pointer, false))
2180  getDriver().Diag(clang::diag::warn_drv_unsupported_opt_for_target)
2181  << "-fomit-frame-pointer" << BoundArch;
2182  }
2183 
2184  return DAL;
2185 }
2186 
2187 bool MachO::IsUnwindTablesDefault(const ArgList &Args) const {
2188  // Unwind tables are not emitted if -fno-exceptions is supplied (except when
2189  // targeting x86_64).
2190  return getArch() == llvm::Triple::x86_64 ||
2191  (GetExceptionModel(Args) != llvm::ExceptionHandling::SjLj &&
2192  Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
2193  true));
2194 }
2195 
2197  if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
2198  return S[0] != '\0';
2199  return false;
2200 }
2201 
2202 llvm::ExceptionHandling Darwin::GetExceptionModel(const ArgList &Args) const {
2203  // Darwin uses SjLj exceptions on ARM.
2204  if (getTriple().getArch() != llvm::Triple::arm &&
2205  getTriple().getArch() != llvm::Triple::thumb)
2207 
2208  // Only watchOS uses the new DWARF/Compact unwinding method.
2209  llvm::Triple Triple(ComputeLLVMTriple(Args));
2210  if (Triple.isWatchABI())
2211  return llvm::ExceptionHandling::DwarfCFI;
2212 
2213  return llvm::ExceptionHandling::SjLj;
2214 }
2215 
2217  assert(TargetInitialized && "Target not initialized!");
2218  if (isTargetIPhoneOS() && isIPhoneOSVersionLT(6, 0))
2219  return false;
2220  return true;
2221 }
2222 
2223 bool MachO::isPICDefault() const { return true; }
2224 
2225 bool MachO::isPIEDefault() const { return false; }
2226 
2228  return (getArch() == llvm::Triple::x86_64 ||
2229  getArch() == llvm::Triple::aarch64);
2230 }
2231 
2233  // Profiling instrumentation is only supported on x86.
2234  return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64;
2235 }
2236 
2237 void Darwin::addMinVersionArgs(const ArgList &Args,
2238  ArgStringList &CmdArgs) const {
2239  VersionTuple TargetVersion = getTargetVersion();
2240 
2241  if (isTargetWatchOS())
2242  CmdArgs.push_back("-watchos_version_min");
2243  else if (isTargetWatchOSSimulator())
2244  CmdArgs.push_back("-watchos_simulator_version_min");
2245  else if (isTargetTvOS())
2246  CmdArgs.push_back("-tvos_version_min");
2247  else if (isTargetTvOSSimulator())
2248  CmdArgs.push_back("-tvos_simulator_version_min");
2249  else if (isTargetIOSSimulator())
2250  CmdArgs.push_back("-ios_simulator_version_min");
2251  else if (isTargetIOSBased())
2252  CmdArgs.push_back("-iphoneos_version_min");
2253  else {
2254  assert(isTargetMacOS() && "unexpected target");
2255  CmdArgs.push_back("-macosx_version_min");
2256  }
2257 
2258  CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString()));
2259 }
2260 
2261 void Darwin::addStartObjectFileArgs(const ArgList &Args,
2262  ArgStringList &CmdArgs) const {
2263  // Derived from startfile spec.
2264  if (Args.hasArg(options::OPT_dynamiclib)) {
2265  // Derived from darwin_dylib1 spec.
2266  if (isTargetWatchOSBased()) {
2267  ; // watchOS does not need dylib1.o.
2268  } else if (isTargetIOSSimulator()) {
2269  ; // iOS simulator does not need dylib1.o.
2270  } else if (isTargetIPhoneOS()) {
2271  if (isIPhoneOSVersionLT(3, 1))
2272  CmdArgs.push_back("-ldylib1.o");
2273  } else {
2274  if (isMacosxVersionLT(10, 5))
2275  CmdArgs.push_back("-ldylib1.o");
2276  else if (isMacosxVersionLT(10, 6))
2277  CmdArgs.push_back("-ldylib1.10.5.o");
2278  }
2279  } else {
2280  if (Args.hasArg(options::OPT_bundle)) {
2281  if (!Args.hasArg(options::OPT_static)) {
2282  // Derived from darwin_bundle1 spec.
2283  if (isTargetWatchOSBased()) {
2284  ; // watchOS does not need bundle1.o.
2285  } else if (isTargetIOSSimulator()) {
2286  ; // iOS simulator does not need bundle1.o.
2287  } else if (isTargetIPhoneOS()) {
2288  if (isIPhoneOSVersionLT(3, 1))
2289  CmdArgs.push_back("-lbundle1.o");
2290  } else {
2291  if (isMacosxVersionLT(10, 6))
2292  CmdArgs.push_back("-lbundle1.o");
2293  }
2294  }
2295  } else {
2296  if (Args.hasArg(options::OPT_pg) && SupportsProfiling()) {
2297  if (isTargetMacOS() && isMacosxVersionLT(10, 9)) {
2298  if (Args.hasArg(options::OPT_static) ||
2299  Args.hasArg(options::OPT_object) ||
2300  Args.hasArg(options::OPT_preload)) {
2301  CmdArgs.push_back("-lgcrt0.o");
2302  } else {
2303  CmdArgs.push_back("-lgcrt1.o");
2304 
2305  // darwin_crt2 spec is empty.
2306  }
2307  // By default on OS X 10.8 and later, we don't link with a crt1.o
2308  // file and the linker knows to use _main as the entry point. But,
2309  // when compiling with -pg, we need to link with the gcrt1.o file,
2310  // so pass the -no_new_main option to tell the linker to use the
2311  // "start" symbol as the entry point.
2312  if (isTargetMacOS() && !isMacosxVersionLT(10, 8))
2313  CmdArgs.push_back("-no_new_main");
2314  } else {
2315  getDriver().Diag(diag::err_drv_clang_unsupported_opt_pg_darwin)
2316  << isTargetMacOS();
2317  }
2318  } else {
2319  if (Args.hasArg(options::OPT_static) ||
2320  Args.hasArg(options::OPT_object) ||
2321  Args.hasArg(options::OPT_preload)) {
2322  CmdArgs.push_back("-lcrt0.o");
2323  } else {
2324  // Derived from darwin_crt1 spec.
2325  if (isTargetWatchOSBased()) {
2326  ; // watchOS does not need crt1.o.
2327  } else if (isTargetIOSSimulator()) {
2328  ; // iOS simulator does not need crt1.o.
2329  } else if (isTargetIPhoneOS()) {
2330  if (getArch() == llvm::Triple::aarch64)
2331  ; // iOS does not need any crt1 files for arm64
2332  else if (isIPhoneOSVersionLT(3, 1))
2333  CmdArgs.push_back("-lcrt1.o");
2334  else if (isIPhoneOSVersionLT(6, 0))
2335  CmdArgs.push_back("-lcrt1.3.1.o");
2336  } else {
2337  if (isMacosxVersionLT(10, 5))
2338  CmdArgs.push_back("-lcrt1.o");
2339  else if (isMacosxVersionLT(10, 6))
2340  CmdArgs.push_back("-lcrt1.10.5.o");
2341  else if (isMacosxVersionLT(10, 8))
2342  CmdArgs.push_back("-lcrt1.10.6.o");
2343 
2344  // darwin_crt2 spec is empty.
2345  }
2346  }
2347  }
2348  }
2349  }
2350 
2351  if (!isTargetIPhoneOS() && Args.hasArg(options::OPT_shared_libgcc) &&
2352  !isTargetWatchOS() && isMacosxVersionLT(10, 5)) {
2353  const char *Str = Args.MakeArgString(GetFilePath("crt3.o"));
2354  CmdArgs.push_back(Str);
2355  }
2356 }
2357 
2358 void Darwin::CheckObjCARC() const {
2360  (isTargetMacOS() && !isMacosxVersionLT(10, 6)))
2361  return;
2362  getDriver().Diag(diag::err_arc_unsupported_on_toolchain);
2363 }
2364 
2366  const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
2368  Res |= SanitizerKind::Address;
2369  Res |= SanitizerKind::Leak;
2370  Res |= SanitizerKind::Fuzzer;
2371  Res |= SanitizerKind::FuzzerNoLink;
2372  Res |= SanitizerKind::Function;
2373 
2374  // Prior to 10.9, macOS shipped a version of the C++ standard library without
2375  // C++11 support. The same is true of iOS prior to version 5. These OS'es are
2376  // incompatible with -fsanitize=vptr.
2377  if (!(isTargetMacOS() && isMacosxVersionLT(10, 9))
2378  && !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
2379  Res |= SanitizerKind::Vptr;
2380 
2381  if (isTargetMacOS()) {
2382  if (IsX86_64)
2383  Res |= SanitizerKind::Thread;
2384  } else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) {
2385  if (IsX86_64)
2386  Res |= SanitizerKind::Thread;
2387  }
2388  return Res;
2389 }
2390 
2391 void Darwin::printVerboseInfo(raw_ostream &OS) const {
2392  CudaInstallation.print(OS);
2393 }
StringRef getSysRoot() const
Returns the sysroot path.
static bool GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor, unsigned &Micro, bool &HadExtra)
GetReleaseVersion - Parse (([0-9]+)(.
Definition: Driver.cpp:4710
StringRef getMachOArchName(const llvm::opt::ArgList &Args) const
Get the "MachO" arch name for a particular compiler invocation.
Definition: Darwin.cpp:785
virtual std::string ComputeLLVMTriple(const llvm::opt::ArgList &Args, types::ID InputType=types::TY_INVALID) const
ComputeLLVMTriple - Return the LLVM target triple to use, after taking command line arguments into ac...
Definition: ToolChain.cpp:533
bool SupportsEmbeddedBitcode() const override
SupportsEmbeddedBitcode - Does this tool chain support embedded bitcode.
Definition: Darwin.cpp:2216
bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const
Definition: Darwin.h:414
Tool * buildAssembler() const override
Definition: Darwin.cpp:856
std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const
GetTemporaryPath - Return the pathname of a temporary file to use as part of compilation; the file wi...
Definition: Driver.cpp:4489
Link the library in even if it can&#39;t be found in the VFS.
Definition: Darwin.h:179
Use the embedded runtime from the macho_embedded directory.
Definition: Darwin.h:182
const char * getTypeTempSuffix(ID Id, bool CLMode=false)
getTypeTempSuffix - Return the suffix to use when creating a temp file of this type, or null if unspecified.
Definition: Types.cpp:54
bool UseDwarfDebugFlags() const override
UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf compile unit information...
Definition: Darwin.cpp:2196
StringRef P
bool isUsingLTO() const
Returns true if we are performing any kind of LTO.
Definition: Driver.h:525
Defines types useful for describing an Objective-C runtime.
CXXStdlibType GetDefaultCXXStdlibType() const override
Definition: Darwin.cpp:707
The base class of the type hierarchy.
Definition: Type.h:1414
const XRayArgs & getXRayArgs() const
Definition: ToolChain.cpp:121
virtual void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: ToolChain.cpp:781
void AddLinkRuntimeLib(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, StringRef Component, RuntimeLinkOptions Opts=RuntimeLinkOptions(), bool IsShared=false) const
Add a runtime library to the list of items to link.
Definition: Darwin.cpp:924
bool HasNativeLLVMSupport() const override
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition: Darwin.cpp:705
bool embedBitcodeEnabled() const
Definition: Driver.h:333
constexpr XRayInstrMask Function
Definition: XRayInstr.h:38
LTOKind getLTOMode() const
Get the specific kind of LTO being performed.
Definition: Driver.h:528
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:108
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Darwin.cpp:427
void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
Add any profiling runtime libraries that are needed.
Definition: Darwin.cpp:1040
FloatABI getARMFloatABI(const ToolChain &TC, const llvm::opt::ArgList &Args)
DarwinEnvironmentKind TargetEnvironment
Definition: Darwin.h:286
CudaInstallationDetector CudaInstallation
Definition: Darwin.h:294
bool TargetInitialized
Whether the information on the target has been initialized.
Definition: Darwin.h:271
void print(raw_ostream &OS) const
Print information about the detected CUDA installation.
Definition: Cuda.cpp:275
bool hasBlocksRuntime() const override
Darwin provides a blocks runtime starting in MacOS X 10.6 and iOS 3.2.
Definition: Darwin.cpp:729
types::ID LookupTypeForExtension(StringRef Ext) const override
LookupTypeForExtension - Return the default language type to use for the given extension.
Definition: Darwin.cpp:695
&#39;macosx-fragile&#39; is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the fragil...
Definition: ObjCRuntime.h:39
const char * getFilename() const
Definition: InputInfo.h:83
path_list & getProgramPaths()
Definition: ToolChain.h:234
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: Darwin.cpp:2225
bool embedBitcodeMarkerOnly() const
Definition: Driver.h:335
ActionList & getInputs()
Definition: Action.h:142
bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override
IsUnwindTablesDefault - Does this tool chain use -funwind-tables by default.
Definition: Darwin.cpp:2187
StringRef getPlatformFamily() const
Definition: Darwin.cpp:975
std::string Dir
The path the driver executable was in, as invoked from the command line.
Definition: Driver.h:119
Darwin - The base Darwin tool chain.
Definition: Darwin.h:264
void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
Add the linker arguments to link the compiler runtime library.
Definition: Darwin.cpp:1084
ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override
Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0.
Definition: Darwin.cpp:718
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: Darwin.cpp:2223
Action - Represent an abstract compilation step to perform.
Definition: Action.h:47
static bool needsProfileRT(const llvm::opt::ArgList &Args)
needsProfileRT - returns true if instrumentation profile is on.
Definition: ToolChain.cpp:415
llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: Darwin.cpp:1850
The information about the darwin SDK that was used during this compilation.
Definition: DarwinSDKInfo.h:21
Tool * getTool(Action::ActionClass AC) const override
Definition: Darwin.cpp:835
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
static bool hasExportSymbolDirective(const ArgList &Args)
Check if the link command contains a symbol export directive.
Definition: Darwin.cpp:1020
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:444
types::ID getType() const
Definition: Action.h:140
CompileCommand Cmd
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:57
bool needsXRayRt() const
Definition: XRayArgs.h:40
types::ID getType() const
Definition: InputInfo.h:77
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: Darwin.cpp:2365
bool isTargetInitialized() const
Definition: Darwin.h:401
void AddMachOArch(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Definition: Darwin.cpp:153
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: Darwin.cpp:2227
StringRef getPlatform() const
Definition: ToolChain.h:211
llvm::ExceptionHandling GetExceptionModel(const llvm::opt::ArgList &Args) const override
GetExceptionModel - Return the tool chain exception model.
Definition: Darwin.cpp:2202
bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC, const llvm::opt::ArgList &Args, bool IsOffloadingHost=false, bool GompNeedsRT=false)
Returns true, if an OpenMP runtime has been added.
static bool shouldLinkerNotDedup(bool IsLinkerOnlyAction, const ArgList &Args)
Pass -no_deduplicate to ld64 under certain conditions:
Definition: Darwin.cpp:184
Darwin(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Darwin - Darwin tool chain for i386 and x86_64.
Definition: Darwin.cpp:691
&#39;watchos&#39; is a variant of iOS for Apple&#39;s watchOS.
Definition: ObjCRuntime.h:48
void printVerboseInfo(raw_ostream &OS) const override
Dispatch to the specific toolchain for verbose printing.
Definition: Darwin.cpp:2391
Defines a function that returns the minimum OS versions supporting C++17&#39;s aligned allocation functio...
Expected< Optional< DarwinSDKInfo > > parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath)
Parse the SDK information from the SDKSettings.json file.
bool requiresMinimalRuntime() const
Definition: SanitizerArgs.h:70
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: Darwin.cpp:2098
ActionClass getKind() const
Definition: Action.h:139
bool isTargetWatchOSBased() const
Definition: Darwin.h:391
std::string GetTemporaryDirectory(StringRef Prefix) const
GetTemporaryDirectory - Return the pathname of a temporary directory to use as part of compilation; t...
Definition: Driver.cpp:4500
&#39;macosx&#39; is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the non-fragile AB...
Definition: ObjCRuntime.h:34
llvm::StringRef getAsString(SyncScope S)
Definition: SyncScope.h:50
static void addExportedSymbol(ArgStringList &CmdArgs, const char *Symbol)
Add an export directive for Symbol to the link command.
Definition: Darwin.cpp:1035
virtual bool SupportsEmbeddedBitcode() const
SupportsEmbeddedBitcode - Does this tool chain support embedded bitcode.
Definition: ToolChain.h:465
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: Darwin.cpp:1746
VersionTuple TargetVersion
The OS version we are targeting.
Definition: Darwin.h:289
static const char * ArmMachOArchNameCPU(StringRef CPU)
Definition: Darwin.cpp:766
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:205
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add arguments to use system-specific CUDA includes.
Definition: Darwin.cpp:740
bool isObjCAutoRefCount(const llvm::opt::ArgList &Args)
bool isTargetIOSSimulator() const
Definition: Darwin.h:355
llvm::Triple::ArchType getArchTypeForMachOArchName(StringRef Str)
Definition: Darwin.cpp:33
unsigned GetDefaultDwarfVersion() const override
Definition: Darwin.cpp:916
virtual void addMinVersionArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Definition: Darwin.h:166
llvm::Triple::ArchType getArch() const
Definition: ToolChain.h:209
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Cuda.cpp:232
Link the library in before any others.
Definition: Darwin.h:188
static std::string getSystemOrSDKMacOSVersion(StringRef MacOSSDKVersion)
Returns the most appropriate macOS target version for the current process.
Definition: Darwin.cpp:1154
#define false
Definition: stdbool.h:33
Kind
llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind DeviceOffloadKind) const override
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition: Darwin.cpp:2119
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition: Darwin.cpp:2232
const llvm::opt::DerivedArgList & getArgs() const
Definition: Compilation.h:186
VersionTuple getTargetVersion() const
Definition: Darwin.h:403
const Driver & getDriver() const
Definition: ToolChain.h:193
std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, types::ID InputType) const override
ComputeEffectiveClangTriple - Return the Clang triple to use for this target, which may take into acc...
Definition: Darwin.cpp:811
bool isTargetIOSBased() const
Is the target either iOS or an iOS simulator?
Definition: Darwin.h:174
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
Definition: ToolChain.cpp:742
DarwinClang(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: Darwin.cpp:860
llvm::opt::Arg * getLastProfileUseArg(const llvm::opt::ArgList &Args)
constexpr XRayInstrMask None
Definition: XRayInstr.h:37
Optional< DarwinSDKInfo > SDKInfo
The information about the darwin SDK that was used.
Definition: Darwin.h:292
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:101
void addStartObjectFileArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
Definition: Darwin.cpp:2261
static const char * ArmMachOArchName(StringRef Arch)
Definition: Darwin.cpp:749
void AddLinkARCArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
Add the linker arguments to link the ARC runtime library.
Definition: Darwin.cpp:879
DarwinPlatformKind TargetPlatform
Definition: Darwin.h:285
Dataflow Directional Tag Classes.
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Darwin.cpp:659
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Darwin.cpp:639
static StringRef getSDKName(StringRef isysroot)
Definition: Darwin.cpp:989
void CheckObjCARC() const override
Complain if this tool chain doesn&#39;t support Objective-C ARC.
Definition: Darwin.cpp:2358
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Darwin.cpp:83
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:27
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Add the linker arguments to link the compiler runtime library.
Definition: Darwin.cpp:2062
StringRef getOSLibraryNameSuffix(bool IgnoreSim=false) const override
Definition: Darwin.cpp:1002
llvm::VersionTuple alignedAllocMinVersion(llvm::Triple::OSType OS)
unsigned getLTOParallelism(const llvm::opt::ArgList &Args, const Driver &D)
Tool - Information on a specific compilation tool.
Definition: Tool.h:33
void setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str)
Definition: Darwin.cpp:68
const SanitizerArgs & getSanitizerArgs() const
Definition: ToolChain.cpp:115
void addMinVersionArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
Definition: Darwin.cpp:2237
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
Definition: Darwin.cpp:1779
const char * getInstalledDir() const
Get the path to where the clang executable was installed.
Definition: Driver.h:321
&#39;ios&#39; is the Apple-provided NeXT-derived runtime on iOS or the iOS simulator; it is always non-fragil...
Definition: ObjCRuntime.h:44
StringRef getDefaultUniversalArchName() const
Provide the default architecture name (as expected by -arch) for this toolchain.
Definition: ToolChain.cpp:225
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
const Driver & getDriver() const
Definition: Compilation.h:133
RuntimeLinkOptions
Options to control how a runtime library is linked.
Definition: Darwin.h:177
const llvm::Triple & getTriple() const
Definition: ToolChain.h:195
Tool * buildLinker() const override
Definition: Darwin.cpp:854
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:858
ID lookupTypeForExtension(llvm::StringRef Ext)
lookupTypeForExtension - Lookup the type to use for the file extension Ext.
Definition: Types.cpp:194
virtual Tool * getTool(Action::ActionClass AC) const
Definition: ToolChain.cpp:288
Emit rpaths for as well as the resource directory.
Definition: Darwin.h:185
void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override
Add warning options that need to be passed to cc1 for this target.
Definition: Darwin.cpp:864
bool isTargetWatchOSSimulator() const
Definition: Darwin.h:386
bool isFilename() const
Definition: InputInfo.h:75
static bool needsGCovInstrumentation(const llvm::opt::ArgList &Args)
Returns true if gcov instrumentation (-fprofile-arcs or –coverage) is on.
Definition: ToolChain.cpp:430
const llvm::opt::OptTable & getOpts() const
Definition: Driver.h:298
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:723
const char * addTempFile(const char *Name)
addTempFile - Add a file to remove on exit, and returns its argument.
Definition: Compilation.h:232
RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const override
Definition: Darwin.cpp:1072
bool hasNativeARC() const
Does this runtime natively provide the ARC entrypoints?
Definition: ObjCRuntime.h:161
static bool isObjCRuntimeLinked(const ArgList &Args)
Determine whether we are linking the ObjC runtime.
Definition: Darwin.cpp:419
bool isTargetTvOSSimulator() const
Definition: Darwin.h:371
bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const
Definition: Darwin.h:408
bool hasSubscripting() const
Does this runtime directly support the subscripting methods?
Definition: ObjCRuntime.h:297
void setTarget(DarwinPlatformKind Platform, DarwinEnvironmentKind Environment, unsigned Major, unsigned Minor, unsigned Micro) const
Definition: Darwin.h:331
bool empty() const
Definition: Job.h:193
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: Darwin.cpp:617
bool isAlignedAllocationUnavailable() const
Return true if c++17 aligned allocation/deallocation functions are not implemented in the c++ standar...
Definition: Darwin.cpp:2077
void AddCCKextLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
AddCCKextLibArgs - Add the system specific linker arguments to use for kernel extensions (Darwin-spec...
Definition: Darwin.cpp:1824
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:88