1//===--- BareMetal.h - Bare Metal Tool and 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#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
10#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
11
12#include "clang/Driver/Tool.h"
13#include "clang/Driver/ToolChain.h"
14
15#include <string>
16
17namespace clang {
18namespace driver {
19
20namespace toolchains {
21
22class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
23public:
24 BareMetal(const Driver &D, const llvm::Triple &Triple,
25 const llvm::opt::ArgList &Args);
26 ~BareMetal() override = default;
27
28 static bool handlesTarget(const llvm::Triple &Triple);
29
30 void findMultilibs(const Driver &D, const llvm::Triple &Triple,
31 const llvm::opt::ArgList &Args);
32
33protected:
34 Tool *buildLinker() const override;
35 Tool *buildStaticLibTool() const override;
36
37public:
38 bool useIntegratedAs() const override { return true; }
39 bool isBareMetal() const override { return true; }
40 bool isCrossCompiling() const override { return true; }
41 bool HasNativeLLVMSupport() const override { return true; }
42 bool isPICDefault() const override { return false; }
43 bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
44 return false;
45 }
46 bool isPICDefaultForced() const override { return false; }
47 bool SupportsProfiling() const override { return false; }
48
49 StringRef getOSLibName() const override { return "baremetal"; }
50
51 RuntimeLibType GetDefaultRuntimeLibType() const override {
52 return ToolChain::RLT_CompilerRT;
53 }
54 CXXStdlibType GetDefaultCXXStdlibType() const override {
55 return ToolChain::CST_Libcxx;
56 }
57
58 const char *getDefaultLinker() const override { return "ld.lld"; }
59
60 void
61 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
62 llvm::opt::ArgStringList &CC1Args) const override;
63 void
64 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
65 llvm::opt::ArgStringList &CC1Args,
66 Action::OffloadKind DeviceOffloadKind) const override;
67 void AddClangCXXStdlibIncludeArgs(
68 const llvm::opt::ArgList &DriverArgs,
69 llvm::opt::ArgStringList &CC1Args) const override;
70 void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
71 llvm::opt::ArgStringList &CmdArgs) const override;
72 void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
73 llvm::opt::ArgStringList &CmdArgs) const;
74 std::string computeSysRoot() const override;
75 SanitizerMask getSupportedSanitizers() const override;
76
77private:
78 using OrderedMultilibs =
79 llvm::iterator_range<llvm::SmallVector<Multilib>::const_reverse_iterator>;
80 OrderedMultilibs getOrderedMultilibs() const;
81};
82
83} // namespace toolchains
84
85namespace tools {
86namespace baremetal {
87
88class LLVM_LIBRARY_VISIBILITY StaticLibTool : public Tool {
89public:
90 StaticLibTool(const ToolChain &TC)
91 : Tool("baremetal::StaticLibTool", "llvm-ar", TC) {}
92
93 bool hasIntegratedCPP() const override { return false; }
94 bool isLinkJob() const override { return true; }
95
96 void ConstructJob(Compilation &C, const JobAction &JA,
97 const InputInfo &Output, const InputInfoList &Inputs,
98 const llvm::opt::ArgList &TCArgs,
99 const char *LinkingOutput) const override;
100};
101
102class LLVM_LIBRARY_VISIBILITY Linker final : public Tool {
103public:
104 Linker(const ToolChain &TC) : Tool("baremetal::Linker", "ld.lld", TC) {}
105 bool isLinkJob() const override { return true; }
106 bool hasIntegratedCPP() const override { return false; }
107 void ConstructJob(Compilation &C, const JobAction &JA,
108 const InputInfo &Output, const InputInfoList &Inputs,
109 const llvm::opt::ArgList &TCArgs,
110 const char *LinkingOutput) const override;
111};
112
113} // namespace baremetal
114} // namespace tools
115
116} // namespace driver
117} // namespace clang
118
119#endif
120

source code of clang/lib/Driver/ToolChains/BareMetal.h