Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: lib/Driver/Tools.cpp

Issue 1547623002: Clang toolchain driver for PNaCl (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-clang.git@master
Patch Set: Review feedback addressed Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/Driver/Tools.h ('k') | test/CodeGen/pr18235.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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
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 "__nacl_get_arch",
8274 };
8275 for (StringRef Symbol : AllowUnresolvedSymbols1)
8276 CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symbol ));
8277
8278 if (EH) {
8279 // These symbols are defined by libsupc++ and the PNaClSjLjEH pass
8280 // generates references to them.
8281 const StringRef UndefinedSymbols[] = {
8282 "__pnacl_eh_stack",
8283 "__pnacl_eh_resume",
8284 };
8285 for (StringRef Symbol : UndefinedSymbols)
8286 CmdArgs.push_back(Args.MakeArgString(Twine("--undefined=") + Symbol));
8287 // These symbols are defined by the PNaClSjLjEH pass and libsupc++ refers
8288 // to them.
8289 const StringRef AllowUnresolvedSymbols[] = {
8290 "__pnacl_eh_type_table",
8291 "__pnacl_eh_action_table",
8292 "__pnacl_eh_filter_table",
8293 };
8294 for (StringRef Symbol : AllowUnresolvedSymbols)
8295 CmdArgs.push_back(Args.MakeArgString(Twine("--allow-unresolved=") + Symb ol));
8296 }
8297 }
8298
8299 CmdArgs.push_back("-o");
8300 CmdArgs.push_back(Output.getFilename());
8301
8302 if (!Args.hasArg(options::OPT_nostdlib) &&
8303 !Args.hasArg(options::OPT_nostartfiles)) {
8304 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.x")));
8305 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.bc")));
8306 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.bc")));
8307
8308 const char *unwind = nullptr;
8309 if (EH)
8310 unwind = "sjlj_eh_redirect.bc";
8311 else
8312 unwind = "unwind_stubs.bc";
8313 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(unwind)));
8314 }
8315
8316 Args.AddAllArgs(CmdArgs, options::OPT_L);
8317 Args.AddAllArgs(CmdArgs, options::OPT_u);
8318
8319 const ToolChain::path_list &Paths = ToolChain.getFilePaths();
8320
8321 for (const auto &Path : Paths)
8322 CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path));
8323
8324 // Tell the linker to load the plugin. This has to come before AddLinkerInputs
8325 // as gold requires -plugin to come before any -plugin-opt that -Wl might
8326 // forward.
8327 CmdArgs.push_back("-plugin");
8328 std::string Plugin = ToolChain.getDriver().Dir +
8329 "/../lib" CLANG_LIBDIR_SUFFIX "/LLVMgold" LTDL_SHLIB_EXT;
8330
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=") +
8336 ToolChain.getTriple().str()));
8337
8338 if (EH)
8339 CmdArgs.push_back("-plugin-opt=-enable-pnacl-sjlj-eh");
8340
8341 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
8342 CmdArgs.push_back("--no-demangle");
8343
8344 AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
8345
8346 if (D.CCCIsCXX() &&
8347 !Args.hasArg(options::OPT_nostdlib) &&
8348 !Args.hasArg(options::OPT_nodefaultlibs)) {
8349 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
8350 CmdArgs.push_back("-lpthread");
8351 CmdArgs.push_back("-lm");
8352 }
8353 // Silence warnings when linking C code with a C++ '-stdlib' argument.
8354 Args.ClaimAllArgs(options::OPT_stdlib_EQ);
8355
8356 if (!Args.hasArg(options::OPT_nostdlib)) {
8357 if (!Args.hasArg(options::OPT_nodefaultlibs)) {
8358 CmdArgs.push_back("--start-group");
8359
8360 if ((Args.hasArg(options::OPT_pthread) ||
8361 Args.hasArg(options::OPT_pthreads)))
8362 CmdArgs.push_back("-lpthread");
8363
8364 CmdArgs.push_back("-lc");
8365 CmdArgs.push_back("-lgcc");
8366 CmdArgs.push_back("-lm");
8367 ToolChain.AddLinkRuntimeLibArgs(Args, CmdArgs);
8368
8369 CmdArgs.push_back("--end-group");
8370 }
8371 }
8372
8373 std::string Linker = ToolChain.GetProgramPath("le32-nacl-ld.gold");
8374 C.addCommand(
8375 llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker), CmdArgs) );
8376 }
8184 8377
8185 void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA, 8378 void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
8186 const InputInfo &Output, 8379 const InputInfo &Output,
8187 const InputInfoList &Inputs, 8380 const InputInfoList &Inputs,
8188 const ArgList &Args, 8381 const ArgList &Args,
8189 const char *LinkingOutput) const { 8382 const char *LinkingOutput) const {
8190 claimNoWarnArgs(Args); 8383 claimNoWarnArgs(Args);
8191 ArgStringList CmdArgs; 8384 ArgStringList CmdArgs;
8192 8385
8193 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler); 8386 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
8926 CmdArgs.push_back("-lmsvcrt"); 9119 CmdArgs.push_back("-lmsvcrt");
8927 AddRunTimeLibs(TC, D, CmdArgs, Args); 9120 AddRunTimeLibs(TC, D, CmdArgs, Args);
8928 } 9121 }
8929 } 9122 }
8930 9123
8931 const std::string Linker = TC.GetProgramPath("ld"); 9124 const std::string Linker = TC.GetProgramPath("ld");
8932 Exec = Args.MakeArgString(Linker); 9125 Exec = Args.MakeArgString(Linker);
8933 9126
8934 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs)); 9127 C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs));
8935 } 9128 }
OLDNEW
« no previous file with comments | « lib/Driver/Tools.h ('k') | test/CodeGen/pr18235.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698