14#include "clang/Config/config.h"
18#include "llvm/Option/ArgList.h"
19#include "llvm/Support/Path.h"
20#include "llvm/Support/VirtualFileSystem.h"
32 const char *LinkingOutput)
const {
36 ArgStringList CmdArgs;
41 case llvm::Triple::x86:
44 CmdArgs.push_back(
"--32");
47 case llvm::Triple::arm: {
48 StringRef MArch, MCPU;
51 CmdArgs.push_back(Args.MakeArgString(
"-mcpu=" + Arch));
55 case llvm::Triple::ppc:
56 CmdArgs.push_back(
"-mppc");
57 CmdArgs.push_back(
"-many");
60 case llvm::Triple::sparcv9: {
61 CmdArgs.push_back(
"-64");
68 case llvm::Triple::mips64:
69 case llvm::Triple::mips64el: {
74 CmdArgs.push_back(
"-march");
75 CmdArgs.push_back(CPUName.data());
77 CmdArgs.push_back(
"-mabi");
80 if (Triple.isLittleEndian())
81 CmdArgs.push_back(
"-EL");
83 CmdArgs.push_back(
"-EB");
93 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
95 CmdArgs.push_back(
"-o");
98 for (
const auto &II : Inputs)
99 CmdArgs.push_back(II.getFilename());
102 C.addCommand(std::make_unique<Command>(JA, *
this,
104 Exec, CmdArgs, Inputs, Output));
111 const char *LinkingOutput)
const {
116 const bool Static = Args.hasArg(options::OPT_static);
117 const bool Shared = Args.hasArg(options::OPT_shared);
118 const bool Profiling = Args.hasArg(options::OPT_pg);
119 const bool Pie = Args.hasArg(options::OPT_pie);
120 const bool Nopie = Args.hasArg(options::OPT_no_pie, options::OPT_nopie);
121 const bool Relocatable = Args.hasArg(options::OPT_r);
122 ArgStringList CmdArgs;
125 Args.ClaimAllArgs(options::OPT_g_Group);
127 Args.ClaimAllArgs(options::OPT_emit_llvm);
130 Args.ClaimAllArgs(options::OPT_w);
132 if (!
D.SysRoot.empty())
133 CmdArgs.push_back(Args.MakeArgString(
"--sysroot=" +
D.SysRoot));
135 if (Arch == llvm::Triple::mips64)
136 CmdArgs.push_back(
"-EB");
137 else if (Arch == llvm::Triple::mips64el)
138 CmdArgs.push_back(
"-EL");
140 if (!Args.hasArg(options::OPT_nostdlib) && !Shared && !Relocatable) {
141 CmdArgs.push_back(
"-e");
142 CmdArgs.push_back(
"__start");
145 CmdArgs.push_back(
"--eh-frame-hdr");
147 CmdArgs.push_back(
"-Bstatic");
149 if (Args.hasArg(options::OPT_rdynamic))
150 CmdArgs.push_back(
"-export-dynamic");
152 CmdArgs.push_back(
"-shared");
153 }
else if (!Relocatable) {
154 CmdArgs.push_back(
"-dynamic-linker");
155 CmdArgs.push_back(
"/usr/libexec/ld.so");
160 CmdArgs.push_back(
"-pie");
161 if (Nopie || Profiling)
162 CmdArgs.push_back(
"-nopie");
164 if (Triple.isRISCV64()) {
165 CmdArgs.push_back(
"-X");
166 if (Args.hasArg(options::OPT_mno_relax))
167 CmdArgs.push_back(
"--no-relax");
172 CmdArgs.push_back(
"-o");
176 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
178 const char *crt0 =
nullptr;
179 const char *crtbegin =
nullptr;
183 else if (
Static && !Nopie)
187 crtbegin =
"crtbegin.o";
189 crtbegin =
"crtbeginS.o";
197 Args.AddAllArgs(CmdArgs, options::OPT_L);
199 Args.addAllArgs(CmdArgs,
200 {options::OPT_T_Group, options::OPT_s, options::OPT_t});
202 if (
D.isUsingLTO()) {
203 assert(!Inputs.empty() &&
"Must have at least one input.");
205 auto Input = llvm::find_if(
207 if (Input == Inputs.end())
210 Input = Inputs.begin();
220 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
223 bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) && !
Static;
230 CmdArgs.push_back(
"-lm_p");
232 CmdArgs.push_back(
"-lm");
236 Args.ClaimAllArgs(options::OPT_stdlib_EQ);
242 if (
D.IsFlangMode() &&
243 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
247 CmdArgs.push_back(
"-lm_p");
249 CmdArgs.push_back(
"-lm");
252 if (NeedsSanitizerDeps) {
262 CmdArgs.push_back(
"-lcompiler_rt");
264 if (Args.hasArg(options::OPT_pthread)) {
265 if (!Shared && Profiling)
266 CmdArgs.push_back(
"-lpthread_p");
268 CmdArgs.push_back(
"-lpthread");
273 CmdArgs.push_back(
"-lc_p");
275 CmdArgs.push_back(
"-lc");
278 CmdArgs.push_back(
"-lcompiler_rt");
281 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
283 const char *crtend =
nullptr;
287 crtend =
"crtendS.o";
295 C.addCommand(std::make_unique<Command>(JA, *
this,
297 Exec, CmdArgs, Inputs, Output));
301 const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
302 const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
304 if (IsX86 || IsX86_64) {
305 Res |= SanitizerKind::Vptr;
306 Res |= SanitizerKind::Fuzzer;
307 Res |= SanitizerKind::FuzzerNoLink;
310 Res |= SanitizerKind::KernelAddress;
324 const llvm::opt::ArgList &DriverArgs,
325 llvm::opt::ArgStringList &CC1Args)
const {
328 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
331 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
333 llvm::sys::path::append(Dir,
"include");
337 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
341 StringRef CIncludeDirs(C_INCLUDE_DIRS);
342 if (CIncludeDirs !=
"") {
344 CIncludeDirs.split(dirs,
":");
345 for (StringRef dir : dirs) {
347 llvm::sys::path::is_absolute(dir) ? StringRef(
D.SysRoot) :
"";
354 concat(
D.SysRoot,
"/usr/include"));
358 llvm::opt::ArgStringList &CC1Args)
const {
364 ArgStringList &CmdArgs)
const {
365 bool Profiling = Args.hasArg(options::OPT_pg);
367 CmdArgs.push_back(Profiling ?
"-lc++_p" :
"-lc++");
368 if (Args.hasArg(options::OPT_fexperimental_library))
369 CmdArgs.push_back(
"-lc++experimental");
370 CmdArgs.push_back(Profiling ?
"-lc++abi_p" :
"-lc++abi");
371 CmdArgs.push_back(Profiling ?
"-lpthread_p" :
"-lpthread");
376 if (Component ==
"builtins") {
378 llvm::sys::path::append(
Path,
"/usr/lib/libcompiler_rt.a");
380 return std::string(
Path);
383 std::string CRTBasename =
385 llvm::sys::path::append(
P,
"lib", CRTBasename);
388 return std::string(
P);
403 case llvm::Triple::arm:
The base class of the type hierarchy.
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()