-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0079-Xtensa-Improve-Xtensa-multilib-support-in-clang.patch
511 lines (481 loc) · 24.7 KB
/
0079-Xtensa-Improve-Xtensa-multilib-support-in-clang.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
From d80ada05e4e28c4a462ccd4a31325dd3c3499d1f Mon Sep 17 00:00:00 2001
From: Andrei Safronov <[email protected]>
Date: Wed, 5 Apr 2023 00:59:18 +0300
Subject: [PATCH 079/158] [Xtensa] Improve Xtensa multilib support in clang.
Use GCCInstallationDetector in Xtensa toolchain instead of XtensaGCCToolchainDetector for
initialization of the gcc environment. Add xtensa toolchain test tree with multilib
subdirectories.
---
clang/lib/Driver/ToolChains/Gnu.cpp | 42 ++++-
clang/lib/Driver/ToolChains/Xtensa.cpp | 174 ++++++------------
clang/lib/Driver/ToolChains/Xtensa.h | 23 +--
.../bin/xtensa-esp32-elf-ld | 1 +
.../lib/gcc/xtensa-esp32-elf/8.4.0/crtbegin.o | 0
.../lib/gcc/xtensa-esp32-elf/8.4.0/crtend.o | 0
.../8.4.0/esp32-psram/crtbegin.o | 0
.../8.4.0/esp32-psram/crtend.o | 0
.../8.4.0/esp32-psram/no-rtti/crtbegin.o | 0
.../8.4.0/esp32-psram/no-rtti/crtend.o | 0
.../xtensa-esp32-elf/8.4.0/no-rtti/crtbegin.o | 0
.../xtensa-esp32-elf/8.4.0/no-rtti/crtend.o | 0
.../xtensa-esp32-elf/lib/crt0.o | 0
.../xtensa-esp32-elf/lib/esp32-psram/crt0.o | 0
.../lib/esp32-psram/no-rtti/crt0.o | 0
.../xtensa-esp32-elf/lib/no-rtti/crt0.o | 0
clang/test/Driver/xtensa-toolchain.c | 42 +++++
17 files changed, 146 insertions(+), 136 deletions(-)
create mode 100755 clang/test/Driver/Inputs/multilib_xtensa_tree/bin/xtensa-esp32-elf-ld
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/crtbegin.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/crtend.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/crtbegin.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/crtend.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/no-rtti/crtbegin.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/no-rtti/crtend.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/no-rtti/crtbegin.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/no-rtti/crtend.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/crt0.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/esp32-psram/crt0.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/esp32-psram/no-rtti/crt0.o
create mode 100644 clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/no-rtti/crt0.o
create mode 100644 clang/test/Driver/xtensa-toolchain.c
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index ed66a0071c0c..21ee62e94ecb 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1772,6 +1772,42 @@ static void findRISCVMultilibs(const Driver &D,
Result.Multilibs = RISCVMultilibs;
}
+static void findXtensaMultilibs(const Driver &D,
+ const llvm::Triple &TargetTriple, StringRef Path,
+ const ArgList &Args, DetectedMultilibs &Result) {
+
+ MultilibSet XtensaMultilibs = MultilibSet();
+ bool IsESP32 = Args.getLastArgValue(options::OPT_mcpu_EQ, "esp32").equals("esp32");
+
+ XtensaMultilibs.push_back(Multilib());
+ if (IsESP32)
+ XtensaMultilibs.push_back(Multilib("esp32-psram", {}, {}, 2)
+ .flag("+mfix-esp32-psram-cache-issue"));
+
+ XtensaMultilibs.push_back(
+ Multilib("no-rtti", {}, {}, 1).flag("+fno-rtti").flag("-frtti"));
+
+ if (IsESP32)
+ XtensaMultilibs.push_back(Multilib("esp32-psram/no-rtti", {}, {}, 3)
+ .flag("+fno-rtti")
+ .flag("-frtti")
+ .flag("+mfix-esp32-psram-cache-issue"));
+
+ Multilib::flags_list Flags;
+ addMultilibFlag(
+ Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti, false), "frtti",
+ Flags);
+
+ if (IsESP32)
+ addMultilibFlag(Args.hasFlag(options::OPT_mfix_esp32_psram_cache_issue,
+ options::OPT_mfix_esp32_psram_cache_issue,
+ false),
+ "mfix-esp32-psram-cache-issue", Flags);
+
+ if (XtensaMultilibs.select(Flags, Result.SelectedMultilib))
+ Result.Multilibs = XtensaMultilibs;
+}
+
static bool findBiarchMultilibs(const Driver &D,
const llvm::Triple &TargetTriple,
StringRef Path, const ArgList &Args,
@@ -2339,7 +2375,9 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
"s390x-suse-linux", "s390x-redhat-linux"};
static const char *const XtensaLibDirs[] = {"/lib"};
- static const char *const XtensaTriples[] = {"xtensa-unknown-elf"};
+ static const char *const XtensaTriples[] = {
+ "xtensa-unknown-elf", "xtensa-esp32-elf", "xtensa-esp32s2-elf",
+ "xtensa-esp32s3-elf"};
using std::begin;
using std::end;
@@ -2654,6 +2692,8 @@ bool Generic_GCC::GCCInstallationDetector::ScanGCCForMultilibs(
findMSP430Multilibs(D, TargetTriple, Path, Args, Detected);
} else if (TargetArch == llvm::Triple::avr) {
// AVR has no multilibs.
+ } else if (TargetArch == llvm::Triple::xtensa) {
+ findXtensaMultilibs(D, TargetTriple, Path, Args, Detected);
} else if (!findBiarchMultilibs(D, TargetTriple, Path, Args,
NeedsBiarchSuffix, Detected)) {
return false;
diff --git a/clang/lib/Driver/ToolChains/Xtensa.cpp b/clang/lib/Driver/ToolChains/Xtensa.cpp
index c8b663204913..2eb40d668e6f 100644
--- a/clang/lib/Driver/ToolChains/Xtensa.cpp
+++ b/clang/lib/Driver/ToolChains/Xtensa.cpp
@@ -10,7 +10,6 @@
#include "Xtensa.h"
#include "CommonArgs.h"
-#include "clang/Driver/InputInfo.h"
#include "clang/Basic/Cuda.h"
#include "clang/Config/config.h"
#include "clang/Driver/Compilation.h"
@@ -32,58 +31,26 @@ using namespace llvm::opt;
using tools::addMultilibFlag;
-XtensaGCCToolchainDetector::XtensaGCCToolchainDetector(
- const Driver &D, const llvm::Triple &HostTriple,
- const llvm::opt::ArgList &Args) {
- std::string InstalledDir;
- InstalledDir = D.getInstalledDir();
- StringRef CPUName = XtensaToolChain::GetTargetCPUVersion(Args);
- std::string Dir;
- std::string ToolchainName;
- std::string ToolchainDir;
-
- if (CPUName.equals("esp32"))
- ToolchainName = "xtensa-esp32-elf";
- else if (CPUName.equals("esp32-s2") || CPUName.equals("esp32s2"))
- ToolchainName = "xtensa-esp32s2-elf";
- else if (CPUName.equals("esp32-s3") || CPUName.equals("esp32s3"))
- ToolchainName = "xtensa-esp32s3-elf";
- else if (CPUName.equals("esp8266"))
- ToolchainName = "xtensa-lx106-elf";
-
- Slash = llvm::sys::path::get_separator().str();
-
- ToolchainDir = InstalledDir + Slash + "..";
- Dir = ToolchainDir + Slash + "lib" + Slash + "gcc" + Slash + ToolchainName +
- Slash;
- GCCLibAndIncVersion = "";
-
- if (D.getVFS().exists(Dir)) {
- std::error_code EC;
- for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin(Dir, EC), LE;
- !EC && LI != LE; LI = LI.increment(EC)) {
- StringRef VersionText = llvm::sys::path::filename(LI->path());
- auto GCCVersion = Generic_GCC::GCCVersion::Parse(VersionText);
- if (GCCVersion.Major == -1)
- continue;
- GCCLibAndIncVersion = GCCVersion.Text;
- }
- if (GCCLibAndIncVersion == "")
- llvm_unreachable("Unexpected Xtensa GCC toolchain version");
-
- } else {
- // Unable to find Xtensa GCC toolchain;
- GCCToolchainName = "";
- return;
- }
- GCCToolchainDir = ToolchainDir;
- GCCToolchainName = ToolchainName;
-}
-
/// Xtensa Toolchain
XtensaToolChain::XtensaToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
- : Generic_ELF(D, Triple, Args), XtensaGCCToolchain(D, getTriple(), Args) {
+ : Generic_ELF(D, Triple, Args) {
+
+ GCCInstallation.init(Triple, Args);
+
+ if (!GCCInstallation.isValid()) {
+ llvm_unreachable("Unexpected Xtensa GCC toolchain version");
+ }
+
+ Multilibs = GCCInstallation.getMultilibs();
+ SelectedMultilib = GCCInstallation.getMultilib();
+
+ GCCLibAndIncVersion = GCCInstallation.getVersion().Text;
+ GCCToolchainName = GCCInstallation.getTriple().str();
+ SmallString<128> Path(GCCInstallation.getParentLibPath());
+ llvm::sys::path::append(Path, "..");
+ GCCToolchainDir = Path.c_str();
+
for (auto *A : Args) {
std::string Str = A->getAsString(Args);
if (!Str.compare("-mlongcalls"))
@@ -110,45 +77,18 @@ XtensaToolChain::XtensaToolChain(const Driver &D, const llvm::Triple &Triple,
IsIntegratedAsm = false;
}
- bool IsESP32 = XtensaToolChain::GetTargetCPUVersion(Args).equals("esp32");
- Multilibs.push_back(Multilib());
- if (IsESP32)
- Multilibs.push_back(Multilib("esp32-psram", {}, {}, 2)
- .flag("+mfix-esp32-psram-cache-issue"));
-
- Multilibs.push_back(
- Multilib("no-rtti", {}, {}, 1).flag("+fno-rtti").flag("-frtti"));
-
- if (IsESP32)
- Multilibs.push_back(Multilib("esp32-psram/no-rtti", {}, {}, 3)
- .flag("+fno-rtti")
- .flag("-frtti")
- .flag("+mfix-esp32-psram-cache-issue"));
-
- Multilib::flags_list Flags;
- addMultilibFlag(
- Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti, false), "frtti",
- Flags);
-
- if (IsESP32)
- addMultilibFlag(Args.hasFlag(options::OPT_mfix_esp32_psram_cache_issue,
- options::OPT_mfix_esp32_psram_cache_issue,
- false),
- "mfix-esp32-psram-cache-issue", Flags);
-
- Multilibs.select(Flags, SelectedMultilib);
-
- const std::string Slash = XtensaGCCToolchain.Slash;
- std::string Libs =
- XtensaGCCToolchain.GCCToolchainDir + Slash + "lib" + Slash + "gcc" +
- Slash + XtensaGCCToolchain.GCCToolchainName + Slash +
- XtensaGCCToolchain.GCCLibAndIncVersion + SelectedMultilib.gccSuffix();
- getFilePaths().push_back(Libs);
-
- Libs = XtensaGCCToolchain.GCCToolchainDir + Slash +
- XtensaGCCToolchain.GCCToolchainName + Slash + "lib" +
- SelectedMultilib.gccSuffix();
- getFilePaths().push_back(Libs);
+ SmallString<128> Libs1(GCCToolchainDir);
+ llvm::sys::path::append(Libs1, "lib", "gcc", GCCToolchainName,
+ GCCLibAndIncVersion);
+ if (!SelectedMultilib.gccSuffix().empty())
+ llvm::sys::path::append(Libs1, SelectedMultilib.gccSuffix());
+ getFilePaths().push_back(Libs1.c_str());
+
+ SmallString<128> Libs2(GCCToolchainDir);
+ llvm::sys::path::append(Libs2, GCCToolchainName, "lib");
+ if (!SelectedMultilib.gccSuffix().empty())
+ llvm::sys::path::append(Libs2, SelectedMultilib.gccSuffix());
+ getFilePaths().push_back(Libs2.c_str());
}
Tool *XtensaToolChain::buildLinker() const {
@@ -165,17 +105,15 @@ void XtensaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
DriverArgs.hasArg(options::OPT_nostdlibinc))
return;
- if (!XtensaGCCToolchain.IsValid())
+ if (!GCCInstallation.isValid())
return;
- std::string Slash = XtensaGCCToolchain.Slash;
-
- std::string Path1 = getDriver().ResourceDir.c_str() + Slash + "include";
- std::string Path2 = XtensaGCCToolchain.GCCToolchainDir + Slash +
- XtensaGCCToolchain.GCCToolchainName + Slash +
- "sys-include";
- std::string Path3 = XtensaGCCToolchain.GCCToolchainDir + Slash +
- XtensaGCCToolchain.GCCToolchainName + Slash + "include";
+ SmallString<128> Path1(getDriver().ResourceDir);
+ llvm::sys::path::append(Path1, "include");
+ SmallString<128> Path2(GCCToolchainDir);
+ llvm::sys::path::append(Path2, GCCToolchainName, "sys-include");
+ SmallString<128> Path3(GCCToolchainDir);
+ llvm::sys::path::append(Path3, GCCToolchainName, "include");
const StringRef Paths[] = {Path1, Path2, Path3};
addSystemIncludes(DriverArgs, CC1Args, Paths);
@@ -184,20 +122,20 @@ void XtensaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
void XtensaToolChain::addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
- if (!XtensaGCCToolchain.IsValid())
+ if (!GCCInstallation.isValid())
return;
- std::string Slash = XtensaGCCToolchain.Slash;
+ SmallString<128> BaseDir(GCCToolchainDir);
+ llvm::sys::path::append(BaseDir, GCCToolchainName, "include", "c++",
+ GCCLibAndIncVersion);
+ SmallString<128> TargetDir(BaseDir);
+ llvm::sys::path::append(TargetDir, GCCToolchainName);
+ SmallString<128> TargetDirBackward(BaseDir);
+ llvm::sys::path::append(TargetDirBackward, "backward");
- std::string BaseDir = XtensaGCCToolchain.GCCToolchainDir + Slash +
- XtensaGCCToolchain.GCCToolchainName + Slash +
- "include" + Slash + "c++" + Slash +
- XtensaGCCToolchain.GCCLibAndIncVersion;
- std::string TargetDir = BaseDir + Slash + XtensaGCCToolchain.GCCToolchainName;
addLibStdCXXIncludePaths(BaseDir, "", "", DriverArgs, CC1Args);
addLibStdCXXIncludePaths(TargetDir, "", "", DriverArgs, CC1Args);
- TargetDir = BaseDir + Slash + "backward";
- addLibStdCXXIncludePaths(TargetDir, "", "", DriverArgs, CC1Args);
+ addLibStdCXXIncludePaths(TargetDirBackward, "", "", DriverArgs, CC1Args);
}
ToolChain::CXXStdlibType
@@ -229,7 +167,7 @@ void tools::xtensa::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
const auto &TC =
static_cast<const toolchains::XtensaToolChain &>(getToolChain());
- if (!TC.XtensaGCCToolchain.IsValid())
+ if (TC.GCCToolchainName == "")
llvm_unreachable("Unable to find Xtensa GCC assembler");
claimNoWarnArgs(Args);
@@ -256,13 +194,13 @@ void tools::xtensa::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- std::string Slash = TC.XtensaGCCToolchain.Slash;
+ SmallString<128> Asm(TC.GCCToolchainDir);
+ llvm::sys::path::append(Asm, "bin",
+ TC.GCCToolchainName + "-" + getShortName());
- const char *Asm =
- Args.MakeArgString(getToolChain().getDriver().Dir + Slash +
- TC.XtensaGCCToolchain.GCCToolchainName + "-as");
- C.addCommand(std::make_unique<Command>(
- JA, *this, ResponseFileSupport::AtFileCurCP(), Asm, CmdArgs, Inputs));
+ C.addCommand(
+ std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileCurCP(),
+ Args.MakeArgString(Asm), CmdArgs, Inputs));
}
void xtensa::Linker::ConstructJob(Compilation &C, const JobAction &JA,
@@ -272,13 +210,13 @@ void xtensa::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const char *LinkingOutput) const {
const auto &TC =
static_cast<const toolchains::XtensaToolChain &>(getToolChain());
- std::string Slash = TC.XtensaGCCToolchain.Slash;
- if (!TC.XtensaGCCToolchain.IsValid())
+ if (TC.GCCToolchainName == "")
llvm_unreachable("Unable to find Xtensa GCC linker");
- std::string Linker = getToolChain().getDriver().Dir + Slash +
- TC.XtensaGCCToolchain.GCCToolchainName + "-ld";
+ SmallString<128> Linker(TC.GCCToolchainDir);
+ llvm::sys::path::append(Linker, "bin",
+ TC.GCCToolchainName + "-" + getShortName());
ArgStringList CmdArgs;
Args.AddAllArgs(CmdArgs, options::OPT_L);
diff --git a/clang/lib/Driver/ToolChains/Xtensa.h b/clang/lib/Driver/ToolChains/Xtensa.h
index ce6781040c42..0457d23ff42c 100644
--- a/clang/lib/Driver/ToolChains/Xtensa.h
+++ b/clang/lib/Driver/ToolChains/Xtensa.h
@@ -20,19 +20,6 @@ namespace clang {
namespace driver {
namespace toolchains {
-class XtensaGCCToolchainDetector {
-public:
- std::string GCCLibAndIncVersion;
- std::string GCCToolchainName;
- std::string GCCToolchainDir;
- std::string Slash;
-
- XtensaGCCToolchainDetector(const Driver &D, const llvm::Triple &HostTriple,
- const llvm::opt::ArgList &Args);
-
- bool IsValid() const { return GCCToolchainName != ""; }
-};
-
class LLVM_LIBRARY_VISIBILITY XtensaToolChain : public Generic_ELF {
protected:
Tool *buildLinker() const override;
@@ -49,13 +36,15 @@ public:
llvm::opt::ArgStringList &CC1Args) const override;
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
bool IsIntegratedAssemblerDefault() const override {
- return (IsIntegratedAsm || (XtensaGCCToolchain.GCCToolchainName == ""));
+ return (IsIntegratedAsm || (GCCToolchainName == ""));
}
static const StringRef GetTargetCPUVersion(const llvm::opt::ArgList &Args);
- XtensaGCCToolchainDetector XtensaGCCToolchain;
bool IsIntegratedAsm = true;
+ std::string GCCLibAndIncVersion = "";
+ std::string GCCToolchainName = "";
+ std::string GCCToolchainDir = "";
};
} // end namespace toolchains
@@ -65,7 +54,7 @@ namespace xtensa {
class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
public:
Linker(const ToolChain &TC)
- : Tool("Xtensa::Linker", "xtensa-esp32-elf-ld", TC) {}
+ : Tool("Xtensa::Linker", "ld", TC) {}
bool hasIntegratedCPP() const override { return false; }
bool isLinkJob() const override { return true; }
void ConstructJob(Compilation &C, const JobAction &JA,
@@ -77,7 +66,7 @@ public:
class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
public:
Assembler(const ToolChain &TC)
- : Tool("Xtensa::Assembler", "xtensa-esp32-elf-as", TC) {}
+ : Tool("Xtensa::Assembler", "as", TC) {}
bool hasIntegratedCPP() const override { return false; }
void ConstructJob(Compilation &C, const JobAction &JA,
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/bin/xtensa-esp32-elf-ld b/clang/test/Driver/Inputs/multilib_xtensa_tree/bin/xtensa-esp32-elf-ld
new file mode 100755
index 000000000000..b23e55619b2f
--- /dev/null
+++ b/clang/test/Driver/Inputs/multilib_xtensa_tree/bin/xtensa-esp32-elf-ld
@@ -0,0 +1 @@
+#!/bin/true
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/crtbegin.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/crtend.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/crtbegin.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/crtend.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/no-rtti/crtbegin.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/no-rtti/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/no-rtti/crtend.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/esp32-psram/no-rtti/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/no-rtti/crtbegin.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/no-rtti/crtbegin.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/no-rtti/crtend.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/no-rtti/crtend.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/crt0.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/esp32-psram/crt0.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/esp32-psram/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/esp32-psram/no-rtti/crt0.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/esp32-psram/no-rtti/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/no-rtti/crt0.o b/clang/test/Driver/Inputs/multilib_xtensa_tree/xtensa-esp32-elf/lib/no-rtti/crt0.o
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/clang/test/Driver/xtensa-toolchain.c b/clang/test/Driver/xtensa-toolchain.c
new file mode 100644
index 000000000000..245e09902f0f
--- /dev/null
+++ b/clang/test/Driver/xtensa-toolchain.c
@@ -0,0 +1,42 @@
+// A basic clang -cc1 command-line, and simple environment check.
+
+// RUN: %clang %s -### -no-canonical-prefixes -target xtensa \
+// RUN: --gcc-toolchain=%S/Inputs/multilib_xtensa_tree 2>&1 \
+// RUN: | FileCheck -check-prefix=CC1 %s
+// CC1: clang{{.*}} "-cc1" "-triple" "xtensa"
+
+// RUN: %clang %s -### -no-canonical-prefixes -fuse-ld= \
+// RUN: -target xtensa --rtlib=platform \
+// RUN: --gcc-toolchain=%S/Inputs/multilib_xtensa_tree 2>&1 \
+// RUN: | FileCheck -check-prefix=C-XTENSA-BAREMETAL %s
+
+// C-XTENSA-BAREMETAL: "{{.*}}Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}xtensa-esp32-elf-ld"
+// C-XTENSA-BAREMETAL: "-L{{.*}}/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}xtensa-esp32-elf{{/|\\\\}}8.4.0/no-rtti"
+// C-XTENSA-BAREMETAL: "-L{{.*}}/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}xtensa-esp32-elf{{/|\\\\}}lib/no-rtti"
+
+// RUN: %clang %s -### -no-canonical-prefixes -fuse-ld= \
+// RUN: -target xtensa --rtlib=platform \
+// RUN: --gcc-toolchain=%S/Inputs/multilib_xtensa_tree -frtti 2>&1 \
+// RUN: | FileCheck -check-prefix=C-XTENSA-BAREMETAL-RTTI %s
+
+// C-XTENSA-BAREMETAL-RTTI: "{{.*}}Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}xtensa-esp32-elf-ld"
+// C-XTENSA-BAREMETAL-RTTI: "-L{{.*}}/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}xtensa-esp32-elf{{/|\\\\}}8.4.0"
+// C-XTENSA-BAREMETAL-RTTI: "-L{{.*}}/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}xtensa-esp32-elf{{/|\\\\}}lib"
+
+// RUN: %clang %s -### -no-canonical-prefixes -fuse-ld= \
+// RUN: -target xtensa --rtlib=platform \
+// RUN: --gcc-toolchain=%S/Inputs/multilib_xtensa_tree -mfix-esp32-psram-cache-issue 2>&1 \
+// RUN: | FileCheck -check-prefix=C-XTENSA-BAREMETAL-PSRAM %s
+
+// C-XTENSA-BAREMETAL-PSRAM: "{{.*}}Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}xtensa-esp32-elf-ld"
+// C-XTENSA-BAREMETAL-PSRAM: "-L{{.*}}/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}xtensa-esp32-elf{{/|\\\\}}8.4.0/esp32-psram/no-rtti"
+// C-XTENSA-BAREMETAL-PSRAM: "-L{{.*}}/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}xtensa-esp32-elf{{/|\\\\}}lib/esp32-psram/no-rtti"
+
+// RUN: %clang %s -### -no-canonical-prefixes -fuse-ld= \
+// RUN: -target xtensa --rtlib=platform \
+// RUN: --gcc-toolchain=%S/Inputs/multilib_xtensa_tree -mfix-esp32-psram-cache-issue -frtti 2>&1 \
+// RUN: | FileCheck -check-prefix=C-XTENSA-BAREMETAL-PSRAM-RTTI %s
+
+// C-XTENSA-BAREMETAL-PSRAM-RTTI: "{{.*}}Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}bin{{/|\\\\}}xtensa-esp32-elf-ld"
+// C-XTENSA-BAREMETAL-PSRAM-RTTI: "-L{{.*}}/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}xtensa-esp32-elf{{/|\\\\}}8.4.0/esp32-psram"
+// C-XTENSA-BAREMETAL-PSRAM-RTTI: "-L{{.*}}/Inputs/multilib_xtensa_tree/lib/gcc/xtensa-esp32-elf/8.4.0/../../..{{/|\\\\}}..{{/|\\\\}}xtensa-esp32-elf{{/|\\\\}}lib/esp32-psram"
--
2.40.1