xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/BareMetal.h (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
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   std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args,
37                                       StringRef Component,
38                                       FileType Type = ToolChain::FT_Static,
39                                       bool AddArch = true) const override;
40 
41 public:
42   bool useIntegratedAs() const override { return true; }
43   bool isCrossCompiling() const override { return true; }
44   bool isPICDefault() const override { return false; }
45   bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
46     return false;
47   }
48   bool isPICDefaultForced() const override { return false; }
49   bool SupportsProfiling() const override { return false; }
50 
51   StringRef getOSLibName() const override { return "baremetal"; }
52 
53   std::string getCompilerRTPath() const override;
54 
55   RuntimeLibType GetDefaultRuntimeLibType() const override {
56     return ToolChain::RLT_CompilerRT;
57   }
58   CXXStdlibType GetDefaultCXXStdlibType() const override {
59     return ToolChain::CST_Libcxx;
60   }
61 
62   const char *getDefaultLinker() const override { return "ld.lld"; }
63 
64   std::string getRuntimesDir() const;
65   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
66                                  llvm::opt::ArgStringList &CC1Args) const override;
67   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
68                              llvm::opt::ArgStringList &CC1Args,
69                              Action::OffloadKind DeviceOffloadKind) const override;
70   void AddClangCXXStdlibIncludeArgs(
71       const llvm::opt::ArgList &DriverArgs,
72       llvm::opt::ArgStringList &CC1Args) const override;
73   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
74                            llvm::opt::ArgStringList &CmdArgs) const override;
75   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
76                          llvm::opt::ArgStringList &CmdArgs) const;
77   std::string computeSysRoot() const override;
78 };
79 
80 } // namespace toolchains
81 
82 namespace tools {
83 namespace baremetal {
84 
85 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
86 public:
87   Linker(const ToolChain &TC) : Tool("baremetal::Linker", "ld.lld", TC) {}
88   bool isLinkJob() const override { return true; }
89   bool hasIntegratedCPP() const override { return false; }
90   void ConstructJob(Compilation &C, const JobAction &JA,
91                     const InputInfo &Output, const InputInfoList &Inputs,
92                     const llvm::opt::ArgList &TCArgs,
93                     const char *LinkingOutput) const override;
94 };
95 
96 } // namespace baremetal
97 } // namespace tools
98 
99 } // namespace driver
100 } // namespace clang
101 
102 #endif
103