clang 20.0.0git
BareMetal.cpp
Go to the documentation of this file.
1//===-- BareMetal.cpp - Bare Metal ToolChain --------------------*- 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 "BareMetal.h"
10
11#include "CommonArgs.h"
12#include "Gnu.h"
14
15#include "Arch/ARM.h"
16#include "Arch/RISCV.h"
18#include "clang/Driver/Driver.h"
22#include "llvm/ADT/StringExtras.h"
23#include "llvm/Option/ArgList.h"
24#include "llvm/Support/Path.h"
25#include "llvm/Support/VirtualFileSystem.h"
26#include "llvm/Support/raw_ostream.h"
27
28#include <sstream>
29
30using namespace llvm::opt;
31using namespace clang;
32using namespace clang::driver;
33using namespace clang::driver::tools;
34using namespace clang::driver::toolchains;
35
36static bool findRISCVMultilibs(const Driver &D,
37 const llvm::Triple &TargetTriple,
38 const ArgList &Args, DetectedMultilibs &Result) {
40 std::string Arch = riscv::getRISCVArch(Args, TargetTriple);
41 StringRef Abi = tools::riscv::getRISCVABI(Args, TargetTriple);
42
43 if (TargetTriple.isRISCV64()) {
44 MultilibBuilder Imac =
45 MultilibBuilder().flag("-march=rv64imac").flag("-mabi=lp64");
46 MultilibBuilder Imafdc = MultilibBuilder("/rv64imafdc/lp64d")
47 .flag("-march=rv64imafdc")
48 .flag("-mabi=lp64d");
49
50 // Multilib reuse
51 bool UseImafdc =
52 (Arch == "rv64imafdc") || (Arch == "rv64gc"); // gc => imafdc
53
54 addMultilibFlag((Arch == "rv64imac"), "-march=rv64imac", Flags);
55 addMultilibFlag(UseImafdc, "-march=rv64imafdc", Flags);
56 addMultilibFlag(Abi == "lp64", "-mabi=lp64", Flags);
57 addMultilibFlag(Abi == "lp64d", "-mabi=lp64d", Flags);
58
59 Result.Multilibs =
61 return Result.Multilibs.select(D, Flags, Result.SelectedMultilibs);
62 }
63 if (TargetTriple.isRISCV32()) {
64 MultilibBuilder Imac =
65 MultilibBuilder().flag("-march=rv32imac").flag("-mabi=ilp32");
66 MultilibBuilder I = MultilibBuilder("/rv32i/ilp32")
67 .flag("-march=rv32i")
68 .flag("-mabi=ilp32");
69 MultilibBuilder Im = MultilibBuilder("/rv32im/ilp32")
70 .flag("-march=rv32im")
71 .flag("-mabi=ilp32");
72 MultilibBuilder Iac = MultilibBuilder("/rv32iac/ilp32")
73 .flag("-march=rv32iac")
74 .flag("-mabi=ilp32");
75 MultilibBuilder Imafc = MultilibBuilder("/rv32imafc/ilp32f")
76 .flag("-march=rv32imafc")
77 .flag("-mabi=ilp32f");
78
79 // Multilib reuse
80 bool UseI = (Arch == "rv32i") || (Arch == "rv32ic"); // ic => i
81 bool UseIm = (Arch == "rv32im") || (Arch == "rv32imc"); // imc => im
82 bool UseImafc = (Arch == "rv32imafc") || (Arch == "rv32imafdc") ||
83 (Arch == "rv32gc"); // imafdc,gc => imafc
84
85 addMultilibFlag(UseI, "-march=rv32i", Flags);
86 addMultilibFlag(UseIm, "-march=rv32im", Flags);
87 addMultilibFlag((Arch == "rv32iac"), "-march=rv32iac", Flags);
88 addMultilibFlag((Arch == "rv32imac"), "-march=rv32imac", Flags);
89 addMultilibFlag(UseImafc, "-march=rv32imafc", Flags);
90 addMultilibFlag(Abi == "ilp32", "-mabi=ilp32", Flags);
91 addMultilibFlag(Abi == "ilp32f", "-mabi=ilp32f", Flags);
92
93 Result.Multilibs =
94 MultilibSetBuilder().Either(I, Im, Iac, Imac, Imafc).makeMultilibSet();
95 return Result.Multilibs.select(D, Flags, Result.SelectedMultilibs);
96 }
97 return false;
98}
99
100static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
101 if (!D.SysRoot.empty())
102 return D.SysRoot;
103
104 SmallString<128> SysRootDir(D.Dir);
105 llvm::sys::path::append(SysRootDir, "..", "lib", "clang-runtimes");
106
107 if (IncludeTriple)
108 llvm::sys::path::append(SysRootDir, D.getTargetTriple());
109
110 return std::string(SysRootDir);
111}
112
113BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
114 const ArgList &Args)
115 : ToolChain(D, Triple, Args),
116 SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) {
117 getProgramPaths().push_back(getDriver().Dir);
118
119 findMultilibs(D, Triple, Args);
121 if (!SysRoot.empty()) {
122 for (const Multilib &M : getOrderedMultilibs()) {
123 SmallString<128> Dir(SysRoot);
124 llvm::sys::path::append(Dir, M.osSuffix(), "lib");
125 getFilePaths().push_back(std::string(Dir));
126 getLibraryPaths().push_back(std::string(Dir));
127 }
128 }
129}
130
131/// Is the triple {aarch64.aarch64_be}-none-elf?
132static bool isAArch64BareMetal(const llvm::Triple &Triple) {
133 if (Triple.getArch() != llvm::Triple::aarch64 &&
134 Triple.getArch() != llvm::Triple::aarch64_be)
135 return false;
136
137 if (Triple.getVendor() != llvm::Triple::UnknownVendor)
138 return false;
139
140 if (Triple.getOS() != llvm::Triple::UnknownOS)
141 return false;
142
143 return Triple.getEnvironmentName() == "elf";
144}
145
146static bool isRISCVBareMetal(const llvm::Triple &Triple) {
147 if (!Triple.isRISCV())
148 return false;
149
150 if (Triple.getVendor() != llvm::Triple::UnknownVendor)
151 return false;
152
153 if (Triple.getOS() != llvm::Triple::UnknownOS)
154 return false;
155
156 return Triple.getEnvironmentName() == "elf";
157}
158
159/// Is the triple powerpc[64][le]-*-none-eabi?
160static bool isPPCBareMetal(const llvm::Triple &Triple) {
161 return Triple.isPPC() && Triple.getOS() == llvm::Triple::UnknownOS &&
162 Triple.getEnvironment() == llvm::Triple::EABI;
163}
164
165static void findMultilibsFromYAML(const ToolChain &TC, const Driver &D,
166 StringRef MultilibPath, const ArgList &Args,
168 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB =
169 D.getVFS().getBufferForFile(MultilibPath);
170 if (!MB)
171 return;
172 Multilib::flags_list Flags = TC.getMultilibFlags(Args);
173 llvm::ErrorOr<MultilibSet> ErrorOrMultilibSet =
174 MultilibSet::parseYaml(*MB.get());
175 if (ErrorOrMultilibSet.getError())
176 return;
177 Result.Multilibs = ErrorOrMultilibSet.get();
178 if (Result.Multilibs.select(D, Flags, Result.SelectedMultilibs))
179 return;
180 D.Diag(clang::diag::warn_drv_missing_multilib) << llvm::join(Flags, " ");
181 std::stringstream ss;
182
183 // If multilib selection didn't complete successfully, report a list
184 // of all the configurations the user could have provided.
185 for (const Multilib &Multilib : Result.Multilibs)
186 if (!Multilib.isError())
187 ss << "\n" << llvm::join(Multilib.flags(), " ");
188 D.Diag(clang::diag::note_drv_available_multilibs) << ss.str();
189
190 // Now report any custom error messages requested by the YAML. We do
191 // this after displaying the list of available multilibs, because
192 // that list is probably large, and (in interactive use) risks
193 // scrolling the useful error message off the top of the user's
194 // terminal.
195 for (const Multilib &Multilib : Result.SelectedMultilibs)
196 if (Multilib.isError())
197 D.Diag(clang::diag::err_drv_multilib_custom_error)
199
200 // If there was an error, clear the SelectedMultilibs vector, in
201 // case it contains partial data.
202 Result.SelectedMultilibs.clear();
203}
204
205static constexpr llvm::StringLiteral MultilibFilename = "multilib.yaml";
206
207static std::optional<llvm::SmallString<128>>
208getMultilibConfigPath(const Driver &D, const llvm::Triple &Triple,
209 const ArgList &Args) {
210 llvm::SmallString<128> MultilibPath;
211 if (Arg *ConfigFileArg = Args.getLastArg(options::OPT_multi_lib_config)) {
212 MultilibPath = ConfigFileArg->getValue();
213 if (!D.getVFS().exists(MultilibPath)) {
214 D.Diag(clang::diag::err_drv_no_such_file) << MultilibPath.str();
215 return {};
216 }
217 } else {
218 MultilibPath = computeBaseSysRoot(D, /*IncludeTriple=*/false);
219 llvm::sys::path::append(MultilibPath, MultilibFilename);
220 }
221 return MultilibPath;
222}
223
224void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple,
225 const ArgList &Args) {
227 // Look for a multilib.yaml before trying target-specific hardwired logic.
228 // If it exists, always do what it specifies.
229 std::optional<llvm::SmallString<128>> MultilibPath =
230 getMultilibConfigPath(D, Triple, Args);
231 if (!MultilibPath)
232 return;
233 if (D.getVFS().exists(*MultilibPath)) {
234 // If multilib.yaml is found, update sysroot so it doesn't use a target
235 // specific suffix
236 SysRoot = computeBaseSysRoot(D, /*IncludeTriple=*/false);
237 findMultilibsFromYAML(*this, D, *MultilibPath, Args, Result);
238 SelectedMultilibs = Result.SelectedMultilibs;
239 Multilibs = Result.Multilibs;
240 } else if (isRISCVBareMetal(Triple)) {
241 if (findRISCVMultilibs(D, Triple, Args, Result)) {
242 SelectedMultilibs = Result.SelectedMultilibs;
243 Multilibs = Result.Multilibs;
244 }
245 }
246}
247
248bool BareMetal::handlesTarget(const llvm::Triple &Triple) {
249 return arm::isARMEABIBareMetal(Triple) || isAArch64BareMetal(Triple) ||
250 isRISCVBareMetal(Triple) || isPPCBareMetal(Triple);
251}
252
254 return new tools::baremetal::Linker(*this);
255}
256
258 return new tools::baremetal::StaticLibTool(*this);
259}
260
261std::string BareMetal::computeSysRoot() const { return SysRoot; }
262
263BareMetal::OrderedMultilibs BareMetal::getOrderedMultilibs() const {
264 // Get multilibs in reverse order because they're ordered most-specific last.
265 if (!SelectedMultilibs.empty())
266 return llvm::reverse(SelectedMultilibs);
267
268 // No multilibs selected so return a single default multilib.
270 return llvm::reverse(Default);
271}
272
273void BareMetal::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
274 ArgStringList &CC1Args) const {
275 if (DriverArgs.hasArg(options::OPT_nostdinc))
276 return;
277
278 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
279 SmallString<128> Dir(getDriver().ResourceDir);
280 llvm::sys::path::append(Dir, "include");
281 addSystemInclude(DriverArgs, CC1Args, Dir.str());
282 }
283
284 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
285 return;
286
287 if (std::optional<std::string> Path = getStdlibIncludePath())
288 addSystemInclude(DriverArgs, CC1Args, *Path);
289
290 const SmallString<128> SysRoot(computeSysRoot());
291 if (!SysRoot.empty()) {
292 for (const Multilib &M : getOrderedMultilibs()) {
293 SmallString<128> Dir(SysRoot);
294 llvm::sys::path::append(Dir, M.includeSuffix());
295 llvm::sys::path::append(Dir, "include");
296 addSystemInclude(DriverArgs, CC1Args, Dir.str());
297 }
298 }
299}
300
301void BareMetal::addClangTargetOptions(const ArgList &DriverArgs,
302 ArgStringList &CC1Args,
303 Action::OffloadKind) const {
304 CC1Args.push_back("-nostdsysteminc");
305}
306
307void BareMetal::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
308 ArgStringList &CC1Args) const {
309 if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc,
310 options::OPT_nostdincxx))
311 return;
312
313 const Driver &D = getDriver();
314 std::string Target = getTripleString();
315
316 auto AddCXXIncludePath = [&](StringRef Path) {
317 std::string Version = detectLibcxxVersion(Path);
318 if (Version.empty())
319 return;
320
321 {
322 // First the per-target include dir: include/<target>/c++/v1.
323 SmallString<128> TargetDir(Path);
324 llvm::sys::path::append(TargetDir, Target, "c++", Version);
325 addSystemInclude(DriverArgs, CC1Args, TargetDir);
326 }
327
328 {
329 // Then the generic dir: include/c++/v1.
331 llvm::sys::path::append(Dir, "c++", Version);
332 addSystemInclude(DriverArgs, CC1Args, Dir);
333 }
334 };
335
336 switch (GetCXXStdlibType(DriverArgs)) {
338 SmallString<128> P(D.Dir);
339 llvm::sys::path::append(P, "..", "include");
340 AddCXXIncludePath(P);
341 break;
342 }
344 // We only support libc++ toolchain installation.
345 break;
346 }
347
348 std::string SysRoot(computeSysRoot());
349 if (SysRoot.empty())
350 return;
351
352 for (const Multilib &M : getOrderedMultilibs()) {
353 SmallString<128> Dir(SysRoot);
354 llvm::sys::path::append(Dir, M.gccSuffix());
355 switch (GetCXXStdlibType(DriverArgs)) {
357 // First check sysroot/usr/include/c++/v1 if it exists.
358 SmallString<128> TargetDir(Dir);
359 llvm::sys::path::append(TargetDir, "usr", "include", "c++", "v1");
360 if (D.getVFS().exists(TargetDir)) {
361 addSystemInclude(DriverArgs, CC1Args, TargetDir.str());
362 break;
363 }
364 // Add generic path if nothing else succeeded so far.
365 llvm::sys::path::append(Dir, "include", "c++", "v1");
366 addSystemInclude(DriverArgs, CC1Args, Dir.str());
367 break;
368 }
370 llvm::sys::path::append(Dir, "include", "c++");
371 std::error_code EC;
372 Generic_GCC::GCCVersion Version = {"", -1, -1, -1, "", "", ""};
373 // Walk the subdirs, and find the one with the newest gcc version:
374 for (llvm::vfs::directory_iterator
375 LI = D.getVFS().dir_begin(Dir.str(), EC),
376 LE;
377 !EC && LI != LE; LI = LI.increment(EC)) {
378 StringRef VersionText = llvm::sys::path::filename(LI->path());
379 auto CandidateVersion = Generic_GCC::GCCVersion::Parse(VersionText);
380 if (CandidateVersion.Major == -1)
381 continue;
382 if (CandidateVersion <= Version)
383 continue;
384 Version = CandidateVersion;
385 }
386 if (Version.Major != -1) {
387 llvm::sys::path::append(Dir, Version.Text);
388 addSystemInclude(DriverArgs, CC1Args, Dir.str());
389 }
390 break;
391 }
392 }
393 }
394}
395
397 const InputInfo &Output,
398 const InputInfoList &Inputs,
399 const ArgList &Args,
400 const char *LinkingOutput) const {
401 const Driver &D = getToolChain().getDriver();
402
403 // Silence warning for "clang -g foo.o -o foo"
404 Args.ClaimAllArgs(options::OPT_g_Group);
405 // and "clang -emit-llvm foo.o -o foo"
406 Args.ClaimAllArgs(options::OPT_emit_llvm);
407 // and for "clang -w foo.o -o foo". Other warning options are already
408 // handled somewhere else.
409 Args.ClaimAllArgs(options::OPT_w);
410 // Silence warnings when linking C code with a C++ '-stdlib' argument.
411 Args.ClaimAllArgs(options::OPT_stdlib_EQ);
412
413 // ar tool command "llvm-ar <options> <output_file> <input_files>".
414 ArgStringList CmdArgs;
415 // Create and insert file members with a deterministic index.
416 CmdArgs.push_back("rcsD");
417 CmdArgs.push_back(Output.getFilename());
418
419 for (const auto &II : Inputs) {
420 if (II.isFilename()) {
421 CmdArgs.push_back(II.getFilename());
422 }
423 }
424
425 // Delete old output archive file if it already exists before generating a new
426 // archive file.
427 const char *OutputFileName = Output.getFilename();
428 if (Output.isFilename() && llvm::sys::fs::exists(OutputFileName)) {
429 if (std::error_code EC = llvm::sys::fs::remove(OutputFileName)) {
430 D.Diag(diag::err_drv_unable_to_remove_file) << EC.message();
431 return;
432 }
433 }
434
435 const char *Exec = Args.MakeArgString(getToolChain().GetStaticLibToolPath());
436 C.addCommand(std::make_unique<Command>(JA, *this,
438 Exec, CmdArgs, Inputs, Output));
439}
440
442 const InputInfo &Output,
443 const InputInfoList &Inputs,
444 const ArgList &Args,
445 const char *LinkingOutput) const {
446 ArgStringList CmdArgs;
447
448 auto &TC = static_cast<const toolchains::BareMetal &>(getToolChain());
449 const Driver &D = getToolChain().getDriver();
450 const llvm::Triple::ArchType Arch = TC.getArch();
451 const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
452
453 AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
454
455 CmdArgs.push_back("-Bstatic");
456
457 if (TC.getTriple().isRISCV() && Args.hasArg(options::OPT_mno_relax))
458 CmdArgs.push_back("--no-relax");
459
460 if (Triple.isARM() || Triple.isThumb()) {
461 bool IsBigEndian = arm::isARMBigEndian(Triple, Args);
462 if (IsBigEndian)
463 arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
464 CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
465 } else if (Triple.isAArch64()) {
466 CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
467 }
468
469 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
470 options::OPT_r)) {
471 CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o")));
472 }
473
474 Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
475 options::OPT_s, options::OPT_t, options::OPT_r});
476
477 TC.AddFilePathLibArgs(Args, CmdArgs);
478
479 for (const auto &LibPath : TC.getLibraryPaths())
480 CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-L", LibPath)));
481
482 if (TC.ShouldLinkCXXStdlib(Args)) {
483 bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
484 !Args.hasArg(options::OPT_static);
485 if (OnlyLibstdcxxStatic)
486 CmdArgs.push_back("-Bstatic");
487 TC.AddCXXStdlibLibArgs(Args, CmdArgs);
488 if (OnlyLibstdcxxStatic)
489 CmdArgs.push_back("-Bdynamic");
490 CmdArgs.push_back("-lm");
491 }
492
493 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
494 AddRunTimeLibs(TC, D, CmdArgs, Args);
495
496 CmdArgs.push_back("-lc");
497 }
498
499 if (D.isUsingLTO()) {
500 assert(!Inputs.empty() && "Must have at least one input.");
501 // Find the first filename InputInfo object.
502 auto Input = llvm::find_if(
503 Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
504 if (Input == Inputs.end())
505 // For a very rare case, all of the inputs to the linker are
506 // InputArg. If that happens, just use the first InputInfo.
507 Input = Inputs.begin();
508
509 addLTOOptions(TC, Args, CmdArgs, Output, *Input,
510 D.getLTOMode() == LTOK_Thin);
511 }
512 if (TC.getTriple().isRISCV())
513 CmdArgs.push_back("-X");
514
515 // The R_ARM_TARGET2 relocation must be treated as R_ARM_REL32 on arm*-*-elf
516 // and arm*-*-eabi (the default is R_ARM_GOT_PREL, used on arm*-*-linux and
517 // arm*-*-*bsd).
518 if (arm::isARMEABIBareMetal(TC.getTriple()))
519 CmdArgs.push_back("--target2=rel");
520
521 CmdArgs.push_back("-o");
522 CmdArgs.push_back(Output.getFilename());
523
524 C.addCommand(std::make_unique<Command>(
526 Args.MakeArgString(TC.GetLinkerPath()), CmdArgs, Inputs, Output));
527}
528
529// BareMetal toolchain allows all sanitizers where the compiler generates valid
530// code, ignoring all runtime library support issues on the assumption that
531// baremetal targets typically implement their own runtime support.
533 const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
534 const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 ||
535 getTriple().getArch() == llvm::Triple::aarch64_be;
536 const bool IsRISCV64 = getTriple().getArch() == llvm::Triple::riscv64;
538 Res |= SanitizerKind::Address;
539 Res |= SanitizerKind::KernelAddress;
540 Res |= SanitizerKind::PointerCompare;
541 Res |= SanitizerKind::PointerSubtract;
542 Res |= SanitizerKind::Fuzzer;
543 Res |= SanitizerKind::FuzzerNoLink;
544 Res |= SanitizerKind::Vptr;
545 Res |= SanitizerKind::SafeStack;
546 Res |= SanitizerKind::Thread;
547 Res |= SanitizerKind::Scudo;
548 if (IsX86_64 || IsAArch64 || IsRISCV64) {
549 Res |= SanitizerKind::HWAddress;
550 Res |= SanitizerKind::KernelHWAddress;
551 }
552 return Res;
553}
StringRef P
static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple)
Definition: BareMetal.cpp:100
static bool isRISCVBareMetal(const llvm::Triple &Triple)
Definition: BareMetal.cpp:146
static std::optional< llvm::SmallString< 128 > > getMultilibConfigPath(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
Definition: BareMetal.cpp:208
static constexpr llvm::StringLiteral MultilibFilename
Definition: BareMetal.cpp:205
static bool isPPCBareMetal(const llvm::Triple &Triple)
Is the triple powerpc[64][le]-*-none-eabi?
Definition: BareMetal.cpp:160
static void findMultilibsFromYAML(const ToolChain &TC, const Driver &D, StringRef MultilibPath, const ArgList &Args, DetectedMultilibs &Result)
Definition: BareMetal.cpp:165
static bool findRISCVMultilibs(const Driver &D, const llvm::Triple &TargetTriple, const ArgList &Args, DetectedMultilibs &Result)
Definition: BareMetal.cpp:36
static bool isAArch64BareMetal(const llvm::Triple &Triple)
Is the triple {aarch64.aarch64_be}-none-elf?
Definition: BareMetal.cpp:132
const Decl * D
IndirectLocalPath & Path
llvm::MachO::Target Target
Definition: MachO.h:51
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
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
const char * getFilename() const
Definition: InputInfo.h:83
bool isFilename() const
Definition: InputInfo.h:75
This corresponds to a single GCC multilib, or a segment of one controlled by a command line flag.
MultilibBuilder & flag(StringRef Flag, bool Disallow=false)
Add a flag to the flags list Flag must be a flag accepted by the driver.
This class can be used to create a MultilibSet, and contains helper functions to add combinations of ...
MultilibSetBuilder & Either(const MultilibBuilder &M1, const MultilibBuilder &M2)
Add a set of mutually incompatible Multilib segments.
static llvm::ErrorOr< MultilibSet > parseYaml(llvm::MemoryBufferRef, llvm::SourceMgr::DiagHandlerTy=nullptr, void *DiagHandlerCtxt=nullptr)
Definition: Multilib.cpp:296
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag.
Definition: Multilib.h:35
const std::string & getErrorMessage() const
Definition: Multilib.h:99
const flags_list & flags() const
Get the flags that indicate or contraindicate this multilib's use All elements begin with either '-' ...
Definition: Multilib.h:82
std::vector< std::string > flags_list
Definition: Multilib.h:37
bool isError() const
Definition: Multilib.h:97
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:1265
path_list & getFilePaths()
Definition: ToolChain.h:294
const Driver & getDriver() const
Definition: ToolChain.h:252
virtual std::string detectLibcxxVersion(StringRef IncludePath) const
Definition: ToolChain.cpp:1312
Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const
Get flags suitable for multilib selection, based on the provided clang command line arguments.
Definition: ToolChain.cpp:332
path_list & getProgramPaths()
Definition: ToolChain.h:297
const llvm::Triple & getTriple() const
Definition: ToolChain.h:254
std::optional< std::string > getStdlibIncludePath() const
Definition: ToolChain.cpp:895
std::string getTripleString() const
Definition: ToolChain.h:277
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:1239
llvm::SmallVector< Multilib > SelectedMultilibs
Definition: ToolChain.h:201
path_list & getLibraryPaths()
Definition: ToolChain.h:291
virtual SanitizerMask getSupportedSanitizers() const
Return sanitizers which are available in this toolchain.
Definition: ToolChain.cpp:1456
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
std::string computeSysRoot() const override
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
Definition: BareMetal.cpp:261
BareMetal(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: BareMetal.cpp:113
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: BareMetal.cpp:532
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: BareMetal.cpp:307
static bool handlesTarget(const llvm::Triple &Triple)
Definition: BareMetal.cpp:248
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: BareMetal.cpp:273
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: BareMetal.cpp:301
Tool * buildStaticLibTool() const override
Definition: BareMetal.cpp:257
void findMultilibs(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: BareMetal.cpp:224
Tool * buildLinker() const override
Definition: BareMetal.cpp:253
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: BareMetal.cpp:441
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: BareMetal.cpp:396
void appendBE8LinkFlag(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple)
bool isARMEABIBareMetal(const llvm::Triple &Triple)
Is the triple {arm,armeb,thumb,thumbeb}-none-none-{eabi,eabihf} ?
Definition: ARM.cpp:56
bool isARMBigEndian(const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
std::string getRISCVArch(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
Definition: RISCV.cpp:249
StringRef getRISCVABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
void addMultilibFlag(bool Enabled, const StringRef Flag, Multilib::flags_list &Flags)
Flag must be a flag accepted by the driver.
void AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output, const InputInfo &Input, bool IsThinLTO)
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
#define true
Definition: stdbool.h:25
static constexpr ResponseFileSupport AtFileCurCP()
Definition: Job.h:92
Struct to store and manipulate GCC versions.
Definition: Gnu.h:162
int Major
The parsed major, minor, and patch numbers.
Definition: Gnu.h:167
std::string Text
The unparsed text of the version.
Definition: Gnu.h:164
static GCCVersion Parse(StringRef VersionText)
Parse a GCCVersion object out of a string of text.
Definition: Gnu.cpp:2126