-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0080-Xtensa-Add-rtlib-option-support-for-ESP-Xtensa.patch
120 lines (109 loc) · 4.85 KB
/
0080-Xtensa-Add-rtlib-option-support-for-ESP-Xtensa.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
From 24514d08fdce934ff215ff54e7d597b176b4d1a3 Mon Sep 17 00:00:00 2001
From: Andrei Safronov <safronov@espressif.com>
Date: Wed, 5 Apr 2023 00:59:18 +0300
Subject: [PATCH 080/158] [Xtensa]: Add '--rtlib' option support for ESP Xtensa
toolchain
---
clang/lib/Driver/ToolChains/Xtensa.cpp | 62 ++++++++++++++++++++------
clang/lib/Driver/ToolChains/Xtensa.h | 2 +
2 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Xtensa.cpp b/clang/lib/Driver/ToolChains/Xtensa.cpp
index 2eb40d668e6f..f41b1db3c663 100644
--- a/clang/lib/Driver/ToolChains/Xtensa.cpp
+++ b/clang/lib/Driver/ToolChains/Xtensa.cpp
@@ -151,6 +151,11 @@ XtensaToolChain::GetCXXStdlibType(const ArgList &Args) const {
return ToolChain::CST_Libstdcxx;
}
+ToolChain::UnwindLibType
+XtensaToolChain::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
+ return ToolChain::UNW_None;
+}
+
const StringRef XtensaToolChain::GetTargetCPUVersion(const ArgList &Args) {
if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
StringRef CPUName = A->getValue();
@@ -208,33 +213,62 @@ void xtensa::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {
- const auto &TC =
- static_cast<const toolchains::XtensaToolChain &>(getToolChain());
+ ArgStringList CmdArgs;
+ bool WantCRTs =
+ !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
+ const auto &ToolChain =
+ static_cast<const toolchains::XtensaToolChain &>(getToolChain());
- if (TC.GCCToolchainName == "")
+ if (ToolChain.GCCToolchainName == "")
llvm_unreachable("Unable to find Xtensa GCC linker");
- SmallString<128> Linker(TC.GCCToolchainDir);
+ SmallString<128> Linker(ToolChain.GCCToolchainDir);
llvm::sys::path::append(Linker, "bin",
- TC.GCCToolchainName + "-" + getShortName());
- ArgStringList CmdArgs;
+ ToolChain.GCCToolchainName + "-" + getShortName());
- Args.AddAllArgs(CmdArgs, options::OPT_L);
- TC.AddFilePathLibArgs(Args, CmdArgs);
+ const char *crtbegin, *crtend;
+ auto RuntimeLib = ToolChain.GetRuntimeLibType(Args);
+ if (RuntimeLib == ToolChain::RLT_Libgcc) {
+ crtbegin = "crtbegin.o";
+ crtend = "crtend.o";
+ } else {
+ assert (RuntimeLib == ToolChain::RLT_CompilerRT);
+ crtbegin = ToolChain.getCompilerRTArgString(Args, "crtbegin",
+ ToolChain::FT_Object);
+ crtend = ToolChain.getCompilerRTArgString(Args, "crtend",
+ ToolChain::FT_Object);
+ }
+ if (WantCRTs) {
+ // TODO: The crt0.o is not used for esp targets, but maybe used in
+ // future for other vendors
+ //CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
+ }
+
+ AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+
+ Args.AddAllArgs(CmdArgs, options::OPT_L);
+ ToolChain.AddFilePathLibArgs(Args, CmdArgs);
Args.AddAllArgs(CmdArgs,
{options::OPT_T_Group, options::OPT_e, options::OPT_s,
options::OPT_t, options::OPT_u_Group});
+
+ if (!Args.hasArg(options::OPT_nostdlib) &&
+ !Args.hasArg(options::OPT_nodefaultlibs)) {
+ if (ToolChain.ShouldLinkCXXStdlib(Args))
+ ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
+ AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);
+ }
- AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
-
- CmdArgs.push_back("-lgcc");
+ if (WantCRTs)
+ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend)));
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- C.addCommand(
- std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileCurCP(),
- Args.MakeArgString(Linker), CmdArgs, Inputs));
+ C.addCommand(std::make_unique<Command>(
+ JA, *this, ResponseFileSupport::AtFileCurCP(), Args.MakeArgString(Linker),
+ CmdArgs, Inputs));
}
// Get features by CPU name
diff --git a/clang/lib/Driver/ToolChains/Xtensa.h b/clang/lib/Driver/ToolChains/Xtensa.h
index 0457d23ff42c..d645b55b5476 100644
--- a/clang/lib/Driver/ToolChains/Xtensa.h
+++ b/clang/lib/Driver/ToolChains/Xtensa.h
@@ -35,6 +35,8 @@ public:
addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
+ UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const override;
+
bool IsIntegratedAssemblerDefault() const override {
return (IsIntegratedAsm || (GCCToolchainName == ""));
}
--
2.40.1