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()) {
246 CmdArgs.push_back(
"-lm_p");
248 CmdArgs.push_back(
"-lm");
251 if (NeedsSanitizerDeps) {
261 CmdArgs.push_back(
"-lcompiler_rt");
263 if (Args.hasArg(options::OPT_pthread)) {
264 if (!Shared && Profiling)
265 CmdArgs.push_back(
"-lpthread_p");
267 CmdArgs.push_back(
"-lpthread");
272 CmdArgs.push_back(
"-lc_p");
274 CmdArgs.push_back(
"-lc");
277 CmdArgs.push_back(
"-lcompiler_rt");
280 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
282 const char *crtend =
nullptr;
286 crtend =
"crtendS.o";
294 C.addCommand(std::make_unique<Command>(JA, *
this,
296 Exec, CmdArgs, Inputs, Output));
300 const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
301 const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
303 if (IsX86 || IsX86_64) {
304 Res |= SanitizerKind::Vptr;
305 Res |= SanitizerKind::Fuzzer;
306 Res |= SanitizerKind::FuzzerNoLink;
309 Res |= SanitizerKind::KernelAddress;
323 const llvm::opt::ArgList &DriverArgs,
324 llvm::opt::ArgStringList &CC1Args)
const {
327 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
330 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
332 llvm::sys::path::append(Dir,
"include");
336 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
340 StringRef CIncludeDirs(C_INCLUDE_DIRS);
341 if (CIncludeDirs !=
"") {
343 CIncludeDirs.split(dirs,
":");
344 for (StringRef dir : dirs) {
346 llvm::sys::path::is_absolute(dir) ? StringRef(
D.SysRoot) :
"";
353 concat(
D.SysRoot,
"/usr/include"));
357 llvm::opt::ArgStringList &CC1Args)
const {
363 ArgStringList &CmdArgs)
const {
364 bool Profiling = Args.hasArg(options::OPT_pg);
366 CmdArgs.push_back(Profiling ?
"-lc++_p" :
"-lc++");
367 if (Args.hasArg(options::OPT_fexperimental_library))
368 CmdArgs.push_back(
"-lc++experimental");
369 CmdArgs.push_back(Profiling ?
"-lc++abi_p" :
"-lc++abi");
370 CmdArgs.push_back(Profiling ?
"-lpthread_p" :
"-lpthread");
375 if (Component ==
"builtins") {
377 llvm::sys::path::append(
Path,
"/usr/lib/libcompiler_rt.a");
379 return std::string(
Path);
382 std::string CRTBasename =
384 llvm::sys::path::append(
P,
"lib", CRTBasename);
387 return std::string(
P);
402 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()