14#include "clang/Config/config.h"
19#include "llvm/Option/ArgList.h"
20#include "llvm/Support/VirtualFileSystem.h"
32 const char *LinkingOutput)
const {
36 ArgStringList CmdArgs;
45 case llvm::Triple::x86:
46 CmdArgs.push_back(
"--32");
48 case llvm::Triple::ppc:
49 case llvm::Triple::ppcle:
50 CmdArgs.push_back(
"-a32");
52 case llvm::Triple::mips:
53 case llvm::Triple::mipsel:
54 case llvm::Triple::mips64:
55 case llvm::Triple::mips64el: {
60 CmdArgs.push_back(
"-march");
61 CmdArgs.push_back(CPUName.data());
63 CmdArgs.push_back(
"-mabi");
66 if (Triple.isLittleEndian())
67 CmdArgs.push_back(
"-EL");
69 CmdArgs.push_back(
"-EB");
71 if (Arg *A = Args.getLastArg(options::OPT_G)) {
72 StringRef
v = A->getValue();
73 CmdArgs.push_back(Args.MakeArgString(
"-G" +
v));
80 case llvm::Triple::arm:
81 case llvm::Triple::armeb:
82 case llvm::Triple::thumb:
83 case llvm::Triple::thumbeb: {
87 CmdArgs.push_back(
"-mfpu=vfp");
89 CmdArgs.push_back(
"-mfpu=softvfp");
91 CmdArgs.push_back(
"-meabi=5");
94 case llvm::Triple::sparcv9: {
102 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
103 options::OPT_fdebug_prefix_map_EQ)) {
104 StringRef Map = A->getValue();
105 if (!Map.contains(
'='))
106 D.Diag(diag::err_drv_invalid_argument_to_option)
107 << Map << A->getOption().getName();
109 CmdArgs.push_back(Args.MakeArgString(
"--debug-prefix-map"));
110 CmdArgs.push_back(Args.MakeArgString(Map));
115 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
117 CmdArgs.push_back(
"-o");
120 for (
const auto &II : Inputs)
121 CmdArgs.push_back(II.getFilename());
124 C.addCommand(std::make_unique<Command>(JA, *
this,
126 Exec, CmdArgs, Inputs, Output));
133 const char *LinkingOutput)
const {
139 !Args.hasArg(options::OPT_shared) &&
141 ArgStringList CmdArgs;
144 Args.ClaimAllArgs(options::OPT_g_Group);
146 Args.ClaimAllArgs(options::OPT_emit_llvm);
149 Args.ClaimAllArgs(options::OPT_w);
151 if (!
D.SysRoot.empty())
152 CmdArgs.push_back(Args.MakeArgString(
"--sysroot=" +
D.SysRoot));
155 CmdArgs.push_back(
"-pie");
157 CmdArgs.push_back(
"--eh-frame-hdr");
158 if (Args.hasArg(options::OPT_static)) {
159 CmdArgs.push_back(
"-Bstatic");
161 if (Args.hasArg(options::OPT_rdynamic))
162 CmdArgs.push_back(
"-export-dynamic");
163 if (Args.hasArg(options::OPT_shared)) {
164 CmdArgs.push_back(
"-shared");
165 }
else if (!Args.hasArg(options::OPT_r)) {
166 CmdArgs.push_back(
"-dynamic-linker");
167 CmdArgs.push_back(
"/libexec/ld-elf.so.1");
169 if (Arch == llvm::Triple::arm || Triple.isX86())
170 CmdArgs.push_back(
"--hash-style=both");
171 CmdArgs.push_back(
"--enable-new-dtags");
177 case llvm::Triple::x86:
178 CmdArgs.push_back(
"-m");
179 CmdArgs.push_back(
"elf_i386_fbsd");
181 case llvm::Triple::ppc:
182 CmdArgs.push_back(
"-m");
183 CmdArgs.push_back(
"elf32ppc_fbsd");
185 case llvm::Triple::ppcle:
186 CmdArgs.push_back(
"-m");
188 CmdArgs.push_back(
"elf32lppc");
190 case llvm::Triple::mips:
191 CmdArgs.push_back(
"-m");
192 CmdArgs.push_back(
"elf32btsmip_fbsd");
194 case llvm::Triple::mipsel:
195 CmdArgs.push_back(
"-m");
196 CmdArgs.push_back(
"elf32ltsmip_fbsd");
198 case llvm::Triple::mips64:
199 CmdArgs.push_back(
"-m");
201 CmdArgs.push_back(
"elf32btsmipn32_fbsd");
203 CmdArgs.push_back(
"elf64btsmip_fbsd");
205 case llvm::Triple::mips64el:
206 CmdArgs.push_back(
"-m");
208 CmdArgs.push_back(
"elf32ltsmipn32_fbsd");
210 CmdArgs.push_back(
"elf64ltsmip_fbsd");
212 case llvm::Triple::riscv64:
213 CmdArgs.push_back(
"-m");
214 CmdArgs.push_back(
"elf64lriscv");
216 case llvm::Triple::loongarch32:
217 CmdArgs.push_back(
"-m");
218 CmdArgs.push_back(
"elf32loongarch");
220 case llvm::Triple::loongarch64:
221 CmdArgs.push_back(
"-m");
222 CmdArgs.push_back(
"elf64loongarch");
228 if (Triple.isLoongArch64() || Triple.isRISCV64()) {
229 CmdArgs.push_back(
"-X");
230 if (Args.hasArg(options::OPT_mno_relax))
231 CmdArgs.push_back(
"--no-relax");
234 if (Arg *A = Args.getLastArg(options::OPT_G)) {
236 StringRef
v = A->getValue();
237 CmdArgs.push_back(Args.MakeArgString(
"-G" +
v));
244 CmdArgs.push_back(
"-o");
248 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
250 const char *crt1 =
nullptr;
251 if (!Args.hasArg(options::OPT_shared)) {
252 if (Args.hasArg(options::OPT_pg))
264 const char *crtbegin =
nullptr;
265 if (Args.hasArg(options::OPT_static))
266 crtbegin =
"crtbeginT.o";
267 else if (Args.hasArg(options::OPT_shared) || IsPIE)
268 crtbegin =
"crtbeginS.o";
270 crtbegin =
"crtbegin.o";
275 Args.AddAllArgs(CmdArgs, options::OPT_L);
277 Args.addAllArgs(CmdArgs,
278 {options::OPT_T_Group, options::OPT_s, options::OPT_t});
280 if (
D.isUsingLTO()) {
281 assert(!Inputs.empty() &&
"Must have at least one input.");
283 auto Input = llvm::find_if(
285 if (Input == Inputs.end())
288 Input = Inputs.begin();
300 bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
301 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
304 bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
305 !Args.hasArg(options::OPT_static);
312 CmdArgs.push_back(
"-lm_p");
314 CmdArgs.push_back(
"-lm");
318 Args.ClaimAllArgs(options::OPT_stdlib_EQ);
324 if (
D.IsFlangMode() &&
325 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
329 CmdArgs.push_back(
"-lm_p");
331 CmdArgs.push_back(
"-lm");
334 if (NeedsSanitizerDeps)
341 CmdArgs.push_back(
"-lgcc_p");
343 CmdArgs.push_back(
"-lgcc");
344 if (Args.hasArg(options::OPT_static)) {
345 CmdArgs.push_back(
"-lgcc_eh");
346 }
else if (Profiling) {
347 CmdArgs.push_back(
"-lgcc_eh_p");
349 CmdArgs.push_back(
"--as-needed");
350 CmdArgs.push_back(
"-lgcc_s");
351 CmdArgs.push_back(
"--no-as-needed");
354 if (Args.hasArg(options::OPT_pthread)) {
356 CmdArgs.push_back(
"-lpthread_p");
358 CmdArgs.push_back(
"-lpthread");
362 if (Args.hasArg(options::OPT_shared))
363 CmdArgs.push_back(
"-lc");
365 CmdArgs.push_back(
"-lc_p");
366 CmdArgs.push_back(
"-lgcc_p");
368 CmdArgs.push_back(
"-lc");
369 CmdArgs.push_back(
"-lgcc");
372 if (Args.hasArg(options::OPT_static)) {
373 CmdArgs.push_back(
"-lgcc_eh");
374 }
else if (Profiling) {
375 CmdArgs.push_back(
"-lgcc_eh_p");
377 CmdArgs.push_back(
"--as-needed");
378 CmdArgs.push_back(
"-lgcc_s");
379 CmdArgs.push_back(
"--no-as-needed");
383 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
385 const char *crtend =
nullptr;
386 if (Args.hasArg(options::OPT_shared) || IsPIE)
387 crtend =
"crtendS.o";
396 const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
397 C.addCommand(std::make_unique<Command>(JA, *
this,
399 Exec, CmdArgs, Inputs, Output));
410 if (Triple.isArch32Bit() &&
418 const llvm::opt::ArgList &DriverArgs,
419 llvm::opt::ArgStringList &CC1Args)
const {
422 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
425 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
427 llvm::sys::path::append(Dir,
"include");
431 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
435 StringRef CIncludeDirs(C_INCLUDE_DIRS);
436 if (CIncludeDirs !=
"") {
438 CIncludeDirs.split(dirs,
":");
439 for (StringRef dir : dirs) {
441 llvm::sys::path::is_absolute(dir) ? StringRef(
D.SysRoot) :
"";
448 concat(
D.SysRoot,
"/usr/include"));
452 llvm::opt::ArgStringList &CC1Args)
const {
458 ArgStringList &CmdArgs)
const {
459 unsigned Major =
getTriple().getOSMajorVersion();
460 bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
462 CmdArgs.push_back(Profiling ?
"-lc++_p" :
"-lc++");
463 if (Args.hasArg(options::OPT_fexperimental_library))
464 CmdArgs.push_back(
"-lc++experimental");
468 ArgStringList &CC1Args)
const {
473 ArgStringList &CC1Args)
const {
495 const bool IsAArch64 =
getTriple().getArch() == llvm::Triple::aarch64;
496 const bool IsX86 =
getTriple().getArch() == llvm::Triple::x86;
497 const bool IsX86_64 =
getTriple().getArch() == llvm::Triple::x86_64;
498 const bool IsMIPS64 =
getTriple().isMIPS64();
500 Res |= SanitizerKind::Address;
501 Res |= SanitizerKind::PointerCompare;
502 Res |= SanitizerKind::PointerSubtract;
503 Res |= SanitizerKind::Vptr;
504 if (IsAArch64 || IsX86_64 || IsMIPS64) {
505 Res |= SanitizerKind::Leak;
506 Res |= SanitizerKind::Thread;
508 if (IsAArch64 || IsX86 || IsX86_64) {
509 Res |= SanitizerKind::SafeStack;
510 Res |= SanitizerKind::Fuzzer;
511 Res |= SanitizerKind::FuzzerNoLink;
513 if (IsAArch64 || IsX86_64) {
514 Res |= SanitizerKind::KernelAddress;
515 Res |= SanitizerKind::KernelMemory;
516 Res |= SanitizerKind::Memory;
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport AtFileCurCP()