clang 20.0.0git
WebAssembly.cpp
Go to the documentation of this file.
1//===--- WebAssembly.cpp - WebAssembly ToolChain Implementation -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "WebAssembly.h"
10#include "CommonArgs.h"
11#include "Gnu.h"
12#include "clang/Basic/Version.h"
13#include "clang/Config/config.h"
15#include "clang/Driver/Driver.h"
18#include "llvm/Config/llvm-config.h" // for LLVM_VERSION_STRING
19#include "llvm/Option/ArgList.h"
20#include "llvm/Support/FileSystem.h"
21#include "llvm/Support/Path.h"
22#include "llvm/Support/VirtualFileSystem.h"
23
24using namespace clang::driver;
25using namespace clang::driver::tools;
26using namespace clang::driver::toolchains;
27using namespace clang;
28using namespace llvm::opt;
29
30/// Following the conventions in https://wiki.debian.org/Multiarch/Tuples,
31/// we remove the vendor field to form the multiarch triple.
32std::string WebAssembly::getMultiarchTriple(const Driver &D,
33 const llvm::Triple &TargetTriple,
34 StringRef SysRoot) const {
35 return (TargetTriple.getArchName() + "-" +
36 TargetTriple.getOSAndEnvironmentName()).str();
37}
38
39std::string wasm::Linker::getLinkerPath(const ArgList &Args) const {
40 const ToolChain &ToolChain = getToolChain();
41 if (const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
42 StringRef UseLinker = A->getValue();
43 if (!UseLinker.empty()) {
44 if (llvm::sys::path::is_absolute(UseLinker) &&
45 llvm::sys::fs::can_execute(UseLinker))
46 return std::string(UseLinker);
47
48 // Interpret 'lld' as explicitly requesting `wasm-ld`, so look for that
49 // linker. Note that for `wasm32-wasip2` this overrides the default linker
50 // of `wasm-component-ld`.
51 if (UseLinker == "lld") {
52 return ToolChain.GetProgramPath("wasm-ld");
53 }
54
55 // Allow 'ld' as an alias for the default linker
56 if (UseLinker != "ld")
57 ToolChain.getDriver().Diag(diag::err_drv_invalid_linker_name)
58 << A->getAsString(Args);
59 }
60 }
61
63}
64
65static bool TargetBuildsComponents(const llvm::Triple &TargetTriple) {
66 // WASIp2 and above are all based on components, so test for WASI but exclude
67 // the original `wasi` target in addition to the `wasip1` name.
68 return TargetTriple.isOSWASI() && TargetTriple.getOSName() != "wasip1" &&
69 TargetTriple.getOSName() != "wasi";
70}
71
73 const InputInfo &Output,
74 const InputInfoList &Inputs,
75 const ArgList &Args,
76 const char *LinkingOutput) const {
77
78 const ToolChain &ToolChain = getToolChain();
79 const char *Linker = Args.MakeArgString(getLinkerPath(Args));
80 ArgStringList CmdArgs;
81
82 CmdArgs.push_back("-m");
83 if (ToolChain.getTriple().isArch64Bit())
84 CmdArgs.push_back("wasm64");
85 else
86 CmdArgs.push_back("wasm32");
87
88 if (Args.hasArg(options::OPT_s))
89 CmdArgs.push_back("--strip-all");
90
91 // On `wasip2` the default linker is `wasm-component-ld` which wraps the
92 // execution of `wasm-ld`. Find `wasm-ld` and pass it as an argument of where
93 // to find it to avoid it needing to hunt and rediscover or search `PATH` for
94 // where it is.
95 if (llvm::sys::path::stem(Linker).ends_with_insensitive(
96 "wasm-component-ld")) {
97 CmdArgs.push_back("--wasm-ld-path");
98 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetProgramPath("wasm-ld")));
99 }
100
101 Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
102
103 ToolChain.AddFilePathLibArgs(Args, CmdArgs);
104
105 bool IsCommand = true;
106 const char *Crt1;
107 const char *Entry = nullptr;
108
109 // When -shared is specified, use the reactor exec model unless
110 // specified otherwise.
111 if (Args.hasArg(options::OPT_shared))
112 IsCommand = false;
113
114 if (const Arg *A = Args.getLastArg(options::OPT_mexec_model_EQ)) {
115 StringRef CM = A->getValue();
116 if (CM == "command") {
117 IsCommand = true;
118 } else if (CM == "reactor") {
119 IsCommand = false;
120 } else {
121 ToolChain.getDriver().Diag(diag::err_drv_invalid_argument_to_option)
122 << CM << A->getOption().getName();
123 }
124 }
125
126 if (IsCommand) {
127 // If crt1-command.o exists, it supports new-style commands, so use it.
128 // Otherwise, use the old crt1.o. This is a temporary transition measure.
129 // Once WASI libc no longer needs to support LLVM versions which lack
130 // support for new-style command, it can make crt1.o the same as
131 // crt1-command.o. And once LLVM no longer needs to support WASI libc
132 // versions before that, it can switch to using crt1-command.o.
133 Crt1 = "crt1.o";
134 if (ToolChain.GetFilePath("crt1-command.o") != "crt1-command.o")
135 Crt1 = "crt1-command.o";
136 } else {
137 Crt1 = "crt1-reactor.o";
138 Entry = "_initialize";
139 }
140
141 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
142 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt1)));
143 if (Entry) {
144 CmdArgs.push_back(Args.MakeArgString("--entry"));
145 CmdArgs.push_back(Args.MakeArgString(Entry));
146 }
147
148 if (Args.hasArg(options::OPT_shared))
149 CmdArgs.push_back(Args.MakeArgString("-shared"));
150
151 AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
152
153 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
155 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
156
157 if (Args.hasArg(options::OPT_pthread)) {
158 CmdArgs.push_back("-lpthread");
159 CmdArgs.push_back("--shared-memory");
160 }
161
162 CmdArgs.push_back("-lc");
163 AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);
164 }
165
166 ToolChain.addProfileRTLibs(Args, CmdArgs);
167
168 CmdArgs.push_back("-o");
169 CmdArgs.push_back(Output.getFilename());
170
171 // Don't use wasm-opt by default on `wasip2` as it doesn't have support for
172 // components at this time. Retain the historical default otherwise, though,
173 // of running `wasm-opt` by default.
174 bool WasmOptDefault = !TargetBuildsComponents(ToolChain.getTriple());
175 bool RunWasmOpt = Args.hasFlag(options::OPT_wasm_opt,
176 options::OPT_no_wasm_opt, WasmOptDefault);
177
178 // If wasm-opt is enabled and optimizations are happening look for the
179 // `wasm-opt` program. If it's not found auto-disable it.
180 std::string WasmOptPath;
181 if (RunWasmOpt && Args.getLastArg(options::OPT_O_Group)) {
182 WasmOptPath = ToolChain.GetProgramPath("wasm-opt");
183 if (WasmOptPath == "wasm-opt") {
184 WasmOptPath = {};
185 }
186 }
187
188 if (!WasmOptPath.empty()) {
189 CmdArgs.push_back("--keep-section=target_features");
190 }
191
192 C.addCommand(std::make_unique<Command>(JA, *this,
194 Linker, CmdArgs, Inputs, Output));
195
196 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
197 if (!WasmOptPath.empty()) {
198 StringRef OOpt = "s";
199 if (A->getOption().matches(options::OPT_O4) ||
200 A->getOption().matches(options::OPT_Ofast))
201 OOpt = "4";
202 else if (A->getOption().matches(options::OPT_O0))
203 OOpt = "0";
204 else if (A->getOption().matches(options::OPT_O))
205 OOpt = A->getValue();
206
207 if (OOpt != "0") {
208 const char *WasmOpt = Args.MakeArgString(WasmOptPath);
209 ArgStringList OptArgs;
210 OptArgs.push_back(Output.getFilename());
211 OptArgs.push_back(Args.MakeArgString(llvm::Twine("-O") + OOpt));
212 OptArgs.push_back("-o");
213 OptArgs.push_back(Output.getFilename());
214 C.addCommand(std::make_unique<Command>(
215 JA, *this, ResponseFileSupport::AtFileCurCP(), WasmOpt, OptArgs,
216 Inputs, Output));
217 }
218 }
219 }
220}
221
222/// Given a base library directory, append path components to form the
223/// LTO directory.
224static std::string AppendLTOLibDir(const std::string &Dir) {
225 // The version allows the path to be keyed to the specific version of
226 // LLVM in used, as the bitcode format is not stable.
227 return Dir + "/llvm-lto/" LLVM_VERSION_STRING;
228}
229
230WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
231 const llvm::opt::ArgList &Args)
232 : ToolChain(D, Triple, Args) {
233
234 assert(Triple.isArch32Bit() != Triple.isArch64Bit());
235
236 getProgramPaths().push_back(getDriver().Dir);
237
238 auto SysRoot = getDriver().SysRoot;
239 if (getTriple().getOS() == llvm::Triple::UnknownOS) {
240 // Theoretically an "unknown" OS should mean no standard libraries, however
241 // it could also mean that a custom set of libraries is in use, so just add
242 // /lib to the search path. Disable multiarch in this case, to discourage
243 // paths containing "unknown" from acquiring meanings.
244 getFilePaths().push_back(SysRoot + "/lib");
245 } else {
246 const std::string MultiarchTriple =
247 getMultiarchTriple(getDriver(), Triple, SysRoot);
248 if (D.isUsingLTO()) {
249 // For LTO, enable use of lto-enabled sysroot libraries too, if available.
250 // Note that the directory is keyed to the LLVM revision, as LLVM's
251 // bitcode format is not stable.
252 auto Dir = AppendLTOLibDir(SysRoot + "/lib/" + MultiarchTriple);
253 getFilePaths().push_back(Dir);
254 }
255 getFilePaths().push_back(SysRoot + "/lib/" + MultiarchTriple);
256 }
257}
258
259const char *WebAssembly::getDefaultLinker() const {
261 return "wasm-component-ld";
262 return "wasm-ld";
263}
264
265bool WebAssembly::IsMathErrnoDefault() const { return false; }
266
267bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; }
268
269bool WebAssembly::UseObjCMixedDispatch() const { return true; }
270
271bool WebAssembly::isPICDefault() const { return false; }
272
273bool WebAssembly::isPIEDefault(const llvm::opt::ArgList &Args) const {
274 return false;
275}
276
277bool WebAssembly::isPICDefaultForced() const { return false; }
278
279bool WebAssembly::hasBlocksRuntime() const { return false; }
280
281// TODO: Support profiling.
282bool WebAssembly::SupportsProfiling() const { return false; }
283
284bool WebAssembly::HasNativeLLVMSupport() const { return true; }
285
286void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
287 ArgStringList &CC1Args,
288 Action::OffloadKind) const {
289 if (!DriverArgs.hasFlag(clang::driver::options::OPT_fuse_init_array,
290 options::OPT_fno_use_init_array, true))
291 CC1Args.push_back("-fno-use-init-array");
292
293 // '-pthread' implies atomics, bulk-memory, mutable-globals, and sign-ext
294 if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
295 false)) {
296 if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
297 false))
298 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
299 << "-pthread"
300 << "-mno-atomics";
301 if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
302 options::OPT_mbulk_memory, false))
303 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
304 << "-pthread"
305 << "-mno-bulk-memory";
306 if (DriverArgs.hasFlag(options::OPT_mno_mutable_globals,
307 options::OPT_mmutable_globals, false))
308 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
309 << "-pthread"
310 << "-mno-mutable-globals";
311 if (DriverArgs.hasFlag(options::OPT_mno_sign_ext, options::OPT_msign_ext,
312 false))
313 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
314 << "-pthread"
315 << "-mno-sign-ext";
316 CC1Args.push_back("-target-feature");
317 CC1Args.push_back("+atomics");
318 CC1Args.push_back("-target-feature");
319 CC1Args.push_back("+bulk-memory");
320 CC1Args.push_back("-target-feature");
321 CC1Args.push_back("+mutable-globals");
322 CC1Args.push_back("-target-feature");
323 CC1Args.push_back("+sign-ext");
324 }
325
326 if (!DriverArgs.hasFlag(options::OPT_mmutable_globals,
327 options::OPT_mno_mutable_globals, false)) {
328 // -fPIC implies +mutable-globals because the PIC ABI used by the linker
329 // depends on importing and exporting mutable globals.
330 llvm::Reloc::Model RelocationModel;
331 unsigned PICLevel;
332 bool IsPIE;
333 std::tie(RelocationModel, PICLevel, IsPIE) =
334 ParsePICArgs(*this, DriverArgs);
335 if (RelocationModel == llvm::Reloc::PIC_) {
336 if (DriverArgs.hasFlag(options::OPT_mno_mutable_globals,
337 options::OPT_mmutable_globals, false)) {
338 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
339 << "-fPIC"
340 << "-mno-mutable-globals";
341 }
342 CC1Args.push_back("-target-feature");
343 CC1Args.push_back("+mutable-globals");
344 }
345 }
346
347 // Bans incompatible options for Wasm EH / SjLj. We don't allow using
348 // different modes for EH and SjLj.
349 auto BanIncompatibleOptionsForWasmEHSjLj = [&](StringRef CurOption) {
350 if (DriverArgs.hasFlag(options::OPT_mno_exception_handing,
351 options::OPT_mexception_handing, false))
352 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
353 << CurOption << "-mno-exception-handling";
354 // The standardized Wasm EH spec requires multivalue and reference-types.
355 if (DriverArgs.hasFlag(options::OPT_mno_multivalue,
356 options::OPT_mmultivalue, false))
357 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
358 << CurOption << "-mno-multivalue";
359 if (DriverArgs.hasFlag(options::OPT_mno_reference_types,
360 options::OPT_mreference_types, false))
361 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
362 << CurOption << "-mno-reference-types";
363
364 for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
365 for (const auto *Option :
366 {"-enable-emscripten-cxx-exceptions", "-enable-emscripten-sjlj",
367 "-emscripten-cxx-exceptions-allowed"}) {
368 if (StringRef(A->getValue(0)) == Option)
369 getDriver().Diag(diag::err_drv_argument_not_allowed_with)
370 << CurOption << Option;
371 }
372 }
373 };
374
375 // Enable necessary features for Wasm EH / SjLj in the backend.
376 auto EnableFeaturesForWasmEHSjLj = [&]() {
377 CC1Args.push_back("-target-feature");
378 CC1Args.push_back("+exception-handling");
379 // The standardized Wasm EH spec requires multivalue and reference-types.
380 CC1Args.push_back("-target-feature");
381 CC1Args.push_back("+multivalue");
382 CC1Args.push_back("-target-feature");
383 CC1Args.push_back("+reference-types");
384 // Backend needs '-exception-model=wasm' to use Wasm EH instructions
385 CC1Args.push_back("-exception-model=wasm");
386 };
387
388 if (DriverArgs.getLastArg(options::OPT_fwasm_exceptions)) {
389 BanIncompatibleOptionsForWasmEHSjLj("-fwasm-exceptions");
390 EnableFeaturesForWasmEHSjLj();
391 // Backend needs -wasm-enable-eh to enable Wasm EH
392 CC1Args.push_back("-mllvm");
393 CC1Args.push_back("-wasm-enable-eh");
394 }
395
396 for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
397 StringRef Opt = A->getValue(0);
398 if (Opt.starts_with("-emscripten-cxx-exceptions-allowed")) {
399 // '-mllvm -emscripten-cxx-exceptions-allowed' should be used with
400 // '-mllvm -enable-emscripten-cxx-exceptions'
401 bool EmEHArgExists = false;
402 for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
403 if (StringRef(A->getValue(0)) == "-enable-emscripten-cxx-exceptions") {
404 EmEHArgExists = true;
405 break;
406 }
407 }
408 if (!EmEHArgExists)
409 getDriver().Diag(diag::err_drv_argument_only_allowed_with)
410 << "-mllvm -emscripten-cxx-exceptions-allowed"
411 << "-mllvm -enable-emscripten-cxx-exceptions";
412
413 // Prevent functions specified in -emscripten-cxx-exceptions-allowed list
414 // from being inlined before reaching the wasm backend.
415 StringRef FuncNamesStr = Opt.split('=').second;
417 FuncNamesStr.split(FuncNames, ',');
418 for (auto Name : FuncNames) {
419 CC1Args.push_back("-mllvm");
420 CC1Args.push_back(DriverArgs.MakeArgString("--force-attribute=" + Name +
421 ":noinline"));
422 }
423 }
424
425 for (const auto *Option :
426 {"-wasm-enable-eh", "-wasm-enable-sjlj", "-wasm-use-legacy-eh"}) {
427 if (Opt.starts_with(Option)) {
428 BanIncompatibleOptionsForWasmEHSjLj(Option);
429 EnableFeaturesForWasmEHSjLj();
430 }
431 }
432 }
433}
434
435ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const {
437}
438
440WebAssembly::GetCXXStdlibType(const ArgList &Args) const {
441 if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
442 StringRef Value = A->getValue();
443 if (Value == "libc++")
445 else if (Value == "libstdc++")
447 else
448 getDriver().Diag(diag::err_drv_invalid_stdlib_name)
449 << A->getAsString(Args);
450 }
452}
453
454void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
455 ArgStringList &CC1Args) const {
456 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
457 return;
458
459 const Driver &D = getDriver();
460
461 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
462 SmallString<128> P(D.ResourceDir);
463 llvm::sys::path::append(P, "include");
464 addSystemInclude(DriverArgs, CC1Args, P);
465 }
466
467 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
468 return;
469
470 // Check for configure-time C include directories.
471 StringRef CIncludeDirs(C_INCLUDE_DIRS);
472 if (CIncludeDirs != "") {
474 CIncludeDirs.split(dirs, ":");
475 for (StringRef dir : dirs) {
476 StringRef Prefix =
477 llvm::sys::path::is_absolute(dir) ? "" : StringRef(D.SysRoot);
478 addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
479 }
480 return;
481 }
482
483 if (getTriple().getOS() != llvm::Triple::UnknownOS) {
484 const std::string MultiarchTriple =
485 getMultiarchTriple(D, getTriple(), D.SysRoot);
486 addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include/" + MultiarchTriple);
487 }
488 addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
489}
490
491void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
492 ArgStringList &CC1Args) const {
493
494 if (DriverArgs.hasArg(options::OPT_nostdlibinc, options::OPT_nostdinc,
495 options::OPT_nostdincxx))
496 return;
497
498 switch (GetCXXStdlibType(DriverArgs)) {
500 addLibCxxIncludePaths(DriverArgs, CC1Args);
501 break;
503 addLibStdCXXIncludePaths(DriverArgs, CC1Args);
504 break;
505 }
506}
507
508void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
509 llvm::opt::ArgStringList &CmdArgs) const {
510
511 switch (GetCXXStdlibType(Args)) {
513 CmdArgs.push_back("-lc++");
514 if (Args.hasArg(options::OPT_fexperimental_library))
515 CmdArgs.push_back("-lc++experimental");
516 CmdArgs.push_back("-lc++abi");
517 break;
519 CmdArgs.push_back("-lstdc++");
520 break;
521 }
522}
523
524SanitizerMask WebAssembly::getSupportedSanitizers() const {
526 if (getTriple().isOSEmscripten()) {
527 Res |= SanitizerKind::Vptr | SanitizerKind::Leak | SanitizerKind::Address;
528 }
529 // -fsanitize=function places two words before the function label, which are
530 // -unsupported.
532 return Res;
533}
534
535Tool *WebAssembly::buildLinker() const {
536 return new tools::wasm::Linker(*this);
537}
538
539void WebAssembly::addLibCxxIncludePaths(
540 const llvm::opt::ArgList &DriverArgs,
541 llvm::opt::ArgStringList &CC1Args) const {
542 const Driver &D = getDriver();
543 std::string SysRoot = computeSysRoot();
544 std::string LibPath = SysRoot + "/include";
545 const std::string MultiarchTriple =
546 getMultiarchTriple(D, getTriple(), SysRoot);
547 bool IsKnownOs = (getTriple().getOS() != llvm::Triple::UnknownOS);
548
549 std::string Version = detectLibcxxVersion(LibPath);
550 if (Version.empty())
551 return;
552
553 // First add the per-target include path if the OS is known.
554 if (IsKnownOs) {
555 std::string TargetDir = LibPath + "/" + MultiarchTriple + "/c++/" + Version;
556 addSystemInclude(DriverArgs, CC1Args, TargetDir);
557 }
558
559 // Second add the generic one.
560 addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version);
561}
562
563void WebAssembly::addLibStdCXXIncludePaths(
564 const llvm::opt::ArgList &DriverArgs,
565 llvm::opt::ArgStringList &CC1Args) const {
566 // We cannot use GCCInstallationDetector here as the sysroot usually does
567 // not contain a full GCC installation.
568 // Instead, we search the given sysroot for /usr/include/xx, similar
569 // to how we do it for libc++.
570 const Driver &D = getDriver();
571 std::string SysRoot = computeSysRoot();
572 std::string LibPath = SysRoot + "/include";
573 const std::string MultiarchTriple =
574 getMultiarchTriple(D, getTriple(), SysRoot);
575 bool IsKnownOs = (getTriple().getOS() != llvm::Triple::UnknownOS);
576
577 // This is similar to detectLibcxxVersion()
578 std::string Version;
579 {
580 std::error_code EC;
581 Generic_GCC::GCCVersion MaxVersion =
583 SmallString<128> Path(LibPath);
584 llvm::sys::path::append(Path, "c++");
585 for (llvm::vfs::directory_iterator LI = getVFS().dir_begin(Path, EC), LE;
586 !EC && LI != LE; LI = LI.increment(EC)) {
587 StringRef VersionText = llvm::sys::path::filename(LI->path());
588 if (VersionText[0] != 'v') {
589 auto Version = Generic_GCC::GCCVersion::Parse(VersionText);
590 if (Version > MaxVersion)
591 MaxVersion = Version;
592 }
593 }
594 if (MaxVersion.Major > 0)
595 Version = MaxVersion.Text;
596 }
597
598 if (Version.empty())
599 return;
600
601 // First add the per-target include path if the OS is known.
602 if (IsKnownOs) {
603 std::string TargetDir = LibPath + "/c++/" + Version + "/" + MultiarchTriple;
604 addSystemInclude(DriverArgs, CC1Args, TargetDir);
605 }
606
607 // Second add the generic one.
608 addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version);
609 // Third the backward one.
610 addSystemInclude(DriverArgs, CC1Args, LibPath + "/c++/" + Version + "/backward");
611}
StringRef P
const Decl * D
IndirectLocalPath & Path
static bool TargetBuildsComponents(const llvm::Triple &TargetTriple)
Definition: WebAssembly.cpp:65
static std::string AppendLTOLibDir(const std::string &Dir)
Given a base library directory, append path components to form the LTO directory.
Defines version macros and version-related utility functions for Clang.
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:144
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
const char * getFilename() const
Definition: InputInfo.h:83
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
Definition: ToolChain.cpp:1277
virtual std::string computeSysRoot() const
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
Definition: ToolChain.cpp:1163
bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const
Returns if the C++ standard library should be linked in.
Definition: ToolChain.cpp:1379
static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory with extern "C" semantics to CC1 arguments.
Definition: ToolChain.cpp:1292
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:961
StringRef getOS() const
Definition: ToolChain.h:271
const Driver & getDriver() const
Definition: ToolChain.h:252
virtual std::string detectLibcxxVersion(StringRef IncludePath) const
Definition: ToolChain.cpp:1324
llvm::vfs::FileSystem & getVFS() const
Definition: ToolChain.cpp:153
virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
Definition: ToolChain.cpp:1385
virtual const char * getDefaultLinker() const
GetDefaultLinker - Get the default linker to use.
Definition: ToolChain.h:493
const llvm::Triple & getTriple() const
Definition: ToolChain.h:254
virtual void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass a suitable profile runtime ...
Definition: ToolChain.cpp:1181
std::string GetProgramPath(const char *Name) const
Definition: ToolChain.cpp:965
void AddFilePathLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option.
Definition: ToolChain.cpp:1404
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:1468
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
WebAssembly(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
std::string getLinkerPath(const llvm::opt::ArgList &Args) const
Definition: WebAssembly.cpp:39
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: WebAssembly.cpp:72
void AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
std::tuple< llvm::Reloc::Model, unsigned, bool > ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args)
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
bool LE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1171
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport AtFileCurCP()
Definition: Job.h:92
Struct to store and manipulate GCC versions.
Definition: Gnu.h:163
int Major
The parsed major, minor, and patch numbers.
Definition: Gnu.h:168
std::string Text
The unparsed text of the version.
Definition: Gnu.h:165
static GCCVersion Parse(StringRef VersionText)
Parse a GCCVersion object out of a string of text.
Definition: Gnu.cpp:2126