ToolChains.h revision 8aa76ea4472349e081d046f7b21dc1e54014f335
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 10#ifndef CLANG_LIB_DRIVER_TOOLCHAINS_H_ 11#define CLANG_LIB_DRIVER_TOOLCHAINS_H_ 12 13#include "clang/Driver/Action.h" 14#include "clang/Driver/ToolChain.h" 15 16#include "llvm/ADT/DenseMap.h" 17#include "llvm/Support/Compiler.h" 18 19#include "Tools.h" 20 21namespace clang { 22namespace driver { 23namespace toolchains { 24 25/// Generic_GCC - A tool chain using the 'gcc' command to perform 26/// all subcommands; this relies on gcc translating the majority of 27/// command line options. 28class LLVM_LIBRARY_VISIBILITY Generic_GCC : public ToolChain { 29protected: 30 mutable llvm::DenseMap<unsigned, Tool*> Tools; 31 32public: 33 Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple); 34 ~Generic_GCC(); 35 36 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 37 const ActionList &Inputs) const; 38 39 virtual bool IsUnwindTablesDefault() const; 40 virtual const char *GetDefaultRelocationModel() const; 41 virtual const char *GetForcedPicModel() const; 42}; 43 44/// Darwin - The base Darwin tool chain. 45class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain { 46public: 47 /// The host version. 48 unsigned DarwinVersion[3]; 49 50private: 51 mutable llvm::DenseMap<unsigned, Tool*> Tools; 52 53 /// Whether the information on the target has been initialized. 54 // 55 // FIXME: This should be eliminated. What we want to do is make this part of 56 // the "default target for arguments" selection process, once we get out of 57 // the argument translation business. 58 mutable bool TargetInitialized; 59 60 // FIXME: Remove this once there is a proper way to detect an ARC runtime 61 // for the simulator. 62 public: 63 mutable enum { 64 ARCSimulator_None, 65 ARCSimulator_HasARCRuntime, 66 ARCSimulator_NoARCRuntime 67 } ARCRuntimeForSimulator; 68 69private: 70 /// Whether we are targeting iPhoneOS target. 71 mutable bool TargetIsIPhoneOS; 72 73 /// Whether we are targeting the iPhoneOS simulator target. 74 mutable bool TargetIsIPhoneOSSimulator; 75 76 /// The OS version we are targeting. 77 mutable unsigned TargetVersion[3]; 78 79 /// The default macosx-version-min of this tool chain; empty until 80 /// initialized. 81 std::string MacosxVersionMin; 82 83 bool hasARCRuntime() const; 84 85private: 86 void AddDeploymentTarget(DerivedArgList &Args) const; 87 88public: 89 Darwin(const HostInfo &Host, const llvm::Triple& Triple); 90 ~Darwin(); 91 92 std::string ComputeEffectiveClangTriple(const ArgList &Args, 93 types::ID InputType) const; 94 95 /// @name Darwin Specific Toolchain API 96 /// { 97 98 // FIXME: Eliminate these ...Target functions and derive separate tool chains 99 // for these targets and put version in constructor. 100 void setTarget(bool IsIPhoneOS, unsigned Major, unsigned Minor, 101 unsigned Micro, bool IsIOSSim) const { 102 assert((!IsIOSSim || IsIPhoneOS) && "Unexpected deployment target!"); 103 104 // FIXME: For now, allow reinitialization as long as values don't 105 // change. This will go away when we move away from argument translation. 106 if (TargetInitialized && TargetIsIPhoneOS == IsIPhoneOS && 107 TargetIsIPhoneOSSimulator == IsIOSSim && 108 TargetVersion[0] == Major && TargetVersion[1] == Minor && 109 TargetVersion[2] == Micro) 110 return; 111 112 assert(!TargetInitialized && "Target already initialized!"); 113 TargetInitialized = true; 114 TargetIsIPhoneOS = IsIPhoneOS; 115 TargetIsIPhoneOSSimulator = IsIOSSim; 116 TargetVersion[0] = Major; 117 TargetVersion[1] = Minor; 118 TargetVersion[2] = Micro; 119 } 120 121 bool isTargetIPhoneOS() const { 122 assert(TargetInitialized && "Target not initialized!"); 123 return TargetIsIPhoneOS; 124 } 125 126 bool isTargetIOSSimulator() const { 127 assert(TargetInitialized && "Target not initialized!"); 128 return TargetIsIPhoneOSSimulator; 129 } 130 131 bool isTargetInitialized() const { return TargetInitialized; } 132 133 void getTargetVersion(unsigned (&Res)[3]) const { 134 assert(TargetInitialized && "Target not initialized!"); 135 Res[0] = TargetVersion[0]; 136 Res[1] = TargetVersion[1]; 137 Res[2] = TargetVersion[2]; 138 } 139 140 /// getDarwinArchName - Get the "Darwin" arch name for a particular compiler 141 /// invocation. For example, Darwin treats different ARM variations as 142 /// distinct architectures. 143 StringRef getDarwinArchName(const ArgList &Args) const; 144 145 static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) { 146 for (unsigned i=0; i < 3; ++i) { 147 if (A[i] > B[i]) return false; 148 if (A[i] < B[i]) return true; 149 } 150 return false; 151 } 152 153 bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const { 154 assert(isTargetIPhoneOS() && "Unexpected call for OS X target!"); 155 unsigned B[3] = { V0, V1, V2 }; 156 return isVersionLT(TargetVersion, B); 157 } 158 159 bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const { 160 assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!"); 161 unsigned B[3] = { V0, V1, V2 }; 162 return isVersionLT(TargetVersion, B); 163 } 164 165 /// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs. 166 /// 167 /// \param Args - The input argument list. 168 /// \param CmdArgs [out] - The command argument list to append the paths 169 /// (prefixed by -L) to. 170 virtual void AddLinkSearchPathArgs(const ArgList &Args, 171 ArgStringList &CmdArgs) const = 0; 172 173 /// AddLinkARCArgs - Add the linker arguments to link the ARC runtime library. 174 virtual void AddLinkARCArgs(const ArgList &Args, 175 ArgStringList &CmdArgs) const = 0; 176 177 /// AddLinkRuntimeLibArgs - Add the linker arguments to link the compiler 178 /// runtime library. 179 virtual void AddLinkRuntimeLibArgs(const ArgList &Args, 180 ArgStringList &CmdArgs) const = 0; 181 182 /// } 183 /// @name ToolChain Implementation 184 /// { 185 186 virtual types::ID LookupTypeForExtension(const char *Ext) const; 187 188 virtual bool HasNativeLLVMSupport() const; 189 190 virtual void configureObjCRuntime(ObjCRuntime &runtime) const; 191 virtual bool hasBlocksRuntime() const; 192 193 virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args, 194 const char *BoundArch) const; 195 196 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 197 const ActionList &Inputs) const; 198 199 virtual bool IsBlocksDefault() const { 200 // Always allow blocks on Darwin; users interested in versioning are 201 // expected to use /usr/include/Blocks.h. 202 return true; 203 } 204 virtual bool IsIntegratedAssemblerDefault() const { 205#ifdef DISABLE_DEFAULT_INTEGRATED_ASSEMBLER 206 return false; 207#else 208 // Default integrated assembler to on for x86. 209 return (getTriple().getArch() == llvm::Triple::x86 || 210 getTriple().getArch() == llvm::Triple::x86_64); 211#endif 212 } 213 virtual bool IsStrictAliasingDefault() const { 214#ifdef DISABLE_DEFAULT_STRICT_ALIASING 215 return false; 216#else 217 return ToolChain::IsStrictAliasingDefault(); 218#endif 219 } 220 221 virtual bool IsObjCDefaultSynthPropertiesDefault() const { 222 return false; 223 } 224 225 virtual bool IsObjCNonFragileABIDefault() const { 226 // Non-fragile ABI is default for everything but i386. 227 return getTriple().getArch() != llvm::Triple::x86; 228 } 229 virtual bool IsObjCLegacyDispatchDefault() const { 230 // This is only used with the non-fragile ABI. 231 232 // Legacy dispatch is used everywhere except on x86_64. 233 return getTriple().getArch() != llvm::Triple::x86_64; 234 } 235 virtual bool UseObjCMixedDispatch() const { 236 // This is only used with the non-fragile ABI and non-legacy dispatch. 237 238 // Mixed dispatch is used everywhere except OS X before 10.6. 239 return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6)); 240 } 241 virtual bool IsUnwindTablesDefault() const; 242 virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const { 243 // Stack protectors default to on for user code on 10.5, 244 // and for everything in 10.6 and beyond 245 return !isTargetIPhoneOS() && 246 (!isMacosxVersionLT(10, 6) || 247 (!isMacosxVersionLT(10, 5) && !KernelOrKext)); 248 } 249 virtual const char *GetDefaultRelocationModel() const; 250 virtual const char *GetForcedPicModel() const; 251 252 virtual bool SupportsProfiling() const; 253 254 virtual bool SupportsObjCGC() const; 255 256 virtual bool UseDwarfDebugFlags() const; 257 258 virtual bool UseSjLjExceptions() const; 259 260 /// } 261}; 262 263/// DarwinClang - The Darwin toolchain used by Clang. 264class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin { 265private: 266 void AddGCCLibexecPath(unsigned darwinVersion); 267 268public: 269 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple); 270 271 /// @name Darwin ToolChain Implementation 272 /// { 273 274 virtual void AddLinkSearchPathArgs(const ArgList &Args, 275 ArgStringList &CmdArgs) const; 276 277 virtual void AddLinkRuntimeLibArgs(const ArgList &Args, 278 ArgStringList &CmdArgs) const; 279 void AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, 280 const char *DarwinStaticLib) const; 281 282 virtual void AddCXXStdlibLibArgs(const ArgList &Args, 283 ArgStringList &CmdArgs) const; 284 285 virtual void AddCCKextLibArgs(const ArgList &Args, 286 ArgStringList &CmdArgs) const; 287 288 virtual void AddLinkARCArgs(const ArgList &Args, 289 ArgStringList &CmdArgs) const; 290 /// } 291}; 292 293/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc. 294class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC { 295public: 296 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) 297 : Generic_GCC(Host, Triple) {} 298 299 std::string ComputeEffectiveClangTriple(const ArgList &Args, 300 types::ID InputType) const; 301 302 virtual const char *GetDefaultRelocationModel() const { return "pic"; } 303}; 304 305class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC { 306 public: 307 Generic_ELF(const HostInfo &Host, const llvm::Triple& Triple) 308 : Generic_GCC(Host, Triple) {} 309 310 virtual bool IsIntegratedAssemblerDefault() const { 311 // Default integrated assembler to on for x86. 312 return (getTriple().getArch() == llvm::Triple::x86 || 313 getTriple().getArch() == llvm::Triple::x86_64); 314 } 315}; 316 317class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC { 318public: 319 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple); 320 321 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 322 const ActionList &Inputs) const; 323}; 324 325class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF { 326public: 327 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple); 328 329 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 330 const ActionList &Inputs) const; 331}; 332 333class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF { 334public: 335 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple); 336 337 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 338 const ActionList &Inputs) const; 339}; 340 341class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF { 342 const llvm::Triple ToolTriple; 343 344public: 345 NetBSD(const HostInfo &Host, const llvm::Triple& Triple, 346 const llvm::Triple& ToolTriple); 347 348 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 349 const ActionList &Inputs) const; 350}; 351 352class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC { 353public: 354 Minix(const HostInfo &Host, const llvm::Triple& Triple); 355 356 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 357 const ActionList &Inputs) const; 358}; 359 360class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF { 361public: 362 DragonFly(const HostInfo &Host, const llvm::Triple& Triple); 363 364 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 365 const ActionList &Inputs) const; 366}; 367 368class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF { 369public: 370 Linux(const HostInfo &Host, const llvm::Triple& Triple); 371 372 virtual bool HasNativeLLVMSupport() const; 373 374 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 375 const ActionList &Inputs) const; 376 377 std::string Linker; 378 std::vector<std::string> ExtraOpts; 379}; 380 381 382/// TCEToolChain - A tool chain using the llvm bitcode tools to perform 383/// all subcommands. See http://tce.cs.tut.fi for our peculiar target. 384class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain { 385public: 386 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple); 387 ~TCEToolChain(); 388 389 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 390 const ActionList &Inputs) const; 391 bool IsMathErrnoDefault() const; 392 bool IsUnwindTablesDefault() const; 393 const char* GetDefaultRelocationModel() const; 394 const char* GetForcedPicModel() const; 395 396private: 397 mutable llvm::DenseMap<unsigned, Tool*> Tools; 398 399}; 400 401class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain { 402 mutable llvm::DenseMap<unsigned, Tool*> Tools; 403 404public: 405 Windows(const HostInfo &Host, const llvm::Triple& Triple); 406 407 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 408 const ActionList &Inputs) const; 409 410 virtual bool IsIntegratedAssemblerDefault() const; 411 virtual bool IsUnwindTablesDefault() const; 412 virtual const char *GetDefaultRelocationModel() const; 413 virtual const char *GetForcedPicModel() const; 414}; 415 416} // end namespace toolchains 417} // end namespace driver 418} // end namespace clang 419 420#endif 421