xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/BareMetal.h (revision 77013d11e6483b970af25e13c9b892075742f7e5)
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 
17 namespace clang {
18 namespace driver {
19 
20 namespace toolchains {
21 
22 class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
23 public:
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 
33 protected:
34   Tool *buildLinker() const override;
35 
36 public:
37   bool useIntegratedAs() const override { return true; }
38   bool isCrossCompiling() const override { return true; }
39   bool isPICDefault() const override { return false; }
40   bool isPIEDefault() const override { return false; }
41   bool isPICDefaultForced() const override { return false; }
42   bool SupportsProfiling() const override { return false; }
43 
44   StringRef getOSLibName() const override { return "baremetal"; }
45 
46   std::string getCompilerRTPath() const override;
47   std::string getCompilerRTBasename(const llvm::opt::ArgList &Args,
48                                     StringRef Component,
49                                     FileType Type = ToolChain::FT_Static,
50                                     bool AddArch = true) const override;
51 
52   RuntimeLibType GetDefaultRuntimeLibType() const override {
53     return ToolChain::RLT_CompilerRT;
54   }
55   CXXStdlibType GetDefaultCXXStdlibType() const override {
56     return ToolChain::CST_Libcxx;
57   }
58 
59   const char *getDefaultLinker() const override { return "ld.lld"; }
60 
61   std::string getRuntimesDir() const;
62   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
63                                  llvm::opt::ArgStringList &CC1Args) const override;
64   void 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 };
76 
77 } // namespace toolchains
78 
79 namespace tools {
80 namespace baremetal {
81 
82 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
83 public:
84   Linker(const ToolChain &TC) : Tool("baremetal::Linker", "ld.lld", TC) {}
85   bool isLinkJob() const override { return true; }
86   bool hasIntegratedCPP() const override { return false; }
87   void ConstructJob(Compilation &C, const JobAction &JA,
88                     const InputInfo &Output, const InputInfoList &Inputs,
89                     const llvm::opt::ArgList &TCArgs,
90                     const char *LinkingOutput) const override;
91 };
92 
93 } // namespace baremetal
94 } // namespace tools
95 
96 } // namespace driver
97 } // namespace clang
98 
99 #endif
100