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");
220 if (Triple.isRISCV64()) {
221 CmdArgs.push_back(
"-X");
222 if (Args.hasArg(options::OPT_mno_relax))
223 CmdArgs.push_back(
"--no-relax");
226 if (Arg *A = Args.getLastArg(options::OPT_G)) {
228 StringRef
v = A->getValue();
229 CmdArgs.push_back(Args.MakeArgString(
"-G" +
v));
236 CmdArgs.push_back(
"-o");
240 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
242 const char *crt1 =
nullptr;
243 if (!Args.hasArg(options::OPT_shared)) {
244 if (Args.hasArg(options::OPT_pg))
256 const char *crtbegin =
nullptr;
257 if (Args.hasArg(options::OPT_static))
258 crtbegin =
"crtbeginT.o";
259 else if (Args.hasArg(options::OPT_shared) || IsPIE)
260 crtbegin =
"crtbeginS.o";
262 crtbegin =
"crtbegin.o";
267 Args.AddAllArgs(CmdArgs, options::OPT_L);
269 Args.addAllArgs(CmdArgs,
270 {options::OPT_T_Group, options::OPT_s, options::OPT_t});
272 if (
D.isUsingLTO()) {
273 assert(!Inputs.empty() &&
"Must have at least one input.");
275 auto Input = llvm::find_if(
277 if (Input == Inputs.end())
280 Input = Inputs.begin();
292 bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
293 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
296 bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
297 !Args.hasArg(options::OPT_static);
304 CmdArgs.push_back(
"-lm_p");
306 CmdArgs.push_back(
"-lm");
310 Args.ClaimAllArgs(options::OPT_stdlib_EQ);
316 if (
D.IsFlangMode()) {
320 CmdArgs.push_back(
"-lm_p");
322 CmdArgs.push_back(
"-lm");
325 if (NeedsSanitizerDeps)
332 CmdArgs.push_back(
"-lgcc_p");
334 CmdArgs.push_back(
"-lgcc");
335 if (Args.hasArg(options::OPT_static)) {
336 CmdArgs.push_back(
"-lgcc_eh");
337 }
else if (Profiling) {
338 CmdArgs.push_back(
"-lgcc_eh_p");
340 CmdArgs.push_back(
"--as-needed");
341 CmdArgs.push_back(
"-lgcc_s");
342 CmdArgs.push_back(
"--no-as-needed");
345 if (Args.hasArg(options::OPT_pthread)) {
347 CmdArgs.push_back(
"-lpthread_p");
349 CmdArgs.push_back(
"-lpthread");
353 if (Args.hasArg(options::OPT_shared))
354 CmdArgs.push_back(
"-lc");
356 CmdArgs.push_back(
"-lc_p");
357 CmdArgs.push_back(
"-lgcc_p");
359 CmdArgs.push_back(
"-lc");
360 CmdArgs.push_back(
"-lgcc");
363 if (Args.hasArg(options::OPT_static)) {
364 CmdArgs.push_back(
"-lgcc_eh");
365 }
else if (Profiling) {
366 CmdArgs.push_back(
"-lgcc_eh_p");
368 CmdArgs.push_back(
"--as-needed");
369 CmdArgs.push_back(
"-lgcc_s");
370 CmdArgs.push_back(
"--no-as-needed");
374 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
376 const char *crtend =
nullptr;
377 if (Args.hasArg(options::OPT_shared) || IsPIE)
378 crtend =
"crtendS.o";
387 const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
388 C.addCommand(std::make_unique<Command>(JA, *
this,
390 Exec, CmdArgs, Inputs, Output));
401 if (Triple.isArch32Bit() &&
409 const llvm::opt::ArgList &DriverArgs,
410 llvm::opt::ArgStringList &CC1Args)
const {
413 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
416 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
418 llvm::sys::path::append(Dir,
"include");
422 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
426 StringRef CIncludeDirs(C_INCLUDE_DIRS);
427 if (CIncludeDirs !=
"") {
429 CIncludeDirs.split(dirs,
":");
430 for (StringRef dir : dirs) {
432 llvm::sys::path::is_absolute(dir) ? StringRef(
D.SysRoot) :
"";
439 concat(
D.SysRoot,
"/usr/include"));
443 llvm::opt::ArgStringList &CC1Args)
const {
449 ArgStringList &CmdArgs)
const {
450 unsigned Major =
getTriple().getOSMajorVersion();
451 bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14;
453 CmdArgs.push_back(Profiling ?
"-lc++_p" :
"-lc++");
454 if (Args.hasArg(options::OPT_fexperimental_library))
455 CmdArgs.push_back(
"-lc++experimental");
459 ArgStringList &CC1Args)
const {
464 ArgStringList &CC1Args)
const {
486 const bool IsAArch64 =
getTriple().getArch() == llvm::Triple::aarch64;
487 const bool IsX86 =
getTriple().getArch() == llvm::Triple::x86;
488 const bool IsX86_64 =
getTriple().getArch() == llvm::Triple::x86_64;
489 const bool IsMIPS64 =
getTriple().isMIPS64();
491 Res |= SanitizerKind::Address;
492 Res |= SanitizerKind::PointerCompare;
493 Res |= SanitizerKind::PointerSubtract;
494 Res |= SanitizerKind::Vptr;
495 if (IsAArch64 || IsX86_64 || IsMIPS64) {
496 Res |= SanitizerKind::Leak;
497 Res |= SanitizerKind::Thread;
499 if (IsAArch64 || IsX86 || IsX86_64) {
500 Res |= SanitizerKind::SafeStack;
501 Res |= SanitizerKind::Fuzzer;
502 Res |= SanitizerKind::FuzzerNoLink;
504 if (IsAArch64 || IsX86_64) {
505 Res |= SanitizerKind::KernelAddress;
506 Res |= SanitizerKind::KernelMemory;
507 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()