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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2043 Args.hasFlag(options::OPT_fobjc_exceptions, | 2050 Args.hasFlag(options::OPT_fobjc_exceptions, |
2044 options::OPT_fno_objc_exceptions, | 2051 options::OPT_fno_objc_exceptions, |
2045 true)) { | 2052 true)) { |
2046 CmdArgs.push_back("-fobjc-exceptions"); | 2053 CmdArgs.push_back("-fobjc-exceptions"); |
2047 | 2054 |
2048 EH |= shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple); | 2055 EH |= shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple); |
2049 } | 2056 } |
2050 | 2057 |
2051 if (types::isCXX(InputType)) { | 2058 if (types::isCXX(InputType)) { |
2052 bool CXXExceptionsEnabled = | 2059 bool CXXExceptionsEnabled = |
2053 Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU(); | 2060 Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU() && |
2061 Triple.getArch() != llvm::Triple::le32; | |
2054 Arg *ExceptionArg = Args.getLastArg( | 2062 Arg *ExceptionArg = Args.getLastArg( |
2055 options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions, | 2063 options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions, |
2056 options::OPT_fexceptions, options::OPT_fno_exceptions); | 2064 options::OPT_fexceptions, options::OPT_fno_exceptions); |
2057 if (ExceptionArg) | 2065 if (ExceptionArg) |
2058 CXXExceptionsEnabled = | 2066 CXXExceptionsEnabled = |
2059 ExceptionArg->getOption().matches(options::OPT_fcxx_exceptions) || | 2067 ExceptionArg->getOption().matches(options::OPT_fcxx_exceptions) || |
2060 ExceptionArg->getOption().matches(options::OPT_fexceptions); | 2068 ExceptionArg->getOption().matches(options::OPT_fexceptions); |
2061 | 2069 |
2062 if (CXXExceptionsEnabled) { | 2070 if (CXXExceptionsEnabled) { |
2063 if (Triple.isPS4CPU()) { | 2071 if (Triple.isPS4CPU()) { |
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3263 break; | 3271 break; |
3264 | 3272 |
3265 case llvm::Triple::x86: | 3273 case llvm::Triple::x86: |
3266 case llvm::Triple::x86_64: | 3274 case llvm::Triple::x86_64: |
3267 AddX86TargetArgs(Args, CmdArgs); | 3275 AddX86TargetArgs(Args, CmdArgs); |
3268 break; | 3276 break; |
3269 | 3277 |
3270 case llvm::Triple::hexagon: | 3278 case llvm::Triple::hexagon: |
3271 AddHexagonTargetArgs(Args, CmdArgs); | 3279 AddHexagonTargetArgs(Args, CmdArgs); |
3272 break; | 3280 break; |
3281 | |
3282 case llvm::Triple::le32: | |
3283 AddLe32TargetArgs(Args, CmdArgs); | |
3273 } | 3284 } |
3274 | 3285 |
3275 // Add clang-cl arguments. | 3286 // Add clang-cl arguments. |
3276 if (getToolChain().getDriver().IsCLMode()) | 3287 if (getToolChain().getDriver().IsCLMode()) |
3277 AddClangCLArgs(Args, CmdArgs); | 3288 AddClangCLArgs(Args, CmdArgs); |
3278 | 3289 |
3279 // Pass the linker version in use. | 3290 // Pass the linker version in use. |
3280 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { | 3291 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { |
3281 CmdArgs.push_back("-target-linker-version"); | 3292 CmdArgs.push_back("-target-linker-version"); |
3282 CmdArgs.push_back(A->getValue()); | 3293 CmdArgs.push_back(A->getValue()); |
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4518 CmdArgs.push_back("-fasm-blocks"); | 4529 CmdArgs.push_back("-fasm-blocks"); |
4519 | 4530 |
4520 // -fgnu-inline-asm is default. | 4531 // -fgnu-inline-asm is default. |
4521 if (!Args.hasFlag(options::OPT_fgnu_inline_asm, | 4532 if (!Args.hasFlag(options::OPT_fgnu_inline_asm, |
4522 options::OPT_fno_gnu_inline_asm, true)) | 4533 options::OPT_fno_gnu_inline_asm, true)) |
4523 CmdArgs.push_back("-fno-gnu-inline-asm"); | 4534 CmdArgs.push_back("-fno-gnu-inline-asm"); |
4524 | 4535 |
4525 // Enable vectorization per default according to the optimization level | 4536 // Enable vectorization per default according to the optimization level |
4526 // selected. For optimization levels that want vectorization we use the alias | 4537 // selected. For optimization levels that want vectorization we use the alias |
4527 // option to simplify the hasFlag logic. | 4538 // option to simplify the hasFlag logic. |
4528 bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false); | 4539 bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false) && |
4540 getToolChain().getArch() != llvm::Triple::le32; | |
4529 OptSpecifier VectorizeAliasOption = EnableVec ? options::OPT_O_Group : | 4541 OptSpecifier VectorizeAliasOption = EnableVec ? options::OPT_O_Group : |
4530 options::OPT_fvectorize; | 4542 options::OPT_fvectorize; |
4531 if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption, | 4543 if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption, |
4532 options::OPT_fno_vectorize, EnableVec)) | 4544 options::OPT_fno_vectorize, EnableVec)) |
4533 CmdArgs.push_back("-vectorize-loops"); | 4545 CmdArgs.push_back("-vectorize-loops"); |
4534 | 4546 |
4535 // -fslp-vectorize is enabled based on the optimization level selected. | 4547 // -fslp-vectorize is enabled based on the optimization level selected. |
4536 bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true); | 4548 bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true) && |
4549 getToolChain().getArch() != llvm::Triple::le32; | |
4537 OptSpecifier SLPVectAliasOption = EnableSLPVec ? options::OPT_O_Group : | 4550 OptSpecifier SLPVectAliasOption = EnableSLPVec ? options::OPT_O_Group : |
4538 options::OPT_fslp_vectorize; | 4551 options::OPT_fslp_vectorize; |
4539 if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption, | 4552 if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption, |
4540 options::OPT_fno_slp_vectorize, EnableSLPVec)) | 4553 options::OPT_fno_slp_vectorize, EnableSLPVec)) |
4541 CmdArgs.push_back("-vectorize-slp"); | 4554 CmdArgs.push_back("-vectorize-slp"); |
4542 | 4555 |
4543 // -fno-slp-vectorize-aggressive is default. | 4556 // -fno-slp-vectorize-aggressive is default. |
4544 if (Args.hasFlag(options::OPT_fslp_vectorize_aggressive, | 4557 if (Args.hasFlag(options::OPT_fslp_vectorize_aggressive, |
4545 options::OPT_fno_slp_vectorize_aggressive, false)) | 4558 options::OPT_fno_slp_vectorize_aggressive, false)) |
4546 CmdArgs.push_back("-vectorize-slp-aggressive"); | 4559 CmdArgs.push_back("-vectorize-slp-aggressive"); |
(...skipping 3627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8174 | 8187 |
8175 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); | 8188 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); |
8176 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); | 8189 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
8177 } | 8190 } |
8178 } | 8191 } |
8179 | 8192 |
8180 C.addCommand(llvm::make_unique<Command>(JA, *this, | 8193 C.addCommand(llvm::make_unique<Command>(JA, *this, |
8181 ToolChain.Linker.c_str(), CmdArgs)); | 8194 ToolChain.Linker.c_str(), CmdArgs)); |
8182 } | 8195 } |
8183 | 8196 |
8197 void pnacltools::Link::ConstructJob(Compilation &C, const JobAction &JA, | |
8198 const InputInfo &Output, | |
8199 const InputInfoList &Inputs, | |
8200 const ArgList &Args, | |
8201 const char *LinkingOutput) const { | |
8202 const toolchains::PNaClToolChain& ToolChain = | |
8203 static_cast<const toolchains::PNaClToolChain&>(getToolChain()); | |
8204 const Driver &D = ToolChain.getDriver(); | |
8205 | |
8206 ArgStringList CmdArgs; | |
8207 | |
8208 // Silence warning for "clang -g foo.o -o foo" | |
8209 Args.ClaimAllArgs(options::OPT_g_Group); | |
8210 // and "clang -emit-llvm foo.o -o foo" | |
8211 Args.ClaimAllArgs(options::OPT_emit_llvm); | |
8212 // and for "clang -w foo.o -o foo". Other warning options are already | |
8213 // handled somewhere else. | |
8214 Args.ClaimAllArgs(options::OPT_w); | |
8215 // Silence warning for libgcc since we only support compiler-rt. | |
8216 Args.ClaimAllArgs(options::OPT_shared_libgcc); | |
8217 Args.ClaimAllArgs(options::OPT_static_libgcc); | |
8218 | |
8219 if (!D.SysRoot.empty()) | |
8220 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); | |
8221 | |
8222 if (Arg *A = Args.getLastArg(options::OPT_shared, | |
8223 options::OPT_dynamic, | |
8224 options::OPT_rdynamic)) | |
8225 D.Diag(diag::err_drv_unsupported_opt) << A->getOption().getName(); | |
8226 | |
8227 std::string TripleStr = ToolChain.ComputeEffectiveClangTriple(Args); | |
8228 if (ToolChain.getArch() != llvm::Triple::le32) | |
8229 D.Diag(diag::err_target_unsupported_arch) << ToolChain.getArchName() | |
8230 << TripleStr; | |
8231 | |
8232 Args.AddAllArgs(CmdArgs, options::OPT_static); | |
8233 if (!Args.hasArg(options::OPT_static)) | |
8234 CmdArgs.push_back("-static"); | |
8235 | |
8236 bool EH = exceptionSettings(Args, ToolChain.getTriple()); | |
8237 | |
8238 bool IsRelocatable = false; | |
8239 if (Args.hasArg(options::OPT_Wl_COMMA)) { | |
8240 for (arg_iterator | |
8241 it = Args.filtered_begin(options::OPT_Wl_COMMA), | |
8242 ie = Args.filtered_end(); | |
8243 it != ie; | |
8244 ++it) { | |
8245 for (unsigned i = 0, e = (*it)->getNumValues(); i != e; ++i) { | |
8246 if (StringRef((*it)->getValue(i)) == "-r") | |
8247 IsRelocatable = true; | |
8248 } | |
8249 } | |
8250 } | |
8251 | |
8252 if (!IsRelocatable) { | |
8253 // The following functions are implemented in the native support library. | |
8254 // Before a .pexe is produced, they get rewritten to intrinsic calls. | |
8255 // However, this rewriting happens after bitcode linking - so gold has to | |
8256 // be told that these are allowed to remain unresolved. | |
8257 const StringRef AllowUnresolvedSymbols[] = { | |
8258 "memcpy", | |
8259 "memset", | |
8260 "memmove", | |
8261 "setjmp", | |
8262 "longjmp" | |
8263 }; | |
8264 CmdArgs.push_back("--undef-sym-check"); | |
8265 for (StringRef Symbol : AllowUnresolvedSymbols) | |
8266 CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symbol )); | |
8267 | |
8268 // These TLS layout functions are either defined by the ExpandTls pass or | |
8269 // (for non-ABI-stable code only) by PNaCl's native support code. | |
8270 const StringRef AllowUnresolvedSymbols1[] = { | |
8271 "__nacl_tp_tls_offset", | |
8272 "__nacl_tp_tdb_offset", | |
8273 }; | |
8274 for (StringRef Symbol : AllowUnresolvedSymbols1) | |
8275 CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symbol )); | |
8276 | |
8277 if (EH) { | |
8278 // These symbols are defined by libsupc++ and the PNaClSjLjEH pass | |
8279 // generates references to them. | |
8280 const StringRef UndefinedSymbols[] = { | |
8281 "__pnacl_eh_stack", | |
8282 "__pnacl_eh_resume", | |
8283 }; | |
8284 for (StringRef Symbol : UndefinedSymbols) | |
8285 CmdArgs.push_back(Args.MakeArgString(Twine("--undefined=") + Symbol)); | |
8286 // These symbols are defined by the PNaClSjLjEH pass and libsupc++ refers | |
8287 // to them. | |
8288 const StringRef AllowUnresolvedSymbols[] = { | |
8289 "__pnacl_eh_type_table", | |
8290 "__pnacl_eh_action_table", | |
8291 "__pnacl_eh_filter_table", | |
8292 }; | |
8293 for (StringRef Symbol : AllowUnresolvedSymbols) | |
8294 CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symb ol)); | |
8295 } | |
8296 } | |
8297 | |
8298 CmdArgs.push_back("-o"); | |
8299 CmdArgs.push_back(Output.getFilename()); | |
8300 | |
8301 if (!Args.hasArg(options::OPT_nostdlib) && | |
8302 !Args.hasArg(options::OPT_nostartfiles)) { | |
8303 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.x"))); | |
8304 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.bc"))); | |
8305 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.bc"))); | |
8306 | |
8307 const char *unwind = nullptr; | |
8308 if (EH) | |
8309 unwind = "sjlj_eh_redirect.bc"; | |
8310 else | |
8311 unwind = "unwind_stubs.bc"; | |
8312 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(unwind))); | |
8313 } | |
8314 | |
8315 Args.AddAllArgs(CmdArgs, options::OPT_L); | |
8316 Args.AddAllArgs(CmdArgs, options::OPT_u); | |
8317 | |
8318 const ToolChain::path_list &Paths = ToolChain.getFilePaths(); | |
8319 | |
8320 for (const auto &Path : Paths) | |
8321 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); | |
8322 | |
8323 // Tell the linker to load the plugin. This has to come before AddLinkerInputs | |
8324 // as gold requires -plugin to come before any -plugin-opt that -Wl might | |
8325 // forward. | |
8326 CmdArgs.push_back("-plugin"); | |
8327 std::string Plugin = ToolChain.getDriver().Dir + "/../lib" CLANG_LIBDIR_SUFFIX "/LLVMgold.so"; | |
Derek Schuff
2016/02/24 18:22:29
Is the file name different on Windows?
Petr Hosek
2016/02/26 00:43:39
Done, although I'm not sure if this is the most Cl
Derek Schuff
2016/02/26 22:36:56
There is a define LTDL_SHLIB_EXT in include/llvm/C
Petr Hosek
2016/03/01 22:54:56
Done.
| |
8328 CmdArgs.push_back(Args.MakeArgString(Plugin)); | |
8329 | |
8330 CmdArgs.push_back("-plugin-opt=emit-llvm"); | |
8331 if (!IsRelocatable) | |
8332 CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=mtriple=") + ToolCha in.getTriple().str())); | |
8333 | |
8334 if (EH) | |
8335 CmdArgs.push_back("-plugin-opt=-enable-pnacl-sjlj-eh"); | |
8336 | |
8337 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) | |
8338 CmdArgs.push_back("--no-demangle"); | |
8339 | |
8340 AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); | |
8341 | |
8342 if (D.CCCIsCXX() && | |
8343 !Args.hasArg(options::OPT_nostdlib) && | |
8344 !Args.hasArg(options::OPT_nodefaultlibs)) { | |
8345 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); | |
8346 CmdArgs.push_back("-lpthread"); | |
8347 CmdArgs.push_back("-lm"); | |
8348 } | |
8349 // Silence warnings when linking C code with a C++ '-stdlib' argument. | |
8350 Args.ClaimAllArgs(options::OPT_stdlib_EQ); | |
8351 | |
8352 if (!Args.hasArg(options::OPT_nostdlib)) { | |
8353 if (!Args.hasArg(options::OPT_nodefaultlibs)) { | |
8354 CmdArgs.push_back("--start-group"); | |
8355 | |
8356 if ((Args.hasArg(options::OPT_pthread) || | |
8357 Args.hasArg(options::OPT_pthreads))) | |
8358 CmdArgs.push_back("-lpthread"); | |
8359 | |
8360 CmdArgs.push_back("-lc"); | |
8361 CmdArgs.push_back("-lgcc"); | |
8362 CmdArgs.push_back("-lm"); | |
8363 ToolChain.AddLinkRuntimeLibArgs(Args, CmdArgs); | |
8364 | |
8365 CmdArgs.push_back("--end-group"); | |
8366 } | |
8367 } | |
8368 | |
8369 std::string Linker = ToolChain.GetProgramPath("le32-nacl-ld.gold"); | |
8370 C.addCommand( | |
8371 llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker), CmdArgs) ); | |
8372 } | |
8184 | 8373 |
8185 void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA, | 8374 void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
8186 const InputInfo &Output, | 8375 const InputInfo &Output, |
8187 const InputInfoList &Inputs, | 8376 const InputInfoList &Inputs, |
8188 const ArgList &Args, | 8377 const ArgList &Args, |
8189 const char *LinkingOutput) const { | 8378 const char *LinkingOutput) const { |
8190 claimNoWarnArgs(Args); | 8379 claimNoWarnArgs(Args); |
8191 ArgStringList CmdArgs; | 8380 ArgStringList CmdArgs; |
8192 | 8381 |
8193 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); | 8382 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"); | 9115 CmdArgs.push_back("-lmsvcrt"); |
8927 AddRunTimeLibs(TC, D, CmdArgs, Args); | 9116 AddRunTimeLibs(TC, D, CmdArgs, Args); |
8928 } | 9117 } |
8929 } | 9118 } |
8930 | 9119 |
8931 const std::string Linker = TC.GetProgramPath("ld"); | 9120 const std::string Linker = TC.GetProgramPath("ld"); |
8932 Exec = Args.MakeArgString(Linker); | 9121 Exec = Args.MakeArgString(Linker); |
8933 | 9122 |
8934 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); | 9123 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); |
8935 } | 9124 } |
OLD | NEW |