ToolChains.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. //===--- ToolChains.h - ToolChain Implementations ---------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
  10. #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_H
  11. #include "Tools.h"
  12. #include "clang/Basic/VersionTuple.h"
  13. #include "clang/Driver/Action.h"
  14. #include "clang/Driver/Multilib.h"
  15. #include "clang/Driver/ToolChain.h"
  16. #include "llvm/ADT/DenseMap.h"
  17. #include "llvm/ADT/Optional.h"
  18. #include "llvm/Support/Compiler.h"
  19. #include <set>
  20. #include <vector>
  21. namespace clang {
  22. namespace driver {
  23. namespace toolchains {
  24. /// Generic_GCC - A tool chain using the 'gcc' command to perform
  25. /// all subcommands; this relies on gcc translating the majority of
  26. /// command line options.
  27. class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain {
  28. public:
  29. /// \brief Struct to store and manipulate GCC versions.
  30. ///
  31. /// We rely on assumptions about the form and structure of GCC version
  32. /// numbers: they consist of at most three '.'-separated components, and each
  33. /// component is a non-negative integer except for the last component. For
  34. /// the last component we are very flexible in order to tolerate release
  35. /// candidates or 'x' wildcards.
  36. ///
  37. /// Note that the ordering established among GCCVersions is based on the
  38. /// preferred version string to use. For example we prefer versions without
  39. /// a hard-coded patch number to those with a hard coded patch number.
  40. ///
  41. /// Currently this doesn't provide any logic for textual suffixes to patches
  42. /// in the way that (for example) Debian's version format does. If that ever
  43. /// becomes necessary, it can be added.
  44. struct GCCVersion {
  45. /// \brief The unparsed text of the version.
  46. std::string Text;
  47. /// \brief The parsed major, minor, and patch numbers.
  48. int Major, Minor, Patch;
  49. /// \brief The text of the parsed major, and major+minor versions.
  50. std::string MajorStr, MinorStr;
  51. /// \brief Any textual suffix on the patch number.
  52. std::string PatchSuffix;
  53. static GCCVersion Parse(StringRef VersionText);
  54. bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch,
  55. StringRef RHSPatchSuffix = StringRef()) const;
  56. bool operator<(const GCCVersion &RHS) const {
  57. return isOlderThan(RHS.Major, RHS.Minor, RHS.Patch, RHS.PatchSuffix);
  58. }
  59. bool operator>(const GCCVersion &RHS) const { return RHS < *this; }
  60. bool operator<=(const GCCVersion &RHS) const { return !(*this > RHS); }
  61. bool operator>=(const GCCVersion &RHS) const { return !(*this < RHS); }
  62. };
  63. /// \brief This is a class to find a viable GCC installation for Clang to
  64. /// use.
  65. ///
  66. /// This class tries to find a GCC installation on the system, and report
  67. /// information about it. It starts from the host information provided to the
  68. /// Driver, and has logic for fuzzing that where appropriate.
  69. class GCCInstallationDetector {
  70. bool IsValid;
  71. llvm::Triple GCCTriple;
  72. // FIXME: These might be better as path objects.
  73. std::string GCCInstallPath;
  74. std::string GCCParentLibPath;
  75. /// The primary multilib appropriate for the given flags.
  76. Multilib SelectedMultilib;
  77. /// On Biarch systems, this corresponds to the default multilib when
  78. /// targeting the non-default multilib. Otherwise, it is empty.
  79. llvm::Optional<Multilib> BiarchSibling;
  80. GCCVersion Version;
  81. // We retain the list of install paths that were considered and rejected in
  82. // order to print out detailed information in verbose mode.
  83. std::set<std::string> CandidateGCCInstallPaths;
  84. /// The set of multilibs that the detected installation supports.
  85. MultilibSet Multilibs;
  86. public:
  87. GCCInstallationDetector() : IsValid(false) {}
  88. void init(const Driver &D, const llvm::Triple &TargetTriple,
  89. const llvm::opt::ArgList &Args);
  90. /// \brief Check whether we detected a valid GCC install.
  91. bool isValid() const { return IsValid; }
  92. /// \brief Get the GCC triple for the detected install.
  93. const llvm::Triple &getTriple() const { return GCCTriple; }
  94. /// \brief Get the detected GCC installation path.
  95. StringRef getInstallPath() const { return GCCInstallPath; }
  96. /// \brief Get the detected GCC parent lib path.
  97. StringRef getParentLibPath() const { return GCCParentLibPath; }
  98. /// \brief Get the detected Multilib
  99. const Multilib &getMultilib() const { return SelectedMultilib; }
  100. /// \brief Get the whole MultilibSet
  101. const MultilibSet &getMultilibs() const { return Multilibs; }
  102. /// Get the biarch sibling multilib (if it exists).
  103. /// \return true iff such a sibling exists
  104. bool getBiarchSibling(Multilib &M) const;
  105. /// \brief Get the detected GCC version string.
  106. const GCCVersion &getVersion() const { return Version; }
  107. /// \brief Print information about the detected GCC installation.
  108. void print(raw_ostream &OS) const;
  109. private:
  110. static void
  111. CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
  112. const llvm::Triple &BiarchTriple,
  113. SmallVectorImpl<StringRef> &LibDirs,
  114. SmallVectorImpl<StringRef> &TripleAliases,
  115. SmallVectorImpl<StringRef> &BiarchLibDirs,
  116. SmallVectorImpl<StringRef> &BiarchTripleAliases);
  117. void ScanLibDirForGCCTriple(const llvm::Triple &TargetArch,
  118. const llvm::opt::ArgList &Args,
  119. const std::string &LibDir,
  120. StringRef CandidateTriple,
  121. bool NeedsBiarchSuffix = false);
  122. };
  123. protected:
  124. GCCInstallationDetector GCCInstallation;
  125. public:
  126. Generic_GCC(const Driver &D, const llvm::Triple &Triple,
  127. const llvm::opt::ArgList &Args);
  128. ~Generic_GCC() override;
  129. void printVerboseInfo(raw_ostream &OS) const override;
  130. bool IsUnwindTablesDefault() const override;
  131. bool isPICDefault() const override;
  132. bool isPIEDefault() const override;
  133. bool isPICDefaultForced() const override;
  134. bool IsIntegratedAssemblerDefault() const override;
  135. protected:
  136. Tool *getTool(Action::ActionClass AC) const override;
  137. Tool *buildAssembler() const override;
  138. Tool *buildLinker() const override;
  139. /// \name ToolChain Implementation Helper Functions
  140. /// @{
  141. /// \brief Check whether the target triple's architecture is 64-bits.
  142. bool isTarget64Bit() const { return getTriple().isArch64Bit(); }
  143. /// \brief Check whether the target triple's architecture is 32-bits.
  144. bool isTarget32Bit() const { return getTriple().isArch32Bit(); }
  145. /// @}
  146. private:
  147. mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocess;
  148. mutable std::unique_ptr<tools::gcc::Compiler> Compile;
  149. };
  150. class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
  151. protected:
  152. Tool *buildAssembler() const override;
  153. Tool *buildLinker() const override;
  154. Tool *getTool(Action::ActionClass AC) const override;
  155. private:
  156. mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
  157. mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;
  158. mutable std::unique_ptr<tools::darwin::VerifyDebug> VerifyDebug;
  159. public:
  160. MachO(const Driver &D, const llvm::Triple &Triple,
  161. const llvm::opt::ArgList &Args);
  162. ~MachO() override;
  163. /// @name MachO specific toolchain API
  164. /// {
  165. /// Get the "MachO" arch name for a particular compiler invocation. For
  166. /// example, Apple treats different ARM variations as distinct architectures.
  167. StringRef getMachOArchName(const llvm::opt::ArgList &Args) const;
  168. /// Add the linker arguments to link the ARC runtime library.
  169. virtual void AddLinkARCArgs(const llvm::opt::ArgList &Args,
  170. llvm::opt::ArgStringList &CmdArgs) const {}
  171. /// Add the linker arguments to link the compiler runtime library.
  172. virtual void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
  173. llvm::opt::ArgStringList &CmdArgs) const;
  174. virtual void addStartObjectFileArgs(const llvm::opt::ArgList &Args,
  175. llvm::opt::ArgStringList &CmdArgs) const {
  176. }
  177. virtual void addMinVersionArgs(const llvm::opt::ArgList &Args,
  178. llvm::opt::ArgStringList &CmdArgs) const {}
  179. /// On some iOS platforms, kernel and kernel modules were built statically. Is
  180. /// this such a target?
  181. virtual bool isKernelStatic() const { return false; }
  182. /// Is the target either iOS or an iOS simulator?
  183. bool isTargetIOSBased() const { return false; }
  184. void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
  185. llvm::opt::ArgStringList &CmdArgs,
  186. StringRef DarwinLibName, bool AlwaysLink = false,
  187. bool IsEmbedded = false, bool AddRPath = false) const;
  188. /// Add any profiling runtime libraries that are needed. This is essentially a
  189. /// MachO specific version of addProfileRT in Tools.cpp.
  190. virtual void addProfileRTLibs(const llvm::opt::ArgList &Args,
  191. llvm::opt::ArgStringList &CmdArgs) const {
  192. // There aren't any profiling libs for embedded targets currently.
  193. }
  194. /// }
  195. /// @name ToolChain Implementation
  196. /// {
  197. std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
  198. types::ID InputType) const override;
  199. types::ID LookupTypeForExtension(const char *Ext) const override;
  200. bool HasNativeLLVMSupport() const override;
  201. llvm::opt::DerivedArgList *
  202. TranslateArgs(const llvm::opt::DerivedArgList &Args,
  203. const char *BoundArch) const override;
  204. bool IsBlocksDefault() const override {
  205. // Always allow blocks on Apple; users interested in versioning are
  206. // expected to use /usr/include/Block.h.
  207. return true;
  208. }
  209. bool IsIntegratedAssemblerDefault() const override {
  210. // Default integrated assembler to on for Apple's MachO targets.
  211. return true;
  212. }
  213. bool IsMathErrnoDefault() const override { return false; }
  214. bool IsEncodeExtendedBlockSignatureDefault() const override { return true; }
  215. bool IsObjCNonFragileABIDefault() const override {
  216. // Non-fragile ABI is default for everything but i386.
  217. return getTriple().getArch() != llvm::Triple::x86;
  218. }
  219. bool UseObjCMixedDispatch() const override { return true; }
  220. bool IsUnwindTablesDefault() const override;
  221. RuntimeLibType GetDefaultRuntimeLibType() const override {
  222. return ToolChain::RLT_CompilerRT;
  223. }
  224. bool isPICDefault() const override;
  225. bool isPIEDefault() const override;
  226. bool isPICDefaultForced() const override;
  227. bool SupportsProfiling() const override;
  228. bool SupportsObjCGC() const override { return false; }
  229. bool UseDwarfDebugFlags() const override;
  230. bool UseSjLjExceptions() const override { return false; }
  231. /// }
  232. };
  233. /// Darwin - The base Darwin tool chain.
  234. class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
  235. public:
  236. /// Whether the information on the target has been initialized.
  237. //
  238. // FIXME: This should be eliminated. What we want to do is make this part of
  239. // the "default target for arguments" selection process, once we get out of
  240. // the argument translation business.
  241. mutable bool TargetInitialized;
  242. enum DarwinPlatformKind { MacOS, IPhoneOS, IPhoneOSSimulator };
  243. mutable DarwinPlatformKind TargetPlatform;
  244. /// The OS version we are targeting.
  245. mutable VersionTuple TargetVersion;
  246. private:
  247. void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
  248. public:
  249. Darwin(const Driver &D, const llvm::Triple &Triple,
  250. const llvm::opt::ArgList &Args);
  251. ~Darwin() override;
  252. std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
  253. types::ID InputType) const override;
  254. /// @name Apple Specific Toolchain Implementation
  255. /// {
  256. void addMinVersionArgs(const llvm::opt::ArgList &Args,
  257. llvm::opt::ArgStringList &CmdArgs) const override;
  258. void addStartObjectFileArgs(const llvm::opt::ArgList &Args,
  259. llvm::opt::ArgStringList &CmdArgs) const override;
  260. bool isKernelStatic() const override {
  261. return !isTargetIPhoneOS() || isIPhoneOSVersionLT(6, 0);
  262. }
  263. void addProfileRTLibs(const llvm::opt::ArgList &Args,
  264. llvm::opt::ArgStringList &CmdArgs) const override;
  265. protected:
  266. /// }
  267. /// @name Darwin specific Toolchain functions
  268. /// {
  269. // FIXME: Eliminate these ...Target functions and derive separate tool chains
  270. // for these targets and put version in constructor.
  271. void setTarget(DarwinPlatformKind Platform, unsigned Major, unsigned Minor,
  272. unsigned Micro) const {
  273. // FIXME: For now, allow reinitialization as long as values don't
  274. // change. This will go away when we move away from argument translation.
  275. if (TargetInitialized && TargetPlatform == Platform &&
  276. TargetVersion == VersionTuple(Major, Minor, Micro))
  277. return;
  278. assert(!TargetInitialized && "Target already initialized!");
  279. TargetInitialized = true;
  280. TargetPlatform = Platform;
  281. TargetVersion = VersionTuple(Major, Minor, Micro);
  282. }
  283. bool isTargetIPhoneOS() const {
  284. assert(TargetInitialized && "Target not initialized!");
  285. return TargetPlatform == IPhoneOS;
  286. }
  287. bool isTargetIOSSimulator() const {
  288. assert(TargetInitialized && "Target not initialized!");
  289. return TargetPlatform == IPhoneOSSimulator;
  290. }
  291. bool isTargetIOSBased() const {
  292. assert(TargetInitialized && "Target not initialized!");
  293. return isTargetIPhoneOS() || isTargetIOSSimulator();
  294. }
  295. bool isTargetMacOS() const {
  296. assert(TargetInitialized && "Target not initialized!");
  297. return TargetPlatform == MacOS;
  298. }
  299. bool isTargetInitialized() const { return TargetInitialized; }
  300. VersionTuple getTargetVersion() const {
  301. assert(TargetInitialized && "Target not initialized!");
  302. return TargetVersion;
  303. }
  304. bool isIPhoneOSVersionLT(unsigned V0, unsigned V1 = 0,
  305. unsigned V2 = 0) const {
  306. assert(isTargetIOSBased() && "Unexpected call for non iOS target!");
  307. return TargetVersion < VersionTuple(V0, V1, V2);
  308. }
  309. bool isMacosxVersionLT(unsigned V0, unsigned V1 = 0, unsigned V2 = 0) const {
  310. assert(isTargetMacOS() && "Unexpected call for non OS X target!");
  311. return TargetVersion < VersionTuple(V0, V1, V2);
  312. }
  313. public:
  314. /// }
  315. /// @name ToolChain Implementation
  316. /// {
  317. // Darwin tools support multiple architecture (e.g., i386 and x86_64) and
  318. // most development is done against SDKs, so compiling for a different
  319. // architecture should not get any special treatment.
  320. bool isCrossCompiling() const override { return false; }
  321. llvm::opt::DerivedArgList *
  322. TranslateArgs(const llvm::opt::DerivedArgList &Args,
  323. const char *BoundArch) const override;
  324. ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
  325. bool hasBlocksRuntime() const override;
  326. bool UseObjCMixedDispatch() const override {
  327. // This is only used with the non-fragile ABI and non-legacy dispatch.
  328. // Mixed dispatch is used everywhere except OS X before 10.6.
  329. return !(isTargetMacOS() && isMacosxVersionLT(10, 6));
  330. }
  331. unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
  332. // Stack protectors default to on for user code on 10.5,
  333. // and for everything in 10.6 and beyond
  334. if (isTargetIOSBased())
  335. return 1;
  336. else if (isTargetMacOS() && !isMacosxVersionLT(10, 6))
  337. return 1;
  338. else if (isTargetMacOS() && !isMacosxVersionLT(10, 5) && !KernelOrKext)
  339. return 1;
  340. return 0;
  341. }
  342. bool SupportsObjCGC() const override;
  343. void CheckObjCARC() const override;
  344. bool UseSjLjExceptions() const override;
  345. SanitizerMask getSupportedSanitizers() const override;
  346. };
  347. /// DarwinClang - The Darwin toolchain used by Clang.
  348. class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
  349. public:
  350. DarwinClang(const Driver &D, const llvm::Triple &Triple,
  351. const llvm::opt::ArgList &Args);
  352. /// @name Apple ToolChain Implementation
  353. /// {
  354. void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
  355. llvm::opt::ArgStringList &CmdArgs) const override;
  356. void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
  357. llvm::opt::ArgStringList &CmdArgs) const override;
  358. void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
  359. llvm::opt::ArgStringList &CmdArgs) const override;
  360. void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
  361. void AddLinkARCArgs(const llvm::opt::ArgList &Args,
  362. llvm::opt::ArgStringList &CmdArgs) const override;
  363. /// }
  364. private:
  365. void AddLinkSanitizerLibArgs(const llvm::opt::ArgList &Args,
  366. llvm::opt::ArgStringList &CmdArgs,
  367. StringRef Sanitizer) const;
  368. };
  369. class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC {
  370. virtual void anchor();
  371. public:
  372. Generic_ELF(const Driver &D, const llvm::Triple &Triple,
  373. const llvm::opt::ArgList &Args)
  374. : Generic_GCC(D, Triple, Args) {}
  375. void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
  376. llvm::opt::ArgStringList &CC1Args) const override;
  377. };
  378. class LLVM_LIBRARY_VISIBILITY CloudABI : public Generic_ELF {
  379. public:
  380. CloudABI(const Driver &D, const llvm::Triple &Triple,
  381. const llvm::opt::ArgList &Args);
  382. bool HasNativeLLVMSupport() const override { return true; }
  383. bool IsMathErrnoDefault() const override { return false; }
  384. bool IsObjCNonFragileABIDefault() const override { return true; }
  385. CXXStdlibType
  386. GetCXXStdlibType(const llvm::opt::ArgList &Args) const override {
  387. return ToolChain::CST_Libcxx;
  388. }
  389. void AddClangCXXStdlibIncludeArgs(
  390. const llvm::opt::ArgList &DriverArgs,
  391. llvm::opt::ArgStringList &CC1Args) const override;
  392. void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
  393. llvm::opt::ArgStringList &CmdArgs) const override;
  394. bool isPIEDefault() const override { return false; }
  395. protected:
  396. Tool *buildLinker() const override;
  397. };
  398. class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
  399. public:
  400. Solaris(const Driver &D, const llvm::Triple &Triple,
  401. const llvm::opt::ArgList &Args);
  402. bool IsIntegratedAssemblerDefault() const override { return true; }
  403. protected:
  404. Tool *buildAssembler() const override;
  405. Tool *buildLinker() const override;
  406. };
  407. class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain {
  408. public:
  409. MinGW(const Driver &D, const llvm::Triple &Triple,
  410. const llvm::opt::ArgList &Args);
  411. bool IsIntegratedAssemblerDefault() const override;
  412. bool IsUnwindTablesDefault() const override;
  413. bool isPICDefault() const override;
  414. bool isPIEDefault() const override;
  415. bool isPICDefaultForced() const override;
  416. bool UseSEHExceptions() const;
  417. void
  418. AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  419. llvm::opt::ArgStringList &CC1Args) const override;
  420. void AddClangCXXStdlibIncludeArgs(
  421. const llvm::opt::ArgList &DriverArgs,
  422. llvm::opt::ArgStringList &CC1Args) const override;
  423. protected:
  424. Tool *getTool(Action::ActionClass AC) const override;
  425. Tool *buildLinker() const override;
  426. Tool *buildAssembler() const override;
  427. private:
  428. std::string Base;
  429. std::string GccLibDir;
  430. std::string Ver;
  431. std::string Arch;
  432. mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocessor;
  433. mutable std::unique_ptr<tools::gcc::Compiler> Compiler;
  434. void findGccLibDir();
  435. };
  436. class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF {
  437. public:
  438. OpenBSD(const Driver &D, const llvm::Triple &Triple,
  439. const llvm::opt::ArgList &Args);
  440. bool IsMathErrnoDefault() const override { return false; }
  441. bool IsObjCNonFragileABIDefault() const override { return true; }
  442. bool isPIEDefault() const override { return true; }
  443. unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
  444. return 2;
  445. }
  446. protected:
  447. Tool *buildAssembler() const override;
  448. Tool *buildLinker() const override;
  449. };
  450. class LLVM_LIBRARY_VISIBILITY Bitrig : public Generic_ELF {
  451. public:
  452. Bitrig(const Driver &D, const llvm::Triple &Triple,
  453. const llvm::opt::ArgList &Args);
  454. bool IsMathErrnoDefault() const override { return false; }
  455. bool IsObjCNonFragileABIDefault() const override { return true; }
  456. CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
  457. void AddClangCXXStdlibIncludeArgs(
  458. const llvm::opt::ArgList &DriverArgs,
  459. llvm::opt::ArgStringList &CC1Args) const override;
  460. void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
  461. llvm::opt::ArgStringList &CmdArgs) const override;
  462. unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
  463. return 1;
  464. }
  465. protected:
  466. Tool *buildAssembler() const override;
  467. Tool *buildLinker() const override;
  468. };
  469. class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF {
  470. public:
  471. FreeBSD(const Driver &D, const llvm::Triple &Triple,
  472. const llvm::opt::ArgList &Args);
  473. bool HasNativeLLVMSupport() const override;
  474. bool IsMathErrnoDefault() const override { return false; }
  475. bool IsObjCNonFragileABIDefault() const override { return true; }
  476. CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
  477. void AddClangCXXStdlibIncludeArgs(
  478. const llvm::opt::ArgList &DriverArgs,
  479. llvm::opt::ArgStringList &CC1Args) const override;
  480. bool UseSjLjExceptions() const override;
  481. bool isPIEDefault() const override;
  482. SanitizerMask getSupportedSanitizers() const override;
  483. protected:
  484. Tool *buildAssembler() const override;
  485. Tool *buildLinker() const override;
  486. };
  487. class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF {
  488. public:
  489. NetBSD(const Driver &D, const llvm::Triple &Triple,
  490. const llvm::opt::ArgList &Args);
  491. bool IsMathErrnoDefault() const override { return false; }
  492. bool IsObjCNonFragileABIDefault() const override { return true; }
  493. CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
  494. void AddClangCXXStdlibIncludeArgs(
  495. const llvm::opt::ArgList &DriverArgs,
  496. llvm::opt::ArgStringList &CC1Args) const override;
  497. bool IsUnwindTablesDefault() const override { return true; }
  498. protected:
  499. Tool *buildAssembler() const override;
  500. Tool *buildLinker() const override;
  501. };
  502. class LLVM_LIBRARY_VISIBILITY Minix : public Generic_ELF {
  503. public:
  504. Minix(const Driver &D, const llvm::Triple &Triple,
  505. const llvm::opt::ArgList &Args);
  506. protected:
  507. Tool *buildAssembler() const override;
  508. Tool *buildLinker() const override;
  509. };
  510. class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF {
  511. public:
  512. DragonFly(const Driver &D, const llvm::Triple &Triple,
  513. const llvm::opt::ArgList &Args);
  514. bool IsMathErrnoDefault() const override { return false; }
  515. protected:
  516. Tool *buildAssembler() const override;
  517. Tool *buildLinker() const override;
  518. };
  519. class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
  520. public:
  521. Linux(const Driver &D, const llvm::Triple &Triple,
  522. const llvm::opt::ArgList &Args);
  523. bool HasNativeLLVMSupport() const override;
  524. void
  525. AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  526. llvm::opt::ArgStringList &CC1Args) const override;
  527. void AddClangCXXStdlibIncludeArgs(
  528. const llvm::opt::ArgList &DriverArgs,
  529. llvm::opt::ArgStringList &CC1Args) const override;
  530. bool isPIEDefault() const override;
  531. SanitizerMask getSupportedSanitizers() const override;
  532. std::string Linker;
  533. std::vector<std::string> ExtraOpts;
  534. protected:
  535. Tool *buildAssembler() const override;
  536. Tool *buildLinker() const override;
  537. private:
  538. static bool addLibStdCXXIncludePaths(Twine Base, Twine Suffix,
  539. StringRef GCCTriple,
  540. StringRef GCCMultiarchTriple,
  541. StringRef TargetMultiarchTriple,
  542. Twine IncludeSuffix,
  543. const llvm::opt::ArgList &DriverArgs,
  544. llvm::opt::ArgStringList &CC1Args);
  545. std::string computeSysRoot() const;
  546. };
  547. class LLVM_LIBRARY_VISIBILITY CudaToolChain : public Linux {
  548. public:
  549. CudaToolChain(const Driver &D, const llvm::Triple &Triple,
  550. const llvm::opt::ArgList &Args);
  551. llvm::opt::DerivedArgList *
  552. TranslateArgs(const llvm::opt::DerivedArgList &Args,
  553. const char *BoundArch) const override;
  554. void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
  555. llvm::opt::ArgStringList &CC1Args) const override;
  556. };
  557. class LLVM_LIBRARY_VISIBILITY Hexagon_TC : public Linux {
  558. protected:
  559. GCCVersion GCCLibAndIncVersion;
  560. Tool *buildAssembler() const override;
  561. Tool *buildLinker() const override;
  562. public:
  563. Hexagon_TC(const Driver &D, const llvm::Triple &Triple,
  564. const llvm::opt::ArgList &Args);
  565. ~Hexagon_TC() override;
  566. void
  567. AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  568. llvm::opt::ArgStringList &CC1Args) const override;
  569. void AddClangCXXStdlibIncludeArgs(
  570. const llvm::opt::ArgList &DriverArgs,
  571. llvm::opt::ArgStringList &CC1Args) const override;
  572. CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
  573. StringRef GetGCCLibAndIncVersion() const { return GCCLibAndIncVersion.Text; }
  574. static std::string GetGnuDir(const std::string &InstalledDir,
  575. const llvm::opt::ArgList &Args);
  576. static StringRef GetTargetCPU(const llvm::opt::ArgList &Args);
  577. static const char *GetSmallDataThreshold(const llvm::opt::ArgList &Args);
  578. static bool UsesG0(const char *smallDataThreshold);
  579. };
  580. class LLVM_LIBRARY_VISIBILITY NaCl_TC : public Generic_ELF {
  581. public:
  582. NaCl_TC(const Driver &D, const llvm::Triple &Triple,
  583. const llvm::opt::ArgList &Args);
  584. void
  585. AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  586. llvm::opt::ArgStringList &CC1Args) const override;
  587. void AddClangCXXStdlibIncludeArgs(
  588. const llvm::opt::ArgList &DriverArgs,
  589. llvm::opt::ArgStringList &CC1Args) const override;
  590. CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
  591. void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
  592. llvm::opt::ArgStringList &CmdArgs) const override;
  593. bool IsIntegratedAssemblerDefault() const override {
  594. return getTriple().getArch() == llvm::Triple::mipsel;
  595. }
  596. // Get the path to the file containing NaCl's ARM macros. It lives in NaCl_TC
  597. // because the AssembleARM tool needs a const char * that it can pass around
  598. // and the toolchain outlives all the jobs.
  599. const char *GetNaClArmMacrosPath() const { return NaClArmMacrosPath.c_str(); }
  600. std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
  601. types::ID InputType) const override;
  602. std::string Linker;
  603. protected:
  604. Tool *buildLinker() const override;
  605. Tool *buildAssembler() const override;
  606. private:
  607. std::string NaClArmMacrosPath;
  608. };
  609. /// TCEToolChain - A tool chain using the llvm bitcode tools to perform
  610. /// all subcommands. See http://tce.cs.tut.fi for our peculiar target.
  611. class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain {
  612. public:
  613. TCEToolChain(const Driver &D, const llvm::Triple &Triple,
  614. const llvm::opt::ArgList &Args);
  615. ~TCEToolChain() override;
  616. bool IsMathErrnoDefault() const override;
  617. bool isPICDefault() const override;
  618. bool isPIEDefault() const override;
  619. bool isPICDefaultForced() const override;
  620. };
  621. class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public ToolChain {
  622. public:
  623. MSVCToolChain(const Driver &D, const llvm::Triple &Triple,
  624. const llvm::opt::ArgList &Args);
  625. bool IsIntegratedAssemblerDefault() const override;
  626. bool IsUnwindTablesDefault() const override;
  627. bool isPICDefault() const override;
  628. bool isPIEDefault() const override;
  629. bool isPICDefaultForced() const override;
  630. void
  631. AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  632. llvm::opt::ArgStringList &CC1Args) const override;
  633. void AddClangCXXStdlibIncludeArgs(
  634. const llvm::opt::ArgList &DriverArgs,
  635. llvm::opt::ArgStringList &CC1Args) const override;
  636. bool getWindowsSDKDir(std::string &path, int &major, int &minor) const;
  637. bool getWindowsSDKLibraryPath(std::string &path) const;
  638. bool getVisualStudioInstallDir(std::string &path) const;
  639. bool getVisualStudioBinariesFolder(const char *clangProgramPath,
  640. std::string &path) const;
  641. std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
  642. types::ID InputType) const override;
  643. SanitizerMask getSupportedSanitizers() const override;
  644. protected:
  645. void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList &DriverArgs,
  646. llvm::opt::ArgStringList &CC1Args,
  647. const std::string &folder,
  648. const char *subfolder) const;
  649. Tool *buildLinker() const override;
  650. Tool *buildAssembler() const override;
  651. };
  652. class LLVM_LIBRARY_VISIBILITY CrossWindowsToolChain : public Generic_GCC {
  653. public:
  654. CrossWindowsToolChain(const Driver &D, const llvm::Triple &T,
  655. const llvm::opt::ArgList &Args);
  656. bool IsIntegratedAssemblerDefault() const override { return true; }
  657. bool IsUnwindTablesDefault() const override;
  658. bool isPICDefault() const override;
  659. bool isPIEDefault() const override;
  660. bool isPICDefaultForced() const override;
  661. unsigned int GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
  662. return 0;
  663. }
  664. void
  665. AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  666. llvm::opt::ArgStringList &CC1Args) const override;
  667. void AddClangCXXStdlibIncludeArgs(
  668. const llvm::opt::ArgList &DriverArgs,
  669. llvm::opt::ArgStringList &CC1Args) const override;
  670. void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
  671. llvm::opt::ArgStringList &CmdArgs) const override;
  672. protected:
  673. Tool *buildLinker() const override;
  674. Tool *buildAssembler() const override;
  675. };
  676. class LLVM_LIBRARY_VISIBILITY XCore : public ToolChain {
  677. public:
  678. XCore(const Driver &D, const llvm::Triple &Triple,
  679. const llvm::opt::ArgList &Args);
  680. protected:
  681. Tool *buildAssembler() const override;
  682. Tool *buildLinker() const override;
  683. public:
  684. bool isPICDefault() const override;
  685. bool isPIEDefault() const override;
  686. bool isPICDefaultForced() const override;
  687. bool SupportsProfiling() const override;
  688. bool hasBlocksRuntime() const override;
  689. void
  690. AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  691. llvm::opt::ArgStringList &CC1Args) const override;
  692. void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
  693. llvm::opt::ArgStringList &CC1Args) const override;
  694. void AddClangCXXStdlibIncludeArgs(
  695. const llvm::opt::ArgList &DriverArgs,
  696. llvm::opt::ArgStringList &CC1Args) const override;
  697. void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
  698. llvm::opt::ArgStringList &CmdArgs) const override;
  699. };
  700. /// SHAVEToolChain - A tool chain using the compiler installed by the the
  701. // Movidius SDK into MV_TOOLS_DIR (which we assume will be copied to llvm's
  702. // installation dir) to perform all subcommands.
  703. class LLVM_LIBRARY_VISIBILITY SHAVEToolChain : public Generic_GCC {
  704. public:
  705. SHAVEToolChain(const Driver &D, const llvm::Triple &Triple,
  706. const llvm::opt::ArgList &Args);
  707. ~SHAVEToolChain() override;
  708. virtual Tool *SelectTool(const JobAction &JA) const override;
  709. protected:
  710. Tool *getTool(Action::ActionClass AC) const override;
  711. Tool *buildAssembler() const override;
  712. Tool *buildLinker() const override;
  713. private:
  714. mutable std::unique_ptr<Tool> Compiler;
  715. mutable std::unique_ptr<Tool> Assembler;
  716. };
  717. } // end namespace toolchains
  718. } // end namespace driver
  719. } // end namespace clang
  720. #endif