Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===--- Tools.cpp - Tools Implementations --------------------------------===// | 1 //===--- Tools.cpp - Tools Implementations --------------------------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 | 9 |
| 10 #include "Tools.h" | 10 #include "Tools.h" |
| (...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1759 if (!Args.hasArg(options::OPT_fno_short_enums)) | 1759 if (!Args.hasArg(options::OPT_fno_short_enums)) |
| 1760 CmdArgs.push_back("-fshort-enums"); | 1760 CmdArgs.push_back("-fshort-enums"); |
| 1761 if (Args.getLastArg(options::OPT_mieee_rnd_near)) { | 1761 if (Args.getLastArg(options::OPT_mieee_rnd_near)) { |
| 1762 CmdArgs.push_back ("-mllvm"); | 1762 CmdArgs.push_back ("-mllvm"); |
| 1763 CmdArgs.push_back ("-enable-hexagon-ieee-rnd-near"); | 1763 CmdArgs.push_back ("-enable-hexagon-ieee-rnd-near"); |
| 1764 } | 1764 } |
| 1765 CmdArgs.push_back ("-mllvm"); | 1765 CmdArgs.push_back ("-mllvm"); |
| 1766 CmdArgs.push_back ("-machine-sink-split=0"); | 1766 CmdArgs.push_back ("-machine-sink-split=0"); |
| 1767 } | 1767 } |
| 1768 | 1768 |
| 1769 void Clang::AddLe32TargetArgs(const ArgList &Args, | |
| 1770 ArgStringList &CmdArgs) const { | |
| 1771 Args.ClaimAllArgs(options::OPT_emit_obj); | |
| 1772 | |
| 1773 CmdArgs.push_back("-fno-gnu-inline-asm"); | |
| 1774 } | |
| 1775 | |
| 1769 // Decode AArch64 features from string like +[no]featureA+[no]featureB+... | 1776 // Decode AArch64 features from string like +[no]featureA+[no]featureB+... |
| 1770 static bool DecodeAArch64Features(const Driver &D, StringRef text, | 1777 static bool DecodeAArch64Features(const Driver &D, StringRef text, |
| 1771 std::vector<const char *> &Features) { | 1778 std::vector<const char *> &Features) { |
| 1772 SmallVector<StringRef, 8> Split; | 1779 SmallVector<StringRef, 8> Split; |
| 1773 text.split(Split, StringRef("+"), -1, false); | 1780 text.split(Split, StringRef("+"), -1, false); |
| 1774 | 1781 |
| 1775 for (unsigned I = 0, E = Split.size(); I != E; ++I) { | 1782 for (unsigned I = 0, E = Split.size(); I != E; ++I) { |
| 1776 const char *result = llvm::StringSwitch<const char *>(Split[I]) | 1783 const char *result = llvm::StringSwitch<const char *>(Split[I]) |
| 1777 .Case("fp", "+fp-armv8") | 1784 .Case("fp", "+fp-armv8") |
| 1778 .Case("simd", "+neon") | 1785 .Case("simd", "+neon") |
| (...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3263 break; | 3270 break; |
| 3264 | 3271 |
| 3265 case llvm::Triple::x86: | 3272 case llvm::Triple::x86: |
| 3266 case llvm::Triple::x86_64: | 3273 case llvm::Triple::x86_64: |
| 3267 AddX86TargetArgs(Args, CmdArgs); | 3274 AddX86TargetArgs(Args, CmdArgs); |
| 3268 break; | 3275 break; |
| 3269 | 3276 |
| 3270 case llvm::Triple::hexagon: | 3277 case llvm::Triple::hexagon: |
| 3271 AddHexagonTargetArgs(Args, CmdArgs); | 3278 AddHexagonTargetArgs(Args, CmdArgs); |
| 3272 break; | 3279 break; |
| 3280 | |
| 3281 case llvm::Triple::le32: | |
| 3282 AddLe32TargetArgs(Args, CmdArgs); | |
| 3273 } | 3283 } |
| 3274 | 3284 |
| 3275 // Add clang-cl arguments. | 3285 // Add clang-cl arguments. |
| 3276 if (getToolChain().getDriver().IsCLMode()) | 3286 if (getToolChain().getDriver().IsCLMode()) |
| 3277 AddClangCLArgs(Args, CmdArgs); | 3287 AddClangCLArgs(Args, CmdArgs); |
| 3278 | 3288 |
| 3279 // Pass the linker version in use. | 3289 // Pass the linker version in use. |
| 3280 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { | 3290 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { |
| 3281 CmdArgs.push_back("-target-linker-version"); | 3291 CmdArgs.push_back("-target-linker-version"); |
| 3282 CmdArgs.push_back(A->getValue()); | 3292 CmdArgs.push_back(A->getValue()); |
| (...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4518 CmdArgs.push_back("-fasm-blocks"); | 4528 CmdArgs.push_back("-fasm-blocks"); |
| 4519 | 4529 |
| 4520 // -fgnu-inline-asm is default. | 4530 // -fgnu-inline-asm is default. |
| 4521 if (!Args.hasFlag(options::OPT_fgnu_inline_asm, | 4531 if (!Args.hasFlag(options::OPT_fgnu_inline_asm, |
| 4522 options::OPT_fno_gnu_inline_asm, true)) | 4532 options::OPT_fno_gnu_inline_asm, true)) |
| 4523 CmdArgs.push_back("-fno-gnu-inline-asm"); | 4533 CmdArgs.push_back("-fno-gnu-inline-asm"); |
| 4524 | 4534 |
| 4525 // Enable vectorization per default according to the optimization level | 4535 // Enable vectorization per default according to the optimization level |
| 4526 // selected. For optimization levels that want vectorization we use the alias | 4536 // selected. For optimization levels that want vectorization we use the alias |
| 4527 // option to simplify the hasFlag logic. | 4537 // option to simplify the hasFlag logic. |
| 4528 bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false); | 4538 bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false) && |
| 4539 getToolChain().getArch() != llvm::Triple::le32; | |
| 4529 OptSpecifier VectorizeAliasOption = EnableVec ? options::OPT_O_Group : | 4540 OptSpecifier VectorizeAliasOption = EnableVec ? options::OPT_O_Group : |
| 4530 options::OPT_fvectorize; | 4541 options::OPT_fvectorize; |
| 4531 if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption, | 4542 if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption, |
| 4532 options::OPT_fno_vectorize, EnableVec)) | 4543 options::OPT_fno_vectorize, |
| 4544 EnableVec && | |
| 4545 getToolChain().getArch() != llvm::Triple::le32)) | |
|
Derek Schuff
2016/02/02 23:19:11
is this extra condition subsumed by EnableVec?
Petr Hosek
2016/02/03 22:49:27
This was a leftover, removed.
| |
| 4533 CmdArgs.push_back("-vectorize-loops"); | 4546 CmdArgs.push_back("-vectorize-loops"); |
| 4534 | 4547 |
| 4535 // -fslp-vectorize is enabled based on the optimization level selected. | 4548 // -fslp-vectorize is enabled based on the optimization level selected. |
| 4536 bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true); | 4549 bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true) && |
| 4550 getToolChain().getArch() != llvm::Triple::le32; | |
| 4537 OptSpecifier SLPVectAliasOption = EnableSLPVec ? options::OPT_O_Group : | 4551 OptSpecifier SLPVectAliasOption = EnableSLPVec ? options::OPT_O_Group : |
| 4538 options::OPT_fslp_vectorize; | 4552 options::OPT_fslp_vectorize; |
| 4539 if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption, | 4553 if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption, |
| 4540 options::OPT_fno_slp_vectorize, EnableSLPVec)) | 4554 options::OPT_fno_slp_vectorize, |
| 4555 EnableSLPVec && | |
| 4556 getToolChain().getArch() != llvm::Triple::le32)) | |
| 4541 CmdArgs.push_back("-vectorize-slp"); | 4557 CmdArgs.push_back("-vectorize-slp"); |
| 4542 | 4558 |
| 4543 // -fno-slp-vectorize-aggressive is default. | 4559 // -fno-slp-vectorize-aggressive is default. |
| 4544 if (Args.hasFlag(options::OPT_fslp_vectorize_aggressive, | 4560 if (Args.hasFlag(options::OPT_fslp_vectorize_aggressive, |
| 4545 options::OPT_fno_slp_vectorize_aggressive, false)) | 4561 options::OPT_fno_slp_vectorize_aggressive, false)) |
| 4546 CmdArgs.push_back("-vectorize-slp-aggressive"); | 4562 CmdArgs.push_back("-vectorize-slp-aggressive"); |
| 4547 | 4563 |
| 4548 if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ)) | 4564 if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ)) |
| 4549 A->render(Args, CmdArgs); | 4565 A->render(Args, CmdArgs); |
| 4550 | 4566 |
| (...skipping 3623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8174 | 8190 |
| 8175 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); | 8191 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); |
| 8176 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); | 8192 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
| 8177 } | 8193 } |
| 8178 } | 8194 } |
| 8179 | 8195 |
| 8180 C.addCommand(llvm::make_unique<Command>(JA, *this, | 8196 C.addCommand(llvm::make_unique<Command>(JA, *this, |
| 8181 ToolChain.Linker.c_str(), CmdArgs)); | 8197 ToolChain.Linker.c_str(), CmdArgs)); |
| 8182 } | 8198 } |
| 8183 | 8199 |
| 8200 void pnacltools::Link::ConstructJob(Compilation &C, const JobAction &JA, | |
| 8201 const InputInfo &Output, | |
| 8202 const InputInfoList &Inputs, | |
| 8203 const ArgList &Args, | |
| 8204 const char *LinkingOutput) const { | |
| 8205 const toolchains::PNaClToolChain& ToolChain = | |
| 8206 static_cast<const toolchains::PNaClToolChain&>(getToolChain()); | |
| 8207 const Driver &D = ToolChain.getDriver(); | |
| 8208 | |
| 8209 ArgStringList CmdArgs; | |
| 8210 | |
| 8211 // Silence warning for "clang -g foo.o -o foo" | |
| 8212 Args.ClaimAllArgs(options::OPT_g_Group); | |
| 8213 // and "clang -emit-llvm foo.o -o foo" | |
| 8214 Args.ClaimAllArgs(options::OPT_emit_llvm); | |
| 8215 // and for "clang -w foo.o -o foo". Other warning options are already | |
| 8216 // handled somewhere else. | |
| 8217 Args.ClaimAllArgs(options::OPT_w); | |
| 8218 // Silence warning for libgcc since we only support compiler-rt. | |
| 8219 Args.ClaimAllArgs(options::OPT_shared_libgcc); | |
| 8220 Args.ClaimAllArgs(options::OPT_static_libgcc); | |
| 8221 | |
| 8222 if (!D.SysRoot.empty()) | |
| 8223 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); | |
| 8224 | |
| 8225 if (Arg *A = Args.getLastArg(options::OPT_shared, | |
| 8226 options::OPT_dynamic, | |
| 8227 options::OPT_rdynamic)) | |
| 8228 D.Diag(diag::err_drv_unsupported_opt) << A->getOption().getName(); | |
| 8229 | |
| 8230 std::string TripleStr = ToolChain.ComputeEffectiveClangTriple(Args); | |
| 8231 if (ToolChain.getArch() != llvm::Triple::le32) | |
| 8232 D.Diag(diag::err_target_unsupported_arch) << ToolChain.getArchName() | |
| 8233 << TripleStr; | |
| 8234 | |
| 8235 Args.AddAllArgs(CmdArgs, options::OPT_static); | |
| 8236 if (!Args.hasArg(options::OPT_static)) | |
| 8237 CmdArgs.push_back("-static"); | |
| 8238 | |
| 8239 bool EH = exceptionSettings(Args, ToolChain.getTriple()); | |
|
Derek Schuff
2016/02/02 23:19:11
do we have code somewhere that makes -fno-exceptio
Petr Hosek
2016/02/03 22:49:27
I changed the code that enables exception in addEx
| |
| 8240 | |
| 8241 bool IsRelocatable = false; | |
| 8242 if (Args.hasArg(options::OPT_Wl_COMMA)) { | |
| 8243 for (arg_iterator | |
| 8244 it = Args.filtered_begin(options::OPT_Wl_COMMA), | |
| 8245 ie = Args.filtered_end(); | |
| 8246 it != ie; | |
| 8247 ++it) { | |
| 8248 for (unsigned i = 0, e = (*it)->getNumValues(); i != e; ++i) { | |
| 8249 if (StringRef((*it)->getValue(i)) == "-r") | |
| 8250 IsRelocatable = true; | |
| 8251 } | |
| 8252 } | |
| 8253 } | |
| 8254 | |
| 8255 if (!IsRelocatable) { | |
| 8256 // The following functions are implemented in the native support library. | |
| 8257 // Before a .pexe is produced, they get rewritten to intrinsic calls. | |
| 8258 // However, this rewriting happens after bitcode linking - so gold has to | |
| 8259 // be told that these are allowed to remain unresolved. | |
| 8260 const StringRef AllowUnresolvedSymbols[] = { | |
| 8261 "memcpy", | |
| 8262 "memset", | |
| 8263 "memmove", | |
| 8264 "setjmp", | |
| 8265 "longjmp" | |
| 8266 }; | |
| 8267 CmdArgs.push_back("--undef-sym-check"); | |
| 8268 for (StringRef Symbol : AllowUnresolvedSymbols) | |
| 8269 CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symbol )); | |
| 8270 | |
| 8271 // These TLS layout functions are either defined by the ExpandTls pass or | |
| 8272 // (for non-ABI-stable code only) by PNaCl's native support code. | |
| 8273 const StringRef AllowUnresolvedSymbols1[] = { | |
| 8274 "__nacl_tp_tls_offset", | |
| 8275 "__nacl_tp_tdb_offset", | |
| 8276 }; | |
| 8277 for (StringRef Symbol : AllowUnresolvedSymbols1) | |
| 8278 CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symbol )); | |
| 8279 | |
| 8280 if (EH) { | |
| 8281 // These symbols are defined by libsupc++ and the PNaClSjLjEH pass | |
| 8282 // generates references to them. | |
| 8283 const StringRef UndefinedSymbols[] = { | |
| 8284 "__pnacl_eh_stack", | |
| 8285 "__pnacl_eh_resume", | |
| 8286 }; | |
| 8287 for (StringRef Symbol : UndefinedSymbols) | |
| 8288 CmdArgs.push_back(Args.MakeArgString(Twine("--undefined=") + Symbol)); | |
| 8289 // These symbols are defined by the PNaClSjLjEH pass and libsupc++ refers | |
| 8290 // to them. | |
| 8291 const StringRef AllowUnresolvedSymbols[] = { | |
| 8292 "__pnacl_eh_type_table", | |
| 8293 "__pnacl_eh_action_table", | |
| 8294 "__pnacl_eh_filter_table", | |
| 8295 }; | |
| 8296 for (StringRef Symbol : AllowUnresolvedSymbols) | |
| 8297 CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symb ol)); | |
| 8298 } | |
| 8299 } | |
| 8300 | |
| 8301 CmdArgs.push_back("-o"); | |
| 8302 CmdArgs.push_back(Output.getFilename()); | |
| 8303 | |
| 8304 if (!Args.hasArg(options::OPT_nostdlib) && | |
| 8305 !Args.hasArg(options::OPT_nostartfiles)) { | |
| 8306 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.x"))); | |
| 8307 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.bc"))); | |
| 8308 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.bc"))); | |
| 8309 | |
| 8310 const char *unwind = nullptr; | |
| 8311 if (EH) | |
| 8312 unwind = "sjlj_eh_redirect.bc"; | |
| 8313 else | |
| 8314 unwind = "unwind_stubs.bc"; | |
| 8315 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(unwind))); | |
| 8316 } | |
| 8317 | |
| 8318 Args.AddAllArgs(CmdArgs, options::OPT_L); | |
| 8319 Args.AddAllArgs(CmdArgs, options::OPT_u); | |
| 8320 | |
| 8321 const ToolChain::path_list &Paths = ToolChain.getFilePaths(); | |
| 8322 | |
| 8323 for (const auto &Path : Paths) | |
| 8324 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); | |
| 8325 | |
| 8326 // Tell the linker to load the plugin. This has to come before AddLinkerInputs | |
| 8327 // as gold requires -plugin to come before any -plugin-opt that -Wl might | |
| 8328 // forward. | |
| 8329 CmdArgs.push_back("-plugin"); | |
| 8330 std::string Plugin = ToolChain.getDriver().Dir + "/../lib" CLANG_LIBDIR_SUFFIX "/LLVMgold.so"; | |
| 8331 CmdArgs.push_back(Args.MakeArgString(Plugin)); | |
| 8332 | |
| 8333 CmdArgs.push_back("-plugin-opt=emit-llvm"); | |
| 8334 if (!IsRelocatable) | |
| 8335 CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=mtriple=") + ToolCha in.getTriple().str())); | |
| 8336 | |
| 8337 if (EH) | |
| 8338 CmdArgs.push_back("-plugin-opt=-enable-pnacl-sjlj-eh"); | |
| 8339 | |
| 8340 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) | |
| 8341 CmdArgs.push_back("--no-demangle"); | |
| 8342 | |
| 8343 AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); | |
| 8344 | |
| 8345 if (D.CCCIsCXX() && | |
| 8346 !Args.hasArg(options::OPT_nostdlib) && | |
| 8347 !Args.hasArg(options::OPT_nodefaultlibs)) { | |
| 8348 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); | |
| 8349 CmdArgs.push_back("-lpthread"); | |
| 8350 CmdArgs.push_back("-lm"); | |
| 8351 } | |
| 8352 // Silence warnings when linking C code with a C++ '-stdlib' argument. | |
| 8353 Args.ClaimAllArgs(options::OPT_stdlib_EQ); | |
| 8354 | |
| 8355 if (!Args.hasArg(options::OPT_nostdlib)) { | |
| 8356 if (!Args.hasArg(options::OPT_nodefaultlibs)) { | |
| 8357 CmdArgs.push_back("--start-group"); | |
| 8358 | |
| 8359 if ((Args.hasArg(options::OPT_pthread) || | |
| 8360 Args.hasArg(options::OPT_pthreads))) | |
| 8361 CmdArgs.push_back("-lpthread"); | |
| 8362 | |
| 8363 CmdArgs.push_back("-lc"); | |
| 8364 CmdArgs.push_back("-lgcc"); | |
| 8365 CmdArgs.push_back("-lm"); | |
| 8366 ToolChain.AddLinkRuntimeLibArgs(Args, CmdArgs); | |
| 8367 | |
| 8368 CmdArgs.push_back("--end-group"); | |
| 8369 } | |
| 8370 } | |
| 8371 | |
| 8372 std::string Linker = ToolChain.GetProgramPath("le32-nacl-ld.gold"); | |
| 8373 C.addCommand( | |
| 8374 llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker), CmdArgs) ); | |
| 8375 } | |
| 8184 | 8376 |
| 8185 void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA, | 8377 void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 8186 const InputInfo &Output, | 8378 const InputInfo &Output, |
| 8187 const InputInfoList &Inputs, | 8379 const InputInfoList &Inputs, |
| 8188 const ArgList &Args, | 8380 const ArgList &Args, |
| 8189 const char *LinkingOutput) const { | 8381 const char *LinkingOutput) const { |
| 8190 claimNoWarnArgs(Args); | 8382 claimNoWarnArgs(Args); |
| 8191 ArgStringList CmdArgs; | 8383 ArgStringList CmdArgs; |
| 8192 | 8384 |
| 8193 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); | 8385 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8926 CmdArgs.push_back("-lmsvcrt"); | 9118 CmdArgs.push_back("-lmsvcrt"); |
| 8927 AddRunTimeLibs(TC, D, CmdArgs, Args); | 9119 AddRunTimeLibs(TC, D, CmdArgs, Args); |
| 8928 } | 9120 } |
| 8929 } | 9121 } |
| 8930 | 9122 |
| 8931 const std::string Linker = TC.GetProgramPath("ld"); | 9123 const std::string Linker = TC.GetProgramPath("ld"); |
| 8932 Exec = Args.MakeArgString(Linker); | 9124 Exec = Args.MakeArgString(Linker); |
| 8933 | 9125 |
| 8934 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); | 9126 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); |
| 8935 } | 9127 } |
| OLD | NEW |