clang 20.0.0git
BareMetal.h
Go to the documentation of this file.
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"
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
52 return ToolChain::RLT_CompilerRT;
53 }
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:
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
const Decl * D
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
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
bool isBareMetal() const override
isBareMetal - Is this a bare metal target.
Definition: BareMetal.h:39
RuntimeLibType GetDefaultRuntimeLibType() const override
GetDefaultRuntimeLibType - Get the default runtime library variant to use.
Definition: BareMetal.h:51
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: BareMetal.h:46
bool HasNativeLLVMSupport() const override
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
Definition: BareMetal.h:41
bool useIntegratedAs() const override
Check if the toolchain should use the integrated assembler.
Definition: BareMetal.h:38
const char * getDefaultLinker() const override
GetDefaultLinker - Get the default linker to use.
Definition: BareMetal.h:58
CXXStdlibType GetDefaultCXXStdlibType() const override
Definition: BareMetal.h:54
StringRef getOSLibName() const override
Definition: BareMetal.h:49
bool isCrossCompiling() const override
Returns true if the toolchain is targeting a non-native architecture.
Definition: BareMetal.h:40
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition: BareMetal.h:47
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: BareMetal.h:42
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition: BareMetal.h:43
bool hasIntegratedCPP() const override
Definition: BareMetal.h:106
The JSON file list parser is used to communicate input to InstallAPI.