Chromium Code Reviews| Index: lib/Driver/Tools.cpp |
| diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp |
| index 05e81f55fff0020b42eb4d89bbe9b17e3e7c6567..d3de88ca8712ff18ab8cbbac3e03be36d3b1b79a 100644 |
| --- a/lib/Driver/Tools.cpp |
| +++ b/lib/Driver/Tools.cpp |
| @@ -1766,6 +1766,13 @@ void Clang::AddHexagonTargetArgs(const ArgList &Args, |
| CmdArgs.push_back ("-machine-sink-split=0"); |
| } |
| +void Clang::AddLe32TargetArgs(const ArgList &Args, |
| + ArgStringList &CmdArgs) const { |
| + Args.ClaimAllArgs(options::OPT_emit_obj); |
| + |
| + CmdArgs.push_back("-fno-gnu-inline-asm"); |
| +} |
| + |
| // Decode AArch64 features from string like +[no]featureA+[no]featureB+... |
| static bool DecodeAArch64Features(const Driver &D, StringRef text, |
| std::vector<const char *> &Features) { |
| @@ -2050,7 +2057,8 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType, |
| if (types::isCXX(InputType)) { |
| bool CXXExceptionsEnabled = |
| - Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU(); |
| + Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU() && |
| + Triple.getArch() != llvm::Triple::le32; |
| Arg *ExceptionArg = Args.getLastArg( |
| options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions, |
| options::OPT_fexceptions, options::OPT_fno_exceptions); |
| @@ -3270,6 +3278,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
| case llvm::Triple::hexagon: |
| AddHexagonTargetArgs(Args, CmdArgs); |
| break; |
| + |
| + case llvm::Triple::le32: |
| + AddLe32TargetArgs(Args, CmdArgs); |
| } |
| // Add clang-cl arguments. |
| @@ -4525,7 +4536,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
| // Enable vectorization per default according to the optimization level |
| // selected. For optimization levels that want vectorization we use the alias |
| // option to simplify the hasFlag logic. |
| - bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false); |
| + bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false) && |
| + getToolChain().getArch() != llvm::Triple::le32; |
| OptSpecifier VectorizeAliasOption = EnableVec ? options::OPT_O_Group : |
| options::OPT_fvectorize; |
| if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption, |
| @@ -4533,7 +4545,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
| CmdArgs.push_back("-vectorize-loops"); |
| // -fslp-vectorize is enabled based on the optimization level selected. |
| - bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true); |
| + bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true) && |
| + getToolChain().getArch() != llvm::Triple::le32; |
| OptSpecifier SLPVectAliasOption = EnableSLPVec ? options::OPT_O_Group : |
| options::OPT_fslp_vectorize; |
| if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption, |
| @@ -8181,6 +8194,182 @@ void nacltools::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| ToolChain.Linker.c_str(), CmdArgs)); |
| } |
| +void pnacltools::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| + const InputInfo &Output, |
| + const InputInfoList &Inputs, |
| + const ArgList &Args, |
| + const char *LinkingOutput) const { |
| + const toolchains::PNaClToolChain& ToolChain = |
| + static_cast<const toolchains::PNaClToolChain&>(getToolChain()); |
| + const Driver &D = ToolChain.getDriver(); |
| + |
| + ArgStringList CmdArgs; |
| + |
| + // Silence warning for "clang -g foo.o -o foo" |
| + Args.ClaimAllArgs(options::OPT_g_Group); |
| + // and "clang -emit-llvm foo.o -o foo" |
| + Args.ClaimAllArgs(options::OPT_emit_llvm); |
| + // and for "clang -w foo.o -o foo". Other warning options are already |
| + // handled somewhere else. |
| + Args.ClaimAllArgs(options::OPT_w); |
| + // Silence warning for libgcc since we only support compiler-rt. |
| + Args.ClaimAllArgs(options::OPT_shared_libgcc); |
| + Args.ClaimAllArgs(options::OPT_static_libgcc); |
| + |
| + if (!D.SysRoot.empty()) |
| + CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| + |
| + if (Arg *A = Args.getLastArg(options::OPT_shared, |
| + options::OPT_dynamic, |
| + options::OPT_rdynamic)) |
| + D.Diag(diag::err_drv_unsupported_opt) << A->getOption().getName(); |
| + |
| + std::string TripleStr = ToolChain.ComputeEffectiveClangTriple(Args); |
| + if (ToolChain.getArch() != llvm::Triple::le32) |
| + D.Diag(diag::err_target_unsupported_arch) << ToolChain.getArchName() |
| + << TripleStr; |
| + |
| + Args.AddAllArgs(CmdArgs, options::OPT_static); |
| + if (!Args.hasArg(options::OPT_static)) |
| + CmdArgs.push_back("-static"); |
| + |
| + bool EH = exceptionSettings(Args, ToolChain.getTriple()); |
| + |
| + bool IsRelocatable = false; |
| + if (Args.hasArg(options::OPT_Wl_COMMA)) { |
| + for (arg_iterator |
| + it = Args.filtered_begin(options::OPT_Wl_COMMA), |
| + ie = Args.filtered_end(); |
| + it != ie; |
| + ++it) { |
| + for (unsigned i = 0, e = (*it)->getNumValues(); i != e; ++i) { |
| + if (StringRef((*it)->getValue(i)) == "-r") |
| + IsRelocatable = true; |
| + } |
| + } |
| + } |
| + |
| + if (!IsRelocatable) { |
| + // The following functions are implemented in the native support library. |
| + // Before a .pexe is produced, they get rewritten to intrinsic calls. |
| + // However, this rewriting happens after bitcode linking - so gold has to |
| + // be told that these are allowed to remain unresolved. |
| + const StringRef AllowUnresolvedSymbols[] = { |
| + "memcpy", |
| + "memset", |
| + "memmove", |
| + "setjmp", |
| + "longjmp" |
| + }; |
| + CmdArgs.push_back("--undef-sym-check"); |
| + for (StringRef Symbol : AllowUnresolvedSymbols) |
| + CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symbol)); |
| + |
| + // These TLS layout functions are either defined by the ExpandTls pass or |
| + // (for non-ABI-stable code only) by PNaCl's native support code. |
| + const StringRef AllowUnresolvedSymbols1[] = { |
| + "__nacl_tp_tls_offset", |
| + "__nacl_tp_tdb_offset", |
| + }; |
| + for (StringRef Symbol : AllowUnresolvedSymbols1) |
| + CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symbol)); |
| + |
| + if (EH) { |
| + // These symbols are defined by libsupc++ and the PNaClSjLjEH pass |
| + // generates references to them. |
| + const StringRef UndefinedSymbols[] = { |
| + "__pnacl_eh_stack", |
| + "__pnacl_eh_resume", |
| + }; |
| + for (StringRef Symbol : UndefinedSymbols) |
| + CmdArgs.push_back(Args.MakeArgString(Twine("--undefined=") + Symbol)); |
| + // These symbols are defined by the PNaClSjLjEH pass and libsupc++ refers |
| + // to them. |
| + const StringRef AllowUnresolvedSymbols[] = { |
| + "__pnacl_eh_type_table", |
| + "__pnacl_eh_action_table", |
| + "__pnacl_eh_filter_table", |
| + }; |
| + for (StringRef Symbol : AllowUnresolvedSymbols) |
| + CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symbol)); |
| + } |
| + } |
| + |
| + CmdArgs.push_back("-o"); |
| + CmdArgs.push_back(Output.getFilename()); |
| + |
| + if (!Args.hasArg(options::OPT_nostdlib) && |
| + !Args.hasArg(options::OPT_nostartfiles)) { |
| + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.x"))); |
| + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.bc"))); |
| + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.bc"))); |
| + |
| + const char *unwind = nullptr; |
| + if (EH) |
| + unwind = "sjlj_eh_redirect.bc"; |
| + else |
| + unwind = "unwind_stubs.bc"; |
| + CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(unwind))); |
| + } |
| + |
| + Args.AddAllArgs(CmdArgs, options::OPT_L); |
| + Args.AddAllArgs(CmdArgs, options::OPT_u); |
| + |
| + const ToolChain::path_list &Paths = ToolChain.getFilePaths(); |
| + |
| + for (const auto &Path : Paths) |
| + CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path)); |
| + |
| + // Tell the linker to load the plugin. This has to come before AddLinkerInputs |
| + // as gold requires -plugin to come before any -plugin-opt that -Wl might |
| + // forward. |
| + CmdArgs.push_back("-plugin"); |
| + 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.
|
| + CmdArgs.push_back(Args.MakeArgString(Plugin)); |
| + |
| + CmdArgs.push_back("-plugin-opt=emit-llvm"); |
| + if (!IsRelocatable) |
| + CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=mtriple=") + ToolChain.getTriple().str())); |
| + |
| + if (EH) |
| + CmdArgs.push_back("-plugin-opt=-enable-pnacl-sjlj-eh"); |
| + |
| + if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) |
| + CmdArgs.push_back("--no-demangle"); |
| + |
| + AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); |
| + |
| + if (D.CCCIsCXX() && |
| + !Args.hasArg(options::OPT_nostdlib) && |
| + !Args.hasArg(options::OPT_nodefaultlibs)) { |
| + ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
| + CmdArgs.push_back("-lpthread"); |
| + CmdArgs.push_back("-lm"); |
| + } |
| + // Silence warnings when linking C code with a C++ '-stdlib' argument. |
| + Args.ClaimAllArgs(options::OPT_stdlib_EQ); |
| + |
| + if (!Args.hasArg(options::OPT_nostdlib)) { |
| + if (!Args.hasArg(options::OPT_nodefaultlibs)) { |
| + CmdArgs.push_back("--start-group"); |
| + |
| + if ((Args.hasArg(options::OPT_pthread) || |
| + Args.hasArg(options::OPT_pthreads))) |
| + CmdArgs.push_back("-lpthread"); |
| + |
| + CmdArgs.push_back("-lc"); |
| + CmdArgs.push_back("-lgcc"); |
| + CmdArgs.push_back("-lm"); |
| + ToolChain.AddLinkRuntimeLibArgs(Args, CmdArgs); |
| + |
| + CmdArgs.push_back("--end-group"); |
| + } |
| + } |
| + |
| + std::string Linker = ToolChain.GetProgramPath("le32-nacl-ld.gold"); |
| + C.addCommand( |
| + llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker), CmdArgs)); |
| +} |
| void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| const InputInfo &Output, |