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" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 11 | #include "InputInfo.h" |
| 12 | #include "SanitizerArgs.h" |
| 13 | #include "ToolChains.h" |
| 14 | #include "clang/Basic/ObjCRuntime.h" |
Kevin Enderby | 0234179 | 2013-01-17 21:38:06 +0000 | [diff] [blame] | 15 | #include "clang/Basic/Version.h" |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Arg.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 18 | #include "clang/Driver/ArgList.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Compilation.h" |
Daniel Dunbar | ee848a7 | 2009-10-29 02:39:57 +0000 | [diff] [blame] | 20 | #include "clang/Driver/Driver.h" |
| 21 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 22 | #include "clang/Driver/Job.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 23 | #include "clang/Driver/Option.h" |
Daniel Dunbar | 265e9ef | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 24 | #include "clang/Driver/Options.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 25 | #include "clang/Driver/ToolChain.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 26 | #include "clang/Driver/Util.h" |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/SmallString.h" |
Douglas Gregor | 55d3f7a | 2009-10-29 00:41:01 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/StringSwitch.h" |
Daniel Dunbar | 5b750fe | 2009-09-09 22:32:34 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/Twine.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 31 | #include "llvm/Support/FileSystem.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Format.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Host.h" |
| 34 | #include "llvm/Support/Process.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 36 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 37 | using namespace clang::driver; |
| 38 | using namespace clang::driver::tools; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 39 | using namespace clang; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 40 | |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 41 | /// CheckPreprocessingOptions - Perform some validation of preprocessing |
| 42 | /// arguments that is shared with gcc. |
| 43 | static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) { |
| 44 | if (Arg *A = Args.getLastArg(options::OPT_C, options::OPT_CC)) |
Joerg Sonnenberger | 9ade4ae | 2011-03-06 23:31:01 +0000 | [diff] [blame] | 45 | if (!Args.hasArg(options::OPT_E) && !D.CCCIsCPP) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 46 | D.Diag(diag::err_drv_argument_only_allowed_with) |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 47 | << A->getAsString(Args) << "-E"; |
| 48 | } |
| 49 | |
Daniel Dunbar | e2fd664 | 2009-09-10 01:21:12 +0000 | [diff] [blame] | 50 | /// CheckCodeGenerationOptions - Perform some validation of code generation |
| 51 | /// arguments that is shared with gcc. |
| 52 | static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args) { |
| 53 | // In gcc, only ARM checks this, but it seems reasonable to check universally. |
| 54 | if (Args.hasArg(options::OPT_static)) |
| 55 | if (const Arg *A = Args.getLastArg(options::OPT_dynamic, |
| 56 | options::OPT_mdynamic_no_pic)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 57 | D.Diag(diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | e2fd664 | 2009-09-10 01:21:12 +0000 | [diff] [blame] | 58 | << A->getAsString(Args) << "-static"; |
| 59 | } |
| 60 | |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 61 | // Quote target names for inclusion in GNU Make dependency files. |
| 62 | // Only the characters '$', '#', ' ', '\t' are quoted. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 63 | static void QuoteTarget(StringRef Target, |
| 64 | SmallVectorImpl<char> &Res) { |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 65 | for (unsigned i = 0, e = Target.size(); i != e; ++i) { |
| 66 | switch (Target[i]) { |
| 67 | case ' ': |
| 68 | case '\t': |
| 69 | // Escape the preceding backslashes |
| 70 | for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j) |
| 71 | Res.push_back('\\'); |
| 72 | |
| 73 | // Escape the space/tab |
| 74 | Res.push_back('\\'); |
| 75 | break; |
| 76 | case '$': |
| 77 | Res.push_back('$'); |
| 78 | break; |
| 79 | case '#': |
| 80 | Res.push_back('\\'); |
| 81 | break; |
| 82 | default: |
| 83 | break; |
| 84 | } |
| 85 | |
| 86 | Res.push_back(Target[i]); |
| 87 | } |
| 88 | } |
| 89 | |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 90 | static void addDirectoryList(const ArgList &Args, |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 91 | ArgStringList &CmdArgs, |
| 92 | const char *ArgName, |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 93 | const char *EnvVar) { |
| 94 | const char *DirList = ::getenv(EnvVar); |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 95 | bool CombinedArg = false; |
| 96 | |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 97 | if (!DirList) |
| 98 | return; // Nothing to do. |
| 99 | |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 100 | StringRef Name(ArgName); |
| 101 | if (Name.equals("-I") || Name.equals("-L")) |
| 102 | CombinedArg = true; |
| 103 | |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 104 | StringRef Dirs(DirList); |
| 105 | if (Dirs.empty()) // Empty string should not add '.'. |
| 106 | return; |
| 107 | |
| 108 | StringRef::size_type Delim; |
| 109 | while ((Delim = Dirs.find(llvm::sys::PathSeparator)) != StringRef::npos) { |
| 110 | if (Delim == 0) { // Leading colon. |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 111 | if (CombinedArg) { |
| 112 | CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + ".")); |
| 113 | } else { |
| 114 | CmdArgs.push_back(ArgName); |
| 115 | CmdArgs.push_back("."); |
| 116 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 117 | } else { |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 118 | if (CombinedArg) { |
| 119 | CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs.substr(0, Delim))); |
| 120 | } else { |
| 121 | CmdArgs.push_back(ArgName); |
| 122 | CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim))); |
| 123 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 124 | } |
Nico Weber | 09c5c39 | 2012-03-19 15:00:03 +0000 | [diff] [blame] | 125 | Dirs = Dirs.substr(Delim + 1); |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | if (Dirs.empty()) { // Trailing colon. |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 129 | if (CombinedArg) { |
| 130 | CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + ".")); |
| 131 | } else { |
| 132 | CmdArgs.push_back(ArgName); |
| 133 | CmdArgs.push_back("."); |
| 134 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 135 | } else { // Add the last path. |
Chad Rosier | 89aa2ce | 2012-10-30 21:42:09 +0000 | [diff] [blame] | 136 | if (CombinedArg) { |
| 137 | CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs)); |
| 138 | } else { |
| 139 | CmdArgs.push_back(ArgName); |
| 140 | CmdArgs.push_back(Args.MakeArgString(Dirs)); |
| 141 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 145 | static void AddLinkerInputs(const ToolChain &TC, |
| 146 | const InputInfoList &Inputs, const ArgList &Args, |
| 147 | ArgStringList &CmdArgs) { |
| 148 | const Driver &D = TC.getDriver(); |
| 149 | |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 150 | // Add extra linker input arguments which are not treated as inputs |
| 151 | // (constructed via -Xarch_). |
| 152 | Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input); |
| 153 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 154 | for (InputInfoList::const_iterator |
| 155 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 156 | const InputInfo &II = *it; |
| 157 | |
| 158 | if (!TC.HasNativeLLVMSupport()) { |
| 159 | // Don't try to pass LLVM inputs unless we have native support. |
| 160 | if (II.getType() == types::TY_LLVM_IR || |
| 161 | II.getType() == types::TY_LTO_IR || |
| 162 | II.getType() == types::TY_LLVM_BC || |
| 163 | II.getType() == types::TY_LTO_BC) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 164 | D.Diag(diag::err_drv_no_linker_llvm_support) |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 165 | << TC.getTripleString(); |
| 166 | } |
| 167 | |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 168 | // Add filenames immediately. |
| 169 | if (II.isFilename()) { |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 170 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 171 | continue; |
| 172 | } |
| 173 | |
| 174 | // Otherwise, this is a linker input argument. |
| 175 | const Arg &A = II.getInputArg(); |
| 176 | |
| 177 | // Handle reserved library options. |
| 178 | if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 179 | TC.AddCXXStdlibLibArgs(Args, CmdArgs); |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 180 | } else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext)) { |
| 181 | TC.AddCCKextLibArgs(Args, CmdArgs); |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 182 | } else |
| 183 | A.renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 184 | } |
Bill Wendling | bdb8f3c | 2012-03-12 21:22:35 +0000 | [diff] [blame] | 185 | |
| 186 | // LIBRARY_PATH - included following the user specified library paths. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 187 | addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH"); |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 188 | } |
| 189 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 190 | /// \brief Determine whether Objective-C automated reference counting is |
| 191 | /// enabled. |
| 192 | static bool isObjCAutoRefCount(const ArgList &Args) { |
| 193 | return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); |
| 194 | } |
| 195 | |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 196 | /// \brief Determine whether we are linking the ObjC runtime. |
| 197 | static bool isObjCRuntimeLinked(const ArgList &Args) { |
Bob Wilson | a7635f1 | 2012-08-07 19:58:00 +0000 | [diff] [blame] | 198 | if (isObjCAutoRefCount(Args)) { |
| 199 | Args.ClaimAllArgs(options::OPT_fobjc_link_runtime); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 200 | return true; |
Bob Wilson | a7635f1 | 2012-08-07 19:58:00 +0000 | [diff] [blame] | 201 | } |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 202 | return Args.hasArg(options::OPT_fobjc_link_runtime); |
| 203 | } |
| 204 | |
Rafael Espindola | db3f24a | 2011-06-02 18:58:46 +0000 | [diff] [blame] | 205 | static void addProfileRT(const ToolChain &TC, const ArgList &Args, |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 206 | ArgStringList &CmdArgs, |
| 207 | llvm::Triple Triple) { |
| 208 | if (!(Args.hasArg(options::OPT_fprofile_arcs) || |
| 209 | Args.hasArg(options::OPT_fprofile_generate) || |
| 210 | Args.hasArg(options::OPT_fcreate_profile) || |
| 211 | Args.hasArg(options::OPT_coverage))) |
| 212 | return; |
| 213 | |
| 214 | // GCC links libgcov.a by adding -L<inst>/gcc/lib/gcc/<triple>/<ver> -lgcov to |
| 215 | // the link line. We cannot do the same thing because unlike gcov there is a |
| 216 | // libprofile_rt.so. We used to use the -l:libprofile_rt.a syntax, but that is |
| 217 | // not supported by old linkers. |
Benjamin Kramer | f2db04c | 2011-11-07 16:02:25 +0000 | [diff] [blame] | 218 | std::string ProfileRT = |
| 219 | std::string(TC.getDriver().Dir) + "/../lib/libprofile_rt.a"; |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 220 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 221 | CmdArgs.push_back(Args.MakeArgString(ProfileRT)); |
Rafael Espindola | db3f24a | 2011-06-02 18:58:46 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Michael J. Spencer | 91e06da | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 224 | static bool forwardToGCC(const Option &O) { |
| 225 | return !O.hasFlag(options::NoForward) && |
| 226 | !O.hasFlag(options::DriverOption) && |
| 227 | !O.hasFlag(options::LinkerInput); |
| 228 | } |
| 229 | |
Peter Collingbourne | 54db68b | 2011-11-06 00:40:05 +0000 | [diff] [blame] | 230 | void Clang::AddPreprocessingOptions(Compilation &C, |
Chad Rosier | 9d71863 | 2013-01-24 19:14:47 +0000 | [diff] [blame] | 231 | const JobAction &JA, |
Peter Collingbourne | 54db68b | 2011-11-06 00:40:05 +0000 | [diff] [blame] | 232 | const Driver &D, |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 233 | const ArgList &Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 234 | ArgStringList &CmdArgs, |
| 235 | const InputInfo &Output, |
| 236 | const InputInfoList &Inputs) const { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 237 | Arg *A; |
Daniel Dunbar | 3a183d3 | 2009-06-08 21:48:20 +0000 | [diff] [blame] | 238 | |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 239 | CheckPreprocessingOptions(D, Args); |
| 240 | |
| 241 | Args.AddLastArg(CmdArgs, options::OPT_C); |
| 242 | Args.AddLastArg(CmdArgs, options::OPT_CC); |
Daniel Dunbar | 3a183d3 | 2009-06-08 21:48:20 +0000 | [diff] [blame] | 243 | |
| 244 | // Handle dependency file generation. |
Daniel Dunbar | 9eb93b0 | 2010-12-08 21:33:40 +0000 | [diff] [blame] | 245 | if ((A = Args.getLastArg(options::OPT_M, options::OPT_MM)) || |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 246 | (A = Args.getLastArg(options::OPT_MD)) || |
| 247 | (A = Args.getLastArg(options::OPT_MMD))) { |
| 248 | // Determine the output location. |
| 249 | const char *DepFile; |
Benjamin Kramer | 99c7208 | 2012-09-26 19:01:49 +0000 | [diff] [blame] | 250 | if (Arg *MF = Args.getLastArg(options::OPT_MF)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 251 | DepFile = MF->getValue(); |
Chad Rosier | 9d71863 | 2013-01-24 19:14:47 +0000 | [diff] [blame] | 252 | C.addFailureResultFile(DepFile, &JA); |
Benjamin Kramer | 99c7208 | 2012-09-26 19:01:49 +0000 | [diff] [blame] | 253 | } else if (Output.getType() == types::TY_Dependencies) { |
| 254 | DepFile = Output.getFilename(); |
Daniel Dunbar | b827a05 | 2009-11-19 03:26:40 +0000 | [diff] [blame] | 255 | } else if (A->getOption().matches(options::OPT_M) || |
| 256 | A->getOption().matches(options::OPT_MM)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 257 | DepFile = "-"; |
| 258 | } else { |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 259 | DepFile = getDependencyFileName(Args, Inputs); |
Chad Rosier | 9d71863 | 2013-01-24 19:14:47 +0000 | [diff] [blame] | 260 | C.addFailureResultFile(DepFile, &JA); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 261 | } |
| 262 | CmdArgs.push_back("-dependency-file"); |
| 263 | CmdArgs.push_back(DepFile); |
| 264 | |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 265 | // Add a default target if one wasn't specified. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 266 | if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) { |
| 267 | const char *DepTarget; |
| 268 | |
| 269 | // If user provided -o, that is the dependency target, except |
| 270 | // when we are only generating a dependency file. |
| 271 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 272 | if (OutputOpt && Output.getType() != types::TY_Dependencies) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 273 | DepTarget = OutputOpt->getValue(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 274 | } else { |
| 275 | // Otherwise derive from the base input. |
| 276 | // |
| 277 | // FIXME: This should use the computed output file location. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 278 | SmallString<128> P(Inputs[0].getBaseInput()); |
Michael J. Spencer | 472ccff | 2010-12-18 00:19:12 +0000 | [diff] [blame] | 279 | llvm::sys::path::replace_extension(P, "o"); |
| 280 | DepTarget = Args.MakeArgString(llvm::sys::path::filename(P)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | CmdArgs.push_back("-MT"); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 284 | SmallString<128> Quoted; |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 285 | QuoteTarget(DepTarget, Quoted); |
| 286 | CmdArgs.push_back(Args.MakeArgString(Quoted)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Daniel Dunbar | b827a05 | 2009-11-19 03:26:40 +0000 | [diff] [blame] | 289 | if (A->getOption().matches(options::OPT_M) || |
| 290 | A->getOption().matches(options::OPT_MD)) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 291 | CmdArgs.push_back("-sys-header-deps"); |
| 292 | } |
| 293 | |
Peter Collingbourne | bb52786 | 2011-07-12 19:35:15 +0000 | [diff] [blame] | 294 | if (Args.hasArg(options::OPT_MG)) { |
| 295 | if (!A || A->getOption().matches(options::OPT_MD) || |
| 296 | A->getOption().matches(options::OPT_MMD)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 297 | D.Diag(diag::err_drv_mg_requires_m_or_mm); |
Peter Collingbourne | bb52786 | 2011-07-12 19:35:15 +0000 | [diff] [blame] | 298 | CmdArgs.push_back("-MG"); |
| 299 | } |
| 300 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 301 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 302 | |
| 303 | // Convert all -MQ <target> args to -MT <quoted target> |
| 304 | for (arg_iterator it = Args.filtered_begin(options::OPT_MT, |
| 305 | options::OPT_MQ), |
| 306 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 307 | const Arg *A = *it; |
| 308 | A->claim(); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 309 | |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 310 | if (A->getOption().matches(options::OPT_MQ)) { |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 311 | CmdArgs.push_back("-MT"); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 312 | SmallString<128> Quoted; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 313 | QuoteTarget(A->getValue(), Quoted); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 314 | CmdArgs.push_back(Args.MakeArgString(Quoted)); |
| 315 | |
| 316 | // -MT flag - no change |
| 317 | } else { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 318 | A->render(Args, CmdArgs); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 319 | } |
| 320 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 321 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 322 | // Add -i* options, and automatically translate to |
| 323 | // -include-pch/-include-pth for transparent PCH support. It's |
| 324 | // wonky, but we include looking for .gch so we can support seamless |
| 325 | // replacement into a build system already set up to be generating |
| 326 | // .gch files. |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 327 | bool RenderedImplicitInclude = false; |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 328 | for (arg_iterator it = Args.filtered_begin(options::OPT_clang_i_Group), |
| 329 | ie = Args.filtered_end(); it != ie; ++it) { |
| 330 | const Arg *A = it; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 331 | |
| 332 | if (A->getOption().matches(options::OPT_include)) { |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 333 | bool IsFirstImplicitInclude = !RenderedImplicitInclude; |
| 334 | RenderedImplicitInclude = true; |
| 335 | |
Argyrios Kyrtzidis | e5c3537 | 2010-08-11 23:27:58 +0000 | [diff] [blame] | 336 | // Use PCH if the user requested it. |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 337 | bool UsePCH = D.CCCUsePCH; |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 338 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 339 | bool FoundPTH = false; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 340 | bool FoundPCH = false; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 341 | llvm::sys::Path P(A->getValue()); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 342 | bool Exists; |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 343 | if (UsePCH) { |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 344 | P.appendSuffix("pch"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 345 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 346 | FoundPCH = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 347 | else |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 348 | P.eraseSuffix(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 351 | if (!FoundPCH) { |
| 352 | P.appendSuffix("pth"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 353 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 354 | FoundPTH = true; |
| 355 | else |
| 356 | P.eraseSuffix(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 359 | if (!FoundPCH && !FoundPTH) { |
| 360 | P.appendSuffix("gch"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 361 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) { |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 362 | FoundPCH = UsePCH; |
| 363 | FoundPTH = !UsePCH; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 364 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | else |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 366 | P.eraseSuffix(); |
| 367 | } |
| 368 | |
| 369 | if (FoundPCH || FoundPTH) { |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 370 | if (IsFirstImplicitInclude) { |
| 371 | A->claim(); |
| 372 | if (UsePCH) |
| 373 | CmdArgs.push_back("-include-pch"); |
| 374 | else |
| 375 | CmdArgs.push_back("-include-pth"); |
| 376 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 377 | continue; |
| 378 | } else { |
| 379 | // Ignore the PCH if not first on command line and emit warning. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 380 | D.Diag(diag::warn_drv_pch_not_first_include) |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 381 | << P.str() << A->getAsString(Args); |
| 382 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
| 386 | // Not translated, render as usual. |
| 387 | A->claim(); |
| 388 | A->render(Args, CmdArgs); |
| 389 | } |
| 390 | |
| 391 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 392 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F, |
| 393 | options::OPT_index_header_map); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 394 | |
| 395 | // Add -Wp, and -Xassembler if using the preprocessor. |
| 396 | |
| 397 | // FIXME: There is a very unfortunate problem here, some troubled |
| 398 | // souls abuse -Wp, to pass preprocessor options in gcc syntax. To |
| 399 | // really support that we would have to parse and then translate |
| 400 | // those options. :( |
| 401 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 402 | options::OPT_Xpreprocessor); |
Daniel Dunbar | 607d7f6 | 2009-10-29 01:53:44 +0000 | [diff] [blame] | 403 | |
| 404 | // -I- is a deprecated GCC feature, reject it. |
| 405 | if (Arg *A = Args.getLastArg(options::OPT_I_)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 406 | D.Diag(diag::err_drv_I_dash_not_supported) << A->getAsString(Args); |
Chandler Carruth | feee58c | 2010-10-20 07:00:47 +0000 | [diff] [blame] | 407 | |
| 408 | // If we have a --sysroot, and don't have an explicit -isysroot flag, add an |
| 409 | // -isysroot to the CC1 invocation. |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 410 | StringRef sysroot = C.getSysRoot(); |
| 411 | if (sysroot != "") { |
Chandler Carruth | feee58c | 2010-10-20 07:00:47 +0000 | [diff] [blame] | 412 | if (!Args.hasArg(options::OPT_isysroot)) { |
| 413 | CmdArgs.push_back("-isysroot"); |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 414 | CmdArgs.push_back(C.getArgs().MakeArgString(sysroot)); |
Chandler Carruth | feee58c | 2010-10-20 07:00:47 +0000 | [diff] [blame] | 415 | } |
| 416 | } |
Douglas Gregor | 8ee51ef | 2011-09-14 20:28:46 +0000 | [diff] [blame] | 417 | |
| 418 | // If a module path was provided, pass it along. Otherwise, use a temporary |
| 419 | // directory. |
| 420 | if (Arg *A = Args.getLastArg(options::OPT_fmodule_cache_path)) { |
Douglas Gregor | 8ee51ef | 2011-09-14 20:28:46 +0000 | [diff] [blame] | 421 | A->claim(); |
| 422 | A->render(Args, CmdArgs); |
| 423 | } else { |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 424 | SmallString<128> DefaultModuleCache; |
Douglas Gregor | 8ee51ef | 2011-09-14 20:28:46 +0000 | [diff] [blame] | 425 | llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/false, |
| 426 | DefaultModuleCache); |
| 427 | llvm::sys::path::append(DefaultModuleCache, "clang-module-cache"); |
| 428 | CmdArgs.push_back("-fmodule-cache-path"); |
| 429 | CmdArgs.push_back(Args.MakeArgString(DefaultModuleCache)); |
| 430 | } |
Douglas Gregor | fba18aa | 2011-09-15 22:00:41 +0000 | [diff] [blame] | 431 | |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 432 | // Parse additional include paths from environment variables. |
Chandler Carruth | b5870e7 | 2011-11-04 07:12:58 +0000 | [diff] [blame] | 433 | // FIXME: We should probably sink the logic for handling these from the |
| 434 | // frontend into the driver. It will allow deleting 4 otherwise unused flags. |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 435 | // CPATH - included following the user specified includes (but prior to |
| 436 | // builtin and standard includes). |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 437 | addDirectoryList(Args, CmdArgs, "-I", "CPATH"); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 438 | // C_INCLUDE_PATH - system includes enabled when compiling C. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 439 | addDirectoryList(Args, CmdArgs, "-c-isystem", "C_INCLUDE_PATH"); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 440 | // CPLUS_INCLUDE_PATH - system includes enabled when compiling C++. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 441 | addDirectoryList(Args, CmdArgs, "-cxx-isystem", "CPLUS_INCLUDE_PATH"); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 442 | // OBJC_INCLUDE_PATH - system includes enabled when compiling ObjC. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 443 | addDirectoryList(Args, CmdArgs, "-objc-isystem", "OBJC_INCLUDE_PATH"); |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 444 | // OBJCPLUS_INCLUDE_PATH - system includes enabled when compiling ObjC++. |
Bill Wendling | 3d71715 | 2012-03-12 22:10:06 +0000 | [diff] [blame] | 445 | addDirectoryList(Args, CmdArgs, "-objcxx-isystem", "OBJCPLUS_INCLUDE_PATH"); |
Chandler Carruth | 88491fc | 2011-11-04 07:12:53 +0000 | [diff] [blame] | 446 | |
Chandler Carruth | 88491fc | 2011-11-04 07:12:53 +0000 | [diff] [blame] | 447 | // Add C++ include arguments, if needed. |
Chandler Carruth | a461442 | 2011-11-04 07:43:33 +0000 | [diff] [blame] | 448 | if (types::isCXX(Inputs[0].getType())) |
Chandler Carruth | 7ffa032 | 2011-11-04 07:34:47 +0000 | [diff] [blame] | 449 | getToolChain().AddClangCXXStdlibIncludeArgs(Args, CmdArgs); |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 450 | |
| 451 | // Add system include arguments. |
| 452 | getToolChain().AddClangSystemIncludeArgs(Args, CmdArgs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 455 | /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 456 | /// CPU. |
| 457 | // |
| 458 | // FIXME: This is redundant with -mcpu, why does LLVM use this. |
| 459 | // FIXME: tblgen this, or kill it! |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 460 | static const char *getLLVMArchSuffixForARM(StringRef CPU) { |
Chad Rosier | ae1aee6 | 2011-10-07 17:48:56 +0000 | [diff] [blame] | 461 | return llvm::StringSwitch<const char *>(CPU) |
| 462 | .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "v4t") |
| 463 | .Cases("arm720t", "arm9", "arm9tdmi", "v4t") |
| 464 | .Cases("arm920", "arm920t", "arm922t", "v4t") |
| 465 | .Cases("arm940t", "ep9312","v4t") |
| 466 | .Cases("arm10tdmi", "arm1020t", "v5") |
| 467 | .Cases("arm9e", "arm926ej-s", "arm946e-s", "v5e") |
| 468 | .Cases("arm966e-s", "arm968e-s", "arm10e", "v5e") |
| 469 | .Cases("arm1020e", "arm1022e", "xscale", "iwmmxt", "v5e") |
| 470 | .Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", "v6") |
| 471 | .Cases("arm1176jzf-s", "mpcorenovfp", "mpcore", "v6") |
| 472 | .Cases("arm1156t2-s", "arm1156t2f-s", "v6t2") |
Quentin Colombet | 74632aa | 2012-11-29 23:15:27 +0000 | [diff] [blame] | 473 | .Cases("cortex-a5", "cortex-a8", "cortex-a9", "cortex-a15", "v7") |
Quentin Colombet | ab13751 | 2012-12-21 17:57:47 +0000 | [diff] [blame] | 474 | .Case("cortex-r5", "v7r") |
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 | |
Rafael Espindola | 27fa236 | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 668 | case llvm::Triple::FreeBSD: |
| 669 | // FreeBSD defaults to soft float |
| 670 | FloatABI = "soft"; |
| 671 | break; |
| 672 | |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 673 | default: |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 674 | switch(Triple.getEnvironment()) { |
Jiangning Liu | ff104a1 | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 675 | case llvm::Triple::GNUEABIHF: |
| 676 | FloatABI = "hard"; |
| 677 | break; |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 678 | case llvm::Triple::GNUEABI: |
| 679 | FloatABI = "softfp"; |
| 680 | break; |
| 681 | case llvm::Triple::EABI: |
| 682 | // EABI is always AAPCS, and if it was not marked 'hard', it's softfp |
| 683 | FloatABI = "softfp"; |
| 684 | break; |
Logan Chien | 94a7142 | 2012-09-02 09:30:11 +0000 | [diff] [blame] | 685 | case llvm::Triple::Android: { |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 686 | std::string ArchName = |
Chandler Carruth | b43550b | 2012-01-10 19:47:42 +0000 | [diff] [blame] | 687 | getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple)); |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 688 | if (StringRef(ArchName).startswith("v7")) |
Chandler Carruth | b43550b | 2012-01-10 19:47:42 +0000 | [diff] [blame] | 689 | FloatABI = "softfp"; |
| 690 | else |
| 691 | FloatABI = "soft"; |
| 692 | break; |
| 693 | } |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 694 | default: |
| 695 | // Assume "soft", but warn the user we are guessing. |
| 696 | FloatABI = "soft"; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 697 | D.Diag(diag::warn_drv_assuming_mfloat_abi_is) << "soft"; |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 698 | break; |
| 699 | } |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 703 | return FloatABI; |
| 704 | } |
| 705 | |
| 706 | |
| 707 | void Clang::AddARMTargetArgs(const ArgList &Args, |
| 708 | ArgStringList &CmdArgs, |
| 709 | bool KernelOrKext) const { |
| 710 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 711 | // Get the effective triple, which takes into account the deployment target. |
| 712 | std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); |
| 713 | llvm::Triple Triple(TripleStr); |
Daniel Dunbar | 2e4e110 | 2012-10-22 18:30:51 +0000 | [diff] [blame] | 714 | std::string CPUName = getARMTargetCPU(Args, Triple); |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 715 | |
| 716 | // Select the ABI to use. |
| 717 | // |
| 718 | // FIXME: Support -meabi. |
| 719 | const char *ABIName = 0; |
| 720 | if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 721 | ABIName = A->getValue(); |
Daniel Dunbar | 2e4e110 | 2012-10-22 18:30:51 +0000 | [diff] [blame] | 722 | } else if (Triple.isOSDarwin()) { |
| 723 | // The backend is hardwired to assume AAPCS for M-class processors, ensure |
| 724 | // the frontend matches that. |
| 725 | if (StringRef(CPUName).startswith("cortex-m")) { |
| 726 | ABIName = "aapcs"; |
| 727 | } else { |
| 728 | ABIName = "apcs-gnu"; |
| 729 | } |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 730 | } else { |
| 731 | // Select the default based on the platform. |
| 732 | switch(Triple.getEnvironment()) { |
Logan Chien | 94a7142 | 2012-09-02 09:30:11 +0000 | [diff] [blame] | 733 | case llvm::Triple::Android: |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 734 | case llvm::Triple::GNUEABI: |
Jiangning Liu | ff104a1 | 2012-07-31 08:06:29 +0000 | [diff] [blame] | 735 | case llvm::Triple::GNUEABIHF: |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 736 | ABIName = "aapcs-linux"; |
| 737 | break; |
| 738 | case llvm::Triple::EABI: |
| 739 | ABIName = "aapcs"; |
| 740 | break; |
| 741 | default: |
| 742 | ABIName = "apcs-gnu"; |
| 743 | } |
| 744 | } |
| 745 | CmdArgs.push_back("-target-abi"); |
| 746 | CmdArgs.push_back(ABIName); |
| 747 | |
| 748 | // Set the CPU based on -march= and -mcpu=. |
| 749 | CmdArgs.push_back("-target-cpu"); |
Daniel Dunbar | 2e4e110 | 2012-10-22 18:30:51 +0000 | [diff] [blame] | 750 | CmdArgs.push_back(Args.MakeArgString(CPUName)); |
Anton Korobeynikov | e257179 | 2012-04-09 13:38:30 +0000 | [diff] [blame] | 751 | |
| 752 | // Determine floating point ABI from the options & target defaults. |
| 753 | StringRef FloatABI = getARMFloatABI(D, Args, Triple); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 754 | if (FloatABI == "soft") { |
| 755 | // Floating point operations and argument passing are soft. |
| 756 | // |
| 757 | // FIXME: This changes CPP defines, we need -target-soft-float. |
Daniel Dunbar | 3b31526 | 2009-11-30 08:42:00 +0000 | [diff] [blame] | 758 | CmdArgs.push_back("-msoft-float"); |
Daniel Dunbar | 87667aa | 2009-12-08 19:49:51 +0000 | [diff] [blame] | 759 | CmdArgs.push_back("-mfloat-abi"); |
| 760 | CmdArgs.push_back("soft"); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 761 | } else if (FloatABI == "softfp") { |
| 762 | // Floating point operations are hard, but argument passing is soft. |
Daniel Dunbar | 87667aa | 2009-12-08 19:49:51 +0000 | [diff] [blame] | 763 | CmdArgs.push_back("-mfloat-abi"); |
| 764 | CmdArgs.push_back("soft"); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 765 | } else { |
| 766 | // Floating point operations and argument passing are hard. |
| 767 | assert(FloatABI == "hard" && "Invalid float abi!"); |
Daniel Dunbar | 87667aa | 2009-12-08 19:49:51 +0000 | [diff] [blame] | 768 | CmdArgs.push_back("-mfloat-abi"); |
| 769 | CmdArgs.push_back("hard"); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 770 | } |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 771 | |
| 772 | // Set appropriate target features for floating point mode. |
| 773 | // |
| 774 | // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these |
| 775 | // yet (it uses the -mfloat-abi and -msoft-float options above), and it is |
| 776 | // stripped out by the ARM target. |
| 777 | |
| 778 | // Use software floating point operations? |
| 779 | if (FloatABI == "soft") { |
| 780 | CmdArgs.push_back("-target-feature"); |
| 781 | CmdArgs.push_back("+soft-float"); |
| 782 | } |
| 783 | |
| 784 | // Use software floating point argument passing? |
| 785 | if (FloatABI != "hard") { |
| 786 | CmdArgs.push_back("-target-feature"); |
| 787 | CmdArgs.push_back("+soft-float-abi"); |
| 788 | } |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 789 | |
| 790 | // Honor -mfpu=. |
Chad Rosier | 9931727 | 2012-04-04 20:51:35 +0000 | [diff] [blame] | 791 | if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) |
Chad Rosier | f80f2a5 | 2012-04-04 20:56:36 +0000 | [diff] [blame] | 792 | addFPUArgs(D, A, Args, CmdArgs); |
Daniel Dunbar | 7187fac | 2011-03-17 00:07:34 +0000 | [diff] [blame] | 793 | |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 794 | // Honor -mfpmath=. |
| 795 | if (const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) |
Chad Rosier | 30fe6ba | 2012-04-04 22:13:40 +0000 | [diff] [blame] | 796 | addFPMathArgs(D, A, Args, CmdArgs, getARMTargetCPU(Args, Triple)); |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 797 | |
Daniel Dunbar | 7187fac | 2011-03-17 00:07:34 +0000 | [diff] [blame] | 798 | // Setting -msoft-float effectively disables NEON because of the GCC |
| 799 | // implementation, although the same isn't true of VFP or VFP3. |
| 800 | if (FloatABI == "soft") { |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 801 | CmdArgs.push_back("-target-feature"); |
| 802 | CmdArgs.push_back("-neon"); |
| 803 | } |
| 804 | |
| 805 | // Kernel code has more strict alignment requirements. |
| 806 | if (KernelOrKext) { |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 807 | if (Triple.getOS() != llvm::Triple::IOS || Triple.isOSVersionLT(6)) { |
| 808 | CmdArgs.push_back("-backend-option"); |
| 809 | CmdArgs.push_back("-arm-long-calls"); |
| 810 | } |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 811 | |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 812 | CmdArgs.push_back("-backend-option"); |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 813 | CmdArgs.push_back("-arm-strict-align"); |
Daniel Dunbar | b5fbb89 | 2011-04-18 21:26:42 +0000 | [diff] [blame] | 814 | |
| 815 | // The kext linker doesn't know how to deal with movw/movt. |
Daniel Dunbar | b5fbb89 | 2011-04-18 21:26:42 +0000 | [diff] [blame] | 816 | CmdArgs.push_back("-backend-option"); |
| 817 | CmdArgs.push_back("-arm-darwin-use-movt=0"); |
Daniel Dunbar | 7187fac | 2011-03-17 00:07:34 +0000 | [diff] [blame] | 818 | } |
Chad Rosier | 1b90605 | 2011-08-26 00:26:29 +0000 | [diff] [blame] | 819 | |
| 820 | // Setting -mno-global-merge disables the codegen global merge pass. Setting |
| 821 | // -mglobal-merge has no effect as the pass is enabled by default. |
| 822 | if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge, |
| 823 | options::OPT_mno_global_merge)) { |
| 824 | if (A->getOption().matches(options::OPT_mno_global_merge)) |
| 825 | CmdArgs.push_back("-mno-global-merge"); |
| 826 | } |
Chad Rosier | ee9ad5c | 2012-05-16 20:40:09 +0000 | [diff] [blame] | 827 | |
Chad Rosier | 005af27 | 2012-05-16 21:19:55 +0000 | [diff] [blame] | 828 | if (Args.hasArg(options::OPT_mno_implicit_float)) |
Chad Rosier | ee9ad5c | 2012-05-16 20:40:09 +0000 | [diff] [blame] | 829 | CmdArgs.push_back("-no-implicit-float"); |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 830 | } |
| 831 | |
Simon Atanasyan | 8e1c598 | 2012-09-21 20:19:32 +0000 | [diff] [blame] | 832 | // Translate MIPS CPU name alias option to CPU name. |
| 833 | static StringRef getMipsCPUFromAlias(const Arg &A) { |
| 834 | if (A.getOption().matches(options::OPT_mips32)) |
| 835 | return "mips32"; |
| 836 | if (A.getOption().matches(options::OPT_mips32r2)) |
| 837 | return "mips32r2"; |
| 838 | if (A.getOption().matches(options::OPT_mips64)) |
| 839 | return "mips64"; |
| 840 | if (A.getOption().matches(options::OPT_mips64r2)) |
| 841 | return "mips64r2"; |
| 842 | llvm_unreachable("Unexpected option"); |
| 843 | return ""; |
| 844 | } |
| 845 | |
Simon Atanasyan | a2768be | 2012-04-07 22:09:23 +0000 | [diff] [blame] | 846 | // Get CPU and ABI names. They are not independent |
| 847 | // so we have to calculate them together. |
| 848 | static void getMipsCPUAndABI(const ArgList &Args, |
| 849 | const ToolChain &TC, |
| 850 | StringRef &CPUName, |
| 851 | StringRef &ABIName) { |
Simon Atanasyan | 89d83ff | 2012-09-10 08:32:41 +0000 | [diff] [blame] | 852 | const char *DefMips32CPU = "mips32"; |
| 853 | const char *DefMips64CPU = "mips64"; |
Akira Hatanaka | 9f36062 | 2011-09-26 21:07:52 +0000 | [diff] [blame] | 854 | |
Simon Atanasyan | 89d83ff | 2012-09-10 08:32:41 +0000 | [diff] [blame] | 855 | if (Arg *A = Args.getLastArg(options::OPT_march_EQ, |
Simon Atanasyan | 8e1c598 | 2012-09-21 20:19:32 +0000 | [diff] [blame] | 856 | options::OPT_mcpu_EQ, |
| 857 | options::OPT_mips_CPUs_Group)) { |
| 858 | if (A->getOption().matches(options::OPT_mips_CPUs_Group)) |
| 859 | CPUName = getMipsCPUFromAlias(*A); |
| 860 | else |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 861 | CPUName = A->getValue(); |
Simon Atanasyan | 8e1c598 | 2012-09-21 20:19:32 +0000 | [diff] [blame] | 862 | } |
Simon Atanasyan | 89d83ff | 2012-09-10 08:32:41 +0000 | [diff] [blame] | 863 | |
Akira Hatanaka | 9f36062 | 2011-09-26 21:07:52 +0000 | [diff] [blame] | 864 | if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 865 | ABIName = A->getValue(); |
Simon Atanasyan | 89d83ff | 2012-09-10 08:32:41 +0000 | [diff] [blame] | 866 | |
| 867 | // Setup default CPU and ABI names. |
| 868 | if (CPUName.empty() && ABIName.empty()) { |
| 869 | switch (TC.getTriple().getArch()) { |
| 870 | default: |
| 871 | llvm_unreachable("Unexpected triple arch name"); |
| 872 | case llvm::Triple::mips: |
| 873 | case llvm::Triple::mipsel: |
| 874 | CPUName = DefMips32CPU; |
| 875 | break; |
| 876 | case llvm::Triple::mips64: |
| 877 | case llvm::Triple::mips64el: |
| 878 | CPUName = DefMips64CPU; |
| 879 | break; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | if (!ABIName.empty()) { |
| 884 | // Deduce CPU name from ABI name. |
| 885 | CPUName = llvm::StringSwitch<const char *>(ABIName) |
| 886 | .Cases("o32", "eabi", DefMips32CPU) |
| 887 | .Cases("n32", "n64", DefMips64CPU) |
| 888 | .Default(""); |
| 889 | } |
| 890 | else if (!CPUName.empty()) { |
| 891 | // Deduce ABI name from CPU name. |
| 892 | ABIName = llvm::StringSwitch<const char *>(CPUName) |
| 893 | .Cases("mips32", "mips32r2", "o32") |
| 894 | .Cases("mips64", "mips64r2", "n64") |
| 895 | .Default(""); |
| 896 | } |
| 897 | |
| 898 | // FIXME: Warn on inconsistent cpu and abi usage. |
Simon Atanasyan | a2768be | 2012-04-07 22:09:23 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Simon Atanasyan | 5e62779 | 2012-06-02 15:06:29 +0000 | [diff] [blame] | 901 | // Select the MIPS float ABI as determined by -msoft-float, -mhard-float, |
| 902 | // and -mfloat-abi=. |
| 903 | static StringRef getMipsFloatABI(const Driver &D, const ArgList &Args) { |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 904 | // Select the float ABI as determined by -msoft-float, -mhard-float, |
| 905 | // and -mfloat-abi=. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 906 | StringRef FloatABI; |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 907 | if (Arg *A = Args.getLastArg(options::OPT_msoft_float, |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 908 | options::OPT_mhard_float, |
| 909 | options::OPT_mfloat_abi_EQ)) { |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 910 | if (A->getOption().matches(options::OPT_msoft_float)) |
| 911 | FloatABI = "soft"; |
| 912 | else if (A->getOption().matches(options::OPT_mhard_float)) |
| 913 | FloatABI = "hard"; |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 914 | else { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 915 | FloatABI = A->getValue(); |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 916 | if (FloatABI != "soft" && FloatABI != "single" && FloatABI != "hard") { |
Simon Atanasyan | 5e62779 | 2012-06-02 15:06:29 +0000 | [diff] [blame] | 917 | D.Diag(diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args); |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 918 | FloatABI = "hard"; |
| 919 | } |
| 920 | } |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | // If unspecified, choose the default based on the platform. |
| 924 | if (FloatABI.empty()) { |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 925 | // Assume "hard", because it's a default value used by gcc. |
| 926 | // When we start to recognize specific target MIPS processors, |
| 927 | // we will be able to select the default more correctly. |
| 928 | FloatABI = "hard"; |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 929 | } |
| 930 | |
Simon Atanasyan | 5e62779 | 2012-06-02 15:06:29 +0000 | [diff] [blame] | 931 | return FloatABI; |
| 932 | } |
| 933 | |
Simon Atanasyan | dc536f5 | 2012-07-05 18:51:43 +0000 | [diff] [blame] | 934 | static void AddTargetFeature(const ArgList &Args, |
| 935 | ArgStringList &CmdArgs, |
| 936 | OptSpecifier OnOpt, |
| 937 | OptSpecifier OffOpt, |
| 938 | StringRef FeatureName) { |
| 939 | if (Arg *A = Args.getLastArg(OnOpt, OffOpt)) { |
| 940 | CmdArgs.push_back("-target-feature"); |
| 941 | if (A->getOption().matches(OnOpt)) |
| 942 | CmdArgs.push_back(Args.MakeArgString("+" + FeatureName)); |
| 943 | else |
| 944 | CmdArgs.push_back(Args.MakeArgString("-" + FeatureName)); |
| 945 | } |
| 946 | } |
| 947 | |
Simon Atanasyan | 5e62779 | 2012-06-02 15:06:29 +0000 | [diff] [blame] | 948 | void Clang::AddMIPSTargetArgs(const ArgList &Args, |
| 949 | ArgStringList &CmdArgs) const { |
| 950 | const Driver &D = getToolChain().getDriver(); |
| 951 | StringRef CPUName; |
| 952 | StringRef ABIName; |
| 953 | getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName); |
| 954 | |
| 955 | CmdArgs.push_back("-target-cpu"); |
| 956 | CmdArgs.push_back(CPUName.data()); |
| 957 | |
| 958 | CmdArgs.push_back("-target-abi"); |
| 959 | CmdArgs.push_back(ABIName.data()); |
| 960 | |
| 961 | StringRef FloatABI = getMipsFloatABI(D, Args); |
| 962 | |
Simon Atanasyan | e1d792f | 2013-01-10 12:36:19 +0000 | [diff] [blame] | 963 | bool IsMips16 = Args.getLastArg(options::OPT_mips16) != NULL; |
| 964 | |
| 965 | if (FloatABI == "soft" || (FloatABI == "hard" && IsMips16)) { |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 966 | // Floating point operations and argument passing are soft. |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 967 | CmdArgs.push_back("-msoft-float"); |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 968 | CmdArgs.push_back("-mfloat-abi"); |
| 969 | CmdArgs.push_back("soft"); |
| 970 | |
| 971 | // FIXME: Note, this is a hack. We need to pass the selected float |
| 972 | // mode to the MipsTargetInfoBase to define appropriate macros there. |
| 973 | // Now it is the only method. |
| 974 | CmdArgs.push_back("-target-feature"); |
| 975 | CmdArgs.push_back("+soft-float"); |
Simon Atanasyan | e1d792f | 2013-01-10 12:36:19 +0000 | [diff] [blame] | 976 | |
| 977 | if (FloatABI == "hard" && IsMips16) { |
| 978 | CmdArgs.push_back("-mllvm"); |
| 979 | CmdArgs.push_back("-mips16-hard-float"); |
| 980 | } |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 981 | } |
| 982 | else if (FloatABI == "single") { |
| 983 | // Restrict the use of hardware floating-point |
| 984 | // instructions to 32-bit operations. |
| 985 | CmdArgs.push_back("-target-feature"); |
| 986 | CmdArgs.push_back("+single-float"); |
| 987 | } |
| 988 | else { |
| 989 | // Floating point operations and argument passing are hard. |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 990 | assert(FloatABI == "hard" && "Invalid float abi!"); |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 991 | CmdArgs.push_back("-mfloat-abi"); |
| 992 | CmdArgs.push_back("hard"); |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 993 | } |
Simon Atanasyan | 0b273ef | 2012-07-05 14:19:39 +0000 | [diff] [blame] | 994 | |
Simon Atanasyan | dc536f5 | 2012-07-05 18:51:43 +0000 | [diff] [blame] | 995 | AddTargetFeature(Args, CmdArgs, |
| 996 | options::OPT_mips16, options::OPT_mno_mips16, |
| 997 | "mips16"); |
Simon Atanasyan | d797a85 | 2012-07-05 19:23:00 +0000 | [diff] [blame] | 998 | AddTargetFeature(Args, CmdArgs, |
| 999 | options::OPT_mdsp, options::OPT_mno_dsp, |
| 1000 | "dsp"); |
| 1001 | AddTargetFeature(Args, CmdArgs, |
| 1002 | options::OPT_mdspr2, options::OPT_mno_dspr2, |
| 1003 | "dspr2"); |
Simon Atanasyan | 9804b76 | 2012-08-27 20:55:56 +0000 | [diff] [blame] | 1004 | |
Simon Atanasyan | bda07ac | 2012-12-01 18:27:21 +0000 | [diff] [blame] | 1005 | if (Arg *A = Args.getLastArg(options::OPT_mxgot, options::OPT_mno_xgot)) { |
| 1006 | if (A->getOption().matches(options::OPT_mxgot)) { |
| 1007 | CmdArgs.push_back("-mllvm"); |
| 1008 | CmdArgs.push_back("-mxgot"); |
| 1009 | } |
| 1010 | } |
| 1011 | |
Simon Atanasyan | 9804b76 | 2012-08-27 20:55:56 +0000 | [diff] [blame] | 1012 | if (Arg *A = Args.getLastArg(options::OPT_G)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1013 | StringRef v = A->getValue(); |
Simon Atanasyan | 9804b76 | 2012-08-27 20:55:56 +0000 | [diff] [blame] | 1014 | CmdArgs.push_back("-mllvm"); |
| 1015 | CmdArgs.push_back(Args.MakeArgString("-mips-ssection-threshold=" + v)); |
| 1016 | A->claim(); |
| 1017 | } |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Hal Finkel | 02a8427 | 2012-06-11 22:35:19 +0000 | [diff] [blame] | 1020 | /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting. |
| 1021 | static std::string getPPCTargetCPU(const ArgList &Args) { |
| 1022 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1023 | StringRef CPUName = A->getValue(); |
Hal Finkel | 02a8427 | 2012-06-11 22:35:19 +0000 | [diff] [blame] | 1024 | |
| 1025 | if (CPUName == "native") { |
| 1026 | std::string CPU = llvm::sys::getHostCPUName(); |
| 1027 | if (!CPU.empty() && CPU != "generic") |
| 1028 | return CPU; |
| 1029 | else |
| 1030 | return ""; |
| 1031 | } |
| 1032 | |
| 1033 | return llvm::StringSwitch<const char *>(CPUName) |
| 1034 | .Case("common", "generic") |
| 1035 | .Case("440", "440") |
| 1036 | .Case("440fp", "440") |
| 1037 | .Case("450", "450") |
| 1038 | .Case("601", "601") |
| 1039 | .Case("602", "602") |
| 1040 | .Case("603", "603") |
| 1041 | .Case("603e", "603e") |
| 1042 | .Case("603ev", "603ev") |
| 1043 | .Case("604", "604") |
| 1044 | .Case("604e", "604e") |
| 1045 | .Case("620", "620") |
| 1046 | .Case("G3", "g3") |
| 1047 | .Case("7400", "7400") |
| 1048 | .Case("G4", "g4") |
| 1049 | .Case("7450", "7450") |
| 1050 | .Case("G4+", "g4+") |
| 1051 | .Case("750", "750") |
| 1052 | .Case("970", "970") |
| 1053 | .Case("G5", "g5") |
| 1054 | .Case("a2", "a2") |
Hal Finkel | 7de3296 | 2012-09-18 22:25:03 +0000 | [diff] [blame] | 1055 | .Case("e500mc", "e500mc") |
| 1056 | .Case("e5500", "e5500") |
Hal Finkel | 02a8427 | 2012-06-11 22:35:19 +0000 | [diff] [blame] | 1057 | .Case("power6", "pwr6") |
| 1058 | .Case("power7", "pwr7") |
| 1059 | .Case("powerpc", "ppc") |
| 1060 | .Case("powerpc64", "ppc64") |
| 1061 | .Default(""); |
| 1062 | } |
| 1063 | |
| 1064 | return ""; |
| 1065 | } |
| 1066 | |
| 1067 | void Clang::AddPPCTargetArgs(const ArgList &Args, |
| 1068 | ArgStringList &CmdArgs) const { |
| 1069 | std::string TargetCPUName = getPPCTargetCPU(Args); |
| 1070 | |
| 1071 | // LLVM may default to generating code for the native CPU, |
| 1072 | // but, like gcc, we default to a more generic option for |
| 1073 | // each architecture. (except on Darwin) |
| 1074 | llvm::Triple Triple = getToolChain().getTriple(); |
| 1075 | if (TargetCPUName.empty() && !Triple.isOSDarwin()) { |
| 1076 | if (Triple.getArch() == llvm::Triple::ppc64) |
| 1077 | TargetCPUName = "ppc64"; |
| 1078 | else |
| 1079 | TargetCPUName = "ppc"; |
| 1080 | } |
| 1081 | |
| 1082 | if (!TargetCPUName.empty()) { |
| 1083 | CmdArgs.push_back("-target-cpu"); |
| 1084 | CmdArgs.push_back(Args.MakeArgString(TargetCPUName.c_str())); |
| 1085 | } |
| 1086 | } |
| 1087 | |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1088 | void Clang::AddSparcTargetArgs(const ArgList &Args, |
| 1089 | ArgStringList &CmdArgs) const { |
| 1090 | const Driver &D = getToolChain().getDriver(); |
| 1091 | |
| 1092 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1093 | CmdArgs.push_back("-target-cpu"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1094 | CmdArgs.push_back(A->getValue()); |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | // Select the float ABI as determined by -msoft-float, -mhard-float, and |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1098 | StringRef FloatABI; |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1099 | if (Arg *A = Args.getLastArg(options::OPT_msoft_float, |
| 1100 | options::OPT_mhard_float)) { |
| 1101 | if (A->getOption().matches(options::OPT_msoft_float)) |
| 1102 | FloatABI = "soft"; |
| 1103 | else if (A->getOption().matches(options::OPT_mhard_float)) |
| 1104 | FloatABI = "hard"; |
| 1105 | } |
| 1106 | |
| 1107 | // If unspecified, choose the default based on the platform. |
| 1108 | if (FloatABI.empty()) { |
| 1109 | switch (getToolChain().getTriple().getOS()) { |
| 1110 | default: |
| 1111 | // Assume "soft", but warn the user we are guessing. |
| 1112 | FloatABI = "soft"; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1113 | D.Diag(diag::warn_drv_assuming_mfloat_abi_is) << "soft"; |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1114 | break; |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | if (FloatABI == "soft") { |
| 1119 | // Floating point operations and argument passing are soft. |
| 1120 | // |
| 1121 | // FIXME: This changes CPP defines, we need -target-soft-float. |
| 1122 | CmdArgs.push_back("-msoft-float"); |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1123 | CmdArgs.push_back("-target-feature"); |
| 1124 | CmdArgs.push_back("+soft-float"); |
| 1125 | } else { |
| 1126 | assert(FloatABI == "hard" && "Invalid float abi!"); |
| 1127 | CmdArgs.push_back("-mhard-float"); |
| 1128 | } |
| 1129 | } |
| 1130 | |
Chandler Carruth | 700d4e4 | 2013-01-13 11:46:33 +0000 | [diff] [blame] | 1131 | static const char *getX86TargetCPU(const ArgList &Args, |
| 1132 | const llvm::Triple &Triple) { |
| 1133 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
| 1134 | if (StringRef(A->getValue()) != "native") |
| 1135 | return A->getValue(); |
| 1136 | |
| 1137 | // FIXME: Reject attempts to use -march=native unless the target matches |
| 1138 | // the host. |
| 1139 | // |
| 1140 | // FIXME: We should also incorporate the detected target features for use |
| 1141 | // with -native. |
| 1142 | std::string CPU = llvm::sys::getHostCPUName(); |
| 1143 | if (!CPU.empty() && CPU != "generic") |
| 1144 | return Args.MakeArgString(CPU); |
| 1145 | } |
| 1146 | |
| 1147 | // Select the default CPU if none was given (or detection failed). |
| 1148 | |
| 1149 | if (Triple.getArch() != llvm::Triple::x86_64 && |
| 1150 | Triple.getArch() != llvm::Triple::x86) |
| 1151 | return 0; // This routine is only handling x86 targets. |
| 1152 | |
| 1153 | bool Is64Bit = Triple.getArch() == llvm::Triple::x86_64; |
| 1154 | |
| 1155 | // FIXME: Need target hooks. |
| 1156 | if (Triple.isOSDarwin()) |
| 1157 | return Is64Bit ? "core2" : "yonah"; |
| 1158 | |
| 1159 | // Everything else goes to x86-64 in 64-bit mode. |
| 1160 | if (Is64Bit) |
| 1161 | return "x86-64"; |
| 1162 | |
| 1163 | if (Triple.getOSName().startswith("haiku")) |
| 1164 | return "i586"; |
| 1165 | if (Triple.getOSName().startswith("openbsd")) |
| 1166 | return "i486"; |
| 1167 | if (Triple.getOSName().startswith("bitrig")) |
| 1168 | return "i686"; |
| 1169 | if (Triple.getOSName().startswith("freebsd")) |
| 1170 | return "i486"; |
| 1171 | if (Triple.getOSName().startswith("netbsd")) |
| 1172 | return "i486"; |
| 1173 | // All x86 devices running Android have core2 as their common |
| 1174 | // denominator. This makes a better choice than pentium4. |
| 1175 | if (Triple.getEnvironment() == llvm::Triple::Android) |
| 1176 | return "core2"; |
| 1177 | |
| 1178 | // Fallback to p4. |
| 1179 | return "pentium4"; |
| 1180 | } |
| 1181 | |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1182 | void Clang::AddX86TargetArgs(const ArgList &Args, |
| 1183 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 1184 | if (!Args.hasFlag(options::OPT_mred_zone, |
| 1185 | options::OPT_mno_red_zone, |
| 1186 | true) || |
| 1187 | Args.hasArg(options::OPT_mkernel) || |
| 1188 | Args.hasArg(options::OPT_fapple_kext)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 1189 | CmdArgs.push_back("-disable-red-zone"); |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 1190 | |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 1191 | if (Args.hasFlag(options::OPT_msoft_float, |
| 1192 | options::OPT_mno_soft_float, |
| 1193 | false)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 1194 | CmdArgs.push_back("-no-implicit-float"); |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 1195 | |
Chandler Carruth | 700d4e4 | 2013-01-13 11:46:33 +0000 | [diff] [blame] | 1196 | if (const char *CPUName = getX86TargetCPU(Args, getToolChain().getTriple())) { |
Daniel Dunbar | 38b48af | 2009-12-18 06:30:12 +0000 | [diff] [blame] | 1197 | CmdArgs.push_back("-target-cpu"); |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 1198 | CmdArgs.push_back(CPUName); |
| 1199 | } |
| 1200 | |
Eli Friedman | d18eeca | 2011-07-02 00:34:19 +0000 | [diff] [blame] | 1201 | // The required algorithm here is slightly strange: the options are applied |
| 1202 | // in order (so -mno-sse -msse2 disables SSE3), but any option that gets |
| 1203 | // directly overridden later is ignored (so "-mno-sse -msse2 -mno-sse2 -msse" |
| 1204 | // is equivalent to "-mno-sse2 -msse"). The -cc1 handling deals with the |
| 1205 | // former correctly, but not the latter; handle directly-overridden |
| 1206 | // attributes here. |
| 1207 | llvm::StringMap<unsigned> PrevFeature; |
| 1208 | std::vector<const char*> Features; |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 1209 | for (arg_iterator it = Args.filtered_begin(options::OPT_m_x86_Features_Group), |
| 1210 | ie = Args.filtered_end(); it != ie; ++it) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1211 | StringRef Name = (*it)->getOption().getName(); |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1212 | (*it)->claim(); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1213 | |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 1214 | // Skip over "-m". |
Michael J. Spencer | c635710 | 2012-10-22 22:13:48 +0000 | [diff] [blame] | 1215 | assert(Name.startswith("m") && "Invalid feature name."); |
| 1216 | Name = Name.substr(1); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1217 | |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 1218 | bool IsNegative = Name.startswith("no-"); |
| 1219 | if (IsNegative) |
| 1220 | Name = Name.substr(3); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1221 | |
Eli Friedman | d18eeca | 2011-07-02 00:34:19 +0000 | [diff] [blame] | 1222 | unsigned& Prev = PrevFeature[Name]; |
| 1223 | if (Prev) |
| 1224 | Features[Prev - 1] = 0; |
| 1225 | Prev = Features.size() + 1; |
| 1226 | Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); |
| 1227 | } |
| 1228 | for (unsigned i = 0; i < Features.size(); i++) { |
| 1229 | if (Features[i]) { |
| 1230 | CmdArgs.push_back("-target-feature"); |
| 1231 | CmdArgs.push_back(Features[i]); |
| 1232 | } |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
Matthew Curtis | 33c95f1 | 2012-12-06 17:49:03 +0000 | [diff] [blame] | 1236 | static inline bool HasPICArg(const ArgList &Args) { |
| 1237 | return Args.hasArg(options::OPT_fPIC) |
| 1238 | || Args.hasArg(options::OPT_fpic); |
| 1239 | } |
| 1240 | |
| 1241 | static Arg *GetLastSmallDataThresholdArg(const ArgList &Args) { |
| 1242 | return Args.getLastArg(options::OPT_G, |
| 1243 | options::OPT_G_EQ, |
| 1244 | options::OPT_msmall_data_threshold_EQ); |
| 1245 | } |
| 1246 | |
| 1247 | static std::string GetHexagonSmallDataThresholdValue(const ArgList &Args) { |
| 1248 | std::string value; |
| 1249 | if (HasPICArg(Args)) |
| 1250 | value = "0"; |
| 1251 | else if (Arg *A = GetLastSmallDataThresholdArg(Args)) { |
| 1252 | value = A->getValue(); |
| 1253 | A->claim(); |
| 1254 | } |
| 1255 | return value; |
| 1256 | } |
| 1257 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1258 | void Clang::AddHexagonTargetArgs(const ArgList &Args, |
| 1259 | ArgStringList &CmdArgs) const { |
| 1260 | llvm::Triple Triple = getToolChain().getTriple(); |
| 1261 | |
| 1262 | CmdArgs.push_back("-target-cpu"); |
Matthew Curtis | 6781415 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 1263 | CmdArgs.push_back(Args.MakeArgString( |
| 1264 | "hexagon" |
| 1265 | + toolchains::Hexagon_TC::GetTargetCPU(Args))); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1266 | CmdArgs.push_back("-fno-signed-char"); |
Matthew Curtis | 1dbaef5 | 2012-12-07 13:52:44 +0000 | [diff] [blame] | 1267 | CmdArgs.push_back("-mqdsp6-compat"); |
| 1268 | CmdArgs.push_back("-Wreturn-type"); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1269 | |
Matthew Curtis | 33c95f1 | 2012-12-06 17:49:03 +0000 | [diff] [blame] | 1270 | std::string SmallDataThreshold = GetHexagonSmallDataThresholdValue(Args); |
| 1271 | if (!SmallDataThreshold.empty()) { |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1272 | CmdArgs.push_back ("-mllvm"); |
Matthew Curtis | 33c95f1 | 2012-12-06 17:49:03 +0000 | [diff] [blame] | 1273 | CmdArgs.push_back(Args.MakeArgString( |
| 1274 | "-hexagon-small-data-threshold=" + SmallDataThreshold)); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Sirish Pande | 5f9688b | 2012-05-10 20:19:54 +0000 | [diff] [blame] | 1277 | if (!Args.hasArg(options::OPT_fno_short_enums)) |
| 1278 | CmdArgs.push_back("-fshort-enums"); |
| 1279 | if (Args.getLastArg(options::OPT_mieee_rnd_near)) { |
| 1280 | CmdArgs.push_back ("-mllvm"); |
| 1281 | CmdArgs.push_back ("-enable-hexagon-ieee-rnd-near"); |
| 1282 | } |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 1283 | CmdArgs.push_back ("-mllvm"); |
| 1284 | CmdArgs.push_back ("-machine-sink-split=0"); |
| 1285 | } |
| 1286 | |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1287 | static bool |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1288 | shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime, |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1289 | const llvm::Triple &Triple) { |
| 1290 | // We use the zero-cost exception tables for Objective-C if the non-fragile |
| 1291 | // ABI is enabled or when compiling for x86_64 and ARM on Snow Leopard and |
| 1292 | // later. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1293 | if (runtime.isNonFragile()) |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1294 | return true; |
| 1295 | |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 1296 | if (!Triple.isOSDarwin()) |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1297 | return false; |
| 1298 | |
Eric Christopher | aa7333c | 2011-07-02 00:20:22 +0000 | [diff] [blame] | 1299 | return (!Triple.isMacOSXVersionLT(10,5) && |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1300 | (Triple.getArch() == llvm::Triple::x86_64 || |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1301 | Triple.getArch() == llvm::Triple::arm)); |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1304 | /// addExceptionArgs - Adds exception related arguments to the driver command |
| 1305 | /// arguments. There's a master flag, -fexceptions and also language specific |
| 1306 | /// flags to enable/disable C++ and Objective-C exceptions. |
| 1307 | /// This makes it possible to for example disable C++ exceptions but enable |
| 1308 | /// Objective-C exceptions. |
| 1309 | static void addExceptionArgs(const ArgList &Args, types::ID InputType, |
| 1310 | const llvm::Triple &Triple, |
Fariborz Jahanian | 15b7731 | 2012-04-04 18:28:00 +0000 | [diff] [blame] | 1311 | bool KernelOrKext, |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1312 | const ObjCRuntime &objcRuntime, |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1313 | ArgStringList &CmdArgs) { |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 1314 | if (KernelOrKext) { |
| 1315 | // -mkernel and -fapple-kext imply no exceptions, so claim exception related |
| 1316 | // arguments now to avoid warnings about unused arguments. |
| 1317 | Args.ClaimAllArgs(options::OPT_fexceptions); |
| 1318 | Args.ClaimAllArgs(options::OPT_fno_exceptions); |
| 1319 | Args.ClaimAllArgs(options::OPT_fobjc_exceptions); |
| 1320 | Args.ClaimAllArgs(options::OPT_fno_objc_exceptions); |
| 1321 | Args.ClaimAllArgs(options::OPT_fcxx_exceptions); |
| 1322 | Args.ClaimAllArgs(options::OPT_fno_cxx_exceptions); |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1323 | return; |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 1324 | } |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1325 | |
| 1326 | // Exceptions are enabled by default. |
| 1327 | bool ExceptionsEnabled = true; |
| 1328 | |
| 1329 | // This keeps track of whether exceptions were explicitly turned on or off. |
| 1330 | bool DidHaveExplicitExceptionFlag = false; |
| 1331 | |
Rafael Espindola | f759df0 | 2009-10-01 13:33:33 +0000 | [diff] [blame] | 1332 | if (Arg *A = Args.getLastArg(options::OPT_fexceptions, |
| 1333 | options::OPT_fno_exceptions)) { |
| 1334 | if (A->getOption().matches(options::OPT_fexceptions)) |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1335 | ExceptionsEnabled = true; |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1336 | else |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1337 | ExceptionsEnabled = false; |
| 1338 | |
| 1339 | DidHaveExplicitExceptionFlag = true; |
Rafael Espindola | f759df0 | 2009-10-01 13:33:33 +0000 | [diff] [blame] | 1340 | } |
Daniel Dunbar | 1a2cd4f | 2010-09-14 23:12:31 +0000 | [diff] [blame] | 1341 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1342 | bool ShouldUseExceptionTables = false; |
Fariborz Jahanian | 85caf03 | 2009-10-01 20:30:46 +0000 | [diff] [blame] | 1343 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1344 | // Exception tables and cleanups can be enabled with -fexceptions even if the |
| 1345 | // language itself doesn't support exceptions. |
| 1346 | if (ExceptionsEnabled && DidHaveExplicitExceptionFlag) |
| 1347 | ShouldUseExceptionTables = true; |
Daniel Dunbar | 1a2cd4f | 2010-09-14 23:12:31 +0000 | [diff] [blame] | 1348 | |
Daniel Dunbar | d47ea69 | 2011-03-17 23:28:31 +0000 | [diff] [blame] | 1349 | // Obj-C exceptions are enabled by default, regardless of -fexceptions. This |
| 1350 | // is not necessarily sensible, but follows GCC. |
| 1351 | if (types::isObjC(InputType) && |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1352 | Args.hasFlag(options::OPT_fobjc_exceptions, |
Daniel Dunbar | d47ea69 | 2011-03-17 23:28:31 +0000 | [diff] [blame] | 1353 | options::OPT_fno_objc_exceptions, |
| 1354 | true)) { |
| 1355 | CmdArgs.push_back("-fobjc-exceptions"); |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1356 | |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1357 | ShouldUseExceptionTables |= |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1358 | shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple); |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | if (types::isCXX(InputType)) { |
| 1362 | bool CXXExceptionsEnabled = ExceptionsEnabled; |
| 1363 | |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 1364 | if (Arg *A = Args.getLastArg(options::OPT_fcxx_exceptions, |
| 1365 | options::OPT_fno_cxx_exceptions, |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1366 | options::OPT_fexceptions, |
| 1367 | options::OPT_fno_exceptions)) { |
| 1368 | if (A->getOption().matches(options::OPT_fcxx_exceptions)) |
| 1369 | CXXExceptionsEnabled = true; |
Chandler Carruth | 43f220f | 2011-02-28 07:25:18 +0000 | [diff] [blame] | 1370 | else if (A->getOption().matches(options::OPT_fno_cxx_exceptions)) |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1371 | CXXExceptionsEnabled = false; |
| 1372 | } |
| 1373 | |
| 1374 | if (CXXExceptionsEnabled) { |
| 1375 | CmdArgs.push_back("-fcxx-exceptions"); |
| 1376 | |
| 1377 | ShouldUseExceptionTables = true; |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | if (ShouldUseExceptionTables) |
| 1382 | CmdArgs.push_back("-fexceptions"); |
Rafael Espindola | f759df0 | 2009-10-01 13:33:33 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Rafael Espindola | 61b1efe | 2011-05-02 17:43:32 +0000 | [diff] [blame] | 1385 | static bool ShouldDisableCFI(const ArgList &Args, |
| 1386 | const ToolChain &TC) { |
Rafael Espindola | 701ec8d | 2012-03-08 14:39:55 +0000 | [diff] [blame] | 1387 | bool Default = true; |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 1388 | if (TC.getTriple().isOSDarwin()) { |
Rafael Espindola | 97f6abb | 2011-05-17 16:26:17 +0000 | [diff] [blame] | 1389 | // The native darwin assembler doesn't support cfi directives, so |
Rafael Espindola | cb77392 | 2011-05-17 19:06:58 +0000 | [diff] [blame] | 1390 | // 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] | 1391 | Default = Args.hasFlag(options::OPT_integrated_as, |
Eric Christopher | 27e2b98 | 2012-12-18 00:31:10 +0000 | [diff] [blame] | 1392 | options::OPT_no_integrated_as, |
| 1393 | TC.IsIntegratedAssemblerDefault()); |
Rafael Espindola | 97f6abb | 2011-05-17 16:26:17 +0000 | [diff] [blame] | 1394 | } |
Rafael Espindola | 701ec8d | 2012-03-08 14:39:55 +0000 | [diff] [blame] | 1395 | return !Args.hasFlag(options::OPT_fdwarf2_cfi_asm, |
Eric Christopher | 27e2b98 | 2012-12-18 00:31:10 +0000 | [diff] [blame] | 1396 | options::OPT_fno_dwarf2_cfi_asm, |
| 1397 | Default); |
Rafael Espindola | 61b1efe | 2011-05-02 17:43:32 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 1400 | static bool ShouldDisableDwarfDirectory(const ArgList &Args, |
| 1401 | const ToolChain &TC) { |
| 1402 | bool IsIADefault = TC.IsIntegratedAssemblerDefault(); |
| 1403 | bool UseIntegratedAs = Args.hasFlag(options::OPT_integrated_as, |
| 1404 | options::OPT_no_integrated_as, |
| 1405 | IsIADefault); |
| 1406 | bool UseDwarfDirectory = Args.hasFlag(options::OPT_fdwarf_directory_asm, |
| 1407 | options::OPT_fno_dwarf_directory_asm, |
| 1408 | UseIntegratedAs); |
| 1409 | return !UseDwarfDirectory; |
| 1410 | } |
| 1411 | |
Joerg Sonnenberger | 359cf92 | 2011-05-06 14:35:16 +0000 | [diff] [blame] | 1412 | /// \brief Check whether the given input tree contains any compilation actions. |
| 1413 | static bool ContainsCompileAction(const Action *A) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1414 | if (isa<CompileJobAction>(A)) |
Joerg Sonnenberger | 359cf92 | 2011-05-06 14:35:16 +0000 | [diff] [blame] | 1415 | return true; |
| 1416 | |
| 1417 | for (Action::const_iterator it = A->begin(), ie = A->end(); it != ie; ++it) |
| 1418 | if (ContainsCompileAction(*it)) |
| 1419 | return true; |
| 1420 | |
| 1421 | return false; |
| 1422 | } |
| 1423 | |
| 1424 | /// \brief Check if -relax-all should be passed to the internal assembler. |
| 1425 | /// This is done by default when compiling non-assembler source with -O0. |
| 1426 | static bool UseRelaxAll(Compilation &C, const ArgList &Args) { |
| 1427 | bool RelaxDefault = true; |
| 1428 | |
| 1429 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) |
| 1430 | RelaxDefault = A->getOption().matches(options::OPT_O0); |
| 1431 | |
| 1432 | if (RelaxDefault) { |
| 1433 | RelaxDefault = false; |
| 1434 | for (ActionList::const_iterator it = C.getActions().begin(), |
| 1435 | ie = C.getActions().end(); it != ie; ++it) { |
| 1436 | if (ContainsCompileAction(*it)) { |
| 1437 | RelaxDefault = true; |
| 1438 | break; |
| 1439 | } |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | return Args.hasFlag(options::OPT_mrelax_all, options::OPT_mno_relax_all, |
| 1444 | RelaxDefault); |
| 1445 | } |
| 1446 | |
Alexey Samsonov | a40548c | 2013-01-16 11:34:36 +0000 | [diff] [blame] | 1447 | SanitizerArgs::SanitizerArgs(const Driver &D, const ArgList &Args) |
Alexey Samsonov | 4bdc604 | 2013-01-20 13:12:12 +0000 | [diff] [blame] | 1448 | : Kind(0), BlacklistFile(""), MsanTrackOrigins(false), |
| 1449 | AsanZeroBaseShadow(false) { |
Alexey Samsonov | 3e335c1 | 2013-01-28 07:20:44 +0000 | [diff] [blame] | 1450 | unsigned AllKinds = 0; // All kinds of sanitizers that were turned on |
| 1451 | // at least once (possibly, disabled further). |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1452 | 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] | 1453 | unsigned Add, Remove; |
| 1454 | if (!parse(D, Args, *I, Add, Remove, true)) |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1455 | continue; |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1456 | (*I)->claim(); |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 1457 | Kind |= Add; |
| 1458 | Kind &= ~Remove; |
Alexey Samsonov | 3e335c1 | 2013-01-28 07:20:44 +0000 | [diff] [blame] | 1459 | AllKinds |= Add; |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
Chad Rosier | 78d85b1 | 2013-01-29 23:31:22 +0000 | [diff] [blame] | 1462 | UbsanTrapOnError = |
| 1463 | Args.hasArg(options::OPT_fcatch_undefined_behavior) || |
| 1464 | Args.hasFlag(options::OPT_fsanitize_undefined_trap_on_error, |
| 1465 | options::OPT_fno_sanitize_undefined_trap_on_error, false); |
| 1466 | |
| 1467 | if (Args.hasArg(options::OPT_fcatch_undefined_behavior) && |
| 1468 | !Args.hasFlag(options::OPT_fsanitize_undefined_trap_on_error, |
| 1469 | options::OPT_fno_sanitize_undefined_trap_on_error, true)) { |
| 1470 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 1471 | << "-fcatch-undefined-behavior" |
| 1472 | << "-fno-sanitize-undefined-trap-on-error"; |
| 1473 | } |
| 1474 | |
| 1475 | // Warn about undefined sanitizer options that require runtime support. |
| 1476 | if (UbsanTrapOnError && notAllowedWithTrap()) { |
| 1477 | if (Args.hasArg(options::OPT_fcatch_undefined_behavior)) |
| 1478 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 1479 | << lastArgumentForKind(D, Args, NotAllowedWithTrap) |
| 1480 | << "-fcatch-undefined-behavior"; |
| 1481 | else if (Args.hasFlag(options::OPT_fsanitize_undefined_trap_on_error, |
| 1482 | options::OPT_fno_sanitize_undefined_trap_on_error, |
| 1483 | false)) |
| 1484 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 1485 | << lastArgumentForKind(D, Args, NotAllowedWithTrap) |
| 1486 | << "-fsanitize-undefined-trap-on-error"; |
| 1487 | } |
| 1488 | |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1489 | // Only one runtime library can be used at once. |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 1490 | bool NeedsAsan = needsAsanRt(); |
| 1491 | bool NeedsTsan = needsTsanRt(); |
Evgeniy Stepanov | 99469f7 | 2012-12-05 13:37:12 +0000 | [diff] [blame] | 1492 | bool NeedsMsan = needsMsanRt(); |
Richard Smith | 0565037 | 2012-12-01 01:02:45 +0000 | [diff] [blame] | 1493 | if (NeedsAsan && NeedsTsan) |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1494 | D.Diag(diag::err_drv_argument_not_allowed_with) |
Richard Smith | 0565037 | 2012-12-01 01:02:45 +0000 | [diff] [blame] | 1495 | << lastArgumentForKind(D, Args, NeedsAsanRt) |
| 1496 | << lastArgumentForKind(D, Args, NeedsTsanRt); |
Evgeniy Stepanov | 99469f7 | 2012-12-05 13:37:12 +0000 | [diff] [blame] | 1497 | if (NeedsAsan && NeedsMsan) |
| 1498 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 1499 | << lastArgumentForKind(D, Args, NeedsAsanRt) |
| 1500 | << lastArgumentForKind(D, Args, NeedsMsanRt); |
| 1501 | if (NeedsTsan && NeedsMsan) |
| 1502 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 1503 | << lastArgumentForKind(D, Args, NeedsTsanRt) |
| 1504 | << lastArgumentForKind(D, Args, NeedsMsanRt); |
Alexey Samsonov | 4d1a6e4 | 2012-11-29 22:36:21 +0000 | [diff] [blame] | 1505 | |
| 1506 | // If -fsanitize contains extra features of ASan, it should also |
Alexey Samsonov | 3e335c1 | 2013-01-28 07:20:44 +0000 | [diff] [blame] | 1507 | // explicitly contain -fsanitize=address (probably, turned off later in the |
| 1508 | // command line). |
| 1509 | if ((Kind & AddressFull) != 0 && (AllKinds & Address) == 0) |
| 1510 | D.Diag(diag::warn_drv_unused_sanitizer) |
| 1511 | << lastArgumentForKind(D, Args, AddressFull) |
| 1512 | << "-fsanitize=address"; |
Alexey Samsonov | 91ecfa6 | 2012-12-03 19:12:58 +0000 | [diff] [blame] | 1513 | |
| 1514 | // Parse -f(no-)sanitize-blacklist options. |
| 1515 | if (Arg *BLArg = Args.getLastArg(options::OPT_fsanitize_blacklist, |
| 1516 | options::OPT_fno_sanitize_blacklist)) { |
| 1517 | if (BLArg->getOption().matches(options::OPT_fsanitize_blacklist)) { |
| 1518 | std::string BLPath = BLArg->getValue(); |
| 1519 | bool BLExists = false; |
| 1520 | if (!llvm::sys::fs::exists(BLPath, BLExists) && BLExists) |
| 1521 | BlacklistFile = BLPath; |
| 1522 | else |
| 1523 | D.Diag(diag::err_drv_no_such_file) << BLPath; |
| 1524 | } |
| 1525 | } |
Evgeniy Stepanov | 34ef11b | 2012-12-24 08:42:34 +0000 | [diff] [blame] | 1526 | |
| 1527 | // Parse -f(no-)sanitize-memory-track-origins options. |
Alexey Samsonov | 4bdc604 | 2013-01-20 13:12:12 +0000 | [diff] [blame] | 1528 | if (NeedsMsan) |
Evgeniy Stepanov | 34ef11b | 2012-12-24 08:42:34 +0000 | [diff] [blame] | 1529 | MsanTrackOrigins = |
| 1530 | Args.hasFlag(options::OPT_fsanitize_memory_track_origins, |
| 1531 | options::OPT_fno_sanitize_memory_track_origins, |
| 1532 | /* Default */false); |
Alexey Samsonov | 4bdc604 | 2013-01-20 13:12:12 +0000 | [diff] [blame] | 1533 | |
| 1534 | // Parse -f(no-)sanitize-address-zero-base-shadow options. |
| 1535 | if (NeedsAsan) |
| 1536 | AsanZeroBaseShadow = |
| 1537 | Args.hasFlag(options::OPT_fsanitize_address_zero_base_shadow, |
| 1538 | options::OPT_fno_sanitize_address_zero_base_shadow, |
| 1539 | /* Default */false); |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Kostya Serebryany | dff466c | 2011-11-30 01:39:16 +0000 | [diff] [blame] | 1542 | /// If AddressSanitizer is enabled, add appropriate linker flags (Linux). |
| 1543 | /// This needs to be called before we add the C run-time (malloc, etc). |
| 1544 | static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args, |
Kostya Serebryany | 7b5f101 | 2011-12-06 19:18:44 +0000 | [diff] [blame] | 1545 | ArgStringList &CmdArgs) { |
Logan Chien | 94a7142 | 2012-09-02 09:30:11 +0000 | [diff] [blame] | 1546 | if(TC.getTriple().getEnvironment() == llvm::Triple::Android) { |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 1547 | if (!Args.hasArg(options::OPT_shared)) { |
Evgeniy Stepanov | 8373862 | 2012-06-04 11:15:05 +0000 | [diff] [blame] | 1548 | if (!Args.hasArg(options::OPT_pie)) |
| 1549 | TC.getDriver().Diag(diag::err_drv_asan_android_requires_pie); |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 1550 | } |
Daniel Dunbar | 8cd0d25 | 2011-12-07 23:22:17 +0000 | [diff] [blame] | 1551 | |
Evgeniy Stepanov | 8ba7541 | 2012-09-12 09:09:08 +0000 | [diff] [blame] | 1552 | SmallString<128> LibAsan(TC.getDriver().ResourceDir); |
| 1553 | llvm::sys::path::append(LibAsan, "lib", "linux", |
| 1554 | (Twine("libclang_rt.asan-") + |
| 1555 | TC.getArchName() + "-android.so")); |
Matt Beaumont-Gay | 45b2738 | 2012-12-04 21:18:26 +0000 | [diff] [blame] | 1556 | CmdArgs.insert(CmdArgs.begin(), Args.MakeArgString(LibAsan)); |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 1557 | } else { |
| 1558 | if (!Args.hasArg(options::OPT_shared)) { |
Alexey Samsonov | 4bdc604 | 2013-01-20 13:12:12 +0000 | [diff] [blame] | 1559 | bool ZeroBaseShadow = Args.hasFlag( |
| 1560 | options::OPT_fsanitize_address_zero_base_shadow, |
| 1561 | options::OPT_fno_sanitize_address_zero_base_shadow, false); |
| 1562 | if (ZeroBaseShadow && !Args.hasArg(options::OPT_pie)) { |
| 1563 | TC.getDriver().Diag(diag::err_drv_argument_only_allowed_with) << |
| 1564 | "-fsanitize-address-zero-base-shadow" << "-pie"; |
| 1565 | } |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 1566 | // LibAsan is "libclang_rt.asan-<ArchName>.a" in the Linux library |
| 1567 | // resource directory. |
| 1568 | SmallString<128> LibAsan(TC.getDriver().ResourceDir); |
| 1569 | llvm::sys::path::append(LibAsan, "lib", "linux", |
| 1570 | (Twine("libclang_rt.asan-") + |
| 1571 | TC.getArchName() + ".a")); |
Matt Beaumont-Gay | 45b2738 | 2012-12-04 21:18:26 +0000 | [diff] [blame] | 1572 | // The ASan runtime needs to come before -lstdc++ (or -lc++, libstdc++.a, |
| 1573 | // etc.) so that the linker picks ASan's versions of the global 'operator |
| 1574 | // new' and 'operator delete' symbols. We take the extreme (but simple) |
Chandler Carruth | 1d15398 | 2012-12-04 22:54:37 +0000 | [diff] [blame] | 1575 | // strategy of inserting it at the front of the link command. It also |
| 1576 | // needs to be forced to end up in the executable, so wrap it in |
| 1577 | // whole-archive. |
| 1578 | SmallVector<const char*, 3> PrefixArgs; |
| 1579 | PrefixArgs.push_back("-whole-archive"); |
| 1580 | PrefixArgs.push_back(Args.MakeArgString(LibAsan)); |
| 1581 | PrefixArgs.push_back("-no-whole-archive"); |
| 1582 | CmdArgs.insert(CmdArgs.begin(), PrefixArgs.begin(), PrefixArgs.end()); |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 1583 | CmdArgs.push_back("-lpthread"); |
| 1584 | CmdArgs.push_back("-ldl"); |
| 1585 | CmdArgs.push_back("-export-dynamic"); |
| 1586 | } |
| 1587 | } |
Kostya Serebryany | dff466c | 2011-11-30 01:39:16 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
Kostya Serebryany | f7efb0e | 2012-05-16 06:36:00 +0000 | [diff] [blame] | 1590 | /// If ThreadSanitizer is enabled, add appropriate linker flags (Linux). |
| 1591 | /// This needs to be called before we add the C run-time (malloc, etc). |
| 1592 | static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args, |
| 1593 | ArgStringList &CmdArgs) { |
Kostya Serebryany | f7efb0e | 2012-05-16 06:36:00 +0000 | [diff] [blame] | 1594 | if (!Args.hasArg(options::OPT_shared)) { |
Evgeniy Stepanov | 09ccf39 | 2012-12-03 13:20:43 +0000 | [diff] [blame] | 1595 | if (!Args.hasArg(options::OPT_pie)) |
Evgeniy Stepanov | 99469f7 | 2012-12-05 13:37:12 +0000 | [diff] [blame] | 1596 | TC.getDriver().Diag(diag::err_drv_argument_only_allowed_with) << |
| 1597 | "-fsanitize=thread" << "-pie"; |
Kostya Serebryany | f7efb0e | 2012-05-16 06:36:00 +0000 | [diff] [blame] | 1598 | // LibTsan is "libclang_rt.tsan-<ArchName>.a" in the Linux library |
| 1599 | // resource directory. |
| 1600 | SmallString<128> LibTsan(TC.getDriver().ResourceDir); |
| 1601 | llvm::sys::path::append(LibTsan, "lib", "linux", |
| 1602 | (Twine("libclang_rt.tsan-") + |
| 1603 | TC.getArchName() + ".a")); |
| 1604 | CmdArgs.push_back(Args.MakeArgString(LibTsan)); |
| 1605 | CmdArgs.push_back("-lpthread"); |
| 1606 | CmdArgs.push_back("-ldl"); |
| 1607 | CmdArgs.push_back("-export-dynamic"); |
| 1608 | } |
| 1609 | } |
| 1610 | |
Evgeniy Stepanov | 09ccf39 | 2012-12-03 13:20:43 +0000 | [diff] [blame] | 1611 | /// If MemorySanitizer is enabled, add appropriate linker flags (Linux). |
| 1612 | /// This needs to be called before we add the C run-time (malloc, etc). |
| 1613 | static void addMsanRTLinux(const ToolChain &TC, const ArgList &Args, |
| 1614 | ArgStringList &CmdArgs) { |
| 1615 | if (!Args.hasArg(options::OPT_shared)) { |
| 1616 | if (!Args.hasArg(options::OPT_pie)) |
Evgeniy Stepanov | 99469f7 | 2012-12-05 13:37:12 +0000 | [diff] [blame] | 1617 | TC.getDriver().Diag(diag::err_drv_argument_only_allowed_with) << |
| 1618 | "-fsanitize=memory" << "-pie"; |
Evgeniy Stepanov | 09ccf39 | 2012-12-03 13:20:43 +0000 | [diff] [blame] | 1619 | // LibMsan is "libclang_rt.msan-<ArchName>.a" in the Linux library |
| 1620 | // resource directory. |
| 1621 | SmallString<128> LibMsan(TC.getDriver().ResourceDir); |
| 1622 | llvm::sys::path::append(LibMsan, "lib", "linux", |
| 1623 | (Twine("libclang_rt.msan-") + |
| 1624 | TC.getArchName() + ".a")); |
| 1625 | CmdArgs.push_back(Args.MakeArgString(LibMsan)); |
| 1626 | CmdArgs.push_back("-lpthread"); |
| 1627 | CmdArgs.push_back("-ldl"); |
| 1628 | CmdArgs.push_back("-export-dynamic"); |
| 1629 | } |
| 1630 | } |
| 1631 | |
Richard Smith | 4def70d | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 1632 | /// If UndefinedBehaviorSanitizer is enabled, add appropriate linker flags |
| 1633 | /// (Linux). |
| 1634 | static void addUbsanRTLinux(const ToolChain &TC, const ArgList &Args, |
| 1635 | ArgStringList &CmdArgs) { |
Richard Smith | 79188ae | 2013-01-18 22:09:26 +0000 | [diff] [blame] | 1636 | // LibUbsan is "libclang_rt.ubsan-<ArchName>.a" in the Linux library |
| 1637 | // resource directory. |
| 1638 | SmallString<128> LibUbsan(TC.getDriver().ResourceDir); |
| 1639 | llvm::sys::path::append(LibUbsan, "lib", "linux", |
| 1640 | (Twine("libclang_rt.ubsan-") + |
| 1641 | TC.getArchName() + ".a")); |
| 1642 | CmdArgs.push_back(Args.MakeArgString(LibUbsan)); |
| 1643 | CmdArgs.push_back("-lpthread"); |
| 1644 | CmdArgs.push_back("-export-dynamic"); |
Richard Smith | 4def70d | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Rafael Espindola | 6af27ec | 2011-12-14 21:02:23 +0000 | [diff] [blame] | 1647 | static bool shouldUseFramePointer(const ArgList &Args, |
| 1648 | const llvm::Triple &Triple) { |
| 1649 | if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer, |
| 1650 | options::OPT_fomit_frame_pointer)) |
| 1651 | return A->getOption().matches(options::OPT_fno_omit_frame_pointer); |
| 1652 | |
Rafael Espindola | a2a1789 | 2011-12-14 21:50:24 +0000 | [diff] [blame] | 1653 | // 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] | 1654 | if ((Triple.getArch() == llvm::Triple::x86_64 || |
| 1655 | Triple.getArch() == llvm::Triple::x86) && |
| 1656 | Triple.getOS() == llvm::Triple::Linux) { |
| 1657 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) |
| 1658 | if (!A->getOption().matches(options::OPT_O0)) |
| 1659 | return false; |
| 1660 | } |
| 1661 | |
| 1662 | return true; |
| 1663 | } |
| 1664 | |
Chandler Carruth | d566df6 | 2012-12-17 21:40:04 +0000 | [diff] [blame] | 1665 | /// If the PWD environment variable is set, add a CC1 option to specify the |
| 1666 | /// debug compilation directory. |
| 1667 | static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) { |
| 1668 | if (const char *pwd = ::getenv("PWD")) { |
| 1669 | // GCC also verifies that stat(pwd) and stat(".") have the same inode |
| 1670 | // number. Not doing those because stats are slow, but we could. |
| 1671 | if (llvm::sys::path::is_absolute(pwd)) { |
| 1672 | std::string CompDir = pwd; |
| 1673 | CmdArgs.push_back("-fdebug-compilation-dir"); |
| 1674 | CmdArgs.push_back(Args.MakeArgString(CompDir)); |
| 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1679 | void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 1680 | const InputInfo &Output, |
Daniel Dunbar | 62cf601 | 2009-03-18 06:07:59 +0000 | [diff] [blame] | 1681 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1682 | const ArgList &Args, |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1683 | const char *LinkingOutput) const { |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 1684 | bool KernelOrKext = Args.hasArg(options::OPT_mkernel, |
| 1685 | options::OPT_fapple_kext); |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1686 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1687 | ArgStringList CmdArgs; |
| 1688 | |
Daniel Dunbar | 077ba6a | 2009-03-31 20:53:55 +0000 | [diff] [blame] | 1689 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 1690 | |
Daniel Dunbar | 8ff5b28 | 2009-12-11 23:00:49 +0000 | [diff] [blame] | 1691 | // Invoke ourselves in -cc1 mode. |
| 1692 | // |
| 1693 | // FIXME: Implement custom jobs for internal actions. |
| 1694 | CmdArgs.push_back("-cc1"); |
| 1695 | |
Daniel Dunbar | dd4fe00 | 2009-10-30 18:12:20 +0000 | [diff] [blame] | 1696 | // Add the "effective" target triple. |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 1697 | CmdArgs.push_back("-triple"); |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 1698 | std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); |
Daniel Dunbar | dd4fe00 | 2009-10-30 18:12:20 +0000 | [diff] [blame] | 1699 | CmdArgs.push_back(Args.MakeArgString(TripleStr)); |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 1700 | |
Daniel Dunbar | dd4fe00 | 2009-10-30 18:12:20 +0000 | [diff] [blame] | 1701 | // Select the appropriate action. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1702 | RewriteKind rewriteKind = RK_None; |
Fariborz Jahanian | e982cc0 | 2012-04-04 18:50:28 +0000 | [diff] [blame] | 1703 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1704 | if (isa<AnalyzeJobAction>(JA)) { |
| 1705 | assert(JA.getType() == types::TY_Plist && "Invalid output type."); |
| 1706 | CmdArgs.push_back("-analyze"); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 1707 | } else if (isa<MigrateJobAction>(JA)) { |
| 1708 | CmdArgs.push_back("-migrate"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1709 | } else if (isa<PreprocessJobAction>(JA)) { |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 1710 | if (Output.getType() == types::TY_Dependencies) |
| 1711 | CmdArgs.push_back("-Eonly"); |
| 1712 | else |
| 1713 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 8767cbc | 2010-02-03 03:07:56 +0000 | [diff] [blame] | 1714 | } else if (isa<AssembleJobAction>(JA)) { |
| 1715 | CmdArgs.push_back("-emit-obj"); |
Daniel Dunbar | 9929800 | 2010-05-27 06:18:05 +0000 | [diff] [blame] | 1716 | |
Joerg Sonnenberger | 359cf92 | 2011-05-06 14:35:16 +0000 | [diff] [blame] | 1717 | if (UseRelaxAll(C, Args)) |
Daniel Dunbar | 9929800 | 2010-05-27 06:18:05 +0000 | [diff] [blame] | 1718 | CmdArgs.push_back("-mrelax-all"); |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 1719 | |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 1720 | // When using an integrated assembler, translate -Wa, and -Xassembler |
| 1721 | // options. |
| 1722 | for (arg_iterator it = Args.filtered_begin(options::OPT_Wa_COMMA, |
| 1723 | options::OPT_Xassembler), |
| 1724 | ie = Args.filtered_end(); it != ie; ++it) { |
| 1725 | const Arg *A = *it; |
| 1726 | A->claim(); |
| 1727 | |
| 1728 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1729 | StringRef Value = A->getValue(i); |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 1730 | |
| 1731 | if (Value == "-force_cpusubtype_ALL") { |
| 1732 | // 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] | 1733 | } else if (Value == "-L") { |
Daniel Dunbar | 9693232 | 2011-03-28 22:49:28 +0000 | [diff] [blame] | 1734 | CmdArgs.push_back("-msave-temp-labels"); |
Joerg Sonnenberger | 46a4939 | 2011-05-19 20:46:39 +0000 | [diff] [blame] | 1735 | } else if (Value == "--fatal-warnings") { |
Joerg Sonnenberger | d793350 | 2011-05-19 18:42:29 +0000 | [diff] [blame] | 1736 | CmdArgs.push_back("-mllvm"); |
| 1737 | CmdArgs.push_back("-fatal-assembler-warnings"); |
Nick Lewycky | c3b9014 | 2011-06-21 00:14:18 +0000 | [diff] [blame] | 1738 | } else if (Value == "--noexecstack") { |
| 1739 | CmdArgs.push_back("-mnoexecstack"); |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 1740 | } else { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1741 | D.Diag(diag::err_drv_unsupported_option_argument) |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 1742 | << A->getOption().getName() << Value; |
| 1743 | } |
| 1744 | } |
| 1745 | } |
Daniel Dunbar | d02bba8 | 2010-11-19 16:23:35 +0000 | [diff] [blame] | 1746 | |
| 1747 | // Also ignore explicit -force_cpusubtype_ALL option. |
| 1748 | (void) Args.hasArg(options::OPT_force__cpusubtype__ALL); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1749 | } else if (isa<PrecompileJobAction>(JA)) { |
Argyrios Kyrtzidis | e5c3537 | 2010-08-11 23:27:58 +0000 | [diff] [blame] | 1750 | // Use PCH if the user requested it. |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 1751 | bool UsePCH = D.CCCUsePCH; |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 1752 | |
Aaron Ballman | 761322b | 2012-07-31 01:21:00 +0000 | [diff] [blame] | 1753 | if (JA.getType() == types::TY_Nothing) |
| 1754 | CmdArgs.push_back("-fsyntax-only"); |
| 1755 | else if (UsePCH) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 1756 | CmdArgs.push_back("-emit-pch"); |
| 1757 | else |
| 1758 | CmdArgs.push_back("-emit-pth"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1759 | } else { |
| 1760 | assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool."); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1761 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1762 | if (JA.getType() == types::TY_Nothing) { |
| 1763 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 1764 | } else if (JA.getType() == types::TY_LLVM_IR || |
| 1765 | JA.getType() == types::TY_LTO_IR) { |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1766 | CmdArgs.push_back("-emit-llvm"); |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 1767 | } else if (JA.getType() == types::TY_LLVM_BC || |
| 1768 | JA.getType() == types::TY_LTO_BC) { |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1769 | CmdArgs.push_back("-emit-llvm-bc"); |
| 1770 | } else if (JA.getType() == types::TY_PP_Asm) { |
Daniel Dunbar | e3b8d07 | 2009-09-17 00:47:53 +0000 | [diff] [blame] | 1771 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 1772 | } else if (JA.getType() == types::TY_AST) { |
| 1773 | CmdArgs.push_back("-emit-pch"); |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 1774 | } else if (JA.getType() == types::TY_RewrittenObjC) { |
| 1775 | CmdArgs.push_back("-rewrite-objc"); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1776 | rewriteKind = RK_NonFragile; |
Fariborz Jahanian | 582b395 | 2012-04-02 15:59:19 +0000 | [diff] [blame] | 1777 | } else if (JA.getType() == types::TY_RewrittenLegacyObjC) { |
| 1778 | CmdArgs.push_back("-rewrite-objc"); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1779 | rewriteKind = RK_Fragile; |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 1780 | } else { |
| 1781 | assert(JA.getType() == types::TY_PP_Asm && |
| 1782 | "Unexpected output type!"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1783 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1786 | // The make clang go fast button. |
| 1787 | CmdArgs.push_back("-disable-free"); |
| 1788 | |
John McCall | b689afb | 2010-02-13 03:50:24 +0000 | [diff] [blame] | 1789 | // Disable the verification pass in -asserts builds. |
| 1790 | #ifdef NDEBUG |
| 1791 | CmdArgs.push_back("-disable-llvm-verifier"); |
| 1792 | #endif |
| 1793 | |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 1794 | // Set the main file name, so that debug info works even with |
| 1795 | // -save-temps. |
| 1796 | CmdArgs.push_back("-main-file-name"); |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 1797 | CmdArgs.push_back(getBaseInputName(Args, Inputs)); |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 1798 | |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 1799 | // Some flags which affect the language (via preprocessor |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 1800 | // defines). |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 1801 | if (Args.hasArg(options::OPT_static)) |
| 1802 | CmdArgs.push_back("-static-define"); |
| 1803 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1804 | if (isa<AnalyzeJobAction>(JA)) { |
Ted Kremenek | b8bb3e7 | 2009-09-25 05:55:59 +0000 | [diff] [blame] | 1805 | // Enable region store model by default. |
| 1806 | CmdArgs.push_back("-analyzer-store=region"); |
| 1807 | |
Ted Kremenek | b40d06d | 2009-12-07 22:26:14 +0000 | [diff] [blame] | 1808 | // Treat blocks as analysis entry points. |
| 1809 | CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks"); |
| 1810 | |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1811 | CmdArgs.push_back("-analyzer-eagerly-assume"); |
| 1812 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1813 | // Add default argument set. |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1814 | if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) { |
Argyrios Kyrtzidis | 027a6ab | 2011-02-15 07:42:33 +0000 | [diff] [blame] | 1815 | CmdArgs.push_back("-analyzer-checker=core"); |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1816 | |
Argyrios Kyrtzidis | 027a6ab | 2011-02-15 07:42:33 +0000 | [diff] [blame] | 1817 | if (getToolChain().getTriple().getOS() != llvm::Triple::Win32) |
| 1818 | CmdArgs.push_back("-analyzer-checker=unix"); |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1819 | |
Argyrios Kyrtzidis | 027a6ab | 2011-02-15 07:42:33 +0000 | [diff] [blame] | 1820 | if (getToolChain().getTriple().getVendor() == llvm::Triple::Apple) |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1821 | CmdArgs.push_back("-analyzer-checker=osx"); |
Ted Kremenek | a8180e5 | 2012-01-20 06:00:17 +0000 | [diff] [blame] | 1822 | |
| 1823 | CmdArgs.push_back("-analyzer-checker=deadcode"); |
Ted Kremenek | 8dc0506 | 2012-01-26 02:27:38 +0000 | [diff] [blame] | 1824 | |
| 1825 | // Enable the following experimental checkers for testing. |
Ted Kremenek | 8dc0506 | 2012-01-26 02:27:38 +0000 | [diff] [blame] | 1826 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.UncheckedReturn"); |
| 1827 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.getpw"); |
| 1828 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.gets"); |
| 1829 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mktemp"); |
| 1830 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mkstemp"); |
| 1831 | CmdArgs.push_back("-analyzer-checker=security.insecureAPI.vfork"); |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1832 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1833 | |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1834 | // Set the output format. The default is plist, for (lame) historical |
| 1835 | // reasons. |
| 1836 | CmdArgs.push_back("-analyzer-output"); |
| 1837 | if (Arg *A = Args.getLastArg(options::OPT__analyzer_output)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1838 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1839 | else |
| 1840 | CmdArgs.push_back("plist"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1841 | |
Ted Kremenek | 0647a7b | 2010-03-22 22:32:05 +0000 | [diff] [blame] | 1842 | // Disable the presentation of standard compiler warnings when |
| 1843 | // using --analyze. We only want to show static analyzer diagnostics |
| 1844 | // or frontend errors. |
| 1845 | CmdArgs.push_back("-w"); |
| 1846 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1847 | // Add -Xanalyzer arguments when running as analyzer. |
| 1848 | Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
Daniel Dunbar | e2fd664 | 2009-09-10 01:21:12 +0000 | [diff] [blame] | 1851 | CheckCodeGenerationOptions(D, Args); |
| 1852 | |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1853 | // For the PIC and PIE flag options, this logic is different from the legacy |
| 1854 | // logic in very old versions of GCC, as that logic was just a bug no one had |
| 1855 | // ever fixed. This logic is both more rational and consistent with GCC's new |
| 1856 | // logic now that the bugs are fixed. The last argument relating to either |
| 1857 | // PIC or PIE wins, and no other argument is used. If the last argument is |
| 1858 | // any flavor of the '-fno-...' arguments, both PIC and PIE are disabled. Any |
| 1859 | // PIE option implicitly enables PIC at the same level. |
| 1860 | bool PIE = false; |
| 1861 | bool PIC = getToolChain().isPICDefault(); |
| 1862 | bool IsPICLevelTwo = PIC; |
| 1863 | if (Arg *A = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, |
| 1864 | options::OPT_fpic, options::OPT_fno_pic, |
| 1865 | options::OPT_fPIE, options::OPT_fno_PIE, |
| 1866 | options::OPT_fpie, options::OPT_fno_pie)) { |
| 1867 | Option O = A->getOption(); |
| 1868 | if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) || |
| 1869 | O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) { |
| 1870 | PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie); |
| 1871 | PIC = PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic); |
| 1872 | IsPICLevelTwo = O.matches(options::OPT_fPIE) || |
| 1873 | O.matches(options::OPT_fPIC); |
| 1874 | } else { |
| 1875 | PIE = PIC = false; |
| 1876 | } |
Benjamin Kramer | b12ecd3 | 2012-11-13 15:32:35 +0000 | [diff] [blame] | 1877 | } |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1878 | // Check whether the tool chain trumps the PIC-ness decision. If the PIC-ness |
| 1879 | // is forced, then neither PIC nor PIE flags will have no effect. |
| 1880 | if (getToolChain().isPICDefaultForced()) { |
| 1881 | PIE = false; |
| 1882 | PIC = getToolChain().isPICDefault(); |
| 1883 | IsPICLevelTwo = PIC; |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1884 | } |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1885 | |
| 1886 | // Inroduce a Darwin-specific hack. If the default is PIC but the flags |
| 1887 | // specified while enabling PIC enabled level 1 PIC, just force it back to |
| 1888 | // level 2 PIC instead. This matches the behavior of Darwin GCC (based on my |
| 1889 | // informal testing). |
| 1890 | if (PIC && getToolChain().getTriple().isOSDarwin()) |
| 1891 | IsPICLevelTwo |= getToolChain().isPICDefault(); |
| 1892 | |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1893 | // Note that these flags are trump-cards. Regardless of the order w.r.t. the |
| 1894 | // PIC or PIE options above, if these show up, PIC is disabled. |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 1895 | llvm::Triple Triple(TripleStr); |
| 1896 | if ((Args.hasArg(options::OPT_mkernel) || |
| 1897 | Args.hasArg(options::OPT_fapple_kext)) && |
| 1898 | (Triple.getOS() != llvm::Triple::IOS || |
| 1899 | Triple.isOSVersionLT(6))) |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1900 | PIC = PIE = false; |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1901 | if (Args.hasArg(options::OPT_static)) |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1902 | PIC = PIE = false; |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1903 | |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1904 | if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) { |
| 1905 | // This is a very special mode. It trumps the other modes, almost no one |
| 1906 | // uses it, and it isn't even valid on any OS but Darwin. |
| 1907 | if (!getToolChain().getTriple().isOSDarwin()) |
| 1908 | D.Diag(diag::err_drv_unsupported_opt_for_target) |
| 1909 | << A->getSpelling() << getToolChain().getTriple().str(); |
| 1910 | |
| 1911 | // FIXME: Warn when this flag trumps some other PIC or PIE flag. |
| 1912 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1913 | CmdArgs.push_back("-mrelocation-model"); |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1914 | CmdArgs.push_back("dynamic-no-pic"); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1915 | |
Chandler Carruth | 7ce816a | 2012-11-19 03:52:03 +0000 | [diff] [blame] | 1916 | // Only a forced PIC mode can cause the actual compile to have PIC defines |
| 1917 | // etc., no flags are sufficient. This behavior was selected to closely |
| 1918 | // match that of llvm-gcc and Apple GCC before that. |
| 1919 | if (getToolChain().isPICDefault() && getToolChain().isPICDefaultForced()) { |
| 1920 | CmdArgs.push_back("-pic-level"); |
| 1921 | CmdArgs.push_back("2"); |
| 1922 | } |
| 1923 | } else { |
| 1924 | // Currently, LLVM only knows about PIC vs. static; the PIE differences are |
| 1925 | // handled in Clang's IRGen by the -pie-level flag. |
| 1926 | CmdArgs.push_back("-mrelocation-model"); |
| 1927 | CmdArgs.push_back(PIC ? "pic" : "static"); |
| 1928 | |
| 1929 | if (PIC) { |
| 1930 | CmdArgs.push_back("-pic-level"); |
| 1931 | CmdArgs.push_back(IsPICLevelTwo ? "2" : "1"); |
| 1932 | if (PIE) { |
| 1933 | CmdArgs.push_back("-pie-level"); |
| 1934 | CmdArgs.push_back(IsPICLevelTwo ? "2" : "1"); |
| 1935 | } |
| 1936 | } |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1937 | } |
Chandler Carruth | 5e219cf | 2012-04-08 16:40:35 +0000 | [diff] [blame] | 1938 | |
Tanya Lattner | 59876c2 | 2009-11-04 01:18:09 +0000 | [diff] [blame] | 1939 | if (!Args.hasFlag(options::OPT_fmerge_all_constants, |
| 1940 | options::OPT_fno_merge_all_constants)) |
Chris Lattner | f44a1a0 | 2011-04-08 18:06:54 +0000 | [diff] [blame] | 1941 | CmdArgs.push_back("-fno-merge-all-constants"); |
Daniel Dunbar | 6bea73b | 2009-09-16 06:17:29 +0000 | [diff] [blame] | 1942 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1943 | // LLVM Code Generator Options. |
| 1944 | |
Daniel Dunbar | 17d3fea | 2011-02-09 17:54:19 +0000 | [diff] [blame] | 1945 | if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) { |
| 1946 | CmdArgs.push_back("-mregparm"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 1947 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | 17d3fea | 2011-02-09 17:54:19 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 1950 | if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd, false)) |
| 1951 | CmdArgs.push_back("-mrtd"); |
| 1952 | |
Rafael Espindola | 6af27ec | 2011-12-14 21:02:23 +0000 | [diff] [blame] | 1953 | if (shouldUseFramePointer(Args, getToolChain().getTriple())) |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1954 | CmdArgs.push_back("-mdisable-fp-elim"); |
| 1955 | if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, |
| 1956 | options::OPT_fno_zero_initialized_in_bss)) |
| 1957 | CmdArgs.push_back("-mno-zero-initialized-in-bss"); |
Daniel Dunbar | 398c610 | 2011-02-04 02:20:39 +0000 | [diff] [blame] | 1958 | if (!Args.hasFlag(options::OPT_fstrict_aliasing, |
| 1959 | options::OPT_fno_strict_aliasing, |
| 1960 | getToolChain().IsStrictAliasingDefault())) |
Dan Gohman | 4d5625e | 2010-10-14 22:36:56 +0000 | [diff] [blame] | 1961 | CmdArgs.push_back("-relaxed-aliasing"); |
Chandler Carruth | 82fe6ae | 2012-03-27 23:58:37 +0000 | [diff] [blame] | 1962 | if (Args.hasFlag(options::OPT_fstrict_enums, options::OPT_fno_strict_enums, |
| 1963 | false)) |
| 1964 | CmdArgs.push_back("-fstrict-enums"); |
Nick Lewycky | 1db772b | 2012-01-23 08:29:12 +0000 | [diff] [blame] | 1965 | if (!Args.hasFlag(options::OPT_foptimize_sibling_calls, |
| 1966 | options::OPT_fno_optimize_sibling_calls)) |
| 1967 | CmdArgs.push_back("-mdisable-tail-calls"); |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 1968 | |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1969 | // Handle various floating point optimization flags, mapping them to the |
| 1970 | // appropriate LLVM code generation flags. The pattern for all of these is to |
| 1971 | // default off the codegen optimizations, and if any flag enables them and no |
| 1972 | // flag disables them after the flag enabling them, enable the codegen |
| 1973 | // optimization. This is complicated by several "umbrella" flags. |
| 1974 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1975 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1976 | options::OPT_ffinite_math_only, |
| 1977 | options::OPT_fno_finite_math_only, |
| 1978 | options::OPT_fhonor_infinities, |
| 1979 | options::OPT_fno_honor_infinities)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1980 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 1981 | A->getOption().getID() != options::OPT_fno_finite_math_only && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1982 | A->getOption().getID() != options::OPT_fhonor_infinities) |
| 1983 | CmdArgs.push_back("-menable-no-infs"); |
| 1984 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1985 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1986 | options::OPT_ffinite_math_only, |
| 1987 | options::OPT_fno_finite_math_only, |
| 1988 | options::OPT_fhonor_nans, |
| 1989 | options::OPT_fno_honor_nans)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1990 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 1991 | A->getOption().getID() != options::OPT_fno_finite_math_only && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1992 | A->getOption().getID() != options::OPT_fhonor_nans) |
| 1993 | CmdArgs.push_back("-menable-no-nans"); |
| 1994 | |
Benjamin Kramer | 769aa2d | 2012-05-02 14:55:48 +0000 | [diff] [blame] | 1995 | // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes. |
| 1996 | bool MathErrno = getToolChain().IsMathErrnoDefault(); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1997 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 1998 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 1999 | options::OPT_fmath_errno, |
Chandler Carruth | 4f50c50 | 2012-04-26 02:10:51 +0000 | [diff] [blame] | 2000 | options::OPT_fno_math_errno)) |
| 2001 | MathErrno = A->getOption().getID() == options::OPT_fmath_errno; |
| 2002 | if (MathErrno) |
| 2003 | CmdArgs.push_back("-fmath-errno"); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2004 | |
| 2005 | // There are several flags which require disabling very specific |
| 2006 | // optimizations. Any of these being disabled forces us to turn off the |
| 2007 | // entire set of LLVM optimizations, so collect them through all the flag |
| 2008 | // madness. |
| 2009 | bool AssociativeMath = false; |
| 2010 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2011 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2012 | options::OPT_funsafe_math_optimizations, |
| 2013 | options::OPT_fno_unsafe_math_optimizations, |
| 2014 | options::OPT_fassociative_math, |
| 2015 | options::OPT_fno_associative_math)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2016 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 2017 | A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2018 | A->getOption().getID() != options::OPT_fno_associative_math) |
| 2019 | AssociativeMath = true; |
| 2020 | bool ReciprocalMath = false; |
| 2021 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2022 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2023 | options::OPT_funsafe_math_optimizations, |
| 2024 | options::OPT_fno_unsafe_math_optimizations, |
| 2025 | options::OPT_freciprocal_math, |
| 2026 | options::OPT_fno_reciprocal_math)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2027 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 2028 | A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2029 | A->getOption().getID() != options::OPT_fno_reciprocal_math) |
| 2030 | ReciprocalMath = true; |
| 2031 | bool SignedZeros = true; |
| 2032 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2033 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2034 | options::OPT_funsafe_math_optimizations, |
| 2035 | options::OPT_fno_unsafe_math_optimizations, |
| 2036 | options::OPT_fsigned_zeros, |
| 2037 | options::OPT_fno_signed_zeros)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2038 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 2039 | A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2040 | A->getOption().getID() != options::OPT_fsigned_zeros) |
| 2041 | SignedZeros = false; |
| 2042 | bool TrappingMath = true; |
| 2043 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2044 | options::OPT_fno_fast_math, |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2045 | options::OPT_funsafe_math_optimizations, |
| 2046 | options::OPT_fno_unsafe_math_optimizations, |
| 2047 | options::OPT_ftrapping_math, |
| 2048 | options::OPT_fno_trapping_math)) |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2049 | if (A->getOption().getID() != options::OPT_fno_fast_math && |
| 2050 | A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations && |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2051 | A->getOption().getID() != options::OPT_ftrapping_math) |
| 2052 | TrappingMath = false; |
| 2053 | if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && |
| 2054 | !TrappingMath) |
| 2055 | CmdArgs.push_back("-menable-unsafe-fp-math"); |
| 2056 | |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 2057 | |
| 2058 | // Validate and pass through -fp-contract option. |
| 2059 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2060 | options::OPT_fno_fast_math, |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 2061 | options::OPT_ffp_contract)) { |
| 2062 | if (A->getOption().getID() == options::OPT_ffp_contract) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2063 | StringRef Val = A->getValue(); |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 2064 | if (Val == "fast" || Val == "on" || Val == "off") { |
| 2065 | CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + Val)); |
| 2066 | } else { |
| 2067 | D.Diag(diag::err_drv_unsupported_option_argument) |
| 2068 | << A->getOption().getName() << Val; |
| 2069 | } |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2070 | } else if (A->getOption().getID() == options::OPT_ffast_math) { |
Lang Hames | c968671 | 2012-07-06 00:59:19 +0000 | [diff] [blame] | 2071 | // If fast-math is set then set the fp-contract mode to fast. |
| 2072 | CmdArgs.push_back(Args.MakeArgString("-ffp-contract=fast")); |
| 2073 | } |
| 2074 | } |
| 2075 | |
Bob Wilson | 455e72e | 2012-07-19 03:52:53 +0000 | [diff] [blame] | 2076 | // We separately look for the '-ffast-math' and '-ffinite-math-only' flags, |
| 2077 | // and if we find them, tell the frontend to provide the appropriate |
| 2078 | // preprocessor macros. This is distinct from enabling any optimizations as |
| 2079 | // these options induce language changes which must survive serialization |
| 2080 | // and deserialization, etc. |
Chad Rosier | 80ecf5e | 2012-09-25 22:03:25 +0000 | [diff] [blame] | 2081 | if (Arg *A = Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math)) |
| 2082 | if (A->getOption().matches(options::OPT_ffast_math)) |
| 2083 | CmdArgs.push_back("-ffast-math"); |
| 2084 | if (Arg *A = Args.getLastArg(options::OPT_ffinite_math_only, options::OPT_fno_fast_math)) |
| 2085 | if (A->getOption().matches(options::OPT_ffinite_math_only)) |
| 2086 | CmdArgs.push_back("-ffinite-math-only"); |
Chandler Carruth | abf07a7 | 2012-01-02 14:19:45 +0000 | [diff] [blame] | 2087 | |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 2088 | // Decide whether to use verbose asm. Verbose assembly is the default on |
| 2089 | // toolchains which have the integrated assembler on by default. |
| 2090 | bool IsVerboseAsmDefault = getToolChain().IsIntegratedAssemblerDefault(); |
| 2091 | 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] | 2092 | IsVerboseAsmDefault) || |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 2093 | Args.hasArg(options::OPT_dA)) |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2094 | CmdArgs.push_back("-masm-verbose"); |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 2095 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2096 | if (Args.hasArg(options::OPT_fdebug_pass_structure)) { |
| 2097 | CmdArgs.push_back("-mdebug-pass"); |
| 2098 | CmdArgs.push_back("Structure"); |
| 2099 | } |
| 2100 | if (Args.hasArg(options::OPT_fdebug_pass_arguments)) { |
| 2101 | CmdArgs.push_back("-mdebug-pass"); |
| 2102 | CmdArgs.push_back("Arguments"); |
| 2103 | } |
| 2104 | |
John McCall | d0c2ec4 | 2010-02-19 02:45:38 +0000 | [diff] [blame] | 2105 | // Enable -mconstructor-aliases except on darwin, where we have to |
| 2106 | // work around a linker bug; see <rdar://problem/7651567>. |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 2107 | if (!getToolChain().getTriple().isOSDarwin()) |
John McCall | d0c2ec4 | 2010-02-19 02:45:38 +0000 | [diff] [blame] | 2108 | CmdArgs.push_back("-mconstructor-aliases"); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 2109 | |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 2110 | // Darwin's kernel doesn't support guard variables; just die if we |
| 2111 | // try to use them. |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 2112 | if (KernelOrKext && getToolChain().getTriple().isOSDarwin()) |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 2113 | CmdArgs.push_back("-fforbid-guard-variables"); |
| 2114 | |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 2115 | if (Args.hasArg(options::OPT_mms_bitfields)) { |
| 2116 | CmdArgs.push_back("-mms-bitfields"); |
| 2117 | } |
John McCall | d0c2ec4 | 2010-02-19 02:45:38 +0000 | [diff] [blame] | 2118 | |
Daniel Dunbar | 6bea73b | 2009-09-16 06:17:29 +0000 | [diff] [blame] | 2119 | // This is a coarse approximation of what llvm-gcc actually does, both |
| 2120 | // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more |
| 2121 | // complicated ways. |
| 2122 | bool AsynchronousUnwindTables = |
| 2123 | Args.hasFlag(options::OPT_fasynchronous_unwind_tables, |
| 2124 | options::OPT_fno_asynchronous_unwind_tables, |
| 2125 | getToolChain().IsUnwindTablesDefault() && |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 2126 | !KernelOrKext); |
Daniel Dunbar | 6bea73b | 2009-09-16 06:17:29 +0000 | [diff] [blame] | 2127 | if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables, |
| 2128 | AsynchronousUnwindTables)) |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2129 | CmdArgs.push_back("-munwind-tables"); |
| 2130 | |
Chandler Carruth | a6b2581 | 2012-11-21 23:40:23 +0000 | [diff] [blame] | 2131 | getToolChain().addClangTargetOptions(Args, CmdArgs); |
Rafael Espindola | 8af669f | 2012-06-19 01:26:10 +0000 | [diff] [blame] | 2132 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2133 | if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { |
| 2134 | CmdArgs.push_back("-mlimit-float-precision"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2135 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2136 | } |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 2137 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 2138 | // FIXME: Handle -mtune=. |
| 2139 | (void) Args.hasArg(options::OPT_mtune_EQ); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 2140 | |
Benjamin Kramer | 8e9ef0d | 2009-08-05 14:30:52 +0000 | [diff] [blame] | 2141 | if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 2142 | CmdArgs.push_back("-mcode-model"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2143 | CmdArgs.push_back(A->getValue()); |
Benjamin Kramer | 8e9ef0d | 2009-08-05 14:30:52 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 2146 | // Add target specific cpu and features flags. |
| 2147 | switch(getToolChain().getTriple().getArch()) { |
| 2148 | default: |
| 2149 | break; |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 2150 | |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 2151 | case llvm::Triple::arm: |
| 2152 | case llvm::Triple::thumb: |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 2153 | AddARMTargetArgs(Args, CmdArgs, KernelOrKext); |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 2154 | break; |
| 2155 | |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2156 | case llvm::Triple::mips: |
| 2157 | case llvm::Triple::mipsel: |
Akira Hatanaka | 7ec0258 | 2011-09-21 02:13:07 +0000 | [diff] [blame] | 2158 | case llvm::Triple::mips64: |
| 2159 | case llvm::Triple::mips64el: |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2160 | AddMIPSTargetArgs(Args, CmdArgs); |
| 2161 | break; |
| 2162 | |
Hal Finkel | 02a8427 | 2012-06-11 22:35:19 +0000 | [diff] [blame] | 2163 | case llvm::Triple::ppc: |
| 2164 | case llvm::Triple::ppc64: |
| 2165 | AddPPCTargetArgs(Args, CmdArgs); |
| 2166 | break; |
| 2167 | |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 2168 | case llvm::Triple::sparc: |
| 2169 | AddSparcTargetArgs(Args, CmdArgs); |
| 2170 | break; |
| 2171 | |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 2172 | case llvm::Triple::x86: |
| 2173 | case llvm::Triple::x86_64: |
| 2174 | AddX86TargetArgs(Args, CmdArgs); |
| 2175 | break; |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2176 | |
| 2177 | case llvm::Triple::hexagon: |
| 2178 | AddHexagonTargetArgs(Args, CmdArgs); |
| 2179 | break; |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2182 | |
| 2183 | |
Daniel Dunbar | c176bc6 | 2010-08-11 23:07:47 +0000 | [diff] [blame] | 2184 | // Pass the linker version in use. |
| 2185 | if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { |
| 2186 | CmdArgs.push_back("-target-linker-version"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2187 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | c176bc6 | 2010-08-11 23:07:47 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
Nick Lewycky | b2d11cc | 2011-02-02 06:43:03 +0000 | [diff] [blame] | 2190 | // -mno-omit-leaf-frame-pointer is the default on Darwin. |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 2191 | if (Args.hasFlag(options::OPT_momit_leaf_frame_pointer, |
Nick Lewycky | b2d11cc | 2011-02-02 06:43:03 +0000 | [diff] [blame] | 2192 | options::OPT_mno_omit_leaf_frame_pointer, |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 2193 | !getToolChain().getTriple().isOSDarwin())) |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 2194 | CmdArgs.push_back("-momit-leaf-frame-pointer"); |
| 2195 | |
Daniel Dunbar | b30575c | 2010-05-12 18:19:58 +0000 | [diff] [blame] | 2196 | // Explicitly error on some things we know we don't support and can't just |
| 2197 | // ignore. |
| 2198 | types::ID InputType = Inputs[0].getType(); |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 2199 | if (!Args.hasArg(options::OPT_fallow_unsupported)) { |
| 2200 | Arg *Unsupported; |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 2201 | if (types::isCXX(InputType) && |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 2202 | getToolChain().getTriple().isOSDarwin() && |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 2203 | getToolChain().getTriple().getArch() == llvm::Triple::x86) { |
Bob Wilson | a544aee | 2011-08-13 23:48:55 +0000 | [diff] [blame] | 2204 | if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)) || |
| 2205 | (Unsupported = Args.getLastArg(options::OPT_mkernel))) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2206 | D.Diag(diag::err_drv_clang_unsupported_opt_cxx_darwin_i386) |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 2207 | << Unsupported->getOption().getName(); |
| 2208 | } |
Daniel Dunbar | b30575c | 2010-05-12 18:19:58 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2211 | Args.AddAllArgs(CmdArgs, options::OPT_v); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 2212 | Args.AddLastArg(CmdArgs, options::OPT_H); |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 2213 | if (D.CCPrintHeaders && !D.CCGenDiagnostics) { |
Daniel Dunbar | 322c29f | 2011-02-02 21:11:35 +0000 | [diff] [blame] | 2214 | CmdArgs.push_back("-header-include-file"); |
| 2215 | CmdArgs.push_back(D.CCPrintHeadersFilename ? |
| 2216 | D.CCPrintHeadersFilename : "-"); |
| 2217 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2218 | Args.AddLastArg(CmdArgs, options::OPT_P); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2219 | Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2220 | |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 2221 | if (D.CCLogDiagnostics && !D.CCGenDiagnostics) { |
Daniel Dunbar | c8a22b0 | 2011-04-07 18:01:20 +0000 | [diff] [blame] | 2222 | CmdArgs.push_back("-diagnostic-log-file"); |
| 2223 | CmdArgs.push_back(D.CCLogDiagnosticsFilename ? |
| 2224 | D.CCLogDiagnosticsFilename : "-"); |
| 2225 | } |
| 2226 | |
Alexey Samsonov | a9cd83b | 2012-05-29 08:10:34 +0000 | [diff] [blame] | 2227 | // Use the last option from "-g" group. "-gline-tables-only" is |
| 2228 | // preserved, all other debug options are substituted with "-g". |
Rafael Espindola | 18f36d9 | 2010-03-07 04:46:18 +0000 | [diff] [blame] | 2229 | Args.ClaimAllArgs(options::OPT_g_Group); |
Alexey Samsonov | a9cd83b | 2012-05-29 08:10:34 +0000 | [diff] [blame] | 2230 | if (Arg *A = Args.getLastArg(options::OPT_g_Group)) { |
| 2231 | if (A->getOption().matches(options::OPT_gline_tables_only)) { |
| 2232 | CmdArgs.push_back("-gline-tables-only"); |
Alexey Samsonov | 7f32607 | 2012-06-21 08:22:39 +0000 | [diff] [blame] | 2233 | } else if (!A->getOption().matches(options::OPT_g0) && |
| 2234 | !A->getOption().matches(options::OPT_ggdb0)) { |
Chad Rosier | cf6ba2e | 2011-11-07 19:52:29 +0000 | [diff] [blame] | 2235 | CmdArgs.push_back("-g"); |
Chad Rosier | 2875bda | 2011-11-04 19:28:44 +0000 | [diff] [blame] | 2236 | } |
Alexey Samsonov | a9cd83b | 2012-05-29 08:10:34 +0000 | [diff] [blame] | 2237 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2238 | |
Alexey Samsonov | 7f32607 | 2012-06-21 08:22:39 +0000 | [diff] [blame] | 2239 | // We ignore flags -gstrict-dwarf and -grecord-gcc-switches for now. |
| 2240 | Args.ClaimAllArgs(options::OPT_g_flags_Group); |
Eric Christopher | da3301e | 2012-10-18 21:52:18 +0000 | [diff] [blame] | 2241 | if (Args.hasArg(options::OPT_gcolumn_info)) |
| 2242 | CmdArgs.push_back("-dwarf-column-info"); |
Alexey Samsonov | 7f32607 | 2012-06-21 08:22:39 +0000 | [diff] [blame] | 2243 | |
Rafael Espindola | 9cf933a | 2010-05-06 21:06:04 +0000 | [diff] [blame] | 2244 | Args.AddAllArgs(CmdArgs, options::OPT_ffunction_sections); |
| 2245 | Args.AddAllArgs(CmdArgs, options::OPT_fdata_sections); |
| 2246 | |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 2247 | Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); |
| 2248 | |
Nick Lewycky | e8ba8d7 | 2011-04-21 23:44:07 +0000 | [diff] [blame] | 2249 | if (Args.hasArg(options::OPT_ftest_coverage) || |
| 2250 | Args.hasArg(options::OPT_coverage)) |
| 2251 | CmdArgs.push_back("-femit-coverage-notes"); |
| 2252 | if (Args.hasArg(options::OPT_fprofile_arcs) || |
| 2253 | Args.hasArg(options::OPT_coverage)) |
| 2254 | CmdArgs.push_back("-femit-coverage-data"); |
| 2255 | |
Nick Lewycky | 5ea4f44 | 2011-05-04 20:46:58 +0000 | [diff] [blame] | 2256 | if (C.getArgs().hasArg(options::OPT_c) || |
| 2257 | C.getArgs().hasArg(options::OPT_S)) { |
| 2258 | if (Output.isFilename()) { |
Nick Lewycky | 3dc0541 | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 2259 | CmdArgs.push_back("-coverage-file"); |
Bill Wendling | ecbbea4 | 2012-08-30 00:43:41 +0000 | [diff] [blame] | 2260 | SmallString<128> absFilename(Output.getFilename()); |
| 2261 | llvm::sys::fs::make_absolute(absFilename); |
| 2262 | CmdArgs.push_back(Args.MakeArgString(absFilename)); |
Nick Lewycky | 5ea4f44 | 2011-05-04 20:46:58 +0000 | [diff] [blame] | 2263 | } |
| 2264 | } |
| 2265 | |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 2266 | // Pass options for controlling the default header search paths. |
| 2267 | if (Args.hasArg(options::OPT_nostdinc)) { |
| 2268 | CmdArgs.push_back("-nostdsysteminc"); |
| 2269 | CmdArgs.push_back("-nobuiltininc"); |
| 2270 | } else { |
Daniel Dunbar | 92d6d40 | 2011-10-11 18:20:16 +0000 | [diff] [blame] | 2271 | if (Args.hasArg(options::OPT_nostdlibinc)) |
| 2272 | CmdArgs.push_back("-nostdsysteminc"); |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 2273 | Args.AddLastArg(CmdArgs, options::OPT_nostdincxx); |
| 2274 | Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc); |
| 2275 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2276 | |
Daniel Dunbar | 5f12232 | 2009-12-15 01:02:52 +0000 | [diff] [blame] | 2277 | // Pass the path to compiler resource files. |
Daniel Dunbar | 5f12232 | 2009-12-15 01:02:52 +0000 | [diff] [blame] | 2278 | CmdArgs.push_back("-resource-dir"); |
Daniel Dunbar | 225c417 | 2010-01-20 02:35:16 +0000 | [diff] [blame] | 2279 | CmdArgs.push_back(D.ResourceDir.c_str()); |
Daniel Dunbar | 2ac9fc2 | 2009-04-07 21:42:00 +0000 | [diff] [blame] | 2280 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2281 | Args.AddLastArg(CmdArgs, options::OPT_working_directory); |
| 2282 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2283 | bool ARCMTEnabled = false; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2284 | if (!Args.hasArg(options::OPT_fno_objc_arc)) { |
Argyrios Kyrtzidis | 72ac120 | 2011-07-07 04:00:39 +0000 | [diff] [blame] | 2285 | if (const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check, |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 2286 | options::OPT_ccc_arcmt_modify, |
| 2287 | options::OPT_ccc_arcmt_migrate)) { |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2288 | ARCMTEnabled = true; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2289 | switch (A->getOption().getID()) { |
| 2290 | default: |
| 2291 | llvm_unreachable("missed a case"); |
Argyrios Kyrtzidis | 72ac120 | 2011-07-07 04:00:39 +0000 | [diff] [blame] | 2292 | case options::OPT_ccc_arcmt_check: |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2293 | CmdArgs.push_back("-arcmt-check"); |
| 2294 | break; |
Argyrios Kyrtzidis | 72ac120 | 2011-07-07 04:00:39 +0000 | [diff] [blame] | 2295 | case options::OPT_ccc_arcmt_modify: |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2296 | CmdArgs.push_back("-arcmt-modify"); |
| 2297 | break; |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 2298 | case options::OPT_ccc_arcmt_migrate: |
| 2299 | CmdArgs.push_back("-arcmt-migrate"); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2300 | CmdArgs.push_back("-mt-migrate-directory"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2301 | CmdArgs.push_back(A->getValue()); |
Argyrios Kyrtzidis | 7ee2049 | 2011-07-19 17:20:03 +0000 | [diff] [blame] | 2302 | |
| 2303 | Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_report_output); |
| 2304 | Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_emit_arc_errors); |
Argyrios Kyrtzidis | 69325d5 | 2011-07-09 20:00:58 +0000 | [diff] [blame] | 2305 | break; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 2306 | } |
| 2307 | } |
| 2308 | } |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 2309 | |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2310 | if (const Arg *A = Args.getLastArg(options::OPT_ccc_objcmt_migrate)) { |
| 2311 | if (ARCMTEnabled) { |
| 2312 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 2313 | << A->getAsString(Args) << "-ccc-arcmt-migrate"; |
| 2314 | } |
| 2315 | CmdArgs.push_back("-mt-migrate-directory"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2316 | CmdArgs.push_back(A->getValue()); |
Ted Kremenek | 30660a8 | 2012-03-06 20:06:33 +0000 | [diff] [blame] | 2317 | |
| 2318 | if (!Args.hasArg(options::OPT_objcmt_migrate_literals, |
| 2319 | options::OPT_objcmt_migrate_subscripting)) { |
| 2320 | // None specified, means enable them all. |
| 2321 | CmdArgs.push_back("-objcmt-migrate-literals"); |
| 2322 | CmdArgs.push_back("-objcmt-migrate-subscripting"); |
| 2323 | } else { |
| 2324 | Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals); |
| 2325 | Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting); |
| 2326 | } |
| 2327 | } |
| 2328 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2329 | // Add preprocessing options like -I, -D, etc. if we are using the |
| 2330 | // preprocessor. |
| 2331 | // |
| 2332 | // FIXME: Support -fpreprocessed |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2333 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) |
Chad Rosier | 9d71863 | 2013-01-24 19:14:47 +0000 | [diff] [blame] | 2334 | AddPreprocessingOptions(C, JA, D, Args, CmdArgs, Output, Inputs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2335 | |
Rafael Espindola | 19d9d2e | 2011-07-21 23:40:37 +0000 | [diff] [blame] | 2336 | // Don't warn about "clang -c -DPIC -fPIC test.i" because libtool.m4 assumes |
| 2337 | // that "The compiler can only warn and ignore the option if not recognized". |
| 2338 | // When building with ccache, it will pass -D options to clang even on |
| 2339 | // preprocessed inputs and configure concludes that -fPIC is not supported. |
| 2340 | Args.ClaimAllArgs(options::OPT_D); |
| 2341 | |
Daniel Dunbar | 20f0eac | 2009-09-17 06:53:36 +0000 | [diff] [blame] | 2342 | // Manually translate -O to -O2 and -O4 to -O3; let clang reject |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 2343 | // others. |
| 2344 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
Daniel Dunbar | b827a05 | 2009-11-19 03:26:40 +0000 | [diff] [blame] | 2345 | if (A->getOption().matches(options::OPT_O4)) |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 2346 | CmdArgs.push_back("-O3"); |
Daniel Dunbar | 473916c | 2010-05-27 06:51:08 +0000 | [diff] [blame] | 2347 | else if (A->getOption().matches(options::OPT_O) && |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2348 | A->getValue()[0] == '\0') |
Daniel Dunbar | 20f0eac | 2009-09-17 06:53:36 +0000 | [diff] [blame] | 2349 | CmdArgs.push_back("-O2"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2350 | else |
Daniel Dunbar | 5697aa0 | 2009-03-18 23:39:35 +0000 | [diff] [blame] | 2351 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
Chad Rosier | b2c0887 | 2012-12-12 20:06:31 +0000 | [diff] [blame] | 2354 | // Don't warn about unused -flto. This can happen when we're preprocessing or |
| 2355 | // precompiling. |
| 2356 | Args.ClaimAllArgs(options::OPT_flto); |
| 2357 | |
Daniel Dunbar | 6e8371e | 2009-10-29 02:24:45 +0000 | [diff] [blame] | 2358 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group); |
Ted Kremenek | e8cf7d1 | 2012-07-07 05:53:30 +0000 | [diff] [blame] | 2359 | if (Args.hasFlag(options::OPT_pedantic, options::OPT_no_pedantic, false)) |
| 2360 | CmdArgs.push_back("-pedantic"); |
Daniel Dunbar | 6e8371e | 2009-10-29 02:24:45 +0000 | [diff] [blame] | 2361 | Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2362 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 2363 | |
| 2364 | // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi} |
| 2365 | // (-ansi is equivalent to -std=c89). |
| 2366 | // |
| 2367 | // If a std is supplied, only add -trigraphs if it follows the |
| 2368 | // option. |
| 2369 | if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 2370 | if (Std->getOption().matches(options::OPT_ansi)) |
Nuno Lopes | 528365d | 2009-10-16 14:28:06 +0000 | [diff] [blame] | 2371 | if (types::isCXX(InputType)) |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 2372 | CmdArgs.push_back("-std=c++98"); |
Nuno Lopes | 528365d | 2009-10-16 14:28:06 +0000 | [diff] [blame] | 2373 | else |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 2374 | CmdArgs.push_back("-std=c89"); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 2375 | else |
| 2376 | Std->render(Args, CmdArgs); |
| 2377 | |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 2378 | if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi, |
| 2379 | options::OPT_trigraphs)) |
| 2380 | if (A != Std) |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 2381 | A->render(Args, CmdArgs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 2382 | } else { |
| 2383 | // Honor -std-default. |
Daniel Dunbar | 4a5290e | 2010-01-29 21:03:02 +0000 | [diff] [blame] | 2384 | // |
| 2385 | // FIXME: Clang doesn't correctly handle -std= when the input language |
| 2386 | // doesn't match. For the time being just ignore this for C++ inputs; |
| 2387 | // eventually we want to do all the standard defaulting here instead of |
| 2388 | // splitting it between the driver and clang -cc1. |
| 2389 | if (!types::isCXX(InputType)) |
Nico Weber | 50f88b9 | 2012-08-30 02:08:31 +0000 | [diff] [blame] | 2390 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 2391 | "-std=", /*Joined=*/true); |
| 2392 | else if (getToolChain().getTriple().getOS() == llvm::Triple::Win32) |
| 2393 | CmdArgs.push_back("-std=c++11"); |
| 2394 | |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 2395 | Args.AddLastArg(CmdArgs, options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 2396 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2397 | |
Chandler Carruth | 50465d1 | 2011-04-23 06:30:43 +0000 | [diff] [blame] | 2398 | // Map the bizarre '-Wwrite-strings' flag to a more sensible |
| 2399 | // '-fconst-strings'; this better indicates its actual behavior. |
| 2400 | if (Args.hasFlag(options::OPT_Wwrite_strings, options::OPT_Wno_write_strings, |
| 2401 | false)) { |
| 2402 | // For perfect compatibility with GCC, we do this even in the presence of |
| 2403 | // '-w'. This flag names something other than a warning for GCC. |
| 2404 | CmdArgs.push_back("-fconst-strings"); |
| 2405 | } |
| 2406 | |
Chandler Carruth | 1cfe3c3 | 2011-04-23 09:27:53 +0000 | [diff] [blame] | 2407 | // GCC provides a macro definition '__DEPRECATED' when -Wdeprecated is active |
Chandler Carruth | f8c247d | 2011-04-23 19:48:40 +0000 | [diff] [blame] | 2408 | // during C++ compilation, which it is by default. GCC keeps this define even |
| 2409 | // in the presence of '-w', match this behavior bug-for-bug. |
| 2410 | if (types::isCXX(InputType) && |
| 2411 | Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated, |
| 2412 | true)) { |
| 2413 | CmdArgs.push_back("-fdeprecated-macro"); |
Chandler Carruth | 1cfe3c3 | 2011-04-23 09:27:53 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
Chandler Carruth | c304ba3 | 2010-05-22 02:21:53 +0000 | [diff] [blame] | 2416 | // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'. |
| 2417 | if (Arg *Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) { |
| 2418 | if (Asm->getOption().matches(options::OPT_fasm)) |
| 2419 | CmdArgs.push_back("-fgnu-keywords"); |
| 2420 | else |
| 2421 | CmdArgs.push_back("-fno-gnu-keywords"); |
| 2422 | } |
| 2423 | |
Rafael Espindola | 61b1efe | 2011-05-02 17:43:32 +0000 | [diff] [blame] | 2424 | if (ShouldDisableCFI(Args, getToolChain())) |
| 2425 | CmdArgs.push_back("-fno-dwarf2-cfi-asm"); |
Rafael Espindola | f24a151 | 2011-04-30 18:35:43 +0000 | [diff] [blame] | 2426 | |
Nick Lewycky | ea523d7 | 2011-10-17 23:05:52 +0000 | [diff] [blame] | 2427 | if (ShouldDisableDwarfDirectory(Args, getToolChain())) |
| 2428 | CmdArgs.push_back("-fno-dwarf-directory-asm"); |
| 2429 | |
Chandler Carruth | d566df6 | 2012-12-17 21:40:04 +0000 | [diff] [blame] | 2430 | // Add in -fdebug-compilation-dir if necessary. |
| 2431 | addDebugCompDirArg(Args, CmdArgs); |
Nick Lewycky | 7c4fd91 | 2011-10-21 02:32:14 +0000 | [diff] [blame] | 2432 | |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 2433 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_, |
| 2434 | options::OPT_ftemplate_depth_EQ)) { |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2435 | CmdArgs.push_back("-ftemplate-depth"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2436 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 2439 | if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_depth_EQ)) { |
| 2440 | CmdArgs.push_back("-fconstexpr-depth"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2441 | CmdArgs.push_back(A->getValue()); |
Richard Smith | c18c423 | 2011-11-21 19:36:32 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
Argyrios Kyrtzidis | 1380a14 | 2010-11-18 00:20:36 +0000 | [diff] [blame] | 2444 | if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ, |
| 2445 | options::OPT_Wlarge_by_value_copy_def)) { |
Jean-Daniel Dupas | 2e4fd6d | 2012-05-04 08:08:37 +0000 | [diff] [blame] | 2446 | if (A->getNumValues()) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2447 | StringRef bytes = A->getValue(); |
Jean-Daniel Dupas | 2e4fd6d | 2012-05-04 08:08:37 +0000 | [diff] [blame] | 2448 | CmdArgs.push_back(Args.MakeArgString("-Wlarge-by-value-copy=" + bytes)); |
| 2449 | } else |
| 2450 | CmdArgs.push_back("-Wlarge-by-value-copy=64"); // default value |
Argyrios Kyrtzidis | 3532fdd | 2010-11-17 23:11:54 +0000 | [diff] [blame] | 2451 | } |
| 2452 | |
Nuno Lopes | b3198a8 | 2012-05-08 22:10:46 +0000 | [diff] [blame] | 2453 | |
Michael J. Spencer | c635710 | 2012-10-22 22:13:48 +0000 | [diff] [blame] | 2454 | if (Args.hasArg(options::OPT_relocatable_pch)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 2455 | CmdArgs.push_back("-relocatable-pch"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2456 | |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 2457 | if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) { |
| 2458 | CmdArgs.push_back("-fconstant-string-class"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2459 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 2460 | } |
David Chisnall | 8a5a9aa | 2009-08-31 16:41:57 +0000 | [diff] [blame] | 2461 | |
Chris Lattner | 124fca5 | 2010-01-09 21:54:33 +0000 | [diff] [blame] | 2462 | if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) { |
| 2463 | CmdArgs.push_back("-ftabstop"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2464 | CmdArgs.push_back(A->getValue()); |
Chris Lattner | 124fca5 | 2010-01-09 21:54:33 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
Chris Lattner | 0f0c963 | 2010-04-07 20:49:23 +0000 | [diff] [blame] | 2467 | CmdArgs.push_back("-ferror-limit"); |
| 2468 | if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ)) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2469 | CmdArgs.push_back(A->getValue()); |
Chris Lattner | 0f0c963 | 2010-04-07 20:49:23 +0000 | [diff] [blame] | 2470 | else |
| 2471 | CmdArgs.push_back("19"); |
Douglas Gregor | 575cf37 | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 2472 | |
Chandler Carruth | c40f73c | 2010-05-06 04:55:18 +0000 | [diff] [blame] | 2473 | if (Arg *A = Args.getLastArg(options::OPT_fmacro_backtrace_limit_EQ)) { |
| 2474 | CmdArgs.push_back("-fmacro-backtrace-limit"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2475 | CmdArgs.push_back(A->getValue()); |
Chandler Carruth | c40f73c | 2010-05-06 04:55:18 +0000 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ)) { |
| 2479 | CmdArgs.push_back("-ftemplate-backtrace-limit"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2480 | CmdArgs.push_back(A->getValue()); |
Chandler Carruth | c40f73c | 2010-05-06 04:55:18 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
Richard Smith | 08d6e03 | 2011-12-16 19:06:07 +0000 | [diff] [blame] | 2483 | if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_backtrace_limit_EQ)) { |
| 2484 | CmdArgs.push_back("-fconstexpr-backtrace-limit"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2485 | CmdArgs.push_back(A->getValue()); |
Richard Smith | 08d6e03 | 2011-12-16 19:06:07 +0000 | [diff] [blame] | 2486 | } |
| 2487 | |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 2488 | // Pass -fmessage-length=. |
Daniel Dunbar | a28690e | 2009-11-30 08:40:54 +0000 | [diff] [blame] | 2489 | CmdArgs.push_back("-fmessage-length"); |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 2490 | if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2491 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 2492 | } else { |
| 2493 | // If -fmessage-length=N was not specified, determine whether this is a |
| 2494 | // terminal and, if so, implicitly define -fmessage-length appropriately. |
| 2495 | unsigned N = llvm::sys::Process::StandardErrColumns(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2496 | CmdArgs.push_back(Args.MakeArgString(Twine(N))); |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 2497 | } |
| 2498 | |
Daniel Dunbar | ba8d861 | 2009-12-03 18:42:11 +0000 | [diff] [blame] | 2499 | if (const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ)) { |
| 2500 | CmdArgs.push_back("-fvisibility"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2501 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | ba8d861 | 2009-12-03 18:42:11 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 2504 | Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2505 | |
Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 2506 | Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ); |
| 2507 | |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 2508 | // -fhosted is default. |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 2509 | if (Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted, false) || |
| 2510 | KernelOrKext) |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 2511 | CmdArgs.push_back("-ffreestanding"); |
| 2512 | |
Daniel Dunbar | ba8d861 | 2009-12-03 18:42:11 +0000 | [diff] [blame] | 2513 | // Forward -f (flag) options which we can pass directly. |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 2514 | Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 2515 | Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); |
Devang Patel | c69e1cf | 2010-09-30 19:05:55 +0000 | [diff] [blame] | 2516 | Args.AddLastArg(CmdArgs, options::OPT_flimit_debug_info); |
Devang Patel | 033be8b | 2011-11-04 20:05:58 +0000 | [diff] [blame] | 2517 | Args.AddLastArg(CmdArgs, options::OPT_fno_limit_debug_info); |
Eric Christopher | e88c451 | 2011-10-25 07:13:06 +0000 | [diff] [blame] | 2518 | Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); |
Anton Yartsev | 17ba267 | 2011-12-23 20:23:19 +0000 | [diff] [blame] | 2519 | Args.AddLastArg(CmdArgs, options::OPT_faltivec); |
Richard Trieu | 246b6aa | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 2520 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree); |
| 2521 | Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type); |
Chad Rosier | 4574c3d | 2012-03-13 23:45:51 +0000 | [diff] [blame] | 2522 | |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 2523 | SanitizerArgs Sanitize(D, Args); |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2524 | Sanitize.addArgs(Args, CmdArgs); |
| 2525 | |
Will Dietz | 2d382d1 | 2012-12-30 20:53:28 +0000 | [diff] [blame] | 2526 | if (!Args.hasFlag(options::OPT_fsanitize_recover, |
| 2527 | options::OPT_fno_sanitize_recover, |
| 2528 | true)) |
| 2529 | CmdArgs.push_back("-fno-sanitize-recover"); |
| 2530 | |
Chad Rosier | 78d85b1 | 2013-01-29 23:31:22 +0000 | [diff] [blame] | 2531 | if (Args.hasArg(options::OPT_fcatch_undefined_behavior) || |
| 2532 | Args.hasFlag(options::OPT_fsanitize_undefined_trap_on_error, |
| 2533 | options::OPT_fno_sanitize_undefined_trap_on_error, false)) |
| 2534 | CmdArgs.push_back("-fsanitize-undefined-trap-on-error"); |
| 2535 | |
Chad Rosier | 4574c3d | 2012-03-13 23:45:51 +0000 | [diff] [blame] | 2536 | // Report and error for -faltivec on anything other then PowerPC. |
| 2537 | if (const Arg *A = Args.getLastArg(options::OPT_faltivec)) |
| 2538 | if (!(getToolChain().getTriple().getArch() == llvm::Triple::ppc || |
| 2539 | getToolChain().getTriple().getArch() == llvm::Triple::ppc64)) |
| 2540 | D.Diag(diag::err_drv_argument_only_allowed_with) |
| 2541 | << A->getAsString(Args) << "ppc/ppc64"; |
| 2542 | |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 2543 | if (getToolChain().SupportsProfiling()) |
| 2544 | Args.AddLastArg(CmdArgs, options::OPT_pg); |
Daniel Dunbar | 8c6fa84 | 2010-03-16 16:57:46 +0000 | [diff] [blame] | 2545 | |
| 2546 | // -flax-vector-conversions is default. |
| 2547 | if (!Args.hasFlag(options::OPT_flax_vector_conversions, |
| 2548 | options::OPT_fno_lax_vector_conversions)) |
| 2549 | CmdArgs.push_back("-fno-lax-vector-conversions"); |
| 2550 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2551 | if (Args.getLastArg(options::OPT_fapple_kext)) |
| 2552 | CmdArgs.push_back("-fapple-kext"); |
| 2553 | |
David Blaikie | 940152f | 2012-06-14 18:55:27 +0000 | [diff] [blame] | 2554 | if (Args.hasFlag(options::OPT_frewrite_includes, |
| 2555 | options::OPT_fno_rewrite_includes, false)) |
| 2556 | CmdArgs.push_back("-frewrite-includes"); |
| 2557 | |
Fariborz Jahanian | 34e6577 | 2009-05-22 20:17:16 +0000 | [diff] [blame] | 2558 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch); |
Chris Lattner | 182e092 | 2009-04-21 05:34:31 +0000 | [diff] [blame] | 2559 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info); |
Douglas Gregor | 4786c15 | 2010-08-19 20:24:43 +0000 | [diff] [blame] | 2560 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 2561 | Args.AddLastArg(CmdArgs, options::OPT_ftime_report); |
| 2562 | Args.AddLastArg(CmdArgs, options::OPT_ftrapv); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 2563 | |
| 2564 | if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) { |
| 2565 | CmdArgs.push_back("-ftrapv-handler"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2566 | CmdArgs.push_back(A->getValue()); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
Bob Wilson | 71fd6cc | 2012-02-03 06:27:22 +0000 | [diff] [blame] | 2569 | Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ); |
Evan Cheng | 49af1f3 | 2011-04-08 21:37:45 +0000 | [diff] [blame] | 2570 | |
Chandler Carruth | 5adb5a8 | 2011-03-27 00:04:55 +0000 | [diff] [blame] | 2571 | // -fno-strict-overflow implies -fwrapv if it isn't disabled, but |
| 2572 | // -fstrict-overflow won't turn off an explicitly enabled -fwrapv. |
| 2573 | if (Arg *A = Args.getLastArg(options::OPT_fwrapv, |
| 2574 | options::OPT_fno_wrapv)) { |
| 2575 | if (A->getOption().matches(options::OPT_fwrapv)) |
| 2576 | CmdArgs.push_back("-fwrapv"); |
| 2577 | } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow, |
| 2578 | options::OPT_fno_strict_overflow)) { |
| 2579 | if (A->getOption().matches(options::OPT_fno_strict_overflow)) |
| 2580 | CmdArgs.push_back("-fwrapv"); |
| 2581 | } |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 2582 | Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); |
Eric Christopher | f84d409 | 2010-08-07 23:08:14 +0000 | [diff] [blame] | 2583 | Args.AddLastArg(CmdArgs, options::OPT_funroll_loops); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 2584 | |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 2585 | Args.AddLastArg(CmdArgs, options::OPT_pthread); |
| 2586 | |
Mahesha S | f3b5231 | 2012-10-27 07:47:56 +0000 | [diff] [blame] | 2587 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2588 | // -stack-protector=0 is default. |
| 2589 | unsigned StackProtectorLevel = 0; |
Bill Wendling | 45483f7 | 2009-06-28 07:36:13 +0000 | [diff] [blame] | 2590 | if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, |
| 2591 | options::OPT_fstack_protector_all, |
| 2592 | options::OPT_fstack_protector)) { |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2593 | if (A->getOption().matches(options::OPT_fstack_protector)) |
| 2594 | StackProtectorLevel = 1; |
| 2595 | else if (A->getOption().matches(options::OPT_fstack_protector_all)) |
| 2596 | StackProtectorLevel = 2; |
Nico Weber | 2fef111 | 2011-08-23 07:38:27 +0000 | [diff] [blame] | 2597 | } else { |
| 2598 | StackProtectorLevel = |
| 2599 | getToolChain().GetDefaultStackProtectorLevel(KernelOrKext); |
| 2600 | } |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2601 | if (StackProtectorLevel) { |
| 2602 | CmdArgs.push_back("-stack-protector"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2603 | CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel))); |
Joerg Sonnenberger | 53b43a7 | 2012-09-12 13:51:14 +0000 | [diff] [blame] | 2604 | } |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 2605 | |
Joerg Sonnenberger | 53b43a7 | 2012-09-12 13:51:14 +0000 | [diff] [blame] | 2606 | // --param ssp-buffer-size= |
| 2607 | for (arg_iterator it = Args.filtered_begin(options::OPT__param), |
| 2608 | ie = Args.filtered_end(); it != ie; ++it) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2609 | StringRef Str((*it)->getValue()); |
Joerg Sonnenberger | 53b43a7 | 2012-09-12 13:51:14 +0000 | [diff] [blame] | 2610 | if (Str.startswith("ssp-buffer-size=")) { |
| 2611 | if (StackProtectorLevel) { |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 2612 | CmdArgs.push_back("-stack-protector-buffer-size"); |
| 2613 | // FIXME: Verify the argument is a valid integer. |
| 2614 | CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16))); |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 2615 | } |
Joerg Sonnenberger | 53b43a7 | 2012-09-12 13:51:14 +0000 | [diff] [blame] | 2616 | (*it)->claim(); |
Chad Rosier | a7afeb0 | 2012-08-21 16:16:06 +0000 | [diff] [blame] | 2617 | } |
Bill Wendling | 45483f7 | 2009-06-28 07:36:13 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
Nick Lewycky | 4e785c9 | 2011-12-06 03:33:03 +0000 | [diff] [blame] | 2620 | // Translate -mstackrealign |
| 2621 | if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign, |
| 2622 | false)) { |
| 2623 | CmdArgs.push_back("-backend-option"); |
| 2624 | CmdArgs.push_back("-force-align-stack"); |
| 2625 | } |
| 2626 | if (!Args.hasFlag(options::OPT_mno_stackrealign, options::OPT_mstackrealign, |
| 2627 | false)) { |
| 2628 | CmdArgs.push_back(Args.MakeArgString("-mstackrealign")); |
| 2629 | } |
| 2630 | |
Joerg Sonnenberger | e9d11db | 2011-12-05 23:05:23 +0000 | [diff] [blame] | 2631 | if (Args.hasArg(options::OPT_mstack_alignment)) { |
| 2632 | StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment); |
| 2633 | CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment)); |
Eric Christopher | 1a58402 | 2011-05-02 21:18:22 +0000 | [diff] [blame] | 2634 | } |
Chad Rosier | 586a061 | 2012-11-29 00:42:06 +0000 | [diff] [blame] | 2635 | // -mkernel implies -mstrict-align; don't add the redundant option. |
| 2636 | if (Args.hasArg(options::OPT_mstrict_align) && !KernelOrKext) { |
Chad Rosier | 485577d | 2012-11-09 18:27:01 +0000 | [diff] [blame] | 2637 | CmdArgs.push_back("-backend-option"); |
| 2638 | CmdArgs.push_back("-arm-strict-align"); |
Chad Rosier | 7e29327 | 2012-11-09 17:29:19 +0000 | [diff] [blame] | 2639 | } |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 2640 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2641 | // Forward -f options with positive and negative forms; we translate |
| 2642 | // these by hand. |
| 2643 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2644 | if (Args.hasArg(options::OPT_mkernel)) { |
Daniel Dunbar | 2843c19 | 2011-02-04 17:24:47 +0000 | [diff] [blame] | 2645 | if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType)) |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2646 | CmdArgs.push_back("-fapple-kext"); |
| 2647 | if (!Args.hasArg(options::OPT_fbuiltin)) |
| 2648 | CmdArgs.push_back("-fno-builtin"); |
Chad Rosier | 3d26550 | 2012-03-26 21:29:17 +0000 | [diff] [blame] | 2649 | Args.ClaimAllArgs(options::OPT_fno_builtin); |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2650 | } |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2651 | // -fbuiltin is default. |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2652 | else if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin)) |
Daniel Dunbar | 53e8484 | 2009-11-19 04:55:23 +0000 | [diff] [blame] | 2653 | CmdArgs.push_back("-fno-builtin"); |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2654 | |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 2655 | if (!Args.hasFlag(options::OPT_fassume_sane_operator_new, |
| 2656 | options::OPT_fno_assume_sane_operator_new)) |
| 2657 | CmdArgs.push_back("-fno-assume-sane-operator-new"); |
| 2658 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2659 | // -fblocks=0 is default. |
| 2660 | if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks, |
David Chisnall | e6533ff | 2011-02-28 17:11:43 +0000 | [diff] [blame] | 2661 | getToolChain().IsBlocksDefault()) || |
| 2662 | (Args.hasArg(options::OPT_fgnu_runtime) && |
| 2663 | Args.hasArg(options::OPT_fobjc_nonfragile_abi) && |
| 2664 | !Args.hasArg(options::OPT_fno_blocks))) { |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 2665 | CmdArgs.push_back("-fblocks"); |
John McCall | 13db5cf | 2011-09-09 20:41:01 +0000 | [diff] [blame] | 2666 | |
| 2667 | if (!Args.hasArg(options::OPT_fgnu_runtime) && |
| 2668 | !getToolChain().hasBlocksRuntime()) |
| 2669 | CmdArgs.push_back("-fblocks-runtime-optional"); |
David Chisnall | 5e530af | 2009-11-17 19:33:30 +0000 | [diff] [blame] | 2670 | } |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2671 | |
Douglas Gregor | 64554ba | 2012-01-18 15:19:58 +0000 | [diff] [blame] | 2672 | // -fmodules enables modules (off by default). However, for C++/Objective-C++, |
| 2673 | // users must also pass -fcxx-modules. The latter flag will disappear once the |
| 2674 | // modules implementation is solid for C++/Objective-C++ programs as well. |
Douglas Gregor | f43b721 | 2013-01-16 01:23:41 +0000 | [diff] [blame] | 2675 | bool HaveModules = false; |
Douglas Gregor | 64554ba | 2012-01-18 15:19:58 +0000 | [diff] [blame] | 2676 | if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) { |
| 2677 | bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules, |
| 2678 | options::OPT_fno_cxx_modules, |
| 2679 | false); |
Douglas Gregor | f43b721 | 2013-01-16 01:23:41 +0000 | [diff] [blame] | 2680 | if (AllowedInCXX || !types::isCXX(InputType)) { |
Douglas Gregor | 64554ba | 2012-01-18 15:19:58 +0000 | [diff] [blame] | 2681 | CmdArgs.push_back("-fmodules"); |
Douglas Gregor | f43b721 | 2013-01-16 01:23:41 +0000 | [diff] [blame] | 2682 | HaveModules = true; |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | // -fmodules-autolink (on by default when modules is enabled) automatically |
| 2687 | // links against libraries for imported modules. |
| 2688 | if (HaveModules && |
| 2689 | Args.hasFlag(options::OPT_fmodules_autolink, |
| 2690 | options::OPT_fno_modules_autolink, |
| 2691 | true)) { |
| 2692 | CmdArgs.push_back("-fmodules-autolink"); |
Douglas Gregor | 64554ba | 2012-01-18 15:19:58 +0000 | [diff] [blame] | 2693 | } |
Douglas Gregor | 7025d2c | 2012-01-03 17:13:05 +0000 | [diff] [blame] | 2694 | |
John McCall | 32579cf | 2010-04-09 19:12:06 +0000 | [diff] [blame] | 2695 | // -faccess-control is default. |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 2696 | if (Args.hasFlag(options::OPT_fno_access_control, |
| 2697 | options::OPT_faccess_control, |
John McCall | 32579cf | 2010-04-09 19:12:06 +0000 | [diff] [blame] | 2698 | false)) |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 2699 | CmdArgs.push_back("-fno-access-control"); |
John McCall | 3ddd6e0 | 2010-03-17 01:32:13 +0000 | [diff] [blame] | 2700 | |
Anders Carlsson | a4c2475 | 2010-11-21 00:09:52 +0000 | [diff] [blame] | 2701 | // -felide-constructors is the default. |
| 2702 | if (Args.hasFlag(options::OPT_fno_elide_constructors, |
| 2703 | options::OPT_felide_constructors, |
| 2704 | false)) |
| 2705 | CmdArgs.push_back("-fno-elide-constructors"); |
| 2706 | |
Daniel Dunbar | 0be42c4 | 2009-11-17 07:06:20 +0000 | [diff] [blame] | 2707 | // -frtti is default. |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 2708 | if (!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti) || |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2709 | KernelOrKext) { |
Daniel Dunbar | 53e8484 | 2009-11-19 04:55:23 +0000 | [diff] [blame] | 2710 | CmdArgs.push_back("-fno-rtti"); |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 2711 | |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2712 | // -fno-rtti cannot usefully be combined with -fsanitize=vptr. |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 2713 | if (Sanitize.sanitizesVptr()) { |
NAKAMURA Takumi | 03c6076 | 2012-11-06 22:02:00 +0000 | [diff] [blame] | 2714 | std::string NoRttiArg = |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2715 | Args.getLastArg(options::OPT_mkernel, |
| 2716 | options::OPT_fapple_kext, |
Richard Smith | 04fd382 | 2012-11-06 01:12:02 +0000 | [diff] [blame] | 2717 | options::OPT_fno_rtti)->getAsString(Args); |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 2718 | D.Diag(diag::err_drv_argument_not_allowed_with) |
| 2719 | << "-fsanitize=vptr" << NoRttiArg; |
| 2720 | } |
| 2721 | } |
| 2722 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2723 | // -fshort-enums=0 is default for all architectures except Hexagon. |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 2724 | if (Args.hasFlag(options::OPT_fshort_enums, |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2725 | options::OPT_fno_short_enums, |
| 2726 | getToolChain().getTriple().getArch() == |
| 2727 | llvm::Triple::hexagon)) |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 2728 | CmdArgs.push_back("-fshort-enums"); |
| 2729 | |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 2730 | // -fsigned-char is default. |
Daniel Dunbar | 6d2eb4d | 2009-11-25 10:14:30 +0000 | [diff] [blame] | 2731 | if (!Args.hasFlag(options::OPT_fsigned_char, options::OPT_funsigned_char, |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 2732 | isSignedCharDefault(getToolChain().getTriple()))) |
Daniel Dunbar | 7674352 | 2009-11-29 02:39:08 +0000 | [diff] [blame] | 2733 | CmdArgs.push_back("-fno-signed-char"); |
Eli Friedman | 5a77973 | 2009-06-05 07:21:14 +0000 | [diff] [blame] | 2734 | |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 2735 | // -fthreadsafe-static is default. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2736 | if (!Args.hasFlag(options::OPT_fthreadsafe_statics, |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 2737 | options::OPT_fno_threadsafe_statics)) |
| 2738 | CmdArgs.push_back("-fno-threadsafe-statics"); |
| 2739 | |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 2740 | // -fuse-cxa-atexit is default. |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 2741 | if (!Args.hasFlag(options::OPT_fuse_cxa_atexit, |
| 2742 | options::OPT_fno_use_cxa_atexit, |
| 2743 | getToolChain().getTriple().getOS() != llvm::Triple::Cygwin && |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 2744 | getToolChain().getTriple().getOS() != llvm::Triple::MinGW32 && |
Chad Rosier | afc4baa | 2012-03-26 22:04:46 +0000 | [diff] [blame] | 2745 | getToolChain().getTriple().getArch() != llvm::Triple::hexagon) || |
| 2746 | KernelOrKext) |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 2747 | CmdArgs.push_back("-fno-use-cxa-atexit"); |
| 2748 | |
Daniel Dunbar | 0be42c4 | 2009-11-17 07:06:20 +0000 | [diff] [blame] | 2749 | // -fms-extensions=0 is default. |
Daniel Dunbar | 6d2eb4d | 2009-11-25 10:14:30 +0000 | [diff] [blame] | 2750 | if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, |
Daniel Dunbar | 0be42c4 | 2009-11-17 07:06:20 +0000 | [diff] [blame] | 2751 | getToolChain().getTriple().getOS() == llvm::Triple::Win32)) |
| 2752 | CmdArgs.push_back("-fms-extensions"); |
| 2753 | |
Francois Pichet | ae55608 | 2011-09-17 04:32:15 +0000 | [diff] [blame] | 2754 | // -fms-compatibility=0 is default. |
Douglas Gregor | ba97b6e | 2011-10-24 15:49:38 +0000 | [diff] [blame] | 2755 | if (Args.hasFlag(options::OPT_fms_compatibility, |
| 2756 | options::OPT_fno_ms_compatibility, |
| 2757 | (getToolChain().getTriple().getOS() == llvm::Triple::Win32 && |
| 2758 | Args.hasFlag(options::OPT_fms_extensions, |
| 2759 | options::OPT_fno_ms_extensions, |
| 2760 | true)))) |
Francois Pichet | ae55608 | 2011-09-17 04:32:15 +0000 | [diff] [blame] | 2761 | CmdArgs.push_back("-fms-compatibility"); |
| 2762 | |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2763 | // -fmsc-version=1300 is default. |
| 2764 | if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, |
| 2765 | getToolChain().getTriple().getOS() == llvm::Triple::Win32) || |
| 2766 | Args.hasArg(options::OPT_fmsc_version)) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2767 | StringRef msc_ver = Args.getLastArgValue(options::OPT_fmsc_version); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2768 | if (msc_ver.empty()) |
| 2769 | CmdArgs.push_back("-fmsc-version=1300"); |
| 2770 | else |
| 2771 | CmdArgs.push_back(Args.MakeArgString("-fmsc-version=" + msc_ver)); |
| 2772 | } |
| 2773 | |
| 2774 | |
Dawn Perchik | 400b607 | 2010-09-02 23:59:25 +0000 | [diff] [blame] | 2775 | // -fborland-extensions=0 is default. |
| 2776 | if (Args.hasFlag(options::OPT_fborland_extensions, |
| 2777 | options::OPT_fno_borland_extensions, false)) |
| 2778 | CmdArgs.push_back("-fborland-extensions"); |
| 2779 | |
Francois Pichet | 8efcc01 | 2011-09-01 16:38:08 +0000 | [diff] [blame] | 2780 | // -fno-delayed-template-parsing is default, except for Windows where MSVC STL |
| 2781 | // needs it. |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 2782 | if (Args.hasFlag(options::OPT_fdelayed_template_parsing, |
| 2783 | options::OPT_fno_delayed_template_parsing, |
Francois Pichet | 8efcc01 | 2011-09-01 16:38:08 +0000 | [diff] [blame] | 2784 | getToolChain().getTriple().getOS() == llvm::Triple::Win32)) |
Francois Pichet | 805bc1f | 2011-08-26 00:22:34 +0000 | [diff] [blame] | 2785 | CmdArgs.push_back("-fdelayed-template-parsing"); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 2786 | |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2787 | // -fgnu-keywords default varies depending on language; only pass if |
| 2788 | // specified. |
| 2789 | if (Arg *A = Args.getLastArg(options::OPT_fgnu_keywords, |
Daniel Dunbar | 40788d9 | 2010-04-24 17:56:39 +0000 | [diff] [blame] | 2790 | options::OPT_fno_gnu_keywords)) |
| 2791 | A->render(Args, CmdArgs); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2792 | |
Rafael Espindola | 01ba854 | 2011-06-02 17:30:53 +0000 | [diff] [blame] | 2793 | if (Args.hasFlag(options::OPT_fgnu89_inline, |
| 2794 | options::OPT_fno_gnu89_inline, |
| 2795 | false)) |
Rafael Espindola | fb3f4aa | 2011-06-02 16:13:27 +0000 | [diff] [blame] | 2796 | CmdArgs.push_back("-fgnu89-inline"); |
| 2797 | |
Chad Rosier | fc055f9 | 2012-03-15 22:31:42 +0000 | [diff] [blame] | 2798 | if (Args.hasArg(options::OPT_fno_inline)) |
| 2799 | CmdArgs.push_back("-fno-inline"); |
| 2800 | |
Chad Rosier | 634a4b1 | 2012-03-06 21:17:19 +0000 | [diff] [blame] | 2801 | if (Args.hasArg(options::OPT_fno_inline_functions)) |
| 2802 | CmdArgs.push_back("-fno-inline-functions"); |
Chad Rosier | 250008b | 2012-03-06 18:49:20 +0000 | [diff] [blame] | 2803 | |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 2804 | ObjCRuntime objcRuntime = AddObjCRuntimeArgs(Args, CmdArgs, rewriteKind); |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2805 | |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 2806 | // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and |
| 2807 | // legacy is the default. |
| 2808 | if (objcRuntime.isNonFragile()) { |
David Chisnall | 3c3ccd2 | 2011-09-30 13:32:35 +0000 | [diff] [blame] | 2809 | if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch, |
| 2810 | options::OPT_fno_objc_legacy_dispatch, |
David Chisnall | 2c7886d | 2012-07-04 11:52:24 +0000 | [diff] [blame] | 2811 | objcRuntime.isLegacyDispatchDefaultForArch( |
| 2812 | getToolChain().getTriple().getArch()))) { |
David Chisnall | 3c3ccd2 | 2011-09-30 13:32:35 +0000 | [diff] [blame] | 2813 | if (getToolChain().UseObjCMixedDispatch()) |
| 2814 | CmdArgs.push_back("-fobjc-dispatch-method=mixed"); |
| 2815 | else |
| 2816 | CmdArgs.push_back("-fobjc-dispatch-method=non-legacy"); |
| 2817 | } |
| 2818 | } |
| 2819 | |
Nico Weber | df42354 | 2012-03-09 21:19:44 +0000 | [diff] [blame] | 2820 | // -fobjc-default-synthesize-properties=1 is default. This only has an effect |
| 2821 | // if the nonfragile objc abi is used. |
Fariborz Jahanian | e51fe09 | 2012-04-09 18:58:55 +0000 | [diff] [blame] | 2822 | if (getToolChain().IsObjCDefaultSynthPropertiesDefault()) { |
David Chisnall | 3c3ccd2 | 2011-09-30 13:32:35 +0000 | [diff] [blame] | 2823 | CmdArgs.push_back("-fobjc-default-synthesize-properties"); |
| 2824 | } |
| 2825 | |
Fariborz Jahanian | 3d145f6 | 2012-11-15 19:02:45 +0000 | [diff] [blame] | 2826 | // -fencode-extended-block-signature=1 is default. |
| 2827 | if (getToolChain().IsEncodeExtendedBlockSignatureDefault()) { |
| 2828 | CmdArgs.push_back("-fencode-extended-block-signature"); |
| 2829 | } |
| 2830 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2831 | // Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc. |
| 2832 | // NOTE: This logic is duplicated in ToolChains.cpp. |
| 2833 | bool ARC = isObjCAutoRefCount(Args); |
| 2834 | if (ARC) { |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 2835 | getToolChain().CheckObjCARC(); |
Argyrios Kyrtzidis | 5840dd9 | 2012-02-29 03:43:52 +0000 | [diff] [blame] | 2836 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2837 | CmdArgs.push_back("-fobjc-arc"); |
| 2838 | |
Chandler Carruth | 7ffa032 | 2011-11-04 07:34:47 +0000 | [diff] [blame] | 2839 | // FIXME: It seems like this entire block, and several around it should be |
| 2840 | // wrapped in isObjC, but for now we just use it here as this is where it |
| 2841 | // was being used previously. |
| 2842 | if (types::isCXX(InputType) && types::isObjC(InputType)) { |
| 2843 | if (getToolChain().GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) |
| 2844 | CmdArgs.push_back("-fobjc-arc-cxxlib=libc++"); |
| 2845 | else |
| 2846 | CmdArgs.push_back("-fobjc-arc-cxxlib=libstdc++"); |
| 2847 | } |
| 2848 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2849 | // Allow the user to enable full exceptions code emission. |
| 2850 | // We define off for Objective-CC, on for Objective-C++. |
| 2851 | if (Args.hasFlag(options::OPT_fobjc_arc_exceptions, |
| 2852 | options::OPT_fno_objc_arc_exceptions, |
| 2853 | /*default*/ types::isCXX(InputType))) |
| 2854 | CmdArgs.push_back("-fobjc-arc-exceptions"); |
| 2855 | } |
| 2856 | |
| 2857 | // -fobjc-infer-related-result-type is the default, except in the Objective-C |
| 2858 | // rewriter. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 2859 | if (rewriteKind != RK_None) |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2860 | CmdArgs.push_back("-fno-objc-infer-related-result-type"); |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 2861 | |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2862 | // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only |
| 2863 | // takes precedence. |
| 2864 | const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only); |
| 2865 | if (!GCArg) |
| 2866 | GCArg = Args.getLastArg(options::OPT_fobjc_gc); |
| 2867 | if (GCArg) { |
| 2868 | if (ARC) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2869 | D.Diag(diag::err_drv_objc_gc_arr) |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2870 | << GCArg->getAsString(Args); |
| 2871 | } else if (getToolChain().SupportsObjCGC()) { |
| 2872 | GCArg->render(Args, CmdArgs); |
| 2873 | } else { |
| 2874 | // FIXME: We should move this to a hard error. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2875 | D.Diag(diag::warn_drv_objc_gc_unsupported) |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 2876 | << GCArg->getAsString(Args); |
| 2877 | } |
| 2878 | } |
| 2879 | |
John McCall | d71315c | 2011-06-22 00:53:57 +0000 | [diff] [blame] | 2880 | // Add exception args. |
| 2881 | addExceptionArgs(Args, InputType, getToolChain().getTriple(), |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 2882 | KernelOrKext, objcRuntime, CmdArgs); |
John McCall | d71315c | 2011-06-22 00:53:57 +0000 | [diff] [blame] | 2883 | |
| 2884 | if (getToolChain().UseSjLjExceptions()) |
| 2885 | CmdArgs.push_back("-fsjlj-exceptions"); |
| 2886 | |
| 2887 | // C++ "sane" operator new. |
Daniel Dunbar | 984eb86 | 2010-02-01 21:07:25 +0000 | [diff] [blame] | 2888 | if (!Args.hasFlag(options::OPT_fassume_sane_operator_new, |
| 2889 | options::OPT_fno_assume_sane_operator_new)) |
| 2890 | CmdArgs.push_back("-fno-assume-sane-operator-new"); |
| 2891 | |
Daniel Dunbar | f35f14d | 2010-04-27 15:34:57 +0000 | [diff] [blame] | 2892 | // -fconstant-cfstrings is default, and may be subject to argument translation |
| 2893 | // on Darwin. |
| 2894 | if (!Args.hasFlag(options::OPT_fconstant_cfstrings, |
| 2895 | options::OPT_fno_constant_cfstrings) || |
| 2896 | !Args.hasFlag(options::OPT_mconstant_cfstrings, |
| 2897 | options::OPT_mno_constant_cfstrings)) |
| 2898 | CmdArgs.push_back("-fno-constant-cfstrings"); |
| 2899 | |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2900 | // -fshort-wchar default varies depending on platform; only |
| 2901 | // pass if specified. |
Daniel Dunbar | 1744a35 | 2010-04-27 15:35:03 +0000 | [diff] [blame] | 2902 | if (Arg *A = Args.getLastArg(options::OPT_fshort_wchar)) |
| 2903 | A->render(Args, CmdArgs); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2904 | |
Daniel Dunbar | ee848a7 | 2009-10-29 02:39:57 +0000 | [diff] [blame] | 2905 | // -fno-pascal-strings is default, only pass non-default. If the tool chain |
| 2906 | // happened to translate to -mpascal-strings, we want to back translate here. |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 2907 | // |
| 2908 | // FIXME: This is gross; that translation should be pulled from the |
| 2909 | // tool chain. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2910 | if (Args.hasFlag(options::OPT_fpascal_strings, |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 2911 | options::OPT_fno_pascal_strings, |
| 2912 | false) || |
| 2913 | Args.hasFlag(options::OPT_mpascal_strings, |
| 2914 | options::OPT_mno_pascal_strings, |
| 2915 | false)) |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2916 | CmdArgs.push_back("-fpascal-strings"); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 2917 | |
Daniel Dunbar | 88934e8 | 2011-10-05 21:04:55 +0000 | [diff] [blame] | 2918 | // Honor -fpack-struct= and -fpack-struct, if given. Note that |
| 2919 | // -fno-pack-struct doesn't apply to -fpack-struct=. |
| 2920 | if (Arg *A = Args.getLastArg(options::OPT_fpack_struct_EQ)) { |
James Molloy | 8049c44 | 2012-05-02 07:56:14 +0000 | [diff] [blame] | 2921 | std::string PackStructStr = "-fpack-struct="; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2922 | PackStructStr += A->getValue(); |
James Molloy | 8049c44 | 2012-05-02 07:56:14 +0000 | [diff] [blame] | 2923 | CmdArgs.push_back(Args.MakeArgString(PackStructStr)); |
Daniel Dunbar | 88934e8 | 2011-10-05 21:04:55 +0000 | [diff] [blame] | 2924 | } else if (Args.hasFlag(options::OPT_fpack_struct, |
| 2925 | options::OPT_fno_pack_struct, false)) { |
James Molloy | 8049c44 | 2012-05-02 07:56:14 +0000 | [diff] [blame] | 2926 | CmdArgs.push_back("-fpack-struct=1"); |
Daniel Dunbar | 88934e8 | 2011-10-05 21:04:55 +0000 | [diff] [blame] | 2927 | } |
| 2928 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2929 | if (Args.hasArg(options::OPT_mkernel) || |
| 2930 | Args.hasArg(options::OPT_fapple_kext)) { |
| 2931 | if (!Args.hasArg(options::OPT_fcommon)) |
| 2932 | CmdArgs.push_back("-fno-common"); |
Chad Rosier | ec09b3e | 2012-03-26 21:35:40 +0000 | [diff] [blame] | 2933 | Args.ClaimAllArgs(options::OPT_fno_common); |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2934 | } |
Daniel Dunbar | 88934e8 | 2011-10-05 21:04:55 +0000 | [diff] [blame] | 2935 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2936 | // -fcommon is default, only pass non-default. |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 2937 | else if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common)) |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 2938 | CmdArgs.push_back("-fno-common"); |
| 2939 | |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 2940 | // -fsigned-bitfields is default, and clang doesn't yet support |
Daniel Dunbar | 06205ca | 2010-10-15 22:30:42 +0000 | [diff] [blame] | 2941 | // -funsigned-bitfields. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2942 | if (!Args.hasFlag(options::OPT_fsigned_bitfields, |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 2943 | options::OPT_funsigned_bitfields)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2944 | D.Diag(diag::warn_drv_clang_unsupported) |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 2945 | << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args); |
| 2946 | |
Daniel Dunbar | 06205ca | 2010-10-15 22:30:42 +0000 | [diff] [blame] | 2947 | // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope. |
| 2948 | if (!Args.hasFlag(options::OPT_ffor_scope, |
| 2949 | options::OPT_fno_for_scope)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2950 | D.Diag(diag::err_drv_clang_unsupported) |
Daniel Dunbar | 06205ca | 2010-10-15 22:30:42 +0000 | [diff] [blame] | 2951 | << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args); |
| 2952 | |
Jeffrey Yasskin | 0ea22fd | 2010-06-08 04:56:20 +0000 | [diff] [blame] | 2953 | // -fcaret-diagnostics is default. |
| 2954 | if (!Args.hasFlag(options::OPT_fcaret_diagnostics, |
| 2955 | options::OPT_fno_caret_diagnostics, true)) |
| 2956 | CmdArgs.push_back("-fno-caret-diagnostics"); |
| 2957 | |
Daniel Dunbar | 49138fc | 2009-04-19 21:09:34 +0000 | [diff] [blame] | 2958 | // -fdiagnostics-fixit-info is default, only pass non-default. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2959 | if (!Args.hasFlag(options::OPT_fdiagnostics_fixit_info, |
Daniel Dunbar | 49138fc | 2009-04-19 21:09:34 +0000 | [diff] [blame] | 2960 | options::OPT_fno_diagnostics_fixit_info)) |
| 2961 | CmdArgs.push_back("-fno-diagnostics-fixit-info"); |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 2962 | |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 2963 | // Enable -fdiagnostics-show-option by default. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2964 | if (Args.hasFlag(options::OPT_fdiagnostics_show_option, |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 2965 | options::OPT_fno_diagnostics_show_option)) |
| 2966 | CmdArgs.push_back("-fdiagnostics-show-option"); |
Daniel Dunbar | 838be48 | 2009-11-04 06:24:57 +0000 | [diff] [blame] | 2967 | |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 2968 | if (const Arg *A = |
| 2969 | Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) { |
| 2970 | CmdArgs.push_back("-fdiagnostics-show-category"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2971 | CmdArgs.push_back(A->getValue()); |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 2972 | } |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 2973 | |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 2974 | if (const Arg *A = |
| 2975 | Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) { |
| 2976 | CmdArgs.push_back("-fdiagnostics-format"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 2977 | CmdArgs.push_back(A->getValue()); |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 2978 | } |
| 2979 | |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 2980 | if (Arg *A = Args.getLastArg( |
| 2981 | options::OPT_fdiagnostics_show_note_include_stack, |
| 2982 | options::OPT_fno_diagnostics_show_note_include_stack)) { |
| 2983 | if (A->getOption().matches( |
| 2984 | options::OPT_fdiagnostics_show_note_include_stack)) |
| 2985 | CmdArgs.push_back("-fdiagnostics-show-note-include-stack"); |
| 2986 | else |
| 2987 | CmdArgs.push_back("-fno-diagnostics-show-note-include-stack"); |
| 2988 | } |
| 2989 | |
Daniel Dunbar | 838be48 | 2009-11-04 06:24:57 +0000 | [diff] [blame] | 2990 | // Color diagnostics are the default, unless the terminal doesn't support |
| 2991 | // them. |
| 2992 | if (Args.hasFlag(options::OPT_fcolor_diagnostics, |
Argyrios Kyrtzidis | f765d76 | 2010-09-23 12:56:06 +0000 | [diff] [blame] | 2993 | options::OPT_fno_color_diagnostics, |
| 2994 | llvm::sys::Process::StandardErrHasColors())) |
Daniel Dunbar | 838be48 | 2009-11-04 06:24:57 +0000 | [diff] [blame] | 2995 | CmdArgs.push_back("-fcolor-diagnostics"); |
| 2996 | |
Daniel Dunbar | 75eb1d6 | 2009-06-08 21:13:54 +0000 | [diff] [blame] | 2997 | if (!Args.hasFlag(options::OPT_fshow_source_location, |
| 2998 | options::OPT_fno_show_source_location)) |
| 2999 | CmdArgs.push_back("-fno-show-source-location"); |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 3000 | |
Douglas Gregor | c9471b0 | 2011-05-21 17:07:29 +0000 | [diff] [blame] | 3001 | if (!Args.hasFlag(options::OPT_fshow_column, |
| 3002 | options::OPT_fno_show_column, |
| 3003 | true)) |
| 3004 | CmdArgs.push_back("-fno-show-column"); |
| 3005 | |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 3006 | if (!Args.hasFlag(options::OPT_fspell_checking, |
| 3007 | options::OPT_fno_spell_checking)) |
| 3008 | CmdArgs.push_back("-fno-spell-checking"); |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 3009 | |
Daniel Dunbar | 25b26eb | 2010-10-18 22:49:46 +0000 | [diff] [blame] | 3010 | |
Chad Rosier | 15490fd | 2012-12-05 21:08:21 +0000 | [diff] [blame] | 3011 | // -fno-asm-blocks is default. |
| 3012 | if (Args.hasFlag(options::OPT_fasm_blocks, options::OPT_fno_asm_blocks, |
| 3013 | false)) |
| 3014 | CmdArgs.push_back("-fasm-blocks"); |
Daniel Dunbar | 25b26eb | 2010-10-18 22:49:46 +0000 | [diff] [blame] | 3015 | |
Nadav Rotem | 0f6ef28 | 2012-12-18 23:10:16 +0000 | [diff] [blame] | 3016 | // -fvectorize is default. |
Chad Rosier | c04d093 | 2012-12-11 17:12:28 +0000 | [diff] [blame] | 3017 | if (Args.hasFlag(options::OPT_fvectorize, |
Nadav Rotem | 0f6ef28 | 2012-12-18 23:10:16 +0000 | [diff] [blame] | 3018 | options::OPT_fno_vectorize, true)) { |
Chad Rosier | c04d093 | 2012-12-11 17:12:28 +0000 | [diff] [blame] | 3019 | CmdArgs.push_back("-backend-option"); |
| 3020 | CmdArgs.push_back("-vectorize-loops"); |
| 3021 | } |
| 3022 | |
Hal Finkel | 443c999 | 2012-12-11 19:59:32 +0000 | [diff] [blame] | 3023 | // -fno-slp-vectorize is default. |
| 3024 | if (Args.hasFlag(options::OPT_fslp_vectorize, |
| 3025 | options::OPT_fno_slp_vectorize, false)) { |
| 3026 | CmdArgs.push_back("-backend-option"); |
| 3027 | CmdArgs.push_back("-vectorize"); |
| 3028 | } |
| 3029 | |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 3030 | if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ)) |
| 3031 | A->render(Args, CmdArgs); |
| 3032 | |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 3033 | // -fdollars-in-identifiers default varies depending on platform and |
| 3034 | // language; only pass if specified. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3035 | if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers, |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 3036 | options::OPT_fno_dollars_in_identifiers)) { |
| 3037 | if (A->getOption().matches(options::OPT_fdollars_in_identifiers)) |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 3038 | CmdArgs.push_back("-fdollars-in-identifiers"); |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 3039 | else |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 3040 | CmdArgs.push_back("-fno-dollars-in-identifiers"); |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 3043 | // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for |
| 3044 | // practical purposes. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3045 | if (Arg *A = Args.getLastArg(options::OPT_funit_at_a_time, |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 3046 | options::OPT_fno_unit_at_a_time)) { |
| 3047 | if (A->getOption().matches(options::OPT_fno_unit_at_a_time)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3048 | D.Diag(diag::warn_drv_clang_unsupported) << A->getAsString(Args); |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 3049 | } |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 3050 | |
Eli Friedman | 19bda3a | 2011-11-02 01:53:16 +0000 | [diff] [blame] | 3051 | if (Args.hasFlag(options::OPT_fapple_pragma_pack, |
| 3052 | options::OPT_fno_apple_pragma_pack, false)) |
| 3053 | CmdArgs.push_back("-fapple-pragma-pack"); |
| 3054 | |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 3055 | // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM. |
Daniel Dunbar | f84a4a4 | 2009-09-10 04:57:27 +0000 | [diff] [blame] | 3056 | // |
Daniel Dunbar | 8ff5b28 | 2009-12-11 23:00:49 +0000 | [diff] [blame] | 3057 | // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941. |
Daniel Dunbar | f84a4a4 | 2009-09-10 04:57:27 +0000 | [diff] [blame] | 3058 | #if 0 |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 3059 | if (getToolChain().getTriple().isOSDarwin() && |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 3060 | (getToolChain().getTriple().getArch() == llvm::Triple::arm || |
| 3061 | getToolChain().getTriple().getArch() == llvm::Triple::thumb)) { |
| 3062 | if (!Args.hasArg(options::OPT_fbuiltin_strcat)) |
| 3063 | CmdArgs.push_back("-fno-builtin-strcat"); |
| 3064 | if (!Args.hasArg(options::OPT_fbuiltin_strcpy)) |
| 3065 | CmdArgs.push_back("-fno-builtin-strcpy"); |
| 3066 | } |
Daniel Dunbar | f84a4a4 | 2009-09-10 04:57:27 +0000 | [diff] [blame] | 3067 | #endif |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 3068 | |
Daniel Dunbar | d98750f | 2011-03-18 21:23:40 +0000 | [diff] [blame] | 3069 | // Only allow -traditional or -traditional-cpp outside in preprocessing modes. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3070 | if (Arg *A = Args.getLastArg(options::OPT_traditional, |
Daniel Dunbar | d98750f | 2011-03-18 21:23:40 +0000 | [diff] [blame] | 3071 | options::OPT_traditional_cpp)) { |
| 3072 | if (isa<PreprocessJobAction>(JA)) |
| 3073 | CmdArgs.push_back("-traditional-cpp"); |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 3074 | else |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3075 | D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); |
Daniel Dunbar | d98750f | 2011-03-18 21:23:40 +0000 | [diff] [blame] | 3076 | } |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 3077 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3078 | Args.AddLastArg(CmdArgs, options::OPT_dM); |
Chris Lattner | d82df3a | 2009-04-12 01:56:53 +0000 | [diff] [blame] | 3079 | Args.AddLastArg(CmdArgs, options::OPT_dD); |
Ted Kremenek | 36f6e30 | 2011-11-11 00:07:43 +0000 | [diff] [blame] | 3080 | |
| 3081 | // Handle serialized diagnostics. |
| 3082 | if (Arg *A = Args.getLastArg(options::OPT__serialize_diags)) { |
| 3083 | CmdArgs.push_back("-serialize-diagnostic-file"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3084 | CmdArgs.push_back(Args.MakeArgString(A->getValue())); |
Ted Kremenek | 36f6e30 | 2011-11-11 00:07:43 +0000 | [diff] [blame] | 3085 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3086 | |
Ted Kremenek | 127ff2e | 2012-09-13 06:41:18 +0000 | [diff] [blame] | 3087 | if (Args.hasArg(options::OPT_fretain_comments_from_system_headers)) |
| 3088 | CmdArgs.push_back("-fretain-comments-from-system-headers"); |
| 3089 | |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 3090 | // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option |
| 3091 | // parser. |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3092 | Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 3093 | for (arg_iterator it = Args.filtered_begin(options::OPT_mllvm), |
| 3094 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 3095 | (*it)->claim(); |
Daniel Dunbar | fb36d21 | 2010-04-17 06:10:00 +0000 | [diff] [blame] | 3096 | |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 3097 | // We translate this by hand to the -cc1 argument, since nightly test uses |
| 3098 | // it and developers have been trained to spell it with -mllvm. |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3099 | if (StringRef((*it)->getValue(0)) == "-disable-llvm-optzns") |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 3100 | CmdArgs.push_back("-disable-llvm-optzns"); |
| 3101 | else |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 3102 | (*it)->render(Args, CmdArgs); |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 3103 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3104 | |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 3105 | if (Output.getType() == types::TY_Dependencies) { |
| 3106 | // Handled with other dependency code. |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3107 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3108 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3109 | CmdArgs.push_back(Output.getFilename()); |
| 3110 | } else { |
| 3111 | assert(Output.isNothing() && "Invalid output."); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3112 | } |
| 3113 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3114 | for (InputInfoList::const_iterator |
| 3115 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3116 | const InputInfo &II = *it; |
| 3117 | CmdArgs.push_back("-x"); |
Fariborz Jahanian | a5ee089 | 2012-09-28 19:05:17 +0000 | [diff] [blame] | 3118 | if (Args.hasArg(options::OPT_rewrite_objc)) |
| 3119 | CmdArgs.push_back(types::getTypeName(types::TY_PP_ObjCXX)); |
| 3120 | else |
| 3121 | CmdArgs.push_back(types::getTypeName(II.getType())); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3122 | if (II.isFilename()) |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3123 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3124 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3125 | II.getInputArg().renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3126 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3127 | |
Chris Lattner | e6113de | 2009-11-03 19:50:27 +0000 | [diff] [blame] | 3128 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 3129 | |
Daniel Dunbar | a001c1c | 2010-07-18 21:16:15 +0000 | [diff] [blame] | 3130 | const char *Exec = getToolChain().getDriver().getClangProgramPath(); |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 3131 | |
| 3132 | // Optionally embed the -cc1 level arguments into the debug info, for build |
| 3133 | // analysis. |
| 3134 | if (getToolChain().UseDwarfDebugFlags()) { |
Daniel Dunbar | 6e90047 | 2010-06-04 18:47:06 +0000 | [diff] [blame] | 3135 | ArgStringList OriginalArgs; |
| 3136 | for (ArgList::const_iterator it = Args.begin(), |
| 3137 | ie = Args.end(); it != ie; ++it) |
| 3138 | (*it)->render(Args, OriginalArgs); |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 3139 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3140 | SmallString<256> Flags; |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 3141 | Flags += Exec; |
Daniel Dunbar | 6e90047 | 2010-06-04 18:47:06 +0000 | [diff] [blame] | 3142 | for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) { |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 3143 | Flags += " "; |
Daniel Dunbar | 6e90047 | 2010-06-04 18:47:06 +0000 | [diff] [blame] | 3144 | Flags += OriginalArgs[i]; |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 3145 | } |
| 3146 | CmdArgs.push_back("-dwarf-debug-flags"); |
| 3147 | CmdArgs.push_back(Args.MakeArgString(Flags.str())); |
| 3148 | } |
| 3149 | |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3150 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 3151 | |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 3152 | if (Arg *A = Args.getLastArg(options::OPT_pg)) |
| 3153 | if (Args.hasArg(options::OPT_fomit_frame_pointer)) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3154 | D.Diag(diag::err_drv_argument_not_allowed_with) |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 3155 | << "-fomit-frame-pointer" << A->getAsString(Args); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3156 | |
Daniel Dunbar | 68fb469 | 2009-04-03 20:51:31 +0000 | [diff] [blame] | 3157 | // Claim some arguments which clang supports automatically. |
| 3158 | |
Daniel Dunbar | f404686 | 2010-04-15 06:18:42 +0000 | [diff] [blame] | 3159 | // -fpch-preprocess is used with gcc to add a special marker in the output to |
| 3160 | // include the PCH file. Clang's PTH solution is completely transparent, so we |
| 3161 | // do not need to deal with it at all. |
Daniel Dunbar | 68fb469 | 2009-04-03 20:51:31 +0000 | [diff] [blame] | 3162 | Args.ClaimAllArgs(options::OPT_fpch_preprocess); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3163 | |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 3164 | // Claim some arguments which clang doesn't support, but we don't |
| 3165 | // care to warn the user about. |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 3166 | Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group); |
| 3167 | Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group); |
Rafael Espindola | 035ff0c | 2011-02-28 23:29:45 +0000 | [diff] [blame] | 3168 | |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 3169 | // Disable warnings for clang -E -use-gold-plugin -emit-llvm foo.c |
Rafael Espindola | 035ff0c | 2011-02-28 23:29:45 +0000 | [diff] [blame] | 3170 | Args.ClaimAllArgs(options::OPT_use_gold_plugin); |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 3171 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 3174 | void ClangAs::AddARMTargetArgs(const ArgList &Args, |
| 3175 | ArgStringList &CmdArgs) const { |
| 3176 | const Driver &D = getToolChain().getDriver(); |
| 3177 | llvm::Triple Triple = getToolChain().getTriple(); |
| 3178 | |
| 3179 | // Set the CPU based on -march= and -mcpu=. |
| 3180 | CmdArgs.push_back("-target-cpu"); |
Benjamin Kramer | 92c4fd5 | 2012-06-26 22:20:06 +0000 | [diff] [blame] | 3181 | CmdArgs.push_back(Args.MakeArgString(getARMTargetCPU(Args, Triple))); |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 3182 | |
| 3183 | // Honor -mfpu=. |
Chad Rosier | 9931727 | 2012-04-04 20:51:35 +0000 | [diff] [blame] | 3184 | if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) |
Chad Rosier | f80f2a5 | 2012-04-04 20:56:36 +0000 | [diff] [blame] | 3185 | addFPUArgs(D, A, Args, CmdArgs); |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 3186 | |
| 3187 | // Honor -mfpmath=. |
| 3188 | if (const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) |
Chad Rosier | 30fe6ba | 2012-04-04 22:13:40 +0000 | [diff] [blame] | 3189 | addFPMathArgs(D, A, Args, CmdArgs, getARMTargetCPU(Args, Triple)); |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3192 | /// Add options related to the Objective-C runtime/ABI. |
| 3193 | /// |
| 3194 | /// Returns true if the runtime is non-fragile. |
| 3195 | ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args, |
| 3196 | ArgStringList &cmdArgs, |
| 3197 | RewriteKind rewriteKind) const { |
| 3198 | // Look for the controlling runtime option. |
| 3199 | Arg *runtimeArg = args.getLastArg(options::OPT_fnext_runtime, |
| 3200 | options::OPT_fgnu_runtime, |
| 3201 | options::OPT_fobjc_runtime_EQ); |
| 3202 | |
| 3203 | // Just forward -fobjc-runtime= to the frontend. This supercedes |
| 3204 | // options about fragility. |
| 3205 | if (runtimeArg && |
| 3206 | runtimeArg->getOption().matches(options::OPT_fobjc_runtime_EQ)) { |
| 3207 | ObjCRuntime runtime; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3208 | StringRef value = runtimeArg->getValue(); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3209 | if (runtime.tryParse(value)) { |
| 3210 | getToolChain().getDriver().Diag(diag::err_drv_unknown_objc_runtime) |
| 3211 | << value; |
| 3212 | } |
| 3213 | |
| 3214 | runtimeArg->render(args, cmdArgs); |
| 3215 | return runtime; |
| 3216 | } |
| 3217 | |
| 3218 | // Otherwise, we'll need the ABI "version". Version numbers are |
| 3219 | // slightly confusing for historical reasons: |
| 3220 | // 1 - Traditional "fragile" ABI |
| 3221 | // 2 - Non-fragile ABI, version 1 |
| 3222 | // 3 - Non-fragile ABI, version 2 |
| 3223 | unsigned objcABIVersion = 1; |
| 3224 | // If -fobjc-abi-version= is present, use that to set the version. |
| 3225 | if (Arg *abiArg = args.getLastArg(options::OPT_fobjc_abi_version_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3226 | StringRef value = abiArg->getValue(); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3227 | if (value == "1") |
| 3228 | objcABIVersion = 1; |
| 3229 | else if (value == "2") |
| 3230 | objcABIVersion = 2; |
| 3231 | else if (value == "3") |
| 3232 | objcABIVersion = 3; |
| 3233 | else |
| 3234 | getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported) |
| 3235 | << value; |
| 3236 | } else { |
| 3237 | // Otherwise, determine if we are using the non-fragile ABI. |
| 3238 | bool nonFragileABIIsDefault = |
| 3239 | (rewriteKind == RK_NonFragile || |
| 3240 | (rewriteKind == RK_None && |
| 3241 | getToolChain().IsObjCNonFragileABIDefault())); |
| 3242 | if (args.hasFlag(options::OPT_fobjc_nonfragile_abi, |
| 3243 | options::OPT_fno_objc_nonfragile_abi, |
| 3244 | nonFragileABIIsDefault)) { |
| 3245 | // Determine the non-fragile ABI version to use. |
| 3246 | #ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO |
| 3247 | unsigned nonFragileABIVersion = 1; |
| 3248 | #else |
| 3249 | unsigned nonFragileABIVersion = 2; |
| 3250 | #endif |
| 3251 | |
| 3252 | if (Arg *abiArg = args.getLastArg( |
| 3253 | options::OPT_fobjc_nonfragile_abi_version_EQ)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3254 | StringRef value = abiArg->getValue(); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3255 | if (value == "1") |
| 3256 | nonFragileABIVersion = 1; |
| 3257 | else if (value == "2") |
| 3258 | nonFragileABIVersion = 2; |
| 3259 | else |
| 3260 | getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported) |
| 3261 | << value; |
| 3262 | } |
| 3263 | |
| 3264 | objcABIVersion = 1 + nonFragileABIVersion; |
| 3265 | } else { |
| 3266 | objcABIVersion = 1; |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | // We don't actually care about the ABI version other than whether |
| 3271 | // it's non-fragile. |
| 3272 | bool isNonFragile = objcABIVersion != 1; |
| 3273 | |
| 3274 | // If we have no runtime argument, ask the toolchain for its default runtime. |
| 3275 | // However, the rewriter only really supports the Mac runtime, so assume that. |
| 3276 | ObjCRuntime runtime; |
| 3277 | if (!runtimeArg) { |
| 3278 | switch (rewriteKind) { |
| 3279 | case RK_None: |
| 3280 | runtime = getToolChain().getDefaultObjCRuntime(isNonFragile); |
| 3281 | break; |
| 3282 | case RK_Fragile: |
| 3283 | runtime = ObjCRuntime(ObjCRuntime::FragileMacOSX, VersionTuple()); |
| 3284 | break; |
| 3285 | case RK_NonFragile: |
| 3286 | runtime = ObjCRuntime(ObjCRuntime::MacOSX, VersionTuple()); |
| 3287 | break; |
| 3288 | } |
| 3289 | |
| 3290 | // -fnext-runtime |
| 3291 | } else if (runtimeArg->getOption().matches(options::OPT_fnext_runtime)) { |
| 3292 | // On Darwin, make this use the default behavior for the toolchain. |
| 3293 | if (getToolChain().getTriple().isOSDarwin()) { |
| 3294 | runtime = getToolChain().getDefaultObjCRuntime(isNonFragile); |
| 3295 | |
| 3296 | // Otherwise, build for a generic macosx port. |
| 3297 | } else { |
| 3298 | runtime = ObjCRuntime(ObjCRuntime::MacOSX, VersionTuple()); |
| 3299 | } |
| 3300 | |
| 3301 | // -fgnu-runtime |
| 3302 | } else { |
| 3303 | assert(runtimeArg->getOption().matches(options::OPT_fgnu_runtime)); |
David Chisnall | a422cd0 | 2012-07-04 10:37:03 +0000 | [diff] [blame] | 3304 | // Legacy behaviour is to target the gnustep runtime if we are i |
| 3305 | // non-fragile mode or the GCC runtime in fragile mode. |
| 3306 | if (isNonFragile) |
David Chisnall | 891dac7 | 2012-10-16 15:11:55 +0000 | [diff] [blame] | 3307 | runtime = ObjCRuntime(ObjCRuntime::GNUstep, VersionTuple(1,6)); |
David Chisnall | a422cd0 | 2012-07-04 10:37:03 +0000 | [diff] [blame] | 3308 | else |
| 3309 | runtime = ObjCRuntime(ObjCRuntime::GCC, VersionTuple()); |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | cmdArgs.push_back(args.MakeArgString( |
| 3313 | "-fobjc-runtime=" + runtime.getAsString())); |
| 3314 | return runtime; |
| 3315 | } |
| 3316 | |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3317 | void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3318 | const InputInfo &Output, |
| 3319 | const InputInfoList &Inputs, |
| 3320 | const ArgList &Args, |
| 3321 | const char *LinkingOutput) const { |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3322 | ArgStringList CmdArgs; |
| 3323 | |
| 3324 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 3325 | const InputInfo &Input = Inputs[0]; |
| 3326 | |
Rafael Espindola | dbe80d9 | 2010-11-17 22:13:25 +0000 | [diff] [blame] | 3327 | // Don't warn about "clang -w -c foo.s" |
| 3328 | Args.ClaimAllArgs(options::OPT_w); |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 3329 | // and "clang -emit-llvm -c foo.s" |
| 3330 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
| 3331 | // and "clang -use-gold-plugin -c foo.s" |
| 3332 | Args.ClaimAllArgs(options::OPT_use_gold_plugin); |
Rafael Espindola | dbe80d9 | 2010-11-17 22:13:25 +0000 | [diff] [blame] | 3333 | |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3334 | // Invoke ourselves in -cc1as mode. |
| 3335 | // |
| 3336 | // FIXME: Implement custom jobs for internal actions. |
| 3337 | CmdArgs.push_back("-cc1as"); |
| 3338 | |
| 3339 | // Add the "effective" target triple. |
| 3340 | CmdArgs.push_back("-triple"); |
Chad Rosier | 61ab80a | 2011-09-20 20:44:06 +0000 | [diff] [blame] | 3341 | std::string TripleStr = |
| 3342 | getToolChain().ComputeEffectiveClangTriple(Args, Input.getType()); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3343 | CmdArgs.push_back(Args.MakeArgString(TripleStr)); |
| 3344 | |
| 3345 | // Set the output mode, we currently only expect to be used as a real |
| 3346 | // assembler. |
| 3347 | CmdArgs.push_back("-filetype"); |
| 3348 | CmdArgs.push_back("obj"); |
| 3349 | |
Eric Christopher | 27e2b98 | 2012-12-18 00:31:10 +0000 | [diff] [blame] | 3350 | // Set the main file name, so that debug info works even with |
| 3351 | // -save-temps or preprocessed assembly. |
| 3352 | CmdArgs.push_back("-main-file-name"); |
| 3353 | CmdArgs.push_back(Clang::getBaseInputName(Args, Inputs)); |
| 3354 | |
Joerg Sonnenberger | 359cf92 | 2011-05-06 14:35:16 +0000 | [diff] [blame] | 3355 | if (UseRelaxAll(C, Args)) |
Daniel Dunbar | 469d40e | 2010-05-28 16:43:21 +0000 | [diff] [blame] | 3356 | CmdArgs.push_back("-relax-all"); |
Daniel Dunbar | 9929800 | 2010-05-27 06:18:05 +0000 | [diff] [blame] | 3357 | |
Jim Grosbach | fc30829 | 2012-02-10 20:37:10 +0000 | [diff] [blame] | 3358 | // Add target specific cpu and features flags. |
| 3359 | switch(getToolChain().getTriple().getArch()) { |
| 3360 | default: |
| 3361 | break; |
| 3362 | |
| 3363 | case llvm::Triple::arm: |
| 3364 | case llvm::Triple::thumb: |
| 3365 | AddARMTargetArgs(Args, CmdArgs); |
| 3366 | break; |
| 3367 | } |
| 3368 | |
Daniel Dunbar | 7f6f8c8 | 2011-03-17 17:37:29 +0000 | [diff] [blame] | 3369 | // Ignore explicit -force_cpusubtype_ALL option. |
| 3370 | (void) Args.hasArg(options::OPT_force__cpusubtype__ALL); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3371 | |
Eric Christopher | 8f0a403 | 2012-01-10 00:38:01 +0000 | [diff] [blame] | 3372 | // Determine the original source input. |
| 3373 | const Action *SourceAction = &JA; |
| 3374 | while (SourceAction->getKind() != Action::InputClass) { |
| 3375 | assert(!SourceAction->getInputs().empty() && "unexpected root action!"); |
| 3376 | SourceAction = SourceAction->getInputs()[0]; |
| 3377 | } |
| 3378 | |
Chandler Carruth | d566df6 | 2012-12-17 21:40:04 +0000 | [diff] [blame] | 3379 | // Forward -g and handle debug info related flags, assuming we are dealing |
| 3380 | // with an actual assembly file. |
Eric Christopher | 8f0a403 | 2012-01-10 00:38:01 +0000 | [diff] [blame] | 3381 | if (SourceAction->getType() == types::TY_Asm || |
| 3382 | SourceAction->getType() == types::TY_PP_Asm) { |
| 3383 | Args.ClaimAllArgs(options::OPT_g_Group); |
| 3384 | if (Arg *A = Args.getLastArg(options::OPT_g_Group)) |
| 3385 | if (!A->getOption().matches(options::OPT_g0)) |
| 3386 | CmdArgs.push_back("-g"); |
Chandler Carruth | d566df6 | 2012-12-17 21:40:04 +0000 | [diff] [blame] | 3387 | |
| 3388 | // Add the -fdebug-compilation-dir flag if needed. |
| 3389 | addDebugCompDirArg(Args, CmdArgs); |
Kevin Enderby | 0234179 | 2013-01-17 21:38:06 +0000 | [diff] [blame] | 3390 | |
| 3391 | // Set the AT_producer to the clang version when using the integrated |
| 3392 | // assembler on assembly source files. |
| 3393 | CmdArgs.push_back("-dwarf-debug-producer"); |
| 3394 | CmdArgs.push_back(Args.MakeArgString(getClangFullVersion())); |
Eric Christopher | 8f0a403 | 2012-01-10 00:38:01 +0000 | [diff] [blame] | 3395 | } |
Kevin Enderby | 567003e | 2011-12-22 19:31:58 +0000 | [diff] [blame] | 3396 | |
| 3397 | // Optionally embed the -cc1as level arguments into the debug info, for build |
| 3398 | // analysis. |
| 3399 | if (getToolChain().UseDwarfDebugFlags()) { |
| 3400 | ArgStringList OriginalArgs; |
| 3401 | for (ArgList::const_iterator it = Args.begin(), |
| 3402 | ie = Args.end(); it != ie; ++it) |
| 3403 | (*it)->render(Args, OriginalArgs); |
| 3404 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3405 | SmallString<256> Flags; |
Kevin Enderby | 567003e | 2011-12-22 19:31:58 +0000 | [diff] [blame] | 3406 | const char *Exec = getToolChain().getDriver().getClangProgramPath(); |
| 3407 | Flags += Exec; |
| 3408 | for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) { |
| 3409 | Flags += " "; |
| 3410 | Flags += OriginalArgs[i]; |
| 3411 | } |
| 3412 | CmdArgs.push_back("-dwarf-debug-flags"); |
| 3413 | CmdArgs.push_back(Args.MakeArgString(Flags.str())); |
| 3414 | } |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3415 | |
| 3416 | // FIXME: Add -static support, once we have it. |
| 3417 | |
| 3418 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3419 | options::OPT_Xassembler); |
Daniel Dunbar | 3df2325 | 2011-04-29 17:53:18 +0000 | [diff] [blame] | 3420 | Args.AddAllArgs(CmdArgs, options::OPT_mllvm); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3421 | |
| 3422 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 3423 | CmdArgs.push_back("-o"); |
| 3424 | CmdArgs.push_back(Output.getFilename()); |
| 3425 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3426 | assert(Input.isFilename() && "Invalid input."); |
| 3427 | CmdArgs.push_back(Input.getFilename()); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3428 | |
Daniel Dunbar | a001c1c | 2010-07-18 21:16:15 +0000 | [diff] [blame] | 3429 | const char *Exec = getToolChain().getDriver().getClangProgramPath(); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3430 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3433 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3434 | const InputInfo &Output, |
| 3435 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3436 | const ArgList &Args, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3437 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3438 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3439 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3440 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3441 | for (ArgList::const_iterator |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3442 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3443 | Arg *A = *it; |
Michael J. Spencer | 91e06da | 2012-10-19 22:37:06 +0000 | [diff] [blame] | 3444 | if (forwardToGCC(A->getOption())) { |
Daniel Dunbar | 2dffe2d | 2010-08-03 16:14:14 +0000 | [diff] [blame] | 3445 | // Don't forward any -g arguments to assembly steps. |
| 3446 | if (isa<AssembleJobAction>(JA) && |
| 3447 | A->getOption().matches(options::OPT_g_Group)) |
| 3448 | continue; |
| 3449 | |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 3450 | // It is unfortunate that we have to claim here, as this means |
| 3451 | // we will basically never report anything interesting for |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 3452 | // platforms using a generic gcc, even if we are just using gcc |
| 3453 | // to get to the assembler. |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 3454 | A->claim(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 3455 | A->render(Args, CmdArgs); |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 3456 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3457 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3458 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3459 | RenderExtraToolArgs(JA, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3460 | |
| 3461 | // If using a driver driver, force the arch. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3462 | llvm::Triple::ArchType Arch = getToolChain().getArch(); |
Bob Wilson | 905c45f | 2011-10-14 05:03:44 +0000 | [diff] [blame] | 3463 | if (getToolChain().getTriple().isOSDarwin()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3464 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | bf54a06 | 2009-04-01 20:33:11 +0000 | [diff] [blame] | 3465 | |
| 3466 | // FIXME: Remove these special cases. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3467 | if (Arch == llvm::Triple::ppc) |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 3468 | CmdArgs.push_back("ppc"); |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3469 | else if (Arch == llvm::Triple::ppc64) |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 3470 | CmdArgs.push_back("ppc64"); |
| 3471 | else |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3472 | CmdArgs.push_back(Args.MakeArgString(getToolChain().getArchName())); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3473 | } |
| 3474 | |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 3475 | // Try to force gcc to match the tool chain we want, if we recognize |
| 3476 | // the arch. |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 3477 | // |
| 3478 | // FIXME: The triple class should directly provide the information we want |
| 3479 | // here. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3480 | if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc) |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 3481 | CmdArgs.push_back("-m32"); |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 3482 | else if (Arch == llvm::Triple::x86_64 || Arch == llvm::Triple::x86_64) |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 3483 | CmdArgs.push_back("-m64"); |
| 3484 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3485 | if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3486 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3487 | CmdArgs.push_back(Output.getFilename()); |
| 3488 | } else { |
| 3489 | assert(Output.isNothing() && "Unexpected output"); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3490 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3491 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3492 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3493 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3494 | options::OPT_Xassembler); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3495 | |
| 3496 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 3497 | // understands the suffix correctly. The main use case this would go |
| 3498 | // wrong in is for linker inputs if they happened to have an odd |
| 3499 | // suffix; really the only way to get this to happen is a command |
| 3500 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 3501 | // |
| 3502 | // FIXME: For the linker case specifically, can we safely convert |
| 3503 | // inputs into '-Wl,' options? |
| 3504 | for (InputInfoList::const_iterator |
| 3505 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3506 | const InputInfo &II = *it; |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 3507 | |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 3508 | // 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] | 3509 | if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR || |
| 3510 | II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3511 | D.Diag(diag::err_drv_no_linker_llvm_support) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 3512 | << getToolChain().getTripleString(); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 3513 | else if (II.getType() == types::TY_AST) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3514 | D.Diag(diag::err_drv_no_ast_support) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 3515 | << getToolChain().getTripleString(); |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 3516 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3517 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 3518 | CmdArgs.push_back("-x"); |
| 3519 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 3520 | } |
| 3521 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3522 | if (II.isFilename()) |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3523 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 48f9994 | 2010-09-25 18:10:05 +0000 | [diff] [blame] | 3524 | else { |
| 3525 | const Arg &A = II.getInputArg(); |
| 3526 | |
| 3527 | // Reverse translate some rewritten options. |
| 3528 | if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) { |
| 3529 | CmdArgs.push_back("-lstdc++"); |
| 3530 | continue; |
| 3531 | } |
| 3532 | |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 3533 | // Don't render as input, we need gcc to do the translations. |
Daniel Dunbar | 48f9994 | 2010-09-25 18:10:05 +0000 | [diff] [blame] | 3534 | A.render(Args, CmdArgs); |
| 3535 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3536 | } |
| 3537 | |
Dylan Noblesmith | b8a3e81 | 2011-04-09 13:31:59 +0000 | [diff] [blame] | 3538 | const std::string customGCCName = D.getCCCGenericGCCName(); |
| 3539 | const char *GCCName; |
| 3540 | if (!customGCCName.empty()) |
| 3541 | GCCName = customGCCName.c_str(); |
| 3542 | else if (D.CCCIsCXX) { |
Dylan Noblesmith | b8a3e81 | 2011-04-09 13:31:59 +0000 | [diff] [blame] | 3543 | GCCName = "g++"; |
Dylan Noblesmith | b8a3e81 | 2011-04-09 13:31:59 +0000 | [diff] [blame] | 3544 | } else |
| 3545 | GCCName = "gcc"; |
| 3546 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3547 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3548 | Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3549 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3550 | } |
| 3551 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3552 | void gcc::Preprocess::RenderExtraToolArgs(const JobAction &JA, |
| 3553 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3554 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3555 | } |
| 3556 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3557 | void gcc::Precompile::RenderExtraToolArgs(const JobAction &JA, |
| 3558 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3559 | // The type is good enough. |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3560 | } |
| 3561 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3562 | void gcc::Compile::RenderExtraToolArgs(const JobAction &JA, |
| 3563 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 3564 | const Driver &D = getToolChain().getDriver(); |
| 3565 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3566 | // 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] | 3567 | if (JA.getType() == types::TY_LLVM_IR || JA.getType() == types::TY_LTO_IR || |
| 3568 | JA.getType() == types::TY_LLVM_BC || JA.getType() == types::TY_LTO_BC) |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3569 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 3570 | else { |
| 3571 | if (JA.getType() != types::TY_PP_Asm) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3572 | D.Diag(diag::err_drv_invalid_gcc_output_type) |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 3573 | << getTypeName(JA.getType()); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3574 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3575 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 3576 | } |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3577 | } |
| 3578 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3579 | void gcc::Assemble::RenderExtraToolArgs(const JobAction &JA, |
| 3580 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3581 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 3582 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3583 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 3584 | void gcc::Link::RenderExtraToolArgs(const JobAction &JA, |
| 3585 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 3586 | // The types are (hopefully) good enough. |
| 3587 | } |
| 3588 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3589 | // Hexagon tools start. |
| 3590 | void hexagon::Assemble::RenderExtraToolArgs(const JobAction &JA, |
| 3591 | ArgStringList &CmdArgs) const { |
| 3592 | |
| 3593 | } |
| 3594 | void hexagon::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 3595 | const InputInfo &Output, |
| 3596 | const InputInfoList &Inputs, |
| 3597 | const ArgList &Args, |
| 3598 | const char *LinkingOutput) const { |
| 3599 | |
| 3600 | const Driver &D = getToolChain().getDriver(); |
| 3601 | ArgStringList CmdArgs; |
| 3602 | |
| 3603 | std::string MarchString = "-march="; |
Matthew Curtis | 6781415 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 3604 | MarchString += toolchains::Hexagon_TC::GetTargetCPU(Args); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3605 | CmdArgs.push_back(Args.MakeArgString(MarchString)); |
| 3606 | |
| 3607 | RenderExtraToolArgs(JA, CmdArgs); |
| 3608 | |
| 3609 | if (Output.isFilename()) { |
| 3610 | CmdArgs.push_back("-o"); |
| 3611 | CmdArgs.push_back(Output.getFilename()); |
| 3612 | } else { |
| 3613 | assert(Output.isNothing() && "Unexpected output"); |
| 3614 | CmdArgs.push_back("-fsyntax-only"); |
| 3615 | } |
| 3616 | |
Matthew Curtis | 33c95f1 | 2012-12-06 17:49:03 +0000 | [diff] [blame] | 3617 | std::string SmallDataThreshold = GetHexagonSmallDataThresholdValue(Args); |
| 3618 | if (!SmallDataThreshold.empty()) |
| 3619 | CmdArgs.push_back( |
| 3620 | Args.MakeArgString(std::string("-G") + SmallDataThreshold)); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3621 | |
Matthew Curtis | 3d8d422 | 2012-12-07 17:23:04 +0000 | [diff] [blame] | 3622 | Args.AddAllArgs(CmdArgs, options::OPT_g_Group); |
| 3623 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3624 | options::OPT_Xassembler); |
| 3625 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3626 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 3627 | // understands the suffix correctly. The main use case this would go |
| 3628 | // wrong in is for linker inputs if they happened to have an odd |
| 3629 | // suffix; really the only way to get this to happen is a command |
| 3630 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 3631 | // |
| 3632 | // FIXME: For the linker case specifically, can we safely convert |
| 3633 | // inputs into '-Wl,' options? |
| 3634 | for (InputInfoList::const_iterator |
| 3635 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3636 | const InputInfo &II = *it; |
| 3637 | |
| 3638 | // Don't try to pass LLVM or AST inputs to a generic gcc. |
| 3639 | if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR || |
| 3640 | II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC) |
| 3641 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
| 3642 | << getToolChain().getTripleString(); |
| 3643 | else if (II.getType() == types::TY_AST) |
| 3644 | D.Diag(clang::diag::err_drv_no_ast_support) |
| 3645 | << getToolChain().getTripleString(); |
| 3646 | |
| 3647 | if (II.isFilename()) |
| 3648 | CmdArgs.push_back(II.getFilename()); |
| 3649 | else |
| 3650 | // Don't render as input, we need gcc to do the translations. FIXME: Pranav: What is this ? |
| 3651 | II.getInputArg().render(Args, CmdArgs); |
| 3652 | } |
| 3653 | |
| 3654 | const char *GCCName = "hexagon-as"; |
| 3655 | const char *Exec = |
| 3656 | Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); |
| 3657 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 3658 | |
| 3659 | } |
| 3660 | void hexagon::Link::RenderExtraToolArgs(const JobAction &JA, |
| 3661 | ArgStringList &CmdArgs) const { |
| 3662 | // The types are (hopefully) good enough. |
| 3663 | } |
| 3664 | |
| 3665 | void hexagon::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 3666 | const InputInfo &Output, |
| 3667 | const InputInfoList &Inputs, |
| 3668 | const ArgList &Args, |
| 3669 | const char *LinkingOutput) const { |
| 3670 | |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3671 | const toolchains::Hexagon_TC& ToolChain = |
| 3672 | static_cast<const toolchains::Hexagon_TC&>(getToolChain()); |
| 3673 | const Driver &D = ToolChain.getDriver(); |
| 3674 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3675 | ArgStringList CmdArgs; |
| 3676 | |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3677 | //---------------------------------------------------------------------------- |
| 3678 | // |
| 3679 | //---------------------------------------------------------------------------- |
| 3680 | bool hasStaticArg = Args.hasArg(options::OPT_static); |
| 3681 | bool buildingLib = Args.hasArg(options::OPT_shared); |
Matthew Curtis | 33c95f1 | 2012-12-06 17:49:03 +0000 | [diff] [blame] | 3682 | bool buildPIE = Args.hasArg(options::OPT_pie); |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3683 | bool incStdLib = !Args.hasArg(options::OPT_nostdlib); |
| 3684 | bool incStartFiles = !Args.hasArg(options::OPT_nostartfiles); |
| 3685 | bool incDefLibs = !Args.hasArg(options::OPT_nodefaultlibs); |
| 3686 | bool useShared = buildingLib && !hasStaticArg; |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3687 | |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3688 | //---------------------------------------------------------------------------- |
| 3689 | // Silence warnings for various options |
| 3690 | //---------------------------------------------------------------------------- |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3691 | |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3692 | Args.ClaimAllArgs(options::OPT_g_Group); |
| 3693 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
| 3694 | Args.ClaimAllArgs(options::OPT_w); // Other warning options are already |
| 3695 | // handled somewhere else. |
| 3696 | Args.ClaimAllArgs(options::OPT_static_libgcc); |
| 3697 | |
| 3698 | //---------------------------------------------------------------------------- |
| 3699 | // |
| 3700 | //---------------------------------------------------------------------------- |
| 3701 | for (std::vector<std::string>::const_iterator i = ToolChain.ExtraOpts.begin(), |
| 3702 | e = ToolChain.ExtraOpts.end(); |
| 3703 | i != e; ++i) |
| 3704 | CmdArgs.push_back(i->c_str()); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3705 | |
Matthew Curtis | 6781415 | 2012-12-06 14:16:43 +0000 | [diff] [blame] | 3706 | std::string MarchString = toolchains::Hexagon_TC::GetTargetCPU(Args); |
| 3707 | CmdArgs.push_back(Args.MakeArgString("-m" + MarchString)); |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 3708 | |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3709 | if (buildingLib) { |
| 3710 | CmdArgs.push_back("-shared"); |
| 3711 | CmdArgs.push_back("-call_shared"); // should be the default, but doing as |
| 3712 | // hexagon-gcc does |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3713 | } |
| 3714 | |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3715 | if (hasStaticArg) |
| 3716 | CmdArgs.push_back("-static"); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3717 | |
Matthew Curtis | 33c95f1 | 2012-12-06 17:49:03 +0000 | [diff] [blame] | 3718 | if (buildPIE && !buildingLib) |
| 3719 | CmdArgs.push_back("-pie"); |
| 3720 | |
| 3721 | std::string SmallDataThreshold = GetHexagonSmallDataThresholdValue(Args); |
| 3722 | if (!SmallDataThreshold.empty()) { |
| 3723 | CmdArgs.push_back( |
| 3724 | Args.MakeArgString(std::string("-G") + SmallDataThreshold)); |
| 3725 | } |
| 3726 | |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3727 | //---------------------------------------------------------------------------- |
| 3728 | // |
| 3729 | //---------------------------------------------------------------------------- |
| 3730 | CmdArgs.push_back("-o"); |
| 3731 | CmdArgs.push_back(Output.getFilename()); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3732 | |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3733 | const std::string MarchSuffix = "/" + MarchString; |
| 3734 | const std::string G0Suffix = "/G0"; |
| 3735 | const std::string MarchG0Suffix = MarchSuffix + G0Suffix; |
| 3736 | const std::string RootDir = toolchains::Hexagon_TC::GetGnuDir(D.InstalledDir) |
| 3737 | + "/"; |
| 3738 | const std::string StartFilesDir = RootDir |
| 3739 | + "hexagon/lib" |
| 3740 | + (buildingLib |
| 3741 | ? MarchG0Suffix : MarchSuffix); |
| 3742 | |
| 3743 | //---------------------------------------------------------------------------- |
| 3744 | // moslib |
| 3745 | //---------------------------------------------------------------------------- |
| 3746 | std::vector<std::string> oslibs; |
| 3747 | bool hasStandalone= false; |
| 3748 | |
| 3749 | for (arg_iterator it = Args.filtered_begin(options::OPT_moslib_EQ), |
| 3750 | ie = Args.filtered_end(); it != ie; ++it) { |
| 3751 | (*it)->claim(); |
| 3752 | oslibs.push_back((*it)->getValue()); |
| 3753 | hasStandalone = hasStandalone || (oslibs.back() == "standalone"); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3754 | } |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3755 | if (oslibs.empty()) { |
| 3756 | oslibs.push_back("standalone"); |
| 3757 | hasStandalone = true; |
| 3758 | } |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3759 | |
Matthew Curtis | 5fdf350 | 2012-12-06 15:46:07 +0000 | [diff] [blame] | 3760 | //---------------------------------------------------------------------------- |
| 3761 | // Start Files |
| 3762 | //---------------------------------------------------------------------------- |
| 3763 | if (incStdLib && incStartFiles) { |
| 3764 | |
| 3765 | if (!buildingLib) { |
| 3766 | if (hasStandalone) { |
| 3767 | CmdArgs.push_back( |
| 3768 | Args.MakeArgString(StartFilesDir + "/crt0_standalone.o")); |
| 3769 | } |
| 3770 | CmdArgs.push_back(Args.MakeArgString(StartFilesDir + "/crt0.o")); |
| 3771 | } |
| 3772 | std::string initObj = useShared ? "/initS.o" : "/init.o"; |
| 3773 | CmdArgs.push_back(Args.MakeArgString(StartFilesDir + initObj)); |
| 3774 | } |
| 3775 | |
| 3776 | //---------------------------------------------------------------------------- |
| 3777 | // Library Search Paths |
| 3778 | //---------------------------------------------------------------------------- |
| 3779 | const ToolChain::path_list &LibPaths = ToolChain.getFilePaths(); |
| 3780 | for (ToolChain::path_list::const_iterator |
| 3781 | i = LibPaths.begin(), |
| 3782 | e = LibPaths.end(); |
| 3783 | i != e; |
| 3784 | ++i) |
| 3785 | CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i)); |
| 3786 | |
| 3787 | //---------------------------------------------------------------------------- |
| 3788 | // |
| 3789 | //---------------------------------------------------------------------------- |
| 3790 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 3791 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 3792 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 3793 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 3794 | Args.AddAllArgs(CmdArgs, options::OPT_u_Group); |
| 3795 | |
| 3796 | AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); |
| 3797 | |
| 3798 | //---------------------------------------------------------------------------- |
| 3799 | // Libraries |
| 3800 | //---------------------------------------------------------------------------- |
| 3801 | if (incStdLib && incDefLibs) { |
| 3802 | if (D.CCCIsCXX) { |
| 3803 | ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
| 3804 | CmdArgs.push_back("-lm"); |
| 3805 | } |
| 3806 | |
| 3807 | CmdArgs.push_back("--start-group"); |
| 3808 | |
| 3809 | if (!buildingLib) { |
| 3810 | for(std::vector<std::string>::iterator i = oslibs.begin(), |
| 3811 | e = oslibs.end(); i != e; ++i) |
| 3812 | CmdArgs.push_back(Args.MakeArgString("-l" + *i)); |
| 3813 | CmdArgs.push_back("-lc"); |
| 3814 | } |
| 3815 | CmdArgs.push_back("-lgcc"); |
| 3816 | |
| 3817 | CmdArgs.push_back("--end-group"); |
| 3818 | } |
| 3819 | |
| 3820 | //---------------------------------------------------------------------------- |
| 3821 | // End files |
| 3822 | //---------------------------------------------------------------------------- |
| 3823 | if (incStdLib && incStartFiles) { |
| 3824 | std::string finiObj = useShared ? "/finiS.o" : "/fini.o"; |
| 3825 | CmdArgs.push_back(Args.MakeArgString(StartFilesDir + finiObj)); |
| 3826 | } |
| 3827 | |
| 3828 | std::string Linker = ToolChain.GetProgramPath("hexagon-ld"); |
| 3829 | C.addCommand( |
| 3830 | new Command( |
| 3831 | JA, *this, |
| 3832 | Args.MakeArgString(Linker), CmdArgs)); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3833 | } |
| 3834 | // Hexagon tools end. |
| 3835 | |
Rafael Espindola | cfed828 | 2012-10-31 18:51:07 +0000 | [diff] [blame] | 3836 | llvm::Triple::ArchType darwin::getArchTypeForDarwinArchName(StringRef Str) { |
| 3837 | // See arch(3) and llvm-gcc's driver-driver.c. We don't implement support for |
| 3838 | // archs which Darwin doesn't use. |
| 3839 | |
| 3840 | // The matching this routine does is fairly pointless, since it is neither the |
| 3841 | // complete architecture list, nor a reasonable subset. The problem is that |
| 3842 | // historically the driver driver accepts this and also ties its -march= |
| 3843 | // handling to the architecture name, so we need to be careful before removing |
| 3844 | // support for it. |
| 3845 | |
| 3846 | // This code must be kept in sync with Clang's Darwin specific argument |
| 3847 | // translation. |
| 3848 | |
| 3849 | return llvm::StringSwitch<llvm::Triple::ArchType>(Str) |
| 3850 | .Cases("ppc", "ppc601", "ppc603", "ppc604", "ppc604e", llvm::Triple::ppc) |
| 3851 | .Cases("ppc750", "ppc7400", "ppc7450", "ppc970", llvm::Triple::ppc) |
| 3852 | .Case("ppc64", llvm::Triple::ppc64) |
| 3853 | .Cases("i386", "i486", "i486SX", "i586", "i686", llvm::Triple::x86) |
| 3854 | .Cases("pentium", "pentpro", "pentIIm3", "pentIIm5", "pentium4", |
| 3855 | llvm::Triple::x86) |
| 3856 | .Case("x86_64", llvm::Triple::x86_64) |
| 3857 | // This is derived from the driver driver. |
| 3858 | .Cases("arm", "armv4t", "armv5", "armv6", llvm::Triple::arm) |
| 3859 | .Cases("armv7", "armv7f", "armv7k", "armv7s", "xscale", llvm::Triple::arm) |
| 3860 | .Case("r600", llvm::Triple::r600) |
| 3861 | .Case("nvptx", llvm::Triple::nvptx) |
| 3862 | .Case("nvptx64", llvm::Triple::nvptx64) |
| 3863 | .Case("amdil", llvm::Triple::amdil) |
| 3864 | .Case("spir", llvm::Triple::spir) |
| 3865 | .Default(llvm::Triple::UnknownArch); |
| 3866 | } |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3867 | |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 3868 | const char *Clang::getBaseInputName(const ArgList &Args, |
| 3869 | const InputInfoList &Inputs) { |
Michael J. Spencer | 472ccff | 2010-12-18 00:19:12 +0000 | [diff] [blame] | 3870 | return Args.MakeArgString( |
| 3871 | llvm::sys::path::filename(Inputs[0].getBaseInput())); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 3874 | const char *Clang::getBaseInputStem(const ArgList &Args, |
| 3875 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3876 | const char *Str = getBaseInputName(Args, Inputs); |
| 3877 | |
Chris Lattner | 657ca66 | 2011-01-16 08:14:11 +0000 | [diff] [blame] | 3878 | if (const char *End = strrchr(Str, '.')) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 3879 | return Args.MakeArgString(std::string(Str, End)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3880 | |
| 3881 | return Str; |
| 3882 | } |
| 3883 | |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 3884 | const char *Clang::getDependencyFileName(const ArgList &Args, |
| 3885 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3886 | // FIXME: Think about this more. |
| 3887 | std::string Res; |
| 3888 | |
| 3889 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3890 | std::string Str(OutputOpt->getValue()); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3891 | Res = Str.substr(0, Str.rfind('.')); |
Chad Rosier | 3060178 | 2011-08-17 23:08:45 +0000 | [diff] [blame] | 3892 | } else { |
Bob Wilson | 66b8a66 | 2012-11-23 06:14:39 +0000 | [diff] [blame] | 3893 | Res = getBaseInputStem(Args, Inputs); |
Chad Rosier | 3060178 | 2011-08-17 23:08:45 +0000 | [diff] [blame] | 3894 | } |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 3895 | return Args.MakeArgString(Res + ".d"); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 3896 | } |
| 3897 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3898 | void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3899 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3900 | const InputInfoList &Inputs, |
| 3901 | const ArgList &Args, |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3902 | const char *LinkingOutput) const { |
| 3903 | ArgStringList CmdArgs; |
| 3904 | |
| 3905 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 3906 | const InputInfo &Input = Inputs[0]; |
| 3907 | |
Daniel Dunbar | 34bac1f | 2011-04-12 23:59:20 +0000 | [diff] [blame] | 3908 | // Determine the original source input. |
| 3909 | const Action *SourceAction = &JA; |
| 3910 | while (SourceAction->getKind() != Action::InputClass) { |
| 3911 | assert(!SourceAction->getInputs().empty() && "unexpected root action!"); |
| 3912 | SourceAction = SourceAction->getInputs()[0]; |
| 3913 | } |
| 3914 | |
| 3915 | // Forward -g, assuming we are dealing with an actual assembly file. |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 3916 | if (SourceAction->getType() == types::TY_Asm || |
Daniel Dunbar | 34bac1f | 2011-04-12 23:59:20 +0000 | [diff] [blame] | 3917 | SourceAction->getType() == types::TY_PP_Asm) { |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 3918 | if (Args.hasArg(options::OPT_gstabs)) |
| 3919 | CmdArgs.push_back("--gstabs"); |
| 3920 | else if (Args.hasArg(options::OPT_g_Group)) |
Bob Wilson | 591ff15 | 2011-11-02 05:10:45 +0000 | [diff] [blame] | 3921 | CmdArgs.push_back("-g"); |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 3922 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3923 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3924 | // Derived from asm spec. |
Daniel Dunbar | cc6f803 | 2009-09-09 18:36:27 +0000 | [diff] [blame] | 3925 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3926 | |
Daniel Dunbar | f5438e3 | 2010-07-22 01:47:22 +0000 | [diff] [blame] | 3927 | // Use -force_cpusubtype_ALL on x86 by default. |
| 3928 | if (getToolChain().getTriple().getArch() == llvm::Triple::x86 || |
| 3929 | getToolChain().getTriple().getArch() == llvm::Triple::x86_64 || |
Daniel Dunbar | cc6f803 | 2009-09-09 18:36:27 +0000 | [diff] [blame] | 3930 | Args.hasArg(options::OPT_force__cpusubtype__ALL)) |
| 3931 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 3932 | |
Daniel Dunbar | 0e2679d | 2009-08-24 22:26:16 +0000 | [diff] [blame] | 3933 | if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64 && |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 3934 | (((Args.hasArg(options::OPT_mkernel) || |
| 3935 | Args.hasArg(options::OPT_fapple_kext)) && |
| 3936 | (!getDarwinToolChain().isTargetIPhoneOS() || |
| 3937 | getDarwinToolChain().isIPhoneOSVersionLT(6, 0))) || |
| 3938 | Args.hasArg(options::OPT_static))) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3939 | CmdArgs.push_back("-static"); |
| 3940 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3941 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3942 | options::OPT_Xassembler); |
| 3943 | |
| 3944 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 3945 | CmdArgs.push_back("-o"); |
| 3946 | CmdArgs.push_back(Output.getFilename()); |
| 3947 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3948 | assert(Input.isFilename() && "Invalid input."); |
| 3949 | CmdArgs.push_back(Input.getFilename()); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3950 | |
| 3951 | // asm_final spec is empty. |
| 3952 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3953 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3954 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3955 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 3956 | } |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 3957 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 3958 | void darwin::DarwinTool::anchor() {} |
| 3959 | |
Daniel Dunbar | fbefe6b | 2009-09-09 18:36:20 +0000 | [diff] [blame] | 3960 | void darwin::DarwinTool::AddDarwinArch(const ArgList &Args, |
| 3961 | ArgStringList &CmdArgs) const { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3962 | StringRef ArchName = getDarwinToolChain().getDarwinArchName(Args); |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 3963 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3964 | // Derived from darwin_arch spec. |
| 3965 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 3966 | CmdArgs.push_back(Args.MakeArgString(ArchName)); |
Daniel Dunbar | 78dbd58 | 2009-09-04 18:35:31 +0000 | [diff] [blame] | 3967 | |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 3968 | // FIXME: Is this needed anymore? |
| 3969 | if (ArchName == "arm") |
Daniel Dunbar | 78dbd58 | 2009-09-04 18:35:31 +0000 | [diff] [blame] | 3970 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3971 | } |
| 3972 | |
Bill Wendling | 6acf8b4 | 2012-10-02 18:02:50 +0000 | [diff] [blame] | 3973 | bool darwin::Link::NeedsTempPath(const InputInfoList &Inputs) const { |
| 3974 | // We only need to generate a temp path for LTO if we aren't compiling object |
| 3975 | // files. When compiling source files, we run 'dsymutil' after linking. We |
| 3976 | // don't run 'dsymutil' when compiling object files. |
| 3977 | for (InputInfoList::const_iterator |
| 3978 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) |
| 3979 | if (it->getType() != types::TY_Object) |
| 3980 | return true; |
| 3981 | |
| 3982 | return false; |
| 3983 | } |
| 3984 | |
Daniel Dunbar | 748de8e | 2010-09-09 21:51:05 +0000 | [diff] [blame] | 3985 | void darwin::Link::AddLinkArgs(Compilation &C, |
| 3986 | const ArgList &Args, |
Bill Wendling | 6acf8b4 | 2012-10-02 18:02:50 +0000 | [diff] [blame] | 3987 | ArgStringList &CmdArgs, |
| 3988 | const InputInfoList &Inputs) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3989 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | ce911f5 | 2011-04-28 21:23:41 +0000 | [diff] [blame] | 3990 | const toolchains::Darwin &DarwinTC = getDarwinToolChain(); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 3991 | |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 3992 | unsigned Version[3] = { 0, 0, 0 }; |
| 3993 | if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { |
| 3994 | bool HadExtra; |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 3995 | if (!Driver::GetReleaseVersion(A->getValue(), Version[0], |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 3996 | Version[1], Version[2], HadExtra) || |
| 3997 | HadExtra) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3998 | D.Diag(diag::err_drv_invalid_version_number) |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 3999 | << A->getAsString(Args); |
| 4000 | } |
| 4001 | |
| 4002 | // Newer linkers support -demangle, pass it if supported and not disabled by |
| 4003 | // the user. |
Daniel Dunbar | d2d2088 | 2012-01-04 21:45:27 +0000 | [diff] [blame] | 4004 | if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) { |
Daniel Dunbar | bcf1da8 | 2010-09-07 17:07:49 +0000 | [diff] [blame] | 4005 | // Don't pass -demangle to ld_classic. |
| 4006 | // |
| 4007 | // FIXME: This is a temporary workaround, ld should be handling this. |
| 4008 | bool UsesLdClassic = (getToolChain().getArch() == llvm::Triple::x86 && |
| 4009 | Args.hasArg(options::OPT_static)); |
Daniel Dunbar | 9ced704 | 2010-09-07 17:50:41 +0000 | [diff] [blame] | 4010 | if (getToolChain().getArch() == llvm::Triple::x86) { |
| 4011 | for (arg_iterator it = Args.filtered_begin(options::OPT_Xlinker, |
| 4012 | options::OPT_Wl_COMMA), |
| 4013 | ie = Args.filtered_end(); it != ie; ++it) { |
| 4014 | const Arg *A = *it; |
| 4015 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 4016 | if (StringRef(A->getValue(i)) == "-kext") |
Daniel Dunbar | 9ced704 | 2010-09-07 17:50:41 +0000 | [diff] [blame] | 4017 | UsesLdClassic = true; |
| 4018 | } |
| 4019 | } |
Daniel Dunbar | bcf1da8 | 2010-09-07 17:07:49 +0000 | [diff] [blame] | 4020 | if (!UsesLdClassic) |
| 4021 | CmdArgs.push_back("-demangle"); |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 4022 | } |
| 4023 | |
Bill Wendling | c35f908 | 2012-11-16 23:03:00 +0000 | [diff] [blame] | 4024 | // If we are using LTO, then automatically create a temporary file path for |
| 4025 | // the linker to use, so that it's lifetime will extend past a possible |
| 4026 | // dsymutil step. |
| 4027 | if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) { |
| 4028 | const char *TmpPath = C.getArgs().MakeArgString( |
| 4029 | D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object))); |
| 4030 | C.addTempFile(TmpPath); |
| 4031 | CmdArgs.push_back("-object_path_lto"); |
| 4032 | CmdArgs.push_back(TmpPath); |
Daniel Dunbar | 5bfa656 | 2011-06-21 20:55:11 +0000 | [diff] [blame] | 4033 | } |
| 4034 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4035 | // Derived from the "link" spec. |
| 4036 | Args.AddAllArgs(CmdArgs, options::OPT_static); |
| 4037 | if (!Args.hasArg(options::OPT_static)) |
| 4038 | CmdArgs.push_back("-dynamic"); |
| 4039 | if (Args.hasArg(options::OPT_fgnu_runtime)) { |
| 4040 | // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu |
| 4041 | // here. How do we wish to handle such things? |
| 4042 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4043 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4044 | if (!Args.hasArg(options::OPT_dynamiclib)) { |
Daniel Dunbar | a6d3849 | 2010-01-22 02:04:52 +0000 | [diff] [blame] | 4045 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | a6d3849 | 2010-01-22 02:04:52 +0000 | [diff] [blame] | 4046 | // FIXME: Why do this only on this path? |
Daniel Dunbar | 8917dd4 | 2010-01-22 03:37:33 +0000 | [diff] [blame] | 4047 | Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4048 | |
| 4049 | Args.AddLastArg(CmdArgs, options::OPT_bundle); |
| 4050 | Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader); |
| 4051 | Args.AddAllArgs(CmdArgs, options::OPT_client__name); |
| 4052 | |
| 4053 | Arg *A; |
| 4054 | if ((A = Args.getLastArg(options::OPT_compatibility__version)) || |
| 4055 | (A = Args.getLastArg(options::OPT_current__version)) || |
| 4056 | (A = Args.getLastArg(options::OPT_install__name))) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4057 | D.Diag(diag::err_drv_argument_only_allowed_with) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4058 | << A->getAsString(Args) << "-dynamiclib"; |
| 4059 | |
| 4060 | Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace); |
| 4061 | Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs); |
| 4062 | Args.AddLastArg(CmdArgs, options::OPT_private__bundle); |
| 4063 | } else { |
| 4064 | CmdArgs.push_back("-dylib"); |
| 4065 | |
| 4066 | Arg *A; |
| 4067 | if ((A = Args.getLastArg(options::OPT_bundle)) || |
| 4068 | (A = Args.getLastArg(options::OPT_bundle__loader)) || |
| 4069 | (A = Args.getLastArg(options::OPT_client__name)) || |
| 4070 | (A = Args.getLastArg(options::OPT_force__flat__namespace)) || |
| 4071 | (A = Args.getLastArg(options::OPT_keep__private__externs)) || |
| 4072 | (A = Args.getLastArg(options::OPT_private__bundle))) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4073 | D.Diag(diag::err_drv_argument_not_allowed_with) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4074 | << A->getAsString(Args) << "-dynamiclib"; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4075 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4076 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version, |
| 4077 | "-dylib_compatibility_version"); |
| 4078 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version, |
| 4079 | "-dylib_current_version"); |
| 4080 | |
Daniel Dunbar | a6d3849 | 2010-01-22 02:04:52 +0000 | [diff] [blame] | 4081 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4082 | |
| 4083 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name, |
| 4084 | "-dylib_install_name"); |
| 4085 | } |
| 4086 | |
| 4087 | Args.AddLastArg(CmdArgs, options::OPT_all__load); |
| 4088 | Args.AddAllArgs(CmdArgs, options::OPT_allowable__client); |
| 4089 | Args.AddLastArg(CmdArgs, options::OPT_bind__at__load); |
Daniel Dunbar | ce911f5 | 2011-04-28 21:23:41 +0000 | [diff] [blame] | 4090 | if (DarwinTC.isTargetIPhoneOS()) |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 4091 | Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4092 | Args.AddLastArg(CmdArgs, options::OPT_dead__strip); |
| 4093 | Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms); |
| 4094 | Args.AddAllArgs(CmdArgs, options::OPT_dylib__file); |
| 4095 | Args.AddLastArg(CmdArgs, options::OPT_dynamic); |
| 4096 | Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list); |
| 4097 | Args.AddLastArg(CmdArgs, options::OPT_flat__namespace); |
Daniel Dunbar | 99ca47b | 2011-06-28 20:16:02 +0000 | [diff] [blame] | 4098 | Args.AddAllArgs(CmdArgs, options::OPT_force__load); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4099 | Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names); |
| 4100 | Args.AddAllArgs(CmdArgs, options::OPT_image__base); |
| 4101 | Args.AddAllArgs(CmdArgs, options::OPT_init); |
| 4102 | |
Daniel Dunbar | ce911f5 | 2011-04-28 21:23:41 +0000 | [diff] [blame] | 4103 | // Add the deployment target. |
Benjamin Kramer | 09c9a56 | 2012-03-10 20:55:36 +0000 | [diff] [blame] | 4104 | VersionTuple TargetVersion = DarwinTC.getTargetVersion(); |
Daniel Dunbar | b7f5ef7 | 2011-04-30 04:22:58 +0000 | [diff] [blame] | 4105 | |
| 4106 | // If we had an explicit -mios-simulator-version-min argument, honor that, |
| 4107 | // otherwise use the traditional deployment targets. We can't just check the |
| 4108 | // is-sim attribute because existing code follows this path, and the linker |
| 4109 | // may not handle the argument. |
| 4110 | // |
| 4111 | // FIXME: We may be able to remove this, once we can verify no one depends on |
| 4112 | // it. |
| 4113 | if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ)) |
| 4114 | CmdArgs.push_back("-ios_simulator_version_min"); |
| 4115 | else if (DarwinTC.isTargetIPhoneOS()) |
| 4116 | CmdArgs.push_back("-iphoneos_version_min"); |
| 4117 | else |
| 4118 | CmdArgs.push_back("-macosx_version_min"); |
Benjamin Kramer | 09c9a56 | 2012-03-10 20:55:36 +0000 | [diff] [blame] | 4119 | CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString())); |
Daniel Dunbar | ce911f5 | 2011-04-28 21:23:41 +0000 | [diff] [blame] | 4120 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4121 | Args.AddLastArg(CmdArgs, options::OPT_nomultidefs); |
| 4122 | Args.AddLastArg(CmdArgs, options::OPT_multi__module); |
| 4123 | Args.AddLastArg(CmdArgs, options::OPT_single__module); |
| 4124 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined); |
| 4125 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4126 | |
Daniel Dunbar | 47e879d | 2010-07-13 23:31:40 +0000 | [diff] [blame] | 4127 | if (const Arg *A = Args.getLastArg(options::OPT_fpie, options::OPT_fPIE, |
| 4128 | options::OPT_fno_pie, |
| 4129 | options::OPT_fno_PIE)) { |
| 4130 | if (A->getOption().matches(options::OPT_fpie) || |
| 4131 | A->getOption().matches(options::OPT_fPIE)) |
| 4132 | CmdArgs.push_back("-pie"); |
| 4133 | else |
| 4134 | CmdArgs.push_back("-no_pie"); |
| 4135 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4136 | |
| 4137 | Args.AddLastArg(CmdArgs, options::OPT_prebind); |
| 4138 | Args.AddLastArg(CmdArgs, options::OPT_noprebind); |
| 4139 | Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding); |
| 4140 | Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules); |
| 4141 | Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs); |
| 4142 | Args.AddAllArgs(CmdArgs, options::OPT_sectcreate); |
| 4143 | Args.AddAllArgs(CmdArgs, options::OPT_sectorder); |
| 4144 | Args.AddAllArgs(CmdArgs, options::OPT_seg1addr); |
| 4145 | Args.AddAllArgs(CmdArgs, options::OPT_segprot); |
| 4146 | Args.AddAllArgs(CmdArgs, options::OPT_segaddr); |
| 4147 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr); |
| 4148 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr); |
| 4149 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table); |
| 4150 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename); |
| 4151 | Args.AddAllArgs(CmdArgs, options::OPT_sub__library); |
| 4152 | Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 4153 | |
Daniel Dunbar | cc95719 | 2011-05-02 21:03:47 +0000 | [diff] [blame] | 4154 | // Give --sysroot= preference, over the Apple specific behavior to also use |
| 4155 | // --isysroot as the syslibroot. |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 4156 | StringRef sysroot = C.getSysRoot(); |
| 4157 | if (sysroot != "") { |
Daniel Dunbar | cc95719 | 2011-05-02 21:03:47 +0000 | [diff] [blame] | 4158 | CmdArgs.push_back("-syslibroot"); |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 4159 | CmdArgs.push_back(C.getArgs().MakeArgString(sysroot)); |
Daniel Dunbar | cc95719 | 2011-05-02 21:03:47 +0000 | [diff] [blame] | 4160 | } else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { |
| 4161 | CmdArgs.push_back("-syslibroot"); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 4162 | CmdArgs.push_back(A->getValue()); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4165 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace); |
| 4166 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints); |
| 4167 | Args.AddAllArgs(CmdArgs, options::OPT_umbrella); |
| 4168 | Args.AddAllArgs(CmdArgs, options::OPT_undefined); |
| 4169 | Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 4170 | Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4171 | Args.AddLastArg(CmdArgs, options::OPT_X_Flag); |
| 4172 | Args.AddAllArgs(CmdArgs, options::OPT_y); |
| 4173 | Args.AddLastArg(CmdArgs, options::OPT_w); |
| 4174 | Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size); |
| 4175 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__); |
| 4176 | Args.AddLastArg(CmdArgs, options::OPT_seglinkedit); |
| 4177 | Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit); |
| 4178 | Args.AddAllArgs(CmdArgs, options::OPT_sectalign); |
| 4179 | Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols); |
| 4180 | Args.AddAllArgs(CmdArgs, options::OPT_segcreate); |
| 4181 | Args.AddLastArg(CmdArgs, options::OPT_whyload); |
| 4182 | Args.AddLastArg(CmdArgs, options::OPT_whatsloaded); |
| 4183 | Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name); |
| 4184 | Args.AddLastArg(CmdArgs, options::OPT_dylinker); |
| 4185 | Args.AddLastArg(CmdArgs, options::OPT_Mach); |
| 4186 | } |
| 4187 | |
| 4188 | void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4189 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4190 | const InputInfoList &Inputs, |
| 4191 | const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4192 | const char *LinkingOutput) const { |
| 4193 | assert(Output.getType() == types::TY_Image && "Invalid linker output type."); |
Daniel Dunbar | e0be8b1 | 2009-09-08 16:39:16 +0000 | [diff] [blame] | 4194 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4195 | // The logic here is derived from gcc's behavior; most of which |
| 4196 | // comes from specs (starting with link_command). Consult gcc for |
| 4197 | // more information. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4198 | ArgStringList CmdArgs; |
| 4199 | |
Argyrios Kyrtzidis | 2289717 | 2011-10-07 22:58:08 +0000 | [diff] [blame] | 4200 | /// Hack(tm) to ignore linking errors when we are doing ARC migration. |
| 4201 | if (Args.hasArg(options::OPT_ccc_arcmt_check, |
| 4202 | options::OPT_ccc_arcmt_migrate)) { |
| 4203 | for (ArgList::const_iterator I = Args.begin(), E = Args.end(); I != E; ++I) |
| 4204 | (*I)->claim(); |
| 4205 | const char *Exec = |
| 4206 | Args.MakeArgString(getToolChain().GetProgramPath("touch")); |
| 4207 | CmdArgs.push_back(Output.getFilename()); |
| 4208 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4209 | return; |
| 4210 | } |
| 4211 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4212 | // I'm not sure why this particular decomposition exists in gcc, but |
| 4213 | // we follow suite for ease of comparison. |
Bill Wendling | 6acf8b4 | 2012-10-02 18:02:50 +0000 | [diff] [blame] | 4214 | AddLinkArgs(C, Args, CmdArgs, Inputs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4215 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4216 | Args.AddAllArgs(CmdArgs, options::OPT_d_Flag); |
| 4217 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 4218 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 4219 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 4220 | Args.AddAllArgs(CmdArgs, options::OPT_u_Group); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4221 | Args.AddLastArg(CmdArgs, options::OPT_e); |
| 4222 | Args.AddAllArgs(CmdArgs, options::OPT_m_Separate); |
| 4223 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
| 4224 | |
Daniel Dunbar | 270073c | 2010-10-18 22:08:36 +0000 | [diff] [blame] | 4225 | // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading |
| 4226 | // members of static archive libraries which implement Objective-C classes or |
| 4227 | // categories. |
| 4228 | if (Args.hasArg(options::OPT_ObjC) || Args.hasArg(options::OPT_ObjCXX)) |
| 4229 | CmdArgs.push_back("-ObjC"); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4230 | |
Bill Wendling | d56f403 | 2012-12-10 21:48:41 +0000 | [diff] [blame] | 4231 | if (Args.hasArg(options::OPT_rdynamic)) |
| 4232 | CmdArgs.push_back("-export_dynamic"); |
| 4233 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4234 | CmdArgs.push_back("-o"); |
| 4235 | CmdArgs.push_back(Output.getFilename()); |
| 4236 | |
Chad Rosier | 1893731 | 2012-05-16 23:45:12 +0000 | [diff] [blame] | 4237 | if (!Args.hasArg(options::OPT_nostdlib) && |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4238 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4239 | // Derived from startfile spec. |
| 4240 | if (Args.hasArg(options::OPT_dynamiclib)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4241 | // Derived from darwin_dylib1 spec. |
Daniel Dunbar | 1051fc0 | 2011-04-01 21:02:42 +0000 | [diff] [blame] | 4242 | if (getDarwinToolChain().isTargetIOSSimulator()) { |
| 4243 | // The simulator doesn't have a versioned crt1 file. |
| 4244 | CmdArgs.push_back("-ldylib1.o"); |
| 4245 | } else if (getDarwinToolChain().isTargetIPhoneOS()) { |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4246 | if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1)) |
| 4247 | CmdArgs.push_back("-ldylib1.o"); |
| 4248 | } else { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4249 | if (getDarwinToolChain().isMacosxVersionLT(10, 5)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4250 | CmdArgs.push_back("-ldylib1.o"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4251 | else if (getDarwinToolChain().isMacosxVersionLT(10, 6)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4252 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 4253 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4254 | } else { |
| 4255 | if (Args.hasArg(options::OPT_bundle)) { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 4256 | if (!Args.hasArg(options::OPT_static)) { |
| 4257 | // Derived from darwin_bundle1 spec. |
Daniel Dunbar | 1051fc0 | 2011-04-01 21:02:42 +0000 | [diff] [blame] | 4258 | if (getDarwinToolChain().isTargetIOSSimulator()) { |
| 4259 | // The simulator doesn't have a versioned crt1 file. |
| 4260 | CmdArgs.push_back("-lbundle1.o"); |
| 4261 | } else if (getDarwinToolChain().isTargetIPhoneOS()) { |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4262 | if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1)) |
| 4263 | CmdArgs.push_back("-lbundle1.o"); |
| 4264 | } else { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4265 | if (getDarwinToolChain().isMacosxVersionLT(10, 6)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4266 | CmdArgs.push_back("-lbundle1.o"); |
| 4267 | } |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 4268 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4269 | } else { |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 4270 | if (Args.hasArg(options::OPT_pg) && |
| 4271 | getToolChain().SupportsProfiling()) { |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4272 | if (Args.hasArg(options::OPT_static) || |
| 4273 | Args.hasArg(options::OPT_object) || |
| 4274 | Args.hasArg(options::OPT_preload)) { |
| 4275 | CmdArgs.push_back("-lgcrt0.o"); |
| 4276 | } else { |
| 4277 | CmdArgs.push_back("-lgcrt1.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4278 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4279 | // darwin_crt2 spec is empty. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4280 | } |
Bob Wilson | 4e6e791 | 2012-07-04 00:18:41 +0000 | [diff] [blame] | 4281 | // By default on OS X 10.8 and later, we don't link with a crt1.o |
| 4282 | // file and the linker knows to use _main as the entry point. But, |
| 4283 | // when compiling with -pg, we need to link with the gcrt1.o file, |
| 4284 | // so pass the -no_new_main option to tell the linker to use the |
| 4285 | // "start" symbol as the entry point. |
Bob Wilson | 1fc6e4f | 2012-07-03 20:42:10 +0000 | [diff] [blame] | 4286 | if (getDarwinToolChain().isTargetMacOS() && |
| 4287 | !getDarwinToolChain().isMacosxVersionLT(10, 8)) |
| 4288 | CmdArgs.push_back("-no_new_main"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4289 | } else { |
| 4290 | if (Args.hasArg(options::OPT_static) || |
| 4291 | Args.hasArg(options::OPT_object) || |
| 4292 | Args.hasArg(options::OPT_preload)) { |
| 4293 | CmdArgs.push_back("-lcrt0.o"); |
| 4294 | } else { |
| 4295 | // Derived from darwin_crt1 spec. |
Daniel Dunbar | 4035580 | 2011-03-31 17:12:33 +0000 | [diff] [blame] | 4296 | if (getDarwinToolChain().isTargetIOSSimulator()) { |
| 4297 | // The simulator doesn't have a versioned crt1 file. |
| 4298 | CmdArgs.push_back("-lcrt1.o"); |
| 4299 | } else if (getDarwinToolChain().isTargetIPhoneOS()) { |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4300 | if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1)) |
| 4301 | CmdArgs.push_back("-lcrt1.o"); |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 4302 | else if (getDarwinToolChain().isIPhoneOSVersionLT(6, 0)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 4303 | CmdArgs.push_back("-lcrt1.3.1.o"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4304 | } else { |
| 4305 | if (getDarwinToolChain().isMacosxVersionLT(10, 5)) |
| 4306 | CmdArgs.push_back("-lcrt1.o"); |
| 4307 | else if (getDarwinToolChain().isMacosxVersionLT(10, 6)) |
| 4308 | CmdArgs.push_back("-lcrt1.10.5.o"); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4309 | else if (getDarwinToolChain().isMacosxVersionLT(10, 8)) |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4310 | CmdArgs.push_back("-lcrt1.10.6.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4311 | |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4312 | // darwin_crt2 spec is empty. |
| 4313 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4314 | } |
| 4315 | } |
| 4316 | } |
| 4317 | } |
| 4318 | |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 4319 | if (!getDarwinToolChain().isTargetIPhoneOS() && |
| 4320 | Args.hasArg(options::OPT_shared_libgcc) && |
| 4321 | getDarwinToolChain().isMacosxVersionLT(10, 5)) { |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 4322 | const char *Str = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4323 | Args.MakeArgString(getToolChain().GetFilePath("crt3.o")); |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 4324 | CmdArgs.push_back(Str); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4325 | } |
| 4326 | } |
| 4327 | |
| 4328 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4329 | |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 4330 | SanitizerArgs Sanitize(getToolChain().getDriver(), Args); |
Alexey Samsonov | 2cb3d30 | 2013-01-21 08:45:02 +0000 | [diff] [blame] | 4331 | // If we're building a dynamic lib with -fsanitize=address, |
| 4332 | // unresolved symbols may appear. Mark all |
Alexey Samsonov | 75fcb19 | 2012-11-16 12:53:14 +0000 | [diff] [blame] | 4333 | // of them as dynamic_lookup. Linking executables is handled in |
| 4334 | // lib/Driver/ToolChains.cpp. |
Alexey Samsonov | 2cb3d30 | 2013-01-21 08:45:02 +0000 | [diff] [blame] | 4335 | if (Sanitize.needsAsanRt()) { |
Kostya Serebryany | 7b5f101 | 2011-12-06 19:18:44 +0000 | [diff] [blame] | 4336 | if (Args.hasArg(options::OPT_dynamiclib) || |
| 4337 | Args.hasArg(options::OPT_bundle)) { |
| 4338 | CmdArgs.push_back("-undefined"); |
| 4339 | CmdArgs.push_back("dynamic_lookup"); |
| 4340 | } |
| 4341 | } |
| 4342 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4343 | if (Args.hasArg(options::OPT_fopenmp)) |
| 4344 | // This is more complicated in gcc... |
| 4345 | CmdArgs.push_back("-lgomp"); |
| 4346 | |
Douglas Gregor | 04e326b | 2012-05-15 21:00:27 +0000 | [diff] [blame] | 4347 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
| 4348 | |
Bob Wilson | 63d9f3c | 2012-05-15 18:57:39 +0000 | [diff] [blame] | 4349 | if (isObjCRuntimeLinked(Args) && |
| 4350 | !Args.hasArg(options::OPT_nostdlib) && |
| 4351 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4352 | // Avoid linking compatibility stubs on i386 mac. |
| 4353 | if (!getDarwinToolChain().isTargetMacOS() || |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 4354 | getDarwinToolChain().getArch() != llvm::Triple::x86) { |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4355 | // If we don't have ARC or subscripting runtime support, link in the |
| 4356 | // runtime stubs. We have to do this *before* adding any of the normal |
| 4357 | // linker inputs so that its initializer gets run first. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 4358 | ObjCRuntime runtime = |
| 4359 | getDarwinToolChain().getDefaultObjCRuntime(/*nonfragile*/ true); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4360 | // We use arclite library for both ARC and subscripting support. |
John McCall | 0a7dd78 | 2012-08-21 02:47:43 +0000 | [diff] [blame] | 4361 | if ((!runtime.hasNativeARC() && isObjCAutoRefCount(Args)) || |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 4362 | !runtime.hasSubscripting()) |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4363 | getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4364 | } |
Bob Wilson | 0b1c715 | 2012-04-21 00:21:42 +0000 | [diff] [blame] | 4365 | CmdArgs.push_back("-framework"); |
| 4366 | CmdArgs.push_back("Foundation"); |
Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 4367 | // Link libobj. |
| 4368 | CmdArgs.push_back("-lobjc"); |
John McCall | 9f084a3 | 2011-07-06 00:26:06 +0000 | [diff] [blame] | 4369 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 4370 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4371 | if (LinkingOutput) { |
| 4372 | CmdArgs.push_back("-arch_multiple"); |
| 4373 | CmdArgs.push_back("-final_output"); |
| 4374 | CmdArgs.push_back(LinkingOutput); |
| 4375 | } |
| 4376 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4377 | if (Args.hasArg(options::OPT_fnested_functions)) |
| 4378 | CmdArgs.push_back("-allow_stack_execute"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4379 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4380 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4381 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4382 | if (getToolChain().getDriver().CCCIsCXX) |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 4383 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Daniel Dunbar | edfa02b | 2009-04-08 06:06:21 +0000 | [diff] [blame] | 4384 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4385 | // link_ssp spec is empty. |
| 4386 | |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 4387 | // Let the tool chain choose which runtime library to link. |
| 4388 | getDarwinToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4389 | } |
| 4390 | |
Chad Rosier | 1893731 | 2012-05-16 23:45:12 +0000 | [diff] [blame] | 4391 | if (!Args.hasArg(options::OPT_nostdlib) && |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4392 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4393 | // endfile_spec is empty. |
| 4394 | } |
| 4395 | |
| 4396 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4397 | Args.AddAllArgs(CmdArgs, options::OPT_F); |
| 4398 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4399 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4400 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4401 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 4402 | } |
| 4403 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4404 | void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4405 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4406 | const InputInfoList &Inputs, |
| 4407 | const ArgList &Args, |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4408 | const char *LinkingOutput) const { |
| 4409 | ArgStringList CmdArgs; |
| 4410 | |
| 4411 | CmdArgs.push_back("-create"); |
| 4412 | assert(Output.isFilename() && "Unexpected lipo output."); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 4413 | |
| 4414 | CmdArgs.push_back("-output"); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4415 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 4416 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4417 | for (InputInfoList::const_iterator |
| 4418 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4419 | const InputInfo &II = *it; |
| 4420 | assert(II.isFilename() && "Unexpected lipo input."); |
| 4421 | CmdArgs.push_back(II.getFilename()); |
| 4422 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 4423 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4424 | Args.MakeArgString(getToolChain().GetProgramPath("lipo")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4425 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 4426 | } |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 4427 | |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4428 | void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4429 | const InputInfo &Output, |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4430 | const InputInfoList &Inputs, |
| 4431 | const ArgList &Args, |
| 4432 | const char *LinkingOutput) const { |
| 4433 | ArgStringList CmdArgs; |
| 4434 | |
Daniel Dunbar | 03e9230 | 2011-05-09 17:23:16 +0000 | [diff] [blame] | 4435 | CmdArgs.push_back("-o"); |
| 4436 | CmdArgs.push_back(Output.getFilename()); |
| 4437 | |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4438 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 4439 | const InputInfo &Input = Inputs[0]; |
| 4440 | assert(Input.isFilename() && "Unexpected dsymutil input."); |
| 4441 | CmdArgs.push_back(Input.getFilename()); |
| 4442 | |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4443 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4444 | Args.MakeArgString(getToolChain().GetProgramPath("dsymutil")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4445 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 4446 | } |
| 4447 | |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 4448 | void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA, |
Eric Christopher | 27e2b98 | 2012-12-18 00:31:10 +0000 | [diff] [blame] | 4449 | const InputInfo &Output, |
| 4450 | const InputInfoList &Inputs, |
| 4451 | const ArgList &Args, |
| 4452 | const char *LinkingOutput) const { |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 4453 | ArgStringList CmdArgs; |
| 4454 | CmdArgs.push_back("--verify"); |
Eric Christopher | 1c79dc4 | 2012-02-06 19:13:09 +0000 | [diff] [blame] | 4455 | CmdArgs.push_back("--debug-info"); |
| 4456 | CmdArgs.push_back("--eh-frame"); |
Eric Christopher | b822f72 | 2012-02-06 19:43:51 +0000 | [diff] [blame] | 4457 | CmdArgs.push_back("--quiet"); |
Eric Christopher | f857186 | 2011-08-23 17:56:55 +0000 | [diff] [blame] | 4458 | |
| 4459 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 4460 | const InputInfo &Input = Inputs[0]; |
| 4461 | assert(Input.isFilename() && "Unexpected verify input"); |
| 4462 | |
| 4463 | // Grabbing the output of the earlier dsymutil run. |
| 4464 | CmdArgs.push_back(Input.getFilename()); |
| 4465 | |
| 4466 | const char *Exec = |
| 4467 | Args.MakeArgString(getToolChain().GetProgramPath("dwarfdump")); |
| 4468 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4469 | } |
| 4470 | |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4471 | void solaris::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 4472 | const InputInfo &Output, |
| 4473 | const InputInfoList &Inputs, |
| 4474 | const ArgList &Args, |
| 4475 | const char *LinkingOutput) const { |
| 4476 | ArgStringList CmdArgs; |
| 4477 | |
| 4478 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 4479 | options::OPT_Xassembler); |
| 4480 | |
| 4481 | CmdArgs.push_back("-o"); |
| 4482 | CmdArgs.push_back(Output.getFilename()); |
| 4483 | |
| 4484 | for (InputInfoList::const_iterator |
| 4485 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4486 | const InputInfo &II = *it; |
| 4487 | CmdArgs.push_back(II.getFilename()); |
| 4488 | } |
| 4489 | |
| 4490 | const char *Exec = |
| 4491 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
| 4492 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4493 | } |
| 4494 | |
| 4495 | |
| 4496 | void solaris::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 4497 | const InputInfo &Output, |
| 4498 | const InputInfoList &Inputs, |
| 4499 | const ArgList &Args, |
| 4500 | const char *LinkingOutput) const { |
| 4501 | // FIXME: Find a real GCC, don't hard-code versions here |
| 4502 | std::string GCCLibPath = "/usr/gcc/4.5/lib/gcc/"; |
| 4503 | const llvm::Triple &T = getToolChain().getTriple(); |
| 4504 | std::string LibPath = "/usr/lib/"; |
| 4505 | llvm::Triple::ArchType Arch = T.getArch(); |
| 4506 | switch (Arch) { |
| 4507 | case llvm::Triple::x86: |
| 4508 | GCCLibPath += ("i386-" + T.getVendorName() + "-" + |
| 4509 | T.getOSName()).str() + "/4.5.2/"; |
| 4510 | break; |
| 4511 | case llvm::Triple::x86_64: |
| 4512 | GCCLibPath += ("i386-" + T.getVendorName() + "-" + |
| 4513 | T.getOSName()).str(); |
| 4514 | GCCLibPath += "/4.5.2/amd64/"; |
| 4515 | LibPath += "amd64/"; |
| 4516 | break; |
| 4517 | default: |
| 4518 | assert(0 && "Unsupported architecture"); |
| 4519 | } |
| 4520 | |
| 4521 | ArgStringList CmdArgs; |
| 4522 | |
David Chisnall | 41d476d | 2012-02-29 15:06:12 +0000 | [diff] [blame] | 4523 | // Demangle C++ names in errors |
| 4524 | CmdArgs.push_back("-C"); |
| 4525 | |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4526 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
| 4527 | (!Args.hasArg(options::OPT_shared))) { |
| 4528 | CmdArgs.push_back("-e"); |
| 4529 | CmdArgs.push_back("_start"); |
| 4530 | } |
| 4531 | |
| 4532 | if (Args.hasArg(options::OPT_static)) { |
| 4533 | CmdArgs.push_back("-Bstatic"); |
| 4534 | CmdArgs.push_back("-dn"); |
| 4535 | } else { |
| 4536 | CmdArgs.push_back("-Bdynamic"); |
| 4537 | if (Args.hasArg(options::OPT_shared)) { |
| 4538 | CmdArgs.push_back("-shared"); |
| 4539 | } else { |
| 4540 | CmdArgs.push_back("--dynamic-linker"); |
| 4541 | CmdArgs.push_back(Args.MakeArgString(LibPath + "ld.so.1")); |
| 4542 | } |
| 4543 | } |
| 4544 | |
| 4545 | if (Output.isFilename()) { |
| 4546 | CmdArgs.push_back("-o"); |
| 4547 | CmdArgs.push_back(Output.getFilename()); |
| 4548 | } else { |
| 4549 | assert(Output.isNothing() && "Invalid output."); |
| 4550 | } |
| 4551 | |
| 4552 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4553 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4554 | if (!Args.hasArg(options::OPT_shared)) { |
| 4555 | CmdArgs.push_back(Args.MakeArgString(LibPath + "crt1.o")); |
| 4556 | CmdArgs.push_back(Args.MakeArgString(LibPath + "crti.o")); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4557 | CmdArgs.push_back(Args.MakeArgString(LibPath + "values-Xa.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4558 | CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtbegin.o")); |
| 4559 | } else { |
| 4560 | CmdArgs.push_back(Args.MakeArgString(LibPath + "crti.o")); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4561 | CmdArgs.push_back(Args.MakeArgString(LibPath + "values-Xa.o")); |
| 4562 | CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtbegin.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4563 | } |
David Chisnall | e6dd683 | 2012-03-13 14:14:54 +0000 | [diff] [blame] | 4564 | if (getToolChain().getDriver().CCCIsCXX) |
| 4565 | CmdArgs.push_back(Args.MakeArgString(LibPath + "cxa_finalize.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | CmdArgs.push_back(Args.MakeArgString("-L" + GCCLibPath)); |
| 4569 | |
| 4570 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 4571 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4572 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4573 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4574 | |
| 4575 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
| 4576 | |
| 4577 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4578 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
David Chisnall | e58e6f9 | 2012-04-10 11:49:50 +0000 | [diff] [blame] | 4579 | if (getToolChain().getDriver().CCCIsCXX) |
| 4580 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
David Chisnall | b622959 | 2012-02-15 18:24:31 +0000 | [diff] [blame] | 4581 | CmdArgs.push_back("-lgcc_s"); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4582 | if (!Args.hasArg(options::OPT_shared)) { |
| 4583 | CmdArgs.push_back("-lgcc"); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4584 | CmdArgs.push_back("-lc"); |
David Chisnall | 7dbefe1 | 2012-02-28 20:06:45 +0000 | [diff] [blame] | 4585 | CmdArgs.push_back("-lm"); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4586 | } |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4587 | } |
| 4588 | |
| 4589 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4590 | !Args.hasArg(options::OPT_nostartfiles)) { |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 4591 | CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtend.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4592 | } |
David Chisnall | d1ac03e | 2012-02-16 16:00:47 +0000 | [diff] [blame] | 4593 | CmdArgs.push_back(Args.MakeArgString(LibPath + "crtn.o")); |
David Chisnall | 31c4690 | 2012-02-15 13:39:01 +0000 | [diff] [blame] | 4594 | |
| 4595 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
| 4596 | |
| 4597 | const char *Exec = |
| 4598 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
| 4599 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4600 | } |
| 4601 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4602 | void auroraux::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4603 | const InputInfo &Output, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4604 | const InputInfoList &Inputs, |
| 4605 | const ArgList &Args, |
| 4606 | const char *LinkingOutput) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4607 | ArgStringList CmdArgs; |
| 4608 | |
| 4609 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 4610 | options::OPT_Xassembler); |
| 4611 | |
| 4612 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4613 | CmdArgs.push_back(Output.getFilename()); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4614 | |
| 4615 | for (InputInfoList::const_iterator |
| 4616 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4617 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4618 | CmdArgs.push_back(II.getFilename()); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4622 | Args.MakeArgString(getToolChain().GetProgramPath("gas")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4623 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | void auroraux::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4627 | const InputInfo &Output, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4628 | const InputInfoList &Inputs, |
| 4629 | const ArgList &Args, |
| 4630 | const char *LinkingOutput) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4631 | ArgStringList CmdArgs; |
| 4632 | |
| 4633 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4634 | (!Args.hasArg(options::OPT_shared))) { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4635 | CmdArgs.push_back("-e"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 4636 | CmdArgs.push_back("_start"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | if (Args.hasArg(options::OPT_static)) { |
| 4640 | CmdArgs.push_back("-Bstatic"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 4641 | CmdArgs.push_back("-dn"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4642 | } else { |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 4643 | // CmdArgs.push_back("--eh-frame-hdr"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4644 | CmdArgs.push_back("-Bdynamic"); |
| 4645 | if (Args.hasArg(options::OPT_shared)) { |
| 4646 | CmdArgs.push_back("-shared"); |
| 4647 | } else { |
Edward O'Callaghan | 3cecc19 | 2009-10-16 19:44:18 +0000 | [diff] [blame] | 4648 | CmdArgs.push_back("--dynamic-linker"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4649 | CmdArgs.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1 |
| 4650 | } |
| 4651 | } |
| 4652 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4653 | if (Output.isFilename()) { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 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)) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4663 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4664 | getToolChain().GetFilePath("crt1.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4665 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4666 | getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4667 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4668 | getToolChain().GetFilePath("crtbegin.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4669 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4670 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4671 | getToolChain().GetFilePath("crti.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4672 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4673 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4674 | getToolChain().GetFilePath("crtn.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4677 | CmdArgs.push_back(Args.MakeArgString("-L/opt/gcc4/lib/gcc/" |
| 4678 | + getToolChain().getTripleString() |
Daniel Dunbar | f7fb31f | 2009-10-29 02:24:37 +0000 | [diff] [blame] | 4679 | + "/4.2.4")); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4680 | |
| 4681 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 4682 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4683 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 4684 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 4685 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4686 | |
| 4687 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4688 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 4689 | // FIXME: For some reason GCC passes -lgcc before adding |
| 4690 | // the default system libraries. Just mimic this for now. |
| 4691 | CmdArgs.push_back("-lgcc"); |
| 4692 | |
| 4693 | if (Args.hasArg(options::OPT_pthread)) |
| 4694 | CmdArgs.push_back("-pthread"); |
| 4695 | if (!Args.hasArg(options::OPT_shared)) |
| 4696 | CmdArgs.push_back("-lc"); |
| 4697 | CmdArgs.push_back("-lgcc"); |
| 4698 | } |
| 4699 | |
| 4700 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4701 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4702 | if (!Args.hasArg(options::OPT_shared)) |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4703 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4704 | getToolChain().GetFilePath("crtend.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4705 | } |
| 4706 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 4707 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 4708 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4709 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4710 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4711 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 4712 | } |
| 4713 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4714 | void openbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4715 | const InputInfo &Output, |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4716 | const InputInfoList &Inputs, |
| 4717 | const ArgList &Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4718 | const char *LinkingOutput) const { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4719 | ArgStringList CmdArgs; |
| 4720 | |
| 4721 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 4722 | options::OPT_Xassembler); |
| 4723 | |
| 4724 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4725 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4726 | |
| 4727 | for (InputInfoList::const_iterator |
| 4728 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4729 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4730 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
| 4733 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4734 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4735 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | void openbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4739 | const InputInfo &Output, |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4740 | const InputInfoList &Inputs, |
| 4741 | const ArgList &Args, |
| 4742 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 4743 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4744 | ArgStringList CmdArgs; |
| 4745 | |
Rafael Espindola | 6cc2a68 | 2012-12-31 22:41:36 +0000 | [diff] [blame] | 4746 | // Silence warning for "clang -g foo.o -o foo" |
| 4747 | Args.ClaimAllArgs(options::OPT_g_Group); |
| 4748 | // and "clang -emit-llvm foo.o -o foo" |
| 4749 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
| 4750 | // and for "clang -w foo.o -o foo". Other warning options are already |
| 4751 | // handled somewhere else. |
| 4752 | Args.ClaimAllArgs(options::OPT_w); |
| 4753 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4754 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4755 | (!Args.hasArg(options::OPT_shared))) { |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4756 | CmdArgs.push_back("-e"); |
| 4757 | CmdArgs.push_back("__start"); |
| 4758 | } |
| 4759 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4760 | if (Args.hasArg(options::OPT_static)) { |
| 4761 | CmdArgs.push_back("-Bstatic"); |
| 4762 | } else { |
Rafael Espindola | 65ba55d | 2010-11-11 02:17:51 +0000 | [diff] [blame] | 4763 | if (Args.hasArg(options::OPT_rdynamic)) |
| 4764 | CmdArgs.push_back("-export-dynamic"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4765 | CmdArgs.push_back("--eh-frame-hdr"); |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4766 | CmdArgs.push_back("-Bdynamic"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4767 | if (Args.hasArg(options::OPT_shared)) { |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4768 | CmdArgs.push_back("-shared"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4769 | } else { |
| 4770 | CmdArgs.push_back("-dynamic-linker"); |
| 4771 | CmdArgs.push_back("/usr/libexec/ld.so"); |
| 4772 | } |
| 4773 | } |
| 4774 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 4775 | if (Output.isFilename()) { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4776 | CmdArgs.push_back("-o"); |
| 4777 | CmdArgs.push_back(Output.getFilename()); |
| 4778 | } else { |
| 4779 | assert(Output.isNothing() && "Invalid output."); |
| 4780 | } |
| 4781 | |
| 4782 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4783 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4784 | if (!Args.hasArg(options::OPT_shared)) { |
Eli Friedman | 62d829a | 2011-12-15 02:15:56 +0000 | [diff] [blame] | 4785 | if (Args.hasArg(options::OPT_pg)) |
| 4786 | CmdArgs.push_back(Args.MakeArgString( |
| 4787 | getToolChain().GetFilePath("gcrt0.o"))); |
| 4788 | else |
| 4789 | CmdArgs.push_back(Args.MakeArgString( |
| 4790 | getToolChain().GetFilePath("crt0.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4791 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4792 | getToolChain().GetFilePath("crtbegin.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4793 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4794 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4795 | getToolChain().GetFilePath("crtbeginS.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4796 | } |
| 4797 | } |
| 4798 | |
Edward O'Callaghan | e7e1820 | 2009-10-28 15:13:08 +0000 | [diff] [blame] | 4799 | std::string Triple = getToolChain().getTripleString(); |
| 4800 | if (Triple.substr(0, 6) == "x86_64") |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 4801 | Triple.replace(0, 6, "amd64"); |
Daniel Dunbar | f7fb31f | 2009-10-29 02:24:37 +0000 | [diff] [blame] | 4802 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc-lib/" + Triple + |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 4803 | "/4.2.1")); |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4804 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4805 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 4806 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4807 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
Rafael Espindola | 6cc2a68 | 2012-12-31 22:41:36 +0000 | [diff] [blame] | 4808 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 4809 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 4810 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 4811 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4812 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 4813 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4814 | |
| 4815 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4816 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 4817 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 4818 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Eli Friedman | 62d829a | 2011-12-15 02:15:56 +0000 | [diff] [blame] | 4819 | if (Args.hasArg(options::OPT_pg)) |
| 4820 | CmdArgs.push_back("-lm_p"); |
| 4821 | else |
| 4822 | CmdArgs.push_back("-lm"); |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 4823 | } |
| 4824 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4825 | // FIXME: For some reason GCC passes -lgcc before adding |
| 4826 | // the default system libraries. Just mimic this for now. |
| 4827 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4828 | |
Eric Christopher | dc6cc87 | 2012-09-13 06:32:34 +0000 | [diff] [blame] | 4829 | if (Args.hasArg(options::OPT_pthread)) { |
| 4830 | if (!Args.hasArg(options::OPT_shared) && |
| 4831 | Args.hasArg(options::OPT_pg)) |
| 4832 | CmdArgs.push_back("-lpthread_p"); |
| 4833 | else |
| 4834 | CmdArgs.push_back("-lpthread"); |
| 4835 | } |
| 4836 | |
Chandler Carruth | 657849c | 2011-12-17 22:32:42 +0000 | [diff] [blame] | 4837 | if (!Args.hasArg(options::OPT_shared)) { |
Eric Christopher | dc6cc87 | 2012-09-13 06:32:34 +0000 | [diff] [blame] | 4838 | if (Args.hasArg(options::OPT_pg)) |
Eli Friedman | 62d829a | 2011-12-15 02:15:56 +0000 | [diff] [blame] | 4839 | CmdArgs.push_back("-lc_p"); |
| 4840 | else |
| 4841 | CmdArgs.push_back("-lc"); |
Chandler Carruth | 657849c | 2011-12-17 22:32:42 +0000 | [diff] [blame] | 4842 | } |
Eric Christopher | dc6cc87 | 2012-09-13 06:32:34 +0000 | [diff] [blame] | 4843 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 4844 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4848 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4849 | if (!Args.hasArg(options::OPT_shared)) |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4850 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4851 | getToolChain().GetFilePath("crtend.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4852 | else |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4853 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4854 | getToolChain().GetFilePath("crtendS.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4858 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4859 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 4860 | } |
Ed Schouten | c66a5a3 | 2009-04-02 19:13:12 +0000 | [diff] [blame] | 4861 | |
Eli Friedman | 42f74f2 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 4862 | void bitrig::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 4863 | const InputInfo &Output, |
| 4864 | const InputInfoList &Inputs, |
| 4865 | const ArgList &Args, |
| 4866 | const char *LinkingOutput) const { |
| 4867 | ArgStringList CmdArgs; |
| 4868 | |
| 4869 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 4870 | options::OPT_Xassembler); |
| 4871 | |
| 4872 | CmdArgs.push_back("-o"); |
| 4873 | CmdArgs.push_back(Output.getFilename()); |
| 4874 | |
| 4875 | for (InputInfoList::const_iterator |
| 4876 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 4877 | const InputInfo &II = *it; |
| 4878 | CmdArgs.push_back(II.getFilename()); |
| 4879 | } |
| 4880 | |
| 4881 | const char *Exec = |
| 4882 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
| 4883 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4884 | } |
| 4885 | |
| 4886 | void bitrig::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 4887 | const InputInfo &Output, |
| 4888 | const InputInfoList &Inputs, |
| 4889 | const ArgList &Args, |
| 4890 | const char *LinkingOutput) const { |
| 4891 | const Driver &D = getToolChain().getDriver(); |
| 4892 | ArgStringList CmdArgs; |
| 4893 | |
| 4894 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
| 4895 | (!Args.hasArg(options::OPT_shared))) { |
| 4896 | CmdArgs.push_back("-e"); |
| 4897 | CmdArgs.push_back("__start"); |
| 4898 | } |
| 4899 | |
| 4900 | if (Args.hasArg(options::OPT_static)) { |
| 4901 | CmdArgs.push_back("-Bstatic"); |
| 4902 | } else { |
| 4903 | if (Args.hasArg(options::OPT_rdynamic)) |
| 4904 | CmdArgs.push_back("-export-dynamic"); |
| 4905 | CmdArgs.push_back("--eh-frame-hdr"); |
| 4906 | CmdArgs.push_back("-Bdynamic"); |
| 4907 | if (Args.hasArg(options::OPT_shared)) { |
| 4908 | CmdArgs.push_back("-shared"); |
| 4909 | } else { |
| 4910 | CmdArgs.push_back("-dynamic-linker"); |
| 4911 | CmdArgs.push_back("/usr/libexec/ld.so"); |
| 4912 | } |
| 4913 | } |
| 4914 | |
| 4915 | if (Output.isFilename()) { |
| 4916 | CmdArgs.push_back("-o"); |
| 4917 | CmdArgs.push_back(Output.getFilename()); |
| 4918 | } else { |
| 4919 | assert(Output.isNothing() && "Invalid output."); |
| 4920 | } |
| 4921 | |
| 4922 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4923 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4924 | if (!Args.hasArg(options::OPT_shared)) { |
| 4925 | if (Args.hasArg(options::OPT_pg)) |
| 4926 | CmdArgs.push_back(Args.MakeArgString( |
| 4927 | getToolChain().GetFilePath("gcrt0.o"))); |
| 4928 | else |
| 4929 | CmdArgs.push_back(Args.MakeArgString( |
| 4930 | getToolChain().GetFilePath("crt0.o"))); |
| 4931 | CmdArgs.push_back(Args.MakeArgString( |
| 4932 | getToolChain().GetFilePath("crtbegin.o"))); |
| 4933 | } else { |
| 4934 | CmdArgs.push_back(Args.MakeArgString( |
| 4935 | getToolChain().GetFilePath("crtbeginS.o"))); |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 4940 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 4941 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 4942 | |
| 4943 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
| 4944 | |
| 4945 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4946 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 4947 | if (D.CCCIsCXX) { |
| 4948 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
| 4949 | if (Args.hasArg(options::OPT_pg)) |
| 4950 | CmdArgs.push_back("-lm_p"); |
| 4951 | else |
| 4952 | CmdArgs.push_back("-lm"); |
| 4953 | } |
| 4954 | |
Rafael Espindola | 3667bbe | 2012-10-23 17:07:31 +0000 | [diff] [blame] | 4955 | if (Args.hasArg(options::OPT_pthread)) { |
| 4956 | if (!Args.hasArg(options::OPT_shared) && |
| 4957 | Args.hasArg(options::OPT_pg)) |
| 4958 | CmdArgs.push_back("-lpthread_p"); |
| 4959 | else |
| 4960 | CmdArgs.push_back("-lpthread"); |
| 4961 | } |
| 4962 | |
Eli Friedman | 42f74f2 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 4963 | if (!Args.hasArg(options::OPT_shared)) { |
| 4964 | if (Args.hasArg(options::OPT_pg)) |
| 4965 | CmdArgs.push_back("-lc_p"); |
| 4966 | else |
| 4967 | CmdArgs.push_back("-lc"); |
| 4968 | } |
| 4969 | |
| 4970 | std::string myarch = "-lclang_rt."; |
| 4971 | const llvm::Triple &T = getToolChain().getTriple(); |
| 4972 | llvm::Triple::ArchType Arch = T.getArch(); |
| 4973 | switch (Arch) { |
| 4974 | case llvm::Triple::arm: |
| 4975 | myarch += ("arm"); |
| 4976 | break; |
| 4977 | case llvm::Triple::x86: |
| 4978 | myarch += ("i386"); |
| 4979 | break; |
| 4980 | case llvm::Triple::x86_64: |
| 4981 | myarch += ("amd64"); |
| 4982 | break; |
| 4983 | default: |
| 4984 | assert(0 && "Unsupported architecture"); |
| 4985 | } |
| 4986 | CmdArgs.push_back(Args.MakeArgString(myarch)); |
| 4987 | } |
| 4988 | |
| 4989 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4990 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4991 | if (!Args.hasArg(options::OPT_shared)) |
| 4992 | CmdArgs.push_back(Args.MakeArgString( |
| 4993 | getToolChain().GetFilePath("crtend.o"))); |
| 4994 | else |
| 4995 | CmdArgs.push_back(Args.MakeArgString( |
| 4996 | getToolChain().GetFilePath("crtendS.o"))); |
| 4997 | } |
Eli Friedman | c9c48db | 2012-08-09 22:42:04 +0000 | [diff] [blame] | 4998 | |
| 4999 | const char *Exec = |
| 5000 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
| 5001 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Eli Friedman | 42f74f2 | 2012-08-08 23:57:20 +0000 | [diff] [blame] | 5002 | } |
| 5003 | |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 5004 | void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5005 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 5006 | const InputInfoList &Inputs, |
| 5007 | const ArgList &Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5008 | const char *LinkingOutput) const { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 5009 | ArgStringList CmdArgs; |
| 5010 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5011 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 5012 | // instruct as in the base system to assemble 32-bit code. |
Eric Christopher | c55da4b | 2012-09-05 21:32:44 +0000 | [diff] [blame] | 5013 | if (getToolChain().getArch() == llvm::Triple::x86) |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 5014 | CmdArgs.push_back("--32"); |
Eric Christopher | c55da4b | 2012-09-05 21:32:44 +0000 | [diff] [blame] | 5015 | else if (getToolChain().getArch() == llvm::Triple::ppc) |
Roman Divacky | 3393cef | 2011-06-04 07:37:31 +0000 | [diff] [blame] | 5016 | CmdArgs.push_back("-a32"); |
Eric Christopher | c55da4b | 2012-09-05 21:32:44 +0000 | [diff] [blame] | 5017 | else if (getToolChain().getArch() == llvm::Triple::mips || |
| 5018 | getToolChain().getArch() == llvm::Triple::mipsel || |
| 5019 | getToolChain().getArch() == llvm::Triple::mips64 || |
| 5020 | getToolChain().getArch() == llvm::Triple::mips64el) { |
| 5021 | StringRef CPUName; |
| 5022 | StringRef ABIName; |
| 5023 | getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5024 | |
Eric Christopher | c55da4b | 2012-09-05 21:32:44 +0000 | [diff] [blame] | 5025 | CmdArgs.push_back("-march"); |
| 5026 | CmdArgs.push_back(CPUName.data()); |
| 5027 | |
| 5028 | // Convert ABI name to the GNU tools acceptable variant. |
| 5029 | if (ABIName == "o32") |
| 5030 | ABIName = "32"; |
| 5031 | else if (ABIName == "n64") |
| 5032 | ABIName = "64"; |
| 5033 | |
| 5034 | CmdArgs.push_back("-mabi"); |
| 5035 | CmdArgs.push_back(ABIName.data()); |
| 5036 | |
| 5037 | if (getToolChain().getArch() == llvm::Triple::mips || |
| 5038 | getToolChain().getArch() == llvm::Triple::mips64) |
| 5039 | CmdArgs.push_back("-EB"); |
| 5040 | else |
| 5041 | CmdArgs.push_back("-EL"); |
| 5042 | |
| 5043 | Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, |
| 5044 | options::OPT_fpic, options::OPT_fno_pic, |
| 5045 | options::OPT_fPIE, options::OPT_fno_PIE, |
| 5046 | options::OPT_fpie, options::OPT_fno_pie); |
| 5047 | if (LastPICArg && |
| 5048 | (LastPICArg->getOption().matches(options::OPT_fPIC) || |
| 5049 | LastPICArg->getOption().matches(options::OPT_fpic) || |
| 5050 | LastPICArg->getOption().matches(options::OPT_fPIE) || |
| 5051 | LastPICArg->getOption().matches(options::OPT_fpie))) { |
| 5052 | CmdArgs.push_back("-KPIC"); |
| 5053 | } |
Rafael Espindola | 27fa236 | 2012-12-13 04:17:14 +0000 | [diff] [blame] | 5054 | } else if (getToolChain().getArch() == llvm::Triple::arm || |
| 5055 | getToolChain().getArch() == llvm::Triple::thumb) { |
| 5056 | CmdArgs.push_back("-mfpu=softvfp"); |
| 5057 | switch(getToolChain().getTriple().getEnvironment()) { |
| 5058 | case llvm::Triple::GNUEABI: |
| 5059 | case llvm::Triple::EABI: |
| 5060 | break; |
| 5061 | |
| 5062 | default: |
| 5063 | CmdArgs.push_back("-matpcs"); |
| 5064 | } |
Eric Christopher | c55da4b | 2012-09-05 21:32:44 +0000 | [diff] [blame] | 5065 | } |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 5066 | |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 5067 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 5068 | options::OPT_Xassembler); |
| 5069 | |
| 5070 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5071 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 5072 | |
| 5073 | for (InputInfoList::const_iterator |
| 5074 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5075 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5076 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 5077 | } |
| 5078 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 5079 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5080 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5081 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 5082 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5083 | |
| 5084 | void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5085 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 5086 | const InputInfoList &Inputs, |
| 5087 | const ArgList &Args, |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 5088 | const char *LinkingOutput) const { |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5089 | const toolchains::FreeBSD& ToolChain = |
| 5090 | static_cast<const toolchains::FreeBSD&>(getToolChain()); |
| 5091 | const Driver &D = ToolChain.getDriver(); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5092 | ArgStringList CmdArgs; |
David Chisnall | dfa210b | 2012-07-29 15:24:44 +0000 | [diff] [blame] | 5093 | |
| 5094 | // Silence warning for "clang -g foo.o -o foo" |
| 5095 | Args.ClaimAllArgs(options::OPT_g_Group); |
| 5096 | // and "clang -emit-llvm foo.o -o foo" |
| 5097 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
| 5098 | // and for "clang -w foo.o -o foo". Other warning options are already |
| 5099 | // handled somewhere else. |
| 5100 | Args.ClaimAllArgs(options::OPT_w); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5101 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 5102 | if (!D.SysRoot.empty()) |
| 5103 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 5104 | |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5105 | if (Args.hasArg(options::OPT_pie)) |
| 5106 | CmdArgs.push_back("-pie"); |
| 5107 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5108 | if (Args.hasArg(options::OPT_static)) { |
| 5109 | CmdArgs.push_back("-Bstatic"); |
| 5110 | } else { |
Rafael Espindola | 65ba55d | 2010-11-11 02:17:51 +0000 | [diff] [blame] | 5111 | if (Args.hasArg(options::OPT_rdynamic)) |
| 5112 | CmdArgs.push_back("-export-dynamic"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5113 | CmdArgs.push_back("--eh-frame-hdr"); |
| 5114 | if (Args.hasArg(options::OPT_shared)) { |
| 5115 | CmdArgs.push_back("-Bshareable"); |
| 5116 | } else { |
| 5117 | CmdArgs.push_back("-dynamic-linker"); |
| 5118 | CmdArgs.push_back("/libexec/ld-elf.so.1"); |
| 5119 | } |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5120 | if (ToolChain.getTriple().getOSMajorVersion() >= 9) { |
| 5121 | llvm::Triple::ArchType Arch = ToolChain.getArch(); |
David Chisnall | dfa210b | 2012-07-29 15:24:44 +0000 | [diff] [blame] | 5122 | if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc || |
| 5123 | Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) { |
| 5124 | CmdArgs.push_back("--hash-style=both"); |
| 5125 | } |
| 5126 | } |
| 5127 | CmdArgs.push_back("--enable-new-dtags"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 5131 | // instruct ld in the base system to link 32-bit code. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5132 | if (ToolChain.getArch() == llvm::Triple::x86) { |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5133 | CmdArgs.push_back("-m"); |
| 5134 | CmdArgs.push_back("elf_i386_fbsd"); |
| 5135 | } |
| 5136 | |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5137 | if (ToolChain.getArch() == llvm::Triple::ppc) { |
Roman Divacky | 000a655 | 2011-06-04 07:40:24 +0000 | [diff] [blame] | 5138 | CmdArgs.push_back("-m"); |
Roman Divacky | 1052c1d | 2011-11-21 16:50:32 +0000 | [diff] [blame] | 5139 | CmdArgs.push_back("elf32ppc_fbsd"); |
Roman Divacky | 000a655 | 2011-06-04 07:40:24 +0000 | [diff] [blame] | 5140 | } |
| 5141 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5142 | if (Output.isFilename()) { |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5143 | CmdArgs.push_back("-o"); |
| 5144 | CmdArgs.push_back(Output.getFilename()); |
| 5145 | } else { |
| 5146 | assert(Output.isNothing() && "Invalid output."); |
| 5147 | } |
| 5148 | |
| 5149 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5150 | !Args.hasArg(options::OPT_nostartfiles)) { |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5151 | const char *crt1 = NULL; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5152 | if (!Args.hasArg(options::OPT_shared)) { |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 5153 | if (Args.hasArg(options::OPT_pg)) |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5154 | crt1 = "gcrt1.o"; |
| 5155 | else if (Args.hasArg(options::OPT_pie)) |
| 5156 | crt1 = "Scrt1.o"; |
| 5157 | else |
| 5158 | crt1 = "crt1.o"; |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5159 | } |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5160 | if (crt1) |
| 5161 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1))); |
| 5162 | |
| 5163 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); |
| 5164 | |
| 5165 | const char *crtbegin = NULL; |
| 5166 | if (Args.hasArg(options::OPT_static)) |
| 5167 | crtbegin = "crtbeginT.o"; |
| 5168 | else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) |
| 5169 | crtbegin = "crtbeginS.o"; |
| 5170 | else |
| 5171 | crtbegin = "crtbegin.o"; |
| 5172 | |
| 5173 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5177 | const ToolChain::path_list Paths = ToolChain.getFilePaths(); |
Roman Divacky | 58e5ac9 | 2011-03-01 17:53:14 +0000 | [diff] [blame] | 5178 | for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end(); |
| 5179 | i != e; ++i) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5180 | CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i)); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5181 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 5182 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
David Chisnall | c736377 | 2010-08-15 22:58:12 +0000 | [diff] [blame] | 5183 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 5184 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 5185 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 5186 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5187 | |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5188 | AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5189 | |
| 5190 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5191 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | 2002263 | 2010-02-17 08:07:51 +0000 | [diff] [blame] | 5192 | if (D.CCCIsCXX) { |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5193 | ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 5194 | if (Args.hasArg(options::OPT_pg)) |
| 5195 | CmdArgs.push_back("-lm_p"); |
| 5196 | else |
| 5197 | CmdArgs.push_back("-lm"); |
Daniel Dunbar | 2002263 | 2010-02-17 08:07:51 +0000 | [diff] [blame] | 5198 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5199 | // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding |
| 5200 | // the default system libraries. Just mimic this for now. |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 5201 | if (Args.hasArg(options::OPT_pg)) |
| 5202 | CmdArgs.push_back("-lgcc_p"); |
| 5203 | else |
| 5204 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5205 | if (Args.hasArg(options::OPT_static)) { |
| 5206 | CmdArgs.push_back("-lgcc_eh"); |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 5207 | } else if (Args.hasArg(options::OPT_pg)) { |
| 5208 | CmdArgs.push_back("-lgcc_eh_p"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5209 | } else { |
| 5210 | CmdArgs.push_back("--as-needed"); |
| 5211 | CmdArgs.push_back("-lgcc_s"); |
| 5212 | CmdArgs.push_back("--no-as-needed"); |
| 5213 | } |
| 5214 | |
Matt Beaumont-Gay | 2423026 | 2011-02-10 20:35:01 +0000 | [diff] [blame] | 5215 | if (Args.hasArg(options::OPT_pthread)) { |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 5216 | if (Args.hasArg(options::OPT_pg)) |
| 5217 | CmdArgs.push_back("-lpthread_p"); |
| 5218 | else |
| 5219 | CmdArgs.push_back("-lpthread"); |
Matt Beaumont-Gay | 2423026 | 2011-02-10 20:35:01 +0000 | [diff] [blame] | 5220 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5221 | |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 5222 | if (Args.hasArg(options::OPT_pg)) { |
| 5223 | if (Args.hasArg(options::OPT_shared)) |
| 5224 | CmdArgs.push_back("-lc"); |
| 5225 | else |
| 5226 | CmdArgs.push_back("-lc_p"); |
| 5227 | CmdArgs.push_back("-lgcc_p"); |
| 5228 | } else { |
| 5229 | CmdArgs.push_back("-lc"); |
| 5230 | CmdArgs.push_back("-lgcc"); |
| 5231 | } |
| 5232 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5233 | if (Args.hasArg(options::OPT_static)) { |
| 5234 | CmdArgs.push_back("-lgcc_eh"); |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 5235 | } else if (Args.hasArg(options::OPT_pg)) { |
| 5236 | CmdArgs.push_back("-lgcc_eh_p"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5237 | } else { |
| 5238 | CmdArgs.push_back("--as-needed"); |
| 5239 | CmdArgs.push_back("-lgcc_s"); |
| 5240 | CmdArgs.push_back("--no-as-needed"); |
| 5241 | } |
| 5242 | } |
| 5243 | |
| 5244 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5245 | !Args.hasArg(options::OPT_nostartfiles)) { |
Roman Divacky | f651381 | 2012-09-07 13:36:21 +0000 | [diff] [blame] | 5246 | if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5247 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o"))); |
Roman Divacky | f651381 | 2012-09-07 13:36:21 +0000 | [diff] [blame] | 5248 | else |
| 5249 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5250 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5251 | } |
| 5252 | |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5253 | addProfileRT(ToolChain, Args, CmdArgs, ToolChain.getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 5254 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 5255 | const char *Exec = |
Roman Divacky | 9438016 | 2012-08-28 15:09:03 +0000 | [diff] [blame] | 5256 | Args.MakeArgString(ToolChain.GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5257 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 5258 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5259 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5260 | void netbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 5261 | const InputInfo &Output, |
| 5262 | const InputInfoList &Inputs, |
| 5263 | const ArgList &Args, |
| 5264 | const char *LinkingOutput) const { |
| 5265 | ArgStringList CmdArgs; |
| 5266 | |
| 5267 | // When building 32-bit code on NetBSD/amd64, we have to explicitly |
| 5268 | // instruct as in the base system to assemble 32-bit code. |
Joerg Sonnenberger | 1bd9137 | 2012-01-26 22:27:52 +0000 | [diff] [blame] | 5269 | if (getToolChain().getArch() == llvm::Triple::x86) |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5270 | CmdArgs.push_back("--32"); |
| 5271 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5272 | // Set byte order explicitly |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5273 | if (getToolChain().getArch() == llvm::Triple::mips) |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5274 | CmdArgs.push_back("-EB"); |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5275 | else if (getToolChain().getArch() == llvm::Triple::mipsel) |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5276 | CmdArgs.push_back("-EL"); |
| 5277 | |
| 5278 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 5279 | options::OPT_Xassembler); |
| 5280 | |
| 5281 | CmdArgs.push_back("-o"); |
| 5282 | CmdArgs.push_back(Output.getFilename()); |
| 5283 | |
| 5284 | for (InputInfoList::const_iterator |
| 5285 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5286 | const InputInfo &II = *it; |
| 5287 | CmdArgs.push_back(II.getFilename()); |
| 5288 | } |
| 5289 | |
David Chisnall | 5adcec1 | 2011-09-27 22:03:18 +0000 | [diff] [blame] | 5290 | const char *Exec = Args.MakeArgString((getToolChain().GetProgramPath("as"))); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5291 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 5292 | } |
| 5293 | |
| 5294 | void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 5295 | const InputInfo &Output, |
| 5296 | const InputInfoList &Inputs, |
| 5297 | const ArgList &Args, |
| 5298 | const char *LinkingOutput) const { |
| 5299 | const Driver &D = getToolChain().getDriver(); |
| 5300 | ArgStringList CmdArgs; |
| 5301 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 5302 | if (!D.SysRoot.empty()) |
| 5303 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 5304 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5305 | if (Args.hasArg(options::OPT_static)) { |
| 5306 | CmdArgs.push_back("-Bstatic"); |
| 5307 | } else { |
| 5308 | if (Args.hasArg(options::OPT_rdynamic)) |
| 5309 | CmdArgs.push_back("-export-dynamic"); |
| 5310 | CmdArgs.push_back("--eh-frame-hdr"); |
| 5311 | if (Args.hasArg(options::OPT_shared)) { |
| 5312 | CmdArgs.push_back("-Bshareable"); |
| 5313 | } else { |
| 5314 | CmdArgs.push_back("-dynamic-linker"); |
| 5315 | CmdArgs.push_back("/libexec/ld.elf_so"); |
| 5316 | } |
| 5317 | } |
| 5318 | |
| 5319 | // When building 32-bit code on NetBSD/amd64, we have to explicitly |
| 5320 | // instruct ld in the base system to link 32-bit code. |
Joerg Sonnenberger | 1bd9137 | 2012-01-26 22:27:52 +0000 | [diff] [blame] | 5321 | if (getToolChain().getArch() == llvm::Triple::x86) { |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5322 | CmdArgs.push_back("-m"); |
| 5323 | CmdArgs.push_back("elf_i386"); |
| 5324 | } |
| 5325 | |
| 5326 | if (Output.isFilename()) { |
| 5327 | CmdArgs.push_back("-o"); |
| 5328 | CmdArgs.push_back(Output.getFilename()); |
| 5329 | } else { |
| 5330 | assert(Output.isNothing() && "Invalid output."); |
| 5331 | } |
| 5332 | |
| 5333 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5334 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5335 | if (!Args.hasArg(options::OPT_shared)) { |
| 5336 | CmdArgs.push_back(Args.MakeArgString( |
| 5337 | getToolChain().GetFilePath("crt0.o"))); |
| 5338 | CmdArgs.push_back(Args.MakeArgString( |
| 5339 | getToolChain().GetFilePath("crti.o"))); |
| 5340 | CmdArgs.push_back(Args.MakeArgString( |
| 5341 | getToolChain().GetFilePath("crtbegin.o"))); |
| 5342 | } else { |
| 5343 | CmdArgs.push_back(Args.MakeArgString( |
| 5344 | getToolChain().GetFilePath("crti.o"))); |
| 5345 | CmdArgs.push_back(Args.MakeArgString( |
| 5346 | getToolChain().GetFilePath("crtbeginS.o"))); |
| 5347 | } |
| 5348 | } |
| 5349 | |
| 5350 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 5351 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 5352 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 5353 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 5354 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 5355 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 5356 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
| 5357 | |
| 5358 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
| 5359 | |
| 5360 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5361 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 5362 | if (D.CCCIsCXX) { |
| 5363 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
| 5364 | CmdArgs.push_back("-lm"); |
| 5365 | } |
| 5366 | // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding |
| 5367 | // the default system libraries. Just mimic this for now. |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5368 | if (Args.hasArg(options::OPT_static)) { |
| 5369 | CmdArgs.push_back("-lgcc_eh"); |
| 5370 | } else { |
| 5371 | CmdArgs.push_back("--as-needed"); |
| 5372 | CmdArgs.push_back("-lgcc_s"); |
| 5373 | CmdArgs.push_back("--no-as-needed"); |
| 5374 | } |
Joerg Sonnenberger | db6393f | 2011-06-07 23:39:17 +0000 | [diff] [blame] | 5375 | CmdArgs.push_back("-lgcc"); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5376 | |
| 5377 | if (Args.hasArg(options::OPT_pthread)) |
| 5378 | CmdArgs.push_back("-lpthread"); |
| 5379 | CmdArgs.push_back("-lc"); |
| 5380 | |
| 5381 | CmdArgs.push_back("-lgcc"); |
| 5382 | if (Args.hasArg(options::OPT_static)) { |
| 5383 | CmdArgs.push_back("-lgcc_eh"); |
| 5384 | } else { |
| 5385 | CmdArgs.push_back("--as-needed"); |
| 5386 | CmdArgs.push_back("-lgcc_s"); |
| 5387 | CmdArgs.push_back("--no-as-needed"); |
| 5388 | } |
| 5389 | } |
| 5390 | |
| 5391 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5392 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5393 | if (!Args.hasArg(options::OPT_shared)) |
| 5394 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
| 5395 | "crtend.o"))); |
| 5396 | else |
| 5397 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
| 5398 | "crtendS.o"))); |
| 5399 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
| 5400 | "crtn.o"))); |
| 5401 | } |
| 5402 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 5403 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 5404 | |
David Chisnall | 5adcec1 | 2011-09-27 22:03:18 +0000 | [diff] [blame] | 5405 | const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 5406 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 5407 | } |
| 5408 | |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5409 | void linuxtools::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 5410 | const InputInfo &Output, |
| 5411 | const InputInfoList &Inputs, |
| 5412 | const ArgList &Args, |
| 5413 | const char *LinkingOutput) const { |
| 5414 | ArgStringList CmdArgs; |
| 5415 | |
| 5416 | // Add --32/--64 to make sure we get the format we want. |
| 5417 | // This is incomplete |
| 5418 | if (getToolChain().getArch() == llvm::Triple::x86) { |
| 5419 | CmdArgs.push_back("--32"); |
| 5420 | } else if (getToolChain().getArch() == llvm::Triple::x86_64) { |
| 5421 | CmdArgs.push_back("--64"); |
Eli Friedman | 7972c88 | 2011-11-28 23:46:52 +0000 | [diff] [blame] | 5422 | } else if (getToolChain().getArch() == llvm::Triple::ppc) { |
| 5423 | CmdArgs.push_back("-a32"); |
| 5424 | CmdArgs.push_back("-mppc"); |
| 5425 | CmdArgs.push_back("-many"); |
| 5426 | } else if (getToolChain().getArch() == llvm::Triple::ppc64) { |
| 5427 | CmdArgs.push_back("-a64"); |
| 5428 | CmdArgs.push_back("-mppc64"); |
| 5429 | CmdArgs.push_back("-many"); |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5430 | } else if (getToolChain().getArch() == llvm::Triple::arm) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5431 | StringRef MArch = getToolChain().getArchName(); |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5432 | if (MArch == "armv7" || MArch == "armv7a" || MArch == "armv7-a") |
| 5433 | CmdArgs.push_back("-mfpu=neon"); |
Evgeniy Stepanov | 700c508 | 2012-04-20 09:03:40 +0000 | [diff] [blame] | 5434 | |
| 5435 | StringRef ARMFloatABI = getARMFloatABI(getToolChain().getDriver(), Args, |
| 5436 | getToolChain().getTriple()); |
| 5437 | CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=" + ARMFloatABI)); |
Evgeniy Stepanov | eca187e | 2012-04-24 09:05:31 +0000 | [diff] [blame] | 5438 | |
| 5439 | Args.AddLastArg(CmdArgs, options::OPT_march_EQ); |
| 5440 | Args.AddLastArg(CmdArgs, options::OPT_mcpu_EQ); |
| 5441 | Args.AddLastArg(CmdArgs, options::OPT_mfpu_EQ); |
Akira Hatanaka | c85900f | 2011-11-30 19:31:38 +0000 | [diff] [blame] | 5442 | } else if (getToolChain().getArch() == llvm::Triple::mips || |
| 5443 | getToolChain().getArch() == llvm::Triple::mipsel || |
| 5444 | getToolChain().getArch() == llvm::Triple::mips64 || |
| 5445 | getToolChain().getArch() == llvm::Triple::mips64el) { |
Simon Atanasyan | 073a780 | 2012-04-07 22:31:29 +0000 | [diff] [blame] | 5446 | StringRef CPUName; |
| 5447 | StringRef ABIName; |
| 5448 | getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName); |
Akira Hatanaka | c85900f | 2011-11-30 19:31:38 +0000 | [diff] [blame] | 5449 | |
Simon Atanasyan | 073a780 | 2012-04-07 22:31:29 +0000 | [diff] [blame] | 5450 | CmdArgs.push_back("-march"); |
| 5451 | CmdArgs.push_back(CPUName.data()); |
| 5452 | |
| 5453 | // Convert ABI name to the GNU tools acceptable variant. |
| 5454 | if (ABIName == "o32") |
| 5455 | ABIName = "32"; |
| 5456 | else if (ABIName == "n64") |
| 5457 | ABIName = "64"; |
| 5458 | |
| 5459 | CmdArgs.push_back("-mabi"); |
| 5460 | CmdArgs.push_back(ABIName.data()); |
Simon Atanasyan | 5f0a1c1 | 2012-04-06 19:15:24 +0000 | [diff] [blame] | 5461 | |
| 5462 | if (getToolChain().getArch() == llvm::Triple::mips || |
| 5463 | getToolChain().getArch() == llvm::Triple::mips64) |
| 5464 | CmdArgs.push_back("-EB"); |
| 5465 | else |
| 5466 | CmdArgs.push_back("-EL"); |
Simon Atanasyan | 1f0646e | 2012-05-29 19:07:33 +0000 | [diff] [blame] | 5467 | |
| 5468 | Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, |
| 5469 | options::OPT_fpic, options::OPT_fno_pic, |
| 5470 | options::OPT_fPIE, options::OPT_fno_PIE, |
| 5471 | options::OPT_fpie, options::OPT_fno_pie); |
| 5472 | if (LastPICArg && |
| 5473 | (LastPICArg->getOption().matches(options::OPT_fPIC) || |
| 5474 | LastPICArg->getOption().matches(options::OPT_fpic) || |
| 5475 | LastPICArg->getOption().matches(options::OPT_fPIE) || |
| 5476 | LastPICArg->getOption().matches(options::OPT_fpie))) { |
| 5477 | CmdArgs.push_back("-KPIC"); |
| 5478 | } |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 5482 | options::OPT_Xassembler); |
| 5483 | |
| 5484 | CmdArgs.push_back("-o"); |
| 5485 | CmdArgs.push_back(Output.getFilename()); |
| 5486 | |
| 5487 | for (InputInfoList::const_iterator |
| 5488 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5489 | const InputInfo &II = *it; |
| 5490 | CmdArgs.push_back(II.getFilename()); |
| 5491 | } |
| 5492 | |
| 5493 | const char *Exec = |
| 5494 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
| 5495 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 5496 | } |
| 5497 | |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5498 | static void AddLibgcc(llvm::Triple Triple, const Driver &D, |
| 5499 | ArgStringList &CmdArgs, const ArgList &Args) { |
Logan Chien | 94a7142 | 2012-09-02 09:30:11 +0000 | [diff] [blame] | 5500 | bool isAndroid = Triple.getEnvironment() == llvm::Triple::Android; |
Logan Chien | 529a73d | 2012-11-19 12:04:11 +0000 | [diff] [blame] | 5501 | bool StaticLibgcc = Args.hasArg(options::OPT_static) || |
| 5502 | Args.hasArg(options::OPT_static_libgcc); |
Rafael Espindola | abf3ac7 | 2011-10-17 21:39:04 +0000 | [diff] [blame] | 5503 | if (!D.CCCIsCXX) |
| 5504 | CmdArgs.push_back("-lgcc"); |
| 5505 | |
Logan Chien | 529a73d | 2012-11-19 12:04:11 +0000 | [diff] [blame] | 5506 | if (StaticLibgcc || isAndroid) { |
Rafael Espindola | abf3ac7 | 2011-10-17 21:39:04 +0000 | [diff] [blame] | 5507 | if (D.CCCIsCXX) |
| 5508 | CmdArgs.push_back("-lgcc"); |
| 5509 | } else { |
| 5510 | if (!D.CCCIsCXX) |
| 5511 | CmdArgs.push_back("--as-needed"); |
| 5512 | CmdArgs.push_back("-lgcc_s"); |
| 5513 | if (!D.CCCIsCXX) |
| 5514 | CmdArgs.push_back("--no-as-needed"); |
| 5515 | } |
| 5516 | |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5517 | if (StaticLibgcc && !isAndroid) |
Rafael Espindola | abf3ac7 | 2011-10-17 21:39:04 +0000 | [diff] [blame] | 5518 | CmdArgs.push_back("-lgcc_eh"); |
| 5519 | else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX) |
| 5520 | CmdArgs.push_back("-lgcc"); |
Logan Chien | 529a73d | 2012-11-19 12:04:11 +0000 | [diff] [blame] | 5521 | |
| 5522 | // According to Android ABI, we have to link with libdl if we are |
| 5523 | // linking with non-static libgcc. |
| 5524 | // |
| 5525 | // NOTE: This fixes a link error on Android MIPS as well. The non-static |
| 5526 | // libgcc for MIPS relies on _Unwind_Find_FDE and dl_iterate_phdr from libdl. |
| 5527 | if (isAndroid && !StaticLibgcc) |
| 5528 | CmdArgs.push_back("-ldl"); |
Rafael Espindola | abf3ac7 | 2011-10-17 21:39:04 +0000 | [diff] [blame] | 5529 | } |
| 5530 | |
Simon Atanasyan | f4bd329 | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 5531 | static bool hasMipsN32ABIArg(const ArgList &Args) { |
| 5532 | Arg *A = Args.getLastArg(options::OPT_mabi_EQ); |
Richard Smith | 1d489cf | 2012-11-01 04:30:05 +0000 | [diff] [blame] | 5533 | return A && (A->getValue() == StringRef("n32")); |
Simon Atanasyan | f4bd329 | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 5534 | } |
| 5535 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5536 | void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 5537 | const InputInfo &Output, |
| 5538 | const InputInfoList &Inputs, |
| 5539 | const ArgList &Args, |
| 5540 | const char *LinkingOutput) const { |
| 5541 | const toolchains::Linux& ToolChain = |
| 5542 | static_cast<const toolchains::Linux&>(getToolChain()); |
| 5543 | const Driver &D = ToolChain.getDriver(); |
Rafael Espindola | 715852c | 2012-11-02 20:41:30 +0000 | [diff] [blame] | 5544 | const bool isAndroid = |
| 5545 | ToolChain.getTriple().getEnvironment() == llvm::Triple::Android; |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5546 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5547 | ArgStringList CmdArgs; |
| 5548 | |
Rafael Espindola | 26f14c3 | 2010-11-15 18:28:16 +0000 | [diff] [blame] | 5549 | // Silence warning for "clang -g foo.o -o foo" |
| 5550 | Args.ClaimAllArgs(options::OPT_g_Group); |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 5551 | // and "clang -emit-llvm foo.o -o foo" |
| 5552 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
David Chisnall | dfa210b | 2012-07-29 15:24:44 +0000 | [diff] [blame] | 5553 | // 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] | 5554 | // handled somewhere else. |
| 5555 | Args.ClaimAllArgs(options::OPT_w); |
Rafael Espindola | 26f14c3 | 2010-11-15 18:28:16 +0000 | [diff] [blame] | 5556 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 5557 | if (!D.SysRoot.empty()) |
| 5558 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5559 | |
Peter Collingbourne | 17d481f | 2013-01-17 20:17:16 +0000 | [diff] [blame] | 5560 | if (Args.hasArg(options::OPT_pie) && !Args.hasArg(options::OPT_shared)) |
Rafael Espindola | fdda171 | 2010-11-17 22:26:15 +0000 | [diff] [blame] | 5561 | CmdArgs.push_back("-pie"); |
| 5562 | |
Rafael Espindola | dc1b76d | 2010-11-07 22:57:16 +0000 | [diff] [blame] | 5563 | if (Args.hasArg(options::OPT_rdynamic)) |
| 5564 | CmdArgs.push_back("-export-dynamic"); |
| 5565 | |
Rafael Espindola | e0e6d3b | 2010-11-11 19:34:42 +0000 | [diff] [blame] | 5566 | if (Args.hasArg(options::OPT_s)) |
| 5567 | CmdArgs.push_back("-s"); |
| 5568 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5569 | for (std::vector<std::string>::const_iterator i = ToolChain.ExtraOpts.begin(), |
| 5570 | e = ToolChain.ExtraOpts.end(); |
| 5571 | i != e; ++i) |
| 5572 | CmdArgs.push_back(i->c_str()); |
| 5573 | |
| 5574 | if (!Args.hasArg(options::OPT_static)) { |
| 5575 | CmdArgs.push_back("--eh-frame-hdr"); |
| 5576 | } |
| 5577 | |
| 5578 | CmdArgs.push_back("-m"); |
| 5579 | if (ToolChain.getArch() == llvm::Triple::x86) |
| 5580 | CmdArgs.push_back("elf_i386"); |
Eric Christopher | 88b7cf0 | 2011-08-19 00:30:14 +0000 | [diff] [blame] | 5581 | else if (ToolChain.getArch() == llvm::Triple::arm |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 5582 | || ToolChain.getArch() == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5583 | CmdArgs.push_back("armelf_linux_eabi"); |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 5584 | else if (ToolChain.getArch() == llvm::Triple::ppc) |
| 5585 | CmdArgs.push_back("elf32ppclinux"); |
| 5586 | else if (ToolChain.getArch() == llvm::Triple::ppc64) |
| 5587 | CmdArgs.push_back("elf64ppc"); |
Eli Friedman | 5bea4f6 | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 5588 | else if (ToolChain.getArch() == llvm::Triple::mips) |
| 5589 | CmdArgs.push_back("elf32btsmip"); |
| 5590 | else if (ToolChain.getArch() == llvm::Triple::mipsel) |
| 5591 | CmdArgs.push_back("elf32ltsmip"); |
Simon Atanasyan | f4bd329 | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 5592 | else if (ToolChain.getArch() == llvm::Triple::mips64) { |
| 5593 | if (hasMipsN32ABIArg(Args)) |
| 5594 | CmdArgs.push_back("elf32btsmipn32"); |
| 5595 | else |
| 5596 | CmdArgs.push_back("elf64btsmip"); |
| 5597 | } |
| 5598 | else if (ToolChain.getArch() == llvm::Triple::mips64el) { |
| 5599 | if (hasMipsN32ABIArg(Args)) |
| 5600 | CmdArgs.push_back("elf32ltsmipn32"); |
| 5601 | else |
| 5602 | CmdArgs.push_back("elf64ltsmip"); |
| 5603 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5604 | else |
| 5605 | CmdArgs.push_back("elf_x86_64"); |
| 5606 | |
| 5607 | if (Args.hasArg(options::OPT_static)) { |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 5608 | if (ToolChain.getArch() == llvm::Triple::arm |
| 5609 | || ToolChain.getArch() == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5610 | CmdArgs.push_back("-Bstatic"); |
| 5611 | else |
| 5612 | CmdArgs.push_back("-static"); |
| 5613 | } else if (Args.hasArg(options::OPT_shared)) { |
| 5614 | CmdArgs.push_back("-shared"); |
Rafael Espindola | 715852c | 2012-11-02 20:41:30 +0000 | [diff] [blame] | 5615 | if (isAndroid) { |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5616 | CmdArgs.push_back("-Bsymbolic"); |
| 5617 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | if (ToolChain.getArch() == llvm::Triple::arm || |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 5621 | ToolChain.getArch() == llvm::Triple::thumb || |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5622 | (!Args.hasArg(options::OPT_static) && |
| 5623 | !Args.hasArg(options::OPT_shared))) { |
| 5624 | CmdArgs.push_back("-dynamic-linker"); |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5625 | if (isAndroid) |
| 5626 | CmdArgs.push_back("/system/bin/linker"); |
| 5627 | else if (ToolChain.getArch() == llvm::Triple::x86) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5628 | CmdArgs.push_back("/lib/ld-linux.so.2"); |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 5629 | else if (ToolChain.getArch() == llvm::Triple::arm || |
Jiangning Liu | 6cc9dc8 | 2012-07-30 11:05:56 +0000 | [diff] [blame] | 5630 | ToolChain.getArch() == llvm::Triple::thumb) { |
| 5631 | if (ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUEABIHF) |
| 5632 | CmdArgs.push_back("/lib/ld-linux-armhf.so.3"); |
| 5633 | else |
| 5634 | CmdArgs.push_back("/lib/ld-linux.so.3"); |
| 5635 | } |
Eli Friedman | 5bea4f6 | 2011-11-08 19:43:37 +0000 | [diff] [blame] | 5636 | else if (ToolChain.getArch() == llvm::Triple::mips || |
| 5637 | ToolChain.getArch() == llvm::Triple::mipsel) |
| 5638 | CmdArgs.push_back("/lib/ld.so.1"); |
Simon Atanasyan | 8491cb2 | 2012-04-06 20:14:27 +0000 | [diff] [blame] | 5639 | else if (ToolChain.getArch() == llvm::Triple::mips64 || |
Simon Atanasyan | f4bd329 | 2012-10-21 11:44:57 +0000 | [diff] [blame] | 5640 | ToolChain.getArch() == llvm::Triple::mips64el) { |
| 5641 | if (hasMipsN32ABIArg(Args)) |
| 5642 | CmdArgs.push_back("/lib32/ld.so.1"); |
| 5643 | else |
| 5644 | CmdArgs.push_back("/lib64/ld.so.1"); |
| 5645 | } |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 5646 | else if (ToolChain.getArch() == llvm::Triple::ppc) |
Chris Lattner | 09f43ed | 2011-04-11 21:15:37 +0000 | [diff] [blame] | 5647 | CmdArgs.push_back("/lib/ld.so.1"); |
Ted Kremenek | 43ac297 | 2011-04-05 22:04:27 +0000 | [diff] [blame] | 5648 | else if (ToolChain.getArch() == llvm::Triple::ppc64) |
Chris Lattner | 09f43ed | 2011-04-11 21:15:37 +0000 | [diff] [blame] | 5649 | CmdArgs.push_back("/lib64/ld64.so.1"); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5650 | else |
| 5651 | CmdArgs.push_back("/lib64/ld-linux-x86-64.so.2"); |
| 5652 | } |
| 5653 | |
| 5654 | CmdArgs.push_back("-o"); |
| 5655 | CmdArgs.push_back(Output.getFilename()); |
| 5656 | |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5657 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5658 | !Args.hasArg(options::OPT_nostartfiles)) { |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5659 | if (!isAndroid) { |
| 5660 | const char *crt1 = NULL; |
| 5661 | if (!Args.hasArg(options::OPT_shared)){ |
| 5662 | if (Args.hasArg(options::OPT_pie)) |
| 5663 | crt1 = "Scrt1.o"; |
| 5664 | else |
| 5665 | crt1 = "crt1.o"; |
| 5666 | } |
| 5667 | if (crt1) |
| 5668 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1))); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5669 | |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5670 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); |
| 5671 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5672 | |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5673 | const char *crtbegin; |
| 5674 | if (Args.hasArg(options::OPT_static)) |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5675 | crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o"; |
Evgeniy Stepanov | a92983d | 2012-09-10 10:30:12 +0000 | [diff] [blame] | 5676 | else if (Args.hasArg(options::OPT_shared)) |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5677 | crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o"; |
Evgeniy Stepanov | a92983d | 2012-09-10 10:30:12 +0000 | [diff] [blame] | 5678 | else if (Args.hasArg(options::OPT_pie)) |
| 5679 | crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o"; |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5680 | else |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5681 | crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o"; |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5682 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); |
Benjamin Kramer | e20e508 | 2012-10-04 19:42:20 +0000 | [diff] [blame] | 5683 | |
| 5684 | // Add crtfastmath.o if available and fast math is enabled. |
| 5685 | ToolChain.AddFastMathRuntimeIfAvailable(Args, CmdArgs); |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5686 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5687 | |
| 5688 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 5689 | |
| 5690 | const ToolChain::path_list Paths = ToolChain.getFilePaths(); |
| 5691 | |
Roman Divacky | 58e5ac9 | 2011-03-01 17:53:14 +0000 | [diff] [blame] | 5692 | for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end(); |
| 5693 | i != e; ++i) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5694 | CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i)); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5695 | |
Rafael Espindola | c515154 | 2012-04-09 23:53:34 +0000 | [diff] [blame] | 5696 | // Tell the linker to load the plugin. This has to come before AddLinkerInputs |
| 5697 | // as gold requires -plugin to come before any -plugin-opt that -Wl might |
| 5698 | // forward. |
| 5699 | if (D.IsUsingLTO(Args) || Args.hasArg(options::OPT_use_gold_plugin)) { |
| 5700 | CmdArgs.push_back("-plugin"); |
| 5701 | std::string Plugin = ToolChain.getDriver().Dir + "/../lib/LLVMgold.so"; |
| 5702 | CmdArgs.push_back(Args.MakeArgString(Plugin)); |
Chandler Carruth | 700d4e4 | 2013-01-13 11:46:33 +0000 | [diff] [blame] | 5703 | |
| 5704 | // Try to pass driver level flags relevant to LTO code generation down to |
| 5705 | // the plugin. |
| 5706 | |
| 5707 | // Handle architecture-specific flags for selecting CPU variants. |
| 5708 | if (ToolChain.getArch() == llvm::Triple::x86 || |
| 5709 | ToolChain.getArch() == llvm::Triple::x86_64) |
| 5710 | CmdArgs.push_back( |
| 5711 | Args.MakeArgString(Twine("-plugin-opt=mcpu=") + |
| 5712 | getX86TargetCPU(Args, ToolChain.getTriple()))); |
| 5713 | else if (ToolChain.getArch() == llvm::Triple::arm || |
| 5714 | ToolChain.getArch() == llvm::Triple::thumb) |
| 5715 | CmdArgs.push_back( |
| 5716 | Args.MakeArgString(Twine("-plugin-opt=mcpu=") + |
| 5717 | getARMTargetCPU(Args, ToolChain.getTriple()))); |
| 5718 | |
| 5719 | // FIXME: Factor out logic for MIPS, PPC, and other targets to support this |
| 5720 | // as well. |
Rafael Espindola | c515154 | 2012-04-09 23:53:34 +0000 | [diff] [blame] | 5721 | } |
| 5722 | |
Chandler Carruth | 700d4e4 | 2013-01-13 11:46:33 +0000 | [diff] [blame] | 5723 | |
Nick Lewycky | e276cfc | 2012-08-17 03:39:16 +0000 | [diff] [blame] | 5724 | if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) |
| 5725 | CmdArgs.push_back("--no-demangle"); |
| 5726 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5727 | AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); |
| 5728 | |
Alexey Samsonov | bb1071c | 2012-11-06 15:09:03 +0000 | [diff] [blame] | 5729 | SanitizerArgs Sanitize(D, Args); |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 5730 | |
Eric Christopher | 6716d94 | 2012-11-29 18:51:05 +0000 | [diff] [blame] | 5731 | // Call these before we add the C++ ABI library. |
Richard Smith | c4dabad | 2012-11-05 22:04:41 +0000 | [diff] [blame] | 5732 | if (Sanitize.needsUbsanRt()) |
| 5733 | addUbsanRTLinux(getToolChain(), Args, CmdArgs); |
Eric Christopher | 6716d94 | 2012-11-29 18:51:05 +0000 | [diff] [blame] | 5734 | if (Sanitize.needsAsanRt()) |
| 5735 | addAsanRTLinux(getToolChain(), Args, CmdArgs); |
| 5736 | if (Sanitize.needsTsanRt()) |
| 5737 | addTsanRTLinux(getToolChain(), Args, CmdArgs); |
Evgeniy Stepanov | 09ccf39 | 2012-12-03 13:20:43 +0000 | [diff] [blame] | 5738 | if (Sanitize.needsMsanRt()) |
| 5739 | addMsanRTLinux(getToolChain(), Args, CmdArgs); |
Richard Smith | 8e1cee6 | 2012-10-25 02:14:12 +0000 | [diff] [blame] | 5740 | |
Chandler Carruth | 2ba542c | 2012-05-14 18:31:18 +0000 | [diff] [blame] | 5741 | if (D.CCCIsCXX && |
| 5742 | !Args.hasArg(options::OPT_nostdlib) && |
| 5743 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Rafael Espindola | 19706f8 | 2011-10-17 22:14:51 +0000 | [diff] [blame] | 5744 | bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && |
| 5745 | !Args.hasArg(options::OPT_static); |
| 5746 | if (OnlyLibstdcxxStatic) |
| 5747 | CmdArgs.push_back("-Bstatic"); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5748 | ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
Rafael Espindola | 19706f8 | 2011-10-17 22:14:51 +0000 | [diff] [blame] | 5749 | if (OnlyLibstdcxxStatic) |
| 5750 | CmdArgs.push_back("-Bdynamic"); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5751 | CmdArgs.push_back("-lm"); |
| 5752 | } |
| 5753 | |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5754 | if (!Args.hasArg(options::OPT_nostdlib)) { |
Chandler Carruth | 2ba542c | 2012-05-14 18:31:18 +0000 | [diff] [blame] | 5755 | if (!Args.hasArg(options::OPT_nodefaultlibs)) { |
| 5756 | if (Args.hasArg(options::OPT_static)) |
| 5757 | CmdArgs.push_back("--start-group"); |
Nick Lewycky | 80df025 | 2011-06-04 06:27:06 +0000 | [diff] [blame] | 5758 | |
Chandler Carruth | df96e02 | 2013-01-17 13:19:29 +0000 | [diff] [blame] | 5759 | bool OpenMP = Args.hasArg(options::OPT_fopenmp); |
| 5760 | if (OpenMP) { |
| 5761 | CmdArgs.push_back("-lgomp"); |
| 5762 | |
| 5763 | // FIXME: Exclude this for platforms whith libgomp that doesn't require |
| 5764 | // librt. Most modern Linux platfroms require it, but some may not. |
| 5765 | CmdArgs.push_back("-lrt"); |
| 5766 | } |
| 5767 | |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5768 | AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args); |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5769 | |
Chandler Carruth | 2ba542c | 2012-05-14 18:31:18 +0000 | [diff] [blame] | 5770 | if (Args.hasArg(options::OPT_pthread) || |
Chandler Carruth | df96e02 | 2013-01-17 13:19:29 +0000 | [diff] [blame] | 5771 | Args.hasArg(options::OPT_pthreads) || OpenMP) |
Chandler Carruth | 2ba542c | 2012-05-14 18:31:18 +0000 | [diff] [blame] | 5772 | CmdArgs.push_back("-lpthread"); |
| 5773 | |
| 5774 | CmdArgs.push_back("-lc"); |
| 5775 | |
| 5776 | if (Args.hasArg(options::OPT_static)) |
| 5777 | CmdArgs.push_back("--end-group"); |
| 5778 | else |
| 5779 | AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args); |
| 5780 | } |
Rafael Espindola | fdda171 | 2010-11-17 22:26:15 +0000 | [diff] [blame] | 5781 | |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5782 | if (!Args.hasArg(options::OPT_nostartfiles)) { |
| 5783 | const char *crtend; |
Evgeniy Stepanov | a92983d | 2012-09-10 10:30:12 +0000 | [diff] [blame] | 5784 | if (Args.hasArg(options::OPT_shared)) |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5785 | crtend = isAndroid ? "crtend_so.o" : "crtendS.o"; |
Evgeniy Stepanov | a92983d | 2012-09-10 10:30:12 +0000 | [diff] [blame] | 5786 | else if (Args.hasArg(options::OPT_pie)) |
| 5787 | crtend = isAndroid ? "crtend_android.o" : "crtendS.o"; |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5788 | else |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5789 | crtend = isAndroid ? "crtend_android.o" : "crtend.o"; |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 5790 | |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5791 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); |
Evgeniy Stepanov | a6ddc02 | 2012-04-25 08:59:22 +0000 | [diff] [blame] | 5792 | if (!isAndroid) |
| 5793 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 5794 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5795 | } |
| 5796 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 5797 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 5798 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 5799 | C.addCommand(new Command(JA, *this, ToolChain.Linker.c_str(), CmdArgs)); |
| 5800 | } |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 5801 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5802 | void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5803 | const InputInfo &Output, |
| 5804 | const InputInfoList &Inputs, |
| 5805 | const ArgList &Args, |
| 5806 | const char *LinkingOutput) const { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5807 | ArgStringList CmdArgs; |
| 5808 | |
| 5809 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 5810 | options::OPT_Xassembler); |
| 5811 | |
| 5812 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5813 | CmdArgs.push_back(Output.getFilename()); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5814 | |
| 5815 | for (InputInfoList::const_iterator |
| 5816 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5817 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5818 | CmdArgs.push_back(II.getFilename()); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | const char *Exec = |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5822 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5823 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | void minix::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5827 | const InputInfo &Output, |
| 5828 | const InputInfoList &Inputs, |
| 5829 | const ArgList &Args, |
| 5830 | const char *LinkingOutput) const { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5831 | const Driver &D = getToolChain().getDriver(); |
| 5832 | ArgStringList CmdArgs; |
| 5833 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5834 | if (Output.isFilename()) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5835 | CmdArgs.push_back("-o"); |
| 5836 | CmdArgs.push_back(Output.getFilename()); |
| 5837 | } else { |
| 5838 | assert(Output.isNothing() && "Invalid output."); |
| 5839 | } |
| 5840 | |
| 5841 | if (!Args.hasArg(options::OPT_nostdlib) && |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5842 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5843 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o"))); |
| 5844 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); |
| 5845 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); |
| 5846 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o"))); |
| 5847 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5848 | |
| 5849 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 5850 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 5851 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 5852 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 5853 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5854 | |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5855 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
| 5856 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5857 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5858 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 5859 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 5860 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5861 | CmdArgs.push_back("-lm"); |
| 5862 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5866 | !Args.hasArg(options::OPT_nostartfiles)) { |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5867 | if (Args.hasArg(options::OPT_pthread)) |
| 5868 | CmdArgs.push_back("-lpthread"); |
| 5869 | CmdArgs.push_back("-lc"); |
| 5870 | CmdArgs.push_back("-lCompilerRT-Generic"); |
| 5871 | CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib"); |
| 5872 | CmdArgs.push_back( |
Eric Christopher | 27e2b98 | 2012-12-18 00:31:10 +0000 | [diff] [blame] | 5873 | Args.MakeArgString(getToolChain().GetFilePath("crtend.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5874 | } |
| 5875 | |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 5876 | const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5877 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5878 | } |
| 5879 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5880 | /// DragonFly Tools |
| 5881 | |
| 5882 | // For now, DragonFly Assemble does just about the same as for |
| 5883 | // FreeBSD, but this may change soon. |
| 5884 | void dragonfly::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5885 | const InputInfo &Output, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 5886 | const InputInfoList &Inputs, |
| 5887 | const ArgList &Args, |
| 5888 | const char *LinkingOutput) const { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5889 | ArgStringList CmdArgs; |
| 5890 | |
| 5891 | // When building 32-bit code on DragonFly/pc64, we have to explicitly |
| 5892 | // instruct as in the base system to assemble 32-bit code. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5893 | if (getToolChain().getArch() == llvm::Triple::x86) |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5894 | CmdArgs.push_back("--32"); |
| 5895 | |
| 5896 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 5897 | options::OPT_Xassembler); |
| 5898 | |
| 5899 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5900 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5901 | |
| 5902 | for (InputInfoList::const_iterator |
| 5903 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 5904 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5905 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5909 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5910 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 5914 | const InputInfo &Output, |
| 5915 | const InputInfoList &Inputs, |
| 5916 | const ArgList &Args, |
| 5917 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 5918 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5919 | ArgStringList CmdArgs; |
| 5920 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 5921 | if (!D.SysRoot.empty()) |
| 5922 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 5923 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5924 | if (Args.hasArg(options::OPT_static)) { |
| 5925 | CmdArgs.push_back("-Bstatic"); |
| 5926 | } else { |
| 5927 | if (Args.hasArg(options::OPT_shared)) |
| 5928 | CmdArgs.push_back("-Bshareable"); |
| 5929 | else { |
| 5930 | CmdArgs.push_back("-dynamic-linker"); |
| 5931 | CmdArgs.push_back("/usr/libexec/ld-elf.so.2"); |
| 5932 | } |
| 5933 | } |
| 5934 | |
| 5935 | // When building 32-bit code on DragonFly/pc64, we have to explicitly |
| 5936 | // instruct ld in the base system to link 32-bit code. |
Rafael Espindola | 64f7ad9 | 2012-10-07 04:44:33 +0000 | [diff] [blame] | 5937 | if (getToolChain().getArch() == llvm::Triple::x86) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5938 | CmdArgs.push_back("-m"); |
| 5939 | CmdArgs.push_back("elf_i386"); |
| 5940 | } |
| 5941 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 5942 | if (Output.isFilename()) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5943 | CmdArgs.push_back("-o"); |
| 5944 | CmdArgs.push_back(Output.getFilename()); |
| 5945 | } else { |
| 5946 | assert(Output.isNothing() && "Invalid output."); |
| 5947 | } |
| 5948 | |
| 5949 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5950 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 5951 | if (!Args.hasArg(options::OPT_shared)) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5952 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5953 | Args.MakeArgString(getToolChain().GetFilePath("crt1.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5954 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5955 | Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5956 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5957 | Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5958 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5959 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5960 | Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 5961 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 5962 | Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5963 | } |
| 5964 | } |
| 5965 | |
| 5966 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 5967 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 5968 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 5969 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 5970 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5971 | |
| 5972 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 5973 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 5974 | // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of |
| 5975 | // rpaths |
| 5976 | CmdArgs.push_back("-L/usr/lib/gcc41"); |
| 5977 | |
| 5978 | if (!Args.hasArg(options::OPT_static)) { |
| 5979 | CmdArgs.push_back("-rpath"); |
| 5980 | CmdArgs.push_back("/usr/lib/gcc41"); |
| 5981 | |
| 5982 | CmdArgs.push_back("-rpath-link"); |
| 5983 | CmdArgs.push_back("/usr/lib/gcc41"); |
| 5984 | |
| 5985 | CmdArgs.push_back("-rpath"); |
| 5986 | CmdArgs.push_back("/usr/lib"); |
| 5987 | |
| 5988 | CmdArgs.push_back("-rpath-link"); |
| 5989 | CmdArgs.push_back("/usr/lib"); |
| 5990 | } |
| 5991 | |
Rafael Espindola | 405861d | 2010-07-20 12:59:03 +0000 | [diff] [blame] | 5992 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 5993 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Rafael Espindola | 405861d | 2010-07-20 12:59:03 +0000 | [diff] [blame] | 5994 | CmdArgs.push_back("-lm"); |
| 5995 | } |
| 5996 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 5997 | if (Args.hasArg(options::OPT_shared)) { |
| 5998 | CmdArgs.push_back("-lgcc_pic"); |
| 5999 | } else { |
| 6000 | CmdArgs.push_back("-lgcc"); |
| 6001 | } |
| 6002 | |
| 6003 | |
| 6004 | if (Args.hasArg(options::OPT_pthread)) |
Mike Stump | 4d63f8b | 2009-10-31 20:11:46 +0000 | [diff] [blame] | 6005 | CmdArgs.push_back("-lpthread"); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 6006 | |
| 6007 | if (!Args.hasArg(options::OPT_nolibc)) { |
| 6008 | CmdArgs.push_back("-lc"); |
| 6009 | } |
| 6010 | |
| 6011 | if (Args.hasArg(options::OPT_shared)) { |
| 6012 | CmdArgs.push_back("-lgcc_pic"); |
| 6013 | } else { |
| 6014 | CmdArgs.push_back("-lgcc"); |
| 6015 | } |
| 6016 | } |
| 6017 | |
| 6018 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 6019 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 6020 | if (!Args.hasArg(options::OPT_shared)) |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 6021 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 6022 | getToolChain().GetFilePath("crtend.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 6023 | else |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 6024 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 6025 | getToolChain().GetFilePath("crtendS.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 6026 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 6027 | getToolChain().GetFilePath("crtn.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 6028 | } |
| 6029 | |
Bill Wendling | 3f4be6f | 2011-06-27 19:15:03 +0000 | [diff] [blame] | 6030 | addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple()); |
Nick Lewycky | 2e95a6d | 2011-05-24 21:54:59 +0000 | [diff] [blame] | 6031 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 6032 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 6033 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 6034 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 6035 | } |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 6036 | |
| 6037 | void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 6038 | const InputInfo &Output, |
| 6039 | const InputInfoList &Inputs, |
| 6040 | const ArgList &Args, |
| 6041 | const char *LinkingOutput) const { |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 6042 | ArgStringList CmdArgs; |
| 6043 | |
| 6044 | if (Output.isFilename()) { |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 6045 | CmdArgs.push_back(Args.MakeArgString(std::string("-out:") + |
| 6046 | Output.getFilename())); |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 6047 | } else { |
| 6048 | assert(Output.isNothing() && "Invalid output."); |
| 6049 | } |
| 6050 | |
| 6051 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 6052 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 6053 | CmdArgs.push_back("-defaultlib:libcmt"); |
| 6054 | } |
| 6055 | |
| 6056 | CmdArgs.push_back("-nologo"); |
| 6057 | |
Michael J. Spencer | a2284f5 | 2012-06-18 16:56:04 +0000 | [diff] [blame] | 6058 | Args.AddAllArgValues(CmdArgs, options::OPT_l); |
| 6059 | |
| 6060 | // Add filenames immediately. |
| 6061 | for (InputInfoList::const_iterator |
| 6062 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 6063 | if (it->isFilename()) |
| 6064 | CmdArgs.push_back(it->getFilename()); |
| 6065 | } |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 6066 | |
| 6067 | const char *Exec = |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 6068 | Args.MakeArgString(getToolChain().GetProgramPath("link.exe")); |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 6069 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 6070 | } |