clang  14.0.0git
AVR.cpp
Go to the documentation of this file.
1 //===--- AVR.cpp - AVR ToolChain Implementations ----------------*- 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 #include "AVR.h"
10 #include "CommonArgs.h"
13 #include "clang/Driver/InputInfo.h"
14 #include "clang/Driver/Options.h"
15 #include "llvm/ADT/Optional.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/MC/MCSubtargetInfo.h"
19 #include "llvm/MC/SubtargetFeature.h"
20 #include "llvm/Option/ArgList.h"
21 #include "llvm/Support/FileSystem.h"
22 
23 using namespace clang::driver;
24 using namespace clang::driver::toolchains;
25 using namespace clang::driver::tools;
26 using namespace clang;
27 using namespace llvm::opt;
28 
29 namespace {
30 
31 const struct {
32  StringRef Name;
33  std::string SubPath;
34  StringRef Family;
35  unsigned DataAddr;
36 } MCUInfo[] = {
37  {"at90s1200", "", "avr1", 0},
38  {"attiny11", "", "avr1", 0},
39  {"attiny12", "", "avr1", 0},
40  {"attiny15", "", "avr1", 0},
41  {"attiny28", "", "avr1", 0},
42  {"at90s2313", "tiny-stack", "avr2", 0x800060},
43  {"at90s2323", "tiny-stack", "avr2", 0x800060},
44  {"at90s2333", "tiny-stack", "avr2", 0x800060},
45  {"at90s2343", "tiny-stack", "avr2", 0x800060},
46  {"at90s4433", "tiny-stack", "avr2", 0x800060},
47  {"attiny22", "tiny-stack", "avr2", 0x800060},
48  {"attiny26", "tiny-stack", "avr2", 0x800060},
49  {"at90s4414", "", "avr2", 0x800060},
50  {"at90s4434", "", "avr2", 0x800060},
51  {"at90s8515", "", "avr2", 0x800060},
52  {"at90c8534", "", "avr2", 0x800060},
53  {"at90s8535", "", "avr2", 0x800060},
54  {"attiny13", "avr25/tiny-stack", "avr25", 0x800060},
55  {"attiny13a", "avr25/tiny-stack", "avr25", 0x800060},
56  {"attiny2313", "avr25/tiny-stack", "avr25", 0x800060},
57  {"attiny2313a", "avr25/tiny-stack", "avr25", 0x800060},
58  {"attiny24", "avr25/tiny-stack", "avr25", 0x800060},
59  {"attiny24a", "avr25/tiny-stack", "avr25", 0x800060},
60  {"attiny25", "avr25/tiny-stack", "avr25", 0x800060},
61  {"attiny261", "avr25/tiny-stack", "avr25", 0x800060},
62  {"attiny261a", "avr25/tiny-stack", "avr25", 0x800060},
63  {"at86rf401", "avr25", "avr25", 0x800060},
64  {"ata5272", "avr25", "avr25", 0x800100},
65  {"attiny4313", "avr25", "avr25", 0x800060},
66  {"attiny44", "avr25", "avr25", 0x800060},
67  {"attiny44a", "avr25", "avr25", 0x800060},
68  {"attiny84", "avr25", "avr25", 0x800060},
69  {"attiny84a", "avr25", "avr25", 0x800060},
70  {"attiny45", "avr25", "avr25", 0x800060},
71  {"attiny85", "avr25", "avr25", 0x800060},
72  {"attiny441", "avr25", "avr25", 0x800100},
73  {"attiny461", "avr25", "avr25", 0x800060},
74  {"attiny461a", "avr25", "avr25", 0x800060},
75  {"attiny841", "avr25", "avr25", 0x800100},
76  {"attiny861", "avr25", "avr25", 0x800060},
77  {"attiny861a", "avr25", "avr25", 0x800060},
78  {"attiny87", "avr25", "avr25", 0x800100},
79  {"attiny43u", "avr25", "avr25", 0x800060},
80  {"attiny48", "avr25", "avr25", 0x800100},
81  {"attiny88", "avr25", "avr25", 0x800100},
82  {"attiny828", "avr25", "avr25", 0x800100},
83  {"at43usb355", "avr3", "avr3", 0x800100},
84  {"at76c711", "avr3", "avr3", 0x800060},
85  {"atmega103", "avr31", "avr31", 0x800060},
86  {"at43usb320", "avr31", "avr31", 0x800060},
87  {"attiny167", "avr35", "avr35", 0x800100},
88  {"at90usb82", "avr35", "avr35", 0x800100},
89  {"at90usb162", "avr35", "avr35", 0x800100},
90  {"ata5505", "avr35", "avr35", 0x800100},
91  {"atmega8u2", "avr35", "avr35", 0x800100},
92  {"atmega16u2", "avr35", "avr35", 0x800100},
93  {"atmega32u2", "avr35", "avr35", 0x800100},
94  {"attiny1634", "avr35", "avr35", 0x800100},
95  {"atmega8", "avr4", "avr4", 0x800060},
96  {"ata6289", "avr4", "avr4", 0x800100},
97  {"atmega8a", "avr4", "avr4", 0x800060},
98  {"ata6285", "avr4", "avr4", 0x800100},
99  {"ata6286", "avr4", "avr4", 0x800100},
100  {"atmega48", "avr4", "avr4", 0x800100},
101  {"atmega48a", "avr4", "avr4", 0x800100},
102  {"atmega48pa", "avr4", "avr4", 0x800100},
103  {"atmega48pb", "avr4", "avr4", 0x800100},
104  {"atmega48p", "avr4", "avr4", 0x800100},
105  {"atmega88", "avr4", "avr4", 0x800100},
106  {"atmega88a", "avr4", "avr4", 0x800100},
107  {"atmega88p", "avr4", "avr4", 0x800100},
108  {"atmega88pa", "avr4", "avr4", 0x800100},
109  {"atmega88pb", "avr4", "avr4", 0x800100},
110  {"atmega8515", "avr4", "avr4", 0x800060},
111  {"atmega8535", "avr4", "avr4", 0x800060},
112  {"atmega8hva", "avr4", "avr4", 0x800100},
113  {"at90pwm1", "avr4", "avr4", 0x800100},
114  {"at90pwm2", "avr4", "avr4", 0x800100},
115  {"at90pwm2b", "avr4", "avr4", 0x800100},
116  {"at90pwm3", "avr4", "avr4", 0x800100},
117  {"at90pwm3b", "avr4", "avr4", 0x800100},
118  {"at90pwm81", "avr4", "avr4", 0x800100},
119  {"ata5790", "avr5", "avr5", 0x800100},
120  {"ata5795", "avr5", "avr5", 0x800100},
121  {"atmega16", "avr5", "avr5", 0x800060},
122  {"atmega16a", "avr5", "avr5", 0x800060},
123  {"atmega161", "avr5", "avr5", 0x800060},
124  {"atmega162", "avr5", "avr5", 0x800100},
125  {"atmega163", "avr5", "avr5", 0x800060},
126  {"atmega164a", "avr5", "avr5", 0x800100},
127  {"atmega164p", "avr5", "avr5", 0x800100},
128  {"atmega164pa", "avr5", "avr5", 0x800100},
129  {"atmega165", "avr5", "avr5", 0x800100},
130  {"atmega165a", "avr5", "avr5", 0x800100},
131  {"atmega165p", "avr5", "avr5", 0x800100},
132  {"atmega165pa", "avr5", "avr5", 0x800100},
133  {"atmega168", "avr5", "avr5", 0x800100},
134  {"atmega168a", "avr5", "avr5", 0x800100},
135  {"atmega168p", "avr5", "avr5", 0x800100},
136  {"atmega168pa", "avr5", "avr5", 0x800100},
137  {"atmega168pb", "avr5", "avr5", 0x800100},
138  {"atmega169", "avr5", "avr5", 0x800100},
139  {"atmega169a", "avr5", "avr5", 0x800100},
140  {"atmega169p", "avr5", "avr5", 0x800100},
141  {"atmega169pa", "avr5", "avr5", 0x800100},
142  {"atmega32", "avr5", "avr5", 0x800060},
143  {"atmega32a", "avr5", "avr5", 0x800060},
144  {"atmega323", "avr5", "avr5", 0x800060},
145  {"atmega324a", "avr5", "avr5", 0x800100},
146  {"atmega324p", "avr5", "avr5", 0x800100},
147  {"atmega324pa", "avr5", "avr5", 0x800100},
148  {"atmega325", "avr5", "avr5", 0x800100},
149  {"atmega325a", "avr5", "avr5", 0x800100},
150  {"atmega325p", "avr5", "avr5", 0x800100},
151  {"atmega325pa", "avr5", "avr5", 0x800100},
152  {"atmega3250", "avr5", "avr5", 0x800100},
153  {"atmega3250a", "avr5", "avr5", 0x800100},
154  {"atmega3250p", "avr5", "avr5", 0x800100},
155  {"atmega3250pa", "avr5", "avr5", 0x800100},
156  {"atmega328", "avr5", "avr5", 0x800100},
157  {"atmega328p", "avr5", "avr5", 0x800100},
158  {"atmega329", "avr5", "avr5", 0x800100},
159  {"atmega329a", "avr5", "avr5", 0x800100},
160  {"atmega329p", "avr5", "avr5", 0x800100},
161  {"atmega329pa", "avr5", "avr5", 0x800100},
162  {"atmega3290", "avr5", "avr5", 0x800100},
163  {"atmega3290a", "avr5", "avr5", 0x800100},
164  {"atmega3290p", "avr5", "avr5", 0x800100},
165  {"atmega3290pa", "avr5", "avr5", 0x800100},
166  {"atmega406", "avr5", "avr5", 0x800100},
167  {"atmega64", "avr5", "avr5", 0x800100},
168  {"atmega64a", "avr5", "avr5", 0x800100},
169  {"atmega640", "avr5", "avr5", 0x800200},
170  {"atmega644", "avr5", "avr5", 0x800100},
171  {"atmega644a", "avr5", "avr5", 0x800100},
172  {"atmega644p", "avr5", "avr5", 0x800100},
173  {"atmega644pa", "avr5", "avr5", 0x800100},
174  {"atmega645", "avr5", "avr5", 0x800100},
175  {"atmega645a", "avr5", "avr5", 0x800100},
176  {"atmega645p", "avr5", "avr5", 0x800100},
177  {"atmega649", "avr5", "avr5", 0x800100},
178  {"atmega649a", "avr5", "avr5", 0x800100},
179  {"atmega649p", "avr5", "avr5", 0x800100},
180  {"atmega6450", "avr5", "avr5", 0x800100},
181  {"atmega6450a", "avr5", "avr5", 0x800100},
182  {"atmega6450p", "avr5", "avr5", 0x800100},
183  {"atmega6490", "avr5", "avr5", 0x800100},
184  {"atmega6490a", "avr5", "avr5", 0x800100},
185  {"atmega6490p", "avr5", "avr5", 0x800100},
186  {"atmega64rfr2", "avr5", "avr5", 0x800200},
187  {"atmega644rfr2", "avr5", "avr5", 0x800200},
188  {"atmega16hva", "avr5", "avr5", 0x800100},
189  {"atmega16hva2", "avr5", "avr5", 0x800100},
190  {"atmega16hvb", "avr5", "avr5", 0x800100},
191  {"atmega16hvbrevb", "avr5", "avr5", 0x800100},
192  {"atmega32hvb", "avr5", "avr5", 0x800100},
193  {"atmega32hvbrevb", "avr5", "avr5", 0x800100},
194  {"atmega64hve", "avr5", "avr5", 0x800100},
195  {"at90can32", "avr5", "avr5", 0x800100},
196  {"at90can64", "avr5", "avr5", 0x800100},
197  {"at90pwm161", "avr5", "avr5", 0x800100},
198  {"at90pwm216", "avr5", "avr5", 0x800100},
199  {"at90pwm316", "avr5", "avr5", 0x800100},
200  {"atmega32c1", "avr5", "avr5", 0x800100},
201  {"atmega64c1", "avr5", "avr5", 0x800100},
202  {"atmega16m1", "avr5", "avr5", 0x800100},
203  {"atmega32m1", "avr5", "avr5", 0x800100},
204  {"atmega64m1", "avr5", "avr5", 0x800100},
205  {"atmega16u4", "avr5", "avr5", 0x800100},
206  {"atmega32u4", "avr5", "avr5", 0x800100},
207  {"atmega32u6", "avr5", "avr5", 0x800100},
208  {"at90usb646", "avr5", "avr5", 0x800100},
209  {"at90usb647", "avr5", "avr5", 0x800100},
210  {"at90scr100", "avr5", "avr5", 0x800100},
211  {"at94k", "avr5", "avr5", 0x800060},
212  {"m3000", "avr5", "avr5", 0x800060},
213  {"atmega128", "avr51", "avr51", 0x800100},
214  {"atmega128a", "avr51", "avr51", 0x800100},
215  {"atmega1280", "avr51", "avr51", 0x800200},
216  {"atmega1281", "avr51", "avr51", 0x800200},
217  {"atmega1284", "avr51", "avr51", 0x800100},
218  {"atmega1284p", "avr51", "avr51", 0x800100},
219  {"atmega128rfa1", "avr51", "avr51", 0x800200},
220  {"atmega128rfr2", "avr51", "avr51", 0x800200},
221  {"atmega1284rfr2", "avr51", "avr51", 0x800200},
222  {"at90can128", "avr51", "avr51", 0x800200},
223  {"at90usb1286", "avr51", "avr51", 0x800200},
224  {"at90usb1287", "avr51", "avr51", 0x800200},
225  {"atmega2560", "avr6", "avr6", 0x800200},
226  {"atmega2561", "avr6", "avr6", 0x800200},
227  {"atmega256rfr2", "avr6", "avr6", 0x800200},
228  {"atmega2564rfr2", "avr6", "avr6", 0x800200},
229  {"attiny4", "avrtiny", "avrtiny", 0x800040},
230  {"attiny5", "avrtiny", "avrtiny", 0x800040},
231  {"attiny9", "avrtiny", "avrtiny", 0x800040},
232  {"attiny10", "avrtiny", "avrtiny", 0x800040},
233  {"attiny20", "avrtiny", "avrtiny", 0x800040},
234  {"attiny40", "avrtiny", "avrtiny", 0x800040},
235  {"atxmega16a4", "avrxmega2", "avrxmega2", 0x802000},
236  {"atxmega16a4u", "avrxmega2", "avrxmega2", 0x802000},
237  {"atxmega16c4", "avrxmega2", "avrxmega2", 0x802000},
238  {"atxmega16d4", "avrxmega2", "avrxmega2", 0x802000},
239  {"atxmega32a4", "avrxmega2", "avrxmega2", 0x802000},
240  {"atxmega32a4u", "avrxmega2", "avrxmega2", 0x802000},
241  {"atxmega32c4", "avrxmega2", "avrxmega2", 0x802000},
242  {"atxmega32d4", "avrxmega2", "avrxmega2", 0x802000},
243  {"atxmega32e5", "avrxmega2", "avrxmega2", 0x802000},
244  {"atxmega16e5", "avrxmega2", "avrxmega2", 0x802000},
245  {"atxmega8e5", "avrxmega2", "avrxmega2", 0x802000},
246  {"atxmega64a3u", "avrxmega4", "avrxmega4", 0x802000},
247  {"atxmega64a4u", "avrxmega4", "avrxmega4", 0x802000},
248  {"atxmega64b1", "avrxmega4", "avrxmega4", 0x802000},
249  {"atxmega64b3", "avrxmega4", "avrxmega4", 0x802000},
250  {"atxmega64c3", "avrxmega4", "avrxmega4", 0x802000},
251  {"atxmega64d3", "avrxmega4", "avrxmega4", 0x802000},
252  {"atxmega64d4", "avrxmega4", "avrxmega4", 0x802000},
253  {"atxmega64a1", "avrxmega5", "avrxmega5", 0x802000},
254  {"atxmega64a1u", "avrxmega5", "avrxmega5", 0x802000},
255  {"atxmega128a3", "avrxmega6", "avrxmega6", 0x802000},
256  {"atxmega128a3u", "avrxmega6", "avrxmega6", 0x802000},
257  {"atxmega128b1", "avrxmega6", "avrxmega6", 0x802000},
258  {"atxmega128b3", "avrxmega6", "avrxmega6", 0x802000},
259  {"atxmega128c3", "avrxmega6", "avrxmega6", 0x802000},
260  {"atxmega128d3", "avrxmega6", "avrxmega6", 0x802000},
261  {"atxmega128d4", "avrxmega6", "avrxmega6", 0x802000},
262  {"atxmega192a3", "avrxmega6", "avrxmega6", 0x802000},
263  {"atxmega192a3u", "avrxmega6", "avrxmega6", 0x802000},
264  {"atxmega192c3", "avrxmega6", "avrxmega6", 0x802000},
265  {"atxmega192d3", "avrxmega6", "avrxmega6", 0x802000},
266  {"atxmega256a3", "avrxmega6", "avrxmega6", 0x802000},
267  {"atxmega256a3u", "avrxmega6", "avrxmega6", 0x802000},
268  {"atxmega256a3b", "avrxmega6", "avrxmega6", 0x802000},
269  {"atxmega256a3bu", "avrxmega6", "avrxmega6", 0x802000},
270  {"atxmega256c3", "avrxmega6", "avrxmega6", 0x802000},
271  {"atxmega256d3", "avrxmega6", "avrxmega6", 0x802000},
272  {"atxmega384c3", "avrxmega6", "avrxmega6", 0x802000},
273  {"atxmega384d3", "avrxmega6", "avrxmega6", 0x802000},
274  {"atxmega128a1", "avrxmega7", "avrxmega7", 0x802000},
275  {"atxmega128a1u", "avrxmega7", "avrxmega7", 0x802000},
276  {"atxmega128a4u", "avrxmega7", "avrxmega7", 0x802000},
277 };
278 
279 std::string GetMCUSubPath(StringRef MCUName) {
280  for (const auto &MCU : MCUInfo)
281  if (MCU.Name == MCUName)
282  return std::string(MCU.SubPath);
283  return "";
284 }
285 
286 llvm::Optional<StringRef> GetMCUFamilyName(StringRef MCUName) {
287  for (const auto &MCU : MCUInfo)
288  if (MCU.Name == MCUName)
289  return Optional<StringRef>(MCU.Family);
290  return Optional<StringRef>();
291 }
292 
293 llvm::Optional<unsigned> GetMCUSectionAddressData(StringRef MCUName) {
294  for (const auto &MCU : MCUInfo)
295  if (MCU.Name == MCUName && MCU.DataAddr > 0)
296  return Optional<unsigned>(MCU.DataAddr);
297  return Optional<unsigned>();
298 }
299 
300 const StringRef PossibleAVRLibcLocations[] = {
301  "/avr",
302  "/usr/avr",
303  "/usr/lib/avr",
304 };
305 
306 } // end anonymous namespace
307 
308 /// AVR Toolchain
309 AVRToolChain::AVRToolChain(const Driver &D, const llvm::Triple &Triple,
310  const ArgList &Args)
311  : Generic_ELF(D, Triple, Args), LinkStdlib(false) {
312  GCCInstallation.init(Triple, Args);
313 
314  // Only add default libraries if the user hasn't explicitly opted out.
315  if (!Args.hasArg(options::OPT_nostdlib) &&
316  !Args.hasArg(options::OPT_nodefaultlibs) &&
317  !Args.hasArg(options::OPT_c /* does not apply when not linking */)) {
318  std::string CPU = getCPUName(D, Args, Triple);
319 
320  if (CPU.empty()) {
321  // We cannot link any standard libraries without an MCU specified.
322  D.Diag(diag::warn_drv_avr_mcu_not_specified);
323  } else {
324  Optional<StringRef> FamilyName = GetMCUFamilyName(CPU);
325  Optional<std::string> AVRLibcRoot = findAVRLibcInstallation();
326 
327  if (!FamilyName.hasValue()) {
328  // We do not have an entry for this CPU in the family
329  // mapping table yet.
330  D.Diag(diag::warn_drv_avr_family_linking_stdlibs_not_implemented)
331  << CPU;
332  } else if (!GCCInstallation.isValid()) {
333  // No avr-gcc found and so no runtime linked.
334  D.Diag(diag::warn_drv_avr_gcc_not_found);
335  } else if (!AVRLibcRoot.hasValue()) {
336  // No avr-libc found and so no runtime linked.
337  D.Diag(diag::warn_drv_avr_libc_not_found);
338  } else { // We have enough information to link stdlibs
341  std::string LibcRoot = AVRLibcRoot.getValue();
342  std::string SubPath = GetMCUSubPath(CPU);
343 
344  getProgramPaths().push_back(GCCParentPath + "/../bin");
345  getFilePaths().push_back(LibcRoot + std::string("/lib/") + SubPath);
346  getFilePaths().push_back(GCCRoot + std::string("/") + SubPath);
347 
348  LinkStdlib = true;
349  }
350  }
351 
352  if (!LinkStdlib)
353  D.Diag(diag::warn_drv_avr_stdlib_not_linked);
354  }
355 }
356 
357 void AVRToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
358  ArgStringList &CC1Args) const {
359  if (DriverArgs.hasArg(options::OPT_nostdinc) ||
360  DriverArgs.hasArg(options::OPT_nostdlibinc))
361  return;
362 
363  // Omit if there is no avr-libc installed.
364  Optional<std::string> AVRLibcRoot = findAVRLibcInstallation();
365  if (!AVRLibcRoot.hasValue())
366  return;
367 
368  // Add 'avr-libc/include' to clang system include paths if applicable.
369  std::string AVRInc = AVRLibcRoot.getValue() + "/include";
370  if (llvm::sys::fs::is_directory(AVRInc))
371  addSystemInclude(DriverArgs, CC1Args, AVRInc);
372 }
373 
375  const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
376  Action::OffloadKind DeviceOffloadKind) const {
377  // By default, use `.ctors` (not `.init_array`), as required by libgcc, which
378  // runs constructors/destructors on AVR.
379  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
380  options::OPT_fno_use_init_array, false))
381  CC1Args.push_back("-fno-use-init-array");
382 }
383 
385  return new tools::AVR::Linker(getTriple(), *this, LinkStdlib);
386 }
387 
388 void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
389  const InputInfo &Output,
390  const InputInfoList &Inputs, const ArgList &Args,
391  const char *LinkingOutput) const {
392  const Driver &D = getToolChain().getDriver();
393 
394  // Compute information about the target AVR.
395  std::string CPU = getCPUName(D, Args, getToolChain().getTriple());
396  llvm::Optional<StringRef> FamilyName = GetMCUFamilyName(CPU);
397  llvm::Optional<unsigned> SectionAddressData = GetMCUSectionAddressData(CPU);
398 
399  std::string Linker = getToolChain().GetProgramPath(getShortName());
400  ArgStringList CmdArgs;
401  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
402 
403  CmdArgs.push_back("-o");
404  CmdArgs.push_back(Output.getFilename());
405 
406  // Enable garbage collection of unused sections.
407  CmdArgs.push_back("--gc-sections");
408 
409  // Add library search paths before we specify libraries.
410  Args.AddAllArgs(CmdArgs, options::OPT_L);
411  getToolChain().AddFilePathLibArgs(Args, CmdArgs);
412 
413  if (SectionAddressData.hasValue()) {
414  std::string DataSectionArg = std::string("-Tdata=0x") +
415  llvm::utohexstr(SectionAddressData.getValue());
416  CmdArgs.push_back(Args.MakeArgString(DataSectionArg));
417  } else {
418  // We do not have an entry for this CPU in the address mapping table yet.
419  D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented) << CPU;
420  }
421 
422  // If the family name is known, we can link with the device-specific libgcc.
423  // Without it, libgcc will simply not be linked. This matches avr-gcc
424  // behavior.
425  if (LinkStdlib) {
426  assert(!CPU.empty() && "CPU name must be known in order to link stdlibs");
427 
428  CmdArgs.push_back("--start-group");
429 
430  // Add the object file for the CRT.
431  std::string CrtFileName = std::string("-l:crt") + CPU + std::string(".o");
432  CmdArgs.push_back(Args.MakeArgString(CrtFileName));
433 
434  CmdArgs.push_back("-lgcc");
435  CmdArgs.push_back("-lm");
436  CmdArgs.push_back("-lc");
437 
438  // Add the link library specific to the MCU.
439  CmdArgs.push_back(Args.MakeArgString(std::string("-l") + CPU));
440 
441  CmdArgs.push_back("--end-group");
442 
443  // Specify the family name as the emulation mode to use.
444  // This is almost always required because otherwise avr-ld
445  // will assume 'avr2' and warn about the program being larger
446  // than the bare minimum supports.
447  CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
448  }
449 
450  C.addCommand(std::make_unique<Command>(
451  JA, *this, ResponseFileSupport::AtFileCurCP(), Args.MakeArgString(Linker),
452  CmdArgs, Inputs, Output));
453 }
454 
455 llvm::Optional<std::string> AVRToolChain::findAVRLibcInstallation() const {
456  // Search avr-libc installation according to avr-gcc installation.
458  std::string Path(GCCParent + "/avr");
459  if (llvm::sys::fs::is_directory(Path))
460  return Path;
461  Path = GCCParent + "/../avr";
462  if (llvm::sys::fs::is_directory(Path))
463  return Path;
464 
465  // Search avr-libc installation from possible locations, and return the first
466  // one that exists, if there is no avr-gcc installed.
467  for (StringRef PossiblePath : PossibleAVRLibcLocations) {
468  std::string Path = getDriver().SysRoot + PossiblePath.str();
469  if (llvm::sys::fs::is_directory(Path))
470  return Path;
471  }
472 
473  return llvm::None;
474 }
clang::driver::toolchains
Definition: AIX.h:55
clang::driver::ToolChain::getProgramPaths
path_list & getProgramPaths()
Definition: ToolChain.h:262
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
llvm::SmallVector
Definition: LLVM.h:38
clang::driver::toolchains::Generic_GCC::GCCInstallation
GCCInstallationDetector GCCInstallation
Definition: Gnu.h:288
clang::driver::tools
Definition: AIX.h:17
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:221
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::isValid
bool isValid() const
Check whether we detected a valid GCC install.
Definition: Gnu.h:224
clang::driver::tools::getCPUName
std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &T, bool FromAs=false)
llvm::Optional
Definition: LLVM.h:40
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::init
void init(const llvm::Triple &TargetTriple, const llvm::opt::ArgList &Args, ArrayRef< std::string > ExtraTripleAliases=None)
Initialize a GCCInstallationDetector from the driver.
Definition: Gnu.cpp:1891
clang::driver::toolchains::AVRToolChain::AddClangSystemIncludeArgs
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: AVR.cpp:357
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
InputInfo.h
clang::driver::tools::AddLinkerInputs
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
clang::driver::ToolChain::getFilePaths
path_list & getFilePaths()
Definition: ToolChain.h:259
clang::driver::Driver::Diag
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:112
clang::driver::tools::AVR::Linker
Definition: AVR.h:51
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
clang::driver::toolchains::Generic_ELF
Definition: Gnu.h:362
Options.h
llvm::opt
Definition: DiagnosticOptions.h:19
DriverDiagnostic.h
clang::driver::ResponseFileSupport::AtFileCurCP
static constexpr ResponseFileSupport AtFileCurCP()
Definition: Job.h:92
clang::driver::toolchains::AVRToolChain::addClangTargetOptions
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: AVR.cpp:374
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::getParentLibPath
StringRef getParentLibPath() const
Get the detected GCC parent lib path.
Definition: Gnu.h:233
clang::driver::ToolChain::getTriple
const llvm::Triple & getTriple() const
Definition: ToolChain.h:223
clang::driver::Driver::SysRoot
std::string SysRoot
sysroot, if present
Definition: Driver.h:151
false
#define false
Definition: stdbool.h:17
Compilation.h
clang::driver::toolchains::AVRToolChain::buildLinker
Tool * buildLinker() const override
Definition: AVR.cpp:384
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::getInstallPath
StringRef getInstallPath() const
Get the detected GCC installation path.
Definition: Gnu.h:230
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:83
CommonArgs.h
clang
Definition: CalledOnceCheck.h:17
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
clang::driver::toolchains::AVRToolChain::AVRToolChain
AVRToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
AVR Toolchain.
Definition: AVR.cpp:309
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:85
clang::driver
Definition: Action.h:31
clang::driver::ToolChain::addSystemInclude
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
Definition: ToolChain.cpp:845
AVR.h
clang::driver::JobAction
Definition: Action.h:380