ToolChains.h revision 61ab80a8b35e6fe9363e8ef1b3d27209b0e89349
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 { 265public: 266 DarwinClang(const HostInfo &Host, const llvm::Triple& Triple); 267 268 /// @name Darwin ToolChain Implementation 269 /// { 270 271 virtual void AddLinkSearchPathArgs(const ArgList &Args, 272 ArgStringList &CmdArgs) const; 273 274 virtual void AddLinkRuntimeLibArgs(const ArgList &Args, 275 ArgStringList &CmdArgs) const; 276 void AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, 277 const char *DarwinStaticLib) const; 278 279 virtual void AddCXXStdlibLibArgs(const ArgList &Args, 280 ArgStringList &CmdArgs) const; 281 282 virtual void AddCCKextLibArgs(const ArgList &Args, 283 ArgStringList &CmdArgs) const; 284 285 virtual void AddLinkARCArgs(const ArgList &Args, 286 ArgStringList &CmdArgs) const; 287 /// } 288}; 289 290/// Darwin_Generic_GCC - Generic Darwin tool chain using gcc. 291class LLVM_LIBRARY_VISIBILITY Darwin_Generic_GCC : public Generic_GCC { 292public: 293 Darwin_Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) 294 : Generic_GCC(Host, Triple) {} 295 296 std::string ComputeEffectiveClangTriple(const ArgList &Args, 297 types::ID InputType) const; 298 299 virtual const char *GetDefaultRelocationModel() const { return "pic"; } 300}; 301 302class LLVM_LIBRARY_VISIBILITY Generic_ELF : public Generic_GCC { 303 public: 304 Generic_ELF(const HostInfo &Host, const llvm::Triple& Triple) 305 : Generic_GCC(Host, Triple) {} 306 307 virtual bool IsIntegratedAssemblerDefault() const { 308 // Default integrated assembler to on for x86. 309 return (getTriple().getArch() == llvm::Triple::x86 || 310 getTriple().getArch() == llvm::Triple::x86_64); 311 } 312}; 313 314class LLVM_LIBRARY_VISIBILITY AuroraUX : public Generic_GCC { 315public: 316 AuroraUX(const HostInfo &Host, const llvm::Triple& Triple); 317 318 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 319 const ActionList &Inputs) const; 320}; 321 322class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF { 323public: 324 OpenBSD(const HostInfo &Host, const llvm::Triple& Triple); 325 326 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 327 const ActionList &Inputs) const; 328}; 329 330class LLVM_LIBRARY_VISIBILITY FreeBSD : public Generic_ELF { 331public: 332 FreeBSD(const HostInfo &Host, const llvm::Triple& Triple); 333 334 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 335 const ActionList &Inputs) const; 336}; 337 338class LLVM_LIBRARY_VISIBILITY NetBSD : public Generic_ELF { 339 const llvm::Triple ToolTriple; 340 341public: 342 NetBSD(const HostInfo &Host, const llvm::Triple& Triple, 343 const llvm::Triple& ToolTriple); 344 345 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 346 const ActionList &Inputs) const; 347}; 348 349class LLVM_LIBRARY_VISIBILITY Minix : public Generic_GCC { 350public: 351 Minix(const HostInfo &Host, const llvm::Triple& Triple); 352 353 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 354 const ActionList &Inputs) const; 355}; 356 357class LLVM_LIBRARY_VISIBILITY DragonFly : public Generic_ELF { 358public: 359 DragonFly(const HostInfo &Host, const llvm::Triple& Triple); 360 361 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 362 const ActionList &Inputs) const; 363}; 364 365class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF { 366public: 367 Linux(const HostInfo &Host, const llvm::Triple& Triple); 368 369 virtual bool HasNativeLLVMSupport() const; 370 371 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 372 const ActionList &Inputs) const; 373 374 std::string Linker; 375 std::vector<std::string> ExtraOpts; 376}; 377 378 379/// TCEToolChain - A tool chain using the llvm bitcode tools to perform 380/// all subcommands. See http://tce.cs.tut.fi for our peculiar target. 381class LLVM_LIBRARY_VISIBILITY TCEToolChain : public ToolChain { 382public: 383 TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple); 384 ~TCEToolChain(); 385 386 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 387 const ActionList &Inputs) const; 388 bool IsMathErrnoDefault() const; 389 bool IsUnwindTablesDefault() const; 390 const char* GetDefaultRelocationModel() const; 391 const char* GetForcedPicModel() const; 392 393private: 394 mutable llvm::DenseMap<unsigned, Tool*> Tools; 395 396}; 397 398class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain { 399 mutable llvm::DenseMap<unsigned, Tool*> Tools; 400 401public: 402 Windows(const HostInfo &Host, const llvm::Triple& Triple); 403 404 virtual Tool &SelectTool(const Compilation &C, const JobAction &JA, 405 const ActionList &Inputs) const; 406 407 virtual bool IsIntegratedAssemblerDefault() const; 408 virtual bool IsUnwindTablesDefault() const; 409 virtual const char *GetDefaultRelocationModel() const; 410 virtual const char *GetForcedPicModel() const; 411}; 412 413} // end namespace toolchains 414} // end namespace driver 415} // end namespace clang 416 417#endif 418