16#include "llvm/Option/ArgList.h"
17#include "llvm/Support/Path.h"
33 const char *LinkingOutput)
const {
38 NewInputs.push_back(NaClMacros);
39 NewInputs.append(Inputs.begin(), Inputs.end());
52 const char *LinkingOutput)
const {
58 !Args.hasArg(options::OPT_dynamic) && !Args.hasArg(options::OPT_shared);
60 ArgStringList CmdArgs;
63 Args.ClaimAllArgs(options::OPT_g_Group);
65 Args.ClaimAllArgs(options::OPT_emit_llvm);
68 Args.ClaimAllArgs(options::OPT_w);
70 if (!
D.SysRoot.empty())
71 CmdArgs.push_back(Args.MakeArgString(
"--sysroot=" +
D.SysRoot));
73 if (Args.hasArg(options::OPT_rdynamic))
74 CmdArgs.push_back(
"-export-dynamic");
76 if (Args.hasArg(options::OPT_s))
77 CmdArgs.push_back(
"-s");
81 CmdArgs.push_back(
"--build-id");
84 CmdArgs.push_back(
"--eh-frame-hdr");
86 CmdArgs.push_back(
"-m");
87 if (Arch == llvm::Triple::x86)
88 CmdArgs.push_back(
"elf_i386_nacl");
89 else if (Arch == llvm::Triple::arm)
90 CmdArgs.push_back(
"armelf_nacl");
91 else if (Arch == llvm::Triple::x86_64)
92 CmdArgs.push_back(
"elf_x86_64_nacl");
93 else if (Arch == llvm::Triple::mipsel)
94 CmdArgs.push_back(
"mipselelf_nacl");
100 CmdArgs.push_back(
"-static");
101 else if (Args.hasArg(options::OPT_shared))
102 CmdArgs.push_back(
"-shared");
104 CmdArgs.push_back(
"-o");
106 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
107 if (!Args.hasArg(options::OPT_shared))
111 const char *crtbegin;
113 crtbegin =
"crtbeginT.o";
114 else if (Args.hasArg(options::OPT_shared))
115 crtbegin =
"crtbeginS.o";
117 crtbegin =
"crtbegin.o";
121 Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
125 if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
126 CmdArgs.push_back(
"--no-demangle");
131 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
133 bool OnlyLibstdcxxStatic =
134 Args.hasArg(options::OPT_static_libstdcxx) && !
IsStatic;
135 if (OnlyLibstdcxxStatic)
136 CmdArgs.push_back(
"-Bstatic");
138 if (OnlyLibstdcxxStatic)
139 CmdArgs.push_back(
"-Bdynamic");
141 CmdArgs.push_back(
"-lm");
144 if (!Args.hasArg(options::OPT_nostdlib)) {
145 if (!Args.hasArg(options::OPT_nodefaultlibs)) {
147 CmdArgs.push_back(
"--start-group");
148 CmdArgs.push_back(
"-lc");
151 if (Args.hasArg(options::OPT_pthread) ||
152 Args.hasArg(options::OPT_pthreads) ||
D.CCCIsCXX()) {
157 if (getToolChain().getArch() == llvm::Triple::mipsel)
158 CmdArgs.push_back(
"-lnacl");
160 CmdArgs.push_back(
"-lpthread");
163 CmdArgs.push_back(
"-lgcc");
164 CmdArgs.push_back(
"--as-needed");
166 CmdArgs.push_back(
"-lgcc_eh");
168 CmdArgs.push_back(
"-lgcc_s");
169 CmdArgs.push_back(
"--no-as-needed");
174 if (getToolChain().getArch() == llvm::Triple::mipsel)
175 CmdArgs.push_back(
"-lpnacl_legacy");
177 CmdArgs.push_back(
"--end-group");
180 if (!Args.hasArg(options::OPT_nostartfiles)) {
182 if (Args.hasArg(options::OPT_shared))
183 crtend =
"crtendS.o";
193 C.addCommand(std::make_unique<Command>(JA, *
this,
195 Exec, CmdArgs, Inputs, Output));
213 std::string FilePath(
getDriver().Dir +
"/../");
216 std::string ProgPath(
getDriver().Dir +
"/../");
219 std::string ToolPath(
getDriver().ResourceDir +
"/lib/");
221 switch (Triple.getArch()) {
222 case llvm::Triple::x86:
223 file_paths.push_back(FilePath +
"x86_64-nacl/lib32");
224 file_paths.push_back(FilePath +
"i686-nacl/usr/lib");
225 prog_paths.push_back(ProgPath +
"x86_64-nacl/bin");
226 file_paths.push_back(ToolPath +
"i686-nacl");
228 case llvm::Triple::x86_64:
229 file_paths.push_back(FilePath +
"x86_64-nacl/lib");
230 file_paths.push_back(FilePath +
"x86_64-nacl/usr/lib");
231 prog_paths.push_back(ProgPath +
"x86_64-nacl/bin");
232 file_paths.push_back(ToolPath +
"x86_64-nacl");
234 case llvm::Triple::arm:
235 file_paths.push_back(FilePath +
"arm-nacl/lib");
236 file_paths.push_back(FilePath +
"arm-nacl/usr/lib");
237 prog_paths.push_back(ProgPath +
"arm-nacl/bin");
238 file_paths.push_back(ToolPath +
"arm-nacl");
240 case llvm::Triple::mipsel:
241 file_paths.push_back(FilePath +
"mipsel-nacl/lib");
242 file_paths.push_back(FilePath +
"mipsel-nacl/usr/lib");
243 prog_paths.push_back(ProgPath +
"bin");
244 file_paths.push_back(ToolPath +
"mipsel-nacl");
250 NaClArmMacrosPath =
GetFilePath(
"nacl-arm-macros.s");
254 ArgStringList &CC1Args)
const {
256 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
259 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
261 llvm::sys::path::append(
P,
"include");
265 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
270 case llvm::Triple::x86:
274 llvm::sys::path::append(
P,
"i686-nacl/usr/include");
276 llvm::sys::path::remove_filename(
P);
277 llvm::sys::path::remove_filename(
P);
278 llvm::sys::path::remove_filename(
P);
279 llvm::sys::path::append(
P,
"x86_64-nacl/include");
282 case llvm::Triple::arm:
283 llvm::sys::path::append(
P,
"arm-nacl/usr/include");
285 case llvm::Triple::x86_64:
286 llvm::sys::path::append(
P,
"x86_64-nacl/usr/include");
288 case llvm::Triple::mipsel:
289 llvm::sys::path::append(
P,
"mipsel-nacl/usr/include");
296 llvm::sys::path::remove_filename(
P);
297 llvm::sys::path::remove_filename(
P);
298 llvm::sys::path::append(
P,
"include");
303 ArgStringList &CmdArgs)
const {
307 CmdArgs.push_back(
"-lc++");
308 if (Args.hasArg(options::OPT_fexperimental_library))
309 CmdArgs.push_back(
"-lc++experimental");
313 const llvm::opt::ArgList &DriverArgs,
314 llvm::opt::ArgStringList &CC1Args)
const {
321 case llvm::Triple::arm:
322 llvm::sys::path::append(
P,
"arm-nacl/include/c++/v1");
325 case llvm::Triple::x86:
326 llvm::sys::path::append(
P,
"x86_64-nacl/include/c++/v1");
329 case llvm::Triple::x86_64:
330 llvm::sys::path::append(
P,
"x86_64-nacl/include/c++/v1");
333 case llvm::Triple::mipsel:
334 llvm::sys::path::append(
P,
"mipsel-nacl/include/c++/v1");
342 if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
343 StringRef
Value = A->getValue();
344 if (
Value ==
"libc++")
347 << A->getAsString(Args);
357 if (TheTriple.getArch() == llvm::Triple::arm &&
358 TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment)
359 TheTriple.setEnvironment(llvm::Triple::GNUEABIHF);
360 return TheTriple.getTriple();
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...
DiagnosticBuilder Diag(unsigned DiagID) const
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport AtFileCurCP()