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 Tool *buildStaticLibTool() const override; 36 37 public: 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 std::string computeSysRoot() const override; 71 SanitizerMask getSupportedSanitizers() const override; 72 73 SmallVector<std::string> 74 getMultilibMacroDefinesStr(llvm::opt::ArgList &Args) const override; 75 76 private: 77 using OrderedMultilibs = 78 llvm::iterator_range<llvm::SmallVector<Multilib>::const_reverse_iterator>; 79 OrderedMultilibs getOrderedMultilibs() const; 80 81 std::string SysRoot; 82 83 SmallVector<std::string> MultilibMacroDefines; 84 }; 85 86 } // namespace toolchains 87 88 namespace tools { 89 namespace baremetal { 90 91 class LLVM_LIBRARY_VISIBILITY StaticLibTool : public Tool { 92 public: 93 StaticLibTool(const ToolChain &TC) 94 : Tool("baremetal::StaticLibTool", "llvm-ar", TC) {} 95 96 bool hasIntegratedCPP() const override { return false; } 97 bool isLinkJob() const override { return true; } 98 99 void ConstructJob(Compilation &C, const JobAction &JA, 100 const InputInfo &Output, const InputInfoList &Inputs, 101 const llvm::opt::ArgList &TCArgs, 102 const char *LinkingOutput) const override; 103 }; 104 105 class LLVM_LIBRARY_VISIBILITY Linker final : public Tool { 106 public: 107 Linker(const ToolChain &TC) : Tool("baremetal::Linker", "ld.lld", TC) {} 108 bool isLinkJob() const override { return true; } 109 bool hasIntegratedCPP() const override { return false; } 110 void ConstructJob(Compilation &C, const JobAction &JA, 111 const InputInfo &Output, const InputInfoList &Inputs, 112 const llvm::opt::ArgList &TCArgs, 113 const char *LinkingOutput) const override; 114 }; 115 116 } // namespace baremetal 117 } // namespace tools 118 119 } // namespace driver 120 } // namespace clang 121 122 #endif 123