Nick Lewycky | e3365aa | 2010-09-23 23:48:20 +0000 | [diff] [blame] | 1 | //===--- Tools.cpp - Tools Implementations --------------------------------===// |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "Tools.h" |
| 11 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Arg.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 14 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | ee848a7 | 2009-10-29 02:39:57 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Driver.h" |
| 16 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Compilation.h" |
| 18 | #include "clang/Driver/Job.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Option.h" |
Daniel Dunbar | 265e9ef | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 20 | #include "clang/Driver/Options.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 21 | #include "clang/Driver/ToolChain.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 22 | #include "clang/Driver/Util.h" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 23 | #include "clang/Basic/ObjCRuntime.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 24 | |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallString.h" |
Douglas Gregor | 55d3f7a | 2009-10-29 00:41:01 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringSwitch.h" |
Daniel Dunbar | 5b750fe | 2009-09-09 22:32:34 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/Twine.h" |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 28 | #include "llvm/Support/FileSystem.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Format.h" |
| 30 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Host.h" |
| 32 | #include "llvm/Support/Process.h" |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 34 | |
| 35 | #include "InputInfo.h" |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 36 | #include "SanitizerArgs.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 37 | #include "ToolChains.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 38 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 39 | using namespace clang::driver; |
| 40 | using namespace clang::driver::tools; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 41 | using namespace clang; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 42 | |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 43 | /// CheckPreprocessingOptions - Perform some validation of preprocessing |
| 44 | /// arguments that is shared with gcc. |
| 45 | static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) { |
| 46 | if (Arg *A = Args.getLastArg(options::OPT_C, options::OPT_CC)) |
Joerg Sonnenberger | 9ade4ae | 2011-03-06 23:31:01 +0000 | [diff] [blame] | 47 | if (!Args.hasArg(options::OPT_E) && !D.CCCIsCPP) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 48 | D.Diag(diag::err_drv_argument_only_allowed_with) |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 49 | << A->getAsString(Args) << "-E"; |
| 50 | } |
| 51 | |
Daniel Dunbar | e2fd664 | 2009-09-10 01:21:12 +0000 | [diff] [blame] | 52 | /// CheckCodeGenerationOptions - Perform some validation of code generation |
| 53 | /// arguments that is shared with gcc. |
| 54 | static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args) { |
| 55 | // In gcc, only ARM checks this, but it seems reasonable to check universally. |
| 56 | if (Args.hasArg(options::OPT_static)) |
| 57 | if (const Arg *A = Args.getLastArg(options::OPT_dynamic, |
| 58 | options::OPT_mdynamic_no_pic)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 59 | D.Diag(diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | e2fd664 | 2009-09-10 01:21:12 +0000 | [diff] [blame] | 60 | << A->getAsString(Args) << "-static"; |
| 61 | } |
| 62 | |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 63 | // Quote target names for inclusion in GNU Make dependency files. |
| 64 | // Only the characters '$', '#', ' ', '\t' are quoted. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 65 | static void QuoteTarget(StringRef Target, |
| 66 | SmallVectorImpl<char> &Res) { |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 67 | for (unsigned i = 0, e = Target.size(); i != e; ++i) { |
| 68 | switch (Target[i]) { |
| 69 | case ' ': |
| 70 | case '\t': |
| 71 | // Escape the preceding backslashes |
| 72 | for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j) |
| 73 | Res.push_back('\\'); |
| 74 | |
| 75 | // Escape the space/tab |
| 76 | Res.push_back('\\'); |
| 77 | break; |
| 78 | case '$': |
| 79 | Res.push_back('$'); |
| 80 | break; |
| 81 | case '#': |
| 82 | Res.push_back('\\'); |
| 83 | break; |
| 84 | default: |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | Res.push_back(Target[i]); |
| 89 | } |
| 90 | } |
| 91 | |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 92 | static void addDirectoryList(const ArgList &Args, |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 93 | ArgStringList &CmdArgs, |
| 94 | const char *ArgName, |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 95 | const char *EnvVar) { |
| 96 | const char *DirList = ::getenv(EnvVar); |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 97 | bool CombinedArg = false; |
| 98 | |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 99 | if (!DirList) |
| 100 | return; // Nothing to do. |
| 101 | |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 102 | StringRef Name(ArgName); |
| 103 | if (Name.equals("-I") || Name.equals("-L")) |
| 104 | CombinedArg = true; |
| 105 | |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 106 | StringRef Dirs(DirList); |
| 107 | if (Dirs.empty()) // Empty string should not add '.'. |
| 108 | return; |
| 109 | |
| 110 | StringRef::size_type Delim; |
| 111 | while ((Delim = Dirs.find(llvm::sys::PathSeparator)) != StringRef::npos) { |
| 112 | if (Delim == 0) { // Leading colon. |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 113 | if (CombinedArg) { |
| 114 | CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + ".")); |
| 115 | } else { |
| 116 | CmdArgs.push_back(ArgName); |
| 117 | CmdArgs.push_back("."); |
| 118 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 119 | } else { |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 120 | if (CombinedArg) { |
| 121 | CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs.substr(0, Delim))); |
| 122 | } else { |
| 123 | CmdArgs.push_back(ArgName); |
| 124 | CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim))); |
| 125 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 126 | } |
Nico Weber | 09c5c39 | 2012-03-19 15:00:03 +0000 | [diff] [blame] | 127 | Dirs = Dirs.substr(Delim + 1); |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | if (Dirs.empty()) { // Trailing colon. |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 131 | if (CombinedArg) { |
| 132 | CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + ".")); |
| 133 | } else { |
| 134 | CmdArgs.push_back(ArgName); |
| 135 | CmdArgs.push_back("."); |
| 136 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 137 | } else { // Add the last path. |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 138 | if (CombinedArg) { |
| 139 | CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs)); |
| 140 | } else { |
| 141 | CmdArgs.push_back(ArgName); |
| 142 | CmdArgs.push_back(Args.MakeArgString(Dirs)); |
| 143 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 147 | static void AddLinkerInputs(const ToolChain &TC, |
| 148 | const InputInfoList &Inputs, const ArgList &Args, |
| 149 | ArgStringList &CmdArgs) { |
| 150 | const Driver &D = TC.getDriver(); |
| 151 | |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 152 | // Add extra linker input arguments which are not treated as inputs |
| 153 | // (constructed via -Xarch_). |
| 154 | Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input); |
| 155 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 156 | for (InputInfoList::const_iterator |
| 157 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 158 | const InputInfo &II = *it; |
| 159 | |
| 160 | if (!TC.HasNativeLLVMSupport()) { |
| 161 | // Don't try to pass LLVM inputs unless we have native support. |
| 162 | if (II.getType() == types::TY_LLVM_IR || |
| 163 | II.getType() == types::TY_LTO_IR || |
| 164 | II.getType() == types::TY_LLVM_BC || |
| 165 | II.getType() == types::TY_LTO_BC) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 166 | D.Diag(diag::err_drv_no_linker_llvm_support) |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 167 | << TC.getTripleString(); |
| 168 | } |
| 169 | |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 170 | // Add filenames immediately. |
| 171 | if (II.isFilename()) { |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 172 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 173 | continue; |
| 174 | } |
| 175 | |
| 176 | // Otherwise, this is a linker input argument. |
| 177 | const Arg &A = II.getInputArg(); |
| 178 | |
| 179 | // Handle reserved library options. |
| 180 | if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 181 | TC.AddCXXStdlibLibArgs(Args, CmdArgs); |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 182 | } else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext)) { |
| 183 | TC.AddCCKextLibArgs(Args, CmdArgs); |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 184 | } else |
| 185 | A.renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 186 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 187 | |
| 188 | // LIBRARY_PATH - included following the user specified library paths. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 189 | addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH"); |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 190 | } |
| 191 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 192 | /// \brief Determine whether Objective-C automated reference counting is |
| 193 | /// enabled. |
| 194 | static bool isObjCAutoRefCount(const ArgList &Args) { |
| 195 | return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); |
| 196 | } |
| 197 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 198 | /// \brief Determine whether we are linking the ObjC runtime. |
| 199 | static bool isObjCRuntimeLinked(const ArgList &Args) { |
Bob Wilson | a7635f1 | 2012-08-07 19:58:00 +0000 | [diff] [blame] | 200 | if (isObjCAutoRefCount(Args)) { |
| 201 | Args.ClaimAllArgs(options::OPT_fobjc_link_runtime); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 202 | return true; |
Bob Wilson | a7635f1 | 2012-08-07 19:58:00 +0000 | [diff] [blame] | 203 | } |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 204 | return Args.hasArg(options::OPT_fobjc_link_runtime); |
| 205 | } |
| 206 | |
Rafael Espindola | db3f24a | 2011-06-02 18:58:46 +0000 | [diff] [blame] | 207 | static void addProfileRT(const ToolChain &TC, const ArgList &Args, |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 208 | ArgStringList &CmdArgs, |
| 209 | llvm::Triple Triple) { |
| 210 | if (!(Args.hasArg(options::OPT_fprofile_arcs) || |
| 211 | Args.hasArg(options::OPT_fprofile_generate) || |
| 212 | Args.hasArg(options::OPT_fcreate_profile) || |
| 213 | Args.hasArg(options::OPT_coverage))) |
| 214 | return; |
| 215 | |
| 216 | // GCC links libgcov.a by adding -L<inst>/gcc/lib/gcc/<triple>/<ver> -lgcov to |
| 217 | // the link line. We cannot do the same thing because unlike gcov there is a |
| 218 | // libprofile_rt.so. We used to use the -l:libprofile_rt.a syntax, but that is |
| 219 | // not supported by old linkers. |
Benjamin Kramer | f2db04c | 2011-11-07 16:02:25 +0000 | [diff] [blame] | 220 | std::string ProfileRT = |
| 221 | std::string(TC.getDriver().Dir) + "/../lib/libprofile_rt.a"; |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 222 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 223 | CmdArgs.push_back(Args.MakeArgString(ProfileRT)); |
Rafael Espindola | db3f24a | 2011-06-02 18:58:46 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Michael J. Spencer | 91e06da | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 226 | static bool forwardToGCC(const Option &O) { |
| 227 | return !O.hasFlag(options::NoForward) && |
| 228 | !O.hasFlag(options::DriverOption) && |
| 229 | !O.hasFlag(options::LinkerInput); |
| 230 | } |
| 231 | |
Peter Collingbourne | 54db68b | 2011-11-06 00:40:05 +0000 | [diff] [blame] | 232 | void Clang::AddPreprocessingOptions(Compilation &C, |
| 233 | const Driver &D, |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 234 | const ArgList &Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 235 | ArgStringList &CmdArgs, |
| 236 | const InputInfo &Output, |
| 237 | const InputInfoList &Inputs) const { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 238 | Arg *A; |
Daniel Dunbar | 3a183d3 | 2009-06-08 21:48:20 +0000 | [diff] [blame] | 239 | |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 240 | CheckPreprocessingOptions(D, Args); |
| 241 | |
| 242 | Args.AddLastArg(CmdArgs, options::OPT_C); |
| 243 | Args.AddLastArg(CmdArgs, options::OPT_CC); |
Daniel Dunbar | 3a183d3 | 2009-06-08 21:48:20 +0000 | [diff] [blame] | 244 | |
| 245 | // Handle dependency file generation. |
Daniel Dunbar | 9eb93b0 | 2010-12-08 21:33:40 +0000 | [diff] [blame] | 246 | if ((A = Args.getLastArg(options::OPT_M, options::OPT_MM)) || |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 247 | (A = Args.getLastArg(options::OPT_MD)) || |
| 248 | (A = Args.getLastArg(options::OPT_MMD))) { |
| 249 | // Determine the output location. |
| 250 | const char *DepFile; |
Benjamin Kramer | 99c7208 | 2012-09-26 19:01:49 +0000 | [diff] [blame] | 251 | if (Arg *MF = Args.getLastArg(options::OPT_MF)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 252 | DepFile = MF->getValue(); |
Peter Collingbourne | 5d4d980 | 2011-11-21 00:01:05 +0000 | [diff] [blame] | 253 | C.addFailureResultFile(DepFile); |
Benjamin Kramer | 99c7208 | 2012-09-26 19:01:49 +0000 | [diff] [blame] | 254 | } else if (Output.getType() == types::TY_Dependencies) { |
| 255 | DepFile = Output.getFilename(); |
Daniel Dunbar | b827a05 | 2009-11-19 03:26:40 +0000 | [diff] [blame] | 256 | } else if (A->getOption().matches(options::OPT_M) || |
| 257 | A->getOption().matches(options::OPT_MM)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 258 | DepFile = "-"; |
| 259 | } else { |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 260 | DepFile = getDependencyFileName(Args, Inputs); |
Peter Collingbourne | 5d4d980 | 2011-11-21 00:01:05 +0000 | [diff] [blame] | 261 | C.addFailureResultFile(DepFile); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 262 | } |
| 263 | CmdArgs.push_back("-dependency-file"); |
| 264 | CmdArgs.push_back(DepFile); |
| 265 | |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 266 | // Add a default target if one wasn't specified. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 267 | if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) { |
| 268 | const char *DepTarget; |
| 269 | |
| 270 | // If user provided -o, that is the dependency target, except |
| 271 | // when we are only generating a dependency file. |
| 272 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 273 | if (OutputOpt && Output.getType() != types::TY_Dependencies) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 274 | DepTarget = OutputOpt->getValue(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 275 | } else { |
| 276 | // Otherwise derive from the base input. |
| 277 | // |
| 278 | // FIXME: This should use the computed output file location. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 279 | SmallString<128> P(Inputs[0].getBaseInput()); |
Michael J. Spencer | 472ccff | 2010-12-18 00:19:12 +0000 | [diff] [blame] | 280 | llvm::sys::path::replace_extension(P, "o"); |
| 281 | DepTarget = Args.MakeArgString(llvm::sys::path::filename(P)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | CmdArgs.push_back("-MT"); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 285 | SmallString<128> Quoted; |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 286 | QuoteTarget(DepTarget, Quoted); |
| 287 | CmdArgs.push_back(Args.MakeArgString(Quoted)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Daniel Dunbar | b827a05 | 2009-11-19 03:26:40 +0000 | [diff] [blame] | 290 | if (A->getOption().matches(options::OPT_M) || |
| 291 | A->getOption().matches(options::OPT_MD)) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 292 | CmdArgs.push_back("-sys-header-deps"); |
| 293 | } |
| 294 | |
Peter Collingbourne | bb52786 | 2011-07-12 19:35:15 +0000 | [diff] [blame] | 295 | if (Args.hasArg(options::OPT_MG)) { |
| 296 | if (!A || A->getOption().matches(options::OPT_MD) || |
| 297 | A->getOption().matches(options::OPT_MMD)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 298 | D.Diag(diag::err_drv_mg_requires_m_or_mm); |
Peter Collingbourne | bb52786 | 2011-07-12 19:35:15 +0000 | [diff] [blame] | 299 | CmdArgs.push_back("-MG"); |
| 300 | } |
| 301 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 302 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 303 | |
| 304 | // Convert all -MQ <target> args to -MT <quoted target> |
| 305 | for (arg_iterator it = Args.filtered_begin(options::OPT_MT, |
| 306 | options::OPT_MQ), |
| 307 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 308 | const Arg *A = *it; |
| 309 | A->claim(); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 310 | |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 311 | if (A->getOption().matches(options::OPT_MQ)) { |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 312 | CmdArgs.push_back("-MT"); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 313 | SmallString<128> Quoted; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 314 | QuoteTarget(A->getValue(), Quoted); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 315 | CmdArgs.push_back(Args.MakeArgString(Quoted)); |
| 316 | |
| 317 | // -MT flag - no change |
| 318 | } else { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 319 | A->render(Args, CmdArgs); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 320 | } |
| 321 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 322 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 323 | // Add -i* options, and automatically translate to |
| 324 | // -include-pch/-include-pth for transparent PCH support. It's |
| 325 | // wonky, but we include looking for .gch so we can support seamless |
| 326 | // replacement into a build system already set up to be generating |
| 327 | // .gch files. |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 328 | bool RenderedImplicitInclude = false; |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 329 | for (arg_iterator it = Args.filtered_begin(options::OPT_clang_i_Group), |
| 330 | ie = Args.filtered_end(); it != ie; ++it) { |
| 331 | const Arg *A = it; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 332 | |
| 333 | if (A->getOption().matches(options::OPT_include)) { |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 334 | bool IsFirstImplicitInclude = !RenderedImplicitInclude; |
| 335 | RenderedImplicitInclude = true; |
| 336 | |
Argyrios Kyrtzidis | e5c3537 | 2010-08-11 23:27:58 +0000 | [diff] [blame] | 337 | // Use PCH if the user requested it. |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 338 | bool UsePCH = D.CCCUsePCH; |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 339 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 340 | bool FoundPTH = false; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 341 | bool FoundPCH = false; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 342 | llvm::sys::Path P(A->getValue()); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 343 | bool Exists; |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 344 | if (UsePCH) { |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 345 | P.appendSuffix("pch"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 346 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 347 | FoundPCH = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 348 | else |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 349 | P.eraseSuffix(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 352 | if (!FoundPCH) { |
| 353 | P.appendSuffix("pth"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 354 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 355 | FoundPTH = true; |
| 356 | else |
| 357 | P.eraseSuffix(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 360 | if (!FoundPCH && !FoundPTH) { |
| 361 | P.appendSuffix("gch"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 362 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) { |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 363 | FoundPCH = UsePCH; |
| 364 | FoundPTH = !UsePCH; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 365 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 366 | else |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 367 | P.eraseSuffix(); |
| 368 | } |
| 369 | |
| 370 | if (FoundPCH || FoundPTH) { |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 371 | if (IsFirstImplicitInclude) { |
| 372 | A->claim(); |
| 373 | if (UsePCH) |
| 374 | CmdArgs.push_back("-include-pch"); |
| 375 | else |
| 376 | CmdArgs.push_back("-include-pth"); |
| 377 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 378 | continue; |
| 379 | } else { |
| 380 | // Ignore the PCH if not first on command line and emit warning. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 381 | D.Diag(diag::warn_drv_pch_not_first_include) |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 382 | << P.str() << A->getAsString(Args); |
| 383 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
| 387 | // Not translated, render as usual. |
| 388 | A->claim(); |
| 389 | A->render(Args, CmdArgs); |
| 390 | } |
| 391 | |
| 392 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 393 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F, |
| 394 | options::OPT_index_header_map); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 395 | |
| 396 | // Add -Wp, and -Xassembler if using the preprocessor. |
| 397 | |
| 398 | // FIXME: There is a very unfortunate problem here, some troubled |
| 399 | // souls abuse -Wp, to pass preprocessor options in gcc syntax. To |
| 400 | // really support that we would have to parse and then translate |
| 401 | // those options. :( |
| 402 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 403 | options::OPT_Xpreprocessor); |
Daniel Dunbar | 607d7f6 | 2009-10-29 01:53:44 +0000 | [diff] [blame] | 404 | |
| 405 | // -I- is a deprecated GCC feature, reject it. |
| 406 | if (Arg *A = Args.getLastArg(options::OPT_I_)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 407 | D.Diag(diag::err_drv_I_dash_not_supported) << A->getAsString(Args); |
Chandler Carruth | feee58c | 2010-10-20 07:00:47 +0000 | [diff] [blame] | 408 | |
| 409 | // If we have a --sysroot, and don't have an explicit -isysroot flag, add an |
| 410 | // -isysroot to the CC1 invocation. |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 411 | StringRef sysroot = C.getSysRoot(); |
| 412 | if (sysroot != "") { |
Chandler Carruth | feee58c | 2010-10-20 07:00:47 +0000 | [diff] [blame] | 413 | if (!Args.hasArg(options::OPT_isysroot)) { |
| 414 | CmdArgs.push_back("-isysroot"); |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 415 | CmdArgs.push_back(C.getArgs().MakeArgString(sysroot)); |
Chandler Carruth | feee58c | 2010-10-20 07:00:47 +0000 | [diff] [blame] | 416 | } |
| 417 | } |
Douglas Gregor | 8ee51ef | 2011-09-14 20:28:46 +0000 | [diff] [blame] | 418 | |
| 419 | // If a module path was provided, pass it along. Otherwise, use a temporary |
| 420 | // directory. |
| 421 | if (Arg *A = Args.getLastArg(options::OPT_fmodule_cache_path)) { |
Douglas Gregor | 8ee51ef | 2011-09-14 20:28:46 +0000 | [diff] [blame] | 422 | A->claim(); |
| 423 | A->render(Args, CmdArgs); |
| 424 | } else { |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 425 | SmallString<128> DefaultModuleCache; |
Douglas Gregor | 8ee51ef | 2011-09-14 20:28:46 +0000 | [diff] [blame] | 426 | llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/false, |
| 427 | DefaultModuleCache); |
| 428 | llvm::sys::path::append(DefaultModuleCache, "clang-module-cache"); |
| 429 | CmdArgs.push_back("-fmodule-cache-path"); |
| 430 | CmdArgs.push_back(Args.MakeArgString(DefaultModuleCache)); |
| 431 | } |
Douglas Gregor | fba18aa | 2011-09-15 22:00:41 +0000 | [diff] [blame] | 432 | |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 433 | // Parse additional include paths from environment variables. |
Chandler Carruth | b5870e7 | 2011-11-04 07:12:58 +0000 | [diff] [blame] | 434 | // FIXME: We should probably sink the logic for handling these from the |
| 435 | // frontend into the driver. It will allow deleting 4 otherwise unused flags. |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 436 | // CPATH - included following the user specified includes (but prior to |
| 437 | // builtin and standard includes). |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 438 | addDirectoryList(Args, CmdArgs, "-I", "CPATH"); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 439 | // C_INCLUDE_PATH - system includes enabled when compiling C. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 440 | addDirectoryList(Args, CmdArgs, "-c-isystem", "C_INCLUDE_PATH"); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 441 | // CPLUS_INCLUDE_PATH - system includes enabled when compiling C++. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 442 | addDirectoryList(Args, CmdArgs, "-cxx-isystem", "CPLUS_INCLUDE_PATH"); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 443 | // OBJC_INCLUDE_PATH - system includes enabled when compiling ObjC. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 444 | addDirectoryList(Args, CmdArgs, "-objc-isystem", "OBJC_INCLUDE_PATH"); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 445 | // OBJCPLUS_INCLUDE_PATH - system includes enabled when compiling ObjC++. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 446 | addDirectoryList(Args, CmdArgs, "-objcxx-isystem", "OBJCPLUS_INCLUDE_PATH"); |
Chandler Carruth | 88491fc | 2011-11-04 07:12:53 +0000 | [diff] [blame] | 447 | |
Chandler Carruth | 88491fc | 2011-11-04 07:12:53 +0000 | [diff] [blame] | 448 | // Add C++ include arguments, if needed. |
Chandler Carruth | a461442 | 2011-11-04 07:43:33 +0000 | [diff] [blame] | 449 | if (types::isCXX(Inputs[0].getType())) |
Chandler Carruth | 7ffa032 | 2011-11-04 07:34:47 +0000 | [diff] [blame] | 450 | getToolChain().AddClangCXXStdlibIncludeArgs(Args, CmdArgs); |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 451 | |
| 452 | // Add system include arguments. |
| 453 | getToolChain().AddClangSystemIncludeArgs(Args, CmdArgs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 456 | /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 457 | /// CPU. |
| 458 | // |
| 459 | // FIXME: This is redundant with -mcpu, why does LLVM use this. |
| 460 | // FIXME: tblgen this, or kill it! |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 461 | static const char *getLLVMArchSuffixForARM(StringRef CPU) { |
Chad Rosier | ae1aee6 | 2011-10-07 17:48:56 +0000 | [diff] [blame] | 462 | return llvm::StringSwitch<const char *>(CPU) |
| 463 | .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "v4t") |
| 464 | .Cases("arm720t", "arm9", "arm9tdmi", "v4t") |
| 465 | .Cases("arm920", "arm920t", "arm922t", "v4t") |
| 466 | .Cases("arm940t", "ep9312","v4t") |
| 467 | .Cases("arm10tdmi", "arm1020t", "v5") |
| 468 | .Cases("arm9e", "arm926ej-s", "arm946e-s", "v5e") |
| 469 | .Cases("arm966e-s", "arm968e-s", "arm10e", "v5e") |
| 470 | .Cases("arm1020e", "arm1022e", "xscale", "iwmmxt", "v5e") |
| 471 | .Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", "v6") |
| 472 | .Cases("arm1176jzf-s", "mpcorenovfp", "mpcore", "v6") |
| 473 | .Cases("arm1156t2-s", "arm1156t2f-s", "v6t2") |
Quentin Colombet | 74632aa | 2012-11-29 23:15:27 +0000 | [diff] [blame] | 474 | .Cases("cortex-a5", "cortex-a8", "cortex-a9", "cortex-a15", "v7") |
Bob Wilson | 57f6d19 | 2012-03-21 17:19:12 +0000 | [diff] [blame] | 475 | .Case("cortex-m3", "v7m") |
Jim Grosbach | 6903313 | 2012-03-29 19:53:34 +0000 | [diff] [blame] | 476 | .Case("cortex-m4", "v7m") |
Bob Wilson | 57f6d19 | 2012-03-21 17:19:12 +0000 | [diff] [blame] | 477 | .Case("cortex-m0", "v6m") |
Bob Wilson | 336bfa3 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 478 | .Case("cortex-a9-mp", "v7f") |
| 479 | .Case("swift", "v7s") |
Chad Rosier | ae1aee6 | 2011-10-07 17:48:56 +0000 | [diff] [blame] | 480 | .Default(""); |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 483 | /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting. |
| 484 | // |
| 485 | // FIXME: tblgen this. |
| 486 | static std::string getARMTargetCPU(const ArgList &Args, |
| 487 | const llvm::Triple &Triple) { |
| 488 | // FIXME: Warn on inconsistent use of -mcpu and -march. |
| 489 | |
| 490 | // If we have -mcpu=, use that. |
| 491 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 492 | StringRef MCPU = A->getValue(); |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 493 | // Handle -mcpu=native. |
| 494 | if (MCPU == "native") |
| 495 | return llvm::sys::getHostCPUName(); |
| 496 | else |
| 497 | return MCPU; |
| 498 | } |
| 499 | |
| 500 | StringRef MArch; |
| 501 | if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
| 502 | // Otherwise, if we have -march= choose the base CPU for that arch. |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 503 | MArch = A->getValue(); |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 504 | } else { |
| 505 | // Otherwise, use the Arch from the triple. |
| 506 | MArch = Triple.getArchName(); |
| 507 | } |
| 508 | |
| 509 | // Handle -march=native. |
| 510 | std::string NativeMArch; |
| 511 | if (MArch == "native") { |
| 512 | std::string CPU = llvm::sys::getHostCPUName(); |
| 513 | if (CPU != "generic") { |
| 514 | // Translate the native cpu into the architecture. The switch below will |
| 515 | // then chose the minimum cpu for that arch. |
| 516 | NativeMArch = std::string("arm") + getLLVMArchSuffixForARM(CPU); |
| 517 | MArch = NativeMArch; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | return llvm::StringSwitch<const char *>(MArch) |
| 522 | .Cases("armv2", "armv2a","arm2") |
| 523 | .Case("armv3", "arm6") |
| 524 | .Case("armv3m", "arm7m") |
| 525 | .Cases("armv4", "armv4t", "arm7tdmi") |
| 526 | .Cases("armv5", "armv5t", "arm10tdmi") |
| 527 | .Cases("armv5e", "armv5te", "arm1022e") |
| 528 | .Case("armv5tej", "arm926ej-s") |
| 529 | .Cases("armv6", "armv6k", "arm1136jf-s") |
| 530 | .Case("armv6j", "arm1136j-s") |
| 531 | .Cases("armv6z", "armv6zk", "arm1176jzf-s") |
| 532 | .Case("armv6t2", "arm1156t2-s") |
| 533 | .Cases("armv7", "armv7a", "armv7-a", "cortex-a8") |
Bob Wilson | 336bfa3 | 2012-09-29 23:52:50 +0000 | [diff] [blame] | 534 | .Cases("armv7f", "armv7-f", "cortex-a9-mp") |
| 535 | .Cases("armv7s", "armv7-s", "swift") |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 536 | .Cases("armv7r", "armv7-r", "cortex-r4") |
| 537 | .Cases("armv7m", "armv7-m", "cortex-m3") |
| 538 | .Case("ep9312", "ep9312") |
| 539 | .Case("iwmmxt", "iwmmxt") |
| 540 | .Case("xscale", "xscale") |
| 541 | .Cases("armv6m", "armv6-m", "cortex-m0") |
| 542 | // If all else failed, return the most base CPU LLVM supports. |
| 543 | .Default("arm7tdmi"); |
| 544 | } |
| 545 | |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 546 | // FIXME: Move to target hook. |
| 547 | static bool isSignedCharDefault(const llvm::Triple &Triple) { |
| 548 | switch (Triple.getArch()) { |
| 549 | default: |
| 550 | return true; |
| 551 | |
Jim Grosbach | 5b4e7b1 | 2011-05-24 15:40:46 +0000 | [diff] [blame] | 552 | case llvm::Triple::arm: |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 553 | case llvm::Triple::ppc: |
| 554 | case llvm::Triple::ppc64: |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 555 | if (Triple.isOSDarwin()) |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 556 | return true; |
| 557 | return false; |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 558 | } |
| 559 | } |
| 560 | |
Chad Rosier | 9931727 | 2012-04-04 20:51:35 +0000 | [diff] [blame] | 561 | // Handle -mfpu=. |
| 562 | // |
| 563 | // FIXME: Centralize feature selection, defaulting shouldn't be also in the |
| 564 | // frontend target. |
| 565 | static void addFPUArgs(const Driver &D, const Arg *A, const ArgList &Args, |
| 566 | ArgStringList &CmdArgs) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 567 | StringRef FPU = A->getValue(); |
Chad Rosier | 9931727 | 2012-04-04 20:51:35 +0000 | [diff] [blame] | 568 | |
| 569 | // Set the target features based on the FPU. |
| 570 | if (FPU == "fpa" || FPU == "fpe2" || FPU == "fpe3" || FPU == "maverick") { |
| 571 | // Disable any default FPU support. |
| 572 | CmdArgs.push_back("-target-feature"); |
| 573 | CmdArgs.push_back("-vfp2"); |
| 574 | CmdArgs.push_back("-target-feature"); |
| 575 | CmdArgs.push_back("-vfp3"); |
| 576 | CmdArgs.push_back("-target-feature"); |
| 577 | CmdArgs.push_back("-neon"); |
| 578 | } else if (FPU == "vfp3-d16" || FPU == "vfpv3-d16") { |
| 579 | CmdArgs.push_back("-target-feature"); |
| 580 | CmdArgs.push_back("+vfp3"); |
| 581 | CmdArgs.push_back("-target-feature"); |
| 582 | CmdArgs.push_back("+d16"); |
| 583 | CmdArgs.push_back("-target-feature"); |
| 584 | CmdArgs.push_back("-neon"); |
| 585 | } else if (FPU == "vfp") { |
| 586 | CmdArgs.push_back("-target-feature"); |
| 587 | CmdArgs.push_back("+vfp2"); |
| 588 | CmdArgs.push_back("-target-feature"); |
| 589 | CmdArgs.push_back("-neon"); |
| 590 | } else if (FPU == "vfp3" || FPU == "vfpv3") { |
| 591 | CmdArgs.push_back("-target-feature"); |
| 592 | CmdArgs.push_back("+vfp3"); |
| 593 | CmdArgs.push_back("-target-feature"); |
| 594 | CmdArgs.push_back("-neon"); |
| 595 | } else if (FPU == "neon") { |
| 596 | CmdArgs.push_back("-target-feature"); |
| 597 | CmdArgs.push_back("+neon"); |
| 598 | } else |
| 599 | D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); |
| 600 | } |
| 601 | |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 602 | // Handle -mfpmath=. |
| 603 | static void addFPMathArgs(const Driver &D, const Arg *A, const ArgList &Args, |
Chad Rosier | 30fe6ba | 2012-04-04 22:13:40 +0000 | [diff] [blame] | 604 | ArgStringList &CmdArgs, StringRef CPU) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 605 | StringRef FPMath = A->getValue(); |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 606 | |
| 607 | // Set the target features based on the FPMath. |
| 608 | if (FPMath == "neon") { |
| 609 | CmdArgs.push_back("-target-feature"); |
| 610 | CmdArgs.push_back("+neonfp"); |
Chad Rosier | 30fe6ba | 2012-04-04 22:13:40 +0000 | [diff] [blame] | 611 | |
Silviu Baranga | 2df67ea | 2012-09-13 15:06:00 +0000 | [diff] [blame] | 612 | if (CPU != "cortex-a8" && CPU != "cortex-a9" && CPU != "cortex-a9-mp" && |
Quentin Colombet | 74632aa | 2012-11-29 23:15:27 +0000 | [diff] [blame] | 613 | CPU != "cortex-a15" && CPU != "cortex-a5") |
Chad Rosier | 30fe6ba | 2012-04-04 22:13:40 +0000 | [diff] [blame] | 614 | D.Diag(diag::err_drv_invalid_feature) << "-mfpmath=neon" << CPU; |
| 615 | |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 616 | } else if (FPMath == "vfp" || FPMath == "vfp2" || FPMath == "vfp3" || |
| 617 | FPMath == "vfp4") { |
| 618 | CmdArgs.push_back("-target-feature"); |
| 619 | CmdArgs.push_back("-neonfp"); |
Chad Rosier | 30fe6ba | 2012-04-04 22:13:40 +0000 | [diff] [blame] | 620 | |
| 621 | // FIXME: Add warnings when disabling a feature not present for a given CPU. |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 622 | } else |
| 623 | D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); |
| 624 | } |
| 625 | |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 626 | // Select the float ABI as determined by -msoft-float, -mhard-float, and |
| 627 | // -mfloat-abi=. |
| 628 | static StringRef getARMFloatABI(const Driver &D, |
| 629 | const ArgList &Args, |
| 630 | const llvm::Triple &Triple) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 631 | StringRef FloatABI; |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 632 | if (Arg *A = Args.getLastArg(options::OPT_msoft_float, |
| 633 | options::OPT_mhard_float, |
| 634 | options::OPT_mfloat_abi_EQ)) { |
| 635 | if (A->getOption().matches(options::OPT_msoft_float)) |
| 636 | FloatABI = "soft"; |
| 637 | else if (A->getOption().matches(options::OPT_mhard_float)) |
| 638 | FloatABI = "hard"; |
| 639 | else { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 640 | FloatABI = A->getValue(); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 641 | if (FloatABI != "soft" && FloatABI != "softfp" && FloatABI != "hard") { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 642 | D.Diag(diag::err_drv_invalid_mfloat_abi) |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 643 | << A->getAsString(Args); |
| 644 | FloatABI = "soft"; |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | // If unspecified, choose the default based on the platform. |
| 650 | if (FloatABI.empty()) { |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 651 | switch (Triple.getOS()) { |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 652 | case llvm::Triple::Darwin: |
| 653 | case llvm::Triple::MacOSX: |
| 654 | case llvm::Triple::IOS: { |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 655 | // Darwin defaults to "softfp" for v6 and v7. |
| 656 | // |
| 657 | // FIXME: Factor out an ARM class so we can cache the arch somewhere. |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 658 | std::string ArchName = |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 659 | getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple)); |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 660 | if (StringRef(ArchName).startswith("v6") || |
| 661 | StringRef(ArchName).startswith("v7")) |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 662 | FloatABI = "softfp"; |
| 663 | else |
| 664 | FloatABI = "soft"; |
| 665 | break; |
| 666 | } |
| 667 | |
| 668 | default: |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 669 | switch(Triple.getEnvironment()) { |
Jiangning Liu | ff104a1 | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 670 | case llvm::Triple::GNUEABIHF: |
| 671 | FloatABI = "hard"; |
| 672 | break; |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 673 | case llvm::Triple::GNUEABI: |
| 674 | FloatABI = "softfp"; |
| 675 | break; |
| 676 | case llvm::Triple::EABI: |
| 677 | // EABI is always AAPCS, and if it was not marked 'hard', it's softfp |
| 678 | FloatABI = "softfp"; |
| 679 | break; |
Logan Chien | 94a7142 | 2012-09-02 09:30:11 +0000 | [diff] [blame] | 680 | case llvm::Triple::Android: { |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 681 | std::string ArchName = |
Chandler Carruth | b43550b | 2012-01-10 19:47:42 +0000 | [diff] [blame] | 682 | getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple)); |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 683 | if (StringRef(ArchName).startswith("v7")) |
Chandler Carruth | b43550b | 2012-01-10 19:47:42 +0000 | [diff] [blame] | 684 | FloatABI = "softfp"; |
| 685 | else |
| 686 | FloatABI = "soft"; |
| 687 | break; |
| 688 | } |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 689 | default: |
| 690 | // Assume "soft", but warn the user we are guessing. |
| 691 | FloatABI = "soft"; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 692 | D.Diag(diag::warn_drv_assuming_mfloat_abi_is) << "soft"; |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 693 | break; |
| 694 | } |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 698 | return FloatABI; |
| 699 | } |
| 700 | |
| 701 | |
| 702 | void Clang::AddARMTargetArgs(const ArgList &Args, |
| 703 | ArgStringList &CmdArgs, |
| 704 | bool KernelOrKext) const { |
| 705 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 706 | // Get the effective triple, which takes into account the deployment target. |
| 707 | std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); |
| 708 | llvm::Triple Triple(TripleStr); |
Daniel Dunbar | 2e4e110 | 2012-10-22 18:30:51 +0000 | [diff] [blame] | 709 | std::string CPUName = getARMTargetCPU(Args, Triple); |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 710 | |
| 711 | // Select the ABI to use. |
| 712 | // |
| 713 | // FIXME: Support -meabi. |
| 714 | const char *ABIName = 0; |
| 715 | if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 716 | ABIName = A->getValue(); |
Daniel Dunbar | 2e4e110 | 2012-10-22 18:30:51 +0000 | [diff] [blame] | 717 | } else if (Triple.isOSDarwin()) { |
| 718 | // The backend is hardwired to assume AAPCS for M-class processors, ensure |
| 719 | // the frontend matches that. |
| 720 | if (StringRef(CPUName).startswith("cortex-m")) { |
| 721 | ABIName = "aapcs"; |
| 722 | } else { |
| 723 | ABIName = "apcs-gnu"; |
| 724 | } |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 725 | } else { |
| 726 | // Select the default based on the platform. |
| 727 | switch(Triple.getEnvironment()) { |
Logan Chien | 94a7142 | 2012-09-02 09:30:11 +0000 | [diff] [blame] | 728 | case llvm::Triple::Android: |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 729 | case llvm::Triple::GNUEABI: |
Jiangning Liu | ff104a1 | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 730 | case llvm::Triple::GNUEABIHF: |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 731 | ABIName = "aapcs-linux"; |
| 732 | break; |
| 733 | case llvm::Triple::EABI: |
| 734 | ABIName = "aapcs"; |
| 735 | break; |
| 736 | default: |
| 737 | ABIName = "apcs-gnu"; |
| 738 | } |
| 739 | } |
| 740 | CmdArgs.push_back("-target-abi"); |
| 741 | CmdArgs.push_back(ABIName); |
| 742 | |
| 743 | // Set the CPU based on -march= and -mcpu=. |
| 744 | CmdArgs.push_back("-target-cpu"); |
Daniel Dunbar | 2e4e110 | 2012-10-22 18:30:51 +0000 | [diff] [blame] | 745 | CmdArgs.push_back(Args.MakeArgString(CPUName)); |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 746 | |
| 747 | // Determine floating point ABI from the options & target defaults. |
| 748 | StringRef FloatABI = getARMFloatABI(D, Args, Triple); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 749 | if (FloatABI == "soft") { |
| 750 | // Floating point operations and argument passing are soft. |
| 751 | // |
| 752 | // FIXME: This changes CPP defines, we need -target-soft-float. |
Daniel Dunbar | 3b31526 | 2009-11-30 08:42:00 +0000 | [diff] [blame] | 753 | CmdArgs.push_back("-msoft-float"); |
Daniel Dunbar | 87667aa | 2009-12-08 19:49:51 +0000 | [diff] [blame] | 754 | CmdArgs.push_back("-mfloat-abi"); |
| 755 | CmdArgs.push_back("soft"); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 756 | } else if (FloatABI == "softfp") { |
| 757 | // Floating point operations are hard, but argument passing is soft. |
Daniel Dunbar | 87667aa | 2009-12-08 19:49:51 +0000 | [diff] [blame] | 758 | CmdArgs.push_back("-mfloat-abi"); |
| 759 | CmdArgs.push_back("soft"); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 760 | } else { |
| 761 | // Floating point operations and argument passing are hard. |
| 762 | assert(FloatABI == "hard" && "Invalid float abi!"); |
Daniel Dunbar | 87667aa | 2009-12-08 19:49:51 +0000 | [diff] [blame] | 763 | CmdArgs.push_back("-mfloat-abi"); |
| 764 | CmdArgs.push_back("hard"); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 765 | } |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 766 | |
| 767 | // Set appropriate target features for floating point mode. |
| 768 | // |
| 769 | // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these |
| 770 | // yet (it uses the -mfloat-abi and -msoft-float options above), and it is |
| 771 | // stripped out by the ARM target. |
| 772 | |
| 773 | // Use software floating point operations? |
| 774 | if (FloatABI == "soft") { |
| 775 | CmdArgs.push_back("-target-feature"); |
| 776 | CmdArgs.push_back("+soft-float"); |
| 777 | } |
| 778 | |
| 779 | // Use software floating point argument passing? |
| 780 | if (FloatABI != "hard") { |
| 781 | CmdArgs.push_back("-target-feature"); |
| 782 | CmdArgs.push_back("+soft-float-abi"); |
| 783 | } |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 784 | |
| 785 | // Honor -mfpu=. |
Chad Rosier | 9931727 | 2012-04-04 20:51:35 +0000 | [diff] [blame] | 786 | if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) |
Chad Rosier | f80f2a5 | 2012-04-04 20:56:36 +0000 | [diff] [blame] | 787 | addFPUArgs(D, A, Args, CmdArgs); |
Daniel Dunbar | 7187fac | 2011-03-17 00:07:34 +0000 | [diff] [blame] | 788 | |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 789 | // Honor -mfpmath=. |
| 790 | if (const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) |
Chad Rosier | 30fe6ba | 2012-04-04 22:13:40 +0000 | [diff] [blame] | 791 | addFPMathArgs(D, A, Args, CmdArgs, getARMTargetCPU(Args, Triple)); |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 792 | |
Daniel Dunbar | 7187fac | 2011-03-17 00:07:34 +0000 | [diff] [blame] | 793 | // Setting -msoft-float effectively disables NEON because of the GCC |
| 794 | // implementation, although the same isn't true of VFP or VFP3. |
| 795 | if (FloatABI == "soft") { |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 796 | CmdArgs.push_back("-target-feature"); |
| 797 | CmdArgs.push_back("-neon"); |
| 798 | } |
| 799 | |
| 800 | // Kernel code has more strict alignment requirements. |
| 801 | if (KernelOrKext) { |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 802 | if (Triple.getOS() != llvm::Triple::IOS || Triple.isOSVersionLT(6)) { |
| 803 | CmdArgs.push_back("-backend-option"); |
| 804 | CmdArgs.push_back("-arm-long-calls"); |
| 805 | } |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 806 | |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 807 | CmdArgs.push_back("-backend-option"); |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 808 | CmdArgs.push_back("-arm-strict-align"); |
Daniel Dunbar | b5fbb89 | 2011-04-18 21:26:42 +0000 | [diff] [blame] | 809 | |
| 810 | // The kext linker doesn't know how to deal with movw/movt. |
Daniel Dunbar | b5fbb89 | 2011-04-18 21:26:42 +0000 | [diff] [blame] | 811 | CmdArgs.push_back("-backend-option"); |
| 812 | CmdArgs.push_back("-arm-darwin-use-movt=0"); |
Daniel Dunbar | 7187fac | 2011-03-17 00:07:34 +0000 | [diff] [blame] | 813 | } |
Chad Rosier | 1b90605 | 2011-08-26 00:26:29 +0000 | [diff] [blame] | 814 | |
| 815 | // Setting -mno-global-merge disables the codegen global merge pass. Setting |
| 816 | // -mglobal-merge has no effect as the pass is enabled by default. |
| 817 | if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge, |
| 818 | options::OPT_mno_global_merge)) { |
| 819 | if (A->getOption().matches(options::OPT_mno_global_merge)) |
| 820 | CmdArgs.push_back("-mno-global-merge"); |
| 821 | } |
Chad Rosier | ee9ad5c | 2012-05-16 20:40:09 +0000 | [diff] [blame] | 822 | |
Chad Rosier | 005af27 | 2012-05-16 21:19:55 +0000 | [diff] [blame] | 823 | if (Args.hasArg(options::OPT_mno_implicit_float)) |
Chad Rosier | ee9ad5c | 2012-05-16 20:40:09 +0000 | [diff] [blame] | 824 | CmdArgs.push_back("-no-implicit-float"); |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 825 | } |
| 826 | |
Simon Atanasyan | 8e1c598 | 2012-09-21 20:19:32 +0000 | [diff] [blame] | 827 | // Translate MIPS CPU name alias option to CPU name. |
| 828 | static StringRef getMipsCPUFromAlias(const Arg &A) { |
| 829 | if (A.getOption().matches(options::OPT_mips32)) |
| 830 | return "mips32"; |
| 831 | if (A.getOption().matches(options::OPT_mips32r2)) |
| 832 | return "mips32r2"; |
| 833 | if (A.getOption().matches(options::OPT_mips64)) |
| 834 | return "mips64"; |
| 835 | if (A.getOption().matches(options::OPT_mips64r2)) |
| 836 | return "mips64r2"; |
| 837 | llvm_unreachable("Unexpected option"); |
| 838 | return ""; |
| 839 | } |
| 840 | |
Simon Atanasyan | a2768be | 2012-04-07 22:09:23 +0000 | [diff] [blame] | 841 | // Get CPU and ABI names. They are not independent |
| 842 | // so we have to calculate them together. |
| 843 | static void getMipsCPUAndABI(const ArgList &Args, |
| 844 | const ToolChain &TC, |
| 845 | StringRef &CPUName, |
| 846 | StringRef &ABIName) { |
Simon Atanasyan | 89d83ff | 2012-09-10 08:32:41 +0000 | [diff] [blame] | 847 | const char *DefMips32CPU = "mips32"; |
| 848 | const char *DefMips64CPU = "mips64"; |
Akira Hatanaka | 9f36062 | 2011-09-26 21:07:52 +0000 | [diff] [blame] | 849 | |
Simon Atanasyan | 89d83ff | 2012-09-10 08:32:41 +0000 | [diff] [blame] | 850 | if (Arg *A = Args.getLastArg(options::OPT_march_EQ, |
Simon Atanasyan | 8e1c598 | 2012-09-21 20:19:32 +0000 | [diff] [blame] | 851 | options::OPT_mcpu_EQ, |
| 852 | options::OPT_mips_CPUs_Group)) { |
| 853 | if (A->getOption().matches(options::OPT_mips_CPUs_Group)) |
| 854 | CPUName = getMipsCPUFromAlias(*A); |
| 855 | else |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 856 | CPUName = A->getValue(); |
Simon Atanasyan | 8e1c598 | 2012-09-21 20:19:32 +0000 | [diff] [blame] | 857 | } |
Simon Atanasyan | 89d83ff | 2012-09-10 08:32:41 +0000 | [diff] [blame] | 858 | |
Akira Hatanaka | 9f36062 | 2011-09-26 21:07:52 +0000 | [diff] [blame] | 859 | if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 860 | ABIName = A->getValue(); |
Simon Atanasyan | 89d83ff | 2012-09-10 08:32:41 +0000 | [diff] [blame] | 861 | |
| 862 | // Setup default CPU and ABI names. |
| 863 | if (CPUName.empty() && ABIName.empty()) { |
| 864 | switch (TC.getTriple().getArch()) { |
| 865 | default: |
| 866 | llvm_unreachable("Unexpected triple arch name"); |
| 867 | case llvm::Triple::mips: |
| 868 | case llvm::Triple::mipsel: |
| 869 | CPUName = DefMips32CPU; |
| 870 | break; |
| 871 | case llvm::Triple::mips64: |
| 872 | case llvm::Triple::mips64el: |
| 873 | CPUName = DefMips64CPU; |
| 874 | break; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | if (!ABIName.empty()) { |
| 879 | // Deduce CPU name from ABI name. |
| 880 | CPUName = llvm::StringSwitch<const char *>(ABIName) |
| 881 | .Cases("o32", "eabi", DefMips32CPU) |
| 882 | .Cases("n32", "n64", DefMips64CPU) |
| 883 | .Default(""); |
| 884 | } |
| 885 | else if (!CPUName.empty()) { |
| 886 | // Deduce ABI name from CPU name. |
| 887 | ABIName = llvm::StringSwitch<const char *>(CPUName) |
| 888 | .Cases("mips32", "mips32r2", "o32") |
| 889 | .Cases("mips64", "mips64r2", "n64") |
| 890 | .Default(""); |
| 891 | } |
| 892 | |
| 893 | // FIXME: Warn on inconsistent cpu and abi usage. |
Simon Atanasyan | a2768be | 2012-04-07 22:09:23 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Simon Atanasyan | 5e62779 | 2012-06-02 15:06:29 +0000 | [diff] [blame] | 896 | // Select the MIPS float ABI as determined by -msoft-float, -mhard-float, |
| 897 | // and -mfloat-abi=. |
| 898 | static StringRef getMipsFloatABI(const Driver &D, const ArgList &Args) { |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 899 | // Select the float ABI as determined by -msoft-float, -mhard-float, |
| 900 | // and -mfloat-abi=. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 901 | StringRef FloatABI; |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 902 | if (Arg *A = Args.getLastArg(options::OPT_msoft_float, |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 903 | options::OPT_mhard_float, |
| 904 | options::OPT_mfloat_abi_EQ)) { |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 905 | if (A->getOption().matches(options::OPT_msoft_float)) |
| 906 | FloatABI = "soft"; |
| 907 | else if (A->getOption().matches(options::OPT_mhard_float)) |
| 908 | FloatABI = "hard"; |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 909 | else { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 910 | FloatABI = A->getValue(); |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 911 | if (FloatABI != "soft" && FloatABI != "single" && FloatABI != "hard") { |
Simon Atanasyan | 5e62779 | 2012-06-02 15:06:29 +0000 | [diff] [blame] | 912 | D.Diag(diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args); |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 913 | FloatABI = "hard"; |
| 914 | } |
| 915 | } |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | // If unspecified, choose the default based on the platform. |
| 919 | if (FloatABI.empty()) { |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 920 | // Assume "hard", because it's a default value used by gcc. |
| 921 | // When we start to recognize specific target MIPS processors, |
| 922 | // we will be able to select the default more correctly. |
| 923 | FloatABI = "hard"; |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Simon Atanasyan | 5e62779 | 2012-06-02 15:06:29 +0000 | [diff] [blame] | 926 | return FloatABI; |
| 927 | } |
| 928 | |
Simon Atanasyan | dc536f5 | 2012-07-05 18:51:43 +0000 | [diff] [blame] | 929 | static void AddTargetFeature(const ArgList &Args, |
| 930 | ArgStringList &CmdArgs, |
| 931 | OptSpecifier OnOpt, |
| 932 | OptSpecifier OffOpt, |
| 933 | StringRef FeatureName) { |
| 934 | if (Arg *A = Args.getLastArg(OnOpt, OffOpt)) { |
| 935 | CmdArgs.push_back("-target-feature"); |
| 936 | if (A->getOption().matches(OnOpt)) |
| 937 | CmdArgs.push_back(Args.MakeArgString("+" + FeatureName)); |
| 938 | else |
| 939 | CmdArgs.push_back(Args.MakeArgString("-" + FeatureName)); |
| 940 | } |
| 941 | } |
| 942 | |
Simon Atanasyan | 5e62779 | 2012-06-02 15:06:29 +0000 | [diff] [blame] | 943 | void Clang::AddMIPSTargetArgs(const ArgList &Args, |
| 944 | ArgStringList &CmdArgs) const { |
| 945 | const Driver &D = getToolChain().getDriver(); |
| 946 | StringRef CPUName; |
| 947 | StringRef ABIName; |
| 948 | getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName); |
| 949 | |
| 950 | CmdArgs.push_back("-target-cpu"); |
| 951 | CmdArgs.push_back(CPUName.data()); |
| 952 | |
| 953 | CmdArgs.push_back("-target-abi"); |
| 954 | CmdArgs.push_back(ABIName.data()); |
| 955 | |
| 956 | StringRef FloatABI = getMipsFloatABI(D, Args); |
| 957 | |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 958 | if (FloatABI == "soft") { |
| 959 | // Floating point operations and argument passing are soft. |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 960 | CmdArgs.push_back("-msoft-float"); |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 961 | CmdArgs.push_back("-mfloat-abi"); |
| 962 | CmdArgs.push_back("soft"); |
| 963 | |
| 964 | // FIXME: Note, this is a hack. We need to pass the selected float |
| 965 | // mode to the MipsTargetInfoBase to define appropriate macros there. |
| 966 | // Now it is the only method. |
| 967 | CmdArgs.push_back("-target-feature"); |
| 968 | CmdArgs.push_back("+soft-float"); |
| 969 | } |
| 970 | else if (FloatABI == "single") { |
| 971 | // Restrict the use of hardware floating-point |
| 972 | // instructions to 32-bit operations. |
| 973 | CmdArgs.push_back("-target-feature"); |
| 974 | CmdArgs.push_back("+single-float"); |
| 975 | } |
| 976 | else { |
| 977 | // Floating point operations and argument passing are hard. |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 978 | assert(FloatABI == "hard" && "Invalid float abi!"); |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 979 | CmdArgs.push_back("-mfloat-abi"); |
| 980 | CmdArgs.push_back("hard"); |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 981 | } |
Simon Atanasyan | 0b273ef | 2012-07-05 14:19:39 +0000 | [diff] [blame] | 982 | |
Simon Atanasyan | dc536f5 | 2012-07-05 18:51:43 +0000 | [diff] [blame] | 983 | AddTargetFeature(Args, CmdArgs, |
| 984 | options::OPT_mips16, options::OPT_mno_mips16, |
| 985 | "mips16"); |
Simon Atanasyan | d797a85 | 2012-07-05 19:23:00 +0000 | [diff] [blame] | 986 | AddTargetFeature(Args, CmdArgs, |
| 987 | options::OPT_mdsp, options::OPT_mno_dsp, |
| 988 | "dsp"); |
| 989 | AddTargetFeature(Args, CmdArgs, |
| 990 | options::OPT_mdspr2, options::OPT_mno_dspr2, |
| 991 | "dspr2"); |
Simon Atanasyan | 9804b76 | 2012-08-27 20:55:56 +0000 | [diff] [blame] | 992 | |
Simon Atanasyan | bda07ac | 2012-12-01 18:27:21 +0000 | [diff] [blame] | 993 | if (Arg *A = Args.getLastArg(options::OPT_mxgot, options::OPT_mno_xgot)) { |
| 994 | if (A->getOption().matches(options::OPT_mxgot)) { |
| 995 | CmdArgs.push_back("-mllvm"); |
| 996 | CmdArgs.push_back("-mxgot"); |
| 997 | } |
| 998 | } |
| 999 | |
Simon Atanasyan | 9804b76 | 2012-08-27 20:55:56 +0000 | [diff] [blame] | 1000 | if (Arg *A = Args.getLastArg(options::OPT_G)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1001 | StringRef v = A->getValue(); |
Simon Atanasyan | 9804b76 | 2012-08-27 20:55:56 +0000 | [diff] [blame] | 1002 | CmdArgs.push_back("-mllvm"); |
| 1003 | CmdArgs.push_back(Args.MakeArgString("-mips-ssection-threshold=" + v)); |
| 1004 | A->claim(); |
| 1005 | } |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Hal Finkel | 02a8427 | 2012-06-11 22:35:19 +0000 | [diff] [blame] | 1008 | /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting. |
| 1009 | static std::string getPPCTargetCPU(const ArgList &Args) { |
| 1010 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1011 | StringRef CPUName = A->getValue(); |
Hal Finkel | 02a8427 | 2012-06-11 22:35:19 +0000 | [diff] [blame] | 1012 | |
| 1013 | if (CPUName == "native") { |
| 1014 | std::string CPU = llvm::sys::getHostCPUName(); |
| 1015 | if (!CPU.empty() && CPU != "generic") |
| 1016 | return CPU; |
| 1017 | else |
| 1018 | return ""; |
| 1019 | } |
| 1020 | |
| 1021 | return llvm::StringSwitch<const char *>(CPUName) |
| 1022 | .Case("common", "generic") |
| 1023 | .Case("440", "440") |
| 1024 | .Case("440fp", "440") |
| 1025 | .Case("450", "450") |
| 1026 | .Case("601", "601") |
| 1027 | .Case("602", "602") |
| 1028 | .Case("603", "603") |
| 1029 | .Case("603e", "603e") |
| 1030 | .Case("603ev", "603ev") |
| 1031 | .Case("604", "604") |
| 1032 | .Case("604e", "604e") |
| 1033 | .Case("620", "620") |
| 1034 | .Case("G3", "g3") |
| 1035 | .Case("7400", "7400") |
| 1036 | .Case("G4", "g4") |
| 1037 | .Case("7450", "7450") |
| 1038 | .Case("G4+", "g4+") |
| 1039 | .Case("750", "750") |
| 1040 | .Case("970", "970") |
| 1041 | .Case("G5", "g5") |
| 1042 | .Case("a2", "a2") |
Hal Finkel | 7de3296 | 2012-09-18 22:25:03 +0000 | [diff] [blame] | 1043 | .Case("e500mc", "e500mc") |
| 1044 | .Case("e5500", "e5500") |
Hal Finkel | 02a8427 | 2012-06-11 22:35:19 +0000 | [diff] [blame] | 1045 | .Case("power6", "pwr6") |
| 1046 | .Case("power7", "pwr7") |
| 1047 | .Case("powerpc", "ppc") |
| 1048 | .Case("powerpc64", "ppc64") |
| 1049 | .Default(""); |
| 1050 | } |
| 1051 | |
| 1052 | return ""; |
| 1053 | } |
| 1054 | |
| 1055 | void Clang::AddPPCTargetArgs(const ArgList &Args, |
| 1056 | ArgStringList &CmdArgs) const { |
| 1057 | std::string TargetCPUName = getPPCTargetCPU(Args); |
| 1058 | |
| 1059 | // LLVM may default to generating code for the native CPU, |
| 1060 | // but, like gcc, we default to a more generic option for |
| 1061 | // each architecture. (except on Darwin) |
| 1062 | llvm::Triple Triple = getToolChain().getTriple(); |
| 1063 | if (TargetCPUName.empty() && !Triple.isOSDarwin()) { |
| 1064 | if (Triple.getArch() == llvm::Triple::ppc64) |
| 1065 | TargetCPUName = "ppc64"; |
| 1066 | else |
| 1067 | TargetCPUName = "ppc"; |
| 1068 | } |
| 1069 | |
| 1070 | if (!TargetCPUName.empty()) { |
| 1071 | CmdArgs.push_back("-target-cpu"); |
| 1072 | CmdArgs.push_back(Args.MakeArgString(TargetCPUName.c_str())); |
| 1073 | } |
| 1074 | } |
| 1075 | |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1076 | void Clang::AddSparcTargetArgs(const ArgList &Args, |
| 1077 | ArgStringList &CmdArgs) const { |
| 1078 | const Driver &D = getToolChain().getDriver(); |
| 1079 | |
| 1080 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1081 | CmdArgs.push_back("-target-cpu"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1082 | CmdArgs.push_back(A->getValue()); |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | // Select the float ABI as determined by -msoft-float, -mhard-float, and |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1086 | StringRef FloatABI; |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1087 | if (Arg *A = Args.getLastArg(options::OPT_msoft_float, |
| 1088 | options::OPT_mhard_float)) { |
| 1089 | if (A->getOption().matches(options::OPT_msoft_float)) |
| 1090 | FloatABI = "soft"; |
| 1091 | else if (A->getOption().matches(options::OPT_mhard_float)) |
| 1092 | FloatABI = "hard"; |
| 1093 | } |
| 1094 | |
| 1095 | // If unspecified, choose the default based on the platform. |
| 1096 | if (FloatABI.empty()) { |
| 1097 | switch (getToolChain().getTriple().getOS()) { |
| 1098 | default: |
| 1099 | // Assume "soft", but warn the user we are guessing. |
| 1100 | FloatABI = "soft"; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1101 | D.Diag(diag::warn_drv_assuming_mfloat_abi_is) << "soft"; |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1102 | break; |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | if (FloatABI == "soft") { |
| 1107 | // Floating point operations and argument passing are soft. |
| 1108 | // |
| 1109 | // FIXME: This changes CPP defines, we need -target-soft-float. |
| 1110 | CmdArgs.push_back("-msoft-float"); |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1111 | CmdArgs.push_back("-target-feature"); |
| 1112 | CmdArgs.push_back("+soft-float"); |
| 1113 | } else { |
| 1114 | assert(FloatABI == "hard" && "Invalid float abi!"); |
| 1115 | CmdArgs.push_back("-mhard-float"); |
| 1116 | } |
| 1117 | } |
| 1118 | |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1119 | void Clang::AddX86TargetArgs(const ArgList &Args, |
| 1120 | ArgStringList &CmdArgs) const { |
Rafael Espindola | 715852c | 2012-11-02 20:41:30 +0000 | [diff] [blame] | 1121 | const bool isAndroid = |
| 1122 | getToolChain().getTriple().getEnvironment() == llvm::Triple::Android; |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 1123 | if (!Args.hasFlag(options::OPT_mred_zone, |
| 1124 | options::OPT_mno_red_zone, |
| 1125 | true) || |
| 1126 | Args.hasArg(options::OPT_mkernel) || |
| 1127 | Args.hasArg(options::OPT_fapple_kext)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 1128 | CmdArgs.push_back("-disable-red-zone"); |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 1129 | |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 1130 | if (Args.hasFlag(options::OPT_msoft_float, |
| 1131 | options::OPT_mno_soft_float, |
| 1132 | false)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 1133 | CmdArgs.push_back("-no-implicit-float"); |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 1134 | |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1135 | const char *CPUName = 0; |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1136 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1137 | if (StringRef(A->getValue()) == "native") { |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1138 | // FIXME: Reject attempts to use -march=native unless the target matches |
| 1139 | // the host. |
| 1140 | // |
| 1141 | // FIXME: We should also incorporate the detected target features for use |
| 1142 | // with -native. |
| 1143 | std::string CPU = llvm::sys::getHostCPUName(); |
Bob Wilson | e0cc309 | 2012-05-09 17:53:10 +0000 | [diff] [blame] | 1144 | if (!CPU.empty() && CPU != "generic") |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1145 | CPUName = Args.MakeArgString(CPU); |
| 1146 | } else |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1147 | CPUName = A->getValue(); |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1148 | } |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1149 | |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1150 | // Select the default CPU if none was given (or detection failed). |
| 1151 | if (!CPUName) { |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1152 | // FIXME: Need target hooks. |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 1153 | if (getToolChain().getTriple().isOSDarwin()) { |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1154 | if (getToolChain().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1155 | CPUName = "core2"; |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1156 | else if (getToolChain().getArch() == llvm::Triple::x86) |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1157 | CPUName = "yonah"; |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 1158 | } else if (getToolChain().getOS().startswith("haiku")) { |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1159 | if (getToolChain().getArch() == llvm::Triple::x86_64) |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 1160 | CPUName = "x86-64"; |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1161 | else if (getToolChain().getArch() == llvm::Triple::x86) |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 1162 | CPUName = "i586"; |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 1163 | } else if (getToolChain().getOS().startswith("openbsd")) { |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1164 | if (getToolChain().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 1165 | CPUName = "x86-64"; |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1166 | else if (getToolChain().getArch() == llvm::Triple::x86) |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 1167 | CPUName = "i486"; |
Eli Friedman | 42f74f2 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 1168 | } else if (getToolChain().getOS().startswith("bitrig")) { |
| 1169 | if (getToolChain().getArch() == llvm::Triple::x86_64) |
| 1170 | CPUName = "x86-64"; |
| 1171 | else if (getToolChain().getArch() == llvm::Triple::x86) |
| 1172 | CPUName = "i686"; |
Roman Divacky | 451f8ca | 2011-03-01 18:11:37 +0000 | [diff] [blame] | 1173 | } else if (getToolChain().getOS().startswith("freebsd")) { |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1174 | if (getToolChain().getArch() == llvm::Triple::x86_64) |
Roman Divacky | 451f8ca | 2011-03-01 18:11:37 +0000 | [diff] [blame] | 1175 | CPUName = "x86-64"; |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1176 | else if (getToolChain().getArch() == llvm::Triple::x86) |
Roman Divacky | 451f8ca | 2011-03-01 18:11:37 +0000 | [diff] [blame] | 1177 | CPUName = "i486"; |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1178 | } else if (getToolChain().getOS().startswith("netbsd")) { |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1179 | if (getToolChain().getArch() == llvm::Triple::x86_64) |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1180 | CPUName = "x86-64"; |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1181 | else if (getToolChain().getArch() == llvm::Triple::x86) |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 1182 | CPUName = "i486"; |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1183 | } else { |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1184 | if (getToolChain().getArch() == llvm::Triple::x86_64) |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1185 | CPUName = "x86-64"; |
Daniel Dunbar | 951733d | 2011-05-31 15:58:55 +0000 | [diff] [blame] | 1186 | else if (getToolChain().getArch() == llvm::Triple::x86) |
Rafael Espindola | 715852c | 2012-11-02 20:41:30 +0000 | [diff] [blame] | 1187 | // All x86 devices running Android have core2 as their common |
| 1188 | // denominator. This makes a better choice than pentium4. |
| 1189 | CPUName = isAndroid ? "core2" : "pentium4"; |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1190 | } |
| 1191 | } |
| 1192 | |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1193 | if (CPUName) { |
Daniel Dunbar | 38b48af | 2009-12-18 06:30:12 +0000 | [diff] [blame] | 1194 | CmdArgs.push_back("-target-cpu"); |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1195 | CmdArgs.push_back(CPUName); |
| 1196 | } |
| 1197 | |
Eli Friedman | d18eeca | 2011-07-02 00:34:19 +0000 | [diff] [blame] | 1198 | // The required algorithm here is slightly strange: the options are applied |
| 1199 | // in order (so -mno-sse -msse2 disables SSE3), but any option that gets |
| 1200 | // directly overridden later is ignored (so "-mno-sse -msse2 -mno-sse2 -msse" |
| 1201 | // is equivalent to "-mno-sse2 -msse"). The -cc1 handling deals with the |
| 1202 | // former correctly, but not the latter; handle directly-overridden |
| 1203 | // attributes here. |
| 1204 | llvm::StringMap<unsigned> PrevFeature; |
| 1205 | std::vector<const char*> Features; |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 1206 | for (arg_iterator it = Args.filtered_begin(options::OPT_m_x86_Features_Group), |
| 1207 | ie = Args.filtered_end(); it != ie; ++it) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1208 | StringRef Name = (*it)->getOption().getName(); |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1209 | (*it)->claim(); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1210 | |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 1211 | // Skip over "-m". |
Michael J. Spencer | c635710 | 2012-10-22 22:13:48 +0000 | [diff] [blame] | 1212 | assert(Name.startswith("m") && "Invalid feature name."); |
| 1213 | Name = Name.substr(1); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1214 | |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 1215 | bool IsNegative = Name.startswith("no-"); |
| 1216 | if (IsNegative) |
| 1217 | Name = Name.substr(3); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1218 | |
Eli Friedman | d18eeca | 2011-07-02 00:34:19 +0000 | [diff] [blame] | 1219 | unsigned& Prev = PrevFeature[Name]; |
| 1220 | if (Prev) |
| 1221 | Features[Prev - 1] = 0; |
| 1222 | Prev = Features.size() + 1; |
| 1223 | Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); |
| 1224 | } |
| 1225 | for (unsigned i = 0; i < Features.size(); i++) { |
| 1226 | if (Features[i]) { |
| 1227 | CmdArgs.push_back("-target-feature"); |
| 1228 | CmdArgs.push_back(Features[i]); |
| 1229 | } |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1230 | } |
| 1231 | } |
| 1232 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1233 | static Arg* getLastHexagonArchArg (const ArgList &Args) |
| 1234 | { |
| 1235 | Arg * A = NULL; |
| 1236 | |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 1237 | for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); |
| 1238 | it != ie; ++it) { |
| 1239 | if ((*it)->getOption().matches(options::OPT_march_EQ) || |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1240 | (*it)->getOption().matches(options::OPT_mcpu_EQ)) { |
| 1241 | A = *it; |
| 1242 | A->claim(); |
| 1243 | } |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 1244 | else if ((*it)->getOption().matches(options::OPT_m_Joined)){ |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1245 | StringRef Value = (*it)->getValue(0); |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 1246 | if (Value.startswith("v")) { |
| 1247 | A = *it; |
| 1248 | A->claim(); |
| 1249 | } |
| 1250 | } |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1251 | } |
| 1252 | return A; |
| 1253 | } |
| 1254 | |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 1255 | static StringRef getHexagonTargetCPU(const ArgList &Args) |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1256 | { |
| 1257 | Arg *A; |
| 1258 | llvm::StringRef WhichHexagon; |
| 1259 | |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 1260 | // Select the default CPU (v4) if none was given or detection failed. |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1261 | if ((A = getLastHexagonArchArg (Args))) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1262 | WhichHexagon = A->getValue(); |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 1263 | if (WhichHexagon == "") |
| 1264 | return "v4"; |
| 1265 | else |
| 1266 | return WhichHexagon; |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1267 | } |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 1268 | else |
| 1269 | return "v4"; |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | void Clang::AddHexagonTargetArgs(const ArgList &Args, |
| 1273 | ArgStringList &CmdArgs) const { |
| 1274 | llvm::Triple Triple = getToolChain().getTriple(); |
| 1275 | |
| 1276 | CmdArgs.push_back("-target-cpu"); |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 1277 | CmdArgs.push_back(Args.MakeArgString("hexagon" + getHexagonTargetCPU(Args))); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1278 | CmdArgs.push_back("-fno-signed-char"); |
| 1279 | CmdArgs.push_back("-nobuiltininc"); |
| 1280 | |
Sirish Pande | 5f9688b | 2012-05-10 20:19:54 +0000 | [diff] [blame] | 1281 | if (Args.hasArg(options::OPT_mqdsp6_compat)) |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1282 | CmdArgs.push_back("-mqdsp6-compat"); |
| 1283 | |
| 1284 | if (Arg *A = Args.getLastArg(options::OPT_G, |
| 1285 | options::OPT_msmall_data_threshold_EQ)) { |
| 1286 | std::string SmallDataThreshold="-small-data-threshold="; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1287 | SmallDataThreshold += A->getValue(); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1288 | CmdArgs.push_back ("-mllvm"); |
| 1289 | CmdArgs.push_back(Args.MakeArgString(SmallDataThreshold)); |
| 1290 | A->claim(); |
| 1291 | } |
| 1292 | |
Sirish Pande | 5f9688b | 2012-05-10 20:19:54 +0000 | [diff] [blame] | 1293 | if (!Args.hasArg(options::OPT_fno_short_enums)) |
| 1294 | CmdArgs.push_back("-fshort-enums"); |
| 1295 | if (Args.getLastArg(options::OPT_mieee_rnd_near)) { |
| 1296 | CmdArgs.push_back ("-mllvm"); |
| 1297 | CmdArgs.push_back ("-enable-hexagon-ieee-rnd-near"); |
| 1298 | } |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1299 | CmdArgs.push_back ("-mllvm"); |
| 1300 | CmdArgs.push_back ("-machine-sink-split=0"); |
| 1301 | } |
| 1302 | |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1303 | static bool |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1304 | shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime, |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1305 | const llvm::Triple &Triple) { |
| 1306 | // We use the zero-cost exception tables for Objective-C if the non-fragile |
| 1307 | // ABI is enabled or when compiling for x86_64 and ARM on Snow Leopard and |
| 1308 | // later. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1309 | if (runtime.isNonFragile()) |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1310 | return true; |
| 1311 | |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 1312 | if (!Triple.isOSDarwin()) |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1313 | return false; |
| 1314 | |
Eric Christopher | aa7333c | 2011-07-02 00:20:22 +0000 | [diff] [blame] | 1315 | return (!Triple.isMacOSXVersionLT(10,5) && |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1316 | (Triple.getArch() == llvm::Triple::x86_64 || |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1317 | Triple.getArch() == llvm::Triple::arm)); |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1320 | /// addExceptionArgs - Adds exception related arguments to the driver command |
| 1321 | /// arguments. There's a master flag, -fexceptions and also language specific |
| 1322 | /// flags to enable/disable C++ and Objective-C exceptions. |
| 1323 | /// This makes it possible to for example disable C++ exceptions but enable |
| 1324 | /// Objective-C exceptions. |
| 1325 | static void addExceptionArgs(const ArgList &Args, types::ID InputType, |
| 1326 | const llvm::Triple &Triple, |
Fariborz Jahanian | 15b7731 | 2012-04-04 18:28:00 +0000 | [diff] [blame] | 1327 | bool KernelOrKext, |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1328 | const ObjCRuntime &objcRuntime, |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1329 | ArgStringList &CmdArgs) { |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 1330 | if (KernelOrKext) { |
| 1331 | // -mkernel and -fapple-kext imply no exceptions, so claim exception related |
| 1332 | // arguments now to avoid warnings about unused arguments. |
| 1333 | Args.ClaimAllArgs(options::OPT_fexceptions); |
| 1334 | Args.ClaimAllArgs(options::OPT_fno_exceptions); |
| 1335 | Args.ClaimAllArgs(options::OPT_fobjc_exceptions); |
| 1336 | Args.ClaimAllArgs(options::OPT_fno_objc_exceptions); |
| 1337 | Args.ClaimAllArgs(options::OPT_fcxx_exceptions); |
| 1338 | Args.ClaimAllArgs(options::OPT_fno_cxx_exceptions); |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1339 | return; |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 1340 | } |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1341 | |
| 1342 | // Exceptions are enabled by default. |
| 1343 | bool ExceptionsEnabled = true; |
| 1344 | |
| 1345 | // This keeps track of whether exceptions were explicitly turned on or off. |
| 1346 | bool DidHaveExplicitExceptionFlag = false; |
| 1347 | |
Rafael Espindola | f759df0 | 2009-10-01 13:33:33 +0000 | [diff] [blame] | 1348 | if (Arg *A = Args.getLastArg(options::OPT_fexceptions, |
| 1349 | options::OPT_fno_exceptions)) { |
| 1350 | if (A->getOption().matches(options::OPT_fexceptions)) |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1351 | ExceptionsEnabled = true; |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1352 | else |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1353 | ExceptionsEnabled = false; |
| 1354 | |
| 1355 | DidHaveExplicitExceptionFlag = true; |
Rafael Espindola | f759df0 | 2009-10-01 13:33:33 +0000 | [diff] [blame] | 1356 | } |
Daniel Dunbar | 1a2cd4f | 2010-09-14 23:12:31 +0000 | [diff] [blame] | 1357 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1358 | bool ShouldUseExceptionTables = false; |
Fariborz Jahanian | 85caf03 | 2009-10-01 20:30:46 +0000 | [diff] [blame] | 1359 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1360 | // Exception tables and cleanups can be enabled with -fexceptions even if the |
| 1361 | // language itself doesn't support exceptions. |
| 1362 | if (ExceptionsEnabled && DidHaveExplicitExceptionFlag) |
| 1363 | ShouldUseExceptionTables = true; |
Daniel Dunbar | 1a2cd4f | 2010-09-14 23:12:31 +0000 | [diff] [blame] | 1364 | |
Daniel Dunbar | d47ea69 | 2011-03-17 23:28:31 +0000 | [diff] [blame] | 1365 | // Obj-C exceptions are enabled by default, regardless of -fexceptions. This |
| 1366 | // is not necessarily sensible, but follows GCC. |
| 1367 | if (types::isObjC(InputType) && |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1368 | Args.hasFlag(options::OPT_fobjc_exceptions, |
Daniel Dunbar | d47ea69 | 2011-03-17 23:28:31 +0000 | [diff] [blame] | 1369 | options::OPT_fno_objc_exceptions, |
| 1370 | true)) { |
| 1371 | CmdArgs.push_back("-fobjc-exceptions"); |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1372 | |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1373 | ShouldUseExceptionTables |= |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1374 | shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple); |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | if (types::isCXX(InputType)) { |
| 1378 | bool CXXExceptionsEnabled = ExceptionsEnabled; |
| 1379 | |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1380 | if (Arg *A = Args.getLastArg(options::OPT_fcxx_exceptions, |
| 1381 | options::OPT_fno_cxx_exceptions, |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1382 | options::OPT_fexceptions, |
| 1383 | options::OPT_fno_exceptions)) { |
| 1384 | if (A->getOption().matches(options::OPT_fcxx_exceptions)) |
| 1385 | CXXExceptionsEnabled = true; |
Chandler Carruth | 43f220f | 2011-02-28 07:25:18 +0000 | [diff] [blame] | 1386 | else if (A->getOption().matches(options::OPT_fno_cxx_exceptions)) |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1387 | CXXExceptionsEnabled = false; |
| 1388 | } |
| 1389 | |
| 1390 | if (CXXExceptionsEnabled) { |
| 1391 | CmdArgs.push_back("-fcxx-exceptions"); |
| 1392 | |
| 1393 | ShouldUseExceptionTables = true; |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | if (ShouldUseExceptionTables) |
| 1398 | CmdArgs.push_back("-fexceptions"); |
Rafael Espindola | f759df0 | 2009-10-01 13:33:33 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
Rafael Espindola | 61b1efe | 2011-05-02 17:43:32 +0000 | [diff] [blame] | 1401 | static bool ShouldDisableCFI(const ArgList &Args, |
| 1402 | const ToolChain &TC) { |
Rafael Espindola | 701ec8d | 2012-03-08 14:39:55 +0000 | [diff] [blame] | 1403 | bool Default = true; |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 1404 | if (TC.getTriple().isOSDarwin()) { |
Rafael Espindola | 97f6abb | 2011-05-17 16:26:17 +0000 | [diff] [blame] | 1405 | // The native darwin assembler doesn't support cfi directives, so |
Rafael Espindola | cb77392 | 2011-05-17 19:06:58 +0000 | [diff] [blame] | 1406 | // we disable them if we think the .s file will be passed to it. |
Rafael Espindola | 701ec8d | 2012-03-08 14:39:55 +0000 | [diff] [blame] | 1407 | Default = Args.hasFlag(options::OPT_integrated_as, |
| 1408 | options::OPT_no_integrated_as, |
| 1409 | TC.IsIntegratedAssemblerDefault()); |
Rafael Espindola | 97f6abb | 2011-05-17 16:26:17 +0000 | [diff] [blame] | 1410 | } |
Rafael Espindola | 701ec8d | 2012-03-08 14:39:55 +0000 | [diff] [blame] | 1411 | return !Args.hasFlag(options::OPT_fdwarf2_cfi_asm, |
| 1412 | options::OPT_fno_dwarf2_cfi_asm, |
| 1413 | Default); |
Rafael Espindola | 61b1efe | 2011-05-02 17:43:32 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 1416 | static bool ShouldDisableDwarfDirectory(const ArgList &Args, |
| 1417 | const ToolChain &TC) { |
| 1418 | bool IsIADefault = TC.IsIntegratedAssemblerDefault(); |
| 1419 | bool UseIntegratedAs = Args.hasFlag(options::OPT_integrated_as, |
| 1420 | options::OPT_no_integrated_as, |
| 1421 | IsIADefault); |
| 1422 | bool UseDwarfDirectory = Args.hasFlag(options::OPT_fdwarf_directory_asm, |
| 1423 | options::OPT_fno_dwarf_directory_asm, |
| 1424 | UseIntegratedAs); |
| 1425 | return !UseDwarfDirectory; |
| 1426 | } |
| 1427 | |
Joerg Sonnenberger | 359cf92 | 2011-05-06 14:35:16 +0000 | [diff] [blame] | 1428 | /// \brief Check whether the given input tree contains any compilation actions. |
| 1429 | static bool ContainsCompileAction(const Action *A) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1430 | if (isa<CompileJobAction>(A)) |
Joerg Sonnenberger | 359cf92 | 2011-05-06 14:35:16 +0000 | [diff] [blame] | 1431 | return true; |
| 1432 | |
| 1433 | for (Action::const_iterator it = A->begin(), ie = A->end(); it != ie; ++it) |
| 1434 | if (ContainsCompileAction(*it)) |
| 1435 | return true; |
| 1436 | |
| 1437 | return false; |
| 1438 | } |
| 1439 | |
| 1440 | /// \brief Check if -relax-all should be passed to the internal assembler. |
| 1441 | /// This is done by default when compiling non-assembler source with -O0. |
| 1442 | static bool UseRelaxAll(Compilation &C, const ArgList &Args) { |
| 1443 | bool RelaxDefault = true; |
| 1444 | |
| 1445 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) |
| 1446 | RelaxDefault = A->getOption().matches(options::OPT_O0); |
| 1447 | |
| 1448 | if (RelaxDefault) { |
| 1449 | RelaxDefault = false; |
| 1450 | for (ActionList::const_iterator it = C.getActions().begin(), |
| 1451 | ie = C.getActions().end(); it != ie; ++it) { |
| 1452 | if (ContainsCompileAction(*it)) { |
| 1453 | RelaxDefault = true; |
| 1454 | break; |
| 1455 | } |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | return Args.hasFlag(options::OPT_mrelax_all, options::OPT_mno_relax_all, |
| 1460 | RelaxDefault); |
| 1461 | } |
| 1462 | |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 1463 | SanitizerArgs::SanitizerArgs(const Driver &D, const ArgList &Args) { |
| 1464 | Kind = 0; |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1465 | |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1466 | for (ArgList::const_iterator I = Args.begin(), E = Args.end(); I != E; ++I) { |
Alexey Samsonov | 3325b16 | 2012-11-28 17:34:24 +0000 | [diff] [blame] | 1467 | unsigned Add, Remove; |
| 1468 | if (!parse(D, Args, *I, Add, Remove, true)) |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1469 | continue; |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1470 | (*I)->claim(); |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 1471 | Kind |= Add; |
| 1472 | Kind &= ~Remove; |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | // Only one runtime library can be used at once. |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 1476 | bool NeedsAsan = needsAsanRt(); |
| 1477 | bool NeedsTsan = needsTsanRt(); |
Richard Smith | 0565037 | 2012-12-01 01:02:45 +0000 | [diff] [blame] | 1478 | if (NeedsAsan && NeedsTsan) |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1479 | D.Diag(diag::err_drv_argument_not_allowed_with) |
Richard Smith | 0565037 | 2012-12-01 01:02:45 +0000 | [diff] [blame] | 1480 | << lastArgumentForKind(D, Args, NeedsAsanRt) |
| 1481 | << lastArgumentForKind(D, Args, NeedsTsanRt); |
Alexey Samsonov | 4d1a6e4 | 2012-11-29 22:36:21 +0000 | [diff] [blame] | 1482 | |
| 1483 | // If -fsanitize contains extra features of ASan, it should also |
| 1484 | // explicitly contain -fsanitize=address. |
| 1485 | if (NeedsAsan && ((Kind & Address) == 0)) |
| 1486 | D.Diag(diag::err_drv_argument_only_allowed_with) |
| 1487 | << lastArgumentForKind(D, Args, NeedsAsanRt) |
| 1488 | << "-fsanitize=address"; |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Kostya Serebryany | dff466c | 2011-11-30 01:39:16 +0000 | [diff] [blame] | 1491 | /// If AddressSanitizer is enabled, add appropriate linker flags (Linux). |
| 1492 | /// This needs to be called before we add the C run-time (malloc, etc). |
| 1493 | static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args, |
Kostya Serebryany | 7b5f101 | 2011-12-06 19:18:44 +0000 | [diff] [blame] | 1494 | ArgStringList &CmdArgs) { |
Logan Chien | 94a7142 | 2012-09-02 09:30:11 +0000 | [diff] [blame] | 1495 | if(TC.getTriple().getEnvironment() == llvm::Triple::Android) { |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 1496 | if (!Args.hasArg(options::OPT_shared)) { |
Evgeniy Stepanov | 8373862 | 2012-06-04 11:15:05 +0000 | [diff] [blame] | 1497 | if (!Args.hasArg(options::OPT_pie)) |
| 1498 | TC.getDriver().Diag(diag::err_drv_asan_android_requires_pie); |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 1499 | } |
Daniel Dunbar | 8cd0d25 | 2011-12-07 23:22:17 +0000 | [diff] [blame] | 1500 | |
Evgeniy Stepanov | 8ba7541 | 2012-09-12 09:09:08 +0000 | [diff] [blame] | 1501 | SmallString<128> LibAsan(TC.getDriver().ResourceDir); |
| 1502 | llvm::sys::path::append(LibAsan, "lib", "linux", |
| 1503 | (Twine("libclang_rt.asan-") + |
| 1504 | TC.getArchName() + "-android.so")); |
| 1505 | CmdArgs.push_back(Args.MakeArgString(LibAsan)); |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 1506 | } else { |
| 1507 | if (!Args.hasArg(options::OPT_shared)) { |
| 1508 | // LibAsan is "libclang_rt.asan-<ArchName>.a" in the Linux library |
| 1509 | // resource directory. |
| 1510 | SmallString<128> LibAsan(TC.getDriver().ResourceDir); |
| 1511 | llvm::sys::path::append(LibAsan, "lib", "linux", |
| 1512 | (Twine("libclang_rt.asan-") + |
| 1513 | TC.getArchName() + ".a")); |
| 1514 | CmdArgs.push_back(Args.MakeArgString(LibAsan)); |
| 1515 | CmdArgs.push_back("-lpthread"); |
| 1516 | CmdArgs.push_back("-ldl"); |
| 1517 | CmdArgs.push_back("-export-dynamic"); |
| 1518 | } |
| 1519 | } |
Kostya Serebryany | dff466c | 2011-11-30 01:39:16 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Kostya Serebryany | f7efb0e | 2012-05-16 06:36:00 +0000 | [diff] [blame] | 1522 | /// If ThreadSanitizer is enabled, add appropriate linker flags (Linux). |
| 1523 | /// This needs to be called before we add the C run-time (malloc, etc). |
| 1524 | static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args, |
| 1525 | ArgStringList &CmdArgs) { |
Kostya Serebryany | f7efb0e | 2012-05-16 06:36:00 +0000 | [diff] [blame] | 1526 | if (!Args.hasArg(options::OPT_shared)) { |
| 1527 | // LibTsan is "libclang_rt.tsan-<ArchName>.a" in the Linux library |
| 1528 | // resource directory. |
| 1529 | SmallString<128> LibTsan(TC.getDriver().ResourceDir); |
| 1530 | llvm::sys::path::append(LibTsan, "lib", "linux", |
| 1531 | (Twine("libclang_rt.tsan-") + |
| 1532 | TC.getArchName() + ".a")); |
| 1533 | CmdArgs.push_back(Args.MakeArgString(LibTsan)); |
| 1534 | CmdArgs.push_back("-lpthread"); |
| 1535 | CmdArgs.push_back("-ldl"); |
| 1536 | CmdArgs.push_back("-export-dynamic"); |
| 1537 | } |
| 1538 | } |
| 1539 | |
Richard Smith | 4def70d | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 1540 | /// If UndefinedBehaviorSanitizer is enabled, add appropriate linker flags |
| 1541 | /// (Linux). |
| 1542 | static void addUbsanRTLinux(const ToolChain &TC, const ArgList &Args, |
| 1543 | ArgStringList &CmdArgs) { |
Richard Smith | 4def70d | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 1544 | if (!Args.hasArg(options::OPT_shared)) { |
| 1545 | // LibUbsan is "libclang_rt.ubsan-<ArchName>.a" in the Linux library |
| 1546 | // resource directory. |
| 1547 | SmallString<128> LibUbsan(TC.getDriver().ResourceDir); |
| 1548 | llvm::sys::path::append(LibUbsan, "lib", "linux", |
| 1549 | (Twine("libclang_rt.ubsan-") + |
| 1550 | TC.getArchName() + ".a")); |
| 1551 | CmdArgs.push_back(Args.MakeArgString(LibUbsan)); |
Richard Smith | eb52aed | 2012-11-02 20:32:19 +0000 | [diff] [blame] | 1552 | CmdArgs.push_back("-lpthread"); |
Richard Smith | 0565037 | 2012-12-01 01:02:45 +0000 | [diff] [blame] | 1553 | CmdArgs.push_back("-export-dynamic"); |
Richard Smith | 4def70d | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | |
Rafael Espindola | 6af27ec | 2011-12-14 21:02:23 +0000 | [diff] [blame] | 1557 | static bool shouldUseFramePointer(const ArgList &Args, |
| 1558 | const llvm::Triple &Triple) { |
| 1559 | if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer, |
| 1560 | options::OPT_fomit_frame_pointer)) |
| 1561 | return A->getOption().matches(options::OPT_fno_omit_frame_pointer); |
| 1562 | |
Rafael Espindola | a2a1789 | 2011-12-14 21:50:24 +0000 | [diff] [blame] | 1563 | // Don't use a frame pointer on linux x86 and x86_64 if optimizing. |
Rafael Espindola | 6af27ec | 2011-12-14 21:02:23 +0000 | [diff] [blame] | 1564 | if ((Triple.getArch() == llvm::Triple::x86_64 || |
| 1565 | Triple.getArch() == llvm::Triple::x86) && |
| 1566 | Triple.getOS() == llvm::Triple::Linux) { |
| 1567 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) |
| 1568 | if (!A->getOption().matches(options::OPT_O0)) |
| 1569 | return false; |
| 1570 | } |
| 1571 | |
| 1572 | return true; |
| 1573 | } |
| 1574 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1575 | void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 1576 | const InputInfo &Output, |
Daniel Dunbar | 62cf601 | 2009-03-18 06:07:59 +0000 | [diff] [blame] | 1577 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1578 | const ArgList &Args, |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1579 | const char *LinkingOutput) const { |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 1580 | bool KernelOrKext = Args.hasArg(options::OPT_mkernel, |
| 1581 | options::OPT_fapple_kext); |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1582 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1583 | ArgStringList CmdArgs; |
| 1584 | |
Daniel Dunbar | 077ba6a | 2009-03-31 20:53:55 +0000 | [diff] [blame] | 1585 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 1586 | |
Daniel Dunbar | 8ff5b28 | 2009-12-11 23:00:49 +0000 | [diff] [blame] | 1587 | // Invoke ourselves in -cc1 mode. |
| 1588 | // |
| 1589 | // FIXME: Implement custom jobs for internal actions. |
| 1590 | CmdArgs.push_back("-cc1"); |
| 1591 | |
Daniel Dunbar | dd4fe00 | 2009-10-30 18:12:20 +0000 | [diff] [blame] | 1592 | // Add the "effective" target triple. |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 1593 | CmdArgs.push_back("-triple"); |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 1594 | std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); |
Daniel Dunbar | dd4fe00 | 2009-10-30 18:12:20 +0000 | [diff] [blame] | 1595 | CmdArgs.push_back(Args.MakeArgString(TripleStr)); |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 1596 | |
Daniel Dunbar | dd4fe00 | 2009-10-30 18:12:20 +0000 | [diff] [blame] | 1597 | // Select the appropriate action. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1598 | RewriteKind rewriteKind = RK_None; |
Fariborz Jahanian | e982cc0 | 2012-04-04 18:50:28 +0000 | [diff] [blame] | 1599 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1600 | if (isa<AnalyzeJobAction>(JA)) { |
| 1601 | assert(JA.getType() == types::TY_Plist && "Invalid output type."); |
| 1602 | CmdArgs.push_back("-analyze"); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1603 | } else if (isa<MigrateJobAction>(JA)) { |
| 1604 | CmdArgs.push_back("-migrate"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1605 | } else if (isa<PreprocessJobAction>(JA)) { |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 1606 | if (Output.getType() == types::TY_Dependencies) |
| 1607 | CmdArgs.push_back("-Eonly"); |
| 1608 | else |
| 1609 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 8767cbc | 2010-02-03 03:07:56 +0000 | [diff] [blame] | 1610 | } else if (isa<AssembleJobAction>(JA)) { |
| 1611 | CmdArgs.push_back("-emit-obj"); |
Daniel Dunbar | 9929800 | 2010-05-27 06:18:05 +0000 | [diff] [blame] | 1612 | |
Joerg Sonnenberger | 359cf92 | 2011-05-06 14:35:16 +0000 | [diff] [blame] | 1613 | if (UseRelaxAll(C, Args)) |
Daniel Dunbar | 9929800 | 2010-05-27 06:18:05 +0000 | [diff] [blame] | 1614 | CmdArgs.push_back("-mrelax-all"); |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 1615 | |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 1616 | // When using an integrated assembler, translate -Wa, and -Xassembler |
| 1617 | // options. |
| 1618 | for (arg_iterator it = Args.filtered_begin(options::OPT_Wa_COMMA, |
| 1619 | options::OPT_Xassembler), |
| 1620 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1621 | const Arg *A = *it; |
| 1622 | A->claim(); |
| 1623 | |
| 1624 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1625 | StringRef Value = A->getValue(i); |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 1626 | |
| 1627 | if (Value == "-force_cpusubtype_ALL") { |
| 1628 | // Do nothing, this is the default and we don't support anything else. |
Daniel Dunbar | b14eed0 | 2010-10-28 20:36:23 +0000 | [diff] [blame] | 1629 | } else if (Value == "-L") { |
Daniel Dunbar | 9693232 | 2011-03-28 22:49:28 +0000 | [diff] [blame] | 1630 | CmdArgs.push_back("-msave-temp-labels"); |
Joerg Sonnenberger | 46a4939 | 2011-05-19 20:46:39 +0000 | [diff] [blame] | 1631 | } else if (Value == "--fatal-warnings") { |
Joerg Sonnenberger | d793350 | 2011-05-19 18:42:29 +0000 | [diff] [blame] | 1632 | CmdArgs.push_back("-mllvm"); |
| 1633 | CmdArgs.push_back("-fatal-assembler-warnings"); |
Nick Lewycky | c3b9014 | 2011-06-21 00:14:18 +0000 | [diff] [blame] | 1634 | } else if (Value == "--noexecstack") { |
| 1635 | CmdArgs.push_back("-mnoexecstack"); |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 1636 | } else { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1637 | D.Diag(diag::err_drv_unsupported_option_argument) |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 1638 | << A->getOption().getName() << Value; |
| 1639 | } |
| 1640 | } |
| 1641 | } |
Daniel Dunbar | d02bba8 | 2010-11-19 16:23:35 +0000 | [diff] [blame] | 1642 | |
| 1643 | // Also ignore explicit -force_cpusubtype_ALL option. |
| 1644 | (void) Args.hasArg(options::OPT_force__cpusubtype__ALL); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1645 | } else if (isa<PrecompileJobAction>(JA)) { |
Argyrios Kyrtzidis | e5c3537 | 2010-08-11 23:27:58 +0000 | [diff] [blame] | 1646 | // Use PCH if the user requested it. |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 1647 | bool UsePCH = D.CCCUsePCH; |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 1648 | |
Aaron Ballman | 761322b | 2012-07-31 01:21:00 +0000 | [diff] [blame] | 1649 | if (JA.getType() == types::TY_Nothing) |
| 1650 | CmdArgs.push_back("-fsyntax-only"); |
| 1651 | else if (UsePCH) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 1652 | CmdArgs.push_back("-emit-pch"); |
| 1653 | else |
| 1654 | CmdArgs.push_back("-emit-pth"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1655 | } else { |
| 1656 | assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool."); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1657 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1658 | if (JA.getType() == types::TY_Nothing) { |
| 1659 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 1660 | } else if (JA.getType() == types::TY_LLVM_IR || |
| 1661 | JA.getType() == types::TY_LTO_IR) { |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1662 | CmdArgs.push_back("-emit-llvm"); |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 1663 | } else if (JA.getType() == types::TY_LLVM_BC || |
| 1664 | JA.getType() == types::TY_LTO_BC) { |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1665 | CmdArgs.push_back("-emit-llvm-bc"); |
| 1666 | } else if (JA.getType() == types::TY_PP_Asm) { |
Daniel Dunbar | e3b8d07 | 2009-09-17 00:47:53 +0000 | [diff] [blame] | 1667 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 1668 | } else if (JA.getType() == types::TY_AST) { |
| 1669 | CmdArgs.push_back("-emit-pch"); |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 1670 | } else if (JA.getType() == types::TY_RewrittenObjC) { |
| 1671 | CmdArgs.push_back("-rewrite-objc"); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1672 | rewriteKind = RK_NonFragile; |
Fariborz Jahanian | 582b395 | 2012-04-02 15:59:19 +0000 | [diff] [blame] | 1673 | } else if (JA.getType() == types::TY_RewrittenLegacyObjC) { |
| 1674 | CmdArgs.push_back("-rewrite-objc"); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1675 | rewriteKind = RK_Fragile; |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 1676 | } else { |
| 1677 | assert(JA.getType() == types::TY_PP_Asm && |
| 1678 | "Unexpected output type!"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1679 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1682 | // The make clang go fast button. |
| 1683 | CmdArgs.push_back("-disable-free"); |
| 1684 | |
John McCall | b689afb | 2010-02-13 03:50:24 +0000 | [diff] [blame] | 1685 | // Disable the verification pass in -asserts builds. |
| 1686 | #ifdef NDEBUG |
| 1687 | CmdArgs.push_back("-disable-llvm-verifier"); |
| 1688 | #endif |
| 1689 | |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 1690 | // Set the main file name, so that debug info works even with |
| 1691 | // -save-temps. |
| 1692 | CmdArgs.push_back("-main-file-name"); |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 1693 | CmdArgs.push_back(getBaseInputName(Args, Inputs)); |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 1694 | |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 1695 | // Some flags which affect the language (via preprocessor |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 1696 | // defines). |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 1697 | if (Args.hasArg(options::OPT_static)) |
| 1698 | CmdArgs.push_back("-static-define"); |
| 1699 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1700 | if (isa<AnalyzeJobAction>(JA)) { |
Ted Kremenek | b8bb3e7 | 2009-09-25 05:55:59 +0000 | [diff] [blame] | 1701 | // Enable region store model by default. |
| 1702 | CmdArgs.push_back("-analyzer-store=region"); |
| 1703 | |
Ted Kremenek | b40d06d | 2009-12-07 22:26:14 +0000 | [diff] [blame] | 1704 | // Treat blocks as analysis entry points. |
| 1705 | CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks"); |
| 1706 | |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1707 | CmdArgs.push_back("-analyzer-eagerly-assume"); |
| 1708 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1709 | // Add default argument set. |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1710 | if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) { |
Argyrios Kyrtzidis | 027a6ab | 2011-02-15 07:42:33 +0000 | [diff] [blame] | 1711 | CmdArgs.push_back("-analyzer-checker=core"); |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1712 | |
Argyrios Kyrtzidis | 027a6ab | 2011-02-15 07:42:33 +0000 | [diff] [blame] | 1713 | if (getToolChain().getTriple().getOS() != llvm::Triple::Win32) |
| 1714 | CmdArgs.push_back("-analyzer-checker=unix"); |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1715 | |
Argyrios Kyrtzidis | 027a6ab | 2011-02-15 07:42:33 +0000 | [diff] [blame] | 1716 | if (getToolChain().getTriple().getVendor() == llvm::Triple::Apple) |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1717 | CmdArgs.push_back("-analyzer-checker=osx"); |
Ted Kremenek | a8180e5 | 2012-01-20 06:00:17 +0000 | [diff] [blame] | 1718 | |
| 1719 | CmdArgs.push_back("-analyzer-checker=deadcode"); |
Ted Kremenek | 8dc0506 | 2012-01-26 02:27:38 +0000 | [diff] [blame] | 1720 | |
| 1721 | // Enable the following experimental checkers for testing. |
Ted Kremenek | 8dc0506 | 2012-01-26 02:27:38 +0000 | [diff] [blame] | 1722 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.UncheckedReturn"); |
| 1723 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.getpw"); |
| 1724 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.gets"); |
| 1725 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mktemp"); |
| 1726 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mkstemp"); |
| 1727 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.vfork"); |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1728 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1729 | |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1730 | // Set the output format. The default is plist, for (lame) historical |
| 1731 | // reasons. |
| 1732 | CmdArgs.push_back("-analyzer-output"); |
| 1733 | if (Arg *A = Args.getLastArg(options::OPT__analyzer_output)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1734 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1735 | else |
| 1736 | CmdArgs.push_back("plist"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1737 | |
Ted Kremenek | 0647a7b | 2010-03-22 22:32:05 +0000 | [diff] [blame] | 1738 | // Disable the presentation of standard compiler warnings when |
| 1739 | // using --analyze. We only want to show static analyzer diagnostics |
| 1740 | // or frontend errors. |
| 1741 | CmdArgs.push_back("-w"); |
| 1742 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1743 | // Add -Xanalyzer arguments when running as analyzer. |
| 1744 | Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Daniel Dunbar | e2fd664 | 2009-09-10 01:21:12 +0000 | [diff] [blame] | 1747 | CheckCodeGenerationOptions(D, Args); |
| 1748 | |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1749 | // For the PIC and PIE flag options, this logic is different from the legacy |
| 1750 | // logic in very old versions of GCC, as that logic was just a bug no one had |
| 1751 | // ever fixed. This logic is both more rational and consistent with GCC's new |
| 1752 | // logic now that the bugs are fixed. The last argument relating to either |
| 1753 | // PIC or PIE wins, and no other argument is used. If the last argument is |
| 1754 | // any flavor of the '-fno-...' arguments, both PIC and PIE are disabled. Any |
| 1755 | // PIE option implicitly enables PIC at the same level. |
| 1756 | bool PIE = false; |
| 1757 | bool PIC = getToolChain().isPICDefault(); |
| 1758 | bool IsPICLevelTwo = PIC; |
| 1759 | if (Arg *A = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, |
| 1760 | options::OPT_fpic, options::OPT_fno_pic, |
| 1761 | options::OPT_fPIE, options::OPT_fno_PIE, |
| 1762 | options::OPT_fpie, options::OPT_fno_pie)) { |
| 1763 | Option O = A->getOption(); |
| 1764 | if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) || |
| 1765 | O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) { |
| 1766 | PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie); |
| 1767 | PIC = PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic); |
| 1768 | IsPICLevelTwo = O.matches(options::OPT_fPIE) || |
| 1769 | O.matches(options::OPT_fPIC); |
| 1770 | } else { |
| 1771 | PIE = PIC = false; |
| 1772 | } |
Benjamin Kramer | b12ecd3 | 2012-11-13 15:32:35 +0000 | [diff] [blame] | 1773 | } |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1774 | // Check whether the tool chain trumps the PIC-ness decision. If the PIC-ness |
| 1775 | // is forced, then neither PIC nor PIE flags will have no effect. |
| 1776 | if (getToolChain().isPICDefaultForced()) { |
| 1777 | PIE = false; |
| 1778 | PIC = getToolChain().isPICDefault(); |
| 1779 | IsPICLevelTwo = PIC; |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1780 | } |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1781 | |
| 1782 | // Inroduce a Darwin-specific hack. If the default is PIC but the flags |
| 1783 | // specified while enabling PIC enabled level 1 PIC, just force it back to |
| 1784 | // level 2 PIC instead. This matches the behavior of Darwin GCC (based on my |
| 1785 | // informal testing). |
| 1786 | if (PIC && getToolChain().getTriple().isOSDarwin()) |
| 1787 | IsPICLevelTwo |= getToolChain().isPICDefault(); |
| 1788 | |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1789 | // Note that these flags are trump-cards. Regardless of the order w.r.t. the |
| 1790 | // PIC or PIE options above, if these show up, PIC is disabled. |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1791 | llvm::Triple Triple(TripleStr); |
| 1792 | if ((Args.hasArg(options::OPT_mkernel) || |
| 1793 | Args.hasArg(options::OPT_fapple_kext)) && |
| 1794 | (Triple.getOS() != llvm::Triple::IOS || |
| 1795 | Triple.isOSVersionLT(6))) |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1796 | PIC = PIE = false; |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1797 | if (Args.hasArg(options::OPT_static)) |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1798 | PIC = PIE = false; |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1799 | |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1800 | if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) { |
| 1801 | // This is a very special mode. It trumps the other modes, almost no one |
| 1802 | // uses it, and it isn't even valid on any OS but Darwin. |
| 1803 | if (!getToolChain().getTriple().isOSDarwin()) |
| 1804 | D.Diag(diag::err_drv_unsupported_opt_for_target) |
| 1805 | << A->getSpelling() << getToolChain().getTriple().str(); |
| 1806 | |
| 1807 | // FIXME: Warn when this flag trumps some other PIC or PIE flag. |
| 1808 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1809 | CmdArgs.push_back("-mrelocation-model"); |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1810 | CmdArgs.push_back("dynamic-no-pic"); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1811 | |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1812 | // Only a forced PIC mode can cause the actual compile to have PIC defines |
| 1813 | // etc., no flags are sufficient. This behavior was selected to closely |
| 1814 | // match that of llvm-gcc and Apple GCC before that. |
| 1815 | if (getToolChain().isPICDefault() && getToolChain().isPICDefaultForced()) { |
| 1816 | CmdArgs.push_back("-pic-level"); |
| 1817 | CmdArgs.push_back("2"); |
| 1818 | } |
| 1819 | } else { |
| 1820 | // Currently, LLVM only knows about PIC vs. static; the PIE differences are |
| 1821 | // handled in Clang's IRGen by the -pie-level flag. |
| 1822 | CmdArgs.push_back("-mrelocation-model"); |
| 1823 | CmdArgs.push_back(PIC ? "pic" : "static"); |
| 1824 | |
| 1825 | if (PIC) { |
| 1826 | CmdArgs.push_back("-pic-level"); |
| 1827 | CmdArgs.push_back(IsPICLevelTwo ? "2" : "1"); |
| 1828 | if (PIE) { |
| 1829 | CmdArgs.push_back("-pie-level"); |
| 1830 | CmdArgs.push_back(IsPICLevelTwo ? "2" : "1"); |
| 1831 | } |
| 1832 | } |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1833 | } |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1834 | |
Tanya Lattner | 59876c2 | 2009-11-04 01:18:09 +0000 | [diff] [blame] | 1835 | if (!Args.hasFlag(options::OPT_fmerge_all_constants, |
| 1836 | options::OPT_fno_merge_all_constants)) |
Chris Lattner | f44a1a0 | 2011-04-08 18:06:54 +0000 | [diff] [blame] | 1837 | CmdArgs.push_back("-fno-merge-all-constants"); |
Daniel Dunbar | 6bea73b | 2009-09-16 06:17:29 +0000 | [diff] [blame] | 1838 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1839 | // LLVM Code Generator Options. |
| 1840 | |
Daniel Dunbar | 17d3fea | 2011-02-09 17:54:19 +0000 | [diff] [blame] | 1841 | if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) { |
| 1842 | CmdArgs.push_back("-mregparm"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1843 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | 17d3fea | 2011-02-09 17:54:19 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 1846 | if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd, false)) |
| 1847 | CmdArgs.push_back("-mrtd"); |
| 1848 | |
Rafael Espindola | 6af27ec | 2011-12-14 21:02:23 +0000 | [diff] [blame] | 1849 | if (shouldUseFramePointer(Args, getToolChain().getTriple())) |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1850 | CmdArgs.push_back("-mdisable-fp-elim"); |
| 1851 | if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, |
| 1852 | options::OPT_fno_zero_initialized_in_bss)) |
| 1853 | CmdArgs.push_back("-mno-zero-initialized-in-bss"); |
Daniel Dunbar | 398c610 | 2011-02-04 02:20:39 +0000 | [diff] [blame] | 1854 | if (!Args.hasFlag(options::OPT_fstrict_aliasing, |
| 1855 | options::OPT_fno_strict_aliasing, |
| 1856 | getToolChain().IsStrictAliasingDefault())) |
Dan Gohman | 4d5625e | 2010-10-14 22:36:56 +0000 | [diff] [blame] | 1857 | CmdArgs.push_back("-relaxed-aliasing"); |
Chandler Carruth | 82fe6ae | 2012-03-27 23:58:37 +0000 | [diff] [blame] | 1858 | if (Args.hasFlag(options::OPT_fstrict_enums, options::OPT_fno_strict_enums, |
| 1859 | false)) |
| 1860 | CmdArgs.push_back("-fstrict-enums"); |
Nick Lewycky | 1db772b | 2012-01-23 08:29:12 +0000 | [diff] [blame] | 1861 | if (!Args.hasFlag(options::OPT_foptimize_sibling_calls, |
| 1862 | options::OPT_fno_optimize_sibling_calls)) |
| 1863 | CmdArgs.push_back("-mdisable-tail-calls"); |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 1864 | |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1865 | // Handle various floating point optimization flags, mapping them to the |
| 1866 | // appropriate LLVM code generation flags. The pattern for all of these is to |
| 1867 | // default off the codegen optimizations, and if any flag enables them and no |
| 1868 | // flag disables them after the flag enabling them, enable the codegen |
| 1869 | // optimization. This is complicated by several "umbrella" flags. |
| 1870 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1871 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1872 | options::OPT_ffinite_math_only, |
| 1873 | options::OPT_fno_finite_math_only, |
| 1874 | options::OPT_fhonor_infinities, |
| 1875 | options::OPT_fno_honor_infinities)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1876 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 1877 | A->getOption().getID() != options::OPT_fno_finite_math_only && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1878 | A->getOption().getID() != options::OPT_fhonor_infinities) |
| 1879 | CmdArgs.push_back("-menable-no-infs"); |
| 1880 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1881 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1882 | options::OPT_ffinite_math_only, |
| 1883 | options::OPT_fno_finite_math_only, |
| 1884 | options::OPT_fhonor_nans, |
| 1885 | options::OPT_fno_honor_nans)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1886 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 1887 | A->getOption().getID() != options::OPT_fno_finite_math_only && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1888 | A->getOption().getID() != options::OPT_fhonor_nans) |
| 1889 | CmdArgs.push_back("-menable-no-nans"); |
| 1890 | |
Benjamin Kramer | 769aa2d | 2012-05-02 14:55:48 +0000 | [diff] [blame] | 1891 | // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes. |
| 1892 | bool MathErrno = getToolChain().IsMathErrnoDefault(); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1893 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1894 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1895 | options::OPT_fmath_errno, |
Chandler Carruth | 4f50c50 | 2012-04-26 02:10:51 +0000 | [diff] [blame] | 1896 | options::OPT_fno_math_errno)) |
| 1897 | MathErrno = A->getOption().getID() == options::OPT_fmath_errno; |
| 1898 | if (MathErrno) |
| 1899 | CmdArgs.push_back("-fmath-errno"); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1900 | |
| 1901 | // There are several flags which require disabling very specific |
| 1902 | // optimizations. Any of these being disabled forces us to turn off the |
| 1903 | // entire set of LLVM optimizations, so collect them through all the flag |
| 1904 | // madness. |
| 1905 | bool AssociativeMath = false; |
| 1906 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1907 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1908 | options::OPT_funsafe_math_optimizations, |
| 1909 | options::OPT_fno_unsafe_math_optimizations, |
| 1910 | options::OPT_fassociative_math, |
| 1911 | options::OPT_fno_associative_math)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1912 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 1913 | A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1914 | A->getOption().getID() != options::OPT_fno_associative_math) |
| 1915 | AssociativeMath = true; |
| 1916 | bool ReciprocalMath = false; |
| 1917 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1918 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1919 | options::OPT_funsafe_math_optimizations, |
| 1920 | options::OPT_fno_unsafe_math_optimizations, |
| 1921 | options::OPT_freciprocal_math, |
| 1922 | options::OPT_fno_reciprocal_math)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1923 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 1924 | A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1925 | A->getOption().getID() != options::OPT_fno_reciprocal_math) |
| 1926 | ReciprocalMath = true; |
| 1927 | bool SignedZeros = true; |
| 1928 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1929 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1930 | options::OPT_funsafe_math_optimizations, |
| 1931 | options::OPT_fno_unsafe_math_optimizations, |
| 1932 | options::OPT_fsigned_zeros, |
| 1933 | options::OPT_fno_signed_zeros)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1934 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 1935 | A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1936 | A->getOption().getID() != options::OPT_fsigned_zeros) |
| 1937 | SignedZeros = false; |
| 1938 | bool TrappingMath = true; |
| 1939 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1940 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1941 | options::OPT_funsafe_math_optimizations, |
| 1942 | options::OPT_fno_unsafe_math_optimizations, |
| 1943 | options::OPT_ftrapping_math, |
| 1944 | options::OPT_fno_trapping_math)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1945 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 1946 | A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1947 | A->getOption().getID() != options::OPT_ftrapping_math) |
| 1948 | TrappingMath = false; |
| 1949 | if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && |
| 1950 | !TrappingMath) |
| 1951 | CmdArgs.push_back("-menable-unsafe-fp-math"); |
| 1952 | |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 1953 | |
| 1954 | // Validate and pass through -fp-contract option. |
| 1955 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1956 | options::OPT_fno_fast_math, |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 1957 | options::OPT_ffp_contract)) { |
| 1958 | if (A->getOption().getID() == options::OPT_ffp_contract) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1959 | StringRef Val = A->getValue(); |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 1960 | if (Val == "fast" || Val == "on" || Val == "off") { |
| 1961 | CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + Val)); |
| 1962 | } else { |
| 1963 | D.Diag(diag::err_drv_unsupported_option_argument) |
| 1964 | << A->getOption().getName() << Val; |
| 1965 | } |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1966 | } else if (A->getOption().getID() == options::OPT_ffast_math) { |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 1967 | // If fast-math is set then set the fp-contract mode to fast. |
| 1968 | CmdArgs.push_back(Args.MakeArgString("-ffp-contract=fast")); |
| 1969 | } |
| 1970 | } |
| 1971 | |
Bob Wilson | 455e72e | 2012-07-19 03:52:53 +0000 | [diff] [blame] | 1972 | // We separately look for the '-ffast-math' and '-ffinite-math-only' flags, |
| 1973 | // and if we find them, tell the frontend to provide the appropriate |
| 1974 | // preprocessor macros. This is distinct from enabling any optimizations as |
| 1975 | // these options induce language changes which must survive serialization |
| 1976 | // and deserialization, etc. |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1977 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math)) |
| 1978 | if (A->getOption().matches(options::OPT_ffast_math)) |
| 1979 | CmdArgs.push_back("-ffast-math"); |
| 1980 | if (Arg *A = Args.getLastArg(options::OPT_ffinite_math_only, options::OPT_fno_fast_math)) |
| 1981 | if (A->getOption().matches(options::OPT_ffinite_math_only)) |
| 1982 | CmdArgs.push_back("-ffinite-math-only"); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1983 | |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 1984 | // Decide whether to use verbose asm. Verbose assembly is the default on |
| 1985 | // toolchains which have the integrated assembler on by default. |
| 1986 | bool IsVerboseAsmDefault = getToolChain().IsIntegratedAssemblerDefault(); |
| 1987 | if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm, |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1988 | IsVerboseAsmDefault) || |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 1989 | Args.hasArg(options::OPT_dA)) |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1990 | CmdArgs.push_back("-masm-verbose"); |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 1991 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1992 | if (Args.hasArg(options::OPT_fdebug_pass_structure)) { |
| 1993 | CmdArgs.push_back("-mdebug-pass"); |
| 1994 | CmdArgs.push_back("Structure"); |
| 1995 | } |
| 1996 | if (Args.hasArg(options::OPT_fdebug_pass_arguments)) { |
| 1997 | CmdArgs.push_back("-mdebug-pass"); |
| 1998 | CmdArgs.push_back("Arguments"); |
| 1999 | } |
| 2000 | |
John McCall | d0c2ec4 | 2010-02-19 02:45:38 +0000 | [diff] [blame] | 2001 | // Enable -mconstructor-aliases except on darwin, where we have to |
| 2002 | // work around a linker bug; see <rdar://problem/7651567>. |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 2003 | if (!getToolChain().getTriple().isOSDarwin()) |
John McCall | d0c2ec4 | 2010-02-19 02:45:38 +0000 | [diff] [blame] | 2004 | CmdArgs.push_back("-mconstructor-aliases"); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 2005 | |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 2006 | // Darwin's kernel doesn't support guard variables; just die if we |
| 2007 | // try to use them. |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 2008 | if (KernelOrKext && getToolChain().getTriple().isOSDarwin()) |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 2009 | CmdArgs.push_back("-fforbid-guard-variables"); |
| 2010 | |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2011 | if (Args.hasArg(options::OPT_mms_bitfields)) { |
| 2012 | CmdArgs.push_back("-mms-bitfields"); |
| 2013 | } |
John McCall | d0c2ec4 | 2010-02-19 02:45:38 +0000 | [diff] [blame] | 2014 | |
Daniel Dunbar | 6bea73b | 2009-09-16 06:17:29 +0000 | [diff] [blame] | 2015 | // This is a coarse approximation of what llvm-gcc actually does, both |
| 2016 | // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more |
| 2017 | // complicated ways. |
| 2018 | bool AsynchronousUnwindTables = |
| 2019 | Args.hasFlag(options::OPT_fasynchronous_unwind_tables, |
| 2020 | options::OPT_fno_asynchronous_unwind_tables, |
| 2021 | getToolChain().IsUnwindTablesDefault() && |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 2022 | !KernelOrKext); |
Daniel Dunbar | 6bea73b | 2009-09-16 06:17:29 +0000 | [diff] [blame] | 2023 | if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables, |
| 2024 | AsynchronousUnwindTables)) |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2025 | CmdArgs.push_back("-munwind-tables"); |
| 2026 | |
Chandler Carruth | a6b2581 | 2012-11-21 23:40:23 +0000 | [diff] [blame] | 2027 | getToolChain().addClangTargetOptions(Args, CmdArgs); |
Rafael Espindola | 8af669f | 2012-06-19 01:26:10 +0000 | [diff] [blame] | 2028 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2029 | if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { |
| 2030 | CmdArgs.push_back("-mlimit-float-precision"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2031 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2032 | } |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 2033 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 2034 | // FIXME: Handle -mtune=. |
| 2035 | (void) Args.hasArg(options::OPT_mtune_EQ); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 2036 | |
Benjamin Kramer | 8e9ef0d | 2009-08-05 14:30:52 +0000 | [diff] [blame] | 2037 | if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2038 | CmdArgs.push_back("-mcode-model"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2039 | CmdArgs.push_back(A->getValue()); |
Benjamin Kramer | 8e9ef0d | 2009-08-05 14:30:52 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 2042 | // Add target specific cpu and features flags. |
| 2043 | switch(getToolChain().getTriple().getArch()) { |
| 2044 | default: |
| 2045 | break; |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 2046 | |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 2047 | case llvm::Triple::arm: |
| 2048 | case llvm::Triple::thumb: |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 2049 | AddARMTargetArgs(Args, CmdArgs, KernelOrKext); |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 2050 | break; |
| 2051 | |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2052 | case llvm::Triple::mips: |
| 2053 | case llvm::Triple::mipsel: |
Akira Hatanaka | 7ec0258 | 2011-09-21 02:13:07 +0000 | [diff] [blame] | 2054 | case llvm::Triple::mips64: |
| 2055 | case llvm::Triple::mips64el: |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2056 | AddMIPSTargetArgs(Args, CmdArgs); |
| 2057 | break; |
| 2058 | |
Hal Finkel | 02a8427 | 2012-06-11 22:35:19 +0000 | [diff] [blame] | 2059 | case llvm::Triple::ppc: |
| 2060 | case llvm::Triple::ppc64: |
| 2061 | AddPPCTargetArgs(Args, CmdArgs); |
| 2062 | break; |
| 2063 | |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 2064 | case llvm::Triple::sparc: |
| 2065 | AddSparcTargetArgs(Args, CmdArgs); |
| 2066 | break; |
| 2067 | |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 2068 | case llvm::Triple::x86: |
| 2069 | case llvm::Triple::x86_64: |
| 2070 | AddX86TargetArgs(Args, CmdArgs); |
| 2071 | break; |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2072 | |
| 2073 | case llvm::Triple::hexagon: |
| 2074 | AddHexagonTargetArgs(Args, CmdArgs); |
| 2075 | break; |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2078 | |
| 2079 | |
Daniel Dunbar | c176bc6 | 2010-08-11 23:07:47 +0000 | [diff] [blame] | 2080 | // Pass the linker version in use. |
| 2081 | if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { |
| 2082 | CmdArgs.push_back("-target-linker-version"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2083 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | c176bc6 | 2010-08-11 23:07:47 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
Nick Lewycky | b2d11cc | 2011-02-02 06:43:03 +0000 | [diff] [blame] | 2086 | // -mno-omit-leaf-frame-pointer is the default on Darwin. |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 2087 | if (Args.hasFlag(options::OPT_momit_leaf_frame_pointer, |
Nick Lewycky | b2d11cc | 2011-02-02 06:43:03 +0000 | [diff] [blame] | 2088 | options::OPT_mno_omit_leaf_frame_pointer, |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 2089 | !getToolChain().getTriple().isOSDarwin())) |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 2090 | CmdArgs.push_back("-momit-leaf-frame-pointer"); |
| 2091 | |
Daniel Dunbar | b30575c | 2010-05-12 18:19:58 +0000 | [diff] [blame] | 2092 | // Explicitly error on some things we know we don't support and can't just |
| 2093 | // ignore. |
| 2094 | types::ID InputType = Inputs[0].getType(); |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 2095 | if (!Args.hasArg(options::OPT_fallow_unsupported)) { |
| 2096 | Arg *Unsupported; |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 2097 | if (types::isCXX(InputType) && |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 2098 | getToolChain().getTriple().isOSDarwin() && |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 2099 | getToolChain().getTriple().getArch() == llvm::Triple::x86) { |
Bob Wilson | a544aee | 2011-08-13 23:48:55 +0000 | [diff] [blame] | 2100 | if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)) || |
| 2101 | (Unsupported = Args.getLastArg(options::OPT_mkernel))) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2102 | D.Diag(diag::err_drv_clang_unsupported_opt_cxx_darwin_i386) |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 2103 | << Unsupported->getOption().getName(); |
| 2104 | } |
Daniel Dunbar | b30575c | 2010-05-12 18:19:58 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2107 | Args.AddAllArgs(CmdArgs, options::OPT_v); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 2108 | Args.AddLastArg(CmdArgs, options::OPT_H); |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 2109 | if (D.CCPrintHeaders && !D.CCGenDiagnostics) { |
Daniel Dunbar | 322c29f | 2011-02-02 21:11:35 +0000 | [diff] [blame] | 2110 | CmdArgs.push_back("-header-include-file"); |
| 2111 | CmdArgs.push_back(D.CCPrintHeadersFilename ? |
| 2112 | D.CCPrintHeadersFilename : "-"); |
| 2113 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2114 | Args.AddLastArg(CmdArgs, options::OPT_P); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2115 | Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2116 | |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 2117 | if (D.CCLogDiagnostics && !D.CCGenDiagnostics) { |
Daniel Dunbar | c8a22b0 | 2011-04-07 18:01:20 +0000 | [diff] [blame] | 2118 | CmdArgs.push_back("-diagnostic-log-file"); |
| 2119 | CmdArgs.push_back(D.CCLogDiagnosticsFilename ? |
| 2120 | D.CCLogDiagnosticsFilename : "-"); |
| 2121 | } |
| 2122 | |
Alexey Samsonov | a9cd83b | 2012-05-29 08:10:34 +0000 | [diff] [blame] | 2123 | // Use the last option from "-g" group. "-gline-tables-only" is |
| 2124 | // preserved, all other debug options are substituted with "-g". |
Rafael Espindola | 18f36d9 | 2010-03-07 04:46:18 +0000 | [diff] [blame] | 2125 | Args.ClaimAllArgs(options::OPT_g_Group); |
Alexey Samsonov | a9cd83b | 2012-05-29 08:10:34 +0000 | [diff] [blame] | 2126 | if (Arg *A = Args.getLastArg(options::OPT_g_Group)) { |
| 2127 | if (A->getOption().matches(options::OPT_gline_tables_only)) { |
| 2128 | CmdArgs.push_back("-gline-tables-only"); |
Alexey Samsonov | 7f32607 | 2012-06-21 08:22:39 +0000 | [diff] [blame] | 2129 | } else if (!A->getOption().matches(options::OPT_g0) && |
| 2130 | !A->getOption().matches(options::OPT_ggdb0)) { |
Chad Rosier | cf6ba2e | 2011-11-07 19:52:29 +0000 | [diff] [blame] | 2131 | CmdArgs.push_back("-g"); |
Chad Rosier | 2875bda | 2011-11-04 19:28:44 +0000 | [diff] [blame] | 2132 | } |
Alexey Samsonov | a9cd83b | 2012-05-29 08:10:34 +0000 | [diff] [blame] | 2133 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2134 | |
Alexey Samsonov | 7f32607 | 2012-06-21 08:22:39 +0000 | [diff] [blame] | 2135 | // We ignore flags -gstrict-dwarf and -grecord-gcc-switches for now. |
| 2136 | Args.ClaimAllArgs(options::OPT_g_flags_Group); |
Eric Christopher | da3301e | 2012-10-18 21:52:18 +0000 | [diff] [blame] | 2137 | if (Args.hasArg(options::OPT_gcolumn_info)) |
| 2138 | CmdArgs.push_back("-dwarf-column-info"); |
Alexey Samsonov | 7f32607 | 2012-06-21 08:22:39 +0000 | [diff] [blame] | 2139 | |
Rafael Espindola | 9cf933a | 2010-05-06 21:06:04 +0000 | [diff] [blame] | 2140 | Args.AddAllArgs(CmdArgs, options::OPT_ffunction_sections); |
| 2141 | Args.AddAllArgs(CmdArgs, options::OPT_fdata_sections); |
| 2142 | |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 2143 | Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); |
| 2144 | |
Nick Lewycky | e8ba8d7 | 2011-04-21 23:44:07 +0000 | [diff] [blame] | 2145 | if (Args.hasArg(options::OPT_ftest_coverage) || |
| 2146 | Args.hasArg(options::OPT_coverage)) |
| 2147 | CmdArgs.push_back("-femit-coverage-notes"); |
| 2148 | if (Args.hasArg(options::OPT_fprofile_arcs) || |
| 2149 | Args.hasArg(options::OPT_coverage)) |
| 2150 | CmdArgs.push_back("-femit-coverage-data"); |
| 2151 | |
Nick Lewycky | 5ea4f44 | 2011-05-04 20:46:58 +0000 | [diff] [blame] | 2152 | if (C.getArgs().hasArg(options::OPT_c) || |
| 2153 | C.getArgs().hasArg(options::OPT_S)) { |
| 2154 | if (Output.isFilename()) { |
Nick Lewycky | 3dc0541 | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 2155 | CmdArgs.push_back("-coverage-file"); |
Bill Wendling | ecbbea4 | 2012-08-30 00:43:41 +0000 | [diff] [blame] | 2156 | SmallString<128> absFilename(Output.getFilename()); |
| 2157 | llvm::sys::fs::make_absolute(absFilename); |
| 2158 | CmdArgs.push_back(Args.MakeArgString(absFilename)); |
Nick Lewycky | 5ea4f44 | 2011-05-04 20:46:58 +0000 | [diff] [blame] | 2159 | } |
| 2160 | } |
| 2161 | |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 2162 | // Pass options for controlling the default header search paths. |
| 2163 | if (Args.hasArg(options::OPT_nostdinc)) { |
| 2164 | CmdArgs.push_back("-nostdsysteminc"); |
| 2165 | CmdArgs.push_back("-nobuiltininc"); |
| 2166 | } else { |
Daniel Dunbar | 92d6d40 | 2011-10-11 18:20:16 +0000 | [diff] [blame] | 2167 | if (Args.hasArg(options::OPT_nostdlibinc)) |
| 2168 | CmdArgs.push_back("-nostdsysteminc"); |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 2169 | Args.AddLastArg(CmdArgs, options::OPT_nostdincxx); |
| 2170 | Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc); |
| 2171 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2172 | |
Daniel Dunbar | 5f12232 | 2009-12-15 01:02:52 +0000 | [diff] [blame] | 2173 | // Pass the path to compiler resource files. |
Daniel Dunbar | 5f12232 | 2009-12-15 01:02:52 +0000 | [diff] [blame] | 2174 | CmdArgs.push_back("-resource-dir"); |
Daniel Dunbar | 225c417 | 2010-01-20 02:35:16 +0000 | [diff] [blame] | 2175 | CmdArgs.push_back(D.ResourceDir.c_str()); |
Daniel Dunbar | 2ac9fc2 | 2009-04-07 21:42:00 +0000 | [diff] [blame] | 2176 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2177 | Args.AddLastArg(CmdArgs, options::OPT_working_directory); |
| 2178 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2179 | bool ARCMTEnabled = false; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2180 | if (!Args.hasArg(options::OPT_fno_objc_arc)) { |
Argyrios Kyrtzidis | 72ac120 | 2011-07-07 04:00:39 +0000 | [diff] [blame] | 2181 | if (const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check, |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 2182 | options::OPT_ccc_arcmt_modify, |
| 2183 | options::OPT_ccc_arcmt_migrate)) { |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2184 | ARCMTEnabled = true; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2185 | switch (A->getOption().getID()) { |
| 2186 | default: |
| 2187 | llvm_unreachable("missed a case"); |
Argyrios Kyrtzidis | 72ac120 | 2011-07-07 04:00:39 +0000 | [diff] [blame] | 2188 | case options::OPT_ccc_arcmt_check: |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2189 | CmdArgs.push_back("-arcmt-check"); |
| 2190 | break; |
Argyrios Kyrtzidis | 72ac120 | 2011-07-07 04:00:39 +0000 | [diff] [blame] | 2191 | case options::OPT_ccc_arcmt_modify: |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2192 | CmdArgs.push_back("-arcmt-modify"); |
| 2193 | break; |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 2194 | case options::OPT_ccc_arcmt_migrate: |
| 2195 | CmdArgs.push_back("-arcmt-migrate"); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2196 | CmdArgs.push_back("-mt-migrate-directory"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2197 | CmdArgs.push_back(A->getValue()); |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 2198 | |
| 2199 | Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_report_output); |
| 2200 | Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_emit_arc_errors); |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 2201 | break; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | } |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 2205 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2206 | if (const Arg *A = Args.getLastArg(options::OPT_ccc_objcmt_migrate)) { |
| 2207 | if (ARCMTEnabled) { |
| 2208 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 2209 | << A->getAsString(Args) << "-ccc-arcmt-migrate"; |
| 2210 | } |
| 2211 | CmdArgs.push_back("-mt-migrate-directory"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2212 | CmdArgs.push_back(A->getValue()); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2213 | |
| 2214 | if (!Args.hasArg(options::OPT_objcmt_migrate_literals, |
| 2215 | options::OPT_objcmt_migrate_subscripting)) { |
| 2216 | // None specified, means enable them all. |
| 2217 | CmdArgs.push_back("-objcmt-migrate-literals"); |
| 2218 | CmdArgs.push_back("-objcmt-migrate-subscripting"); |
| 2219 | } else { |
| 2220 | Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals); |
| 2221 | Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting); |
| 2222 | } |
| 2223 | } |
| 2224 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2225 | // Add preprocessing options like -I, -D, etc. if we are using the |
| 2226 | // preprocessor. |
| 2227 | // |
| 2228 | // FIXME: Support -fpreprocessed |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2229 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) |
Peter Collingbourne | 54db68b | 2011-11-06 00:40:05 +0000 | [diff] [blame] | 2230 | AddPreprocessingOptions(C, D, Args, CmdArgs, Output, Inputs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2231 | |
Rafael Espindola | 19d9d2e | 2011-07-21 23:40:37 +0000 | [diff] [blame] | 2232 | // Don't warn about "clang -c -DPIC -fPIC test.i" because libtool.m4 assumes |
| 2233 | // that "The compiler can only warn and ignore the option if not recognized". |
| 2234 | // When building with ccache, it will pass -D options to clang even on |
| 2235 | // preprocessed inputs and configure concludes that -fPIC is not supported. |
| 2236 | Args.ClaimAllArgs(options::OPT_D); |
| 2237 | |
Daniel Dunbar | 20f0eac | 2009-09-17 06:53:36 +0000 | [diff] [blame] | 2238 | // Manually translate -O to -O2 and -O4 to -O3; let clang reject |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 2239 | // others. |
| 2240 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
Daniel Dunbar | b827a05 | 2009-11-19 03:26:40 +0000 | [diff] [blame] | 2241 | if (A->getOption().matches(options::OPT_O4)) |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 2242 | CmdArgs.push_back("-O3"); |
Daniel Dunbar | 473916c | 2010-05-27 06:51:08 +0000 | [diff] [blame] | 2243 | else if (A->getOption().matches(options::OPT_O) && |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2244 | A->getValue()[0] == '\0') |
Daniel Dunbar | 20f0eac | 2009-09-17 06:53:36 +0000 | [diff] [blame] | 2245 | CmdArgs.push_back("-O2"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2246 | else |
Daniel Dunbar | 5697aa0 | 2009-03-18 23:39:35 +0000 | [diff] [blame] | 2247 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
Daniel Dunbar | 6e8371e | 2009-10-29 02:24:45 +0000 | [diff] [blame] | 2250 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group); |
Ted Kremenek | e8cf7d1 | 2012-07-07 05:53:30 +0000 | [diff] [blame] | 2251 | if (Args.hasFlag(options::OPT_pedantic, options::OPT_no_pedantic, false)) |
| 2252 | CmdArgs.push_back("-pedantic"); |
Daniel Dunbar | 6e8371e | 2009-10-29 02:24:45 +0000 | [diff] [blame] | 2253 | Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2254 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 2255 | |
| 2256 | // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi} |
| 2257 | // (-ansi is equivalent to -std=c89). |
| 2258 | // |
| 2259 | // If a std is supplied, only add -trigraphs if it follows the |
| 2260 | // option. |
| 2261 | if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 2262 | if (Std->getOption().matches(options::OPT_ansi)) |
Nuno Lopes | 528365d | 2009-10-16 14:28:06 +0000 | [diff] [blame] | 2263 | if (types::isCXX(InputType)) |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 2264 | CmdArgs.push_back("-std=c++98"); |
Nuno Lopes | 528365d | 2009-10-16 14:28:06 +0000 | [diff] [blame] | 2265 | else |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 2266 | CmdArgs.push_back("-std=c89"); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 2267 | else |
| 2268 | Std->render(Args, CmdArgs); |
| 2269 | |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 2270 | if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi, |
| 2271 | options::OPT_trigraphs)) |
| 2272 | if (A != Std) |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 2273 | A->render(Args, CmdArgs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 2274 | } else { |
| 2275 | // Honor -std-default. |
Daniel Dunbar | 4a5290e | 2010-01-29 21:03:02 +0000 | [diff] [blame] | 2276 | // |
| 2277 | // FIXME: Clang doesn't correctly handle -std= when the input language |
| 2278 | // doesn't match. For the time being just ignore this for C++ inputs; |
| 2279 | // eventually we want to do all the standard defaulting here instead of |
| 2280 | // splitting it between the driver and clang -cc1. |
| 2281 | if (!types::isCXX(InputType)) |
Nico Weber | 50f88b9 | 2012-08-30 02:08:31 +0000 | [diff] [blame] | 2282 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 2283 | "-std=", /*Joined=*/true); |
| 2284 | else if (getToolChain().getTriple().getOS() == llvm::Triple::Win32) |
| 2285 | CmdArgs.push_back("-std=c++11"); |
| 2286 | |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 2287 | Args.AddLastArg(CmdArgs, options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 2288 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2289 | |
Chandler Carruth | 50465d1 | 2011-04-23 06:30:43 +0000 | [diff] [blame] | 2290 | // Map the bizarre '-Wwrite-strings' flag to a more sensible |
| 2291 | // '-fconst-strings'; this better indicates its actual behavior. |
| 2292 | if (Args.hasFlag(options::OPT_Wwrite_strings, options::OPT_Wno_write_strings, |
| 2293 | false)) { |
| 2294 | // For perfect compatibility with GCC, we do this even in the presence of |
| 2295 | // '-w'. This flag names something other than a warning for GCC. |
| 2296 | CmdArgs.push_back("-fconst-strings"); |
| 2297 | } |
| 2298 | |
Chandler Carruth | 1cfe3c3 | 2011-04-23 09:27:53 +0000 | [diff] [blame] | 2299 | // GCC provides a macro definition '__DEPRECATED' when -Wdeprecated is active |
Chandler Carruth | f8c247d | 2011-04-23 19:48:40 +0000 | [diff] [blame] | 2300 | // during C++ compilation, which it is by default. GCC keeps this define even |
| 2301 | // in the presence of '-w', match this behavior bug-for-bug. |
| 2302 | if (types::isCXX(InputType) && |
| 2303 | Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated, |
| 2304 | true)) { |
| 2305 | CmdArgs.push_back("-fdeprecated-macro"); |
Chandler Carruth | 1cfe3c3 | 2011-04-23 09:27:53 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
Chandler Carruth | c304ba3 | 2010-05-22 02:21:53 +0000 | [diff] [blame] | 2308 | // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'. |
| 2309 | if (Arg *Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) { |
| 2310 | if (Asm->getOption().matches(options::OPT_fasm)) |
| 2311 | CmdArgs.push_back("-fgnu-keywords"); |
| 2312 | else |
| 2313 | CmdArgs.push_back("-fno-gnu-keywords"); |
| 2314 | } |
| 2315 | |
Rafael Espindola | 61b1efe | 2011-05-02 17:43:32 +0000 | [diff] [blame] | 2316 | if (ShouldDisableCFI(Args, getToolChain())) |
| 2317 | CmdArgs.push_back("-fno-dwarf2-cfi-asm"); |
Rafael Espindola | f24a151 | 2011-04-30 18:35:43 +0000 | [diff] [blame] | 2318 | |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 2319 | if (ShouldDisableDwarfDirectory(Args, getToolChain())) |
| 2320 | CmdArgs.push_back("-fno-dwarf-directory-asm"); |
| 2321 | |
Nick Lewycky | 7c4fd91 | 2011-10-21 02:32:14 +0000 | [diff] [blame] | 2322 | if (const char *pwd = ::getenv("PWD")) { |
| 2323 | // GCC also verifies that stat(pwd) and stat(".") have the same inode |
| 2324 | // number. Not doing those because stats are slow, but we could. |
NAKAMURA Takumi | 813a407 | 2011-10-22 10:25:25 +0000 | [diff] [blame] | 2325 | if (llvm::sys::path::is_absolute(pwd)) { |
Nick Lewycky | 7c4fd91 | 2011-10-21 02:32:14 +0000 | [diff] [blame] | 2326 | std::string CompDir = pwd; |
| 2327 | CmdArgs.push_back("-fdebug-compilation-dir"); |
| 2328 | CmdArgs.push_back(Args.MakeArgString(CompDir)); |
| 2329 | } |
| 2330 | } |
| 2331 | |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 2332 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_, |
| 2333 | options::OPT_ftemplate_depth_EQ)) { |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2334 | CmdArgs.push_back("-ftemplate-depth"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2335 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 2338 | if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_depth_EQ)) { |
| 2339 | CmdArgs.push_back("-fconstexpr-depth"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2340 | CmdArgs.push_back(A->getValue()); |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
Argyrios Kyrtzidis | 1380a14 | 2010-11-18 00:20:36 +0000 | [diff] [blame] | 2343 | if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ, |
| 2344 | options::OPT_Wlarge_by_value_copy_def)) { |
Jean-Daniel Dupas | 2e4fd6d | 2012-05-04 08:08:37 +0000 | [diff] [blame] | 2345 | if (A->getNumValues()) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2346 | StringRef bytes = A->getValue(); |
Jean-Daniel Dupas | 2e4fd6d | 2012-05-04 08:08:37 +0000 | [diff] [blame] | 2347 | CmdArgs.push_back(Args.MakeArgString("-Wlarge-by-value-copy=" + bytes)); |
| 2348 | } else |
| 2349 | CmdArgs.push_back("-Wlarge-by-value-copy=64"); // default value |
Argyrios Kyrtzidis | 3532fdd | 2010-11-17 23:11:54 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
Nuno Lopes | b3198a8 | 2012-05-08 22:10:46 +0000 | [diff] [blame] | 2352 | |
Michael J. Spencer | c635710 | 2012-10-22 22:13:48 +0000 | [diff] [blame] | 2353 | if (Args.hasArg(options::OPT_relocatable_pch)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 2354 | CmdArgs.push_back("-relocatable-pch"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2355 | |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 2356 | if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) { |
| 2357 | CmdArgs.push_back("-fconstant-string-class"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2358 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 2359 | } |
David Chisnall | 8a5a9aa | 2009-08-31 16:41:57 +0000 | [diff] [blame] | 2360 | |
Chris Lattner | 124fca5 | 2010-01-09 21:54:33 +0000 | [diff] [blame] | 2361 | if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) { |
| 2362 | CmdArgs.push_back("-ftabstop"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2363 | CmdArgs.push_back(A->getValue()); |
Chris Lattner | 124fca5 | 2010-01-09 21:54:33 +0000 | [diff] [blame] | 2364 | } |
| 2365 | |
Chris Lattner | 0f0c963 | 2010-04-07 20:49:23 +0000 | [diff] [blame] | 2366 | CmdArgs.push_back("-ferror-limit"); |
| 2367 | if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2368 | CmdArgs.push_back(A->getValue()); |
Chris Lattner | 0f0c963 | 2010-04-07 20:49:23 +0000 | [diff] [blame] | 2369 | else |
| 2370 | CmdArgs.push_back("19"); |
Douglas Gregor | 575cf37 | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 2371 | |
Chandler Carruth | c40f73c | 2010-05-06 04:55:18 +0000 | [diff] [blame] | 2372 | if (Arg *A = Args.getLastArg(options::OPT_fmacro_backtrace_limit_EQ)) { |
| 2373 | CmdArgs.push_back("-fmacro-backtrace-limit"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2374 | CmdArgs.push_back(A->getValue()); |
Chandler Carruth | c40f73c | 2010-05-06 04:55:18 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ)) { |
| 2378 | CmdArgs.push_back("-ftemplate-backtrace-limit"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2379 | CmdArgs.push_back(A->getValue()); |
Chandler Carruth | c40f73c | 2010-05-06 04:55:18 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
Richard Smith | 08d6e03 | 2011-12-16 19:06:07 +0000 | [diff] [blame] | 2382 | if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_backtrace_limit_EQ)) { |
| 2383 | CmdArgs.push_back("-fconstexpr-backtrace-limit"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2384 | CmdArgs.push_back(A->getValue()); |
Richard Smith | 08d6e03 | 2011-12-16 19:06:07 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 2387 | // Pass -fmessage-length=. |
Daniel Dunbar | a28690e | 2009-11-30 08:40:54 +0000 | [diff] [blame] | 2388 | CmdArgs.push_back("-fmessage-length"); |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 2389 | if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2390 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 2391 | } else { |
| 2392 | // If -fmessage-length=N was not specified, determine whether this is a |
| 2393 | // terminal and, if so, implicitly define -fmessage-length appropriately. |
| 2394 | unsigned N = llvm::sys::Process::StandardErrColumns(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2395 | CmdArgs.push_back(Args.MakeArgString(Twine(N))); |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
Daniel Dunbar | ba8d861 | 2009-12-03 18:42:11 +0000 | [diff] [blame] | 2398 | if (const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ)) { |
| 2399 | CmdArgs.push_back("-fvisibility"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2400 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | ba8d861 | 2009-12-03 18:42:11 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 2403 | Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2404 | |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 2405 | Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ); |
| 2406 | |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 2407 | // -fhosted is default. |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 2408 | if (Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted, false) || |
| 2409 | KernelOrKext) |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 2410 | CmdArgs.push_back("-ffreestanding"); |
| 2411 | |
Daniel Dunbar | ba8d861 | 2009-12-03 18:42:11 +0000 | [diff] [blame] | 2412 | // Forward -f (flag) options which we can pass directly. |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 2413 | Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 2414 | Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); |
Devang Patel | c69e1cf | 2010-09-30 19:05:55 +0000 | [diff] [blame] | 2415 | Args.AddLastArg(CmdArgs, options::OPT_flimit_debug_info); |
Devang Patel | 033be8b | 2011-11-04 20:05:58 +0000 | [diff] [blame] | 2416 | Args.AddLastArg(CmdArgs, options::OPT_fno_limit_debug_info); |
Eric Christopher | e88c451 | 2011-10-25 07:13:06 +0000 | [diff] [blame] | 2417 | Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); |
Anton Yartsev | 17ba267 | 2011-12-23 20:23:19 +0000 | [diff] [blame] | 2418 | Args.AddLastArg(CmdArgs, options::OPT_faltivec); |
Richard Trieu | 246b6aa | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 2419 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree); |
| 2420 | Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type); |
Chad Rosier | 4574c3d | 2012-03-13 23:45:51 +0000 | [diff] [blame] | 2421 | |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 2422 | SanitizerArgs Sanitize(D, Args); |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2423 | Sanitize.addArgs(Args, CmdArgs); |
| 2424 | |
Chad Rosier | 4574c3d | 2012-03-13 23:45:51 +0000 | [diff] [blame] | 2425 | // Report and error for -faltivec on anything other then PowerPC. |
| 2426 | if (const Arg *A = Args.getLastArg(options::OPT_faltivec)) |
| 2427 | if (!(getToolChain().getTriple().getArch() == llvm::Triple::ppc || |
| 2428 | getToolChain().getTriple().getArch() == llvm::Triple::ppc64)) |
| 2429 | D.Diag(diag::err_drv_argument_only_allowed_with) |
| 2430 | << A->getAsString(Args) << "ppc/ppc64"; |
| 2431 | |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 2432 | if (getToolChain().SupportsProfiling()) |
| 2433 | Args.AddLastArg(CmdArgs, options::OPT_pg); |
Daniel Dunbar | 8c6fa84 | 2010-03-16 16:57:46 +0000 | [diff] [blame] | 2434 | |
| 2435 | // -flax-vector-conversions is default. |
| 2436 | if (!Args.hasFlag(options::OPT_flax_vector_conversions, |
| 2437 | options::OPT_fno_lax_vector_conversions)) |
| 2438 | CmdArgs.push_back("-fno-lax-vector-conversions"); |
| 2439 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2440 | if (Args.getLastArg(options::OPT_fapple_kext)) |
| 2441 | CmdArgs.push_back("-fapple-kext"); |
| 2442 | |
David Blaikie | 940152f | 2012-06-14 18:55:27 +0000 | [diff] [blame] | 2443 | if (Args.hasFlag(options::OPT_frewrite_includes, |
| 2444 | options::OPT_fno_rewrite_includes, false)) |
| 2445 | CmdArgs.push_back("-frewrite-includes"); |
| 2446 | |
Fariborz Jahanian | 34e6577 | 2009-05-22 20:17:16 +0000 | [diff] [blame] | 2447 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch); |
Chris Lattner | 182e092 | 2009-04-21 05:34:31 +0000 | [diff] [blame] | 2448 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info); |
Douglas Gregor | 4786c15 | 2010-08-19 20:24:43 +0000 | [diff] [blame] | 2449 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 2450 | Args.AddLastArg(CmdArgs, options::OPT_ftime_report); |
| 2451 | Args.AddLastArg(CmdArgs, options::OPT_ftrapv); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 2452 | |
| 2453 | if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) { |
| 2454 | CmdArgs.push_back("-ftrapv-handler"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2455 | CmdArgs.push_back(A->getValue()); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
Bob Wilson | 71fd6cc | 2012-02-03 06:27:22 +0000 | [diff] [blame] | 2458 | Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ); |
Evan Cheng | 49af1f3 | 2011-04-08 21:37:45 +0000 | [diff] [blame] | 2459 | |
Chandler Carruth | 5adb5a8 | 2011-03-27 00:04:55 +0000 | [diff] [blame] | 2460 | // -fno-strict-overflow implies -fwrapv if it isn't disabled, but |
| 2461 | // -fstrict-overflow won't turn off an explicitly enabled -fwrapv. |
| 2462 | if (Arg *A = Args.getLastArg(options::OPT_fwrapv, |
| 2463 | options::OPT_fno_wrapv)) { |
| 2464 | if (A->getOption().matches(options::OPT_fwrapv)) |
| 2465 | CmdArgs.push_back("-fwrapv"); |
| 2466 | } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow, |
| 2467 | options::OPT_fno_strict_overflow)) { |
| 2468 | if (A->getOption().matches(options::OPT_fno_strict_overflow)) |
| 2469 | CmdArgs.push_back("-fwrapv"); |
| 2470 | } |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 2471 | Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); |
Eric Christopher | f84d409 | 2010-08-07 23:08:14 +0000 | [diff] [blame] | 2472 | Args.AddLastArg(CmdArgs, options::OPT_funroll_loops); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2473 | |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 2474 | Args.AddLastArg(CmdArgs, options::OPT_pthread); |
| 2475 | |
Mahesha S | f3b5231 | 2012-10-27 07:47:56 +0000 | [diff] [blame] | 2476 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2477 | // -stack-protector=0 is default. |
| 2478 | unsigned StackProtectorLevel = 0; |
Bill Wendling | 45483f7 | 2009-06-28 07:36:13 +0000 | [diff] [blame] | 2479 | if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, |
| 2480 | options::OPT_fstack_protector_all, |
| 2481 | options::OPT_fstack_protector)) { |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2482 | if (A->getOption().matches(options::OPT_fstack_protector)) |
| 2483 | StackProtectorLevel = 1; |
| 2484 | else if (A->getOption().matches(options::OPT_fstack_protector_all)) |
| 2485 | StackProtectorLevel = 2; |
Nico Weber | 2fef111 | 2011-08-23 07:38:27 +0000 | [diff] [blame] | 2486 | } else { |
| 2487 | StackProtectorLevel = |
| 2488 | getToolChain().GetDefaultStackProtectorLevel(KernelOrKext); |
| 2489 | } |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2490 | if (StackProtectorLevel) { |
| 2491 | CmdArgs.push_back("-stack-protector"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2492 | CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel))); |
Joerg Sonnenberger | 53b43a7 | 2012-09-12 13:51:14 +0000 | [diff] [blame] | 2493 | } |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 2494 | |
Joerg Sonnenberger | 53b43a7 | 2012-09-12 13:51:14 +0000 | [diff] [blame] | 2495 | // --param ssp-buffer-size= |
| 2496 | for (arg_iterator it = Args.filtered_begin(options::OPT__param), |
| 2497 | ie = Args.filtered_end(); it != ie; ++it) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2498 | StringRef Str((*it)->getValue()); |
Joerg Sonnenberger | 53b43a7 | 2012-09-12 13:51:14 +0000 | [diff] [blame] | 2499 | if (Str.startswith("ssp-buffer-size=")) { |
| 2500 | if (StackProtectorLevel) { |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 2501 | CmdArgs.push_back("-stack-protector-buffer-size"); |
| 2502 | // FIXME: Verify the argument is a valid integer. |
| 2503 | CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16))); |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 2504 | } |
Joerg Sonnenberger | 53b43a7 | 2012-09-12 13:51:14 +0000 | [diff] [blame] | 2505 | (*it)->claim(); |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 2506 | } |
Bill Wendling | 45483f7 | 2009-06-28 07:36:13 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
Nick Lewycky | 4e785c9 | 2011-12-06 03:33:03 +0000 | [diff] [blame] | 2509 | // Translate -mstackrealign |
| 2510 | if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign, |
| 2511 | false)) { |
| 2512 | CmdArgs.push_back("-backend-option"); |
| 2513 | CmdArgs.push_back("-force-align-stack"); |
| 2514 | } |
| 2515 | if (!Args.hasFlag(options::OPT_mno_stackrealign, options::OPT_mstackrealign, |
| 2516 | false)) { |
| 2517 | CmdArgs.push_back(Args.MakeArgString("-mstackrealign")); |
| 2518 | } |
| 2519 | |
Joerg Sonnenberger | e9d11db | 2011-12-05 23:05:23 +0000 | [diff] [blame] | 2520 | if (Args.hasArg(options::OPT_mstack_alignment)) { |
| 2521 | StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment); |
| 2522 | CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment)); |
Eric Christopher | 1a58402 | 2011-05-02 21:18:22 +0000 | [diff] [blame] | 2523 | } |
Chad Rosier | 586a061 | 2012-11-29 00:42:06 +0000 | [diff] [blame] | 2524 | // -mkernel implies -mstrict-align; don't add the redundant option. |
| 2525 | if (Args.hasArg(options::OPT_mstrict_align) && !KernelOrKext) { |
Chad Rosier | 485577d | 2012-11-09 18:27:01 +0000 | [diff] [blame] | 2526 | CmdArgs.push_back("-backend-option"); |
| 2527 | CmdArgs.push_back("-arm-strict-align"); |
Chad Rosier | 7e29327 | 2012-11-09 17:29:19 +0000 | [diff] [blame] | 2528 | } |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 2529 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2530 | // Forward -f options with positive and negative forms; we translate |
| 2531 | // these by hand. |
| 2532 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2533 | if (Args.hasArg(options::OPT_mkernel)) { |
Daniel Dunbar | 2843c19 | 2011-02-04 17:24:47 +0000 | [diff] [blame] | 2534 | if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType)) |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2535 | CmdArgs.push_back("-fapple-kext"); |
| 2536 | if (!Args.hasArg(options::OPT_fbuiltin)) |
| 2537 | CmdArgs.push_back("-fno-builtin"); |
Chad Rosier | 3d26550 | 2012-03-26 21:29:17 +0000 | [diff] [blame] | 2538 | Args.ClaimAllArgs(options::OPT_fno_builtin); |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2539 | } |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2540 | // -fbuiltin is default. |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2541 | else if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin)) |
Daniel Dunbar | 53e8484 | 2009-11-19 04:55:23 +0000 | [diff] [blame] | 2542 | CmdArgs.push_back("-fno-builtin"); |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2543 | |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 2544 | if (!Args.hasFlag(options::OPT_fassume_sane_operator_new, |
| 2545 | options::OPT_fno_assume_sane_operator_new)) |
| 2546 | CmdArgs.push_back("-fno-assume-sane-operator-new"); |
| 2547 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2548 | // -fblocks=0 is default. |
| 2549 | if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks, |
David Chisnall | e6533ff | 2011-02-28 17:11:43 +0000 | [diff] [blame] | 2550 | getToolChain().IsBlocksDefault()) || |
| 2551 | (Args.hasArg(options::OPT_fgnu_runtime) && |
| 2552 | Args.hasArg(options::OPT_fobjc_nonfragile_abi) && |
| 2553 | !Args.hasArg(options::OPT_fno_blocks))) { |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2554 | CmdArgs.push_back("-fblocks"); |
John McCall | 13db5cf | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 2555 | |
| 2556 | if (!Args.hasArg(options::OPT_fgnu_runtime) && |
| 2557 | !getToolChain().hasBlocksRuntime()) |
| 2558 | CmdArgs.push_back("-fblocks-runtime-optional"); |
David Chisnall | 5e530af | 2009-11-17 19:33:30 +0000 | [diff] [blame] | 2559 | } |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2560 | |
Douglas Gregor | 64554ba | 2012-01-18 15:19:58 +0000 | [diff] [blame] | 2561 | // -fmodules enables modules (off by default). However, for C++/Objective-C++, |
| 2562 | // users must also pass -fcxx-modules. The latter flag will disappear once the |
| 2563 | // modules implementation is solid for C++/Objective-C++ programs as well. |
| 2564 | if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) { |
| 2565 | bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules, |
| 2566 | options::OPT_fno_cxx_modules, |
| 2567 | false); |
| 2568 | if (AllowedInCXX || !types::isCXX(InputType)) |
| 2569 | CmdArgs.push_back("-fmodules"); |
| 2570 | } |
Douglas Gregor | 7025d2c | 2012-01-03 17:13:05 +0000 | [diff] [blame] | 2571 | |
John McCall | 32579cf | 2010-04-09 19:12:06 +0000 | [diff] [blame] | 2572 | // -faccess-control is default. |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 2573 | if (Args.hasFlag(options::OPT_fno_access_control, |
| 2574 | options::OPT_faccess_control, |
John McCall | 32579cf | 2010-04-09 19:12:06 +0000 | [diff] [blame] | 2575 | false)) |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 2576 | CmdArgs.push_back("-fno-access-control"); |
John McCall | 3ddd6e0 | 2010-03-17 01:32:13 +0000 | [diff] [blame] | 2577 | |
Anders Carlsson | a4c2475 | 2010-11-21 00:09:52 +0000 | [diff] [blame] | 2578 | // -felide-constructors is the default. |
| 2579 | if (Args.hasFlag(options::OPT_fno_elide_constructors, |
| 2580 | options::OPT_felide_constructors, |
| 2581 | false)) |
| 2582 | CmdArgs.push_back("-fno-elide-constructors"); |
| 2583 | |
Daniel Dunbar | 0be42c4 | 2009-11-17 07:06:20 +0000 | [diff] [blame] | 2584 | // -frtti is default. |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 2585 | if (!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti) || |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2586 | KernelOrKext) { |
Daniel Dunbar | 53e8484 | 2009-11-19 04:55:23 +0000 | [diff] [blame] | 2587 | CmdArgs.push_back("-fno-rtti"); |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 2588 | |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2589 | // -fno-rtti cannot usefully be combined with -fsanitize=vptr. |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 2590 | if (Sanitize.sanitizesVptr()) { |
NAKAMURA Takumi | 03c6076 | 2012-11-06 22:02:00 +0000 | [diff] [blame] | 2591 | std::string NoRttiArg = |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2592 | Args.getLastArg(options::OPT_mkernel, |
| 2593 | options::OPT_fapple_kext, |
Richard Smith | 04fd382 | 2012-11-06 01:12:02 +0000 | [diff] [blame] | 2594 | options::OPT_fno_rtti)->getAsString(Args); |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2595 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 2596 | << "-fsanitize=vptr" << NoRttiArg; |
| 2597 | } |
| 2598 | } |
| 2599 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2600 | // -fshort-enums=0 is default for all architectures except Hexagon. |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 2601 | if (Args.hasFlag(options::OPT_fshort_enums, |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2602 | options::OPT_fno_short_enums, |
| 2603 | getToolChain().getTriple().getArch() == |
| 2604 | llvm::Triple::hexagon)) |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 2605 | CmdArgs.push_back("-fshort-enums"); |
| 2606 | |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 2607 | // -fsigned-char is default. |
Daniel Dunbar | 6d2eb4d | 2009-11-25 10:14:30 +0000 | [diff] [blame] | 2608 | if (!Args.hasFlag(options::OPT_fsigned_char, options::OPT_funsigned_char, |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 2609 | isSignedCharDefault(getToolChain().getTriple()))) |
Daniel Dunbar | 7674352 | 2009-11-29 02:39:08 +0000 | [diff] [blame] | 2610 | CmdArgs.push_back("-fno-signed-char"); |
Eli Friedman | 5a77973 | 2009-06-05 07:21:14 +0000 | [diff] [blame] | 2611 | |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 2612 | // -fthreadsafe-static is default. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2613 | if (!Args.hasFlag(options::OPT_fthreadsafe_statics, |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 2614 | options::OPT_fno_threadsafe_statics)) |
| 2615 | CmdArgs.push_back("-fno-threadsafe-statics"); |
| 2616 | |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 2617 | // -fuse-cxa-atexit is default. |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 2618 | if (!Args.hasFlag(options::OPT_fuse_cxa_atexit, |
| 2619 | options::OPT_fno_use_cxa_atexit, |
| 2620 | getToolChain().getTriple().getOS() != llvm::Triple::Cygwin && |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2621 | getToolChain().getTriple().getOS() != llvm::Triple::MinGW32 && |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 2622 | getToolChain().getTriple().getArch() != llvm::Triple::hexagon) || |
| 2623 | KernelOrKext) |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 2624 | CmdArgs.push_back("-fno-use-cxa-atexit"); |
| 2625 | |
Daniel Dunbar | 0be42c4 | 2009-11-17 07:06:20 +0000 | [diff] [blame] | 2626 | // -fms-extensions=0 is default. |
Daniel Dunbar | 6d2eb4d | 2009-11-25 10:14:30 +0000 | [diff] [blame] | 2627 | if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, |
Daniel Dunbar | 0be42c4 | 2009-11-17 07:06:20 +0000 | [diff] [blame] | 2628 | getToolChain().getTriple().getOS() == llvm::Triple::Win32)) |
| 2629 | CmdArgs.push_back("-fms-extensions"); |
| 2630 | |
Chad Rosier | f925e04 | 2012-07-20 21:20:33 +0000 | [diff] [blame] | 2631 | // -fms-inline-asm. |
Chad Rosier | d256f86 | 2012-07-20 23:12:26 +0000 | [diff] [blame] | 2632 | if (Args.hasArg(options::OPT_fenable_experimental_ms_inline_asm)) |
| 2633 | CmdArgs.push_back("-fenable-experimental-ms-inline-asm"); |
Chad Rosier | f925e04 | 2012-07-20 21:20:33 +0000 | [diff] [blame] | 2634 | |
Francois Pichet | ae55608 | 2011-09-17 04:32:15 +0000 | [diff] [blame] | 2635 | // -fms-compatibility=0 is default. |
Douglas Gregor | ba97b6e | 2011-10-24 15:49:38 +0000 | [diff] [blame] | 2636 | if (Args.hasFlag(options::OPT_fms_compatibility, |
| 2637 | options::OPT_fno_ms_compatibility, |
| 2638 | (getToolChain().getTriple().getOS() == llvm::Triple::Win32 && |
| 2639 | Args.hasFlag(options::OPT_fms_extensions, |
| 2640 | options::OPT_fno_ms_extensions, |
| 2641 | true)))) |
Francois Pichet | ae55608 | 2011-09-17 04:32:15 +0000 | [diff] [blame] | 2642 | CmdArgs.push_back("-fms-compatibility"); |
| 2643 | |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2644 | // -fmsc-version=1300 is default. |
| 2645 | if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, |
| 2646 | getToolChain().getTriple().getOS() == llvm::Triple::Win32) || |
| 2647 | Args.hasArg(options::OPT_fmsc_version)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2648 | StringRef msc_ver = Args.getLastArgValue(options::OPT_fmsc_version); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2649 | if (msc_ver.empty()) |
| 2650 | CmdArgs.push_back("-fmsc-version=1300"); |
| 2651 | else |
| 2652 | CmdArgs.push_back(Args.MakeArgString("-fmsc-version=" + msc_ver)); |
| 2653 | } |
| 2654 | |
| 2655 | |
Dawn Perchik | 400b607 | 2010-09-02 23:59:25 +0000 | [diff] [blame] | 2656 | // -fborland-extensions=0 is default. |
| 2657 | if (Args.hasFlag(options::OPT_fborland_extensions, |
| 2658 | options::OPT_fno_borland_extensions, false)) |
| 2659 | CmdArgs.push_back("-fborland-extensions"); |
| 2660 | |
Francois Pichet | 8efcc01 | 2011-09-01 16:38:08 +0000 | [diff] [blame] | 2661 | // -fno-delayed-template-parsing is default, except for Windows where MSVC STL |
| 2662 | // needs it. |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 2663 | if (Args.hasFlag(options::OPT_fdelayed_template_parsing, |
| 2664 | options::OPT_fno_delayed_template_parsing, |
Francois Pichet | 8efcc01 | 2011-09-01 16:38:08 +0000 | [diff] [blame] | 2665 | getToolChain().getTriple().getOS() == llvm::Triple::Win32)) |
Francois Pichet | 805bc1f | 2011-08-26 00:22:34 +0000 | [diff] [blame] | 2666 | CmdArgs.push_back("-fdelayed-template-parsing"); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 2667 | |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2668 | // -fgnu-keywords default varies depending on language; only pass if |
| 2669 | // specified. |
| 2670 | if (Arg *A = Args.getLastArg(options::OPT_fgnu_keywords, |
Daniel Dunbar | 40788d9 | 2010-04-24 17:56:39 +0000 | [diff] [blame] | 2671 | options::OPT_fno_gnu_keywords)) |
| 2672 | A->render(Args, CmdArgs); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2673 | |
Rafael Espindola | 01ba854 | 2011-06-02 17:30:53 +0000 | [diff] [blame] | 2674 | if (Args.hasFlag(options::OPT_fgnu89_inline, |
| 2675 | options::OPT_fno_gnu89_inline, |
| 2676 | false)) |
Rafael Espindola | fb3f4aa | 2011-06-02 16:13:27 +0000 | [diff] [blame] | 2677 | CmdArgs.push_back("-fgnu89-inline"); |
| 2678 | |
Chad Rosier | fc055f9 | 2012-03-15 22:31:42 +0000 | [diff] [blame] | 2679 | if (Args.hasArg(options::OPT_fno_inline)) |
| 2680 | CmdArgs.push_back("-fno-inline"); |
| 2681 | |
Chad Rosier | 634a4b1 | 2012-03-06 21:17:19 +0000 | [diff] [blame] | 2682 | if (Args.hasArg(options::OPT_fno_inline_functions)) |
| 2683 | CmdArgs.push_back("-fno-inline-functions"); |
Chad Rosier | 250008b | 2012-03-06 18:49:20 +0000 | [diff] [blame] | 2684 | |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 2685 | ObjCRuntime objcRuntime = AddObjCRuntimeArgs(Args, CmdArgs, rewriteKind); |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2686 | |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 2687 | // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and |
| 2688 | // legacy is the default. |
| 2689 | if (objcRuntime.isNonFragile()) { |
David Chisnall | 3c3ccd2 | 2011-09-30 13:32:35 +0000 | [diff] [blame] | 2690 | if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch, |
| 2691 | options::OPT_fno_objc_legacy_dispatch, |
David Chisnall | 2c7886d | 2012-07-04 11:52:24 +0000 | [diff] [blame] | 2692 | objcRuntime.isLegacyDispatchDefaultForArch( |
| 2693 | getToolChain().getTriple().getArch()))) { |
David Chisnall | 3c3ccd2 | 2011-09-30 13:32:35 +0000 | [diff] [blame] | 2694 | if (getToolChain().UseObjCMixedDispatch()) |
| 2695 | CmdArgs.push_back("-fobjc-dispatch-method=mixed"); |
| 2696 | else |
| 2697 | CmdArgs.push_back("-fobjc-dispatch-method=non-legacy"); |
| 2698 | } |
| 2699 | } |
| 2700 | |
Nico Weber | df42354 | 2012-03-09 21:19:44 +0000 | [diff] [blame] | 2701 | // -fobjc-default-synthesize-properties=1 is default. This only has an effect |
| 2702 | // if the nonfragile objc abi is used. |
Fariborz Jahanian | e51fe09 | 2012-04-09 18:58:55 +0000 | [diff] [blame] | 2703 | if (getToolChain().IsObjCDefaultSynthPropertiesDefault()) { |
David Chisnall | 3c3ccd2 | 2011-09-30 13:32:35 +0000 | [diff] [blame] | 2704 | CmdArgs.push_back("-fobjc-default-synthesize-properties"); |
| 2705 | } |
| 2706 | |
Fariborz Jahanian | 3d145f6 | 2012-11-15 19:02:45 +0000 | [diff] [blame] | 2707 | // -fencode-extended-block-signature=1 is default. |
| 2708 | if (getToolChain().IsEncodeExtendedBlockSignatureDefault()) { |
| 2709 | CmdArgs.push_back("-fencode-extended-block-signature"); |
| 2710 | } |
| 2711 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2712 | // Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc. |
| 2713 | // NOTE: This logic is duplicated in ToolChains.cpp. |
| 2714 | bool ARC = isObjCAutoRefCount(Args); |
| 2715 | if (ARC) { |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 2716 | getToolChain().CheckObjCARC(); |
Argyrios Kyrtzidis | 5840dd9 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 2717 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2718 | CmdArgs.push_back("-fobjc-arc"); |
| 2719 | |
Chandler Carruth | 7ffa032 | 2011-11-04 07:34:47 +0000 | [diff] [blame] | 2720 | // FIXME: It seems like this entire block, and several around it should be |
| 2721 | // wrapped in isObjC, but for now we just use it here as this is where it |
| 2722 | // was being used previously. |
| 2723 | if (types::isCXX(InputType) && types::isObjC(InputType)) { |
| 2724 | if (getToolChain().GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) |
| 2725 | CmdArgs.push_back("-fobjc-arc-cxxlib=libc++"); |
| 2726 | else |
| 2727 | CmdArgs.push_back("-fobjc-arc-cxxlib=libstdc++"); |
| 2728 | } |
| 2729 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2730 | // Allow the user to enable full exceptions code emission. |
| 2731 | // We define off for Objective-CC, on for Objective-C++. |
| 2732 | if (Args.hasFlag(options::OPT_fobjc_arc_exceptions, |
| 2733 | options::OPT_fno_objc_arc_exceptions, |
| 2734 | /*default*/ types::isCXX(InputType))) |
| 2735 | CmdArgs.push_back("-fobjc-arc-exceptions"); |
| 2736 | } |
| 2737 | |
| 2738 | // -fobjc-infer-related-result-type is the default, except in the Objective-C |
| 2739 | // rewriter. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 2740 | if (rewriteKind != RK_None) |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2741 | CmdArgs.push_back("-fno-objc-infer-related-result-type"); |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 2742 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2743 | // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only |
| 2744 | // takes precedence. |
| 2745 | const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only); |
| 2746 | if (!GCArg) |
| 2747 | GCArg = Args.getLastArg(options::OPT_fobjc_gc); |
| 2748 | if (GCArg) { |
| 2749 | if (ARC) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2750 | D.Diag(diag::err_drv_objc_gc_arr) |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2751 | << GCArg->getAsString(Args); |
| 2752 | } else if (getToolChain().SupportsObjCGC()) { |
| 2753 | GCArg->render(Args, CmdArgs); |
| 2754 | } else { |
| 2755 | // FIXME: We should move this to a hard error. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2756 | D.Diag(diag::warn_drv_objc_gc_unsupported) |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2757 | << GCArg->getAsString(Args); |
| 2758 | } |
| 2759 | } |
| 2760 | |
John McCall | d71315c | 2011-06-22 00:53:57 +0000 | [diff] [blame] | 2761 | // Add exception args. |
| 2762 | addExceptionArgs(Args, InputType, getToolChain().getTriple(), |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 2763 | KernelOrKext, objcRuntime, CmdArgs); |
John McCall | d71315c | 2011-06-22 00:53:57 +0000 | [diff] [blame] | 2764 | |
| 2765 | if (getToolChain().UseSjLjExceptions()) |
| 2766 | CmdArgs.push_back("-fsjlj-exceptions"); |
| 2767 | |
| 2768 | // C++ "sane" operator new. |
Daniel Dunbar | 984eb86 | 2010-02-01 21:07:25 +0000 | [diff] [blame] | 2769 | if (!Args.hasFlag(options::OPT_fassume_sane_operator_new, |
| 2770 | options::OPT_fno_assume_sane_operator_new)) |
| 2771 | CmdArgs.push_back("-fno-assume-sane-operator-new"); |
| 2772 | |
Daniel Dunbar | f35f14d | 2010-04-27 15:34:57 +0000 | [diff] [blame] | 2773 | // -fconstant-cfstrings is default, and may be subject to argument translation |
| 2774 | // on Darwin. |
| 2775 | if (!Args.hasFlag(options::OPT_fconstant_cfstrings, |
| 2776 | options::OPT_fno_constant_cfstrings) || |
| 2777 | !Args.hasFlag(options::OPT_mconstant_cfstrings, |
| 2778 | options::OPT_mno_constant_cfstrings)) |
| 2779 | CmdArgs.push_back("-fno-constant-cfstrings"); |
| 2780 | |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2781 | // -fshort-wchar default varies depending on platform; only |
| 2782 | // pass if specified. |
Daniel Dunbar | 1744a35 | 2010-04-27 15:35:03 +0000 | [diff] [blame] | 2783 | if (Arg *A = Args.getLastArg(options::OPT_fshort_wchar)) |
| 2784 | A->render(Args, CmdArgs); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2785 | |
Daniel Dunbar | ee848a7 | 2009-10-29 02:39:57 +0000 | [diff] [blame] | 2786 | // -fno-pascal-strings is default, only pass non-default. If the tool chain |
| 2787 | // happened to translate to -mpascal-strings, we want to back translate here. |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 2788 | // |
| 2789 | // FIXME: This is gross; that translation should be pulled from the |
| 2790 | // tool chain. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2791 | if (Args.hasFlag(options::OPT_fpascal_strings, |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 2792 | options::OPT_fno_pascal_strings, |
| 2793 | false) || |
| 2794 | Args.hasFlag(options::OPT_mpascal_strings, |
| 2795 | options::OPT_mno_pascal_strings, |
| 2796 | false)) |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2797 | CmdArgs.push_back("-fpascal-strings"); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 2798 | |
Daniel Dunbar | 88934e8 | 2011-10-05 21:04:55 +0000 | [diff] [blame] | 2799 | // Honor -fpack-struct= and -fpack-struct, if given. Note that |
| 2800 | // -fno-pack-struct doesn't apply to -fpack-struct=. |
| 2801 | if (Arg *A = Args.getLastArg(options::OPT_fpack_struct_EQ)) { |
James Molloy | 8049c44 | 2012-05-02 07:56:14 +0000 | [diff] [blame] | 2802 | std::string PackStructStr = "-fpack-struct="; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2803 | PackStructStr += A->getValue(); |
James Molloy | 8049c44 | 2012-05-02 07:56:14 +0000 | [diff] [blame] | 2804 | CmdArgs.push_back(Args.MakeArgString(PackStructStr)); |
Daniel Dunbar | 88934e8 | 2011-10-05 21:04:55 +0000 | [diff] [blame] | 2805 | } else if (Args.hasFlag(options::OPT_fpack_struct, |
| 2806 | options::OPT_fno_pack_struct, false)) { |
James Molloy | 8049c44 | 2012-05-02 07:56:14 +0000 | [diff] [blame] | 2807 | CmdArgs.push_back("-fpack-struct=1"); |
Daniel Dunbar | 88934e8 | 2011-10-05 21:04:55 +0000 | [diff] [blame] | 2808 | } |
| 2809 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2810 | if (Args.hasArg(options::OPT_mkernel) || |
| 2811 | Args.hasArg(options::OPT_fapple_kext)) { |
| 2812 | if (!Args.hasArg(options::OPT_fcommon)) |
| 2813 | CmdArgs.push_back("-fno-common"); |
Chad Rosier | ec09b3e | 2012-03-26 21:35:40 +0000 | [diff] [blame] | 2814 | Args.ClaimAllArgs(options::OPT_fno_common); |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2815 | } |
Daniel Dunbar | 88934e8 | 2011-10-05 21:04:55 +0000 | [diff] [blame] | 2816 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2817 | // -fcommon is default, only pass non-default. |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2818 | else if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common)) |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2819 | CmdArgs.push_back("-fno-common"); |
| 2820 | |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 2821 | // -fsigned-bitfields is default, and clang doesn't yet support |
Daniel Dunbar | 06205ca | 2010-10-15 22:30:42 +0000 | [diff] [blame] | 2822 | // -funsigned-bitfields. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2823 | if (!Args.hasFlag(options::OPT_fsigned_bitfields, |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 2824 | options::OPT_funsigned_bitfields)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2825 | D.Diag(diag::warn_drv_clang_unsupported) |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 2826 | << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args); |
| 2827 | |
Daniel Dunbar | 06205ca | 2010-10-15 22:30:42 +0000 | [diff] [blame] | 2828 | // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope. |
| 2829 | if (!Args.hasFlag(options::OPT_ffor_scope, |
| 2830 | options::OPT_fno_for_scope)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2831 | D.Diag(diag::err_drv_clang_unsupported) |
Daniel Dunbar | 06205ca | 2010-10-15 22:30:42 +0000 | [diff] [blame] | 2832 | << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args); |
| 2833 | |
Jeffrey Yasskin | 0ea22fd | 2010-06-08 04:56:20 +0000 | [diff] [blame] | 2834 | // -fcaret-diagnostics is default. |
| 2835 | if (!Args.hasFlag(options::OPT_fcaret_diagnostics, |
| 2836 | options::OPT_fno_caret_diagnostics, true)) |
| 2837 | CmdArgs.push_back("-fno-caret-diagnostics"); |
| 2838 | |
Daniel Dunbar | 49138fc | 2009-04-19 21:09:34 +0000 | [diff] [blame] | 2839 | // -fdiagnostics-fixit-info is default, only pass non-default. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2840 | if (!Args.hasFlag(options::OPT_fdiagnostics_fixit_info, |
Daniel Dunbar | 49138fc | 2009-04-19 21:09:34 +0000 | [diff] [blame] | 2841 | options::OPT_fno_diagnostics_fixit_info)) |
| 2842 | CmdArgs.push_back("-fno-diagnostics-fixit-info"); |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 2843 | |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 2844 | // Enable -fdiagnostics-show-option by default. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2845 | if (Args.hasFlag(options::OPT_fdiagnostics_show_option, |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 2846 | options::OPT_fno_diagnostics_show_option)) |
| 2847 | CmdArgs.push_back("-fdiagnostics-show-option"); |
Daniel Dunbar | 838be48 | 2009-11-04 06:24:57 +0000 | [diff] [blame] | 2848 | |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 2849 | if (const Arg *A = |
| 2850 | Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) { |
| 2851 | CmdArgs.push_back("-fdiagnostics-show-category"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2852 | CmdArgs.push_back(A->getValue()); |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 2853 | } |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 2854 | |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 2855 | if (const Arg *A = |
| 2856 | Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) { |
| 2857 | CmdArgs.push_back("-fdiagnostics-format"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2858 | CmdArgs.push_back(A->getValue()); |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 2859 | } |
| 2860 | |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 2861 | if (Arg *A = Args.getLastArg( |
| 2862 | options::OPT_fdiagnostics_show_note_include_stack, |
| 2863 | options::OPT_fno_diagnostics_show_note_include_stack)) { |
| 2864 | if (A->getOption().matches( |
| 2865 | options::OPT_fdiagnostics_show_note_include_stack)) |
| 2866 | CmdArgs.push_back("-fdiagnostics-show-note-include-stack"); |
| 2867 | else |
| 2868 | CmdArgs.push_back("-fno-diagnostics-show-note-include-stack"); |
| 2869 | } |
| 2870 | |
Daniel Dunbar | 838be48 | 2009-11-04 06:24:57 +0000 | [diff] [blame] | 2871 | // Color diagnostics are the default, unless the terminal doesn't support |
| 2872 | // them. |
| 2873 | if (Args.hasFlag(options::OPT_fcolor_diagnostics, |
Argyrios Kyrtzidis | f765d76 | 2010-09-23 12:56:06 +0000 | [diff] [blame] | 2874 | options::OPT_fno_color_diagnostics, |
| 2875 | llvm::sys::Process::StandardErrHasColors())) |
Daniel Dunbar | 838be48 | 2009-11-04 06:24:57 +0000 | [diff] [blame] | 2876 | CmdArgs.push_back("-fcolor-diagnostics"); |
| 2877 | |
Daniel Dunbar | 75eb1d6 | 2009-06-08 21:13:54 +0000 | [diff] [blame] | 2878 | if (!Args.hasFlag(options::OPT_fshow_source_location, |
| 2879 | options::OPT_fno_show_source_location)) |
| 2880 | CmdArgs.push_back("-fno-show-source-location"); |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 2881 | |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 2882 | if (!Args.hasFlag(options::OPT_fshow_column, |
| 2883 | options::OPT_fno_show_column, |
| 2884 | true)) |
| 2885 | CmdArgs.push_back("-fno-show-column"); |
| 2886 | |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 2887 | if (!Args.hasFlag(options::OPT_fspell_checking, |
| 2888 | options::OPT_fno_spell_checking)) |
| 2889 | CmdArgs.push_back("-fno-spell-checking"); |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 2890 | |
Daniel Dunbar | 25b26eb | 2010-10-18 22:49:46 +0000 | [diff] [blame] | 2891 | |
Daniel Dunbar | 1689439 | 2010-11-02 19:42:04 +0000 | [diff] [blame] | 2892 | // Silently ignore -fasm-blocks for now. |
| 2893 | (void) Args.hasFlag(options::OPT_fasm_blocks, options::OPT_fno_asm_blocks, |
| 2894 | false); |
Daniel Dunbar | 25b26eb | 2010-10-18 22:49:46 +0000 | [diff] [blame] | 2895 | |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 2896 | if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ)) |
| 2897 | A->render(Args, CmdArgs); |
| 2898 | |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 2899 | // -fdollars-in-identifiers default varies depending on platform and |
| 2900 | // language; only pass if specified. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2901 | if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers, |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 2902 | options::OPT_fno_dollars_in_identifiers)) { |
| 2903 | if (A->getOption().matches(options::OPT_fdollars_in_identifiers)) |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 2904 | CmdArgs.push_back("-fdollars-in-identifiers"); |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 2905 | else |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 2906 | CmdArgs.push_back("-fno-dollars-in-identifiers"); |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 2909 | // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for |
| 2910 | // practical purposes. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2911 | if (Arg *A = Args.getLastArg(options::OPT_funit_at_a_time, |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 2912 | options::OPT_fno_unit_at_a_time)) { |
| 2913 | if (A->getOption().matches(options::OPT_fno_unit_at_a_time)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2914 | D.Diag(diag::warn_drv_clang_unsupported) << A->getAsString(Args); |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 2915 | } |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 2916 | |
Eli Friedman | 19bda3a | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 2917 | if (Args.hasFlag(options::OPT_fapple_pragma_pack, |
| 2918 | options::OPT_fno_apple_pragma_pack, false)) |
| 2919 | CmdArgs.push_back("-fapple-pragma-pack"); |
| 2920 | |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 2921 | // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM. |
Daniel Dunbar | f84a4a4 | 2009-09-10 04:57:27 +0000 | [diff] [blame] | 2922 | // |
Daniel Dunbar | 8ff5b28 | 2009-12-11 23:00:49 +0000 | [diff] [blame] | 2923 | // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941. |
Daniel Dunbar | f84a4a4 | 2009-09-10 04:57:27 +0000 | [diff] [blame] | 2924 | #if 0 |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 2925 | if (getToolChain().getTriple().isOSDarwin() && |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 2926 | (getToolChain().getTriple().getArch() == llvm::Triple::arm || |
| 2927 | getToolChain().getTriple().getArch() == llvm::Triple::thumb)) { |
| 2928 | if (!Args.hasArg(options::OPT_fbuiltin_strcat)) |
| 2929 | CmdArgs.push_back("-fno-builtin-strcat"); |
| 2930 | if (!Args.hasArg(options::OPT_fbuiltin_strcpy)) |
| 2931 | CmdArgs.push_back("-fno-builtin-strcpy"); |
| 2932 | } |
Daniel Dunbar | f84a4a4 | 2009-09-10 04:57:27 +0000 | [diff] [blame] | 2933 | #endif |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 2934 | |
Daniel Dunbar | d98750f | 2011-03-18 21:23:40 +0000 | [diff] [blame] | 2935 | // Only allow -traditional or -traditional-cpp outside in preprocessing modes. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2936 | if (Arg *A = Args.getLastArg(options::OPT_traditional, |
Daniel Dunbar | d98750f | 2011-03-18 21:23:40 +0000 | [diff] [blame] | 2937 | options::OPT_traditional_cpp)) { |
| 2938 | if (isa<PreprocessJobAction>(JA)) |
| 2939 | CmdArgs.push_back("-traditional-cpp"); |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 2940 | else |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2941 | D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); |
Daniel Dunbar | d98750f | 2011-03-18 21:23:40 +0000 | [diff] [blame] | 2942 | } |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 2943 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2944 | Args.AddLastArg(CmdArgs, options::OPT_dM); |
Chris Lattner | d82df3a | 2009-04-12 01:56:53 +0000 | [diff] [blame] | 2945 | Args.AddLastArg(CmdArgs, options::OPT_dD); |
Ted Kremenek | 36f6e30 | 2011-11-11 00:07:43 +0000 | [diff] [blame] | 2946 | |
| 2947 | // Handle serialized diagnostics. |
| 2948 | if (Arg *A = Args.getLastArg(options::OPT__serialize_diags)) { |
| 2949 | CmdArgs.push_back("-serialize-diagnostic-file"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2950 | CmdArgs.push_back(Args.MakeArgString(A->getValue())); |
Ted Kremenek | 36f6e30 | 2011-11-11 00:07:43 +0000 | [diff] [blame] | 2951 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2952 | |
Ted Kremenek | 127ff2e | 2012-09-13 06:41:18 +0000 | [diff] [blame] | 2953 | if (Args.hasArg(options::OPT_fretain_comments_from_system_headers)) |
| 2954 | CmdArgs.push_back("-fretain-comments-from-system-headers"); |
| 2955 | |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 2956 | // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option |
| 2957 | // parser. |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2958 | Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 2959 | for (arg_iterator it = Args.filtered_begin(options::OPT_mllvm), |
| 2960 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2961 | (*it)->claim(); |
Daniel Dunbar | fb36d21 | 2010-04-17 06:10:00 +0000 | [diff] [blame] | 2962 | |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 2963 | // We translate this by hand to the -cc1 argument, since nightly test uses |
| 2964 | // it and developers have been trained to spell it with -mllvm. |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2965 | if (StringRef((*it)->getValue(0)) == "-disable-llvm-optzns") |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 2966 | CmdArgs.push_back("-disable-llvm-optzns"); |
| 2967 | else |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2968 | (*it)->render(Args, CmdArgs); |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 2969 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2970 | |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 2971 | if (Output.getType() == types::TY_Dependencies) { |
| 2972 | // Handled with other dependency code. |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 2973 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2974 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 2975 | CmdArgs.push_back(Output.getFilename()); |
| 2976 | } else { |
| 2977 | assert(Output.isNothing() && "Invalid output."); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2978 | } |
| 2979 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2980 | for (InputInfoList::const_iterator |
| 2981 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2982 | const InputInfo &II = *it; |
| 2983 | CmdArgs.push_back("-x"); |
Fariborz Jahanian | a5ee089 | 2012-09-28 19:05:17 +0000 | [diff] [blame] | 2984 | if (Args.hasArg(options::OPT_rewrite_objc)) |
| 2985 | CmdArgs.push_back(types::getTypeName(types::TY_PP_ObjCXX)); |
| 2986 | else |
| 2987 | CmdArgs.push_back(types::getTypeName(II.getType())); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 2988 | if (II.isFilename()) |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 2989 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2990 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 2991 | II.getInputArg().renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2992 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2993 | |
Chris Lattner | e6113de | 2009-11-03 19:50:27 +0000 | [diff] [blame] | 2994 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 2995 | |
Daniel Dunbar | a001c1c | 2010-07-18 21:16:15 +0000 | [diff] [blame] | 2996 | const char *Exec = getToolChain().getDriver().getClangProgramPath(); |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 2997 | |
| 2998 | // Optionally embed the -cc1 level arguments into the debug info, for build |
| 2999 | // analysis. |
| 3000 | if (getToolChain().UseDwarfDebugFlags()) { |
Daniel Dunbar | 6e90047 | 2010-06-04 18:47:06 +0000 | [diff] [blame] | 3001 | ArgStringList OriginalArgs; |
| 3002 | for (ArgList::const_iterator it = Args.begin(), |
| 3003 | ie = Args.end(); it != ie; ++it) |
| 3004 | (*it)->render(Args, OriginalArgs); |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 3005 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3006 | SmallString<256> Flags; |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 3007 | Flags += Exec; |
Daniel Dunbar | 6e90047 | 2010-06-04 18:47:06 +0000 | [diff] [blame] | 3008 | for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) { |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 3009 | Flags += " "; |
Daniel Dunbar | 6e90047 | 2010-06-04 18:47:06 +0000 | [diff] [blame] | 3010 | Flags += OriginalArgs[i]; |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 3011 | } |
| 3012 | CmdArgs.push_back("-dwarf-debug-flags"); |
| 3013 | CmdArgs.push_back(Args.MakeArgString(Flags.str())); |
| 3014 | } |
| 3015 | |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3016 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 3017 | |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 3018 | if (Arg *A = Args.getLastArg(options::OPT_pg)) |
| 3019 | if (Args.hasArg(options::OPT_fomit_frame_pointer)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3020 | D.Diag(diag::err_drv_argument_not_allowed_with) |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 3021 | << "-fomit-frame-pointer" << A->getAsString(Args); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3022 | |
Daniel Dunbar | 68fb469 | 2009-04-03 20:51:31 +0000 | [diff] [blame] | 3023 | // Claim some arguments which clang supports automatically. |
| 3024 | |
Daniel Dunbar | f404686 | 2010-04-15 06:18:42 +0000 | [diff] [blame] | 3025 | // -fpch-preprocess is used with gcc to add a special marker in the output to |
| 3026 | // include the PCH file. Clang's PTH solution is completely transparent, so we |
| 3027 | // do not need to deal with it at all. |
Daniel Dunbar | 68fb469 | 2009-04-03 20:51:31 +0000 | [diff] [blame] | 3028 | Args.ClaimAllArgs(options::OPT_fpch_preprocess); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3029 | |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 3030 | // Claim some arguments which clang doesn't support, but we don't |
| 3031 | // care to warn the user about. |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 3032 | Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group); |
| 3033 | Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group); |
Rafael Espindola | 035ff0c | 2011-02-28 23:29:45 +0000 | [diff] [blame] | 3034 | |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 3035 | // Disable warnings for clang -E -use-gold-plugin -emit-llvm foo.c |
Rafael Espindola | 035ff0c | 2011-02-28 23:29:45 +0000 | [diff] [blame] | 3036 | Args.ClaimAllArgs(options::OPT_use_gold_plugin); |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 3037 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3038 | } |
| 3039 | |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 3040 | void ClangAs::AddARMTargetArgs(const ArgList &Args, |
| 3041 | ArgStringList &CmdArgs) const { |
| 3042 | const Driver &D = getToolChain().getDriver(); |
| 3043 | llvm::Triple Triple = getToolChain().getTriple(); |
| 3044 | |
| 3045 | // Set the CPU based on -march= and -mcpu=. |
| 3046 | CmdArgs.push_back("-target-cpu"); |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 3047 | CmdArgs.push_back(Args.MakeArgString(getARMTargetCPU(Args, Triple))); |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 3048 | |
| 3049 | // Honor -mfpu=. |
Chad Rosier | 9931727 | 2012-04-04 20:51:35 +0000 | [diff] [blame] | 3050 | if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) |
Chad Rosier | f80f2a5 | 2012-04-04 20:56:36 +0000 | [diff] [blame] | 3051 | addFPUArgs(D, A, Args, CmdArgs); |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 3052 | |
| 3053 | // Honor -mfpmath=. |
| 3054 | if (const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) |
Chad Rosier | 30fe6ba | 2012-04-04 22:13:40 +0000 | [diff] [blame] | 3055 | addFPMathArgs(D, A, Args, CmdArgs, getARMTargetCPU(Args, Triple)); |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3058 | /// Add options related to the Objective-C runtime/ABI. |
| 3059 | /// |
| 3060 | /// Returns true if the runtime is non-fragile. |
| 3061 | ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args, |
| 3062 | ArgStringList &cmdArgs, |
| 3063 | RewriteKind rewriteKind) const { |
| 3064 | // Look for the controlling runtime option. |
| 3065 | Arg *runtimeArg = args.getLastArg(options::OPT_fnext_runtime, |
| 3066 | options::OPT_fgnu_runtime, |
| 3067 | options::OPT_fobjc_runtime_EQ); |
| 3068 | |
| 3069 | // Just forward -fobjc-runtime= to the frontend. This supercedes |
| 3070 | // options about fragility. |
| 3071 | if (runtimeArg && |
| 3072 | runtimeArg->getOption().matches(options::OPT_fobjc_runtime_EQ)) { |
| 3073 | ObjCRuntime runtime; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3074 | StringRef value = runtimeArg->getValue(); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3075 | if (runtime.tryParse(value)) { |
| 3076 | getToolChain().getDriver().Diag(diag::err_drv_unknown_objc_runtime) |
| 3077 | << value; |
| 3078 | } |
| 3079 | |
| 3080 | runtimeArg->render(args, cmdArgs); |
| 3081 | return runtime; |
| 3082 | } |
| 3083 | |
| 3084 | // Otherwise, we'll need the ABI "version". Version numbers are |
| 3085 | // slightly confusing for historical reasons: |
| 3086 | // 1 - Traditional "fragile" ABI |
| 3087 | // 2 - Non-fragile ABI, version 1 |
| 3088 | // 3 - Non-fragile ABI, version 2 |
| 3089 | unsigned objcABIVersion = 1; |
| 3090 | // If -fobjc-abi-version= is present, use that to set the version. |
| 3091 | if (Arg *abiArg = args.getLastArg(options::OPT_fobjc_abi_version_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3092 | StringRef value = abiArg->getValue(); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3093 | if (value == "1") |
| 3094 | objcABIVersion = 1; |
| 3095 | else if (value == "2") |
| 3096 | objcABIVersion = 2; |
| 3097 | else if (value == "3") |
| 3098 | objcABIVersion = 3; |
| 3099 | else |
| 3100 | getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported) |
| 3101 | << value; |
| 3102 | } else { |
| 3103 | // Otherwise, determine if we are using the non-fragile ABI. |
| 3104 | bool nonFragileABIIsDefault = |
| 3105 | (rewriteKind == RK_NonFragile || |
| 3106 | (rewriteKind == RK_None && |
| 3107 | getToolChain().IsObjCNonFragileABIDefault())); |
| 3108 | if (args.hasFlag(options::OPT_fobjc_nonfragile_abi, |
| 3109 | options::OPT_fno_objc_nonfragile_abi, |
| 3110 | nonFragileABIIsDefault)) { |
| 3111 | // Determine the non-fragile ABI version to use. |
| 3112 | #ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO |
| 3113 | unsigned nonFragileABIVersion = 1; |
| 3114 | #else |
| 3115 | unsigned nonFragileABIVersion = 2; |
| 3116 | #endif |
| 3117 | |
| 3118 | if (Arg *abiArg = args.getLastArg( |
| 3119 | options::OPT_fobjc_nonfragile_abi_version_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3120 | StringRef value = abiArg->getValue(); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3121 | if (value == "1") |
| 3122 | nonFragileABIVersion = 1; |
| 3123 | else if (value == "2") |
| 3124 | nonFragileABIVersion = 2; |
| 3125 | else |
| 3126 | getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported) |
| 3127 | << value; |
| 3128 | } |
| 3129 | |
| 3130 | objcABIVersion = 1 + nonFragileABIVersion; |
| 3131 | } else { |
| 3132 | objcABIVersion = 1; |
| 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | // We don't actually care about the ABI version other than whether |
| 3137 | // it's non-fragile. |
| 3138 | bool isNonFragile = objcABIVersion != 1; |
| 3139 | |
| 3140 | // If we have no runtime argument, ask the toolchain for its default runtime. |
| 3141 | // However, the rewriter only really supports the Mac runtime, so assume that. |
| 3142 | ObjCRuntime runtime; |
| 3143 | if (!runtimeArg) { |
| 3144 | switch (rewriteKind) { |
| 3145 | case RK_None: |
| 3146 | runtime = getToolChain().getDefaultObjCRuntime(isNonFragile); |
| 3147 | break; |
| 3148 | case RK_Fragile: |
| 3149 | runtime = ObjCRuntime(ObjCRuntime::FragileMacOSX, VersionTuple()); |
| 3150 | break; |
| 3151 | case RK_NonFragile: |
| 3152 | runtime = ObjCRuntime(ObjCRuntime::MacOSX, VersionTuple()); |
| 3153 | break; |
| 3154 | } |
| 3155 | |
| 3156 | // -fnext-runtime |
| 3157 | } else if (runtimeArg->getOption().matches(options::OPT_fnext_runtime)) { |
| 3158 | // On Darwin, make this use the default behavior for the toolchain. |
| 3159 | if (getToolChain().getTriple().isOSDarwin()) { |
| 3160 | runtime = getToolChain().getDefaultObjCRuntime(isNonFragile); |
| 3161 | |
| 3162 | // Otherwise, build for a generic macosx port. |
| 3163 | } else { |
| 3164 | runtime = ObjCRuntime(ObjCRuntime::MacOSX, VersionTuple()); |
| 3165 | } |
| 3166 | |
| 3167 | // -fgnu-runtime |
| 3168 | } else { |
| 3169 | assert(runtimeArg->getOption().matches(options::OPT_fgnu_runtime)); |
David Chisnall | a422cd0 | 2012-07-04 10:37:03 +0000 | [diff] [blame] | 3170 | // Legacy behaviour is to target the gnustep runtime if we are i |
| 3171 | // non-fragile mode or the GCC runtime in fragile mode. |
| 3172 | if (isNonFragile) |
David Chisnall | 891dac7 | 2012-10-16 15:11:55 +0000 | [diff] [blame] | 3173 | runtime = ObjCRuntime(ObjCRuntime::GNUstep, VersionTuple(1,6)); |
David Chisnall | a422cd0 | 2012-07-04 10:37:03 +0000 | [diff] [blame] | 3174 | else |
| 3175 | runtime = ObjCRuntime(ObjCRuntime::GCC, VersionTuple()); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | cmdArgs.push_back(args.MakeArgString( |
| 3179 | "-fobjc-runtime=" + runtime.getAsString())); |
| 3180 | return runtime; |
| 3181 | } |
| 3182 | |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3183 | void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3184 | const InputInfo &Output, |
| 3185 | const InputInfoList &Inputs, |
| 3186 | const ArgList &Args, |
| 3187 | const char *LinkingOutput) const { |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3188 | ArgStringList CmdArgs; |
| 3189 | |
| 3190 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 3191 | const InputInfo &Input = Inputs[0]; |
| 3192 | |
Rafael Espindola | dbe80d9 | 2010-11-17 22:13:25 +0000 | [diff] [blame] | 3193 | // Don't warn about "clang -w -c foo.s" |
| 3194 | Args.ClaimAllArgs(options::OPT_w); |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 3195 | // and "clang -emit-llvm -c foo.s" |
| 3196 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
| 3197 | // and "clang -use-gold-plugin -c foo.s" |
| 3198 | Args.ClaimAllArgs(options::OPT_use_gold_plugin); |
Rafael Espindola | dbe80d9 | 2010-11-17 22:13:25 +0000 | [diff] [blame] | 3199 | |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3200 | // Invoke ourselves in -cc1as mode. |
| 3201 | // |
| 3202 | // FIXME: Implement custom jobs for internal actions. |
| 3203 | CmdArgs.push_back("-cc1as"); |
| 3204 | |
| 3205 | // Add the "effective" target triple. |
| 3206 | CmdArgs.push_back("-triple"); |
Chad Rosier | 61ab80a | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 3207 | std::string TripleStr = |
| 3208 | getToolChain().ComputeEffectiveClangTriple(Args, Input.getType()); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3209 | CmdArgs.push_back(Args.MakeArgString(TripleStr)); |
| 3210 | |
| 3211 | // Set the output mode, we currently only expect to be used as a real |
| 3212 | // assembler. |
| 3213 | CmdArgs.push_back("-filetype"); |
| 3214 | CmdArgs.push_back("obj"); |
| 3215 | |
Joerg Sonnenberger | 359cf92 | 2011-05-06 14:35:16 +0000 | [diff] [blame] | 3216 | if (UseRelaxAll(C, Args)) |
Daniel Dunbar | 469d40e | 2010-05-28 16:43:21 +0000 | [diff] [blame] | 3217 | CmdArgs.push_back("-relax-all"); |
Daniel Dunbar | 9929800 | 2010-05-27 06:18:05 +0000 | [diff] [blame] | 3218 | |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 3219 | // Add target specific cpu and features flags. |
| 3220 | switch(getToolChain().getTriple().getArch()) { |
| 3221 | default: |
| 3222 | break; |
| 3223 | |
| 3224 | case llvm::Triple::arm: |
| 3225 | case llvm::Triple::thumb: |
| 3226 | AddARMTargetArgs(Args, CmdArgs); |
| 3227 | break; |
| 3228 | } |
| 3229 | |
Daniel Dunbar | 7f6f8c8 | 2011-03-17 17:37:29 +0000 | [diff] [blame] | 3230 | // Ignore explicit -force_cpusubtype_ALL option. |
| 3231 | (void) Args.hasArg(options::OPT_force__cpusubtype__ALL); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3232 | |
Eric Christopher | 8f0a403 | 2012-01-10 00:38:01 +0000 | [diff] [blame] | 3233 | // Determine the original source input. |
| 3234 | const Action *SourceAction = &JA; |
| 3235 | while (SourceAction->getKind() != Action::InputClass) { |
| 3236 | assert(!SourceAction->getInputs().empty() && "unexpected root action!"); |
| 3237 | SourceAction = SourceAction->getInputs()[0]; |
| 3238 | } |
| 3239 | |
| 3240 | // Forward -g, assuming we are dealing with an actual assembly file. |
| 3241 | if (SourceAction->getType() == types::TY_Asm || |
| 3242 | SourceAction->getType() == types::TY_PP_Asm) { |
| 3243 | Args.ClaimAllArgs(options::OPT_g_Group); |
| 3244 | if (Arg *A = Args.getLastArg(options::OPT_g_Group)) |
| 3245 | if (!A->getOption().matches(options::OPT_g0)) |
| 3246 | CmdArgs.push_back("-g"); |
| 3247 | } |
Kevin Enderby | 567003e | 2011-12-22 19:31:58 +0000 | [diff] [blame] | 3248 | |
| 3249 | // Optionally embed the -cc1as level arguments into the debug info, for build |
| 3250 | // analysis. |
| 3251 | if (getToolChain().UseDwarfDebugFlags()) { |
| 3252 | ArgStringList OriginalArgs; |
| 3253 | for (ArgList::const_iterator it = Args.begin(), |
| 3254 | ie = Args.end(); it != ie; ++it) |
| 3255 | (*it)->render(Args, OriginalArgs); |
| 3256 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3257 | SmallString<256> Flags; |
Kevin Enderby | 567003e | 2011-12-22 19:31:58 +0000 | [diff] [blame] | 3258 | const char *Exec = getToolChain().getDriver().getClangProgramPath(); |
| 3259 | Flags += Exec; |
| 3260 | for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) { |
| 3261 | Flags += " "; |
| 3262 | Flags += OriginalArgs[i]; |
| 3263 | } |
| 3264 | CmdArgs.push_back("-dwarf-debug-flags"); |
| 3265 | CmdArgs.push_back(Args.MakeArgString(Flags.str())); |
| 3266 | } |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3267 | |
| 3268 | // FIXME: Add -static support, once we have it. |
| 3269 | |
| 3270 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3271 | options::OPT_Xassembler); |
Daniel Dunbar | 3df2325 | 2011-04-29 17:53:18 +0000 | [diff] [blame] | 3272 | Args.AddAllArgs(CmdArgs, options::OPT_mllvm); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3273 | |
| 3274 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 3275 | CmdArgs.push_back("-o"); |
| 3276 | CmdArgs.push_back(Output.getFilename()); |
| 3277 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3278 | assert(Input.isFilename() && "Invalid input."); |
| 3279 | CmdArgs.push_back(Input.getFilename()); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3280 | |
Daniel Dunbar | a001c1c | 2010-07-18 21:16:15 +0000 | [diff] [blame] | 3281 | const char *Exec = getToolChain().getDriver().getClangProgramPath(); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3282 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3283 | } |
| 3284 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3285 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3286 | const InputInfo &Output, |
| 3287 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3288 | const ArgList &Args, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3289 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3290 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3291 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3292 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3293 | for (ArgList::const_iterator |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3294 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3295 | Arg *A = *it; |
Michael J. Spencer | 91e06da | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 3296 | if (forwardToGCC(A->getOption())) { |
Daniel Dunbar | 2dffe2d | 2010-08-03 16:14:14 +0000 | [diff] [blame] | 3297 | // Don't forward any -g arguments to assembly steps. |
| 3298 | if (isa<AssembleJobAction>(JA) && |
| 3299 | A->getOption().matches(options::OPT_g_Group)) |
| 3300 | continue; |
| 3301 | |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 3302 | // It is unfortunate that we have to claim here, as this means |
| 3303 | // we will basically never report anything interesting for |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 3304 | // platforms using a generic gcc, even if we are just using gcc |
| 3305 | // to get to the assembler. |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 3306 | A->claim(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3307 | A->render(Args, CmdArgs); |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 3308 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3309 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3310 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3311 | RenderExtraToolArgs(JA, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3312 | |
| 3313 | // If using a driver driver, force the arch. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3314 | llvm::Triple::ArchType Arch = getToolChain().getArch(); |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 3315 | if (getToolChain().getTriple().isOSDarwin()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3316 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | bf54a06 | 2009-04-01 20:33:11 +0000 | [diff] [blame] | 3317 | |
| 3318 | // FIXME: Remove these special cases. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3319 | if (Arch == llvm::Triple::ppc) |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 3320 | CmdArgs.push_back("ppc"); |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3321 | else if (Arch == llvm::Triple::ppc64) |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 3322 | CmdArgs.push_back("ppc64"); |
| 3323 | else |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3324 | CmdArgs.push_back(Args.MakeArgString(getToolChain().getArchName())); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 3327 | // Try to force gcc to match the tool chain we want, if we recognize |
| 3328 | // the arch. |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 3329 | // |
| 3330 | // FIXME: The triple class should directly provide the information we want |
| 3331 | // here. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3332 | if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc) |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 3333 | CmdArgs.push_back("-m32"); |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3334 | else if (Arch == llvm::Triple::x86_64 || Arch == llvm::Triple::x86_64) |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 3335 | CmdArgs.push_back("-m64"); |
| 3336 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3337 | if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3338 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3339 | CmdArgs.push_back(Output.getFilename()); |
| 3340 | } else { |
| 3341 | assert(Output.isNothing() && "Unexpected output"); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3342 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3343 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3344 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3345 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3346 | options::OPT_Xassembler); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3347 | |
| 3348 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 3349 | // understands the suffix correctly. The main use case this would go |
| 3350 | // wrong in is for linker inputs if they happened to have an odd |
| 3351 | // suffix; really the only way to get this to happen is a command |
| 3352 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 3353 | // |
| 3354 | // FIXME: For the linker case specifically, can we safely convert |
| 3355 | // inputs into '-Wl,' options? |
| 3356 | for (InputInfoList::const_iterator |
| 3357 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3358 | const InputInfo &II = *it; |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 3359 | |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 3360 | // Don't try to pass LLVM or AST inputs to a generic gcc. |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 3361 | if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR || |
| 3362 | II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3363 | D.Diag(diag::err_drv_no_linker_llvm_support) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 3364 | << getToolChain().getTripleString(); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 3365 | else if (II.getType() == types::TY_AST) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3366 | D.Diag(diag::err_drv_no_ast_support) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 3367 | << getToolChain().getTripleString(); |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 3368 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3369 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 3370 | CmdArgs.push_back("-x"); |
| 3371 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 3372 | } |
| 3373 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3374 | if (II.isFilename()) |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3375 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 48f9994 | 2010-09-25 18:10:05 +0000 | [diff] [blame] | 3376 | else { |
| 3377 | const Arg &A = II.getInputArg(); |
| 3378 | |
| 3379 | // Reverse translate some rewritten options. |
| 3380 | if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) { |
| 3381 | CmdArgs.push_back("-lstdc++"); |
| 3382 | continue; |
| 3383 | } |
| 3384 | |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3385 | // Don't render as input, we need gcc to do the translations. |
Daniel Dunbar | 48f9994 | 2010-09-25 18:10:05 +0000 | [diff] [blame] | 3386 | A.render(Args, CmdArgs); |
| 3387 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
Dylan Noblesmith | b8a3e81 | 2011-04-09 13:31:59 +0000 | [diff] [blame] | 3390 | const std::string customGCCName = D.getCCCGenericGCCName(); |
| 3391 | const char *GCCName; |
| 3392 | if (!customGCCName.empty()) |
| 3393 | GCCName = customGCCName.c_str(); |
| 3394 | else if (D.CCCIsCXX) { |
Dylan Noblesmith | b8a3e81 | 2011-04-09 13:31:59 +0000 | [diff] [blame] | 3395 | GCCName = "g++"; |
Dylan Noblesmith | b8a3e81 | 2011-04-09 13:31:59 +0000 | [diff] [blame] | 3396 | } else |
| 3397 | GCCName = "gcc"; |
| 3398 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3399 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3400 | Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3401 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3402 | } |
| 3403 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3404 | void gcc::Preprocess::RenderExtraToolArgs(const JobAction &JA, |
| 3405 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3406 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3409 | void gcc::Precompile::RenderExtraToolArgs(const JobAction &JA, |
| 3410 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3411 | // The type is good enough. |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3412 | } |
| 3413 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3414 | void gcc::Compile::RenderExtraToolArgs(const JobAction &JA, |
| 3415 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 3416 | const Driver &D = getToolChain().getDriver(); |
| 3417 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3418 | // If -flto, etc. are present then make sure not to force assembly output. |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 3419 | if (JA.getType() == types::TY_LLVM_IR || JA.getType() == types::TY_LTO_IR || |
| 3420 | JA.getType() == types::TY_LLVM_BC || JA.getType() == types::TY_LTO_BC) |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3421 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 3422 | else { |
| 3423 | if (JA.getType() != types::TY_PP_Asm) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3424 | D.Diag(diag::err_drv_invalid_gcc_output_type) |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 3425 | << getTypeName(JA.getType()); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3426 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3427 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 3428 | } |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3429 | } |
| 3430 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3431 | void gcc::Assemble::RenderExtraToolArgs(const JobAction &JA, |
| 3432 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3433 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3434 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3435 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3436 | void gcc::Link::RenderExtraToolArgs(const JobAction &JA, |
| 3437 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3438 | // The types are (hopefully) good enough. |
| 3439 | } |
| 3440 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3441 | // Hexagon tools start. |
| 3442 | void hexagon::Assemble::RenderExtraToolArgs(const JobAction &JA, |
| 3443 | ArgStringList &CmdArgs) const { |
| 3444 | |
| 3445 | } |
| 3446 | void hexagon::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 3447 | const InputInfo &Output, |
| 3448 | const InputInfoList &Inputs, |
| 3449 | const ArgList &Args, |
| 3450 | const char *LinkingOutput) const { |
| 3451 | |
| 3452 | const Driver &D = getToolChain().getDriver(); |
| 3453 | ArgStringList CmdArgs; |
| 3454 | |
| 3455 | std::string MarchString = "-march="; |
| 3456 | MarchString += getHexagonTargetCPU(Args); |
| 3457 | CmdArgs.push_back(Args.MakeArgString(MarchString)); |
| 3458 | |
| 3459 | RenderExtraToolArgs(JA, CmdArgs); |
| 3460 | |
| 3461 | if (Output.isFilename()) { |
| 3462 | CmdArgs.push_back("-o"); |
| 3463 | CmdArgs.push_back(Output.getFilename()); |
| 3464 | } else { |
| 3465 | assert(Output.isNothing() && "Unexpected output"); |
| 3466 | CmdArgs.push_back("-fsyntax-only"); |
| 3467 | } |
| 3468 | |
| 3469 | |
| 3470 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 3471 | // understands the suffix correctly. The main use case this would go |
| 3472 | // wrong in is for linker inputs if they happened to have an odd |
| 3473 | // suffix; really the only way to get this to happen is a command |
| 3474 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 3475 | // |
| 3476 | // FIXME: For the linker case specifically, can we safely convert |
| 3477 | // inputs into '-Wl,' options? |
| 3478 | for (InputInfoList::const_iterator |
| 3479 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3480 | const InputInfo &II = *it; |
| 3481 | |
| 3482 | // Don't try to pass LLVM or AST inputs to a generic gcc. |
| 3483 | if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR || |
| 3484 | II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC) |
| 3485 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
| 3486 | << getToolChain().getTripleString(); |
| 3487 | else if (II.getType() == types::TY_AST) |
| 3488 | D.Diag(clang::diag::err_drv_no_ast_support) |
| 3489 | << getToolChain().getTripleString(); |
| 3490 | |
| 3491 | if (II.isFilename()) |
| 3492 | CmdArgs.push_back(II.getFilename()); |
| 3493 | else |
| 3494 | // Don't render as input, we need gcc to do the translations. FIXME: Pranav: What is this ? |
| 3495 | II.getInputArg().render(Args, CmdArgs); |
| 3496 | } |
| 3497 | |
| 3498 | const char *GCCName = "hexagon-as"; |
| 3499 | const char *Exec = |
| 3500 | Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); |
| 3501 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 3502 | |
| 3503 | } |
| 3504 | void hexagon::Link::RenderExtraToolArgs(const JobAction &JA, |
| 3505 | ArgStringList &CmdArgs) const { |
| 3506 | // The types are (hopefully) good enough. |
| 3507 | } |
| 3508 | |
| 3509 | void hexagon::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 3510 | const InputInfo &Output, |
| 3511 | const InputInfoList &Inputs, |
| 3512 | const ArgList &Args, |
| 3513 | const char *LinkingOutput) const { |
| 3514 | |
| 3515 | const Driver &D = getToolChain().getDriver(); |
| 3516 | ArgStringList CmdArgs; |
| 3517 | |
| 3518 | for (ArgList::const_iterator |
| 3519 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 3520 | Arg *A = *it; |
Michael J. Spencer | 91e06da | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 3521 | if (forwardToGCC(A->getOption())) { |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3522 | // Don't forward any -g arguments to assembly steps. |
| 3523 | if (isa<AssembleJobAction>(JA) && |
| 3524 | A->getOption().matches(options::OPT_g_Group)) |
| 3525 | continue; |
| 3526 | |
| 3527 | // It is unfortunate that we have to claim here, as this means |
| 3528 | // we will basically never report anything interesting for |
| 3529 | // platforms using a generic gcc, even if we are just using gcc |
| 3530 | // to get to the assembler. |
| 3531 | A->claim(); |
| 3532 | A->render(Args, CmdArgs); |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | RenderExtraToolArgs(JA, CmdArgs); |
| 3537 | |
| 3538 | // Add Arch Information |
| 3539 | Arg *A; |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 3540 | if ((A = getLastHexagonArchArg(Args))) { |
| 3541 | if (A->getOption().matches(options::OPT_m_Joined)) |
| 3542 | A->render(Args, CmdArgs); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3543 | else |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 3544 | CmdArgs.push_back (Args.MakeArgString("-m" + getHexagonTargetCPU(Args))); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3545 | } |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 3546 | else { |
| 3547 | CmdArgs.push_back (Args.MakeArgString("-m" + getHexagonTargetCPU(Args))); |
| 3548 | } |
| 3549 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3550 | CmdArgs.push_back("-mqdsp6-compat"); |
| 3551 | |
| 3552 | const char *GCCName; |
| 3553 | if (C.getDriver().CCCIsCXX) |
| 3554 | GCCName = "hexagon-g++"; |
| 3555 | else |
| 3556 | GCCName = "hexagon-gcc"; |
| 3557 | const char *Exec = |
| 3558 | Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); |
| 3559 | |
| 3560 | if (Output.isFilename()) { |
| 3561 | CmdArgs.push_back("-o"); |
| 3562 | CmdArgs.push_back(Output.getFilename()); |
| 3563 | } |
| 3564 | |
| 3565 | for (InputInfoList::const_iterator |
| 3566 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3567 | const InputInfo &II = *it; |
| 3568 | |
| 3569 | // Don't try to pass LLVM or AST inputs to a generic gcc. |
| 3570 | if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR || |
| 3571 | II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC) |
| 3572 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
| 3573 | << getToolChain().getTripleString(); |
| 3574 | else if (II.getType() == types::TY_AST) |
| 3575 | D.Diag(clang::diag::err_drv_no_ast_support) |
| 3576 | << getToolChain().getTripleString(); |
| 3577 | |
| 3578 | if (II.isFilename()) |
| 3579 | CmdArgs.push_back(II.getFilename()); |
| 3580 | else |
| 3581 | // Don't render as input, we need gcc to do the translations. FIXME: Pranav: What is this ? |
| 3582 | II.getInputArg().render(Args, CmdArgs); |
| 3583 | } |
| 3584 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 3585 | |
| 3586 | } |
| 3587 | // Hexagon tools end. |
| 3588 | |
Rafael Espindola | cfed828 | 2012-10-31 18:51:07 +0000 | [diff] [blame] | 3589 | llvm::Triple::ArchType darwin::getArchTypeForDarwinArchName(StringRef Str) { |
| 3590 | // See arch(3) and llvm-gcc's driver-driver.c. We don't implement support for |
| 3591 | // archs which Darwin doesn't use. |
| 3592 | |
| 3593 | // The matching this routine does is fairly pointless, since it is neither the |
| 3594 | // complete architecture list, nor a reasonable subset. The problem is that |
| 3595 | // historically the driver driver accepts this and also ties its -march= |
| 3596 | // handling to the architecture name, so we need to be careful before removing |
| 3597 | // support for it. |
| 3598 | |
| 3599 | // This code must be kept in sync with Clang's Darwin specific argument |
| 3600 | // translation. |
| 3601 | |
| 3602 | return llvm::StringSwitch<llvm::Triple::ArchType>(Str) |
| 3603 | .Cases("ppc", "ppc601", "ppc603", "ppc604", "ppc604e", llvm::Triple::ppc) |
| 3604 | .Cases("ppc750", "ppc7400", "ppc7450", "ppc970", llvm::Triple::ppc) |
| 3605 | .Case("ppc64", llvm::Triple::ppc64) |
| 3606 | .Cases("i386", "i486", "i486SX", "i586", "i686", llvm::Triple::x86) |
| 3607 | .Cases("pentium", "pentpro", "pentIIm3", "pentIIm5", "pentium4", |
| 3608 | llvm::Triple::x86) |
| 3609 | .Case("x86_64", llvm::Triple::x86_64) |
| 3610 | // This is derived from the driver driver. |
| 3611 | .Cases("arm", "armv4t", "armv5", "armv6", llvm::Triple::arm) |
| 3612 | .Cases("armv7", "armv7f", "armv7k", "armv7s", "xscale", llvm::Triple::arm) |
| 3613 | .Case("r600", llvm::Triple::r600) |
| 3614 | .Case("nvptx", llvm::Triple::nvptx) |
| 3615 | .Case("nvptx64", llvm::Triple::nvptx64) |
| 3616 | .Case("amdil", llvm::Triple::amdil) |
| 3617 | .Case("spir", llvm::Triple::spir) |
| 3618 | .Default(llvm::Triple::UnknownArch); |
| 3619 | } |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3620 | |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 3621 | const char *Clang::getBaseInputName(const ArgList &Args, |
| 3622 | const InputInfoList &Inputs) { |
Michael J. Spencer | 472ccff | 2010-12-18 00:19:12 +0000 | [diff] [blame] | 3623 | return Args.MakeArgString( |
| 3624 | llvm::sys::path::filename(Inputs[0].getBaseInput())); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3625 | } |
| 3626 | |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 3627 | const char *Clang::getBaseInputStem(const ArgList &Args, |
| 3628 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3629 | const char *Str = getBaseInputName(Args, Inputs); |
| 3630 | |
Chris Lattner | 657ca66 | 2011-01-16 08:14:11 +0000 | [diff] [blame] | 3631 | if (const char *End = strrchr(Str, '.')) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 3632 | return Args.MakeArgString(std::string(Str, End)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3633 | |
| 3634 | return Str; |
| 3635 | } |
| 3636 | |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 3637 | const char *Clang::getDependencyFileName(const ArgList &Args, |
| 3638 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3639 | // FIXME: Think about this more. |
| 3640 | std::string Res; |
| 3641 | |
| 3642 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3643 | std::string Str(OutputOpt->getValue()); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3644 | Res = Str.substr(0, Str.rfind('.')); |
Chad Rosier | 3060178 | 2011-08-17 23:08:45 +0000 | [diff] [blame] | 3645 | } else { |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 3646 | Res = getBaseInputStem(Args, Inputs); |
Chad Rosier | 3060178 | 2011-08-17 23:08:45 +0000 | [diff] [blame] | 3647 | } |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 3648 | return Args.MakeArgString(Res + ".d"); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3649 | } |
| 3650 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3651 | void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3652 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3653 | const InputInfoList &Inputs, |
| 3654 | const ArgList &Args, |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3655 | const char *LinkingOutput) const { |
| 3656 | ArgStringList CmdArgs; |
| 3657 | |
| 3658 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 3659 | const InputInfo &Input = Inputs[0]; |
| 3660 | |
Daniel Dunbar | 34bac1f | 2011-04-12 23:59:20 +0000 | [diff] [blame] | 3661 | // Determine the original source input. |
| 3662 | const Action *SourceAction = &JA; |
| 3663 | while (SourceAction->getKind() != Action::InputClass) { |
| 3664 | assert(!SourceAction->getInputs().empty() && "unexpected root action!"); |
| 3665 | SourceAction = SourceAction->getInputs()[0]; |
| 3666 | } |
| 3667 | |
| 3668 | // Forward -g, assuming we are dealing with an actual assembly file. |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 3669 | if (SourceAction->getType() == types::TY_Asm || |
Daniel Dunbar | 34bac1f | 2011-04-12 23:59:20 +0000 | [diff] [blame] | 3670 | SourceAction->getType() == types::TY_PP_Asm) { |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 3671 | if (Args.hasArg(options::OPT_gstabs)) |
| 3672 | CmdArgs.push_back("--gstabs"); |
| 3673 | else if (Args.hasArg(options::OPT_g_Group)) |
Bob Wilson | 591ff15 | 2011-11-02 05:10:45 +0000 | [diff] [blame] | 3674 | CmdArgs.push_back("-g"); |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 3675 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3676 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3677 | // Derived from asm spec. |
Daniel Dunbar | cc6f803 | 2009-09-09 18:36:27 +0000 | [diff] [blame] | 3678 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3679 | |
Daniel Dunbar | f5438e3 | 2010-07-22 01:47:22 +0000 | [diff] [blame] | 3680 | // Use -force_cpusubtype_ALL on x86 by default. |
| 3681 | if (getToolChain().getTriple().getArch() == llvm::Triple::x86 || |
| 3682 | getToolChain().getTriple().getArch() == llvm::Triple::x86_64 || |
Daniel Dunbar | cc6f803 | 2009-09-09 18:36:27 +0000 | [diff] [blame] | 3683 | Args.hasArg(options::OPT_force__cpusubtype__ALL)) |
| 3684 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 3685 | |
Daniel Dunbar | 0e2679d | 2009-08-24 22:26:16 +0000 | [diff] [blame] | 3686 | if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64 && |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 3687 | (((Args.hasArg(options::OPT_mkernel) || |
| 3688 | Args.hasArg(options::OPT_fapple_kext)) && |
| 3689 | (!getDarwinToolChain().isTargetIPhoneOS() || |
| 3690 | getDarwinToolChain().isIPhoneOSVersionLT(6, 0))) || |
| 3691 | Args.hasArg(options::OPT_static))) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3692 | CmdArgs.push_back("-static"); |
| 3693 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3694 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3695 | options::OPT_Xassembler); |
| 3696 | |
| 3697 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 3698 | CmdArgs.push_back("-o"); |
| 3699 | CmdArgs.push_back(Output.getFilename()); |
| 3700 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3701 | assert(Input.isFilename() && "Invalid input."); |
| 3702 | CmdArgs.push_back(Input.getFilename()); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3703 | |
| 3704 | // asm_final spec is empty. |
| 3705 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3706 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3707 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3708 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3709 | } |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 3710 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 3711 | void darwin::DarwinTool::anchor() {} |
| 3712 | |
Daniel Dunbar | fbefe6b | 2009-09-09 18:36:20 +0000 | [diff] [blame] | 3713 | void darwin::DarwinTool::AddDarwinArch(const ArgList &Args, |
| 3714 | ArgStringList &CmdArgs) const { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3715 | StringRef ArchName = getDarwinToolChain().getDarwinArchName(Args); |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 3716 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3717 | // Derived from darwin_arch spec. |
| 3718 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 3719 | CmdArgs.push_back(Args.MakeArgString(ArchName)); |
Daniel Dunbar | 78dbd58 | 2009-09-04 18:35:31 +0000 | [diff] [blame] | 3720 | |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 3721 | // FIXME: Is this needed anymore? |
| 3722 | if (ArchName == "arm") |
Daniel Dunbar | 78dbd58 | 2009-09-04 18:35:31 +0000 | [diff] [blame] | 3723 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3724 | } |
| 3725 | |
Bill Wendling | 6acf8b4 | 2012-10-02 18:02:50 +0000 | [diff] [blame] | 3726 | bool darwin::Link::NeedsTempPath(const InputInfoList &Inputs) const { |
| 3727 | // We only need to generate a temp path for LTO if we aren't compiling object |
| 3728 | // files. When compiling source files, we run 'dsymutil' after linking. We |
| 3729 | // don't run 'dsymutil' when compiling object files. |
| 3730 | for (InputInfoList::const_iterator |
| 3731 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) |
| 3732 | if (it->getType() != types::TY_Object) |
| 3733 | return true; |
| 3734 | |
| 3735 | return false; |
| 3736 | } |
| 3737 | |
Daniel Dunbar | 748de8e | 2010-09-09 21:51:05 +0000 | [diff] [blame] | 3738 | void darwin::Link::AddLinkArgs(Compilation &C, |
| 3739 | const ArgList &Args, |
Bill Wendling | 6acf8b4 | 2012-10-02 18:02:50 +0000 | [diff] [blame] | 3740 | ArgStringList &CmdArgs, |
| 3741 | const InputInfoList &Inputs) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3742 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | ce911f5 | 2011-04-28 21:23:41 +0000 | [diff] [blame] | 3743 | const toolchains::Darwin &DarwinTC = getDarwinToolChain(); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3744 | |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 3745 | unsigned Version[3] = { 0, 0, 0 }; |
| 3746 | if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { |
| 3747 | bool HadExtra; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3748 | if (!Driver::GetReleaseVersion(A->getValue(), Version[0], |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 3749 | Version[1], Version[2], HadExtra) || |
| 3750 | HadExtra) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3751 | D.Diag(diag::err_drv_invalid_version_number) |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 3752 | << A->getAsString(Args); |
| 3753 | } |
| 3754 | |
| 3755 | // Newer linkers support -demangle, pass it if supported and not disabled by |
| 3756 | // the user. |
Daniel Dunbar | d2d2088 | 2012-01-04 21:45:27 +0000 | [diff] [blame] | 3757 | if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) { |
Daniel Dunbar | bcf1da8 | 2010-09-07 17:07:49 +0000 | [diff] [blame] | 3758 | // Don't pass -demangle to ld_classic. |
| 3759 | // |
| 3760 | // FIXME: This is a temporary workaround, ld should be handling this. |
| 3761 | bool UsesLdClassic = (getToolChain().getArch() == llvm::Triple::x86 && |
| 3762 | Args.hasArg(options::OPT_static)); |
Daniel Dunbar | 9ced704 | 2010-09-07 17:50:41 +0000 | [diff] [blame] | 3763 | if (getToolChain().getArch() == llvm::Triple::x86) { |
| 3764 | for (arg_iterator it = Args.filtered_begin(options::OPT_Xlinker, |
| 3765 | options::OPT_Wl_COMMA), |
| 3766 | ie = Args.filtered_end(); it != ie; ++it) { |
| 3767 | const Arg *A = *it; |
| 3768 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3769 | if (StringRef(A->getValue(i)) == "-kext") |
Daniel Dunbar | 9ced704 | 2010-09-07 17:50:41 +0000 | [diff] [blame] | 3770 | UsesLdClassic = true; |
| 3771 | } |
| 3772 | } |
Daniel Dunbar | bcf1da8 | 2010-09-07 17:07:49 +0000 | [diff] [blame] | 3773 | if (!UsesLdClassic) |
| 3774 | CmdArgs.push_back("-demangle"); |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 3775 | } |
| 3776 | |
Bill Wendling | c35f908 | 2012-11-16 23:03:00 +0000 | [diff] [blame] | 3777 | // If we are using LTO, then automatically create a temporary file path for |
| 3778 | // the linker to use, so that it's lifetime will extend past a possible |
| 3779 | // dsymutil step. |
| 3780 | if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) { |
| 3781 | const char *TmpPath = C.getArgs().MakeArgString( |
| 3782 | D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object))); |
| 3783 | C.addTempFile(TmpPath); |
| 3784 | CmdArgs.push_back("-object_path_lto"); |
| 3785 | CmdArgs.push_back(TmpPath); |
Daniel Dunbar | 5bfa656 | 2011-06-21 20:55:11 +0000 | [diff] [blame] | 3786 | } |
| 3787 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3788 | // Derived from the "link" spec. |
| 3789 | Args.AddAllArgs(CmdArgs, options::OPT_static); |
| 3790 | if (!Args.hasArg(options::OPT_static)) |
| 3791 | CmdArgs.push_back("-dynamic"); |
| 3792 | if (Args.hasArg(options::OPT_fgnu_runtime)) { |
| 3793 | // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu |
| 3794 | // here. How do we wish to handle such things? |
| 3795 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3796 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3797 | if (!Args.hasArg(options::OPT_dynamiclib)) { |
Daniel Dunbar | a6d3849 | 2010-01-22 02:04:52 +0000 | [diff] [blame] | 3798 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | a6d3849 | 2010-01-22 02:04:52 +0000 | [diff] [blame] | 3799 | // FIXME: Why do this only on this path? |
Daniel Dunbar | 8917dd4 | 2010-01-22 03:37:33 +0000 | [diff] [blame] | 3800 | Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3801 | |
| 3802 | Args.AddLastArg(CmdArgs, options::OPT_bundle); |
| 3803 | Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader); |
| 3804 | Args.AddAllArgs(CmdArgs, options::OPT_client__name); |
| 3805 | |
| 3806 | Arg *A; |
| 3807 | if ((A = Args.getLastArg(options::OPT_compatibility__version)) || |
| 3808 | (A = Args.getLastArg(options::OPT_current__version)) || |
| 3809 | (A = Args.getLastArg(options::OPT_install__name))) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3810 | D.Diag(diag::err_drv_argument_only_allowed_with) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3811 | << A->getAsString(Args) << "-dynamiclib"; |
| 3812 | |
| 3813 | Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace); |
| 3814 | Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs); |
| 3815 | Args.AddLastArg(CmdArgs, options::OPT_private__bundle); |
| 3816 | } else { |
| 3817 | CmdArgs.push_back("-dylib"); |
| 3818 | |
| 3819 | Arg *A; |
| 3820 | if ((A = Args.getLastArg(options::OPT_bundle)) || |
| 3821 | (A = Args.getLastArg(options::OPT_bundle__loader)) || |
| 3822 | (A = Args.getLastArg(options::OPT_client__name)) || |
| 3823 | (A = Args.getLastArg(options::OPT_force__flat__namespace)) || |
| 3824 | (A = Args.getLastArg(options::OPT_keep__private__externs)) || |
| 3825 | (A = Args.getLastArg(options::OPT_private__bundle))) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3826 | D.Diag(diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3827 | << A->getAsString(Args) << "-dynamiclib"; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3828 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3829 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version, |
| 3830 | "-dylib_compatibility_version"); |
| 3831 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version, |
| 3832 | "-dylib_current_version"); |
| 3833 | |
Daniel Dunbar | a6d3849 | 2010-01-22 02:04:52 +0000 | [diff] [blame] | 3834 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3835 | |
| 3836 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name, |
| 3837 | "-dylib_install_name"); |
| 3838 | } |
| 3839 | |
| 3840 | Args.AddLastArg(CmdArgs, options::OPT_all__load); |
| 3841 | Args.AddAllArgs(CmdArgs, options::OPT_allowable__client); |
| 3842 | Args.AddLastArg(CmdArgs, options::OPT_bind__at__load); |
Daniel Dunbar | ce911f5 | 2011-04-28 21:23:41 +0000 | [diff] [blame] | 3843 | if (DarwinTC.isTargetIPhoneOS()) |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 3844 | Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3845 | Args.AddLastArg(CmdArgs, options::OPT_dead__strip); |
| 3846 | Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms); |
| 3847 | Args.AddAllArgs(CmdArgs, options::OPT_dylib__file); |
| 3848 | Args.AddLastArg(CmdArgs, options::OPT_dynamic); |
| 3849 | Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list); |
| 3850 | Args.AddLastArg(CmdArgs, options::OPT_flat__namespace); |
Daniel Dunbar | 99ca47b | 2011-06-28 20:16:02 +0000 | [diff] [blame] | 3851 | Args.AddAllArgs(CmdArgs, options::OPT_force__load); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3852 | Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names); |
| 3853 | Args.AddAllArgs(CmdArgs, options::OPT_image__base); |
| 3854 | Args.AddAllArgs(CmdArgs, options::OPT_init); |
| 3855 | |
Daniel Dunbar | ce911f5 | 2011-04-28 21:23:41 +0000 | [diff] [blame] | 3856 | // Add the deployment target. |
Benjamin Kramer | 09c9a56 | 2012-03-10 20:55:36 +0000 | [diff] [blame] | 3857 | VersionTuple TargetVersion = DarwinTC.getTargetVersion(); |
Daniel Dunbar | b7f5ef7 | 2011-04-30 04:22:58 +0000 | [diff] [blame] | 3858 | |
| 3859 | // If we had an explicit -mios-simulator-version-min argument, honor that, |
| 3860 | // otherwise use the traditional deployment targets. We can't just check the |
| 3861 | // is-sim attribute because existing code follows this path, and the linker |
| 3862 | // may not handle the argument. |
| 3863 | // |
| 3864 | // FIXME: We may be able to remove this, once we can verify no one depends on |
| 3865 | // it. |
| 3866 | if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ)) |
| 3867 | CmdArgs.push_back("-ios_simulator_version_min"); |
| 3868 | else if (DarwinTC.isTargetIPhoneOS()) |
| 3869 | CmdArgs.push_back("-iphoneos_version_min"); |
| 3870 | else |
| 3871 | CmdArgs.push_back("-macosx_version_min"); |
Benjamin Kramer | 09c9a56 | 2012-03-10 20:55:36 +0000 | [diff] [blame] | 3872 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); |
Daniel Dunbar | ce911f5 | 2011-04-28 21:23:41 +0000 | [diff] [blame] | 3873 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3874 | Args.AddLastArg(CmdArgs, options::OPT_nomultidefs); |
| 3875 | Args.AddLastArg(CmdArgs, options::OPT_multi__module); |
| 3876 | Args.AddLastArg(CmdArgs, options::OPT_single__module); |
| 3877 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined); |
| 3878 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3879 | |
Daniel Dunbar | 47e879d | 2010-07-13 23:31:40 +0000 | [diff] [blame] | 3880 | if (const Arg *A = Args.getLastArg(options::OPT_fpie, options::OPT_fPIE, |
| 3881 | options::OPT_fno_pie, |
| 3882 | options::OPT_fno_PIE)) { |
| 3883 | if (A->getOption().matches(options::OPT_fpie) || |
| 3884 | A->getOption().matches(options::OPT_fPIE)) |
| 3885 | CmdArgs.push_back("-pie"); |
| 3886 | else |
| 3887 | CmdArgs.push_back("-no_pie"); |
| 3888 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3889 | |
| 3890 | Args.AddLastArg(CmdArgs, options::OPT_prebind); |
| 3891 | Args.AddLastArg(CmdArgs, options::OPT_noprebind); |
| 3892 | Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding); |
| 3893 | Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules); |
| 3894 | Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs); |
| 3895 | Args.AddAllArgs(CmdArgs, options::OPT_sectcreate); |
| 3896 | Args.AddAllArgs(CmdArgs, options::OPT_sectorder); |
| 3897 | Args.AddAllArgs(CmdArgs, options::OPT_seg1addr); |
| 3898 | Args.AddAllArgs(CmdArgs, options::OPT_segprot); |
| 3899 | Args.AddAllArgs(CmdArgs, options::OPT_segaddr); |
| 3900 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr); |
| 3901 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr); |
| 3902 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table); |
| 3903 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename); |
| 3904 | Args.AddAllArgs(CmdArgs, options::OPT_sub__library); |
| 3905 | Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 3906 | |
Daniel Dunbar | cc95719 | 2011-05-02 21:03:47 +0000 | [diff] [blame] | 3907 | // Give --sysroot= preference, over the Apple specific behavior to also use |
| 3908 | // --isysroot as the syslibroot. |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 3909 | StringRef sysroot = C.getSysRoot(); |
| 3910 | if (sysroot != "") { |
Daniel Dunbar | cc95719 | 2011-05-02 21:03:47 +0000 | [diff] [blame] | 3911 | CmdArgs.push_back("-syslibroot"); |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 3912 | CmdArgs.push_back(C.getArgs().MakeArgString(sysroot)); |
Daniel Dunbar | cc95719 | 2011-05-02 21:03:47 +0000 | [diff] [blame] | 3913 | } else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 3914 | CmdArgs.push_back("-syslibroot"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3915 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 3916 | } |
| 3917 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3918 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace); |
| 3919 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints); |
| 3920 | Args.AddAllArgs(CmdArgs, options::OPT_umbrella); |
| 3921 | Args.AddAllArgs(CmdArgs, options::OPT_undefined); |
| 3922 | Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 3923 | Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3924 | Args.AddLastArg(CmdArgs, options::OPT_X_Flag); |
| 3925 | Args.AddAllArgs(CmdArgs, options::OPT_y); |
| 3926 | Args.AddLastArg(CmdArgs, options::OPT_w); |
| 3927 | Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size); |
| 3928 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__); |
| 3929 | Args.AddLastArg(CmdArgs, options::OPT_seglinkedit); |
| 3930 | Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit); |
| 3931 | Args.AddAllArgs(CmdArgs, options::OPT_sectalign); |
| 3932 | Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols); |
| 3933 | Args.AddAllArgs(CmdArgs, options::OPT_segcreate); |
| 3934 | Args.AddLastArg(CmdArgs, options::OPT_whyload); |
| 3935 | Args.AddLastArg(CmdArgs, options::OPT_whatsloaded); |
| 3936 | Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name); |
| 3937 | Args.AddLastArg(CmdArgs, options::OPT_dylinker); |
| 3938 | Args.AddLastArg(CmdArgs, options::OPT_Mach); |
| 3939 | } |
| 3940 | |
| 3941 | void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3942 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3943 | const InputInfoList &Inputs, |
| 3944 | const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3945 | const char *LinkingOutput) const { |
| 3946 | assert(Output.getType() == types::TY_Image && "Invalid linker output type."); |
Daniel Dunbar | e0be8b1 | 2009-09-08 16:39:16 +0000 | [diff] [blame] | 3947 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3948 | // The logic here is derived from gcc's behavior; most of which |
| 3949 | // comes from specs (starting with link_command). Consult gcc for |
| 3950 | // more information. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3951 | ArgStringList CmdArgs; |
| 3952 | |
Argyrios Kyrtzidis | 2289717 | 2011-10-07 22:58:08 +0000 | [diff] [blame] | 3953 | /// Hack(tm) to ignore linking errors when we are doing ARC migration. |
| 3954 | if (Args.hasArg(options::OPT_ccc_arcmt_check, |
| 3955 | options::OPT_ccc_arcmt_migrate)) { |
| 3956 | for (ArgList::const_iterator I = Args.begin(), E = Args.end(); I != E; ++I) |
| 3957 | (*I)->claim(); |
| 3958 | const char *Exec = |
| 3959 | Args.MakeArgString(getToolChain().GetProgramPath("touch")); |
| 3960 | CmdArgs.push_back(Output.getFilename()); |
| 3961 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 3962 | return; |
| 3963 | } |
| 3964 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3965 | // I'm not sure why this particular decomposition exists in gcc, but |
| 3966 | // we follow suite for ease of comparison. |
Bill Wendling | 6acf8b4 | 2012-10-02 18:02:50 +0000 | [diff] [blame] | 3967 | AddLinkArgs(C, Args, CmdArgs, Inputs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3968 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3969 | Args.AddAllArgs(CmdArgs, options::OPT_d_Flag); |
| 3970 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 3971 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 3972 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 3973 | Args.AddAllArgs(CmdArgs, options::OPT_u_Group); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3974 | Args.AddLastArg(CmdArgs, options::OPT_e); |
| 3975 | Args.AddAllArgs(CmdArgs, options::OPT_m_Separate); |
| 3976 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
| 3977 | |
Daniel Dunbar | 270073c | 2010-10-18 22:08:36 +0000 | [diff] [blame] | 3978 | // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading |
| 3979 | // members of static archive libraries which implement Objective-C classes or |
| 3980 | // categories. |
| 3981 | if (Args.hasArg(options::OPT_ObjC) || Args.hasArg(options::OPT_ObjCXX)) |
| 3982 | CmdArgs.push_back("-ObjC"); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3983 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3984 | CmdArgs.push_back("-o"); |
| 3985 | CmdArgs.push_back(Output.getFilename()); |
| 3986 | |
Chad Rosier | 1893731 | 2012-05-16 23:45:12 +0000 | [diff] [blame] | 3987 | if (!Args.hasArg(options::OPT_nostdlib) && |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3988 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3989 | // Derived from startfile spec. |
| 3990 | if (Args.hasArg(options::OPT_dynamiclib)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3991 | // Derived from darwin_dylib1 spec. |
Daniel Dunbar | 1051fc0 | 2011-04-01 21:02:42 +0000 | [diff] [blame] | 3992 | if (getDarwinToolChain().isTargetIOSSimulator()) { |
| 3993 | // The simulator doesn't have a versioned crt1 file. |
| 3994 | CmdArgs.push_back("-ldylib1.o"); |
| 3995 | } else if (getDarwinToolChain().isTargetIPhoneOS()) { |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 3996 | if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1)) |
| 3997 | CmdArgs.push_back("-ldylib1.o"); |
| 3998 | } else { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 3999 | if (getDarwinToolChain().isMacosxVersionLT(10, 5)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4000 | CmdArgs.push_back("-ldylib1.o"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4001 | else if (getDarwinToolChain().isMacosxVersionLT(10, 6)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4002 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 4003 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4004 | } else { |
| 4005 | if (Args.hasArg(options::OPT_bundle)) { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 4006 | if (!Args.hasArg(options::OPT_static)) { |
| 4007 | // Derived from darwin_bundle1 spec. |
Daniel Dunbar | 1051fc0 | 2011-04-01 21:02:42 +0000 | [diff] [blame] | 4008 | if (getDarwinToolChain().isTargetIOSSimulator()) { |
| 4009 | // The simulator doesn't have a versioned crt1 file. |
| 4010 | CmdArgs.push_back("-lbundle1.o"); |
| 4011 | } else if (getDarwinToolChain().isTargetIPhoneOS()) { |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4012 | if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1)) |
| 4013 | CmdArgs.push_back("-lbundle1.o"); |
| 4014 | } else { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4015 | if (getDarwinToolChain().isMacosxVersionLT(10, 6)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4016 | CmdArgs.push_back("-lbundle1.o"); |
| 4017 | } |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 4018 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4019 | } else { |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 4020 | if (Args.hasArg(options::OPT_pg) && |
| 4021 | getToolChain().SupportsProfiling()) { |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4022 | if (Args.hasArg(options::OPT_static) || |
| 4023 | Args.hasArg(options::OPT_object) || |
| 4024 | Args.hasArg(options::OPT_preload)) { |
| 4025 | CmdArgs.push_back("-lgcrt0.o"); |
| 4026 | } else { |
| 4027 | CmdArgs.push_back("-lgcrt1.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4028 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4029 | // darwin_crt2 spec is empty. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4030 | } |
Bob Wilson | 4e6e791 | 2012-07-04 00:18:41 +0000 | [diff] [blame] | 4031 | // By default on OS X 10.8 and later, we don't link with a crt1.o |
| 4032 | // file and the linker knows to use _main as the entry point. But, |
| 4033 | // when compiling with -pg, we need to link with the gcrt1.o file, |
| 4034 | // so pass the -no_new_main option to tell the linker to use the |
| 4035 | // "start" symbol as the entry point. |
Bob Wilson | 1fc6e4f | 2012-07-03 20:42:10 +0000 | [diff] [blame] | 4036 | if (getDarwinToolChain().isTargetMacOS() && |
| 4037 | !getDarwinToolChain().isMacosxVersionLT(10, 8)) |
| 4038 | CmdArgs.push_back("-no_new_main"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4039 | } else { |
| 4040 | if (Args.hasArg(options::OPT_static) || |
| 4041 | Args.hasArg(options::OPT_object) || |
| 4042 | Args.hasArg(options::OPT_preload)) { |
| 4043 | CmdArgs.push_back("-lcrt0.o"); |
| 4044 | } else { |
| 4045 | // Derived from darwin_crt1 spec. |
Daniel Dunbar | 4035580 | 2011-03-31 17:12:33 +0000 | [diff] [blame] | 4046 | if (getDarwinToolChain().isTargetIOSSimulator()) { |
| 4047 | // The simulator doesn't have a versioned crt1 file. |
| 4048 | CmdArgs.push_back("-lcrt1.o"); |
| 4049 | } else if (getDarwinToolChain().isTargetIPhoneOS()) { |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4050 | if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1)) |
| 4051 | CmdArgs.push_back("-lcrt1.o"); |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 4052 | else if (getDarwinToolChain().isIPhoneOSVersionLT(6, 0)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4053 | CmdArgs.push_back("-lcrt1.3.1.o"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4054 | } else { |
| 4055 | if (getDarwinToolChain().isMacosxVersionLT(10, 5)) |
| 4056 | CmdArgs.push_back("-lcrt1.o"); |
| 4057 | else if (getDarwinToolChain().isMacosxVersionLT(10, 6)) |
| 4058 | CmdArgs.push_back("-lcrt1.10.5.o"); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4059 | else if (getDarwinToolChain().isMacosxVersionLT(10, 8)) |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4060 | CmdArgs.push_back("-lcrt1.10.6.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4061 | |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4062 | // darwin_crt2 spec is empty. |
| 4063 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4064 | } |
| 4065 | } |
| 4066 | } |
| 4067 | } |
| 4068 | |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4069 | if (!getDarwinToolChain().isTargetIPhoneOS() && |
| 4070 | Args.hasArg(options::OPT_shared_libgcc) && |
| 4071 | getDarwinToolChain().isMacosxVersionLT(10, 5)) { |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 4072 | const char *Str = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4073 | Args.MakeArgString(getToolChain().GetFilePath("crt3.o")); |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 4074 | CmdArgs.push_back(Str); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4075 | } |
| 4076 | } |
| 4077 | |
| 4078 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4079 | |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 4080 | SanitizerArgs Sanitize(getToolChain().getDriver(), Args); |
Alexey Samsonov | 75fcb19 | 2012-11-16 12:53:14 +0000 | [diff] [blame] | 4081 | // If we're building a dynamic lib with -fsanitize=address, or |
| 4082 | // -fsanitize=undefined, unresolved symbols may appear. Mark all |
| 4083 | // of them as dynamic_lookup. Linking executables is handled in |
| 4084 | // lib/Driver/ToolChains.cpp. |
| 4085 | if (Sanitize.needsAsanRt() || Sanitize.needsUbsanRt()) { |
Kostya Serebryany | 7b5f101 | 2011-12-06 19:18:44 +0000 | [diff] [blame] | 4086 | if (Args.hasArg(options::OPT_dynamiclib) || |
| 4087 | Args.hasArg(options::OPT_bundle)) { |
| 4088 | CmdArgs.push_back("-undefined"); |
| 4089 | CmdArgs.push_back("dynamic_lookup"); |
| 4090 | } |
| 4091 | } |
| 4092 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4093 | if (Args.hasArg(options::OPT_fopenmp)) |
| 4094 | // This is more complicated in gcc... |
| 4095 | CmdArgs.push_back("-lgomp"); |
| 4096 | |
Douglas Gregor | 04e326b | 2012-05-15 21:00:27 +0000 | [diff] [blame] | 4097 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
| 4098 | |
Bob Wilson | 63d9f3c | 2012-05-15 18:57:39 +0000 | [diff] [blame] | 4099 | if (isObjCRuntimeLinked(Args) && |
| 4100 | !Args.hasArg(options::OPT_nostdlib) && |
| 4101 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4102 | // Avoid linking compatibility stubs on i386 mac. |
| 4103 | if (!getDarwinToolChain().isTargetMacOS() || |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 4104 | getDarwinToolChain().getArch() != llvm::Triple::x86) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4105 | // If we don't have ARC or subscripting runtime support, link in the |
| 4106 | // runtime stubs. We have to do this *before* adding any of the normal |
| 4107 | // linker inputs so that its initializer gets run first. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 4108 | ObjCRuntime runtime = |
| 4109 | getDarwinToolChain().getDefaultObjCRuntime(/*nonfragile*/ true); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4110 | // We use arclite library for both ARC and subscripting support. |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 4111 | if ((!runtime.hasNativeARC() && isObjCAutoRefCount(Args)) || |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 4112 | !runtime.hasSubscripting()) |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4113 | getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4114 | } |
Bob Wilson | 0b1c715 | 2012-04-21 00:21:42 +0000 | [diff] [blame] | 4115 | CmdArgs.push_back("-framework"); |
| 4116 | CmdArgs.push_back("Foundation"); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4117 | // Link libobj. |
| 4118 | CmdArgs.push_back("-lobjc"); |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 4119 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4120 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4121 | if (LinkingOutput) { |
| 4122 | CmdArgs.push_back("-arch_multiple"); |
| 4123 | CmdArgs.push_back("-final_output"); |
| 4124 | CmdArgs.push_back(LinkingOutput); |
| 4125 | } |
| 4126 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4127 | if (Args.hasArg(options::OPT_fnested_functions)) |
| 4128 | CmdArgs.push_back("-allow_stack_execute"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4129 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4130 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4131 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4132 | if (getToolChain().getDriver().CCCIsCXX) |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 4133 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Daniel Dunbar | edfa02b | 2009-04-08 06:06:21 +0000 | [diff] [blame] | 4134 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4135 | // link_ssp spec is empty. |
| 4136 | |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 4137 | // Let the tool chain choose which runtime library to link. |
| 4138 | getDarwinToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4139 | } |
| 4140 | |
Chad Rosier | 1893731 | 2012-05-16 23:45:12 +0000 | [diff] [blame] | 4141 | if (!Args.hasArg(options::OPT_nostdlib) && |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4142 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4143 | // endfile_spec is empty. |
| 4144 | } |
| 4145 | |
| 4146 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4147 | Args.AddAllArgs(CmdArgs, options::OPT_F); |
| 4148 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4149 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4150 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4151 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4152 | } |
| 4153 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4154 | void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4155 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4156 | const InputInfoList &Inputs, |
| 4157 | const ArgList &Args, |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4158 | const char *LinkingOutput) const { |
| 4159 | ArgStringList CmdArgs; |
| 4160 | |
| 4161 | CmdArgs.push_back("-create"); |
| 4162 | assert(Output.isFilename() && "Unexpected lipo output."); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 4163 | |
| 4164 | CmdArgs.push_back("-output"); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4165 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 4166 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4167 | for (InputInfoList::const_iterator |
| 4168 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4169 | const InputInfo &II = *it; |
| 4170 | assert(II.isFilename() && "Unexpected lipo input."); |
| 4171 | CmdArgs.push_back(II.getFilename()); |
| 4172 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4173 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4174 | Args.MakeArgString(getToolChain().GetProgramPath("lipo")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4175 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4176 | } |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 4177 | |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4178 | void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4179 | const InputInfo &Output, |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4180 | const InputInfoList &Inputs, |
| 4181 | const ArgList &Args, |
| 4182 | const char *LinkingOutput) const { |
| 4183 | ArgStringList CmdArgs; |
| 4184 | |
Daniel Dunbar | 03e9230 | 2011-05-09 17:23:16 +0000 | [diff] [blame] | 4185 | CmdArgs.push_back("-o"); |
| 4186 | CmdArgs.push_back(Output.getFilename()); |
| 4187 | |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4188 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 4189 | const InputInfo &Input = Inputs[0]; |
| 4190 | assert(Input.isFilename() && "Unexpected dsymutil input."); |
| 4191 | CmdArgs.push_back(Input.getFilename()); |
| 4192 | |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4193 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4194 | Args.MakeArgString(getToolChain().GetProgramPath("dsymutil")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4195 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4196 | } |
| 4197 | |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 4198 | void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA, |
| 4199 | const InputInfo &Output, |
| 4200 | const InputInfoList &Inputs, |
| 4201 | const ArgList &Args, |
| 4202 | const char *LinkingOutput) const { |
| 4203 | ArgStringList CmdArgs; |
| 4204 | CmdArgs.push_back("--verify"); |
Eric Christopher | 1c79dc4 | 2012-02-06 19:13:09 +0000 | [diff] [blame] | 4205 | CmdArgs.push_back("--debug-info"); |
| 4206 | CmdArgs.push_back("--eh-frame"); |
Eric Christopher | b822f72 | 2012-02-06 19:43:51 +0000 | [diff] [blame] | 4207 | CmdArgs.push_back("--quiet"); |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 4208 | |
| 4209 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 4210 | const InputInfo &Input = Inputs[0]; |
| 4211 | assert(Input.isFilename() && "Unexpected verify input"); |
| 4212 | |
| 4213 | // Grabbing the output of the earlier dsymutil run. |
| 4214 | CmdArgs.push_back(Input.getFilename()); |
| 4215 | |
| 4216 | const char *Exec = |
| 4217 | Args.MakeArgString(getToolChain().GetProgramPath("dwarfdump")); |
| 4218 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4219 | } |
| 4220 | |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4221 | void solaris::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 4222 | const InputInfo &Output, |
| 4223 | const InputInfoList &Inputs, |
| 4224 | const ArgList &Args, |
| 4225 | const char *LinkingOutput) const { |
| 4226 | ArgStringList CmdArgs; |
| 4227 | |
| 4228 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 4229 | options::OPT_Xassembler); |
| 4230 | |
| 4231 | CmdArgs.push_back("-o"); |
| 4232 | CmdArgs.push_back(Output.getFilename()); |
| 4233 | |
| 4234 | for (InputInfoList::const_iterator |
| 4235 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4236 | const InputInfo &II = *it; |
| 4237 | CmdArgs.push_back(II.getFilename()); |
| 4238 | } |
| 4239 | |
| 4240 | const char *Exec = |
| 4241 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
| 4242 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4243 | } |
| 4244 | |
| 4245 | |
| 4246 | void solaris::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 4247 | const InputInfo &Output, |
| 4248 | const InputInfoList &Inputs, |
| 4249 | const ArgList &Args, |
| 4250 | const char *LinkingOutput) const { |
| 4251 | // FIXME: Find a real GCC, don't hard-code versions here |
| 4252 | std::string GCCLibPath = "/usr/gcc/4.5/lib/gcc/"; |
| 4253 | const llvm::Triple &T = getToolChain().getTriple(); |
| 4254 | std::string LibPath = "/usr/lib/"; |
| 4255 | llvm::Triple::ArchType Arch = T.getArch(); |
| 4256 | switch (Arch) { |
| 4257 | case llvm::Triple::x86: |
| 4258 | GCCLibPath += ("i386-" + T.getVendorName() + "-" + |
| 4259 | T.getOSName()).str() + "/4.5.2/"; |
| 4260 | break; |
| 4261 | case llvm::Triple::x86_64: |
| 4262 | GCCLibPath += ("i386-" + T.getVendorName() + "-" + |
| 4263 | T.getOSName()).str(); |
| 4264 | GCCLibPath += "/4.5.2/amd64/"; |
| 4265 | LibPath += "amd64/"; |
| 4266 | break; |
| 4267 | default: |
| 4268 | assert(0 && "Unsupported architecture"); |
| 4269 | } |
| 4270 | |
| 4271 | ArgStringList CmdArgs; |
| 4272 | |
David Chisnall | 41d476d | 2012-02-29 15:06:12 +0000 | [diff] [blame] | 4273 | // Demangle C++ names in errors |
| 4274 | CmdArgs.push_back("-C"); |
| 4275 | |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4276 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
| 4277 | (!Args.hasArg(options::OPT_shared))) { |
| 4278 | CmdArgs.push_back("-e"); |
| 4279 | CmdArgs.push_back("_start"); |
| 4280 | } |
| 4281 | |
| 4282 | if (Args.hasArg(options::OPT_static)) { |
| 4283 | CmdArgs.push_back("-Bstatic"); |
| 4284 | CmdArgs.push_back("-dn"); |
| 4285 | } else { |
| 4286 | CmdArgs.push_back("-Bdynamic"); |
| 4287 | if (Args.hasArg(options::OPT_shared)) { |
| 4288 | CmdArgs.push_back("-shared"); |
| 4289 | } else { |
| 4290 | CmdArgs.push_back("--dynamic-linker"); |
| 4291 | CmdArgs.push_back(Args.MakeArgString(LibPath + "ld.so.1")); |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | if (Output.isFilename()) { |
| 4296 | CmdArgs.push_back("-o"); |
| 4297 | CmdArgs.push_back(Output.getFilename()); |
| 4298 | } else { |
| 4299 | assert(Output.isNothing() && "Invalid output."); |
| 4300 | } |
| 4301 | |
| 4302 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4303 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4304 | if (!Args.hasArg(options::OPT_shared)) { |
| 4305 | CmdArgs.push_back(Args.MakeArgString(LibPath + "crt1.o")); |
| 4306 | CmdArgs.push_back(Args.MakeArgString(LibPath + "crti.o")); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4307 | CmdArgs.push_back(Args.MakeArgString(LibPath + "values-Xa.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4308 | CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtbegin.o")); |
| 4309 | } else { |
| 4310 | CmdArgs.push_back(Args.MakeArgString(LibPath + "crti.o")); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4311 | CmdArgs.push_back(Args.MakeArgString(LibPath + "values-Xa.o")); |
| 4312 | CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtbegin.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4313 | } |
David Chisnall | e6dd683 | 2012-03-13 14:14:54 +0000 | [diff] [blame] | 4314 | if (getToolChain().getDriver().CCCIsCXX) |
| 4315 | CmdArgs.push_back(Args.MakeArgString(LibPath + "cxa_finalize.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | CmdArgs.push_back(Args.MakeArgString("-L" + GCCLibPath)); |
| 4319 | |
| 4320 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 4321 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4322 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4323 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4324 | |
| 4325 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
| 4326 | |
| 4327 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4328 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
David Chisnall | e58e6f9 | 2012-04-10 11:49:50 +0000 | [diff] [blame] | 4329 | if (getToolChain().getDriver().CCCIsCXX) |
| 4330 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
David Chisnall | b622959 | 2012-02-15 18:24:31 +0000 | [diff] [blame] | 4331 | CmdArgs.push_back("-lgcc_s"); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4332 | if (!Args.hasArg(options::OPT_shared)) { |
| 4333 | CmdArgs.push_back("-lgcc"); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4334 | CmdArgs.push_back("-lc"); |
David Chisnall | 7dbefe1 | 2012-02-28 20:06:45 +0000 | [diff] [blame] | 4335 | CmdArgs.push_back("-lm"); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4336 | } |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4340 | !Args.hasArg(options::OPT_nostartfiles)) { |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4341 | CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtend.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4342 | } |
David Chisnall | d1ac03e | 2012-02-16 16:00:47 +0000 | [diff] [blame] | 4343 | CmdArgs.push_back(Args.MakeArgString(LibPath + "crtn.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4344 | |
| 4345 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
| 4346 | |
| 4347 | const char *Exec = |
| 4348 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
| 4349 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4350 | } |
| 4351 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4352 | void auroraux::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4353 | const InputInfo &Output, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4354 | const InputInfoList &Inputs, |
| 4355 | const ArgList &Args, |
| 4356 | const char *LinkingOutput) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4357 | ArgStringList CmdArgs; |
| 4358 | |
| 4359 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 4360 | options::OPT_Xassembler); |
| 4361 | |
| 4362 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4363 | CmdArgs.push_back(Output.getFilename()); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4364 | |
| 4365 | for (InputInfoList::const_iterator |
| 4366 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4367 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4368 | CmdArgs.push_back(II.getFilename()); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4372 | Args.MakeArgString(getToolChain().GetProgramPath("gas")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4373 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4374 | } |
| 4375 | |
| 4376 | void auroraux::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4377 | const InputInfo &Output, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4378 | const InputInfoList &Inputs, |
| 4379 | const ArgList &Args, |
| 4380 | const char *LinkingOutput) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4381 | ArgStringList CmdArgs; |
| 4382 | |
| 4383 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4384 | (!Args.hasArg(options::OPT_shared))) { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4385 | CmdArgs.push_back("-e"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 4386 | CmdArgs.push_back("_start"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4387 | } |
| 4388 | |
| 4389 | if (Args.hasArg(options::OPT_static)) { |
| 4390 | CmdArgs.push_back("-Bstatic"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 4391 | CmdArgs.push_back("-dn"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4392 | } else { |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 4393 | // CmdArgs.push_back("--eh-frame-hdr"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4394 | CmdArgs.push_back("-Bdynamic"); |
| 4395 | if (Args.hasArg(options::OPT_shared)) { |
| 4396 | CmdArgs.push_back("-shared"); |
| 4397 | } else { |
Edward O'Callaghan | 3cecc19 | 2009-10-16 19:44:18 +0000 | [diff] [blame] | 4398 | CmdArgs.push_back("--dynamic-linker"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4399 | CmdArgs.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1 |
| 4400 | } |
| 4401 | } |
| 4402 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4403 | if (Output.isFilename()) { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4404 | CmdArgs.push_back("-o"); |
| 4405 | CmdArgs.push_back(Output.getFilename()); |
| 4406 | } else { |
| 4407 | assert(Output.isNothing() && "Invalid output."); |
| 4408 | } |
| 4409 | |
| 4410 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4411 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4412 | if (!Args.hasArg(options::OPT_shared)) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4413 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4414 | getToolChain().GetFilePath("crt1.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4415 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4416 | getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4417 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4418 | getToolChain().GetFilePath("crtbegin.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4419 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4420 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4421 | getToolChain().GetFilePath("crti.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4422 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4423 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4424 | getToolChain().GetFilePath("crtn.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4425 | } |
| 4426 | |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4427 | CmdArgs.push_back(Args.MakeArgString("-L/opt/gcc4/lib/gcc/" |
| 4428 | + getToolChain().getTripleString() |
Daniel Dunbar | f7fb31f | 2009-10-29 02:24:37 +0000 | [diff] [blame] | 4429 | + "/4.2.4")); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4430 | |
| 4431 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 4432 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4433 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 4434 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 4435 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4436 | |
| 4437 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4438 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 4439 | // FIXME: For some reason GCC passes -lgcc before adding |
| 4440 | // the default system libraries. Just mimic this for now. |
| 4441 | CmdArgs.push_back("-lgcc"); |
| 4442 | |
| 4443 | if (Args.hasArg(options::OPT_pthread)) |
| 4444 | CmdArgs.push_back("-pthread"); |
| 4445 | if (!Args.hasArg(options::OPT_shared)) |
| 4446 | CmdArgs.push_back("-lc"); |
| 4447 | CmdArgs.push_back("-lgcc"); |
| 4448 | } |
| 4449 | |
| 4450 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4451 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4452 | if (!Args.hasArg(options::OPT_shared)) |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4453 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4454 | getToolChain().GetFilePath("crtend.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4455 | } |
| 4456 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 4457 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 4458 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4459 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4460 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4461 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4464 | void openbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4465 | const InputInfo &Output, |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4466 | const InputInfoList &Inputs, |
| 4467 | const ArgList &Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4468 | const char *LinkingOutput) const { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4469 | ArgStringList CmdArgs; |
| 4470 | |
| 4471 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 4472 | options::OPT_Xassembler); |
| 4473 | |
| 4474 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4475 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4476 | |
| 4477 | for (InputInfoList::const_iterator |
| 4478 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4479 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4480 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4484 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4485 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | void openbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4489 | const InputInfo &Output, |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4490 | const InputInfoList &Inputs, |
| 4491 | const ArgList &Args, |
| 4492 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4493 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4494 | ArgStringList CmdArgs; |
| 4495 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4496 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4497 | (!Args.hasArg(options::OPT_shared))) { |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4498 | CmdArgs.push_back("-e"); |
| 4499 | CmdArgs.push_back("__start"); |
| 4500 | } |
| 4501 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4502 | if (Args.hasArg(options::OPT_static)) { |
| 4503 | CmdArgs.push_back("-Bstatic"); |
| 4504 | } else { |
Rafael Espindola | 65ba55d | 2010-11-11 02:17:51 +0000 | [diff] [blame] | 4505 | if (Args.hasArg(options::OPT_rdynamic)) |
| 4506 | CmdArgs.push_back("-export-dynamic"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4507 | CmdArgs.push_back("--eh-frame-hdr"); |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4508 | CmdArgs.push_back("-Bdynamic"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4509 | if (Args.hasArg(options::OPT_shared)) { |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4510 | CmdArgs.push_back("-shared"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4511 | } else { |
| 4512 | CmdArgs.push_back("-dynamic-linker"); |
| 4513 | CmdArgs.push_back("/usr/libexec/ld.so"); |
| 4514 | } |
| 4515 | } |
| 4516 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4517 | if (Output.isFilename()) { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4518 | CmdArgs.push_back("-o"); |
| 4519 | CmdArgs.push_back(Output.getFilename()); |
| 4520 | } else { |
| 4521 | assert(Output.isNothing() && "Invalid output."); |
| 4522 | } |
| 4523 | |
| 4524 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4525 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4526 | if (!Args.hasArg(options::OPT_shared)) { |
Eli Friedman | 62d829a | 2011-12-15 02:15:56 +0000 | [diff] [blame] | 4527 | if (Args.hasArg(options::OPT_pg)) |
| 4528 | CmdArgs.push_back(Args.MakeArgString( |
| 4529 | getToolChain().GetFilePath("gcrt0.o"))); |
| 4530 | else |
| 4531 | CmdArgs.push_back(Args.MakeArgString( |
| 4532 | getToolChain().GetFilePath("crt0.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4533 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4534 | getToolChain().GetFilePath("crtbegin.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4535 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4536 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4537 | getToolChain().GetFilePath("crtbeginS.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4538 | } |
| 4539 | } |
| 4540 | |
Edward O'Callaghan | e7e1820 | 2009-10-28 15:13:08 +0000 | [diff] [blame] | 4541 | std::string Triple = getToolChain().getTripleString(); |
| 4542 | if (Triple.substr(0, 6) == "x86_64") |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4543 | Triple.replace(0, 6, "amd64"); |
Daniel Dunbar | f7fb31f | 2009-10-29 02:24:37 +0000 | [diff] [blame] | 4544 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc-lib/" + Triple + |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 4545 | "/4.2.1")); |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4546 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4547 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 4548 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4549 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 4550 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 4551 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4552 | |
| 4553 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4554 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 4555 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 4556 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Eli Friedman | 62d829a | 2011-12-15 02:15:56 +0000 | [diff] [blame] | 4557 | if (Args.hasArg(options::OPT_pg)) |
| 4558 | CmdArgs.push_back("-lm_p"); |
| 4559 | else |
| 4560 | CmdArgs.push_back("-lm"); |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 4561 | } |
| 4562 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4563 | // FIXME: For some reason GCC passes -lgcc before adding |
| 4564 | // the default system libraries. Just mimic this for now. |
| 4565 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4566 | |
Eric Christopher | dc6cc87 | 2012-09-13 06:32:34 +0000 | [diff] [blame] | 4567 | if (Args.hasArg(options::OPT_pthread)) { |
| 4568 | if (!Args.hasArg(options::OPT_shared) && |
| 4569 | Args.hasArg(options::OPT_pg)) |
| 4570 | CmdArgs.push_back("-lpthread_p"); |
| 4571 | else |
| 4572 | CmdArgs.push_back("-lpthread"); |
| 4573 | } |
| 4574 | |
Chandler Carruth | 657849c | 2011-12-17 22:32:42 +0000 | [diff] [blame] | 4575 | if (!Args.hasArg(options::OPT_shared)) { |
Eric Christopher | dc6cc87 | 2012-09-13 06:32:34 +0000 | [diff] [blame] | 4576 | if (Args.hasArg(options::OPT_pg)) |
Eli Friedman | 62d829a | 2011-12-15 02:15:56 +0000 | [diff] [blame] | 4577 | CmdArgs.push_back("-lc_p"); |
| 4578 | else |
| 4579 | CmdArgs.push_back("-lc"); |
Chandler Carruth | 657849c | 2011-12-17 22:32:42 +0000 | [diff] [blame] | 4580 | } |
Eric Christopher | dc6cc87 | 2012-09-13 06:32:34 +0000 | [diff] [blame] | 4581 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4582 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4583 | } |
| 4584 | |
| 4585 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4586 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4587 | if (!Args.hasArg(options::OPT_shared)) |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4588 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4589 | getToolChain().GetFilePath("crtend.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4590 | else |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4591 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4592 | getToolChain().GetFilePath("crtendS.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4596 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4597 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4598 | } |
Ed Schouten | c66a5a3 | 2009-04-02 19:13:12 +0000 | [diff] [blame] | 4599 | |
Eli Friedman | 42f74f2 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 4600 | void bitrig::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 4601 | const InputInfo &Output, |
| 4602 | const InputInfoList &Inputs, |
| 4603 | const ArgList &Args, |
| 4604 | const char *LinkingOutput) const { |
| 4605 | ArgStringList CmdArgs; |
| 4606 | |
| 4607 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 4608 | options::OPT_Xassembler); |
| 4609 | |
| 4610 | CmdArgs.push_back("-o"); |
| 4611 | CmdArgs.push_back(Output.getFilename()); |
| 4612 | |
| 4613 | for (InputInfoList::const_iterator |
| 4614 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4615 | const InputInfo &II = *it; |
| 4616 | CmdArgs.push_back(II.getFilename()); |
| 4617 | } |
| 4618 | |
| 4619 | const char *Exec = |
| 4620 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
| 4621 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4622 | } |
| 4623 | |
| 4624 | void bitrig::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 4625 | const InputInfo &Output, |
| 4626 | const InputInfoList &Inputs, |
| 4627 | const ArgList &Args, |
| 4628 | const char *LinkingOutput) const { |
| 4629 | const Driver &D = getToolChain().getDriver(); |
| 4630 | ArgStringList CmdArgs; |
| 4631 | |
| 4632 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
| 4633 | (!Args.hasArg(options::OPT_shared))) { |
| 4634 | CmdArgs.push_back("-e"); |
| 4635 | CmdArgs.push_back("__start"); |
| 4636 | } |
| 4637 | |
| 4638 | if (Args.hasArg(options::OPT_static)) { |
| 4639 | CmdArgs.push_back("-Bstatic"); |
| 4640 | } else { |
| 4641 | if (Args.hasArg(options::OPT_rdynamic)) |
| 4642 | CmdArgs.push_back("-export-dynamic"); |
| 4643 | CmdArgs.push_back("--eh-frame-hdr"); |
| 4644 | CmdArgs.push_back("-Bdynamic"); |
| 4645 | if (Args.hasArg(options::OPT_shared)) { |
| 4646 | CmdArgs.push_back("-shared"); |
| 4647 | } else { |
| 4648 | CmdArgs.push_back("-dynamic-linker"); |
| 4649 | CmdArgs.push_back("/usr/libexec/ld.so"); |
| 4650 | } |
| 4651 | } |
| 4652 | |
| 4653 | if (Output.isFilename()) { |
| 4654 | CmdArgs.push_back("-o"); |
| 4655 | CmdArgs.push_back(Output.getFilename()); |
| 4656 | } else { |
| 4657 | assert(Output.isNothing() && "Invalid output."); |
| 4658 | } |
| 4659 | |
| 4660 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4661 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4662 | if (!Args.hasArg(options::OPT_shared)) { |
| 4663 | if (Args.hasArg(options::OPT_pg)) |
| 4664 | CmdArgs.push_back(Args.MakeArgString( |
| 4665 | getToolChain().GetFilePath("gcrt0.o"))); |
| 4666 | else |
| 4667 | CmdArgs.push_back(Args.MakeArgString( |
| 4668 | getToolChain().GetFilePath("crt0.o"))); |
| 4669 | CmdArgs.push_back(Args.MakeArgString( |
| 4670 | getToolChain().GetFilePath("crtbegin.o"))); |
| 4671 | } else { |
| 4672 | CmdArgs.push_back(Args.MakeArgString( |
| 4673 | getToolChain().GetFilePath("crtbeginS.o"))); |
| 4674 | } |
| 4675 | } |
| 4676 | |
| 4677 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 4678 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4679 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 4680 | |
| 4681 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
| 4682 | |
| 4683 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4684 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 4685 | if (D.CCCIsCXX) { |
| 4686 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
| 4687 | if (Args.hasArg(options::OPT_pg)) |
| 4688 | CmdArgs.push_back("-lm_p"); |
| 4689 | else |
| 4690 | CmdArgs.push_back("-lm"); |
| 4691 | } |
| 4692 | |
Rafael Espindola | 3667bbe | 2012-10-23 17:07:31 +0000 | [diff] [blame] | 4693 | if (Args.hasArg(options::OPT_pthread)) { |
| 4694 | if (!Args.hasArg(options::OPT_shared) && |
| 4695 | Args.hasArg(options::OPT_pg)) |
| 4696 | CmdArgs.push_back("-lpthread_p"); |
| 4697 | else |
| 4698 | CmdArgs.push_back("-lpthread"); |
| 4699 | } |
| 4700 | |
Eli Friedman | 42f74f2 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 4701 | if (!Args.hasArg(options::OPT_shared)) { |
| 4702 | if (Args.hasArg(options::OPT_pg)) |
| 4703 | CmdArgs.push_back("-lc_p"); |
| 4704 | else |
| 4705 | CmdArgs.push_back("-lc"); |
| 4706 | } |
| 4707 | |
| 4708 | std::string myarch = "-lclang_rt."; |
| 4709 | const llvm::Triple &T = getToolChain().getTriple(); |
| 4710 | llvm::Triple::ArchType Arch = T.getArch(); |
| 4711 | switch (Arch) { |
| 4712 | case llvm::Triple::arm: |
| 4713 | myarch += ("arm"); |
| 4714 | break; |
| 4715 | case llvm::Triple::x86: |
| 4716 | myarch += ("i386"); |
| 4717 | break; |
| 4718 | case llvm::Triple::x86_64: |
| 4719 | myarch += ("amd64"); |
| 4720 | break; |
| 4721 | default: |
| 4722 | assert(0 && "Unsupported architecture"); |
| 4723 | } |
| 4724 | CmdArgs.push_back(Args.MakeArgString(myarch)); |
| 4725 | } |
| 4726 | |
| 4727 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4728 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4729 | if (!Args.hasArg(options::OPT_shared)) |
| 4730 | CmdArgs.push_back(Args.MakeArgString( |
| 4731 | getToolChain().GetFilePath("crtend.o"))); |
| 4732 | else |
| 4733 | CmdArgs.push_back(Args.MakeArgString( |
| 4734 | getToolChain().GetFilePath("crtendS.o"))); |
| 4735 | } |
Eli Friedman | c9c48db | 2012-08-09 22:42:04 +0000 | [diff] [blame] | 4736 | |
| 4737 | const char *Exec = |
| 4738 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
| 4739 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Eli Friedman | 42f74f2 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 4740 | } |
| 4741 | |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 4742 | void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4743 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4744 | const InputInfoList &Inputs, |
| 4745 | const ArgList &Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4746 | const char *LinkingOutput) const { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 4747 | ArgStringList CmdArgs; |
| 4748 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4749 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 4750 | // instruct as in the base system to assemble 32-bit code. |
Eric Christopher | c55da4b | 2012-09-05 21:32:44 +0000 | [diff] [blame] | 4751 | if (getToolChain().getArch() == llvm::Triple::x86) |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 4752 | CmdArgs.push_back("--32"); |
Eric Christopher | c55da4b | 2012-09-05 21:32:44 +0000 | [diff] [blame] | 4753 | else if (getToolChain().getArch() == llvm::Triple::ppc) |
Roman Divacky | 3393cef | 2011-06-04 07:37:31 +0000 | [diff] [blame] | 4754 | CmdArgs.push_back("-a32"); |
Eric Christopher | c55da4b | 2012-09-05 21:32:44 +0000 | [diff] [blame] | 4755 | else if (getToolChain().getArch() == llvm::Triple::mips || |
| 4756 | getToolChain().getArch() == llvm::Triple::mipsel || |
| 4757 | getToolChain().getArch() == llvm::Triple::mips64 || |
| 4758 | getToolChain().getArch() == llvm::Triple::mips64el) { |
| 4759 | StringRef CPUName; |
| 4760 | StringRef ABIName; |
| 4761 | getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4762 | |
Eric Christopher | c55da4b | 2012-09-05 21:32:44 +0000 | [diff] [blame] | 4763 | CmdArgs.push_back("-march"); |
| 4764 | CmdArgs.push_back(CPUName.data()); |
| 4765 | |
| 4766 | // Convert ABI name to the GNU tools acceptable variant. |
| 4767 | if (ABIName == "o32") |
| 4768 | ABIName = "32"; |
| 4769 | else if (ABIName == "n64") |
| 4770 | ABIName = "64"; |
| 4771 | |
| 4772 | CmdArgs.push_back("-mabi"); |
| 4773 | CmdArgs.push_back(ABIName.data()); |
| 4774 | |
| 4775 | if (getToolChain().getArch() == llvm::Triple::mips || |
| 4776 | getToolChain().getArch() == llvm::Triple::mips64) |
| 4777 | CmdArgs.push_back("-EB"); |
| 4778 | else |
| 4779 | CmdArgs.push_back("-EL"); |
| 4780 | |
| 4781 | Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, |
| 4782 | options::OPT_fpic, options::OPT_fno_pic, |
| 4783 | options::OPT_fPIE, options::OPT_fno_PIE, |
| 4784 | options::OPT_fpie, options::OPT_fno_pie); |
| 4785 | if (LastPICArg && |
| 4786 | (LastPICArg->getOption().matches(options::OPT_fPIC) || |
| 4787 | LastPICArg->getOption().matches(options::OPT_fpic) || |
| 4788 | LastPICArg->getOption().matches(options::OPT_fPIE) || |
| 4789 | LastPICArg->getOption().matches(options::OPT_fpie))) { |
| 4790 | CmdArgs.push_back("-KPIC"); |
| 4791 | } |
| 4792 | } |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 4793 | |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 4794 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 4795 | options::OPT_Xassembler); |
| 4796 | |
| 4797 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4798 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 4799 | |
| 4800 | for (InputInfoList::const_iterator |
| 4801 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4802 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4803 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 4804 | } |
| 4805 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4806 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4807 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4808 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 4809 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4810 | |
| 4811 | void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4812 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4813 | const InputInfoList &Inputs, |
| 4814 | const ArgList &Args, |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 4815 | const char *LinkingOutput) const { |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4816 | const toolchains::FreeBSD& ToolChain = |
| 4817 | static_cast<const toolchains::FreeBSD&>(getToolChain()); |
| 4818 | const Driver &D = ToolChain.getDriver(); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4819 | ArgStringList CmdArgs; |
David Chisnall | dfa210b | 2012-07-29 15:24:44 +0000 | [diff] [blame] | 4820 | |
| 4821 | // Silence warning for "clang -g foo.o -o foo" |
| 4822 | Args.ClaimAllArgs(options::OPT_g_Group); |
| 4823 | // and "clang -emit-llvm foo.o -o foo" |
| 4824 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
| 4825 | // and for "clang -w foo.o -o foo". Other warning options are already |
| 4826 | // handled somewhere else. |
| 4827 | Args.ClaimAllArgs(options::OPT_w); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4828 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 4829 | if (!D.SysRoot.empty()) |
| 4830 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 4831 | |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4832 | if (Args.hasArg(options::OPT_pie)) |
| 4833 | CmdArgs.push_back("-pie"); |
| 4834 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4835 | if (Args.hasArg(options::OPT_static)) { |
| 4836 | CmdArgs.push_back("-Bstatic"); |
| 4837 | } else { |
Rafael Espindola | 65ba55d | 2010-11-11 02:17:51 +0000 | [diff] [blame] | 4838 | if (Args.hasArg(options::OPT_rdynamic)) |
| 4839 | CmdArgs.push_back("-export-dynamic"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4840 | CmdArgs.push_back("--eh-frame-hdr"); |
| 4841 | if (Args.hasArg(options::OPT_shared)) { |
| 4842 | CmdArgs.push_back("-Bshareable"); |
| 4843 | } else { |
| 4844 | CmdArgs.push_back("-dynamic-linker"); |
| 4845 | CmdArgs.push_back("/libexec/ld-elf.so.1"); |
| 4846 | } |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4847 | if (ToolChain.getTriple().getOSMajorVersion() >= 9) { |
| 4848 | llvm::Triple::ArchType Arch = ToolChain.getArch(); |
David Chisnall | dfa210b | 2012-07-29 15:24:44 +0000 | [diff] [blame] | 4849 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc || |
| 4850 | Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) { |
| 4851 | CmdArgs.push_back("--hash-style=both"); |
| 4852 | } |
| 4853 | } |
| 4854 | CmdArgs.push_back("--enable-new-dtags"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 4858 | // instruct ld in the base system to link 32-bit code. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 4859 | if (ToolChain.getArch() == llvm::Triple::x86) { |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4860 | CmdArgs.push_back("-m"); |
| 4861 | CmdArgs.push_back("elf_i386_fbsd"); |
| 4862 | } |
| 4863 | |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 4864 | if (ToolChain.getArch() == llvm::Triple::ppc) { |
Roman Divacky | 000a655 | 2011-06-04 07:40:24 +0000 | [diff] [blame] | 4865 | CmdArgs.push_back("-m"); |
Roman Divacky | 1052c1d | 2011-11-21 16:50:32 +0000 | [diff] [blame] | 4866 | CmdArgs.push_back("elf32ppc_fbsd"); |
Roman Divacky | 000a655 | 2011-06-04 07:40:24 +0000 | [diff] [blame] | 4867 | } |
| 4868 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4869 | if (Output.isFilename()) { |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4870 | CmdArgs.push_back("-o"); |
| 4871 | CmdArgs.push_back(Output.getFilename()); |
| 4872 | } else { |
| 4873 | assert(Output.isNothing() && "Invalid output."); |
| 4874 | } |
| 4875 | |
| 4876 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4877 | !Args.hasArg(options::OPT_nostartfiles)) { |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4878 | const char *crt1 = NULL; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4879 | if (!Args.hasArg(options::OPT_shared)) { |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 4880 | if (Args.hasArg(options::OPT_pg)) |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4881 | crt1 = "gcrt1.o"; |
| 4882 | else if (Args.hasArg(options::OPT_pie)) |
| 4883 | crt1 = "Scrt1.o"; |
| 4884 | else |
| 4885 | crt1 = "crt1.o"; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4886 | } |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4887 | if (crt1) |
| 4888 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1))); |
| 4889 | |
| 4890 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); |
| 4891 | |
| 4892 | const char *crtbegin = NULL; |
| 4893 | if (Args.hasArg(options::OPT_static)) |
| 4894 | crtbegin = "crtbeginT.o"; |
| 4895 | else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) |
| 4896 | crtbegin = "crtbeginS.o"; |
| 4897 | else |
| 4898 | crtbegin = "crtbegin.o"; |
| 4899 | |
| 4900 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4901 | } |
| 4902 | |
| 4903 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4904 | const ToolChain::path_list Paths = ToolChain.getFilePaths(); |
Roman Divacky | 58e5ac9 | 2011-03-01 17:53:14 +0000 | [diff] [blame] | 4905 | for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end(); |
| 4906 | i != e; ++i) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4907 | CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i)); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4908 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4909 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
David Chisnall | c736377 | 2010-08-15 22:58:12 +0000 | [diff] [blame] | 4910 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 4911 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 4912 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 4913 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4914 | |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4915 | AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4916 | |
| 4917 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4918 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | 2002263 | 2010-02-17 08:07:51 +0000 | [diff] [blame] | 4919 | if (D.CCCIsCXX) { |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4920 | ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 4921 | if (Args.hasArg(options::OPT_pg)) |
| 4922 | CmdArgs.push_back("-lm_p"); |
| 4923 | else |
| 4924 | CmdArgs.push_back("-lm"); |
Daniel Dunbar | 2002263 | 2010-02-17 08:07:51 +0000 | [diff] [blame] | 4925 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4926 | // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding |
| 4927 | // the default system libraries. Just mimic this for now. |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 4928 | if (Args.hasArg(options::OPT_pg)) |
| 4929 | CmdArgs.push_back("-lgcc_p"); |
| 4930 | else |
| 4931 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4932 | if (Args.hasArg(options::OPT_static)) { |
| 4933 | CmdArgs.push_back("-lgcc_eh"); |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 4934 | } else if (Args.hasArg(options::OPT_pg)) { |
| 4935 | CmdArgs.push_back("-lgcc_eh_p"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4936 | } else { |
| 4937 | CmdArgs.push_back("--as-needed"); |
| 4938 | CmdArgs.push_back("-lgcc_s"); |
| 4939 | CmdArgs.push_back("--no-as-needed"); |
| 4940 | } |
| 4941 | |
Matt Beaumont-Gay | 2423026 | 2011-02-10 20:35:01 +0000 | [diff] [blame] | 4942 | if (Args.hasArg(options::OPT_pthread)) { |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 4943 | if (Args.hasArg(options::OPT_pg)) |
| 4944 | CmdArgs.push_back("-lpthread_p"); |
| 4945 | else |
| 4946 | CmdArgs.push_back("-lpthread"); |
Matt Beaumont-Gay | 2423026 | 2011-02-10 20:35:01 +0000 | [diff] [blame] | 4947 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4948 | |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 4949 | if (Args.hasArg(options::OPT_pg)) { |
| 4950 | if (Args.hasArg(options::OPT_shared)) |
| 4951 | CmdArgs.push_back("-lc"); |
| 4952 | else |
| 4953 | CmdArgs.push_back("-lc_p"); |
| 4954 | CmdArgs.push_back("-lgcc_p"); |
| 4955 | } else { |
| 4956 | CmdArgs.push_back("-lc"); |
| 4957 | CmdArgs.push_back("-lgcc"); |
| 4958 | } |
| 4959 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4960 | if (Args.hasArg(options::OPT_static)) { |
| 4961 | CmdArgs.push_back("-lgcc_eh"); |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 4962 | } else if (Args.hasArg(options::OPT_pg)) { |
| 4963 | CmdArgs.push_back("-lgcc_eh_p"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4964 | } else { |
| 4965 | CmdArgs.push_back("--as-needed"); |
| 4966 | CmdArgs.push_back("-lgcc_s"); |
| 4967 | CmdArgs.push_back("--no-as-needed"); |
| 4968 | } |
| 4969 | } |
| 4970 | |
| 4971 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4972 | !Args.hasArg(options::OPT_nostartfiles)) { |
Roman Divacky | f651381 | 2012-09-07 13:36:21 +0000 | [diff] [blame] | 4973 | if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4974 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); |
Roman Divacky | f651381 | 2012-09-07 13:36:21 +0000 | [diff] [blame] | 4975 | else |
| 4976 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4977 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4978 | } |
| 4979 | |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4980 | addProfileRT(ToolChain, Args, CmdArgs, ToolChain.getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 4981 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4982 | const char *Exec = |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 4983 | Args.MakeArgString(ToolChain.GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4984 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 4985 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4986 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 4987 | void netbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 4988 | const InputInfo &Output, |
| 4989 | const InputInfoList &Inputs, |
| 4990 | const ArgList &Args, |
| 4991 | const char *LinkingOutput) const { |
| 4992 | ArgStringList CmdArgs; |
| 4993 | |
| 4994 | // When building 32-bit code on NetBSD/amd64, we have to explicitly |
| 4995 | // instruct as in the base system to assemble 32-bit code. |
Joerg Sonnenberger | 1bd9137 | 2012-01-26 22:27:52 +0000 | [diff] [blame] | 4996 | if (getToolChain().getArch() == llvm::Triple::x86) |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 4997 | CmdArgs.push_back("--32"); |
| 4998 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 4999 | // Set byte order explicitly |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5000 | if (getToolChain().getArch() == llvm::Triple::mips) |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5001 | CmdArgs.push_back("-EB"); |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5002 | else if (getToolChain().getArch() == llvm::Triple::mipsel) |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5003 | CmdArgs.push_back("-EL"); |
| 5004 | |
| 5005 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 5006 | options::OPT_Xassembler); |
| 5007 | |
| 5008 | CmdArgs.push_back("-o"); |
| 5009 | CmdArgs.push_back(Output.getFilename()); |
| 5010 | |
| 5011 | for (InputInfoList::const_iterator |
| 5012 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5013 | const InputInfo &II = *it; |
| 5014 | CmdArgs.push_back(II.getFilename()); |
| 5015 | } |
| 5016 | |
David Chisnall | 5adcec1 | 2011-09-27 22:03:18 +0000 | [diff] [blame] | 5017 | const char *Exec = Args.MakeArgString((getToolChain().GetProgramPath("as"))); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5018 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 5019 | } |
| 5020 | |
| 5021 | void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 5022 | const InputInfo &Output, |
| 5023 | const InputInfoList &Inputs, |
| 5024 | const ArgList &Args, |
| 5025 | const char *LinkingOutput) const { |
| 5026 | const Driver &D = getToolChain().getDriver(); |
| 5027 | ArgStringList CmdArgs; |
| 5028 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 5029 | if (!D.SysRoot.empty()) |
| 5030 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 5031 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5032 | if (Args.hasArg(options::OPT_static)) { |
| 5033 | CmdArgs.push_back("-Bstatic"); |
| 5034 | } else { |
| 5035 | if (Args.hasArg(options::OPT_rdynamic)) |
| 5036 | CmdArgs.push_back("-export-dynamic"); |
| 5037 | CmdArgs.push_back("--eh-frame-hdr"); |
| 5038 | if (Args.hasArg(options::OPT_shared)) { |
| 5039 | CmdArgs.push_back("-Bshareable"); |
| 5040 | } else { |
| 5041 | CmdArgs.push_back("-dynamic-linker"); |
| 5042 | CmdArgs.push_back("/libexec/ld.elf_so"); |
| 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | // When building 32-bit code on NetBSD/amd64, we have to explicitly |
| 5047 | // instruct ld in the base system to link 32-bit code. |
Joerg Sonnenberger | 1bd9137 | 2012-01-26 22:27:52 +0000 | [diff] [blame] | 5048 | if (getToolChain().getArch() == llvm::Triple::x86) { |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5049 | CmdArgs.push_back("-m"); |
| 5050 | CmdArgs.push_back("elf_i386"); |
| 5051 | } |
| 5052 | |
| 5053 | if (Output.isFilename()) { |
| 5054 | CmdArgs.push_back("-o"); |
| 5055 | CmdArgs.push_back(Output.getFilename()); |
| 5056 | } else { |
| 5057 | assert(Output.isNothing() && "Invalid output."); |
| 5058 | } |
| 5059 | |
| 5060 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5061 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5062 | if (!Args.hasArg(options::OPT_shared)) { |
| 5063 | CmdArgs.push_back(Args.MakeArgString( |
| 5064 | getToolChain().GetFilePath("crt0.o"))); |
| 5065 | CmdArgs.push_back(Args.MakeArgString( |
| 5066 | getToolChain().GetFilePath("crti.o"))); |
| 5067 | CmdArgs.push_back(Args.MakeArgString( |
| 5068 | getToolChain().GetFilePath("crtbegin.o"))); |
| 5069 | } else { |
| 5070 | CmdArgs.push_back(Args.MakeArgString( |
| 5071 | getToolChain().GetFilePath("crti.o"))); |
| 5072 | CmdArgs.push_back(Args.MakeArgString( |
| 5073 | getToolChain().GetFilePath("crtbeginS.o"))); |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 5078 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 5079 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 5080 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 5081 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 5082 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 5083 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
| 5084 | |
| 5085 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
| 5086 | |
| 5087 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5088 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 5089 | if (D.CCCIsCXX) { |
| 5090 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
| 5091 | CmdArgs.push_back("-lm"); |
| 5092 | } |
| 5093 | // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding |
| 5094 | // the default system libraries. Just mimic this for now. |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5095 | if (Args.hasArg(options::OPT_static)) { |
| 5096 | CmdArgs.push_back("-lgcc_eh"); |
| 5097 | } else { |
| 5098 | CmdArgs.push_back("--as-needed"); |
| 5099 | CmdArgs.push_back("-lgcc_s"); |
| 5100 | CmdArgs.push_back("--no-as-needed"); |
| 5101 | } |
Joerg Sonnenberger | db6393f | 2011-06-07 23:39:17 +0000 | [diff] [blame] | 5102 | CmdArgs.push_back("-lgcc"); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5103 | |
| 5104 | if (Args.hasArg(options::OPT_pthread)) |
| 5105 | CmdArgs.push_back("-lpthread"); |
| 5106 | CmdArgs.push_back("-lc"); |
| 5107 | |
| 5108 | CmdArgs.push_back("-lgcc"); |
| 5109 | if (Args.hasArg(options::OPT_static)) { |
| 5110 | CmdArgs.push_back("-lgcc_eh"); |
| 5111 | } else { |
| 5112 | CmdArgs.push_back("--as-needed"); |
| 5113 | CmdArgs.push_back("-lgcc_s"); |
| 5114 | CmdArgs.push_back("--no-as-needed"); |
| 5115 | } |
| 5116 | } |
| 5117 | |
| 5118 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5119 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5120 | if (!Args.hasArg(options::OPT_shared)) |
| 5121 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
| 5122 | "crtend.o"))); |
| 5123 | else |
| 5124 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
| 5125 | "crtendS.o"))); |
| 5126 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
| 5127 | "crtn.o"))); |
| 5128 | } |
| 5129 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 5130 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 5131 | |
David Chisnall | 5adcec1 | 2011-09-27 22:03:18 +0000 | [diff] [blame] | 5132 | const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5133 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 5134 | } |
| 5135 | |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5136 | void linuxtools::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 5137 | const InputInfo &Output, |
| 5138 | const InputInfoList &Inputs, |
| 5139 | const ArgList &Args, |
| 5140 | const char *LinkingOutput) const { |
| 5141 | ArgStringList CmdArgs; |
| 5142 | |
| 5143 | // Add --32/--64 to make sure we get the format we want. |
| 5144 | // This is incomplete |
| 5145 | if (getToolChain().getArch() == llvm::Triple::x86) { |
| 5146 | CmdArgs.push_back("--32"); |
| 5147 | } else if (getToolChain().getArch() == llvm::Triple::x86_64) { |
| 5148 | CmdArgs.push_back("--64"); |
Eli Friedman | 7972c88 | 2011-11-28 23:46:52 +0000 | [diff] [blame] | 5149 | } else if (getToolChain().getArch() == llvm::Triple::ppc) { |
| 5150 | CmdArgs.push_back("-a32"); |
| 5151 | CmdArgs.push_back("-mppc"); |
| 5152 | CmdArgs.push_back("-many"); |
| 5153 | } else if (getToolChain().getArch() == llvm::Triple::ppc64) { |
| 5154 | CmdArgs.push_back("-a64"); |
| 5155 | CmdArgs.push_back("-mppc64"); |
| 5156 | CmdArgs.push_back("-many"); |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5157 | } else if (getToolChain().getArch() == llvm::Triple::arm) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5158 | StringRef MArch = getToolChain().getArchName(); |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5159 | if (MArch == "armv7" || MArch == "armv7a" || MArch == "armv7-a") |
| 5160 | CmdArgs.push_back("-mfpu=neon"); |
Evgeniy Stepanov | 700c508 | 2012-04-20 09:03:40 +0000 | [diff] [blame] | 5161 | |
| 5162 | StringRef ARMFloatABI = getARMFloatABI(getToolChain().getDriver(), Args, |
| 5163 | getToolChain().getTriple()); |
| 5164 | CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=" + ARMFloatABI)); |
Evgeniy Stepanov | eca187e | 2012-04-24 09:05:31 +0000 | [diff] [blame] | 5165 | |
| 5166 | Args.AddLastArg(CmdArgs, options::OPT_march_EQ); |
| 5167 | Args.AddLastArg(CmdArgs, options::OPT_mcpu_EQ); |
| 5168 | Args.AddLastArg(CmdArgs, options::OPT_mfpu_EQ); |
Akira Hatanaka | c85900f | 2011-11-30 19:31:38 +0000 | [diff] [blame] | 5169 | } else if (getToolChain().getArch() == llvm::Triple::mips || |
| 5170 | getToolChain().getArch() == llvm::Triple::mipsel || |
| 5171 | getToolChain().getArch() == llvm::Triple::mips64 || |
| 5172 | getToolChain().getArch() == llvm::Triple::mips64el) { |
Simon Atanasyan | 073a780 | 2012-04-07 22:31:29 +0000 | [diff] [blame] | 5173 | StringRef CPUName; |
| 5174 | StringRef ABIName; |
| 5175 | getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName); |
Akira Hatanaka | c85900f | 2011-11-30 19:31:38 +0000 | [diff] [blame] | 5176 | |
Simon Atanasyan | 073a780 | 2012-04-07 22:31:29 +0000 | [diff] [blame] | 5177 | CmdArgs.push_back("-march"); |
| 5178 | CmdArgs.push_back(CPUName.data()); |
| 5179 | |
| 5180 | // Convert ABI name to the GNU tools acceptable variant. |
| 5181 | if (ABIName == "o32") |
| 5182 | ABIName = "32"; |
| 5183 | else if (ABIName == "n64") |
| 5184 | ABIName = "64"; |
| 5185 | |
| 5186 | CmdArgs.push_back("-mabi"); |
| 5187 | CmdArgs.push_back(ABIName.data()); |
Simon Atanasyan | 5f0a1c1 | 2012-04-06 19:15:24 +0000 | [diff] [blame] | 5188 | |
| 5189 | if (getToolChain().getArch() == llvm::Triple::mips || |
| 5190 | getToolChain().getArch() == llvm::Triple::mips64) |
| 5191 | CmdArgs.push_back("-EB"); |
| 5192 | else |
| 5193 | CmdArgs.push_back("-EL"); |
Simon Atanasyan | 1f0646e | 2012-05-29 19:07:33 +0000 | [diff] [blame] | 5194 | |
| 5195 | Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, |
| 5196 | options::OPT_fpic, options::OPT_fno_pic, |
| 5197 | options::OPT_fPIE, options::OPT_fno_PIE, |
| 5198 | options::OPT_fpie, options::OPT_fno_pie); |
| 5199 | if (LastPICArg && |
| 5200 | (LastPICArg->getOption().matches(options::OPT_fPIC) || |
| 5201 | LastPICArg->getOption().matches(options::OPT_fpic) || |
| 5202 | LastPICArg->getOption().matches(options::OPT_fPIE) || |
| 5203 | LastPICArg->getOption().matches(options::OPT_fpie))) { |
| 5204 | CmdArgs.push_back("-KPIC"); |
| 5205 | } |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5206 | } |
| 5207 | |
| 5208 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 5209 | options::OPT_Xassembler); |
| 5210 | |
| 5211 | CmdArgs.push_back("-o"); |
| 5212 | CmdArgs.push_back(Output.getFilename()); |
| 5213 | |
| 5214 | for (InputInfoList::const_iterator |
| 5215 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5216 | const InputInfo &II = *it; |
| 5217 | CmdArgs.push_back(II.getFilename()); |
| 5218 | } |
| 5219 | |
| 5220 | const char *Exec = |
| 5221 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
| 5222 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 5223 | } |
| 5224 | |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5225 | static void AddLibgcc(llvm::Triple Triple, const Driver &D, |
| 5226 | ArgStringList &CmdArgs, const ArgList &Args) { |
Logan Chien | 94a7142 | 2012-09-02 09:30:11 +0000 | [diff] [blame] | 5227 | bool isAndroid = Triple.getEnvironment() == llvm::Triple::Android; |
Logan Chien | 529a73d | 2012-11-19 12:04:11 +0000 | [diff] [blame] | 5228 | bool StaticLibgcc = Args.hasArg(options::OPT_static) || |
| 5229 | Args.hasArg(options::OPT_static_libgcc); |
Rafael Espindola | abf3ac7 | 2011-10-17 21:39:04 +0000 | [diff] [blame] | 5230 | if (!D.CCCIsCXX) |
| 5231 | CmdArgs.push_back("-lgcc"); |
| 5232 | |
Logan Chien | 529a73d | 2012-11-19 12:04:11 +0000 | [diff] [blame] | 5233 | if (StaticLibgcc || isAndroid) { |
Rafael Espindola | abf3ac7 | 2011-10-17 21:39:04 +0000 | [diff] [blame] | 5234 | if (D.CCCIsCXX) |
| 5235 | CmdArgs.push_back("-lgcc"); |
| 5236 | } else { |
| 5237 | if (!D.CCCIsCXX) |
| 5238 | CmdArgs.push_back("--as-needed"); |
| 5239 | CmdArgs.push_back("-lgcc_s"); |
| 5240 | if (!D.CCCIsCXX) |
| 5241 | CmdArgs.push_back("--no-as-needed"); |
| 5242 | } |
| 5243 | |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5244 | if (StaticLibgcc && !isAndroid) |
Rafael Espindola | abf3ac7 | 2011-10-17 21:39:04 +0000 | [diff] [blame] | 5245 | CmdArgs.push_back("-lgcc_eh"); |
| 5246 | else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX) |
| 5247 | CmdArgs.push_back("-lgcc"); |
Logan Chien | 529a73d | 2012-11-19 12:04:11 +0000 | [diff] [blame] | 5248 | |
| 5249 | // According to Android ABI, we have to link with libdl if we are |
| 5250 | // linking with non-static libgcc. |
| 5251 | // |
| 5252 | // NOTE: This fixes a link error on Android MIPS as well. The non-static |
| 5253 | // libgcc for MIPS relies on _Unwind_Find_FDE and dl_iterate_phdr from libdl. |
| 5254 | if (isAndroid && !StaticLibgcc) |
| 5255 | CmdArgs.push_back("-ldl"); |
Rafael Espindola | abf3ac7 | 2011-10-17 21:39:04 +0000 | [diff] [blame] | 5256 | } |
| 5257 | |
Simon Atanasyan | f4bd329 | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 5258 | static bool hasMipsN32ABIArg(const ArgList &Args) { |
| 5259 | Arg *A = Args.getLastArg(options::OPT_mabi_EQ); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 5260 | return A && (A->getValue() == StringRef("n32")); |
Simon Atanasyan | f4bd329 | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 5261 | } |
| 5262 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5263 | void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 5264 | const InputInfo &Output, |
| 5265 | const InputInfoList &Inputs, |
| 5266 | const ArgList &Args, |
| 5267 | const char *LinkingOutput) const { |
| 5268 | const toolchains::Linux& ToolChain = |
| 5269 | static_cast<const toolchains::Linux&>(getToolChain()); |
| 5270 | const Driver &D = ToolChain.getDriver(); |
Rafael Espindola | 715852c | 2012-11-02 20:41:30 +0000 | [diff] [blame] | 5271 | const bool isAndroid = |
| 5272 | ToolChain.getTriple().getEnvironment() == llvm::Triple::Android; |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5273 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5274 | ArgStringList CmdArgs; |
| 5275 | |
Rafael Espindola | 26f14c3 | 2010-11-15 18:28:16 +0000 | [diff] [blame] | 5276 | // Silence warning for "clang -g foo.o -o foo" |
| 5277 | Args.ClaimAllArgs(options::OPT_g_Group); |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 5278 | // and "clang -emit-llvm foo.o -o foo" |
| 5279 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
David Chisnall | dfa210b | 2012-07-29 15:24:44 +0000 | [diff] [blame] | 5280 | // and for "clang -w foo.o -o foo". Other warning options are already |
Rafael Espindola | 7f6458b | 2010-11-17 20:37:10 +0000 | [diff] [blame] | 5281 | // handled somewhere else. |
| 5282 | Args.ClaimAllArgs(options::OPT_w); |
Rafael Espindola | 26f14c3 | 2010-11-15 18:28:16 +0000 | [diff] [blame] | 5283 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 5284 | if (!D.SysRoot.empty()) |
| 5285 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5286 | |
Rafael Espindola | fdda171 | 2010-11-17 22:26:15 +0000 | [diff] [blame] | 5287 | if (Args.hasArg(options::OPT_pie)) |
| 5288 | CmdArgs.push_back("-pie"); |
| 5289 | |
Rafael Espindola | dc1b76d | 2010-11-07 22:57:16 +0000 | [diff] [blame] | 5290 | if (Args.hasArg(options::OPT_rdynamic)) |
| 5291 | CmdArgs.push_back("-export-dynamic"); |
| 5292 | |
Rafael Espindola | e0e6d3b | 2010-11-11 19:34:42 +0000 | [diff] [blame] | 5293 | if (Args.hasArg(options::OPT_s)) |
| 5294 | CmdArgs.push_back("-s"); |
| 5295 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5296 | for (std::vector<std::string>::const_iterator i = ToolChain.ExtraOpts.begin(), |
| 5297 | e = ToolChain.ExtraOpts.end(); |
| 5298 | i != e; ++i) |
| 5299 | CmdArgs.push_back(i->c_str()); |
| 5300 | |
| 5301 | if (!Args.hasArg(options::OPT_static)) { |
| 5302 | CmdArgs.push_back("--eh-frame-hdr"); |
| 5303 | } |
| 5304 | |
| 5305 | CmdArgs.push_back("-m"); |
| 5306 | if (ToolChain.getArch() == llvm::Triple::x86) |
| 5307 | CmdArgs.push_back("elf_i386"); |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 5308 | else if (ToolChain.getArch() == llvm::Triple::arm |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 5309 | || ToolChain.getArch() == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5310 | CmdArgs.push_back("armelf_linux_eabi"); |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 5311 | else if (ToolChain.getArch() == llvm::Triple::ppc) |
| 5312 | CmdArgs.push_back("elf32ppclinux"); |
| 5313 | else if (ToolChain.getArch() == llvm::Triple::ppc64) |
| 5314 | CmdArgs.push_back("elf64ppc"); |
Eli Friedman | 5bea4f6 | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 5315 | else if (ToolChain.getArch() == llvm::Triple::mips) |
| 5316 | CmdArgs.push_back("elf32btsmip"); |
| 5317 | else if (ToolChain.getArch() == llvm::Triple::mipsel) |
| 5318 | CmdArgs.push_back("elf32ltsmip"); |
Simon Atanasyan | f4bd329 | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 5319 | else if (ToolChain.getArch() == llvm::Triple::mips64) { |
| 5320 | if (hasMipsN32ABIArg(Args)) |
| 5321 | CmdArgs.push_back("elf32btsmipn32"); |
| 5322 | else |
| 5323 | CmdArgs.push_back("elf64btsmip"); |
| 5324 | } |
| 5325 | else if (ToolChain.getArch() == llvm::Triple::mips64el) { |
| 5326 | if (hasMipsN32ABIArg(Args)) |
| 5327 | CmdArgs.push_back("elf32ltsmipn32"); |
| 5328 | else |
| 5329 | CmdArgs.push_back("elf64ltsmip"); |
| 5330 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5331 | else |
| 5332 | CmdArgs.push_back("elf_x86_64"); |
| 5333 | |
| 5334 | if (Args.hasArg(options::OPT_static)) { |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 5335 | if (ToolChain.getArch() == llvm::Triple::arm |
| 5336 | || ToolChain.getArch() == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5337 | CmdArgs.push_back("-Bstatic"); |
| 5338 | else |
| 5339 | CmdArgs.push_back("-static"); |
| 5340 | } else if (Args.hasArg(options::OPT_shared)) { |
| 5341 | CmdArgs.push_back("-shared"); |
Rafael Espindola | 715852c | 2012-11-02 20:41:30 +0000 | [diff] [blame] | 5342 | if (isAndroid) { |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5343 | CmdArgs.push_back("-Bsymbolic"); |
| 5344 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | if (ToolChain.getArch() == llvm::Triple::arm || |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 5348 | ToolChain.getArch() == llvm::Triple::thumb || |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5349 | (!Args.hasArg(options::OPT_static) && |
| 5350 | !Args.hasArg(options::OPT_shared))) { |
| 5351 | CmdArgs.push_back("-dynamic-linker"); |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5352 | if (isAndroid) |
| 5353 | CmdArgs.push_back("/system/bin/linker"); |
| 5354 | else if (ToolChain.getArch() == llvm::Triple::x86) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5355 | CmdArgs.push_back("/lib/ld-linux.so.2"); |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 5356 | else if (ToolChain.getArch() == llvm::Triple::arm || |
Jiangning Liu | 6cc9dc8 | 2012-07-30 11:05:56 +0000 | [diff] [blame] | 5357 | ToolChain.getArch() == llvm::Triple::thumb) { |
| 5358 | if (ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 5359 | CmdArgs.push_back("/lib/ld-linux-armhf.so.3"); |
| 5360 | else |
| 5361 | CmdArgs.push_back("/lib/ld-linux.so.3"); |
| 5362 | } |
Eli Friedman | 5bea4f6 | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 5363 | else if (ToolChain.getArch() == llvm::Triple::mips || |
| 5364 | ToolChain.getArch() == llvm::Triple::mipsel) |
| 5365 | CmdArgs.push_back("/lib/ld.so.1"); |
Simon Atanasyan | 8491cb2 | 2012-04-06 20:14:27 +0000 | [diff] [blame] | 5366 | else if (ToolChain.getArch() == llvm::Triple::mips64 || |
Simon Atanasyan | f4bd329 | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 5367 | ToolChain.getArch() == llvm::Triple::mips64el) { |
| 5368 | if (hasMipsN32ABIArg(Args)) |
| 5369 | CmdArgs.push_back("/lib32/ld.so.1"); |
| 5370 | else |
| 5371 | CmdArgs.push_back("/lib64/ld.so.1"); |
| 5372 | } |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 5373 | else if (ToolChain.getArch() == llvm::Triple::ppc) |
Chris Lattner | 09f43ed | 2011-04-11 21:15:37 +0000 | [diff] [blame] | 5374 | CmdArgs.push_back("/lib/ld.so.1"); |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 5375 | else if (ToolChain.getArch() == llvm::Triple::ppc64) |
Chris Lattner | 09f43ed | 2011-04-11 21:15:37 +0000 | [diff] [blame] | 5376 | CmdArgs.push_back("/lib64/ld64.so.1"); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5377 | else |
| 5378 | CmdArgs.push_back("/lib64/ld-linux-x86-64.so.2"); |
| 5379 | } |
| 5380 | |
| 5381 | CmdArgs.push_back("-o"); |
| 5382 | CmdArgs.push_back(Output.getFilename()); |
| 5383 | |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5384 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5385 | !Args.hasArg(options::OPT_nostartfiles)) { |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5386 | if (!isAndroid) { |
| 5387 | const char *crt1 = NULL; |
| 5388 | if (!Args.hasArg(options::OPT_shared)){ |
| 5389 | if (Args.hasArg(options::OPT_pie)) |
| 5390 | crt1 = "Scrt1.o"; |
| 5391 | else |
| 5392 | crt1 = "crt1.o"; |
| 5393 | } |
| 5394 | if (crt1) |
| 5395 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1))); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5396 | |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5397 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); |
| 5398 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5399 | |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5400 | const char *crtbegin; |
| 5401 | if (Args.hasArg(options::OPT_static)) |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5402 | crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o"; |
Evgeniy Stepanov | a92983d | 2012-09-10 10:30:12 +0000 | [diff] [blame] | 5403 | else if (Args.hasArg(options::OPT_shared)) |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5404 | crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o"; |
Evgeniy Stepanov | a92983d | 2012-09-10 10:30:12 +0000 | [diff] [blame] | 5405 | else if (Args.hasArg(options::OPT_pie)) |
| 5406 | crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o"; |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5407 | else |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5408 | crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o"; |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5409 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); |
Benjamin Kramer | e20e508 | 2012-10-04 19:42:20 +0000 | [diff] [blame] | 5410 | |
| 5411 | // Add crtfastmath.o if available and fast math is enabled. |
| 5412 | ToolChain.AddFastMathRuntimeIfAvailable(Args, CmdArgs); |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5413 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5414 | |
| 5415 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 5416 | |
| 5417 | const ToolChain::path_list Paths = ToolChain.getFilePaths(); |
| 5418 | |
Roman Divacky | 58e5ac9 | 2011-03-01 17:53:14 +0000 | [diff] [blame] | 5419 | for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end(); |
| 5420 | i != e; ++i) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5421 | CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i)); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5422 | |
Rafael Espindola | c515154 | 2012-04-09 23:53:34 +0000 | [diff] [blame] | 5423 | // Tell the linker to load the plugin. This has to come before AddLinkerInputs |
| 5424 | // as gold requires -plugin to come before any -plugin-opt that -Wl might |
| 5425 | // forward. |
| 5426 | if (D.IsUsingLTO(Args) || Args.hasArg(options::OPT_use_gold_plugin)) { |
| 5427 | CmdArgs.push_back("-plugin"); |
| 5428 | std::string Plugin = ToolChain.getDriver().Dir + "/../lib/LLVMgold.so"; |
| 5429 | CmdArgs.push_back(Args.MakeArgString(Plugin)); |
| 5430 | } |
| 5431 | |
Nick Lewycky | e276cfc | 2012-08-17 03:39:16 +0000 | [diff] [blame] | 5432 | if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) |
| 5433 | CmdArgs.push_back("--no-demangle"); |
| 5434 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5435 | AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); |
| 5436 | |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 5437 | SanitizerArgs Sanitize(D, Args); |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 5438 | |
Eric Christopher | 6716d94 | 2012-11-29 18:51:05 +0000 | [diff] [blame] | 5439 | // Call these before we add the C++ ABI library. |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 5440 | if (Sanitize.needsUbsanRt()) |
| 5441 | addUbsanRTLinux(getToolChain(), Args, CmdArgs); |
Eric Christopher | 6716d94 | 2012-11-29 18:51:05 +0000 | [diff] [blame] | 5442 | if (Sanitize.needsAsanRt()) |
| 5443 | addAsanRTLinux(getToolChain(), Args, CmdArgs); |
| 5444 | if (Sanitize.needsTsanRt()) |
| 5445 | addTsanRTLinux(getToolChain(), Args, CmdArgs); |
Richard Smith | 8e1cee6 | 2012-10-25 02:14:12 +0000 | [diff] [blame] | 5446 | |
Chandler Carruth | 2ba542c | 2012-05-14 18:31:18 +0000 | [diff] [blame] | 5447 | if (D.CCCIsCXX && |
| 5448 | !Args.hasArg(options::OPT_nostdlib) && |
| 5449 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Rafael Espindola | 19706f8 | 2011-10-17 22:14:51 +0000 | [diff] [blame] | 5450 | bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && |
| 5451 | !Args.hasArg(options::OPT_static); |
| 5452 | if (OnlyLibstdcxxStatic) |
| 5453 | CmdArgs.push_back("-Bstatic"); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5454 | ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
Rafael Espindola | 19706f8 | 2011-10-17 22:14:51 +0000 | [diff] [blame] | 5455 | if (OnlyLibstdcxxStatic) |
| 5456 | CmdArgs.push_back("-Bdynamic"); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5457 | CmdArgs.push_back("-lm"); |
| 5458 | } |
| 5459 | |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5460 | if (!Args.hasArg(options::OPT_nostdlib)) { |
Chandler Carruth | 2ba542c | 2012-05-14 18:31:18 +0000 | [diff] [blame] | 5461 | if (!Args.hasArg(options::OPT_nodefaultlibs)) { |
| 5462 | if (Args.hasArg(options::OPT_static)) |
| 5463 | CmdArgs.push_back("--start-group"); |
Nick Lewycky | 80df025 | 2011-06-04 06:27:06 +0000 | [diff] [blame] | 5464 | |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5465 | AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args); |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5466 | |
Chandler Carruth | 2ba542c | 2012-05-14 18:31:18 +0000 | [diff] [blame] | 5467 | if (Args.hasArg(options::OPT_pthread) || |
| 5468 | Args.hasArg(options::OPT_pthreads)) |
| 5469 | CmdArgs.push_back("-lpthread"); |
| 5470 | |
| 5471 | CmdArgs.push_back("-lc"); |
| 5472 | |
| 5473 | if (Args.hasArg(options::OPT_static)) |
| 5474 | CmdArgs.push_back("--end-group"); |
| 5475 | else |
| 5476 | AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args); |
| 5477 | } |
Rafael Espindola | fdda171 | 2010-11-17 22:26:15 +0000 | [diff] [blame] | 5478 | |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5479 | if (!Args.hasArg(options::OPT_nostartfiles)) { |
| 5480 | const char *crtend; |
Evgeniy Stepanov | a92983d | 2012-09-10 10:30:12 +0000 | [diff] [blame] | 5481 | if (Args.hasArg(options::OPT_shared)) |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5482 | crtend = isAndroid ? "crtend_so.o" : "crtendS.o"; |
Evgeniy Stepanov | a92983d | 2012-09-10 10:30:12 +0000 | [diff] [blame] | 5483 | else if (Args.hasArg(options::OPT_pie)) |
| 5484 | crtend = isAndroid ? "crtend_android.o" : "crtendS.o"; |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5485 | else |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5486 | crtend = isAndroid ? "crtend_android.o" : "crtend.o"; |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5487 | |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5488 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5489 | if (!isAndroid) |
| 5490 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5491 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5492 | } |
| 5493 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 5494 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 5495 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5496 | C.addCommand(new Command(JA, *this, ToolChain.Linker.c_str(), CmdArgs)); |
| 5497 | } |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5498 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5499 | void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5500 | const InputInfo &Output, |
| 5501 | const InputInfoList &Inputs, |
| 5502 | const ArgList &Args, |
| 5503 | const char *LinkingOutput) const { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5504 | ArgStringList CmdArgs; |
| 5505 | |
| 5506 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 5507 | options::OPT_Xassembler); |
| 5508 | |
| 5509 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5510 | CmdArgs.push_back(Output.getFilename()); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5511 | |
| 5512 | for (InputInfoList::const_iterator |
| 5513 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5514 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5515 | CmdArgs.push_back(II.getFilename()); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | const char *Exec = |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5519 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5520 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | void minix::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5524 | const InputInfo &Output, |
| 5525 | const InputInfoList &Inputs, |
| 5526 | const ArgList &Args, |
| 5527 | const char *LinkingOutput) const { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5528 | const Driver &D = getToolChain().getDriver(); |
| 5529 | ArgStringList CmdArgs; |
| 5530 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5531 | if (Output.isFilename()) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5532 | CmdArgs.push_back("-o"); |
| 5533 | CmdArgs.push_back(Output.getFilename()); |
| 5534 | } else { |
| 5535 | assert(Output.isNothing() && "Invalid output."); |
| 5536 | } |
| 5537 | |
| 5538 | if (!Args.hasArg(options::OPT_nostdlib) && |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5539 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5540 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o"))); |
| 5541 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); |
| 5542 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); |
| 5543 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); |
| 5544 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5545 | |
| 5546 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 5547 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 5548 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 5549 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 5550 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5551 | |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5552 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
| 5553 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5554 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5555 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 5556 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 5557 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5558 | CmdArgs.push_back("-lm"); |
| 5559 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5563 | !Args.hasArg(options::OPT_nostartfiles)) { |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5564 | if (Args.hasArg(options::OPT_pthread)) |
| 5565 | CmdArgs.push_back("-lpthread"); |
| 5566 | CmdArgs.push_back("-lc"); |
| 5567 | CmdArgs.push_back("-lCompilerRT-Generic"); |
| 5568 | CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib"); |
| 5569 | CmdArgs.push_back( |
| 5570 | Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5571 | } |
| 5572 | |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5573 | const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5574 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5575 | } |
| 5576 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5577 | /// DragonFly Tools |
| 5578 | |
| 5579 | // For now, DragonFly Assemble does just about the same as for |
| 5580 | // FreeBSD, but this may change soon. |
| 5581 | void dragonfly::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5582 | const InputInfo &Output, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 5583 | const InputInfoList &Inputs, |
| 5584 | const ArgList &Args, |
| 5585 | const char *LinkingOutput) const { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5586 | ArgStringList CmdArgs; |
| 5587 | |
| 5588 | // When building 32-bit code on DragonFly/pc64, we have to explicitly |
| 5589 | // instruct as in the base system to assemble 32-bit code. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5590 | if (getToolChain().getArch() == llvm::Triple::x86) |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5591 | CmdArgs.push_back("--32"); |
| 5592 | |
| 5593 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 5594 | options::OPT_Xassembler); |
| 5595 | |
| 5596 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5597 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5598 | |
| 5599 | for (InputInfoList::const_iterator |
| 5600 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5601 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5602 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5606 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5607 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5611 | const InputInfo &Output, |
| 5612 | const InputInfoList &Inputs, |
| 5613 | const ArgList &Args, |
| 5614 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 5615 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5616 | ArgStringList CmdArgs; |
| 5617 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 5618 | if (!D.SysRoot.empty()) |
| 5619 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 5620 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5621 | if (Args.hasArg(options::OPT_static)) { |
| 5622 | CmdArgs.push_back("-Bstatic"); |
| 5623 | } else { |
| 5624 | if (Args.hasArg(options::OPT_shared)) |
| 5625 | CmdArgs.push_back("-Bshareable"); |
| 5626 | else { |
| 5627 | CmdArgs.push_back("-dynamic-linker"); |
| 5628 | CmdArgs.push_back("/usr/libexec/ld-elf.so.2"); |
| 5629 | } |
| 5630 | } |
| 5631 | |
| 5632 | // When building 32-bit code on DragonFly/pc64, we have to explicitly |
| 5633 | // instruct ld in the base system to link 32-bit code. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5634 | if (getToolChain().getArch() == llvm::Triple::x86) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5635 | CmdArgs.push_back("-m"); |
| 5636 | CmdArgs.push_back("elf_i386"); |
| 5637 | } |
| 5638 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5639 | if (Output.isFilename()) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5640 | CmdArgs.push_back("-o"); |
| 5641 | CmdArgs.push_back(Output.getFilename()); |
| 5642 | } else { |
| 5643 | assert(Output.isNothing() && "Invalid output."); |
| 5644 | } |
| 5645 | |
| 5646 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5647 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5648 | if (!Args.hasArg(options::OPT_shared)) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5649 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5650 | Args.MakeArgString(getToolChain().GetFilePath("crt1.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5651 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5652 | Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5653 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5654 | Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5655 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5656 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5657 | Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5658 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5659 | Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5660 | } |
| 5661 | } |
| 5662 | |
| 5663 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 5664 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 5665 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 5666 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 5667 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5668 | |
| 5669 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5670 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 5671 | // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of |
| 5672 | // rpaths |
| 5673 | CmdArgs.push_back("-L/usr/lib/gcc41"); |
| 5674 | |
| 5675 | if (!Args.hasArg(options::OPT_static)) { |
| 5676 | CmdArgs.push_back("-rpath"); |
| 5677 | CmdArgs.push_back("/usr/lib/gcc41"); |
| 5678 | |
| 5679 | CmdArgs.push_back("-rpath-link"); |
| 5680 | CmdArgs.push_back("/usr/lib/gcc41"); |
| 5681 | |
| 5682 | CmdArgs.push_back("-rpath"); |
| 5683 | CmdArgs.push_back("/usr/lib"); |
| 5684 | |
| 5685 | CmdArgs.push_back("-rpath-link"); |
| 5686 | CmdArgs.push_back("/usr/lib"); |
| 5687 | } |
| 5688 | |
Rafael Espindola | 405861d | 2010-07-20 12:59:03 +0000 | [diff] [blame] | 5689 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 5690 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Rafael Espindola | 405861d | 2010-07-20 12:59:03 +0000 | [diff] [blame] | 5691 | CmdArgs.push_back("-lm"); |
| 5692 | } |
| 5693 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5694 | if (Args.hasArg(options::OPT_shared)) { |
| 5695 | CmdArgs.push_back("-lgcc_pic"); |
| 5696 | } else { |
| 5697 | CmdArgs.push_back("-lgcc"); |
| 5698 | } |
| 5699 | |
| 5700 | |
| 5701 | if (Args.hasArg(options::OPT_pthread)) |
Mike Stump | 4d63f8b | 2009-10-31 20:11:46 +0000 | [diff] [blame] | 5702 | CmdArgs.push_back("-lpthread"); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5703 | |
| 5704 | if (!Args.hasArg(options::OPT_nolibc)) { |
| 5705 | CmdArgs.push_back("-lc"); |
| 5706 | } |
| 5707 | |
| 5708 | if (Args.hasArg(options::OPT_shared)) { |
| 5709 | CmdArgs.push_back("-lgcc_pic"); |
| 5710 | } else { |
| 5711 | CmdArgs.push_back("-lgcc"); |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5716 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5717 | if (!Args.hasArg(options::OPT_shared)) |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5718 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5719 | getToolChain().GetFilePath("crtend.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5720 | else |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5721 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5722 | getToolChain().GetFilePath("crtendS.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5723 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5724 | getToolChain().GetFilePath("crtn.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5725 | } |
| 5726 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 5727 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 5728 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5729 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5730 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5731 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5732 | } |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 5733 | |
| 5734 | void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 5735 | const InputInfo &Output, |
| 5736 | const InputInfoList &Inputs, |
| 5737 | const ArgList &Args, |
| 5738 | const char *LinkingOutput) const { |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 5739 | ArgStringList CmdArgs; |
| 5740 | |
| 5741 | if (Output.isFilename()) { |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 5742 | CmdArgs.push_back(Args.MakeArgString(std::string("-out:") + |
| 5743 | Output.getFilename())); |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 5744 | } else { |
| 5745 | assert(Output.isNothing() && "Invalid output."); |
| 5746 | } |
| 5747 | |
| 5748 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5749 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5750 | CmdArgs.push_back("-defaultlib:libcmt"); |
| 5751 | } |
| 5752 | |
| 5753 | CmdArgs.push_back("-nologo"); |
| 5754 | |
Michael J. Spencer | a2284f5 | 2012-06-18 16:56:04 +0000 | [diff] [blame] | 5755 | Args.AddAllArgValues(CmdArgs, options::OPT_l); |
| 5756 | |
| 5757 | // Add filenames immediately. |
| 5758 | for (InputInfoList::const_iterator |
| 5759 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5760 | if (it->isFilename()) |
| 5761 | CmdArgs.push_back(it->getFilename()); |
| 5762 | } |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 5763 | |
| 5764 | const char *Exec = |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 5765 | Args.MakeArgString(getToolChain().GetProgramPath("link.exe")); |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 5766 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 5767 | } |