Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1 | //===--- Tools.cpp - Tools Implementations ------------------------------*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "Tools.h" |
| 11 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Arg.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 14 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Driver.h" // FIXME: Remove? |
| 16 | #include "clang/Driver/DriverDiagnostic.h" // FIXME: Remove? |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Compilation.h" |
| 18 | #include "clang/Driver/Job.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 19 | #include "clang/Driver/HostInfo.h" |
| 20 | #include "clang/Driver/Option.h" |
| 21 | #include "clang/Driver/ToolChain.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 22 | #include "clang/Driver/Util.h" |
| 23 | |
| 24 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Format.h" |
| 26 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 27 | |
| 28 | #include "InputInfo.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 29 | #include "ToolChains.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 30 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 31 | using namespace clang::driver; |
| 32 | using namespace clang::driver::tools; |
| 33 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 34 | void Clang::AddPreprocessingOptions(const Driver &D, |
| 35 | const ArgList &Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 36 | ArgStringList &CmdArgs, |
| 37 | const InputInfo &Output, |
| 38 | const InputInfoList &Inputs) const { |
| 39 | // Handle dependency file generation. |
| 40 | Arg *A; |
| 41 | if ((A = Args.getLastArg(options::OPT_M)) || |
| 42 | (A = Args.getLastArg(options::OPT_MM)) || |
| 43 | (A = Args.getLastArg(options::OPT_MD)) || |
| 44 | (A = Args.getLastArg(options::OPT_MMD))) { |
| 45 | // Determine the output location. |
| 46 | const char *DepFile; |
| 47 | if (Output.getType() == types::TY_Dependencies) { |
| 48 | if (Output.isPipe()) |
| 49 | DepFile = "-"; |
| 50 | else |
| 51 | DepFile = Output.getFilename(); |
| 52 | } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) { |
| 53 | DepFile = MF->getValue(Args); |
| 54 | } else if (A->getOption().getId() == options::OPT_M || |
| 55 | A->getOption().getId() == options::OPT_MM) { |
| 56 | DepFile = "-"; |
| 57 | } else { |
| 58 | DepFile = darwin::CC1::getDependencyFileName(Args, Inputs); |
| 59 | } |
| 60 | CmdArgs.push_back("-dependency-file"); |
| 61 | CmdArgs.push_back(DepFile); |
| 62 | |
| 63 | // Add an -MT option if the user didn't specify their own. |
| 64 | // FIXME: This should use -MQ, when we support it. |
| 65 | if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) { |
| 66 | const char *DepTarget; |
| 67 | |
| 68 | // If user provided -o, that is the dependency target, except |
| 69 | // when we are only generating a dependency file. |
| 70 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 71 | if (OutputOpt && Output.getType() != types::TY_Dependencies) { |
| 72 | DepTarget = OutputOpt->getValue(Args); |
| 73 | } else { |
| 74 | // Otherwise derive from the base input. |
| 75 | // |
| 76 | // FIXME: This should use the computed output file location. |
| 77 | llvm::sys::Path P(Inputs[0].getBaseInput()); |
| 78 | |
| 79 | P.eraseSuffix(); |
| 80 | P.appendSuffix("o"); |
| 81 | DepTarget = Args.MakeArgString(P.getLast().c_str()); |
| 82 | } |
| 83 | |
| 84 | CmdArgs.push_back("-MT"); |
| 85 | CmdArgs.push_back(DepTarget); |
| 86 | } |
| 87 | |
| 88 | if (A->getOption().getId() == options::OPT_M || |
| 89 | A->getOption().getId() == options::OPT_MD) |
| 90 | CmdArgs.push_back("-sys-header-deps"); |
| 91 | } |
| 92 | |
| 93 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
| 94 | Args.AddAllArgs(CmdArgs, options::OPT_MT); |
| 95 | |
| 96 | // FIXME: Use iterator. |
| 97 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 98 | // Add -i* options, and automatically translate to |
| 99 | // -include-pch/-include-pth for transparent PCH support. It's |
| 100 | // wonky, but we include looking for .gch so we can support seamless |
| 101 | // replacement into a build system already set up to be generating |
| 102 | // .gch files. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 103 | for (ArgList::const_iterator |
| 104 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 105 | const Arg *A = *it; |
| 106 | if (!A->getOption().matches(options::OPT_clang_i_Group)) |
| 107 | continue; |
| 108 | |
| 109 | if (A->getOption().matches(options::OPT_include)) { |
| 110 | bool FoundPTH = false; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 111 | bool FoundPCH = false; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 112 | llvm::sys::Path P(A->getValue(Args)); |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 113 | if (D.CCCUsePCH) { |
| 114 | P.appendSuffix("pch"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 115 | if (P.exists()) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 116 | FoundPCH = true; |
| 117 | else |
| 118 | P.eraseSuffix(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 121 | if (!FoundPCH) { |
| 122 | P.appendSuffix("pth"); |
| 123 | if (P.exists()) |
| 124 | FoundPTH = true; |
| 125 | else |
| 126 | P.eraseSuffix(); |
| 127 | } |
| 128 | |
| 129 | if (!FoundPCH && !FoundPTH) { |
| 130 | P.appendSuffix("gch"); |
| 131 | if (P.exists()) { |
| 132 | FoundPCH = D.CCCUsePCH; |
| 133 | FoundPTH = !D.CCCUsePCH; |
| 134 | } |
| 135 | else |
| 136 | P.eraseSuffix(); |
| 137 | } |
| 138 | |
| 139 | if (FoundPCH || FoundPTH) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 140 | A->claim(); |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 141 | if (FoundPCH) |
| 142 | CmdArgs.push_back("-include-pch"); |
| 143 | else |
| 144 | CmdArgs.push_back("-include-pth"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 145 | CmdArgs.push_back(Args.MakeArgString(P.c_str())); |
| 146 | continue; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Not translated, render as usual. |
| 151 | A->claim(); |
| 152 | A->render(Args, CmdArgs); |
| 153 | } |
| 154 | |
| 155 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); |
| 156 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 157 | |
| 158 | // Add -Wp, and -Xassembler if using the preprocessor. |
| 159 | |
| 160 | // FIXME: There is a very unfortunate problem here, some troubled |
| 161 | // souls abuse -Wp, to pass preprocessor options in gcc syntax. To |
| 162 | // really support that we would have to parse and then translate |
| 163 | // those options. :( |
| 164 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 165 | options::OPT_Xpreprocessor); |
| 166 | } |
| 167 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 168 | void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 169 | Job &Dest, |
| 170 | const InputInfo &Output, |
Daniel Dunbar | 62cf601 | 2009-03-18 06:07:59 +0000 | [diff] [blame] | 171 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 172 | const ArgList &Args, |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 173 | const char *LinkingOutput) const { |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 174 | const Driver &D = getToolChain().getHost().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 175 | ArgStringList CmdArgs; |
| 176 | |
Daniel Dunbar | 077ba6a | 2009-03-31 20:53:55 +0000 | [diff] [blame] | 177 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 178 | |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 179 | CmdArgs.push_back("-triple"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 180 | const char *TripleStr = |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 181 | Args.MakeArgString(getToolChain().getTripleString().c_str()); |
| 182 | CmdArgs.push_back(TripleStr); |
| 183 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 184 | if (isa<AnalyzeJobAction>(JA)) { |
| 185 | assert(JA.getType() == types::TY_Plist && "Invalid output type."); |
| 186 | CmdArgs.push_back("-analyze"); |
| 187 | } else if (isa<PreprocessJobAction>(JA)) { |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 188 | if (Output.getType() == types::TY_Dependencies) |
| 189 | CmdArgs.push_back("-Eonly"); |
| 190 | else |
| 191 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 192 | } else if (isa<PrecompileJobAction>(JA)) { |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 193 | if (D.CCCUsePCH) |
| 194 | CmdArgs.push_back("-emit-pch"); |
| 195 | else |
| 196 | CmdArgs.push_back("-emit-pth"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 197 | } else { |
| 198 | assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool."); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 199 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 200 | if (JA.getType() == types::TY_Nothing) { |
| 201 | CmdArgs.push_back("-fsyntax-only"); |
| 202 | } else if (JA.getType() == types::TY_LLVMAsm) { |
| 203 | CmdArgs.push_back("-emit-llvm"); |
| 204 | } else if (JA.getType() == types::TY_LLVMBC) { |
| 205 | CmdArgs.push_back("-emit-llvm-bc"); |
| 206 | } else if (JA.getType() == types::TY_PP_Asm) { |
| 207 | CmdArgs.push_back("-S"); |
| 208 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 211 | // The make clang go fast button. |
| 212 | CmdArgs.push_back("-disable-free"); |
| 213 | |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 214 | // Set the main file name, so that debug info works even with |
| 215 | // -save-temps. |
| 216 | CmdArgs.push_back("-main-file-name"); |
| 217 | CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs)); |
| 218 | |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 219 | // Some flags which affect the language (via preprocessor |
| 220 | // defines). See darwin::CC1::AddCPPArgs. |
| 221 | if (Args.hasArg(options::OPT_static)) |
| 222 | CmdArgs.push_back("-static-define"); |
| 223 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 224 | if (isa<AnalyzeJobAction>(JA)) { |
| 225 | // Add default argument set. |
| 226 | // |
| 227 | // FIXME: Move into clang? |
| 228 | CmdArgs.push_back("-warn-dead-stores"); |
| 229 | CmdArgs.push_back("-checker-cfref"); |
Ted Kremenek | 9b646da | 2009-03-25 00:38:14 +0000 | [diff] [blame] | 230 | CmdArgs.push_back("-analyzer-eagerly-assume"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 231 | CmdArgs.push_back("-warn-objc-methodsigs"); |
| 232 | // Do not enable the missing -dealloc check. |
| 233 | // '-warn-objc-missing-dealloc', |
| 234 | CmdArgs.push_back("-warn-objc-unused-ivars"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 235 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 236 | CmdArgs.push_back("-analyzer-output=plist"); |
| 237 | |
| 238 | // Add -Xanalyzer arguments when running as analyzer. |
| 239 | Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer); |
| 240 | } else { |
| 241 | // Perform argument translation for LLVM backend. This |
| 242 | // takes some care in reconciling with llvm-gcc. The |
| 243 | // issue is that llvm-gcc translates these options based on |
| 244 | // the values in cc1, whereas we are processing based on |
| 245 | // the driver arguments. |
| 246 | // |
| 247 | // FIXME: This is currently broken for -f flags when -fno |
| 248 | // variants are present. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 249 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 250 | // This comes from the default translation the driver + cc1 |
| 251 | // would do to enable flag_pic. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 252 | // |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 253 | // FIXME: Centralize this code. |
| 254 | bool PICEnabled = (Args.hasArg(options::OPT_fPIC) || |
| 255 | Args.hasArg(options::OPT_fpic) || |
| 256 | Args.hasArg(options::OPT_fPIE) || |
| 257 | Args.hasArg(options::OPT_fpie)); |
| 258 | bool PICDisabled = (Args.hasArg(options::OPT_mkernel) || |
| 259 | Args.hasArg(options::OPT_static)); |
| 260 | const char *Model = getToolChain().GetForcedPicModel(); |
| 261 | if (!Model) { |
| 262 | if (Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 263 | Model = "dynamic-no-pic"; |
| 264 | else if (PICDisabled) |
| 265 | Model = "static"; |
| 266 | else if (PICEnabled) |
| 267 | Model = "pic"; |
| 268 | else |
| 269 | Model = getToolChain().GetDefaultRelocationModel(); |
| 270 | } |
| 271 | CmdArgs.push_back("--relocation-model"); |
| 272 | CmdArgs.push_back(Model); |
| 273 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 274 | // Infer the __PIC__ value. |
Daniel Dunbar | 9fd0b1f | 2009-04-08 03:03:23 +0000 | [diff] [blame] | 275 | // |
| 276 | // FIXME: This isn't quite right on Darwin, which always sets |
| 277 | // __PIC__=2. |
| 278 | if (strcmp(Model, "pic") == 0 || strcmp(Model, "dynamic-no-pic") == 0) { |
| 279 | if (Args.hasArg(options::OPT_fPIC)) |
| 280 | CmdArgs.push_back("-pic-level=2"); |
| 281 | else |
| 282 | CmdArgs.push_back("-pic-level=1"); |
| 283 | } |
| 284 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 285 | if (Args.hasArg(options::OPT_ftime_report)) |
| 286 | CmdArgs.push_back("--time-passes"); |
| 287 | // FIXME: Set --enable-unsafe-fp-math. |
| 288 | if (!Args.hasArg(options::OPT_fomit_frame_pointer)) |
| 289 | CmdArgs.push_back("--disable-fp-elim"); |
| 290 | if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, |
| 291 | options::OPT_fno_zero_initialized_in_bss, |
| 292 | true)) |
| 293 | CmdArgs.push_back("--nozero-initialized-in-bss"); |
Daniel Dunbar | b3fd500 | 2009-03-24 17:59:06 +0000 | [diff] [blame] | 294 | if (Args.hasArg(options::OPT_dA) || Args.hasArg(options::OPT_fverbose_asm)) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 295 | CmdArgs.push_back("--asm-verbose"); |
| 296 | if (Args.hasArg(options::OPT_fdebug_pass_structure)) |
| 297 | CmdArgs.push_back("--debug-pass=Structure"); |
| 298 | if (Args.hasArg(options::OPT_fdebug_pass_arguments)) |
| 299 | CmdArgs.push_back("--debug-pass=Arguments"); |
| 300 | // FIXME: set --inline-threshhold=50 if (optimize_size || optimize |
| 301 | // < 3) |
| 302 | if (Args.hasFlag(options::OPT_funwind_tables, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 303 | options::OPT_fno_unwind_tables, |
| 304 | getToolChain().IsUnwindTablesDefault())) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 305 | CmdArgs.push_back("--unwind-tables=1"); |
| 306 | else |
| 307 | CmdArgs.push_back("--unwind-tables=0"); |
| 308 | if (!Args.hasFlag(options::OPT_mred_zone, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 309 | options::OPT_mno_red_zone, |
| 310 | true)) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 311 | CmdArgs.push_back("--disable-red-zone"); |
| 312 | if (Args.hasFlag(options::OPT_msoft_float, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 313 | options::OPT_mno_soft_float, |
| 314 | false)) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 315 | CmdArgs.push_back("--soft-float"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 316 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 317 | // FIXME: Need target hooks. |
| 318 | if (memcmp(getToolChain().getPlatform().c_str(), "darwin", 6) == 0) { |
| 319 | if (getToolChain().getArchName() == "x86_64") |
| 320 | CmdArgs.push_back("--mcpu=core2"); |
| 321 | else if (getToolChain().getArchName() == "i386") |
| 322 | CmdArgs.push_back("--mcpu=yonah"); |
| 323 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 324 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 325 | // FIXME: Ignores ordering. Also, we need to find a realistic |
| 326 | // solution for this. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 327 | static const struct { |
| 328 | options::ID Pos, Neg; |
| 329 | const char *Name; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 330 | } FeatureOptions[] = { |
| 331 | { options::OPT_mmmx, options::OPT_mno_mmx, "mmx" }, |
| 332 | { options::OPT_msse, options::OPT_mno_sse, "sse" }, |
| 333 | { options::OPT_msse2, options::OPT_mno_sse2, "sse2" }, |
| 334 | { options::OPT_msse3, options::OPT_mno_sse3, "sse3" }, |
| 335 | { options::OPT_mssse3, options::OPT_mno_ssse3, "ssse3" }, |
| 336 | { options::OPT_msse41, options::OPT_mno_sse41, "sse41" }, |
| 337 | { options::OPT_msse42, options::OPT_mno_sse42, "sse42" }, |
| 338 | { options::OPT_msse4a, options::OPT_mno_sse4a, "sse4a" }, |
| 339 | { options::OPT_m3dnow, options::OPT_mno_3dnow, "3dnow" }, |
| 340 | { options::OPT_m3dnowa, options::OPT_mno_3dnowa, "3dnowa" } |
| 341 | }; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 342 | const unsigned NumFeatureOptions = |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 343 | sizeof(FeatureOptions)/sizeof(FeatureOptions[0]); |
| 344 | |
| 345 | // FIXME: Avoid std::string |
| 346 | std::string Attrs; |
| 347 | for (unsigned i=0; i < NumFeatureOptions; ++i) { |
| 348 | if (Args.hasArg(FeatureOptions[i].Pos)) { |
Daniel Dunbar | 55b3b5f | 2009-03-19 17:36:04 +0000 | [diff] [blame] | 349 | if (!Attrs.empty()) |
| 350 | Attrs += ','; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 351 | Attrs += '+'; |
| 352 | Attrs += FeatureOptions[i].Name; |
| 353 | } else if (Args.hasArg(FeatureOptions[i].Neg)) { |
Daniel Dunbar | 55b3b5f | 2009-03-19 17:36:04 +0000 | [diff] [blame] | 354 | if (!Attrs.empty()) |
| 355 | Attrs += ','; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 356 | Attrs += '-'; |
| 357 | Attrs += FeatureOptions[i].Name; |
| 358 | } |
| 359 | } |
| 360 | if (!Attrs.empty()) { |
| 361 | CmdArgs.push_back("--mattr"); |
| 362 | CmdArgs.push_back(Args.MakeArgString(Attrs.c_str())); |
| 363 | } |
| 364 | |
| 365 | if (Args.hasFlag(options::OPT_fmath_errno, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 366 | options::OPT_fno_math_errno, |
| 367 | getToolChain().IsMathErrnoDefault())) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 368 | CmdArgs.push_back("--fmath-errno=1"); |
| 369 | else |
| 370 | CmdArgs.push_back("--fmath-errno=0"); |
| 371 | |
| 372 | if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { |
| 373 | CmdArgs.push_back("--limit-float-precision"); |
| 374 | CmdArgs.push_back(A->getValue(Args)); |
| 375 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 376 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 377 | // FIXME: Add --stack-protector-buffer-size=<xxx> on |
| 378 | // -fstack-protect. |
| 379 | |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 380 | Arg *Unsupported; |
| 381 | if ((Unsupported = Args.getLastArg(options::OPT_MG)) || |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 382 | (Unsupported = Args.getLastArg(options::OPT_MQ))) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 383 | D.Diag(clang::diag::err_drv_unsupported_opt) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 384 | << Unsupported->getOption().getName(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | Args.AddAllArgs(CmdArgs, options::OPT_v); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 388 | Args.AddLastArg(CmdArgs, options::OPT_P); |
Daniel Dunbar | 2ac9fc2 | 2009-04-07 21:42:00 +0000 | [diff] [blame] | 389 | Args.AddLastArg(CmdArgs, options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 390 | Args.AddLastArg(CmdArgs, options::OPT_miphoneos_version_min_EQ); |
Fariborz Jahanian | 448f5e6 | 2009-04-17 03:04:15 +0000 | [diff] [blame] | 391 | Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 392 | |
| 393 | // Special case debug options to only pass -g to clang. This is |
| 394 | // wrong. |
| 395 | if (Args.hasArg(options::OPT_g_Group)) |
| 396 | CmdArgs.push_back("-g"); |
| 397 | |
| 398 | Args.AddLastArg(CmdArgs, options::OPT_nostdinc); |
| 399 | |
Daniel Dunbar | 2ac9fc2 | 2009-04-07 21:42:00 +0000 | [diff] [blame] | 400 | Args.AddLastArg(CmdArgs, options::OPT_isysroot); |
| 401 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 402 | // Add preprocessing options like -I, -D, etc. if we are using the |
| 403 | // preprocessor. |
| 404 | // |
| 405 | // FIXME: Support -fpreprocessed |
| 406 | types::ID InputType = Inputs[0].getType(); |
| 407 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 408 | AddPreprocessingOptions(D, Args, CmdArgs, Output, Inputs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 409 | |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 410 | // Manually translate -O to -O1 and -O4 to -O3; let clang reject |
| 411 | // others. |
| 412 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 413 | if (A->getOption().getId() == options::OPT_O4) |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 414 | CmdArgs.push_back("-O3"); |
| 415 | else if (A->getValue(Args)[0] == '\0') |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 416 | CmdArgs.push_back("-O1"); |
| 417 | else |
Daniel Dunbar | 5697aa0 | 2009-03-18 23:39:35 +0000 | [diff] [blame] | 418 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Daniel Dunbar | 06ef3c3 | 2009-04-16 03:44:10 +0000 | [diff] [blame] | 421 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 422 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 423 | |
| 424 | // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi} |
| 425 | // (-ansi is equivalent to -std=c89). |
| 426 | // |
| 427 | // If a std is supplied, only add -trigraphs if it follows the |
| 428 | // option. |
| 429 | if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 430 | if (Std->getOption().matches(options::OPT_ansi)) |
| 431 | CmdArgs.push_back("-std=c89"); |
| 432 | else |
| 433 | Std->render(Args, CmdArgs); |
| 434 | |
| 435 | if (Arg *A = Args.getLastArg(options::OPT_trigraphs)) |
| 436 | if (A->getIndex() > Std->getIndex()) |
| 437 | A->render(Args, CmdArgs); |
| 438 | } else |
| 439 | Args.AddLastArg(CmdArgs, options::OPT_trigraphs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 440 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 441 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) { |
| 442 | CmdArgs.push_back("-ftemplate-depth"); |
| 443 | CmdArgs.push_back(A->getValue(Args)); |
| 444 | } |
| 445 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 446 | // Forward -f options which we can pass directly. |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 447 | Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); |
| 448 | Args.AddLastArg(CmdArgs, options::OPT_fexceptions); |
| 449 | Args.AddLastArg(CmdArgs, options::OPT_ffreestanding); |
| 450 | Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); |
| 451 | Args.AddLastArg(CmdArgs, options::OPT_fgnu_runtime); |
| 452 | Args.AddLastArg(CmdArgs, options::OPT_flax_vector_conversions); |
| 453 | Args.AddLastArg(CmdArgs, options::OPT_fms_extensions); |
| 454 | Args.AddLastArg(CmdArgs, options::OPT_fnext_runtime); |
| 455 | Args.AddLastArg(CmdArgs, options::OPT_fno_caret_diagnostics); |
| 456 | Args.AddLastArg(CmdArgs, options::OPT_fno_show_column); |
| 457 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc_only); |
| 458 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc); |
| 459 | // FIXME: Should we remove this? |
| 460 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_nonfragile_abi); |
| 461 | Args.AddLastArg(CmdArgs, options::OPT_fprint_source_range_info); |
| 462 | Args.AddLastArg(CmdArgs, options::OPT_ftime_report); |
| 463 | Args.AddLastArg(CmdArgs, options::OPT_ftrapv); |
| 464 | Args.AddLastArg(CmdArgs, options::OPT_fvisibility_EQ); |
| 465 | Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 466 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 467 | // Forward -f options with positive and negative forms; we translate |
| 468 | // these by hand. |
| 469 | |
| 470 | // -fbuiltin is default, only pass non-default. |
| 471 | if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin)) |
| 472 | CmdArgs.push_back("-fbuiltin=0"); |
| 473 | |
| 474 | // -fblocks default varies depending on platform and language; |
| 475 | // -always pass if specified. |
| 476 | if (Arg *A = Args.getLastArg(options::OPT_fblocks, options::OPT_fno_blocks)) { |
| 477 | if (A->getOption().matches(options::OPT_fblocks)) |
| 478 | CmdArgs.push_back("-fblocks"); |
| 479 | else |
| 480 | CmdArgs.push_back("-fblocks=0"); |
| 481 | } |
| 482 | |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 483 | // -fno-pascal-strings is default, only pass non-default. If the |
| 484 | // -tool chain happened to translate to -mpascal-strings, we want to |
| 485 | // -back translate here. |
| 486 | // |
| 487 | // FIXME: This is gross; that translation should be pulled from the |
| 488 | // tool chain. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 489 | if (Args.hasFlag(options::OPT_fpascal_strings, |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 490 | options::OPT_fno_pascal_strings, |
| 491 | false) || |
| 492 | Args.hasFlag(options::OPT_mpascal_strings, |
| 493 | options::OPT_mno_pascal_strings, |
| 494 | false)) |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 495 | CmdArgs.push_back("-fpascal-strings"); |
| 496 | |
| 497 | // -fcommon is default, only pass non-default. |
| 498 | if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common)) |
| 499 | CmdArgs.push_back("-fno-common"); |
| 500 | |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 501 | // -fsigned-bitfields is default, and clang doesn't yet support |
| 502 | // --funsigned-bitfields. |
| 503 | if (!Args.hasFlag(options::OPT_fsigned_bitfields, |
| 504 | options::OPT_funsigned_bitfields)) |
| 505 | D.Diag(clang::diag::warn_drv_clang_unsupported) |
| 506 | << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args); |
| 507 | |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 508 | // Enable -fdiagnostics-show-option by default. |
| 509 | if (Args.hasFlag(options::OPT_fdiagnostics_show_option, |
| 510 | options::OPT_fno_diagnostics_show_option)) |
| 511 | CmdArgs.push_back("-fdiagnostics-show-option"); |
| 512 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 513 | Args.AddLastArg(CmdArgs, options::OPT_dM); |
Chris Lattner | d82df3a | 2009-04-12 01:56:53 +0000 | [diff] [blame] | 514 | Args.AddLastArg(CmdArgs, options::OPT_dD); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 515 | |
| 516 | Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); |
| 517 | |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 518 | if (Output.getType() == types::TY_Dependencies) { |
| 519 | // Handled with other dependency code. |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 520 | } else if (Output.isPipe()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 521 | CmdArgs.push_back("-o"); |
| 522 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 523 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 524 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 525 | CmdArgs.push_back(Output.getFilename()); |
| 526 | } else { |
| 527 | assert(Output.isNothing() && "Invalid output."); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 530 | for (InputInfoList::const_iterator |
| 531 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 532 | const InputInfo &II = *it; |
| 533 | CmdArgs.push_back("-x"); |
| 534 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 535 | if (II.isPipe()) |
| 536 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 537 | else if (II.isFilename()) |
| 538 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 539 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 540 | II.getInputArg().renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 541 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 542 | |
| 543 | const char *Exec = |
Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 544 | Args.MakeArgString(getToolChain().GetProgramPath(C, "clang-cc").c_str()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 545 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 546 | |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 547 | // Explicitly warn that these options are unsupported, even though |
| 548 | // we are allowing compilation to continue. |
| 549 | // FIXME: Use iterator. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 550 | for (ArgList::const_iterator |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 551 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 552 | const Arg *A = *it; |
| 553 | if (A->getOption().matches(options::OPT_pg)) { |
| 554 | A->claim(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 555 | D.Diag(clang::diag::warn_drv_clang_unsupported) |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 556 | << A->getAsString(Args); |
| 557 | } |
| 558 | } |
| 559 | |
Daniel Dunbar | 68fb469 | 2009-04-03 20:51:31 +0000 | [diff] [blame] | 560 | // Claim some arguments which clang supports automatically. |
| 561 | |
| 562 | // -fpch-preprocess is used with gcc to add a special marker in the |
| 563 | // -output to include the PCH file. Clang's PTH solution is |
| 564 | // -completely transparent, so we do not need to deal with it at |
| 565 | // -all. |
| 566 | Args.ClaimAllArgs(options::OPT_fpch_preprocess); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 567 | |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 568 | // Claim some arguments which clang doesn't support, but we don't |
| 569 | // care to warn the user about. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 570 | |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 571 | // FIXME: Use iterator. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 572 | for (ArgList::const_iterator |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 573 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 574 | const Arg *A = *it; |
Daniel Dunbar | 06ef3c3 | 2009-04-16 03:44:10 +0000 | [diff] [blame] | 575 | if (A->getOption().matches(options::OPT_clang_ignored_f_Group) || |
Daniel Dunbar | 16fd3a9 | 2009-04-07 02:59:27 +0000 | [diff] [blame] | 576 | A->getOption().matches(options::OPT_clang_ignored_m_Group)) |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 577 | A->claim(); |
| 578 | } |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 581 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
| 582 | Job &Dest, |
| 583 | const InputInfo &Output, |
| 584 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 585 | const ArgList &Args, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 586 | const char *LinkingOutput) const { |
| 587 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 588 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 589 | for (ArgList::const_iterator |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 590 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 591 | Arg *A = *it; |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 592 | if (A->getOption().hasForwardToGCC()) { |
| 593 | // It is unfortunate that we have to claim here, as this means |
| 594 | // we will basically never report anything interesting for |
| 595 | // platforms using a generic gcc. |
| 596 | A->claim(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 597 | A->render(Args, CmdArgs); |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 598 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 599 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 600 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 601 | RenderExtraToolArgs(CmdArgs); |
| 602 | |
| 603 | // If using a driver driver, force the arch. |
| 604 | if (getToolChain().getHost().useDriverDriver()) { |
| 605 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | bf54a06 | 2009-04-01 20:33:11 +0000 | [diff] [blame] | 606 | |
| 607 | // FIXME: Remove these special cases. |
| 608 | const char *Str = getToolChain().getArchName().c_str(); |
| 609 | if (strcmp(Str, "powerpc") == 0) |
| 610 | Str = "ppc"; |
| 611 | else if (strcmp(Str, "powerpc64") == 0) |
| 612 | Str = "ppc64"; |
| 613 | CmdArgs.push_back(Str); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | if (Output.isPipe()) { |
| 617 | CmdArgs.push_back("-o"); |
| 618 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 619 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 620 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 621 | CmdArgs.push_back(Output.getFilename()); |
| 622 | } else { |
| 623 | assert(Output.isNothing() && "Unexpected output"); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 624 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 625 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 626 | |
| 627 | |
| 628 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 629 | // understands the suffix correctly. The main use case this would go |
| 630 | // wrong in is for linker inputs if they happened to have an odd |
| 631 | // suffix; really the only way to get this to happen is a command |
| 632 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 633 | // |
| 634 | // FIXME: For the linker case specifically, can we safely convert |
| 635 | // inputs into '-Wl,' options? |
| 636 | for (InputInfoList::const_iterator |
| 637 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 638 | const InputInfo &II = *it; |
| 639 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 640 | CmdArgs.push_back("-x"); |
| 641 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 642 | } |
| 643 | |
| 644 | if (II.isPipe()) |
| 645 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 646 | else if (II.isFilename()) |
| 647 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 648 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 649 | // Don't render as input, we need gcc to do the translations. |
| 650 | II.getInputArg().render(Args, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 653 | const char *GCCName = |
Daniel Dunbar | 78d8a08 | 2009-04-01 23:34:41 +0000 | [diff] [blame] | 654 | getToolChain().getHost().getDriver().CCCGenericGCCName.c_str(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 655 | const char *Exec = |
Daniel Dunbar | 78d8a08 | 2009-04-01 23:34:41 +0000 | [diff] [blame] | 656 | Args.MakeArgString(getToolChain().GetProgramPath(C, GCCName).c_str()); |
Daniel Dunbar | 632f50e | 2009-03-18 21:34:08 +0000 | [diff] [blame] | 657 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 660 | void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 661 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 664 | void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 665 | // The type is good enough. |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 668 | void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 669 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 672 | void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 673 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 674 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 675 | |
| 676 | void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 677 | // The types are (hopefully) good enough. |
| 678 | } |
| 679 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 680 | const char *darwin::CC1::getCC1Name(types::ID Type) const { |
| 681 | switch (Type) { |
| 682 | default: |
| 683 | assert(0 && "Unexpected type for Darwin CC1 tool."); |
| 684 | case types::TY_Asm: |
| 685 | case types::TY_C: case types::TY_CHeader: |
| 686 | case types::TY_PP_C: case types::TY_PP_CHeader: |
| 687 | return "cc1"; |
| 688 | case types::TY_ObjC: case types::TY_ObjCHeader: |
| 689 | case types::TY_PP_ObjC: case types::TY_PP_ObjCHeader: |
| 690 | return "cc1obj"; |
| 691 | case types::TY_CXX: case types::TY_CXXHeader: |
| 692 | case types::TY_PP_CXX: case types::TY_PP_CXXHeader: |
| 693 | return "cc1plus"; |
| 694 | case types::TY_ObjCXX: case types::TY_ObjCXXHeader: |
| 695 | case types::TY_PP_ObjCXX: case types::TY_PP_ObjCXXHeader: |
| 696 | return "cc1objplus"; |
| 697 | } |
| 698 | } |
| 699 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 700 | const char *darwin::CC1::getBaseInputName(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 701 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 702 | llvm::sys::Path P(Inputs[0].getBaseInput()); |
| 703 | return Args.MakeArgString(P.getLast().c_str()); |
| 704 | } |
| 705 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 706 | const char *darwin::CC1::getBaseInputStem(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 707 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 708 | const char *Str = getBaseInputName(Args, Inputs); |
| 709 | |
| 710 | if (const char *End = strchr(Str, '.')) |
| 711 | return Args.MakeArgString(std::string(Str, End).c_str()); |
| 712 | |
| 713 | return Str; |
| 714 | } |
| 715 | |
| 716 | const char * |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 717 | darwin::CC1::getDependencyFileName(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 718 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 719 | // FIXME: Think about this more. |
| 720 | std::string Res; |
| 721 | |
| 722 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
| 723 | std::string Str(OutputOpt->getValue(Args)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 724 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 725 | Res = Str.substr(0, Str.rfind('.')); |
| 726 | } else |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 727 | Res = darwin::CC1::getBaseInputStem(Args, Inputs); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 728 | |
| 729 | return Args.MakeArgString((Res + ".d").c_str()); |
| 730 | } |
| 731 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 732 | void darwin::CC1::AddCC1Args(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 733 | ArgStringList &CmdArgs) const { |
| 734 | // Derived from cc1 spec. |
| 735 | |
| 736 | // FIXME: -fapple-kext seems to disable this too. Investigate. |
| 737 | if (!Args.hasArg(options::OPT_mkernel) && !Args.hasArg(options::OPT_static) && |
| 738 | !Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 739 | CmdArgs.push_back("-fPIC"); |
| 740 | |
| 741 | // gcc has some code here to deal with when no -mmacosx-version-min |
| 742 | // and no -miphoneos-version-min is present, but this never happens |
| 743 | // due to tool chain specific argument translation. |
| 744 | |
| 745 | // FIXME: Remove mthumb |
| 746 | // FIXME: Remove mno-thumb |
| 747 | // FIXME: Remove faltivec |
| 748 | // FIXME: Remove mno-fused-madd |
| 749 | // FIXME: Remove mlong-branch |
| 750 | // FIXME: Remove mlongcall |
| 751 | // FIXME: Remove mcpu=G4 |
| 752 | // FIXME: Remove mcpu=G5 |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 753 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 754 | if (Args.hasArg(options::OPT_g_Flag) && |
| 755 | !Args.hasArg(options::OPT_fno_eliminate_unused_debug_symbols)) |
| 756 | CmdArgs.push_back("-feliminate-unused-debug-symbols"); |
| 757 | } |
| 758 | |
| 759 | void darwin::CC1::AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, |
| 760 | const InputInfoList &Inputs, |
| 761 | const ArgStringList &OutputArgs) const { |
| 762 | const Driver &D = getToolChain().getHost().getDriver(); |
| 763 | |
| 764 | // Derived from cc1_options spec. |
| 765 | if (Args.hasArg(options::OPT_fast) || |
| 766 | Args.hasArg(options::OPT_fastf) || |
| 767 | Args.hasArg(options::OPT_fastcp)) |
| 768 | CmdArgs.push_back("-O3"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 769 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 770 | if (Arg *A = Args.getLastArg(options::OPT_pg)) |
| 771 | if (Args.hasArg(options::OPT_fomit_frame_pointer)) |
| 772 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 773 | << A->getAsString(Args) << "-fomit-frame-pointer"; |
| 774 | |
| 775 | AddCC1Args(Args, CmdArgs); |
| 776 | |
| 777 | if (!Args.hasArg(options::OPT_Q)) |
| 778 | CmdArgs.push_back("-quiet"); |
| 779 | |
| 780 | CmdArgs.push_back("-dumpbase"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 781 | CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 782 | |
| 783 | Args.AddAllArgs(CmdArgs, options::OPT_d_Group); |
| 784 | |
| 785 | Args.AddAllArgs(CmdArgs, options::OPT_m_Group); |
| 786 | Args.AddAllArgs(CmdArgs, options::OPT_a_Group); |
| 787 | |
| 788 | // FIXME: The goal is to use the user provided -o if that is our |
| 789 | // final output, otherwise to drive from the original input |
| 790 | // name. Find a clean way to go about this. |
| 791 | if ((Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) && |
| 792 | Args.hasArg(options::OPT_o)) { |
| 793 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 794 | CmdArgs.push_back("-auxbase-strip"); |
| 795 | CmdArgs.push_back(OutputOpt->getValue(Args)); |
| 796 | } else { |
| 797 | CmdArgs.push_back("-auxbase"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 798 | CmdArgs.push_back(darwin::CC1::getBaseInputStem(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | Args.AddAllArgs(CmdArgs, options::OPT_g_Group); |
| 802 | |
| 803 | Args.AddAllArgs(CmdArgs, options::OPT_O); |
| 804 | // FIXME: -Wall is getting some special treatment. Investigate. |
| 805 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
| 806 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 807 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 808 | options::OPT_trigraphs); |
| 809 | if (Args.hasArg(options::OPT_v)) |
| 810 | CmdArgs.push_back("-version"); |
| 811 | if (Args.hasArg(options::OPT_pg)) |
| 812 | CmdArgs.push_back("-p"); |
| 813 | Args.AddLastArg(CmdArgs, options::OPT_p); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 814 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 815 | // The driver treats -fsyntax-only specially. |
| 816 | Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 817 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 818 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 819 | if (Args.hasArg(options::OPT_Qn)) |
| 820 | CmdArgs.push_back("-fno-ident"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 821 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 822 | // FIXME: This isn't correct. |
| 823 | //Args.AddLastArg(CmdArgs, options::OPT__help) |
| 824 | //Args.AddLastArg(CmdArgs, options::OPT__targetHelp) |
| 825 | |
| 826 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 827 | |
| 828 | // FIXME: Still don't get what is happening here. Investigate. |
| 829 | Args.AddAllArgs(CmdArgs, options::OPT__param); |
| 830 | |
| 831 | if (Args.hasArg(options::OPT_fmudflap) || |
| 832 | Args.hasArg(options::OPT_fmudflapth)) { |
| 833 | CmdArgs.push_back("-fno-builtin"); |
| 834 | CmdArgs.push_back("-fno-merge-constants"); |
| 835 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 836 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 837 | if (Args.hasArg(options::OPT_coverage)) { |
| 838 | CmdArgs.push_back("-fprofile-arcs"); |
| 839 | CmdArgs.push_back("-ftest-coverage"); |
| 840 | } |
| 841 | |
| 842 | if (types::isCXX(Inputs[0].getType())) |
| 843 | CmdArgs.push_back("-D__private_extern__=extern"); |
| 844 | } |
| 845 | |
| 846 | void darwin::CC1::AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, |
| 847 | const InputInfoList &Inputs, |
| 848 | const ArgStringList &OutputArgs) const { |
| 849 | // Derived from cpp_options |
| 850 | AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 851 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 852 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 853 | |
| 854 | AddCC1Args(Args, CmdArgs); |
| 855 | |
| 856 | // NOTE: The code below has some commonality with cpp_options, but |
| 857 | // in classic gcc style ends up sending things in different |
| 858 | // orders. This may be a good merge candidate once we drop pedantic |
| 859 | // compatibility. |
| 860 | |
| 861 | Args.AddAllArgs(CmdArgs, options::OPT_m_Group); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 862 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 863 | options::OPT_trigraphs); |
| 864 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
| 865 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 866 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 867 | // The driver treats -fsyntax-only specially. |
| 868 | Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only); |
| 869 | |
| 870 | if (Args.hasArg(options::OPT_g_Group) && !Args.hasArg(options::OPT_g0) && |
| 871 | !Args.hasArg(options::OPT_fno_working_directory)) |
| 872 | CmdArgs.push_back("-fworking-directory"); |
| 873 | |
| 874 | Args.AddAllArgs(CmdArgs, options::OPT_O); |
| 875 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 876 | if (Args.hasArg(options::OPT_save_temps)) |
| 877 | CmdArgs.push_back("-fpch-preprocess"); |
| 878 | } |
| 879 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 880 | void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 881 | ArgStringList &CmdArgs, |
| 882 | const InputInfoList &Inputs) const |
| 883 | { |
| 884 | const Driver &D = getToolChain().getHost().getDriver(); |
| 885 | |
| 886 | // Derived from cpp_unique_options. |
| 887 | Arg *A; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 888 | if ((A = Args.getLastArg(options::OPT_C)) || |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 889 | (A = Args.getLastArg(options::OPT_CC))) { |
| 890 | if (!Args.hasArg(options::OPT_E)) |
| 891 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 892 | << A->getAsString(Args) << "-E"; |
| 893 | } |
| 894 | if (!Args.hasArg(options::OPT_Q)) |
| 895 | CmdArgs.push_back("-quiet"); |
| 896 | Args.AddAllArgs(CmdArgs, options::OPT_nostdinc); |
| 897 | Args.AddLastArg(CmdArgs, options::OPT_v); |
| 898 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 899 | Args.AddLastArg(CmdArgs, options::OPT_P); |
| 900 | |
| 901 | // FIXME: Handle %I properly. |
| 902 | if (getToolChain().getArchName() == "x86_64") { |
| 903 | CmdArgs.push_back("-imultilib"); |
| 904 | CmdArgs.push_back("x86_64"); |
| 905 | } |
| 906 | |
| 907 | if (Args.hasArg(options::OPT_MD)) { |
| 908 | CmdArgs.push_back("-MD"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 909 | CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | if (Args.hasArg(options::OPT_MMD)) { |
| 913 | CmdArgs.push_back("-MMD"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 914 | CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | Args.AddLastArg(CmdArgs, options::OPT_M); |
| 918 | Args.AddLastArg(CmdArgs, options::OPT_MM); |
| 919 | Args.AddAllArgs(CmdArgs, options::OPT_MF); |
| 920 | Args.AddLastArg(CmdArgs, options::OPT_MG); |
| 921 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
| 922 | Args.AddAllArgs(CmdArgs, options::OPT_MQ); |
| 923 | Args.AddAllArgs(CmdArgs, options::OPT_MT); |
| 924 | if (!Args.hasArg(options::OPT_M) && !Args.hasArg(options::OPT_MM) && |
| 925 | (Args.hasArg(options::OPT_MD) || Args.hasArg(options::OPT_MMD))) { |
| 926 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
| 927 | CmdArgs.push_back("-MQ"); |
| 928 | CmdArgs.push_back(OutputOpt->getValue(Args)); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | Args.AddLastArg(CmdArgs, options::OPT_remap); |
| 933 | if (Args.hasArg(options::OPT_g3)) |
| 934 | CmdArgs.push_back("-dD"); |
| 935 | Args.AddLastArg(CmdArgs, options::OPT_H); |
| 936 | |
| 937 | AddCPPArgs(Args, CmdArgs); |
| 938 | |
| 939 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U, options::OPT_A); |
| 940 | Args.AddAllArgs(CmdArgs, options::OPT_i_Group); |
| 941 | |
| 942 | for (InputInfoList::const_iterator |
| 943 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 944 | const InputInfo &II = *it; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 945 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 946 | if (II.isPipe()) |
| 947 | CmdArgs.push_back("-"); |
| 948 | else |
| 949 | CmdArgs.push_back(II.getFilename()); |
| 950 | } |
| 951 | |
| 952 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 953 | options::OPT_Xpreprocessor); |
| 954 | |
| 955 | if (Args.hasArg(options::OPT_fmudflap)) { |
| 956 | CmdArgs.push_back("-D_MUDFLAP"); |
| 957 | CmdArgs.push_back("-include"); |
| 958 | CmdArgs.push_back("mf-runtime.h"); |
| 959 | } |
| 960 | |
| 961 | if (Args.hasArg(options::OPT_fmudflapth)) { |
| 962 | CmdArgs.push_back("-D_MUDFLAP"); |
| 963 | CmdArgs.push_back("-D_MUDFLAPTH"); |
| 964 | CmdArgs.push_back("-include"); |
| 965 | CmdArgs.push_back("mf-runtime.h"); |
| 966 | } |
| 967 | } |
| 968 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 969 | void darwin::CC1::AddCPPArgs(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 970 | ArgStringList &CmdArgs) const { |
| 971 | // Derived from cpp spec. |
| 972 | |
| 973 | if (Args.hasArg(options::OPT_static)) { |
| 974 | // The gcc spec is broken here, it refers to dynamic but |
| 975 | // that has been translated. Start by being bug compatible. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 976 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 977 | // if (!Args.hasArg(arglist.parser.dynamicOption)) |
| 978 | CmdArgs.push_back("-D__STATIC__"); |
| 979 | } else |
| 980 | CmdArgs.push_back("-D__DYNAMIC__"); |
| 981 | |
| 982 | if (Args.hasArg(options::OPT_pthread)) |
| 983 | CmdArgs.push_back("-D_REENTRANT"); |
| 984 | } |
| 985 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 986 | void darwin::Preprocess::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 987 | Job &Dest, const InputInfo &Output, |
| 988 | const InputInfoList &Inputs, |
| 989 | const ArgList &Args, |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 990 | const char *LinkingOutput) const { |
| 991 | ArgStringList CmdArgs; |
| 992 | |
| 993 | assert(Inputs.size() == 1 && "Unexpected number of inputs!"); |
| 994 | |
| 995 | CmdArgs.push_back("-E"); |
| 996 | |
| 997 | if (Args.hasArg(options::OPT_traditional) || |
| 998 | Args.hasArg(options::OPT_ftraditional) || |
| 999 | Args.hasArg(options::OPT_traditional_cpp)) |
| 1000 | CmdArgs.push_back("-traditional-cpp"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1001 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1002 | ArgStringList OutputArgs; |
| 1003 | if (Output.isFilename()) { |
| 1004 | OutputArgs.push_back("-o"); |
| 1005 | OutputArgs.push_back(Output.getFilename()); |
| 1006 | } else { |
| 1007 | assert(Output.isPipe() && "Unexpected CC1 output."); |
| 1008 | } |
| 1009 | |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 1010 | if (Args.hasArg(options::OPT_E)) { |
| 1011 | AddCPPOptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 1012 | } else { |
| 1013 | AddCPPOptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 1014 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 1015 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1016 | |
Daniel Dunbar | 8a2073a | 2009-04-03 01:27:06 +0000 | [diff] [blame] | 1017 | Args.AddAllArgs(CmdArgs, options::OPT_d_Group); |
| 1018 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1019 | const char *CC1Name = getCC1Name(Inputs[0].getType()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1020 | const char *Exec = |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1021 | Args.MakeArgString(getToolChain().GetProgramPath(C, CC1Name).c_str()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1022 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | void darwin::Compile::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1026 | Job &Dest, const InputInfo &Output, |
| 1027 | const InputInfoList &Inputs, |
| 1028 | const ArgList &Args, |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1029 | const char *LinkingOutput) const { |
| 1030 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1031 | ArgStringList CmdArgs; |
| 1032 | |
| 1033 | assert(Inputs.size() == 1 && "Unexpected number of inputs!"); |
| 1034 | |
| 1035 | types::ID InputType = Inputs[0].getType(); |
| 1036 | const Arg *A; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1037 | if ((A = Args.getLastArg(options::OPT_traditional)) || |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1038 | (A = Args.getLastArg(options::OPT_ftraditional))) |
| 1039 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 1040 | << A->getAsString(Args) << "-E"; |
| 1041 | |
| 1042 | if (Output.getType() == types::TY_LLVMAsm) |
| 1043 | CmdArgs.push_back("-emit-llvm"); |
| 1044 | else if (Output.getType() == types::TY_LLVMBC) |
| 1045 | CmdArgs.push_back("-emit-llvm-bc"); |
| 1046 | |
| 1047 | ArgStringList OutputArgs; |
| 1048 | if (Output.getType() != types::TY_PCH) { |
| 1049 | OutputArgs.push_back("-o"); |
| 1050 | if (Output.isPipe()) |
| 1051 | OutputArgs.push_back("-"); |
| 1052 | else if (Output.isNothing()) |
| 1053 | OutputArgs.push_back("/dev/null"); |
| 1054 | else |
| 1055 | OutputArgs.push_back(Output.getFilename()); |
| 1056 | } |
| 1057 | |
| 1058 | // There is no need for this level of compatibility, but it makes |
| 1059 | // diffing easier. |
| 1060 | bool OutputArgsEarly = (Args.hasArg(options::OPT_fsyntax_only) || |
| 1061 | Args.hasArg(options::OPT_S)); |
| 1062 | |
| 1063 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1064 | AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1065 | if (OutputArgsEarly) { |
| 1066 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 1067 | } else { |
| 1068 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 1069 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 1070 | } |
| 1071 | } else { |
| 1072 | CmdArgs.push_back("-fpreprocessed"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1073 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1074 | // FIXME: There is a spec command to remove |
| 1075 | // -fpredictive-compilation args here. Investigate. |
| 1076 | |
| 1077 | for (InputInfoList::const_iterator |
| 1078 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1079 | const InputInfo &II = *it; |
| 1080 | |
| 1081 | if (II.isPipe()) |
| 1082 | CmdArgs.push_back("-"); |
| 1083 | else |
| 1084 | CmdArgs.push_back(II.getFilename()); |
| 1085 | } |
| 1086 | |
| 1087 | if (OutputArgsEarly) { |
| 1088 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 1089 | } else { |
| 1090 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 1091 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 1092 | } |
| 1093 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1094 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1095 | if (Output.getType() == types::TY_PCH) { |
| 1096 | assert(Output.isFilename() && "Invalid PCH output."); |
| 1097 | |
| 1098 | CmdArgs.push_back("-o"); |
| 1099 | // NOTE: gcc uses a temp .s file for this, but there doesn't seem |
| 1100 | // to be a good reason. |
| 1101 | CmdArgs.push_back("/dev/null"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1102 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1103 | CmdArgs.push_back("--output-pch="); |
| 1104 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1105 | } |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1106 | |
| 1107 | const char *CC1Name = getCC1Name(Inputs[0].getType()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1108 | const char *Exec = |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1109 | Args.MakeArgString(getToolChain().GetProgramPath(C, CC1Name).c_str()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1110 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1113 | void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1114 | Job &Dest, const InputInfo &Output, |
| 1115 | const InputInfoList &Inputs, |
| 1116 | const ArgList &Args, |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1117 | const char *LinkingOutput) const { |
| 1118 | ArgStringList CmdArgs; |
| 1119 | |
| 1120 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 1121 | const InputInfo &Input = Inputs[0]; |
| 1122 | |
| 1123 | // Bit of a hack, this is only used for original inputs. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1124 | // |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 1125 | // FIXME: This is broken for preprocessed .s inputs. |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1126 | if (Input.isFilename() && |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 1127 | strcmp(Input.getFilename(), Input.getBaseInput()) == 0) { |
| 1128 | if (Args.hasArg(options::OPT_gstabs)) |
| 1129 | CmdArgs.push_back("--gstabs"); |
| 1130 | else if (Args.hasArg(options::OPT_g_Group)) |
| 1131 | CmdArgs.push_back("--gdwarf2"); |
| 1132 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1133 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1134 | // Derived from asm spec. |
| 1135 | CmdArgs.push_back("-arch"); |
| 1136 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 1137 | |
| 1138 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 1139 | if ((Args.hasArg(options::OPT_mkernel) || |
| 1140 | Args.hasArg(options::OPT_static) || |
| 1141 | Args.hasArg(options::OPT_fapple_kext)) && |
| 1142 | !Args.hasArg(options::OPT_dynamic)) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1143 | CmdArgs.push_back("-static"); |
| 1144 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1145 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 1146 | options::OPT_Xassembler); |
| 1147 | |
| 1148 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 1149 | CmdArgs.push_back("-o"); |
| 1150 | CmdArgs.push_back(Output.getFilename()); |
| 1151 | |
| 1152 | if (Input.isPipe()) { |
| 1153 | CmdArgs.push_back("-"); |
| 1154 | } else { |
| 1155 | assert(Input.isFilename() && "Invalid input."); |
| 1156 | CmdArgs.push_back(Input.getFilename()); |
| 1157 | } |
| 1158 | |
| 1159 | // asm_final spec is empty. |
| 1160 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1161 | const char *Exec = |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1162 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
| 1163 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 1164 | } |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1165 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1166 | static const char *MakeFormattedString(const ArgList &Args, |
| 1167 | const llvm::format_object_base &Fmt) { |
| 1168 | std::string Str; |
| 1169 | llvm::raw_string_ostream(Str) << Fmt; |
| 1170 | return Args.MakeArgString(Str.c_str()); |
| 1171 | } |
| 1172 | |
| 1173 | /// Helper routine for seeing if we should use dsymutil; this is a |
| 1174 | /// gcc compatible hack, we should remove it and use the input |
| 1175 | /// type information. |
| 1176 | static bool isSourceSuffix(const char *Str) { |
| 1177 | // match: 'C', 'CPP', 'c', 'cc', 'cp', 'c++', 'cpp', 'cxx', 'm', |
| 1178 | // 'mm'. |
| 1179 | switch (strlen(Str)) { |
| 1180 | default: |
| 1181 | return false; |
| 1182 | case 1: |
| 1183 | return (memcmp(Str, "C", 1) == 0 || |
| 1184 | memcmp(Str, "c", 1) == 0 || |
| 1185 | memcmp(Str, "m", 1) == 0); |
| 1186 | case 2: |
| 1187 | return (memcmp(Str, "cc", 2) == 0 || |
| 1188 | memcmp(Str, "cp", 2) == 0 || |
| 1189 | memcmp(Str, "mm", 2) == 0); |
| 1190 | case 3: |
| 1191 | return (memcmp(Str, "CPP", 3) == 0 || |
| 1192 | memcmp(Str, "c++", 3) == 0 || |
| 1193 | memcmp(Str, "cpp", 3) == 0 || |
| 1194 | memcmp(Str, "cxx", 3) == 0); |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) { |
| 1199 | for (unsigned i=0; i < 3; ++i) { |
| 1200 | if (A[i] > B[i]) return false; |
| 1201 | if (A[i] < B[i]) return true; |
| 1202 | } |
| 1203 | return false; |
| 1204 | } |
| 1205 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1206 | static bool isMacosxVersionLT(unsigned (&A)[3], |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1207 | unsigned V0, unsigned V1=0, unsigned V2=0) { |
| 1208 | unsigned B[3] = { V0, V1, V2 }; |
| 1209 | return isMacosxVersionLT(A, B); |
| 1210 | } |
| 1211 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1212 | const toolchains::Darwin_X86 &darwin::Link::getDarwinToolChain() const { |
| 1213 | return reinterpret_cast<const toolchains::Darwin_X86&>(getToolChain()); |
| 1214 | } |
| 1215 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1216 | void darwin::Link::AddDarwinArch(const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1217 | ArgStringList &CmdArgs) const { |
| 1218 | // Derived from darwin_arch spec. |
| 1219 | CmdArgs.push_back("-arch"); |
| 1220 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 1221 | } |
| 1222 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1223 | void darwin::Link::AddDarwinSubArch(const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1224 | ArgStringList &CmdArgs) const { |
| 1225 | // Derived from darwin_subarch spec, not sure what the distinction |
| 1226 | // exists for but at least for this chain it is the same. |
| 1227 | AddDarwinArch(Args, CmdArgs); |
| 1228 | } |
| 1229 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1230 | void darwin::Link::AddLinkArgs(const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1231 | ArgStringList &CmdArgs) const { |
| 1232 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1233 | |
| 1234 | // Derived from the "link" spec. |
| 1235 | Args.AddAllArgs(CmdArgs, options::OPT_static); |
| 1236 | if (!Args.hasArg(options::OPT_static)) |
| 1237 | CmdArgs.push_back("-dynamic"); |
| 1238 | if (Args.hasArg(options::OPT_fgnu_runtime)) { |
| 1239 | // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu |
| 1240 | // here. How do we wish to handle such things? |
| 1241 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1242 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1243 | if (!Args.hasArg(options::OPT_dynamiclib)) { |
| 1244 | if (Args.hasArg(options::OPT_force__cpusubtype__ALL)) { |
| 1245 | AddDarwinArch(Args, CmdArgs); |
| 1246 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 1247 | } else |
| 1248 | AddDarwinSubArch(Args, CmdArgs); |
| 1249 | |
| 1250 | Args.AddLastArg(CmdArgs, options::OPT_bundle); |
| 1251 | Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader); |
| 1252 | Args.AddAllArgs(CmdArgs, options::OPT_client__name); |
| 1253 | |
| 1254 | Arg *A; |
| 1255 | if ((A = Args.getLastArg(options::OPT_compatibility__version)) || |
| 1256 | (A = Args.getLastArg(options::OPT_current__version)) || |
| 1257 | (A = Args.getLastArg(options::OPT_install__name))) |
| 1258 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 1259 | << A->getAsString(Args) << "-dynamiclib"; |
| 1260 | |
| 1261 | Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace); |
| 1262 | Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs); |
| 1263 | Args.AddLastArg(CmdArgs, options::OPT_private__bundle); |
| 1264 | } else { |
| 1265 | CmdArgs.push_back("-dylib"); |
| 1266 | |
| 1267 | Arg *A; |
| 1268 | if ((A = Args.getLastArg(options::OPT_bundle)) || |
| 1269 | (A = Args.getLastArg(options::OPT_bundle__loader)) || |
| 1270 | (A = Args.getLastArg(options::OPT_client__name)) || |
| 1271 | (A = Args.getLastArg(options::OPT_force__flat__namespace)) || |
| 1272 | (A = Args.getLastArg(options::OPT_keep__private__externs)) || |
| 1273 | (A = Args.getLastArg(options::OPT_private__bundle))) |
| 1274 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 1275 | << A->getAsString(Args) << "-dynamiclib"; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1276 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1277 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version, |
| 1278 | "-dylib_compatibility_version"); |
| 1279 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version, |
| 1280 | "-dylib_current_version"); |
| 1281 | |
| 1282 | if (Args.hasArg(options::OPT_force__cpusubtype__ALL)) { |
| 1283 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1284 | // NOTE: We don't add -force_cpusubtype_ALL on this path. Ok. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1285 | } else |
| 1286 | AddDarwinSubArch(Args, CmdArgs); |
| 1287 | |
| 1288 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name, |
| 1289 | "-dylib_install_name"); |
| 1290 | } |
| 1291 | |
| 1292 | Args.AddLastArg(CmdArgs, options::OPT_all__load); |
| 1293 | Args.AddAllArgs(CmdArgs, options::OPT_allowable__client); |
| 1294 | Args.AddLastArg(CmdArgs, options::OPT_bind__at__load); |
| 1295 | Args.AddLastArg(CmdArgs, options::OPT_dead__strip); |
| 1296 | Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms); |
| 1297 | Args.AddAllArgs(CmdArgs, options::OPT_dylib__file); |
| 1298 | Args.AddLastArg(CmdArgs, options::OPT_dynamic); |
| 1299 | Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list); |
| 1300 | Args.AddLastArg(CmdArgs, options::OPT_flat__namespace); |
| 1301 | Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names); |
| 1302 | Args.AddAllArgs(CmdArgs, options::OPT_image__base); |
| 1303 | Args.AddAllArgs(CmdArgs, options::OPT_init); |
| 1304 | |
| 1305 | if (!Args.hasArg(options::OPT_mmacosx_version_min_EQ)) { |
| 1306 | if (!Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1307 | // FIXME: I don't understand what is going on here. This is |
| 1308 | // supposed to come from darwin_ld_minversion, but gcc doesn't |
| 1309 | // seem to be following that; it must be getting overridden |
| 1310 | // somewhere. |
| 1311 | CmdArgs.push_back("-macosx_version_min"); |
| 1312 | CmdArgs.push_back(getDarwinToolChain().getMacosxVersionStr()); |
| 1313 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1314 | } else { |
| 1315 | // Adding all arguments doesn't make sense here but this is what |
| 1316 | // gcc does. |
| 1317 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_mmacosx_version_min_EQ, |
| 1318 | "-macosx_version_min"); |
| 1319 | } |
| 1320 | |
| 1321 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_miphoneos_version_min_EQ, |
| 1322 | "-iphoneos_version_min"); |
| 1323 | Args.AddLastArg(CmdArgs, options::OPT_nomultidefs); |
| 1324 | Args.AddLastArg(CmdArgs, options::OPT_multi__module); |
| 1325 | Args.AddLastArg(CmdArgs, options::OPT_single__module); |
| 1326 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined); |
| 1327 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1328 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1329 | if (Args.hasArg(options::OPT_fpie)) |
| 1330 | CmdArgs.push_back("-pie"); |
| 1331 | |
| 1332 | Args.AddLastArg(CmdArgs, options::OPT_prebind); |
| 1333 | Args.AddLastArg(CmdArgs, options::OPT_noprebind); |
| 1334 | Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding); |
| 1335 | Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules); |
| 1336 | Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs); |
| 1337 | Args.AddAllArgs(CmdArgs, options::OPT_sectcreate); |
| 1338 | Args.AddAllArgs(CmdArgs, options::OPT_sectorder); |
| 1339 | Args.AddAllArgs(CmdArgs, options::OPT_seg1addr); |
| 1340 | Args.AddAllArgs(CmdArgs, options::OPT_segprot); |
| 1341 | Args.AddAllArgs(CmdArgs, options::OPT_segaddr); |
| 1342 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr); |
| 1343 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr); |
| 1344 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table); |
| 1345 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename); |
| 1346 | Args.AddAllArgs(CmdArgs, options::OPT_sub__library); |
| 1347 | Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella); |
| 1348 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_isysroot, "-syslibroot"); |
| 1349 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace); |
| 1350 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints); |
| 1351 | Args.AddAllArgs(CmdArgs, options::OPT_umbrella); |
| 1352 | Args.AddAllArgs(CmdArgs, options::OPT_undefined); |
| 1353 | Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list); |
| 1354 | Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches); |
| 1355 | |
| 1356 | if (!Args.hasArg(options::OPT_weak__reference__mismatches)) { |
| 1357 | CmdArgs.push_back("-weak_reference_mismatches"); |
| 1358 | CmdArgs.push_back("non-weak"); |
| 1359 | } |
| 1360 | |
| 1361 | Args.AddLastArg(CmdArgs, options::OPT_X_Flag); |
| 1362 | Args.AddAllArgs(CmdArgs, options::OPT_y); |
| 1363 | Args.AddLastArg(CmdArgs, options::OPT_w); |
| 1364 | Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size); |
| 1365 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__); |
| 1366 | Args.AddLastArg(CmdArgs, options::OPT_seglinkedit); |
| 1367 | Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit); |
| 1368 | Args.AddAllArgs(CmdArgs, options::OPT_sectalign); |
| 1369 | Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols); |
| 1370 | Args.AddAllArgs(CmdArgs, options::OPT_segcreate); |
| 1371 | Args.AddLastArg(CmdArgs, options::OPT_whyload); |
| 1372 | Args.AddLastArg(CmdArgs, options::OPT_whatsloaded); |
| 1373 | Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name); |
| 1374 | Args.AddLastArg(CmdArgs, options::OPT_dylinker); |
| 1375 | Args.AddLastArg(CmdArgs, options::OPT_Mach); |
| 1376 | } |
| 1377 | |
| 1378 | void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1379 | Job &Dest, const InputInfo &Output, |
| 1380 | const InputInfoList &Inputs, |
| 1381 | const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1382 | const char *LinkingOutput) const { |
| 1383 | assert(Output.getType() == types::TY_Image && "Invalid linker output type."); |
| 1384 | // The logic here is derived from gcc's behavior; most of which |
| 1385 | // comes from specs (starting with link_command). Consult gcc for |
| 1386 | // more information. |
| 1387 | |
| 1388 | // FIXME: The spec references -fdump= which seems to have |
| 1389 | // disappeared? |
| 1390 | |
| 1391 | ArgStringList CmdArgs; |
| 1392 | |
| 1393 | // I'm not sure why this particular decomposition exists in gcc, but |
| 1394 | // we follow suite for ease of comparison. |
| 1395 | AddLinkArgs(Args, CmdArgs); |
| 1396 | |
| 1397 | // FIXME: gcc has %{x} in here. How could this ever happen? Cruft? |
| 1398 | Args.AddAllArgs(CmdArgs, options::OPT_d_Flag); |
| 1399 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 1400 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 1401 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 1402 | Args.AddAllArgs(CmdArgs, options::OPT_u_Group); |
| 1403 | Args.AddAllArgs(CmdArgs, options::OPT_A); |
| 1404 | Args.AddLastArg(CmdArgs, options::OPT_e); |
| 1405 | Args.AddAllArgs(CmdArgs, options::OPT_m_Separate); |
| 1406 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
| 1407 | |
| 1408 | // FIXME: This is just being pedantically bug compatible, gcc |
| 1409 | // doesn't *mean* to forward this, it just does (yay for pattern |
| 1410 | // matching). It doesn't work, of course. |
| 1411 | Args.AddAllArgs(CmdArgs, options::OPT_object); |
| 1412 | |
| 1413 | CmdArgs.push_back("-o"); |
| 1414 | CmdArgs.push_back(Output.getFilename()); |
| 1415 | |
| 1416 | unsigned MacosxVersion[3]; |
| 1417 | if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) { |
| 1418 | bool HadExtra; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1419 | if (!Driver::GetReleaseVersion(A->getValue(Args), MacosxVersion[0], |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1420 | MacosxVersion[1], MacosxVersion[2], |
| 1421 | HadExtra) || |
| 1422 | HadExtra) { |
| 1423 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1424 | D.Diag(clang::diag::err_drv_invalid_version_number) |
| 1425 | << A->getAsString(Args); |
| 1426 | } |
| 1427 | } else { |
| 1428 | getDarwinToolChain().getMacosxVersion(MacosxVersion); |
| 1429 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1430 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1431 | if (!Args.hasArg(options::OPT_A) && |
| 1432 | !Args.hasArg(options::OPT_nostdlib) && |
| 1433 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1434 | // Derived from startfile spec. |
| 1435 | if (Args.hasArg(options::OPT_dynamiclib)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1436 | // Derived from darwin_dylib1 spec. |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1437 | if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1438 | CmdArgs.push_back("-ldylib1.o"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1439 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1440 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 1441 | } else { |
| 1442 | if (Args.hasArg(options::OPT_bundle)) { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1443 | if (!Args.hasArg(options::OPT_static)) { |
| 1444 | // Derived from darwin_bundle1 spec. |
| 1445 | if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
| 1446 | CmdArgs.push_back("-lbundle1.o"); |
| 1447 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1448 | } else { |
| 1449 | if (Args.hasArg(options::OPT_pg)) { |
| 1450 | if (Args.hasArg(options::OPT_static) || |
| 1451 | Args.hasArg(options::OPT_object) || |
| 1452 | Args.hasArg(options::OPT_preload)) { |
| 1453 | CmdArgs.push_back("-lgcrt0.o"); |
| 1454 | } else { |
| 1455 | CmdArgs.push_back("-lgcrt1.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1456 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1457 | // darwin_crt2 spec is empty. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1458 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1459 | } else { |
| 1460 | if (Args.hasArg(options::OPT_static) || |
| 1461 | Args.hasArg(options::OPT_object) || |
| 1462 | Args.hasArg(options::OPT_preload)) { |
| 1463 | CmdArgs.push_back("-lcrt0.o"); |
| 1464 | } else { |
| 1465 | // Derived from darwin_crt1 spec. |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1466 | if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1467 | CmdArgs.push_back("-lcrt1.o"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1468 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1469 | CmdArgs.push_back("-lcrt1.10.5.o"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1470 | else |
| 1471 | CmdArgs.push_back("-lcrt1.10.6.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1472 | |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1473 | // darwin_crt2 spec is empty. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | if (Args.hasArg(options::OPT_shared_libgcc) && |
| 1480 | !Args.hasArg(options::OPT_miphoneos_version_min_EQ) && |
| 1481 | isMacosxVersionLT(MacosxVersion, 10, 5)) { |
| 1482 | const char *Str = getToolChain().GetFilePath(C, "crt3.o").c_str(); |
| 1483 | CmdArgs.push_back(Args.MakeArgString(Str)); |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1488 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1489 | if (Args.hasArg(options::OPT_fopenmp)) |
| 1490 | // This is more complicated in gcc... |
| 1491 | CmdArgs.push_back("-lgomp"); |
| 1492 | |
| 1493 | // FIXME: Derive these correctly. |
| 1494 | const char *TCDir = getDarwinToolChain().getToolChainDir().c_str(); |
| 1495 | if (getToolChain().getArchName() == "x86_64") { |
| 1496 | CmdArgs.push_back(MakeFormattedString(Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1497 | llvm::format("-L/usr/lib/gcc/%s/x86_64", TCDir))); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1498 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 1499 | CmdArgs.push_back(MakeFormattedString(Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1500 | llvm::format("-L/usr/lib/gcc/%s/x86_64", TCDir))); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1501 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1502 | CmdArgs.push_back(MakeFormattedString(Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1503 | llvm::format("-L/usr/lib/%s", TCDir))); |
| 1504 | CmdArgs.push_back(MakeFormattedString(Args, |
| 1505 | llvm::format("-L/usr/lib/gcc/%s", TCDir))); |
| 1506 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 1507 | CmdArgs.push_back(MakeFormattedString(Args, |
| 1508 | llvm::format("-L/usr/lib/gcc/%s", TCDir))); |
| 1509 | CmdArgs.push_back(MakeFormattedString(Args, |
| 1510 | llvm::format("-L/usr/lib/gcc/%s/../../../%s", TCDir, TCDir))); |
| 1511 | CmdArgs.push_back(MakeFormattedString(Args, |
| 1512 | llvm::format("-L/usr/lib/gcc/%s/../../..", TCDir))); |
| 1513 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1514 | for (InputInfoList::const_iterator |
| 1515 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1516 | const InputInfo &II = *it; |
| 1517 | if (II.isFilename()) |
| 1518 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1519 | else |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1520 | II.getInputArg().renderAsInput(Args, CmdArgs); |
| 1521 | } |
| 1522 | |
| 1523 | if (LinkingOutput) { |
| 1524 | CmdArgs.push_back("-arch_multiple"); |
| 1525 | CmdArgs.push_back("-final_output"); |
| 1526 | CmdArgs.push_back(LinkingOutput); |
| 1527 | } |
| 1528 | |
| 1529 | if (Args.hasArg(options::OPT_fprofile_arcs) || |
| 1530 | Args.hasArg(options::OPT_fprofile_generate) || |
| 1531 | Args.hasArg(options::OPT_fcreate_profile) || |
| 1532 | Args.hasArg(options::OPT_coverage)) |
| 1533 | CmdArgs.push_back("-lgcov"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1534 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1535 | if (Args.hasArg(options::OPT_fnested_functions)) |
| 1536 | CmdArgs.push_back("-allow_stack_execute"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1537 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1538 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1539 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | edfa02b | 2009-04-08 06:06:21 +0000 | [diff] [blame] | 1540 | // FIXME: g++ is more complicated here, it tries to put -lstdc++ |
| 1541 | // before -lm, for example. |
| 1542 | if (getToolChain().getHost().getDriver().CCCIsCXX) |
| 1543 | CmdArgs.push_back("-lstdc++"); |
| 1544 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1545 | // link_ssp spec is empty. |
| 1546 | |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1547 | // Derived from libgcc and lib specs but refactored. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1548 | if (Args.hasArg(options::OPT_static)) { |
| 1549 | CmdArgs.push_back("-lgcc_static"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1550 | } else { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1551 | if (Args.hasArg(options::OPT_static_libgcc)) { |
| 1552 | CmdArgs.push_back("-lgcc_eh"); |
| 1553 | } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { |
| 1554 | // Derived from darwin_iphoneos_libgcc spec. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1555 | CmdArgs.push_back("-lgcc_s.10.5"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1556 | } else if (Args.hasArg(options::OPT_shared_libgcc) || |
| 1557 | Args.hasArg(options::OPT_fexceptions) || |
| 1558 | Args.hasArg(options::OPT_fgnu_runtime)) { |
| 1559 | // FIXME: This is probably broken on 10.3? |
| 1560 | if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
| 1561 | CmdArgs.push_back("-lgcc_s.10.4"); |
| 1562 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
| 1563 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 1564 | } else { |
| 1565 | if (isMacosxVersionLT(MacosxVersion, 10, 3, 9)) |
| 1566 | ; // Do nothing. |
| 1567 | else if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
| 1568 | CmdArgs.push_back("-lgcc_s.10.4"); |
| 1569 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
| 1570 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 1571 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1572 | |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1573 | if (isMacosxVersionLT(MacosxVersion, 10, 6)) { |
| 1574 | CmdArgs.push_back("-lgcc"); |
| 1575 | CmdArgs.push_back("-lSystem"); |
| 1576 | } else { |
| 1577 | CmdArgs.push_back("-lSystem"); |
| 1578 | CmdArgs.push_back("-lgcc"); |
| 1579 | } |
| 1580 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | if (!Args.hasArg(options::OPT_A) && |
| 1584 | !Args.hasArg(options::OPT_nostdlib) && |
| 1585 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1586 | // endfile_spec is empty. |
| 1587 | } |
| 1588 | |
| 1589 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 1590 | Args.AddAllArgs(CmdArgs, options::OPT_F); |
| 1591 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1592 | const char *Exec = |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1593 | Args.MakeArgString(getToolChain().GetProgramPath(C, "collect2").c_str()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1594 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1595 | |
Daniel Dunbar | 0b46e1b | 2009-04-04 00:55:30 +0000 | [diff] [blame] | 1596 | // Find the first non-empty base input (we want to ignore linker |
| 1597 | // inputs). |
| 1598 | const char *BaseInput = ""; |
| 1599 | for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { |
| 1600 | if (Inputs[i].getBaseInput()[0] != '\0') { |
| 1601 | BaseInput = Inputs[i].getBaseInput(); |
| 1602 | break; |
| 1603 | } |
| 1604 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1605 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1606 | if (Args.getLastArg(options::OPT_g_Group) && |
| 1607 | !Args.getLastArg(options::OPT_gstabs) && |
| 1608 | !Args.getLastArg(options::OPT_g0)) { |
| 1609 | // FIXME: This is gross, but matches gcc. The test only considers |
| 1610 | // the suffix (not the -x type), and then only of the first |
Daniel Dunbar | 0b46e1b | 2009-04-04 00:55:30 +0000 | [diff] [blame] | 1611 | // source input. Awesome. |
| 1612 | const char *Suffix = strrchr(BaseInput, '.'); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1613 | if (Suffix && isSourceSuffix(Suffix + 1)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1614 | const char *Exec = |
| 1615 | Args.MakeArgString(getToolChain().GetProgramPath(C, "dsymutil").c_str()); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1616 | ArgStringList CmdArgs; |
| 1617 | CmdArgs.push_back(Output.getFilename()); |
| 1618 | C.getJobs().addCommand(new Command(Exec, CmdArgs)); |
| 1619 | } |
| 1620 | } |
| 1621 | } |
| 1622 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1623 | void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1624 | Job &Dest, const InputInfo &Output, |
| 1625 | const InputInfoList &Inputs, |
| 1626 | const ArgList &Args, |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1627 | const char *LinkingOutput) const { |
| 1628 | ArgStringList CmdArgs; |
| 1629 | |
| 1630 | CmdArgs.push_back("-create"); |
| 1631 | assert(Output.isFilename() && "Unexpected lipo output."); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 1632 | |
| 1633 | CmdArgs.push_back("-output"); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1634 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 1635 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1636 | for (InputInfoList::const_iterator |
| 1637 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1638 | const InputInfo &II = *it; |
| 1639 | assert(II.isFilename() && "Unexpected lipo input."); |
| 1640 | CmdArgs.push_back(II.getFilename()); |
| 1641 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1642 | const char *Exec = |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1643 | Args.MakeArgString(getToolChain().GetProgramPath(C, "lipo").c_str()); |
| 1644 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 1645 | } |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1646 | |
Ed Schouten | c66a5a3 | 2009-04-02 19:13:12 +0000 | [diff] [blame] | 1647 | |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1648 | void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1649 | Job &Dest, const InputInfo &Output, |
| 1650 | const InputInfoList &Inputs, |
| 1651 | const ArgList &Args, |
| 1652 | const char *LinkingOutput) const |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1653 | { |
| 1654 | ArgStringList CmdArgs; |
| 1655 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1656 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 1657 | // instruct as in the base system to assemble 32-bit code. |
| 1658 | if (getToolChain().getArchName() == "i386") |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1659 | CmdArgs.push_back("--32"); |
| 1660 | |
| 1661 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 1662 | options::OPT_Xassembler); |
| 1663 | |
| 1664 | CmdArgs.push_back("-o"); |
| 1665 | if (Output.isPipe()) |
| 1666 | CmdArgs.push_back("-"); |
| 1667 | else |
| 1668 | CmdArgs.push_back(Output.getFilename()); |
| 1669 | |
| 1670 | for (InputInfoList::const_iterator |
| 1671 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1672 | const InputInfo &II = *it; |
| 1673 | if (II.isPipe()) |
| 1674 | CmdArgs.push_back("-"); |
| 1675 | else |
| 1676 | CmdArgs.push_back(II.getFilename()); |
| 1677 | } |
| 1678 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1679 | const char *Exec = |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1680 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
| 1681 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 1682 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1683 | |
| 1684 | void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1685 | Job &Dest, const InputInfo &Output, |
| 1686 | const InputInfoList &Inputs, |
| 1687 | const ArgList &Args, |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1688 | const char *LinkingOutput) const |
| 1689 | { |
| 1690 | ArgStringList CmdArgs; |
| 1691 | |
| 1692 | if (Args.hasArg(options::OPT_static)) { |
| 1693 | CmdArgs.push_back("-Bstatic"); |
| 1694 | } else { |
| 1695 | CmdArgs.push_back("--eh-frame-hdr"); |
| 1696 | if (Args.hasArg(options::OPT_shared)) { |
| 1697 | CmdArgs.push_back("-Bshareable"); |
| 1698 | } else { |
| 1699 | CmdArgs.push_back("-dynamic-linker"); |
| 1700 | CmdArgs.push_back("/libexec/ld-elf.so.1"); |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 1705 | // instruct ld in the base system to link 32-bit code. |
| 1706 | if (getToolChain().getArchName() == "i386") { |
| 1707 | CmdArgs.push_back("-m"); |
| 1708 | CmdArgs.push_back("elf_i386_fbsd"); |
| 1709 | } |
| 1710 | |
| 1711 | if (Output.isPipe()) { |
| 1712 | CmdArgs.push_back("-o"); |
| 1713 | CmdArgs.push_back("-"); |
| 1714 | } else if (Output.isFilename()) { |
| 1715 | CmdArgs.push_back("-o"); |
| 1716 | CmdArgs.push_back(Output.getFilename()); |
| 1717 | } else { |
| 1718 | assert(Output.isNothing() && "Invalid output."); |
| 1719 | } |
| 1720 | |
| 1721 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1722 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1723 | if (!Args.hasArg(options::OPT_shared)) { |
| 1724 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crt1.o").c_str())); |
| 1725 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crti.o").c_str())); |
| 1726 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbegin.o").c_str())); |
| 1727 | } else { |
| 1728 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crti.o").c_str())); |
| 1729 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbeginS.o").c_str())); |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 1734 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 1735 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 1736 | |
| 1737 | for (InputInfoList::const_iterator |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1738 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1739 | const InputInfo &II = *it; |
| 1740 | if (II.isPipe()) |
| 1741 | CmdArgs.push_back("-"); |
| 1742 | else if (II.isFilename()) |
| 1743 | CmdArgs.push_back(II.getFilename()); |
| 1744 | else |
| 1745 | II.getInputArg().renderAsInput(Args, CmdArgs); |
| 1746 | } |
| 1747 | |
| 1748 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1749 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 1750 | // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding |
| 1751 | // the default system libraries. Just mimic this for now. |
| 1752 | CmdArgs.push_back("-lgcc"); |
| 1753 | if (Args.hasArg(options::OPT_static)) { |
| 1754 | CmdArgs.push_back("-lgcc_eh"); |
| 1755 | } else { |
| 1756 | CmdArgs.push_back("--as-needed"); |
| 1757 | CmdArgs.push_back("-lgcc_s"); |
| 1758 | CmdArgs.push_back("--no-as-needed"); |
| 1759 | } |
| 1760 | |
| 1761 | if (Args.hasArg(options::OPT_pthread)) |
| 1762 | CmdArgs.push_back("-lpthread"); |
| 1763 | CmdArgs.push_back("-lc"); |
| 1764 | |
| 1765 | CmdArgs.push_back("-lgcc"); |
| 1766 | if (Args.hasArg(options::OPT_static)) { |
| 1767 | CmdArgs.push_back("-lgcc_eh"); |
| 1768 | } else { |
| 1769 | CmdArgs.push_back("--as-needed"); |
| 1770 | CmdArgs.push_back("-lgcc_s"); |
| 1771 | CmdArgs.push_back("--no-as-needed"); |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1776 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1777 | if (!Args.hasArg(options::OPT_shared)) |
| 1778 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtend.o").c_str())); |
| 1779 | else |
| 1780 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtendS.o").c_str())); |
| 1781 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtn.o").c_str())); |
| 1782 | } |
| 1783 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1784 | const char *Exec = |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1785 | Args.MakeArgString(getToolChain().GetProgramPath(C, "ld").c_str()); |
| 1786 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 1787 | } |